diff options
Diffstat (limited to 'posix')
-rw-r--r-- | posix/ChangeLog | 6 | ||||
-rw-r--r-- | posix/gawkmisc.c | 23 |
2 files changed, 27 insertions, 2 deletions
diff --git a/posix/ChangeLog b/posix/ChangeLog index d4710fcc..ddd40114 100644 --- a/posix/ChangeLog +++ b/posix/ChangeLog @@ -1,3 +1,9 @@ +Wed Nov 24 17:26:24 2010 Arnold D. Robbins <arnold@skeeve.com> + + * gawkmisc.c (os_close_on_exec): After discussion on the Bash + list, change the routine to follow POSIX and use read/modify/write + on the flags value. + Thu May 6 20:55:14 2010 Arnold D. Robbins <arnold@skeeve.com> * Release 3.1.8: Release tar file made. diff --git a/posix/gawkmisc.c b/posix/gawkmisc.c index 7fb5f1ef..6032fcdf 100644 --- a/posix/gawkmisc.c +++ b/posix/gawkmisc.c @@ -165,11 +165,30 @@ os_close_on_exec(fd, name, what, dir) int fd; const char *name, *what, *dir; { + int curflags = 0; + if (fd <= 2) /* sanity */ return; - if (fcntl(fd, F_SETFD, 1) < 0) - warning(_("%s %s `%s': could not set close-on-exec: (fcntl: %s)"), + /* + * Per POSIX, use Read/Modify/Write - get the flags, + * add FD_CLOEXEC, set the flags back. + */ + + if ((curflags = fcntl(fd, F_GETFD)) < 0) { + warning(_("%s %s `%s': could not get fd flags: (fcntl F_GETFD: %s)"), + what, dir, name, strerror(errno)); + return; + } + +#ifndef FD_CLOEXEC +#define FD_CLOEXEC 1 +#endif + + curflags |= FD_CLOEXEC; + + if (fcntl(fd, F_SETFD, curflags) < 0) + warning(_("%s %s `%s': could not set close-on-exec: (fcntl F_SETFD: %s)"), what, dir, name, strerror(errno)); } |