Util-Linux package development
 help / color / mirror / Atom feed
* [PATCH] lib/sysfs.c: use fcntl(..F_DUPFD_CLOEXEC) instead of dup(2)
@ 2015-04-10 18:57 Cristian Rodríguez
  2015-04-14  9:47 ` Karel Zak
  0 siblings, 1 reply; 2+ messages in thread
From: Cristian Rodríguez @ 2015-04-10 18:57 UTC (permalink / raw)
  To: util-linux; +Cc: Cristian Rodríguez

"The two descriptors do not share file descriptor flags (the
close-on-exec flag).  The close-on-exec flag  for the duplicate descriptor is off"
---
 lib/sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/sysfs.c b/lib/sysfs.c
index ac35596..1b20191 100644
--- a/lib/sysfs.c
+++ b/lib/sysfs.c
@@ -246,7 +246,7 @@ DIR *sysfs_opendir(struct sysfs_cxt *cxt, const char *attr)
 		 * -- we cannot use cxt->sysfs_fd directly, because closedir()
 		 * will close this our persistent file descriptor.
 		 */
-		fd = dup(cxt->dir_fd);
+		fd = fcntl(cxt->dir_fd, F_DUPFD_CLOEXEC, STDERR_FILENO + 1);
 
 	if (fd < 0)
 		return NULL;
-- 
2.3.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] lib/sysfs.c: use fcntl(..F_DUPFD_CLOEXEC) instead of dup(2)
  2015-04-10 18:57 [PATCH] lib/sysfs.c: use fcntl(..F_DUPFD_CLOEXEC) instead of dup(2) Cristian Rodríguez
@ 2015-04-14  9:47 ` Karel Zak
  0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2015-04-14  9:47 UTC (permalink / raw)
  To: Cristian Rodríguez; +Cc: util-linux

On Fri, Apr 10, 2015 at 03:57:58PM -0300, Cristian Rodríguez wrote:
> "The two descriptors do not share file descriptor flags (the
> close-on-exec flag).  The close-on-exec flag  for the duplicate descriptor is off"
> ---
>  lib/sysfs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

 Excellent catch. Thanks.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-04-14  9:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-10 18:57 [PATCH] lib/sysfs.c: use fcntl(..F_DUPFD_CLOEXEC) instead of dup(2) Cristian Rodríguez
2015-04-14  9:47 ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox