bug-gnulib
[Top][All Lists]
Advanced

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

errno cleanup


From: Eric Blake
Subject: errno cleanup
Date: Wed, 2 Sep 2009 23:23:37 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

I started this patch while working on openat, but it quickly grew into an 
independent patch with broader application.  In particular, it fixes a 
performance bug for anyone using chdir-safer and errno in parallel on mingw 
(where the absence of ELOOP is no longer an accurate indicator of lacking 
symlinks).  I'll be applying this patch soon, to consistently uses the errno 
module (for everything except for the EACCESS snafu in euidaccess.c which is 
copied straight out of glibc).  Since the errno module does not define 
ENAMETOOLONG, I'm assuming that it is universally available; hence why the list 
of lib/*.c files is longer than the list of modules/* edits.

From: Eric Blake <address@hidden>
Date: Wed, 2 Sep 2009 17:06:43 -0600
Subject: [PATCH] errno: use consistently

* lib/c-stack.c (ENOTSUP): <errno.h> guarantees a definition.
* lib/canonicalize-lgpl.c (ENAMETOOLONG): Likewise.
* lib/canonicalize.c (ELOOP): Likewise.
* lib/inet_ntop.c (EAFNOSUPPORT): Likewise.
* lib/inet_pton.c (EAFNOSUPPORT): Likewise.
* lib/lchown.c (EOPNOTSUPP): Likewise.
* lib/openat-priv.h (ENOSYS, EOPNOTSUPP): Likewise.
* lib/savewd.c (ESTALE): Likewise.
* lib/settime.c (ENOSYS): Likewise.
* lib/utimens.c (ENOSYS): Likewise.
* lib/xgethostname.c (ENAMETOOLONG): Likewise.
* lib/chdir-safer.c (ELOOP): Likewise.
(chdir_no_follow): Use HAVE_READLINK, not ELOOP, as witness.
* modules/c-stack (Depends-on): Add errno.
* modules/canonicalize (Depends-on): Likewise.
* modules/chdir-safer (Depends-on): Likewise.
* modules/fdopendir (Depends-on): Likewise.
* modules/inet_ntop (Depends-on): Likewise.
* modules/inet_pton (Depends-on): Likewise.
* modules/lchown (Depends-on): Likewise.
* modules/openat (Depends-on): Likewise.
* modules/savewd (Depends-on): Likewise.
* modules/settime (Depends-on): Likewise.
* m4/chdir-safer.m4 (gl_CHDIR_SAFER): Check for readlink.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog               |   26 ++++++++++++++++++++++++++
 lib/c-stack.c           |    3 ---
 lib/canonicalize-lgpl.c |    5 +----
 lib/canonicalize.c      |    3 ---
 lib/chdir-safer.c       |   10 +++++-----
 lib/inet_ntop.c         |    6 +-----
 lib/inet_pton.c         |    6 +-----
 lib/lchown.c            |   10 ----------
 lib/openat-priv.h       |   22 +---------------------
 lib/savewd.c            |    6 +-----
 lib/settime.c           |   12 +-----------
 lib/utimens.c           |   14 ++------------
 lib/xgethostname.c      |    8 ++------
 m4/chdir-safer.m4       |    5 +++--
 modules/c-stack         |    1 +
 modules/canonicalize    |    1 +
 modules/chdir-safer     |    1 +
 modules/fdopendir       |    3 ++-
 modules/inet_ntop       |    1 +
 modules/inet_pton       |    1 +
 modules/lchown          |    1 +
 modules/openat          |    1 +
 modules/savewd          |    1 +
 modules/settime         |    1 +
 modules/utimens         |    1 +
 25 files changed, 56 insertions(+), 93 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4bb003d..33f1fcc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,31 @@
 2009-09-02  Eric Blake  <address@hidden>

+       errno: use consistently
+       * lib/c-stack.c (ENOTSUP): <errno.h> guarantees a definition.
+       * lib/canonicalize-lgpl.c (ENAMETOOLONG): Likewise.
+       * lib/canonicalize.c (ELOOP): Likewise.
+       * lib/inet_ntop.c (EAFNOSUPPORT): Likewise.
+       * lib/inet_pton.c (EAFNOSUPPORT): Likewise.
+       * lib/lchown.c (EOPNOTSUPP): Likewise.
+       * lib/openat-priv.h (ENOSYS, EOPNOTSUPP): Likewise.
+       * lib/savewd.c (ESTALE): Likewise.
+       * lib/settime.c (ENOSYS): Likewise.
+       * lib/utimens.c (ENOSYS): Likewise.
+       * lib/xgethostname.c (ENAMETOOLONG): Likewise.
+       * lib/chdir-safer.c (ELOOP): Likewise.
+       (chdir_no_follow): Use HAVE_READLINK, not ELOOP, as witness.
+       * modules/c-stack (Depends-on): Add errno.
+       * modules/canonicalize (Depends-on): Likewise.
+       * modules/chdir-safer (Depends-on): Likewise.
+       * modules/fdopendir (Depends-on): Likewise.
+       * modules/inet_ntop (Depends-on): Likewise.
+       * modules/inet_pton (Depends-on): Likewise.
+       * modules/lchown (Depends-on): Likewise.
+       * modules/openat (Depends-on): Likewise.
+       * modules/savewd (Depends-on): Likewise.
+       * modules/settime (Depends-on): Likewise.
+       * m4/chdir-safer.m4 (gl_CHDIR_SAFER): Check for readlink.
+
        gnulib-comp: reduce configure size
        * m4/gnulib-common.m4 (AC_REPLACE_FUNCS): Always override, using
        an idea from autoconf 2.65 while keeping our AC_LIBOBJ overrides.
diff --git a/lib/c-stack.c b/lib/c-stack.c
index d260b47..1dddeef 100644
--- a/lib/c-stack.c
+++ b/lib/c-stack.c
@@ -46,9 +46,6 @@
 #define _(msgid) gettext (msgid)

 #include <errno.h>
-#ifndef ENOTSUP
-# define ENOTSUP EINVAL
-#endif

 #include <signal.h>
 #if ! HAVE_STACK_T && ! defined stack_t
diff --git a/lib/canonicalize-lgpl.c b/lib/canonicalize-lgpl.c
index 3aaa310..6b5663a 100644
--- a/lib/canonicalize-lgpl.c
+++ b/lib/canonicalize-lgpl.c
@@ -1,5 +1,5 @@
 /* Return the canonical absolute name of a given file.
-   Copyright (C) 1996-2003, 2005-2008 Free Software Foundation, Inc.
+   Copyright (C) 1996-2003, 2005-2009 Free Software Foundation, Inc.
    This file is part of the GNU C Library.

    This program is free software: you can redistribute it and/or modify
@@ -50,9 +50,6 @@
 #include <errno.h>
 #ifndef _LIBC
 # define __set_errno(e) errno = (e)
-# ifndef ENAMETOOLONG
-#  define ENAMETOOLONG EINVAL
-# endif
 #endif

 #ifdef _LIBC
diff --git a/lib/canonicalize.c b/lib/canonicalize.c
index 3744654..523e082 100644
--- a/lib/canonicalize.c
+++ b/lib/canonicalize.c
@@ -38,9 +38,6 @@
 #include "xalloc.h"
 #include "xgetcwd.h"

-#ifndef ELOOP
-# define ELOOP 0
-#endif
 #ifndef __set_errno
 # define __set_errno(Val) errno = (Val)
 #endif
diff --git a/lib/chdir-safer.c b/lib/chdir-safer.c
index 03f3720..a6f77b0 100644
--- a/lib/chdir-safer.c
+++ b/lib/chdir-safer.c
@@ -1,6 +1,6 @@
 /* much like chdir(2), but safer

-   Copyright (C) 2005-2006, 2008 Free Software Foundation, Inc.
+   Copyright (C) 2005-2006, 2008-2009 Free Software Foundation, Inc.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -29,8 +29,8 @@
 #include <sys/stat.h>
 #include "same-inode.h"

-#ifndef ELOOP
-# define ELOOP 0
+#ifndef HAVE_READLINK
+# define HAVE_READLINK 0
 #endif

 /* Like chdir, but fail if DIR is a symbolic link to a directory (or
@@ -51,9 +51,9 @@ chdir_no_follow (char const *dir)
      they are the same file; if they are different files, set errno to
      ELOOP (the same value that open uses for symlinks with
      O_NOFOLLOW) so the caller can report a failure.
-     Skip this check if ELOOP == 0, which should be the case
+     Skip this check if HAVE_READLINK == 0, which should be the case
      on any system that lacks symlink support.  */
