diff mbox

[2/5] runstate: Print state transition when invalid

Message ID 1318613203-25892-3-git-send-email-lcapitulino@redhat.com
State New
Headers show

Commit Message

Luiz Capitulino Oct. 14, 2011, 5:26 p.m. UTC
Makes it easier to debug.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 vl.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

Comments

Wen Congyang Oct. 19, 2011, 12:43 a.m. UTC | #1
At 10/15/2011 01:26 AM, Luiz Capitulino Write:
> Makes it easier to debug.
> 
> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> ---
>  vl.c |    4 +++-
>  1 files changed, 3 insertions(+), 1 deletions(-)
> 
> diff --git a/vl.c b/vl.c
> index dbf7778..6645720 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -397,7 +397,9 @@ void runstate_set(RunState new_state)
>  {
>      if (new_state >= RUN_STATE_MAX ||
>          !runstate_valid_transitions[current_run_state][new_state]) {
> -        fprintf(stderr, "invalid runstate transition\n");
> +        fprintf(stderr, "ERROR: invalid runstate transition: '%s' -> '%s'\n",
> +                RunState_lookup[current_run_state],
> +                RunState_lookup[new_state]);

If new_state >= RUN_STATE_MAX, we can not use RunState_lookup.
I think it's better to use:
    new_state >= RUN_STATE_MAX ? "invalid state" : RunState_lookup[new_state]

Thanks
Wen Congyang

>          abort();
>      }
>
diff mbox

Patch

diff --git a/vl.c b/vl.c
index dbf7778..6645720 100644
--- a/vl.c
+++ b/vl.c
@@ -397,7 +397,9 @@  void runstate_set(RunState new_state)
 {
     if (new_state >= RUN_STATE_MAX ||
         !runstate_valid_transitions[current_run_state][new_state]) {
-        fprintf(stderr, "invalid runstate transition\n");
+        fprintf(stderr, "ERROR: invalid runstate transition: '%s' -> '%s'\n",
+                RunState_lookup[current_run_state],
+                RunState_lookup[new_state]);
         abort();
     }