bug-coreutils
[Top][All Lists]
Advanced

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

Re: system.h cleanups


From: Eric Blake
Subject: Re: system.h cleanups
Date: Thu, 8 Oct 2009 15:41:05 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Pádraig Brady <P <at> draigBrady.com> writes:

> I'm not against this but EXIT_TIMEDOUT is specific to timeout.
> Also I'd like to maintain the comments if possible.

Yes, comments help.

> Also stdbuf enums its own EXIT_CANCELED

Fixed in the respin below.

> 
> I also noticed
> 
> nohup enums NOHUP_FAILURE=127 which clashes with EXIT_ENOENT?

Required by POSIX to fail with 127 on internal failure (bummer).

> Also chroot, ence, nice and su only use EXIT_FAILURE?

chroot and su have no POSIX basis; we could probably use EXIT_CANCELED instead 
of EXIT_FAILURE, but that would be a separate patch.

ence?  Did you mean env?  env and nice are required to fail with 1-125, but you 
are right that EXIT_CANCELED is probably more consistent than EXIT_FAILURE.  
This would be the same patch as su and chroot, if we agree to make the change.

>From b7258fb259f9b61e68bc11acf9109df876c73ee4 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Thu, 8 Oct 2009 08:13:02 -0600
Subject: [PATCH 1/3] maint: move timeout exit statuses

* src/timeout.c (EXIT_TIMEDOUT, EXIT_CANCELED): Remove as
macros...
* src/system.h (EXIT_TIMEDOUT, EXIT_CANCELED): ...and provide as
enum values instead.
* src/stdbuf.c (EXIT_CANCELED): Delete.
---
 src/stdbuf.c  |    3 ---
 src/system.h  |    6 ++++--
 src/timeout.c |    6 ------
 3 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/src/stdbuf.c b/src/stdbuf.c
index 05a6b9f..3930713 100644
--- a/src/stdbuf.c
+++ b/src/stdbuf.c
@@ -37,9 +37,6 @@

 #define AUTHORS proper_name_utf8 ("Padraig Brady", "P\303\241draig Brady")

-/* Internal error  */
-enum { EXIT_CANCELED = 125 };
-
 static char *program_path;

 extern char **environ;
diff --git a/src/system.h b/src/system.h
index ce71148..f3e26a8 100644
--- a/src/system.h
+++ b/src/system.h
@@ -107,8 +107,10 @@ you must include <sys/types.h> before including this file
 /* Exit statuses for programs like 'env' that exec other programs.  */
 enum
 {
-  EXIT_CANNOT_INVOKE = 126,
-  EXIT_ENOENT = 127
+  EXIT_TIMEDOUT = 124, /* Time expired before child completed.  */
+  EXIT_CANCELED = 125, /* Internal error prior to exec attempt.  */
+  EXIT_CANNOT_INVOKE = 126, /* Program located, but not usable.  */
+  EXIT_ENOENT = 127 /* Could not find program to exec.  */
 };

 #include "exitfail.h"
diff --git a/src/timeout.c b/src/timeout.c
index 7069f2c..7b0f1d7 100644
--- a/src/timeout.c
+++ b/src/timeout.c
@@ -73,12 +73,6 @@

 #define AUTHORS proper_name_utf8 ("Padraig Brady", "P\303\241draig Brady")

-/* Note ETIMEDOUT is 110 on GNU/Linux systems but this is non standard */
-#define EXIT_TIMEDOUT 124
-
-/* Internal failure.  */
-#define EXIT_CANCELED 125
-
 static int timed_out;
 static int term_signal = SIGTERM;  /* same default as kill command.  */
 static int monitored_pid;
-- 
1.6.4.2


>From 4deeb0f5bf8291d79d53ba7aeb5c1e7811c19c54 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Thu, 8 Oct 2009 09:35:51 -0600
Subject: [PATCH 2/3] maint: remove unused macros and declarations

* src/system.h (EDQUOT, EISDIR, ENOSYS, EOVERFLOW, F_OK, X_OK)
(W_OK, R_OK): Delete; macros provided by gnulib.
(includes): Gnulib guarantees both <time.h> and <sys/time.h>, in
either order.
(free, malloc, memchr, realloc, getenv, lseek): Delete, gnulib
guarantees these declarations.
* m4/check-decl.m4 (gl_CHECK_DECLS): Delete checks now done by
gnulib.
---
 m4/check-decl.m4 |    8 +------
 src/system.h     |   59 +++--------------------------------------------------
 2 files changed, 5 insertions(+), 62 deletions(-)

diff --git a/m4/check-decl.m4 b/m4/check-decl.m4
index d1a520a..530c59e 100644
--- a/m4/check-decl.m4
+++ b/m4/check-decl.m4
@@ -1,4 +1,4 @@
-#serial 24
+#serial 25
 # Check declarations for this package.

 dnl Copyright (C) 1997-2001, 2003-2006, 2008-2009 Free Software
