This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Assume that O_CLOEXEC is always defined and works


Nice cleanup, LGTM with some remarks below.

On 13/04/2017 17:25, Florian Weimer wrote:
> diff --git a/libio/iopopen.c b/libio/iopopen.c
> index 5887bd1..6f3a7b8 100644
> --- a/libio/iopopen.c
> +++ b/libio/iopopen.c
> @@ -140,13 +140,11 @@ _IO_new_proc_open (_IO_FILE *fp, const char *command, const char *mode)
>    if (_IO_file_is_open (fp))
>      return NULL;
>  
> -#ifdef O_CLOEXEC
> -    {
> -      int r = __pipe2 (pipe_fds, O_CLOEXEC);
> -	if (r < 0)
> -	  return NULL;
> -    }
> -#endif
> +  {
> +    int r = __pipe2 (pipe_fds, O_CLOEXEC);
> +    if (r < 0)
> +      return NULL;
> +  }

Just remove the brackets.

>  
>    if (do_read)
>      {
> @@ -169,12 +167,10 @@ _IO_new_proc_open (_IO_FILE *fp, const char *command, const char *mode)
>  
>        if (child_end != child_std_end)
>  	_IO_dup2 (child_end, child_std_end);
> -#ifdef O_CLOEXEC
>        else
>  	/* The descriptor is already the one we will use.  But it must
>  	   not be marked close-on-exec.  Undo the effects.  */
>  	__fcntl (child_end, F_SETFD, 0);
> -#endif
>        /* POSIX.2:  "popen() shall ensure that any streams from previous
>           popen() calls that remain open in the parent process are closed
>  	 in the new child process." */
> @@ -200,11 +196,9 @@ _IO_new_proc_open (_IO_FILE *fp, const char *command, const char *mode)
>      }
>  
>    if (!do_cloexec)
> -#ifdef O_CLOEXEC
>      /* Undo the effects of the pipe2 call which set the
>         close-on-exec flag.  */
>      __fcntl (parent_end, F_SETFD, 0);
> -#endif

Why can't we issue the __pipe2 as '__pipe2 (pipe_fds, do_cloexec ? O_CLOEXEC : 0)'
and get rid of this logic here?

