]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
ui: make interactive and non-interactive exit code the same 447/head
authorSami Kerola <kerolasa@iki.fi>
Tue, 6 Sep 2022 13:16:04 +0000 (14:16 +0100)
committerSami Kerola <kerolasa@iki.fi>
Tue, 6 Sep 2022 13:40:12 +0000 (14:40 +0100)
Before this change the report gave successful exit value when destination
hostname could not be found.

    $ ./mtr --report nxdomain. ; echo $?
    ./mtr: Failed to resolve host: nxdomain.: Name or service not known
    0

Quickly looking 'git grep ---after-context if.*Interactive' there does not
appear to be more than the two instances in main() where exit is called
depending on interactive, so this change should cover all these cases.

Reported-by: Marek Kroemeke <mkroemeke@cloudflare.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
ui/mtr.c

index e4a40410383387e37c057f0374a576f594a25de5..5a70f3130e3ab9d0a7d88c5e3be13c01cfacda25 100644 (file)
--- a/ui/mtr.c
+++ b/ui/mtr.c
@@ -710,6 +710,7 @@ int main(
     int argc,
     char **argv)
 {
+    int exit_val = EXIT_SUCCESS;
     names_t *names_head = NULL;
     names_t *names_walk;
 
@@ -784,6 +785,7 @@ int main(
             if (ctl.Interactive)
                 exit(EXIT_FAILURE);
             else {
+                exit_val = EXIT_FAILURE;
                 names_walk = names_walk->next;
                 continue;
             }
@@ -794,6 +796,7 @@ int main(
             if (ctl.Interactive)
                 exit(EXIT_FAILURE);
             else {
+                exit_val = EXIT_FAILURE;
                 names_walk = names_walk->next;
                 continue;
             }
@@ -829,5 +832,5 @@ int main(
         item = NULL;
     }
 
-    return 0;
+    return exit_val;
 }