]> sourceware.org Git - glibc.git/commitdiff
* libio/fileops.c (_IO_new_file_fopen): Recognize 'e' flag and set
authorUlrich Drepper <drepper@redhat.com>
Sun, 22 Jul 2007 18:38:37 +0000 (18:38 +0000)
committerUlrich Drepper <drepper@redhat.com>
Sun, 22 Jul 2007 18:38:37 +0000 (18:38 +0000)
O_CLOEXEC is needed.
* nis/nss_compat/compat-grp.c: Use 'e' flag when opening file.
Avoid additional fcntl to set O_CLOEXEC if not needed.
* nis/nss_compat/compat-initgroups.c: Likewise.
* nis/nss_compat/compat-pwd.c: Likewise.
* nis/nss_compat/compat-spwd.c: Likewise.

ChangeLog
nis/nss_compat/compat-grp.c
nis/nss_compat/compat-initgroups.c
nis/nss_compat/compat-pwd.c
nis/nss_compat/compat-spwd.c

index ff16e51b56dfcb81ed650d43e30759ec23ff74b6..b7ee4566968e7f68f6da7a3e77827d1ff8db1add 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2007-07-22  Ulrich Drepper  <drepper@redhat.com>
+
+       * libio/fileops.c (_IO_new_file_fopen): Recognize 'e' flag and set
+       O_CLOEXEC is needed.
+       * nis/nss_compat/compat-grp.c: Use 'e' flag when opening file.
+       Avoid additional fcntl to set O_CLOEXEC if not needed.
+       * nis/nss_compat/compat-initgroups.c: Likewise.
+       * nis/nss_compat/compat-pwd.c: Likewise.
+       * nis/nss_compat/compat-spwd.c: Likewise.
+
 2007-07-21  Samuel Thibault  <samuel.thibault@ens-lyon.org>
 
        * manual/errno.texi: Change ECANCELED value to 119.
index 236c84a20fb9bd68bcf4b7abec8a36865b7600ac..939102868c591ab5a27d762ba742ada721bb2e68 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-1999,2001-2005,2006 Free Software Foundation, Inc.
+/* Copyright (C) 1996-1999, 2001-2006, 2007 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
 
@@ -27,6 +27,7 @@
 #include <string.h>
 #include <rpc/types.h>
 #include <bits/libc-lock.h>
+#include <kernel-features.h>
 
 static service_user *ni;
 static enum nss_status (*nss_setgrent) (int stayopen);
@@ -70,6 +71,19 @@ static ent_t ext_ent = { TRUE, NSS_STATUS_SUCCESS, NULL, { NULL, 0, 0 }};
 /* Protect global state against multiple changers.  */
 __libc_lock_define_initialized (static, lock)
 
+/* Positive if O_CLOEXEC is supported, negative if it is not supported,
+   zero if it is still undecided.  This variable is shared with the
+   other compat functions.  */
+#ifdef __ASSUME_O_CLOEXEC
+# define __compat_have_cloexec 1
+#else
+# ifdef O_CLOEXEC
+int __compat_have_cloexec;
+# else
+#  define __compat_have_cloexec -1
+# endif
+#endif
+
 /* Prototypes for local functions.  */
 static void blacklist_store_name (const char *, ent_t *);
 static int in_blacklist (const char *, int, ent_t *);