@@ -37,13 +37,7 @@ AC_DEFUN([gl_CHECK_DECLS],

   AC_CHECK_DECLS([isblank], [], [], [#include <ctype.h>])

-  AC_CHECK_DECLS_ONCE([free])
-  AC_CHECK_DECLS_ONCE([getenv])
   AC_CHECK_DECLS_ONCE([geteuid])
   AC_CHECK_DECLS_ONCE([getlogin])
   AC_CHECK_DECLS_ONCE([getuid])
-  AC_CHECK_DECLS_ONCE([lseek])
-  AC_CHECK_DECLS_ONCE([malloc])
-  AC_CHECK_DECLS_ONCE([memchr])
-  AC_CHECK_DECLS_ONCE([realloc])
 ])
diff --git a/src/system.h b/src/system.h
index f3e26a8..8de0f3c 100644
--- a/src/system.h
+++ b/src/system.h
@@ -44,16 +44,8 @@ you must include <sys/types.h> before including this file

 #include "configmake.h"

-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# else
-#  include <time.h>
-# endif
-#endif
+#include <sys/time.h>
+#include <time.h>

 /* Since major is a function on SVR4, we can't use `ifndef major'.  */
 #if MAJOR_IN_MKDEV
@@ -86,16 +78,8 @@ you must include <sys/types.h> before including this file

 #include <errno.h>

-/* Some systems don't define the following symbols.  */
-#ifndef EDQUOT
-# define EDQUOT (-1)
-#endif
-#ifndef EISDIR
-# define EISDIR (-1)
-#endif
-#ifndef ENOSYS
-# define ENOSYS (-1)
-#endif
+/* Some systems don't define this; POSIX mentions it but says it is
+   obsolete, so gnulib does not provide it either.  */
 #ifndef ENODATA
 # define ENODATA (-1)
 #endif
@@ -125,13 +109,6 @@ initialize_exit_failure (int status)

 #include <fcntl.h>

-#ifndef F_OK
-# define F_OK 0
-# define X_OK 1
-# define W_OK 2
-# define R_OK 4
-#endif
-
 #include <dirent.h>
 #ifndef _D_EXACT_NAMLEN
 # define _D_EXACT_NAMLEN(dp) strlen ((dp)->d_name)
@@ -281,30 +258,6 @@ select_plural (uintmax_t n)

 #define STREQ(a, b) (strcmp (a, b) == 0)

-#if !HAVE_DECL_FREE
-void free ();
-#endif
-
-#if !HAVE_DECL_MALLOC
-char *malloc ();
-#endif
-
-#if !HAVE_DECL_MEMCHR
-char *memchr ();
-#endif
-
-#if !HAVE_DECL_REALLOC
-char *realloc ();
-#endif
-
-#if !HAVE_DECL_GETENV
-char *getenv ();
-#endif
-
-#if !HAVE_DECL_LSEEK
-off_t lseek ();
-#endif
-
 #if !HAVE_DECL_GETLOGIN
 char *getlogin ();
 #endif
@@ -549,10 +502,6 @@ enum
   while (0)
 #endif

-#ifndef EOVERFLOW
-# define EOVERFLOW EINVAL
-#endif
-
 #if ! HAVE_SYNC
 # define sync() /* empty */
 #endif
-- 
1.6.4.2


>From 46f5683629e9d361db0427eb4f0ac7eec247b103 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Thu, 8 Oct 2009 08:35:55 -0600
Subject: [PATCH 3/3] maint: use X2NREALLOC in more places

* src/chroot.c (set_additional_groups): Use X2NREALLOC rather than
x2nrealloc.
* src/factor.c (emit_factor): Likewise.
* src/setuidgid.c (main): Likewise.
---
 src/chroot.c    |    2 +-
 src/factor.c    |    2 +-
 src/setuidgid.c |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/chroot.c b/src/chroot.c
index 5e8cb9c..9269f1b 100644
--- a/src/chroot.c
+++ b/src/chroot.c
@@ -91,7 +91,7 @@ set_additional_groups (char const *groups)
         }

       if (n_gids == n_gids_allocated)
-        gids = x2nrealloc (gids, &n_gids_allocated, sizeof *gids);
+        gids = X2NREALLOC (gids, &n_gids_allocated);
       gids[n_gids++] = value;
     }

diff --git a/src/factor.c b/src/factor.c
index f48a720..38c9a11 100644
--- a/src/factor.c
+++ b/src/factor.c
@@ -67,7 +67,7 @@ static void
 emit_factor (mpz_t n)
 {
   if (nfactors_found == nfactors_allocated)
-    factor = x2nrealloc (factor, &nfactors_allocated, sizeof *factor);
+    factor = X2NREALLOC (factor, &nfactors_allocated);
   mpz_init (factor[nfactors_found]);
   mpz_set (factor[nfactors_found], n);
   ++nfactors_found;
diff --git a/src/setuidgid.c b/src/setuidgid.c
index 7176b1a..34be515 100644
--- a/src/setuidgid.c
+++ b/src/setuidgid.c
@@ -110,7 +110,7 @@ main (int argc, char **argv)
                       error (EXIT_FAILURE, 0, _("invalid group %s"),
                              quote (gr));
                     if (n_gids == n_gids_allocated)
-                      gids = x2nrealloc (gids, &n_gids_allocated, sizeof 
*gids);
+                      gids = X2NREALLOC (gids, &n_gids_allocated);
                     gids[n_gids++] = tmp_ul;

                     if (*ptr == '\0')
-- 
1.6.4.2








reply via email to

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