Welcome to little lamb

Code » anopa » commit 629d178

Add exitcode to aa_die_usage()

author Olivier Brunel
2015-02-21 12:13:40 UTC
committer Olivier Brunel
2015-04-04 12:47:33 UTC
parent 40d61727f22f19962a00532058d62554f7991a3e

Add exitcode to aa_die_usage()

src/anopa/aa-enable.c +7 -5
src/anopa/aa-start.c +7 -5
src/anopa/aa-stop.c +7 -5
src/include/anopa/common.h +1 -1
src/libanopa/die_usage.c +2 -2
src/utils/aa-echo.c +7 -4

diff --git a/src/anopa/aa-enable.c b/src/anopa/aa-enable.c
index 2dea2b2..ea416ad 100644
--- a/src/anopa/aa-enable.c
+++ b/src/anopa/aa-enable.c
@@ -133,9 +133,9 @@ it_list (direntry *d, void *data)
 }
 
 static void
-dieusage (void)
+dieusage (int rc)
 {
-    aa_die_usage ("[OPTION...] [service...]",
+    aa_die_usage (rc, "[OPTION...] [service...]",
             " -D, --double-output           Enable double-output mode\n"
             " -r, --repodir DIR             Use DIR as repository directory\n"
             " -S, --reset-source DIR        Reset list of source directories to DIR\n"
@@ -190,6 +190,9 @@ main (int argc, char * const argv[])
                 mode_both = 1;
                 break;
 
+            case 'h':
+                dieusage (0);
+
             case 'k':
                 skip = optarg;
                 break;
@@ -225,9 +228,8 @@ main (int argc, char * const argv[])
             case 'V':
                 aa_die_version ();
 
-            case 'h':
             default:
-                dieusage ();
+                dieusage (1);
         }
     }
     argc -= optind;
@@ -236,7 +238,7 @@ main (int argc, char * const argv[])
     aa_init_output (mode_both);
 
     if (!path_list && argc < 1)
-        dieusage ();
+        dieusage (1);
 
     r = aa_init_repo (path_repo, AA_REPO_CREATE);
     if (r < 0)
diff --git a/src/anopa/aa-start.c b/src/anopa/aa-start.c
index 91d7e39..7bfde02 100644
--- a/src/anopa/aa-start.c
+++ b/src/anopa/aa-start.c
@@ -184,9 +184,9 @@ scan_cb (int si, int sni)
 }
 
 static void
-dieusage (void)
+dieusage (int rc)
 {
-    aa_die_usage ("[OPTION...] [service...]",
+    aa_die_usage (rc, "[OPTION...] [service...]",
             " -D, --double-output           Enable double-output mode\n"
             " -r, --repodir DIR             Use DIR as repository directory\n"
             " -l, --listdir DIR             Use DIR to list services to start\n"
@@ -233,6 +233,9 @@ main (int argc, char * const argv[])
                 mode_both = 1;
                 break;
 
+            case 'h':
+                dieusage (0);
+
             case 'l':
                 unslash (optarg);
                 path_list = optarg;
@@ -250,9 +253,8 @@ main (int argc, char * const argv[])
             case 'V':
                 aa_die_version ();
 
-            case 'h':
             default:
-                dieusage ();
+                dieusage (1);
         }
     }
     argc -= optind;
@@ -263,7 +265,7 @@ main (int argc, char * const argv[])
     is_utf8 = is_locale_utf8 ();
 
     if (!path_list && argc < 1)
-        dieusage ();
+        dieusage (1);
 
     if (aa_init_repo (path_repo, AA_REPO_WRITE) < 0)
         strerr_diefu2sys (ERR_IO, "init repository ", path_repo);
diff --git a/src/anopa/aa-stop.c b/src/anopa/aa-stop.c
index b452544..b9dc8e3 100644
--- a/src/anopa/aa-stop.c
+++ b/src/anopa/aa-stop.c
@@ -153,9 +153,9 @@ it_stop (direntry *d, void *data)
 }
 
 static void
