bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

maint: avoid usage(1)


From: Eric Blake
Subject: maint: avoid usage(1)
Date: Thu, 29 Oct 2009 06:40:13 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I noticed this during my audit for stderr vs. exec.  We've made previous
cleanups along these lines, but usages have crept back in.  OK to commit?

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkrpjS0ACgkQ84KuGfSFAYB6jQCdGv/RQSp5k2C/ZZcObWxw64gl
AVEAnRUVDaPacsfpXiUZA8kboBm56RjO
=hQyO
-----END PGP SIGNATURE-----
>From c5657bf61fdeee002c2cdf490084c423bca0066b Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Thu, 29 Oct 2009 06:37:38 -0600
Subject: [PATCH] maint: avoid exiting with magic number

* cfg.mk (sc_prohibit_magic_number_exit)
(sc_prohibit_error_success): New rules.
* .x-sc_prohibit_magic_number_exit: Add exemptions.
* Makefile.am (syntax_check_exceptions): Distribute it.
* lib/euidaccess-stat.c (main): Fix culprits.
* src/chcon.c (main): Likewise.
* src/runcon.c (main): Likewise.
* src/setuidgid.c (main): Likewise.
---
 .x-sc_prohibit_magic_number_exit |    3 +++
 Makefile.am                      |    1 +
 cfg.mk                           |   12 ++++++++++++
 lib/euidaccess-stat.c            |    2 +-
 src/chcon.c                      |    2 +-
 src/runcon.c                     |    4 ++--
 src/setuidgid.c                  |    2 +-
 7 files changed, 21 insertions(+), 5 deletions(-)
 create mode 100644 .x-sc_prohibit_magic_number_exit

diff --git a/.x-sc_prohibit_magic_number_exit b/.x-sc_prohibit_magic_number_exit
new file mode 100644
index 0000000..0067bc8
--- /dev/null
+++ b/.x-sc_prohibit_magic_number_exit
@@ -0,0 +1,3 @@
+configure.ac
+*.m4
+ChangeLog*
diff --git a/Makefile.am b/Makefile.am
index 6175a8e..62efb7d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -47,6 +47,7 @@ syntax_check_exceptions =             \
   .x-sc_po_check                       \
   .x-sc_program_name                   \
   .x-sc_prohibit_atoi_atof             \
+  .x-sc_prohibit_magic_number_exit     \
   .x-sc_prohibit_stat_st_blocks                \
   .x-sc_prohibit_strcmp                        \
   .x-sc_prohibit_tab_based_indentation \
diff --git a/cfg.mk b/cfg.mk
index 1e5108b..cce945a 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -203,6 +203,18 @@ sc_prohibit_stat_macro_address:
        msg='stat() and lstat() may be function-like macros'            \
          $(_prohibit_regexp)

+# Pass EXIT_*, not number, to usage, exit, and error
+sc_prohibit_magic_number_exit:
+       @re='\<(usage|exit) \([0-9]|\<error \([1-9][0-9]*,'             \
+       msg='use EXIT_* values rather than magic number'                \
+         $(_prohibit_regexp)
+
+# error (0) is preferred over error (EXIT_SUCCESS), since it does not exit
+sc_prohibit_error_success:
+       @re='\<error \(EXIT_SUCCESS,'                                   \
+       msg='use error(0) rather than error(EXIT_SUCCESS)'              \
+         $(_prohibit_regexp)
+
 # Ensure that date's --help output stays in sync with the info
 # documentation for GNU strftime.  The only exception is %N,
 # which date accepts but GNU strftime does not.
diff --git a/lib/euidaccess-stat.c b/lib/euidaccess-stat.c
index 3d0897b..04cb373 100644
--- a/lib/euidaccess-stat.c
+++ b/lib/euidaccess-stat.c
@@ -130,6 +130,6 @@ main (int argc, char **argv)

   ok = euidaccess_stat (&st, mode);
   printf ("%s: %s\n", file, ok ? "y" : "n");
-  exit (0);
+  return 0;
 }
 #endif
diff --git a/src/chcon.c b/src/chcon.c
index fbfdb4d..2badefb 100644
--- a/src/chcon.c
+++ b/src/chcon.c
@@ -546,7 +546,7 @@ main (int argc, char **argv)
   if (reference_file && component_specified)
     {
       error (0, 0, _("conflicting security context specifiers given"));
-      usage (1);
+      usage (EXIT_FAILURE);
     }

   if (recurse && preserve_root)
diff --git a/src/runcon.c b/src/runcon.c
index f87eada..2637373 100644
--- a/src/runcon.c
+++ b/src/runcon.c
@@ -182,7 +182,7 @@ main (int argc, char **argv)
       if (optind >= argc)
         {
           error (0, 0, _("you must specify -c, -t, -u, -l, -r, or context"));
-          usage (1);
+          usage (EXIT_FAILURE);
         }
       context = argv[optind++];
     }
@@ -190,7 +190,7 @@ main (int argc, char **argv)
   if (optind >= argc)
     {
       error (0, 0, _("no command specified"));
-      usage (1);
+      usage (EXIT_FAILURE);
     }

   if (is_selinux_enabled () != 1)
diff --git a/src/setuidgid.c b/src/setuidgid.c
index 34be515..0adac21 100644
--- a/src/setuidgid.c
+++ b/src/setuidgid.c
@@ -181,7 +181,7 @@ main (int argc, char **argv)
       {
         int n = mgetgroups (pwd->pw_name, pwd->pw_gid, &gids);
         if (n <= 0)
-          error (1, errno, _("failed to get groups for user %s"),
+          error (EXIT_FAILURE, errno, _("failed to get groups for user %s"),
                  quote (pwd->pw_name));
         n_gids = n;
       }
-- 
1.6.5.rc1


reply via email to

[Prev in Thread] Current Thread [Next in Thread]