]> granicus.if.org Git - shadow/blobdiff - src/groupadd.c
* src/chpasswd.c: Add annotations to indicate that usage() does
[shadow] / src / groupadd.c
index 55de85e9ece5a36b25866986650f5079ea065426..7ec21e942d33bd95c3e8990f5ffb05593733b693 100644 (file)
@@ -34,7 +34,6 @@
 
 #ident "$Id$"
 
-#include <assert.h>
 #include <ctype.h>
 #include <fcntl.h>
 #include <getopt.h>
@@ -60,6 +59,7 @@
 /*
  * exit status values
  */
+/*@-exitarg@*/
 #define E_SUCCESS      0       /* success */
 #define E_USAGE                2       /* invalid command syntax */
 #define E_BAD_ARG      3       /* invalid argument to option */
@@ -70,7 +70,7 @@
 /*
  * Global variables
  */
-char *Prog;
+const char *Prog;
 
 static /*@null@*/char *group_name;
 static gid_t group_id;
@@ -88,7 +88,7 @@ static bool is_shadow_grp;
 #endif
 
 /* local function prototypes */
-static void usage (void);
+static void usage (int status);
 static void new_grent (struct group *grent);
 
 #ifdef SHADOWGRP
@@ -105,22 +105,25 @@ static void check_perms (void);
 /*
  * usage - display usage message and exit
  */
-static void usage (void)
+static void usage (int status)
 {
-       fputs (_("Usage: groupadd [options] GROUP\n"
-                "\n"
-                "Options:\n"
-                "  -f, --force                   force exit with success status if the\n"
-                "                                specified group already exists\n"
-                "  -g, --gid GID                 use GID for the new group\n"
-                "  -h, --help                    display this help message and exit\n"
-                "  -K, --key KEY=VALUE           overrides /etc/login.defs defaults\n"
-                "  -o, --non-unique              allow create group with duplicate\n"
-                "                                (non-unique) GID\n"
-                "  -p, --password PASSWORD       use encrypted password for the new group\n"
-                "  -r, --system                  create a system account\n"
-                "\n"), stderr);
-       exit (E_USAGE);
+       FILE *usageout = (E_SUCCESS != status) ? stderr : stdout;
+       (void) fprintf (usageout,
+                       _("Usage: %s [options] GROUP\n"
+                         "\n"
+                         "Options:\n"),
+                       Prog);
+       (void) fputs (_("  -f, --force                   exit successfully if the group already exists,\n"
+                       "                                and cancel -g if the GID is already used\n"), usageout);
+       (void) fputs (_("  -g, --gid GID                 use GID for the new group\n"), usageout);
+       (void) fputs (_("  -h, --help                    display this help message and exit\n"), usageout);
+       (void) fputs (_("  -K, --key KEY=VALUE           override /etc/login.defs defaults\n"), usageout);
+       (void) fputs (_("  -o, --non-unique              allow to create groups with duplicate\n"
+                       "                                (non-unique) GID\n"), usageout);
+       (void) fputs (_("  -p, --password PASSWORD       use this encrypted password for the new group\n"), usageout);
+       (void) fputs (_("  -r, --system                  create a system account\n"), usageout);
+       (void) fputs ("\n", usageout);
+       exit (status);
 }
 
 /*
@@ -341,7 +344,7 @@ static void open_files (void)
         */
        add_cleanup (cleanup_report_add_group, group_name);
 
-       /* An now open the databases */
+       /* And now open the databases */
        if (gr_open (O_RDWR) == 0) {
                fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ());
                SYSLOG ((LOG_WARN, "cannot open %s", gr_dbname ()));
@@ -410,7 +413,7 @@ static void process_flags (int argc, char **argv)
                        }
                        break;
                case 'h':
-                       usage ();
+                       usage (E_SUCCESS);
                        break;
                case 'K':
                        /*
@@ -442,7 +445,7 @@ static void process_flags (int argc, char **argv)
                        rflg = true;
                        break;
                default:
-                       usage ();
+                       usage (E_USAGE);
                }
        }
 
@@ -450,7 +453,7 @@ static void process_flags (int argc, char **argv)
         * Check the flags consistency
         */
        if (optind != argc - 1) {
-               usage ();
+               usage (E_USAGE);
        }
        group_name = argv[optind];
 
@@ -466,7 +469,7 @@ static void check_flags (void)
 {
        /* -o does not make sense without -g */
        if (oflg && !gflg) {
-               usage ();
+               usage (E_USAGE);
        }
 
        check_new_name ();