-dieusage (void)
+dieusage (int rc)
 {
-    aa_die_usage ("[OPTION...] [service...]",
+    aa_die_usage (rc, "[OPTION...] [service...]",
             " -D, --double-output           Enable double-output mode\n"
             " -r, --repodir DIR             Use DIR as repository directory\n"
             " -k, --skip SERVICE            Skip (do not stop) SERVICE\n"
@@ -205,6 +205,9 @@ main (int argc, char * const argv[])
                 all = 1;
                 break;
 
+            case 'h':
+                dieusage (0);
+
             case 'k':
                 skip = optarg;
                 break;
@@ -217,9 +220,8 @@ main (int argc, char * const argv[])
             case 'V':
                 aa_die_version ();
 
-            case 'h':
             default:
-                dieusage ();
+                dieusage (1);
         }
     }
     argc -= optind;
@@ -230,7 +232,7 @@ main (int argc, char * const argv[])
     is_utf8 = is_locale_utf8 ();
 
     if ((all && argc > 0) || (!all && argc < 1))
-        dieusage ();
+        dieusage (1);
 
     if (aa_init_repo (path_repo, AA_REPO_WRITE) < 0)
         strerr_diefu2sys (ERR_IO, "init repository ", path_repo);
diff --git a/src/include/anopa/common.h b/src/include/anopa/common.h
index 234d6e3..999fb33 100644
--- a/src/include/anopa/common.h
+++ b/src/include/anopa/common.h
@@ -4,7 +4,7 @@
 
 #define AA_SCANDIR_DIRNAME      ".scandir"
 
-void aa_die_usage (const char *usage, const char *details);
+void aa_die_usage (int rc, const char *usage, const char *details);
 void aa_die_version (void);
 
 #endif /* AA_COMMON_H */
diff --git a/src/libanopa/die_usage.c b/src/libanopa/die_usage.c
index 039ff95..d6a1315 100644
--- a/src/libanopa/die_usage.c
+++ b/src/libanopa/die_usage.c
@@ -5,7 +5,7 @@
 extern char const *PROG;
 
 void
-aa_die_usage (const char *usage, const char *details)
+aa_die_usage (int rc, const char *usage, const char *details)
 {
     aa_init_output (0);
     aa_bs_noflush (AA_OUT, "Usage: ");
@@ -14,5 +14,5 @@ aa_die_usage (const char *usage, const char *details)
     aa_bs_noflush (AA_OUT, usage);
     aa_bs_noflush (AA_OUT, "\n\n");
     aa_bs_flush (AA_OUT, details);
-    _exit (0);
+    _exit (rc);
 }
diff --git a/src/utils/aa-echo.c b/src/utils/aa-echo.c
index 6eea326..f588058 100644
--- a/src/utils/aa-echo.c
+++ b/src/utils/aa-echo.c
@@ -20,9 +20,9 @@ put_title2 (const char *name, const char *msg, int end)
 }
 
 static void
-dieusage (void)
+dieusage (int rc)
 {
-    aa_die_usage ("[OPTION...] MESSAGE...",
+    aa_die_usage (rc, "[OPTION...] MESSAGE...",
             " -D, --double-output           Enable double-output mode\n"
             " -T, --title                   Show a main title (default)\n"
             " -t, --title2                  Show a secondary title\n"
@@ -74,6 +74,9 @@ main (int argc, char * const argv[])
                 mode_both = 1;
                 break;
 
+            case 'h':
+                dieusage (0);
+
             case 'T':
                 put = put_title;
                 where = AA_OUT;
@@ -98,14 +101,14 @@ main (int argc, char * const argv[])
                 aa_die_version ();
 
             default:
-                dieusage ();
+                dieusage (1);
         }
     }
     argc -= optind;
     argv += optind;
 
     if (argc < 1)
-        dieusage ();
+        dieusage (1);
 
     aa_init_output (mode_both);
     put ("", NULL, 0);