-  if (ELOOP && ! HAVE_WORKING_O_NOFOLLOW)
+  if (HAVE_READLINK && ! HAVE_WORKING_O_NOFOLLOW)
     {
       struct stat sb1;
       result = lstat (dir, &sb1);
diff --git a/lib/inet_ntop.c b/lib/inet_ntop.c
index 16eb109..033847a 100644
--- a/lib/inet_ntop.c
+++ b/lib/inet_ntop.c
@@ -1,6 +1,6 @@
 /* inet_ntop.c -- convert IPv4 and IPv6 addresses from binary to text form

-   Copyright (C) 2005, 2006, 2008  Free Software Foundation, Inc.
+   Copyright (C) 2005, 2006, 2008, 2009  Free Software Foundation, Inc.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -42,10 +42,6 @@
 #include <string.h>
 #include <errno.h>

-#ifndef EAFNOSUPPORT
-# define EAFNOSUPPORT EINVAL
-#endif
-
 #define NS_IN6ADDRSZ 16
 #define NS_INT16SZ 2

diff --git a/lib/inet_pton.c b/lib/inet_pton.c
index 62ef145..a9c9baf 100644
--- a/lib/inet_pton.c
+++ b/lib/inet_pton.c
@@ -1,6 +1,6 @@
 /* inet_pton.c -- convert IPv4 and IPv6 addresses from text to binary form

-   Copyright (C) 2006, 2008 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2008, 2009 Free Software Foundation, Inc.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -41,10 +41,6 @@
 #include <string.h>
 #include <errno.h>

-#ifndef EAFNOSUPPORT
-# define EAFNOSUPPORT EINVAL
-#endif
-
 #define NS_INADDRSZ 4
 #define NS_IN6ADDRSZ 16
 #define NS_INT16SZ 2
diff --git a/lib/lchown.c b/lib/lchown.c
index 5bc7074..10ba1c9 100644
--- a/lib/lchown.c
+++ b/lib/lchown.c
@@ -30,16 +30,6 @@
 #include <errno.h>
 #include <sys/stat.h>

-/* Some systems don't have EOPNOTSUPP.  */
-#ifndef EOPNOTSUPP
-# ifdef ENOTSUP
-#  define EOPNOTSUPP ENOTSUP
-# else
-/* Some systems don't have ENOTSUP either.  */
-#  define EOPNOTSUPP EINVAL
-# endif
-#endif
-
 /* Work just like chown, except when FILE is a symbolic link.
    In that case, set errno to EOPNOTSUPP and return -1.
    But if autoconf tests determined that chown modifies
diff --git a/lib/openat-priv.h b/lib/openat-priv.h
index 9254f6b..2280416 100644
--- a/lib/openat-priv.h
+++ b/lib/openat-priv.h
@@ -1,6 +1,6 @@
 /* Internals for openat-like functions.

-   Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+   Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -23,26 +23,6 @@
 #define OPENAT_BUFFER_SIZE 512
 char *openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const 
*file);

-/* Some systems don't have ENOSYS.  */
-#ifndef ENOSYS
-# ifdef ENOTSUP
-#  define ENOSYS ENOTSUP
-# else
-/* Some systems don't have ENOTSUP either.  */
-#  define ENOSYS EINVAL
-# endif
-#endif
-
-/* Some systems don't have EOPNOTSUPP.  */
-#ifndef EOPNOTSUPP
-# ifdef ENOTSUP
-#  define EOPNOTSUPP ENOTSUP
-# else
-/* Some systems don't have ENOTSUP either.  */
-#  define EOPNOTSUPP EINVAL
-# endif
-#endif
-
 /* Trying to access a BUILD_PROC_NAME file will fail on systems without
    /proc support, and even on systems *with* ProcFS support.  Return
    nonzero if the failure may be legitimate, e.g., because /proc is not
diff --git a/lib/savewd.c b/lib/savewd.c
index c4893ef..f593f94 100644
--- a/lib/savewd.c
+++ b/lib/savewd.c
@@ -1,6 +1,6 @@
 /* Save and restore the working directory, possibly using a child process.

-   Copyright (C) 2006, 2007 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2007, 2009 Free Software Foundation, Inc.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -34,10 +34,6 @@
 #include "dirname.h"
 #include "fcntl-safer.h"

-#ifndef ESTALE
-# define ESTALE -1
-#endif
-
 /* Save the working directory into *WD, if it hasn't been saved
    already.  Return true if a child has been forked to do the real
    work.  */
diff --git a/lib/settime.c b/lib/settime.c
index f565492..366a298 100644
--- a/lib/settime.c
+++ b/lib/settime.c
@@ -1,6 +1,6 @@
 /* settime -- set the system clock

-   Copyright (C) 2002, 2004, 2005, 2006, 2007 Free Software
+   Copyright (C) 2002, 2004, 2005, 2006, 2007, 2009 Free Software
    Foundation, Inc.

    This program is free software: you can redistribute it and/or modify
@@ -27,16 +27,6 @@

 #include <errno.h>

-/* Some systems don't have ENOSYS.  */
-#ifndef ENOSYS
-# ifdef ENOTSUP
-#  define ENOSYS ENOTSUP
-# else
-/* Some systems don't have ENOTSUP either.  */
-#  define ENOSYS EINVAL
-# endif
-#endif
-
 /* Set the system time.  */

 int
diff --git a/lib/utimens.c b/lib/utimens.c
index 708de10..f7bc75e 100644
--- a/lib/utimens.c
+++ b/lib/utimens.c
@@ -1,7 +1,7 @@
 /* Set file access and modification times.

-   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Free Software
-   Foundation, Inc.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free
+   Software Foundation, Inc.

    This program is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
@@ -44,16 +44,6 @@ struct utimbuf
 };
 #endif

-/* Some systems don't have ENOSYS.  */
-#ifndef ENOSYS
-# ifdef ENOTSUP
-#  define ENOSYS ENOTSUP
-# else
-/* Some systems don't have ENOTSUP either.  */
-#  define ENOSYS EINVAL
-# endif
-#endif
-
 #ifndef __attribute__
 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)
 #  define __attribute__(x)