@@ -107,21 +121,36 @@ internal_setgrent (ent_t *ent, int stayopen, int needent)
 
   if (ent->stream == NULL)
     {
-      ent->stream = fopen ("/etc/group", "rm");
+      ent->stream = fopen ("/etc/group", "rme");
 
       if (ent->stream == NULL)
        status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
       else
        {
          /* We have to make sure the file is  `closed on exec'.  */
-         int result, flags;
+         int result = 0;
 
-         result = flags = fcntl (fileno_unlocked (ent->stream), F_GETFD, 0);
-         if (result >= 0)
+         if (__compat_have_cloexec <= 0)
            {
-             flags |= FD_CLOEXEC;
-             result = fcntl (fileno_unlocked (ent->stream), F_SETFD, flags);
+             int flags;
+             result = flags = fcntl (fileno_unlocked (ent->stream), F_GETFD,
+                                     0);
+             if (result >= 0)
+               {
+#if defined O_CLOEXEC && !defined __ASSUME_O_CLOEXEC
+                 if (__compat_have_cloexec == 0)
+                   __compat_have_cloexec = (flags & FD_CLOEXEC) ? 1 : -1;
+
+                 if (__compat_have_cloexec < 0)
+#endif
+                   {
+                     flags |= FD_CLOEXEC;
+                     result = fcntl (fileno_unlocked (ent->stream), F_SETFD,
+                                     flags);
+                   }
+               }
            }
+
          if (result < 0)
            {
              /* Something went wrong.  Close the stream and return a
index 70403a0785edf711108a8c6e1a3b0141db1140e9..fd16475ea9642374b08b7aa4a43ef167e213398b 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998-2003, 2004, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1998-2004, 2006, 2007 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
 
@@ -30,6 +30,7 @@
 #include <sys/param.h>
 #include <nsswitch.h>
 #include <bits/libc-lock.h>
+#include <kernel-features.h>
 
 static service_user *ni;
 /* Type of the lookup function.  */
@@ -74,6 +75,19 @@ struct ent_t
 typedef struct ent_t ent_t;
 
 
+/* Positive if O_CLOEXEC is supported, negative if it is not supported,
+   zero if it is still undecided.  This variable is shared with the
+   other compat functions.  */
+#ifdef __ASSUME_O_CLOEXEC
+# define __compat_have_cloexec 1
+#else
+# ifdef O_CLOEXEC
+extern int __compat_have_cloexec;
+# else
+#  define __compat_have_cloexec -1
+# endif
+#endif
+
 /* Prototypes for local functions.  */
 static void blacklist_store_name (const char *, ent_t *);
 static int in_blacklist (const char *, int, ent_t *);
@@ -117,21 +131,35 @@ internal_setgrent (ent_t *ent)
   else
     ent->blacklist.current = 0;
 
-  ent->stream = fopen ("/etc/group", "rm");
+  ent->stream = fopen ("/etc/group", "rme");
 
   if (ent->stream == NULL)
     status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
   else
     {
       /* We have to make sure the file is  `closed on exec'.  */
-      int result, flags;
+      int result = 0;
 
-      result = flags = fcntl (fileno_unlocked (ent->stream), F_GETFD, 0);
-      if (result >= 0)
+      if (__compat_have_cloexec <= 0)
        {
-         flags |= FD_CLOEXEC;
-         result = fcntl (fileno_unlocked (ent->stream), F_SETFD, flags);
+         int flags;
+         result = flags = fcntl (fileno_unlocked (ent->stream), F_GETFD, 0);
+         if (result >= 0)
+           {
+#if defined O_CLOEXEC && !defined __ASSUME_O_CLOEXEC
+             if (__compat_have_cloexec == 0)
+               __compat_have_cloexec = (flags & FD_CLOEXEC) ? 1 : -1;
+
+             if (__compat_have_cloexec < 0)
+#endif
+               {
+                 flags |= FD_CLOEXEC;
+                 result = fcntl (fileno_unlocked (ent->stream), F_SETFD,
+                                 flags);
+               }
+           }
        }
+
       if (result < 0)
        {
          /* Something went wrong.  Close the stream and return a
index ac132046dae9e2ef63da1d1a3ed630c816ee31fa..df8f91eea01195986887b7f281139be3cc98f5b6 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-1999,2001-2005,2006 Free Software Foundation, Inc.
+/* Copyright (C) 1996-1999, 2001-2006, 2007 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
 
@@ -29,6 +29,7 @@
 #include <rpc/types.h>
 #include <rpcsvc/ypclnt.h>
 #include <bits/libc-lock.h>
+#include <kernel-features.h>
 
 #include "netgroup.h"
 
@@ -80,6 +81,19 @@ static ent_t ext_ent = { false, false, true, NSS_STATUS_SUCCESS, NULL,
 /* Protect global state against multiple changers.  */
 __libc_lock_define_initialized (static, lock)
 
+/* Positive if O_CLOEXEC is supported, negative if it is not supported,
+   zero if it is still undecided.  This variable is shared with the
+   other compat functions.  */
+#ifdef __ASSUME_O_CLOEXEC
+# define __compat_have_cloexec 1
+#else
+# ifdef O_CLOEXEC
+extern int __compat_have_cloexec;
+# else
+#  define __compat_have_cloexec -1
+# endif
+#endif
+
 /* Prototypes for local functions.  */
 static void blacklist_store_name (const char *, ent_t *);
 static int in_blacklist (const char *, int, ent_t *);
@@ -227,21 +241,36 @@ internal_setpwent (ent_t *ent, int stayopen, int needent)
 
   if (ent->stream == NULL)
     {
-      ent->stream = fopen ("/etc/passwd", "rm");
+      ent->stream = fopen ("/etc/passwd", "rme");
 
       if (ent->stream == NULL)
        status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
       else
        {
          /* We have to make sure the file is  `closed on exec'.  */
-         int result, flags;
+         int result = 0;
 
-         result = flags = fcntl (fileno_unlocked (ent->stream), F_GETFD, 0);
-         if (result >= 0)
+         if (__compat_have_cloexec <= 0)
            {
-             flags |= FD_CLOEXEC;
-             result = fcntl (fileno_unlocked (ent->stream), F_SETFD, flags);
+             int flags;
+             result = flags = fcntl (fileno_unlocked (ent->stream), F_GETFD,
+                                     0);
+             if (result >= 0)
+               {
+#if defined O_CLOEXEC && !defined __ASSUME_O_CLOEXEC
+                 if (__compat_have_cloexec == 0)
+                   __compat_have_cloexec = (flags & FD_CLOEXEC) ? 1 : -1;
+
+                 if (__compat_have_cloexec < 0)
+#endif
+                   {
+                     flags |= FD_CLOEXEC;
+                     result = fcntl (fileno_unlocked (ent->stream), F_SETFD,
+                                     flags);
+                   }
+               }
            }
+
          if (result < 0)
            {
              /* Something went wrong.  Close the stream and return a
index d1de3f75b0685b4bebf03ff4949013b18851f234..a5977681f25b514c21668ac62a14f6a9f8274ecd 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-1999,2001-2005,2006 Free Software Foundation, Inc.
+/* Copyright (C) 1996-1999, 2001-2006, 2007 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
 
@@ -29,6 +29,7 @@
 #include <rpc/types.h>
 #include <rpcsvc/ypclnt.h>
 #include <bits/libc-lock.h>
+#include <kernel-features.h>
 
 #include "netgroup.h"
 
@@ -77,6 +78,19 @@ static ent_t ext_ent = { false, true, false, NSS_STATUS_SUCCESS, NULL,
 /* Protect global state against multiple changers.  */
 __libc_lock_define_initialized (static, lock)
 
+/* Positive if O_CLOEXEC is supported, negative if it is not supported,
+   zero if it is still undecided.  This variable is shared with the
+   other compat functions.  */
+#ifdef __ASSUME_O_CLOEXEC
+# define __compat_have_cloexec 1
+#else
+# ifdef O_CLOEXEC
+extern int __compat_have_cloexec;
+# else
+#  define __compat_have_cloexec -1
+# endif
+#endif
+
 /* Prototypes for local functions.  */
 static void blacklist_store_name (const char *, ent_t *);
 static int in_blacklist (const char *, int, ent_t *);
@@ -180,21 +194,36 @@ internal_setspent (ent_t *ent, int stayopen)
 
   if (ent->stream == NULL)
     {
-      ent->stream = fopen ("/etc/shadow", "rm");
+      ent->stream = fopen ("/etc/shadow", "rme");
 
       if (ent->stream == NULL)
        status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
       else
        {
          /* We have to make sure the file is  `closed on exec'.  */
-         int result, flags;
+         int result = 0;
 
-         result = flags = fcntl (fileno_unlocked (ent->stream), F_GETFD, 0);
-         if (result >= 0)
+         if (__compat_have_cloexec <= 0)
            {
-             flags |= FD_CLOEXEC;
-             result = fcntl (fileno_unlocked (ent->stream), F_SETFD, flags);
+             int flags;
+             result = flags = fcntl (fileno_unlocked (ent->stream), F_GETFD,
+                                     0);
+             if (result >= 0)
+               {
+#if defined O_CLOEXEC && !defined __ASSUME_O_CLOEXEC
+                 if (__compat_have_cloexec == 0)
+                   __compat_have_cloexec = (flags & FD_CLOEXEC) ? 1 : -1;
+
+                 if (__compat_have_cloexec < 0)
+#endif
+                   {
+                     flags |= FD_CLOEXEC;
+                     result = fcntl (fileno_unlocked (ent->stream), F_SETFD,
+                                     flags);
+                   }
+               }
            }
+
          if (result < 0)
            {
              /* Something went wrong.  Close the stream and return a
This page took 0.053936 seconds and 5 git commands to generate.