bug-coreutils
[Top][All Lists]
Advanced

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

Re: EXIT_FAIL vs. EXIT_FAILURE


From: Jim Meyering
Subject: Re: EXIT_FAIL vs. EXIT_FAILURE
Date: Wed, 29 Aug 2007 00:15:23 +0200

Eric Blake <address@hidden> wrote:
> system.h currently has:
>
> /* Exit statuses for programs like 'env' that exec other programs.
>    EXIT_FAILURE might not be 1, so use EXIT_FAIL in such programs.  */
> enum
> {
>   EXIT_FAIL = 1,
>
> But gnulib's stdlib_.h has:
>
> /* Tandem/NSK and other platforms that define EXIT_FAILURE as -1 interfere
>    with proper operation of xargs.  */
> #ifndef EXIT_FAILURE
> # define EXIT_FAILURE 1
> #elif EXIT_FAILURE != 1
> # undef EXIT_FAILURE
> # define EXIT_FAILURE 1
> #endif
>
> In other words, thanks to gnulib, EXIT_FAILURE is guaranteed to be 1.  Is 
> there
> any reason to keep EXIT_FAIL in coreutils sources any more?

No.
Good catch.  Thansk!
I was going to say "Send a patch! :-)",
but figured it'd be quicker to do it myself, in this case:

>From 35755454e45a6cbab4c711353131df483d89a979 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Wed, 29 Aug 2007 00:13:16 +0200
Subject: [PATCH] Use EXIT_FAILURE, not EXIT_FAIL, now that EXIT_FAILURE is 
always 1.

* src/system.h (EXIT_FAIL): Remove definition.
* src/chroot.c (main): EXIT_FAIL -> EXIT_FAILURE.
* src/env.c (main): Likewise.
* src/nice.c (main): Likewise.
* src/su.c (change_identity, main): Likewise.
* src/tty.c (main): Likewise.
Suggestion from Eric Blake.

Signed-off-by: Jim Meyering <address@hidden>
---
 ChangeLog    |   11 +++++++++++
 src/chroot.c |   10 +++++-----
 src/env.c    |    4 ++--
 src/nice.c   |   14 +++++++-------
 src/su.c     |   14 +++++++-------
 src/system.h |    4 +---
 src/tty.c    |    2 +-
 7 files changed, 34 insertions(+), 25 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 80d08a1..015bad9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2007-08-29  Jim Meyering  <address@hidden>
+
+       Use EXIT_FAILURE, not EXIT_FAIL, now that EXIT_FAILURE is always 1.
+       * src/system.h (EXIT_FAIL): Remove definition.
+       * src/chroot.c (main): EXIT_FAIL -> EXIT_FAILURE.
+       * src/env.c (main): Likewise.
+       * src/nice.c (main): Likewise.
+       * src/su.c (change_identity, main): Likewise.
+       * src/tty.c (main): Likewise.
+       Suggestion from Eric Blake.
+
 2007-08-28  Jim Meyering  <address@hidden>

        * src/test.c (usage): Note that [ honors --help and --version,
diff --git a/src/chroot.c b/src/chroot.c
index 67bf074..4d23fab 100644
--- a/src/chroot.c
+++ b/src/chroot.c
@@ -70,25 +70,25 @@ main (int argc, char **argv)
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);

-  initialize_exit_failure (EXIT_FAIL);
+  initialize_exit_failure (EXIT_FAILURE);
   atexit (close_stdout);

   parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION,
                      usage, AUTHORS, (char const *) NULL);
   if (getopt_long (argc, argv, "+", NULL, NULL) != -1)
-    usage (EXIT_FAIL);
+    usage (EXIT_FAILURE);

   if (argc <= optind)
     {
       error (0, 0, _("missing operand"));
-      usage (EXIT_FAIL);
+      usage (EXIT_FAILURE);
     }

   if (chroot (argv[optind]) != 0)
-    error (EXIT_FAIL, errno, _("cannot change root directory to %s"), argv[1]);
+    error (EXIT_FAILURE, errno, _("cannot change root directory to %s"), 
argv[1]);

   if (chdir ("/"))
-    error (EXIT_FAIL, errno, _("cannot chdir to root directory"));
+    error (EXIT_FAILURE, errno, _("cannot chdir to root directory"));

   if (argc == optind + 1)
     {
diff --git a/src/env.c b/src/env.c
index 52e24aa..14a62d0 100644
--- a/src/env.c
+++ b/src/env.c
@@ -146,7 +146,7 @@ main (int argc, char **argv)
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);

-  initialize_exit_failure (EXIT_FAIL);
+  initialize_exit_failure (EXIT_FAILURE);
   atexit (close_stdout);

   while ((optc = getopt_long (argc, argv, "+iu:", longopts, NULL)) != -1)
@@ -161,7 +161,7 @@ main (int argc, char **argv)
        case_GETOPT_HELP_CHAR;
        case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
        default:
-         usage (EXIT_FAIL);
+         usage (EXIT_FAILURE);
        }
     }

diff --git a/src/nice.c b/src/nice.c
index 4624e48..7892fea 100644
--- a/src/nice.c
+++ b/src/nice.c
@@ -104,7 +104,7 @@ main (int argc, char **argv)
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);

-  initialize_exit_failure (EXIT_FAIL);
+  initialize_exit_failure (EXIT_FAILURE);
   atexit (close_stdout);

   parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION,
@@ -135,7 +135,7 @@ main (int argc, char **argv)
          i += optind - 1;

          if (optc == '?')
-           usage (EXIT_FAIL);
+           usage (EXIT_FAILURE);
          else if (optc == 'n')
            adjustment_given = optarg;
          else /* optc == -1 */
@@ -151,7 +151,7 @@ main (int argc, char **argv)
       enum { MIN_ADJUSTMENT = 1 - 2 * NZERO, MAX_ADJUSTMENT = 2 * NZERO - 1 };
       long int tmp;
       if (LONGINT_OVERFLOW < xstrtol (adjustment_given, NULL, 10, &tmp, ""))
-       error (EXIT_FAIL, 0, _("invalid adjustment %s"),
+       error (EXIT_FAILURE, 0, _("invalid adjustment %s"),
               quote (adjustment_given));
       adjustment = MAX (MIN_ADJUSTMENT, MIN (tmp, MAX_ADJUSTMENT));
     }
@@ -161,13 +161,13 @@ main (int argc, char **argv)
       if (adjustment_given)
        {
          error (0, 0, _("a command must be given with an adjustment"));
-         usage (EXIT_FAIL);
+         usage (EXIT_FAILURE);
        }
       /* No command given; print the niceness.  */
       errno = 0;
       current_niceness = GET_NICENESS ();
       if (current_niceness == -1 && errno != 0)
-       error (EXIT_FAIL, errno, _("cannot get niceness"));
+       error (EXIT_FAILURE, errno, _("cannot get niceness"));
       printf ("%d\n", current_niceness);
       exit (EXIT_SUCCESS);
     }
@@ -178,11 +178,11 @@ main (int argc, char **argv)
 #else
   current_niceness = GET_NICENESS ();
   if (current_niceness == -1 && errno != 0)
-    error (EXIT_FAIL, errno, _("cannot get niceness"));
+    error (EXIT_FAILURE, errno, _("cannot get niceness"));
   ok = (setpriority (PRIO_PROCESS, 0, current_niceness + adjustment) == 0);
 #endif
   if (!ok)
-    error (errno == EPERM ? 0 : EXIT_FAIL, errno, _("cannot set niceness"));
+    error (errno == EPERM ? 0 : EXIT_FAILURE, errno, _("cannot set niceness"));

   execvp (argv[i], &argv[i]);

diff --git a/src/su.c b/src/su.c
index 51eed60..7778002 100644
--- a/src/su.c
+++ b/src/su.c
@@ -299,13 +299,13 @@ change_identity (const struct passwd *pw)
 #ifdef HAVE_INITGROUPS
   errno = 0;
   if (initgroups (pw->pw_name, pw->pw_gid) == -1)
-    error (EXIT_FAIL, errno, _("cannot set groups"));
+    error (EXIT_FAILURE, errno, _("cannot set groups"));
   endgrent ();
 #endif
   if (setgid (pw->pw_gid))
-    error (EXIT_FAIL, errno, _("cannot set group id"));
+    error (EXIT_FAILURE, errno, _("cannot set group id"));
   if (setuid (pw->pw_uid))
-    error (EXIT_FAIL, errno, _("cannot set user id"));
+    error (EXIT_FAILURE, errno, _("cannot set user id"));
 }

 /* Run SHELL, or DEFAULT_SHELL if SHELL is empty.
@@ -419,7 +419,7 @@ main (int argc, char **argv)
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);

-  initialize_exit_failure (EXIT_FAIL);
+  initialize_exit_failure (EXIT_FAILURE);
   atexit (close_stdout);

   fast_startup = false;
@@ -456,7 +456,7 @@ main (int argc, char **argv)
        case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);

        default:
-         usage (EXIT_FAIL);
+         usage (EXIT_FAILURE);
        }
     }

@@ -471,7 +471,7 @@ main (int argc, char **argv)
   pw = getpwnam (new_user);
   if (! (pw && pw->pw_name && pw->pw_name[0] && pw->pw_dir && pw->pw_dir[0]
         && pw->pw_passwd))
-    error (EXIT_FAIL, 0, _("user %s does not exist"), new_user);
+    error (EXIT_FAILURE, 0, _("user %s does not exist"), new_user);

   /* Make a copy of the password information and point pw at the local
      copy instead.  Otherwise, some systems (e.g. Linux) would clobber
@@ -494,7 +494,7 @@ main (int argc, char **argv)
 #ifdef SYSLOG_FAILURE
       log_su (pw, false);
 #endif
-      error (EXIT_FAIL, 0, _("incorrect password"));
+      error (EXIT_FAILURE, 0, _("incorrect password"));
     }
 #ifdef SYSLOG_SUCCESS
   else
diff --git a/src/system.h b/src/system.h
index a0a4942..d840ed5 100644
--- a/src/system.h
+++ b/src/system.h
@@ -113,11 +113,9 @@ you must include <sys/types.h> before including this file
 #include <stdbool.h>
 #include <stdlib.h>

-/* Exit statuses for programs like 'env' that exec other programs.
-   EXIT_FAILURE might not be 1, so use EXIT_FAIL in such programs.  */
+/* Exit statuses for programs like 'env' that exec other programs.  */
 enum
 {
-  EXIT_FAIL = 1,
   EXIT_CANNOT_INVOKE = 126,
   EXIT_ENOENT = 127
 };
diff --git a/src/tty.c b/src/tty.c
index c7bdb77..0a38093 100644
--- a/src/tty.c
+++ b/src/tty.c
@@ -124,5 +124,5 @@ main (int argc, char **argv)
        puts (_("not a tty"));
     }

-  exit (isatty (STDIN_FILENO) ? EXIT_SUCCESS : EXIT_FAIL);
+  exit (isatty (STDIN_FILENO) ? EXIT_SUCCESS : EXIT_FAILURE);
 }
--
1.5.3.rc6.55.ga0050-dirty




reply via email to

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