diff --git a/lib/xgethostname.c b/lib/xgethostname.c
index 875d497..d649b8d 100644
--- a/lib/xgethostname.c
+++ b/lib/xgethostname.c
@@ -1,7 +1,7 @@
 /* xgethostname.c -- return current hostname with unlimited length

-   Copyright (C) 1992, 1996, 2000, 2001, 2003, 2004, 2005, 2006 Free
-   Software Foundation, Inc.
+   Copyright (C) 1992, 1996, 2000, 2001, 2003, 2004, 2005, 2006, 2009
+   Free Software Foundation, Inc.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -29,10 +29,6 @@

 #include "xalloc.h"

-#ifndef ENAMETOOLONG
-# define ENAMETOOLONG 0
-#endif
-
 #ifndef INITIAL_HOSTNAME_LENGTH
 # define INITIAL_HOSTNAME_LENGTH 34
 #endif
diff --git a/m4/chdir-safer.m4 b/m4/chdir-safer.m4
index 22ad506..d6e741d 100644
--- a/m4/chdir-safer.m4
+++ b/m4/chdir-safer.m4
@@ -1,5 +1,5 @@
-#serial 3
-dnl Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+#serial 4
+dnl Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -7,4 +7,5 @@ dnl with or without modifications, as long as this notice is 
preserved.
 AC_DEFUN([gl_CHDIR_SAFER],
 [
   AC_LIBOBJ([chdir-safer])
+  AC_CHECK_FUNCS_ONCE([readlink])
 ])
diff --git a/modules/c-stack b/modules/c-stack
index 6a589c3..22dd18c 100644
--- a/modules/c-stack
+++ b/modules/c-stack
@@ -8,6 +8,7 @@ m4/c-stack.m4

 Depends-on:
 gettext-h
+errno
 exitfail
 unistd
 raise
diff --git a/modules/canonicalize b/modules/canonicalize
index 23baa75..e24be3d 100644
--- a/modules/canonicalize
+++ b/modules/canonicalize
@@ -9,6 +9,7 @@ m4/canonicalize.m4

 Depends-on:
 areadlink-with-size
+errno
 file-set
 filenamecat
 hash-triple
diff --git a/modules/chdir-safer b/modules/chdir-safer
index b3b47e1..39cfdc7 100644
--- a/modules/chdir-safer
+++ b/modules/chdir-safer
@@ -7,6 +7,7 @@ lib/chdir-safer.c
 m4/chdir-safer.m4

 Depends-on:
+errno
 fchdir
 fcntl-h
 open
diff --git a/modules/fdopendir b/modules/fdopendir
index 7a90aa3..83c2af7 100644
--- a/modules/fdopendir
+++ b/modules/fdopendir
@@ -8,8 +8,9 @@ lib/openat-proc.c
 m4/fdopendir.m4

 Depends-on:
-extensions
 dirent
+errno
+extensions
 fchdir
 openat-die
 save-cwd
diff --git a/modules/inet_ntop b/modules/inet_ntop
index 98df38e..76ff39d 100644
--- a/modules/inet_ntop
+++ b/modules/inet_ntop
@@ -9,6 +9,7 @@ Depends-on:
 socklen
 sys_socket
 arpa_inet
+errno
 netinet_in
 extensions

diff --git a/modules/inet_pton b/modules/inet_pton
index 173710a..314bf0f 100644
--- a/modules/inet_pton
+++ b/modules/inet_pton
@@ -10,6 +10,7 @@ c-ctype
 socklen
 sys_socket
 arpa_inet
+errno
 netinet_in
 extensions

diff --git a/modules/lchown b/modules/lchown
index e011e2b..65c084c 100644
--- a/modules/lchown
+++ b/modules/lchown
@@ -7,6 +7,7 @@ m4/lchown.m4

 Depends-on:
 chown
+errno
 sys_stat
 unistd

diff --git a/modules/openat b/modules/openat
index 5c326a0..3ea5b4d 100644
--- a/modules/openat
+++ b/modules/openat
@@ -16,6 +16,7 @@ m4/mode_t.m4

 Depends-on:
 dirname
+errno
 extensions
 fchdir
 fdopendir
diff --git a/modules/savewd b/modules/savewd
index 360d4b9..6d655c1 100644
--- a/modules/savewd
+++ b/modules/savewd
@@ -8,6 +8,7 @@ m4/savewd.m4

 Depends-on:
 dirname
+errno
 exit
 fchdir
 fcntl-safer
diff --git a/modules/settime b/modules/settime
index 9ca84a0..f88318e 100644
--- a/modules/settime
+++ b/modules/settime
@@ -7,6 +7,7 @@ m4/settime.m4

 Depends-on:
 clock-time
+errno
 extensions
 sys_time
 timespec
diff --git a/modules/utimens b/modules/utimens
index caf8805..4251485 100644
--- a/modules/utimens
+++ b/modules/utimens
@@ -9,6 +9,7 @@ m4/utimens.m4
 m4/utimes.m4

 Depends-on:
+errno
 sys_time
 time

-- 
1.6.3.2







reply via email to

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