diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2010-11-24 20:27:02 +0200 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2010-11-24 20:27:02 +0200 |
commit | 50d4a80f67e5bcbf3902138d85a25f6a90847d31 (patch) | |
tree | 18ebd4f82b1b5732977926b9bac4634bfb002759 /posix/gawkmisc.c | |
parent | b9c0946c39a677f733d42a26d2de3f44131bbdd8 (diff) | |
download | egawk-50d4a80f67e5bcbf3902138d85a25f6a90847d31.tar.gz egawk-50d4a80f67e5bcbf3902138d85a25f6a90847d31.tar.bz2 egawk-50d4a80f67e5bcbf3902138d85a25f6a90847d31.zip |
Add check for plugin license, make close on exec POSIX compatibile.
Diffstat (limited to 'posix/gawkmisc.c')
-rw-r--r-- | posix/gawkmisc.c | 23 |
1 files changed, 21 insertions, 2 deletions
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)); } |