>  
>    _IO_fileno (fp) = parent_end;
>  
> diff --git a/login/utmp_file.c b/login/utmp_file.c
> index b1dfb3f..6ebe1ef 100644
> --- a/login/utmp_file.c
> +++ b/login/utmp_file.c
> @@ -141,42 +141,11 @@ setutent_file (void)
>  
>        file_name = TRANSFORM_UTMP_FILE_NAME (__libc_utmp_file_name);
>  
> -#ifdef O_CLOEXEC
> -# define O_flags O_LARGEFILE | O_CLOEXEC
> -#else
> -# define O_flags O_LARGEFILE
> -#endif
>        file_writable = false;
> -      file_fd = open_not_cancel_2 (file_name, O_RDONLY | O_flags);
> +      file_fd = open_not_cancel_2
> +	(file_name, O_RDONLY | O_LARGEFILE | O_CLOEXEC);
>        if (file_fd == -1)
>  	return 0;
> -
> -#ifndef __ASSUME_O_CLOEXEC
> -# ifdef O_CLOEXEC
> -      if (__have_o_cloexec <= 0)
> -# endif
> -	{
> -	  /* We have to make sure the file is `closed on exec'.  */
> -	  int result = fcntl_not_cancel (file_fd, F_GETFD, 0);
> -	  if (result >= 0)
> -	    {
> -# ifdef O_CLOEXEC
> -	      if (__have_o_cloexec == 0)
> -		__have_o_cloexec = (result & FD_CLOEXEC) ? 1 : -1;
> -
> -	      if (__have_o_cloexec < 0)
> -# endif
> -		result = fcntl_not_cancel (file_fd, F_SETFD,
> -					   result | FD_CLOEXEC);
> -	    }
> -
> -	  if (result == -1)
> -	    {
> -	      close_not_cancel_no_status (file_fd);
> -	      return 0;
> -	    }
> -	}
> -#endif
>      }
>  
>    __lseek64 (file_fd, 0, SEEK_SET);
> @@ -404,37 +373,11 @@ pututline_file (const struct utmp *data)
>        /* We must make the file descriptor writable before going on.  */
>        const char *file_name = TRANSFORM_UTMP_FILE_NAME (__libc_utmp_file_name);
>  
> -      int new_fd = open_not_cancel_2 (file_name, O_RDWR | O_flags);
> +      int new_fd = open_not_cancel_2
> +	(file_name, O_RDWR | O_LARGEFILE | O_CLOEXEC);
>        if (new_fd == -1)
>  	return NULL;
>  
> -#ifndef __ASSUME_O_CLOEXEC
> -# ifdef O_CLOEXEC
> -      if (__have_o_cloexec <= 0)
> -# endif
> -	{
> -	  /* We have to make sure the file is `closed on exec'.  */
> -	  int result = fcntl_not_cancel (file_fd, F_GETFD, 0);
> -	  if (result >= 0)
> -	    {
> -# ifdef O_CLOEXEC
> -	      if (__have_o_cloexec == 0)
> -		__have_o_cloexec = (result & FD_CLOEXEC) ? 1 : -1;
> -
> -	      if (__have_o_cloexec < 0)
> -# endif
> -		result = fcntl_not_cancel (file_fd, F_SETFD,
> -					   result | FD_CLOEXEC);
> -	    }
> -
> -	  if (result == -1)
> -	    {
> -	      close_not_cancel_no_status (file_fd);
> -	      return NULL;
> -	    }
> -	}
> -#endif
> -
>        if (__lseek64 (new_fd, __lseek64 (file_fd, 0, SEEK_CUR), SEEK_SET) == -1
>  	  || __dup2 (new_fd, file_fd) < 0)
>  	{
> diff --git a/malloc/mtrace.c b/malloc/mtrace.c
> index 800f2a8..02c53eb 100644
> --- a/malloc/mtrace.c
> +++ b/malloc/mtrace.c
> @@ -300,15 +300,6 @@ mtrace (void)
>        mallstream = fopen (mallfile != NULL ? mallfile : "/dev/null", "wce");
>        if (mallstream != NULL)
>          {
> -#ifndef __ASSUME_O_CLOEXEC
> -          /* Make sure we close the file descriptor on exec.  */
> -          int flags = __fcntl (fileno (mallstream), F_GETFD, 0);
> -          if (flags >= 0)
> -            {
> -              flags |= FD_CLOEXEC;
> -              __fcntl (fileno (mallstream), F_SETFD, flags);
> -            }
> -#endif
>            /* Be sure it doesn't malloc its buffer!  */
>            malloc_trace_buffer = mtb;
>            setvbuf (mallstream, malloc_trace_buffer, _IOFBF, TRACE_BUFFER_SIZE);
> diff --git a/nis/nss_compat/compat-grp.c b/nis/nss_compat/compat-grp.c
> index e830a2f..0381458 100644
> --- a/nis/nss_compat/compat-grp.c
> +++ b/nis/nss_compat/compat-grp.c
> @@ -70,19 +70,6 @@ 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 *);
> @@ -125,43 +112,8 @@ internal_setgrent (ent_t *ent, int stayopen, int needent)
>        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 = 0;
> -
> -	  if (__compat_have_cloexec <= 0)
> -	    {
> -	      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
> -	         failure.  */
> -	      fclose (ent->stream);
> -	      ent->stream = NULL;
> -	      status = NSS_STATUS_UNAVAIL;
> -	    }
> -	  else
> -	    /* We take care of locking ourself.  */
> -	    __fsetlocking (ent->stream, FSETLOCKING_BYCALLER);
> -	}
> +	/* We take care of locking ourself.  */
> +	__fsetlocking (ent->stream, FSETLOCKING_BYCALLER);
>      }
>    else
>      rewind (ent->stream);
> diff --git a/nis/nss_compat/compat-initgroups.c b/nis/nss_compat/compat-initgroups.c
> index 1b37e0c..7952134 100644
> --- a/nis/nss_compat/compat-initgroups.c
> +++ b/nis/nss_compat/compat-initgroups.c
> @@ -77,20 +77,6 @@ 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 *);
> @@ -141,42 +127,8 @@ internal_setgrent (ent_t *ent)
>    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 = 0;
> -
> -      if (__compat_have_cloexec <= 0)
> -	{
> -	  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
> -	     failure.  */
> -	  fclose (ent->stream);
> -	  ent->stream = NULL;
> -	  status = NSS_STATUS_UNAVAIL;
> -	}
> -      else
> -	/* We take care of locking ourself.  */
> -	__fsetlocking (ent->stream, FSETLOCKING_BYCALLER);
> -    }
> +    /* We take care of locking ourself.  */
> +    __fsetlocking (ent->stream, FSETLOCKING_BYCALLER);
>  
>    return status;
>  }
> diff --git a/nis/nss_compat/compat-pwd.c b/nis/nss_compat/compat-pwd.c
> index 28ae7fb..0583a10 100644
> --- a/nis/nss_compat/compat-pwd.c
> +++ b/nis/nss_compat/compat-pwd.c
> @@ -80,19 +80,6 @@ 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 *);
> @@ -240,43 +227,8 @@ internal_setpwent (ent_t *ent, int stayopen, int needent)
>        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 = 0;
> -
> -	  if (__compat_have_cloexec <= 0)
> -	    {
> -	      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
> -	         failure.  */
> -	      fclose (ent->stream);
> -	      ent->stream = NULL;
> -	      status = NSS_STATUS_UNAVAIL;
> -	    }
> -	  else
> -	    /* We take care of locking ourself.  */
> -	    __fsetlocking (ent->stream, FSETLOCKING_BYCALLER);
> -	}
> +	/* We take care of locking ourself.  */
> +	__fsetlocking (ent->stream, FSETLOCKING_BYCALLER);
>      }
>    else
>      rewind (ent->stream);
> diff --git a/nis/nss_compat/compat-spwd.c b/nis/nss_compat/compat-spwd.c
> index 550444c..eec3af3 100644
> --- a/nis/nss_compat/compat-spwd.c
> +++ b/nis/nss_compat/compat-spwd.c
> @@ -77,19 +77,6 @@ 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 *);
> @@ -196,43 +183,8 @@ internal_setspent (ent_t *ent, int stayopen, int needent)
>        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 = 0;
> -
> -	  if (__compat_have_cloexec <= 0)
> -	    {
> -	      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
> -	         failure.  */
> -	      fclose (ent->stream);
> -	      ent->stream = NULL;
> -	      status = NSS_STATUS_UNAVAIL;
> -	    }
> -	  else
> -	    /* We take care of locking ourself.  */
> -	    __fsetlocking (ent->stream, FSETLOCKING_BYCALLER);
> -	}
> +	/* We take care of locking ourself.  */
> +	__fsetlocking (ent->stream, FSETLOCKING_BYCALLER);
>      }
>    else
>      rewind (ent->stream);
> diff --git a/nscd/connections.c b/nscd/connections.c
> index 205ff42..a5ca57a 100644
> --- a/nscd/connections.c
> +++ b/nscd/connections.c
> @@ -499,13 +499,6 @@ fail:
>  }
>  
>  
> -#ifdef O_CLOEXEC
> -# define EXTRA_O_FLAGS O_CLOEXEC
> -#else
> -# define EXTRA_O_FLAGS 0
> -#endif
> -
> -
>  /* Initialize database information structures.  */
>  void
>  nscd_init (void)
> @@ -528,7 +521,7 @@ nscd_init (void)
>  	if (dbs[cnt].persistent)
>  	  {
>  	    /* Try to open the appropriate file on disk.  */
> -	    int fd = open (dbs[cnt].db_filename, O_RDWR | EXTRA_O_FLAGS);
> +	    int fd = open (dbs[cnt].db_filename, O_RDWR | O_CLOEXEC);
>  	    if (fd != -1)
>  	      {
>  		char *msg = NULL;
> @@ -608,7 +601,7 @@ nscd_init (void)
>  		    if (dbs[cnt].shared)
>  		      {
>  			dbs[cnt].ro_fd = open (dbs[cnt].db_filename,
> -					       O_RDONLY | EXTRA_O_FLAGS);
> +					       O_RDONLY | O_CLOEXEC);
>  			if (dbs[cnt].ro_fd == -1)
>  			  dbg_log (_("\
>  cannot create read-only descriptor for \"%s\"; no mmap"),
> @@ -648,23 +641,23 @@ cannot create read-only descriptor for \"%s\"; no mmap"),
>  	    if (dbs[cnt].persistent)
>  	      {
>  		fd = open (dbs[cnt].db_filename,
> -			   O_RDWR | O_CREAT | O_EXCL | O_TRUNC | EXTRA_O_FLAGS,
> +			   O_RDWR | O_CREAT | O_EXCL | O_TRUNC | O_CLOEXEC,
>  			   S_IRUSR | S_IWUSR);
>  		if (fd != -1 && dbs[cnt].shared)
>  		  ro_fd = open (dbs[cnt].db_filename,
> -				O_RDONLY | EXTRA_O_FLAGS);
> +				O_RDONLY | O_CLOEXEC);
>  	      }
>  	    else
>  	      {
>  		char fname[] = _PATH_NSCD_XYZ_DB_TMP;
> -		fd = mkostemp (fname, EXTRA_O_FLAGS);
> +		fd = mkostemp (fname, O_CLOEXEC);
>  
>  		/* We do not need the file name anymore after we
>  		   opened another file descriptor in read-only mode.  */
>  		if (fd != -1)
>  		  {
>  		    if (dbs[cnt].shared)
> -		      ro_fd = open (fname, O_RDONLY | EXTRA_O_FLAGS);
> +		      ro_fd = open (fname, O_RDONLY | O_CLOEXEC);
>  
>  		    unlink (fname);
>  		  }
> @@ -782,24 +775,6 @@ cannot create read-only descriptor for \"%s\"; no mmap"),
>  	      }
>  	  }
>  
> -#if !defined O_CLOEXEC || !defined __ASSUME_O_CLOEXEC
> -	/* We do not check here whether the O_CLOEXEC provided to the
> -	   open call was successful or not.  The two fcntl calls are
> -	   only performed once each per process start-up and therefore
> -	   is not noticeable at all.  */
> -	if (paranoia
> -	    && ((dbs[cnt].wr_fd != -1
> -		 && fcntl (dbs[cnt].wr_fd, F_SETFD, FD_CLOEXEC) == -1)
> -		|| (dbs[cnt].ro_fd != -1
> -		    && fcntl (dbs[cnt].ro_fd, F_SETFD, FD_CLOEXEC) == -1)))
> -	  {
> -	    dbg_log (_("\
> -cannot set socket to close on exec: %s; disabling paranoia mode"),
> -		     strerror (errno));
> -	    paranoia = 0;
> -	  }
> -#endif
> -
>  	if (dbs[cnt].head == NULL)
>  	  {
>  	    /* We do not use the persistent database.  Just
> diff --git a/nss/Makefile b/nss/Makefile
> index de6c47a..fa0418e 100644
> --- a/nss/Makefile
> +++ b/nss/Makefile
> @@ -74,7 +74,7 @@ vpath %.c $(subdir-dirs) ../locale/programs ../intl
>  
>  
>  libnss_files-routines	:= $(addprefix files-,$(databases)) \
> -			   files-initgroups files-have_o_cloexec files-init
> +			   files-initgroups files-init
>  
>  libnss_db-dbs		:= $(addprefix db-,\
>  				       $(filter-out hosts network key alias,\
> diff --git a/nss/nss_db/db-open.c b/nss/nss_db/db-open.c
> index 42ce00f..1c58bd1 100644
> --- a/nss/nss_db/db-open.c
> +++ b/nss/nss_db/db-open.c
> @@ -36,11 +36,7 @@ internal_setent (const char *file, struct nss_db_map *mapping)
>  {
>    enum nss_status status = NSS_STATUS_UNAVAIL;
>  
> -  int mode = O_RDONLY | O_LARGEFILE;
> -#ifdef O_CLOEXEC
> -  mode |= O_CLOEXEC;
> -#endif
> -  int fd = open_not_cancel_2 (file, mode);
> +  int fd = open_not_cancel_2 (file, O_RDONLY | O_LARGEFILE | O_CLOEXEC);
>    if (fd != -1)
>      {
>        struct nss_db_header header;
> diff --git a/nss/nss_files/files-XXX.c b/nss/nss_files/files-XXX.c
> index dbd38a3..265331e 100644
> --- a/nss/nss_files/files-XXX.c
> +++ b/nss/nss_files/files-XXX.c
> @@ -78,41 +78,6 @@ internal_setent (FILE **stream)
>  
>        if (*stream == NULL)
>  	status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
> -      else
> -	{
> -#if !defined O_CLOEXEC || !defined __ASSUME_O_CLOEXEC
> -# ifdef O_CLOEXEC
> -	  if (__have_o_cloexec <= 0)
> -# endif
> -	    {
> -	      /* We have to make sure the file is  `closed on exec'.  */
> -	      int result;
> -	      int flags;
> -
> -	      result = flags = fcntl (fileno (*stream), F_GETFD, 0);
> -	      if (result >= 0)
> -		{
> -# ifdef O_CLOEXEC
> -		  if (__have_o_cloexec == 0)
> -		    __have_o_cloexec = (flags & FD_CLOEXEC) == 0 ? -1 : 1;
> -		  if (__have_o_cloexec < 0)
> -# endif
> -		    {
> -		      flags |= FD_CLOEXEC;
> -		      result = fcntl (fileno (*stream), F_SETFD, flags);
> -		    }
> -		}
> -	      if (result < 0)
> -		{
> -		  /* Something went wrong.  Close the stream and return a
> -		     failure.  */
> -		  fclose (*stream);
> -		  *stream = NULL;
> -		  status = NSS_STATUS_UNAVAIL;
> -		}
> -	    }
> -#endif
> -	}
>      }
>    else
>      rewind (*stream);
> diff --git a/nss/nss_files/files-alias.c b/nss/nss_files/files-alias.c
> index de4e364..cf872bb 100644
> --- a/nss/nss_files/files-alias.c
> +++ b/nss/nss_files/files-alias.c
> @@ -51,41 +51,6 @@ internal_setent (FILE **stream)
>  
>        if (*stream == NULL)
>  	status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
> -      else
> -	{
> -#if !defined O_CLOEXEC || !defined __ASSUME_O_CLOEXEC
> -# ifdef O_CLOEXEC
> -	  if (__have_o_cloexec <= 0)
> -# endif
> -	    {
> -	      /* We have to make sure the file is  `closed on exec'.  */
> -	      int result;
> -	      int flags;
> -
> -	      result = flags = fcntl (fileno (*stream), F_GETFD, 0);
> -	      if (result >= 0)
> -		{
> -# ifdef O_CLOEXEC
> -		  if (__have_o_cloexec == 0)
> -		    __have_o_cloexec = (flags & FD_CLOEXEC) == 0 ? -1 : 1;
> -		  if (__have_o_cloexec < 0)
> -# endif
> -		    {
> -		      flags |= FD_CLOEXEC;
> -		      result = fcntl (fileno (*stream), F_SETFD, flags);
> -		    }
> -		}
> -	      if (result < 0)
> -		{
> -		  /* Something went wrong.  Close the stream and return a
> -		     failure.  */
> -		  fclose (*stream);
> -		  stream = NULL;
> -		  status = NSS_STATUS_UNAVAIL;
> -		}
> -	    }
> -#endif
> -	}
>      }
>    else
>      rewind (*stream);
> diff --git a/nss/nss_files/files-have_o_cloexec.c b/nss/nss_files/files-have_o_cloexec.c
> deleted file mode 100644
> index 295eccc..0000000
> --- a/nss/nss_files/files-have_o_cloexec.c
> +++ /dev/null
> @@ -1,23 +0,0 @@
> -/* Copyright (C) 2007-2017 Free Software Foundation, Inc.
> -   This file is part of the GNU C Library.
> -
> -   The GNU C Library is free software; you can redistribute it and/or
> -   modify it under the terms of the GNU Lesser General Public
> -   License as published by the Free Software Foundation; either
> -   version 2.1 of the License, or (at your option) any later version.
> -
> -   The GNU C Library is distributed in the hope that it will be useful,
> -   but WITHOUT ANY WARRANTY; without even the implied warranty of
> -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> -   Lesser General Public License for more details.
> -
> -   You should have received a copy of the GNU Lesser General Public
> -   License along with the GNU C Library; if not, see
> -   <http://www.gnu.org/licenses/>.  */
> -
> -#include <fcntl.h>
> -#include <kernel-features.h>
> -
> -#if defined O_CLOEXEC && !defined __ASSUME_O_CLOEXEC
> -int __have_o_cloexec;
> -#endif
> diff --git a/posix/wordexp.c b/posix/wordexp.c
> index 639d73e..ee83838 100644
> --- a/posix/wordexp.c
> +++ b/posix/wordexp.c
> @@ -833,12 +833,8 @@ exec_comm_child (char *comm, int *fildes, int showerr, int noexec)
>        __close (fildes[1]);
>      }
>    else
> -    {
> -#ifdef O_CLOEXEC
> -      /* Reset the close-on-exec flag (if necessary).  */
> -      __fcntl (fildes[1], F_SETFD, 0);
> -#endif
> -    }
> +    /* Reset the close-on-exec flag (if necessary).  */
> +    __fcntl (fildes[1], F_SETFD, 0);
>  
>    /* Redirect stderr to /dev/null if we have to.  */
>    if (showerr == 0)
> @@ -902,14 +898,12 @@ exec_comm (char *comm, char **word, size_t *word_length, size_t *max_length,
>    if (!comm || !*comm)
>      return 0;
>  
> -#ifdef O_CLOEXEC
>    {
>      int r = __pipe2 (fildes, O_CLOEXEC);
>      if (r < 0)
>        /* Bad */
>        return WRDE_NOSPACE;
>    }
> -#endif

Again, just remove the brackets.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]