Hi!
----
Attached (as "astopen20120612_o_cloexec_patch20120616_001.diff") is a
patch which replaces some of the |open()|+|fcntl(...,F_CLOEXEC)|
sequences in ast-open.2012-06-12 with |open(...,O_CLOEXEC)| if the
|O_CLOEXEC| CPP symbol is available on that platform (I've tested with
Solaris 11 and SuSE 12.1).
IMO the patch is simple&&safe enough for ksh93u+, too.
----
Bye,
Roland
--
__ . . __
(o.\ \/ /.o) [email protected]
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)
diff -r -u src/cmd/ksh93/edit/history.c src/cmd/ksh93/edit/history.c
--- src/cmd/ksh93/edit/history.c 2011-12-20 16:01:29.000000000 +0100
+++ src/cmd/ksh93/edit/history.c 2012-06-16 22:49:41.070713953 +0200
@@ -383,7 +383,11 @@
hp->auditfp = 0;
if(sh_isstate(SH_INTERACTIVE) && (hp->auditmask=sh_checkaudit(hp,SHOPT_AUDITFILE, buff, sizeof(buff))))
{
+#ifdef O_CLOEXEC
+ if((fd=sh_open(buff,O_BINARY|O_WRONLY|O_APPEND|O_CREAT|O_CLOEXEC,S_IRUSR|S_IWUSR))>=0 && fd < 10)
+#else
if((fd=sh_open(buff,O_BINARY|O_WRONLY|O_APPEND|O_CREAT,S_IRUSR|S_IWUSR))>=0 && fd < 10)
+#endif
{
int n;
if((n = sh_fcntl(fd,F_DUPFD, 10)) >= 0)
@@ -394,7 +398,9 @@
}
if(fd>=0)
{
+#ifndef O_CLOEXEC
fcntl(fd,F_SETFD,FD_CLOEXEC);
+#endif
hp->tty = strdup(ttyname(2));
hp->auditfp = sfnew((Sfio_t*)0,NULL,-1,fd,SF_WRITE);
}
diff -r -u src/lib/libast/comp/syslog.c src/lib/libast/comp/syslog.c
--- src/lib/libast/comp/syslog.c 2010-07-22 08:51:00.000000000 +0200
+++ src/lib/libast/comp/syslog.c 2012-06-16 22:35:52.998466423 +0200
@@ -268,9 +268,14 @@
continue;
if (*(s = p->name) != '/' && !(s = pathpath(buf, s, "", PATH_REGULAR|PATH_READ, sizeof(buf))))
continue;
+#ifdef O_CLOEXEC
+ if ((log.fd = open(s, O_WRONLY|O_APPEND|O_NOCTTY|O_CLOEXEC)) < 0 && (log.fd = sockopen(s)) < 0)
+ continue;
+#else
if ((log.fd = open(s, O_WRONLY|O_APPEND|O_NOCTTY)) < 0 && (log.fd = sockopen(s)) < 0)
continue;
fcntl(log.fd, F_SETFD, FD_CLOEXEC);
+#endif
}
if (!n || write(log.fd, msg, n) > 0)
break;
diff -r -u src/lib/libast/dir/opendir.c src/lib/libast/dir/opendir.c
--- src/lib/libast/dir/opendir.c 2000-12-14 17:20:34.000000000 +0100
+++ src/lib/libast/dir/opendir.c 2012-06-16 22:33:59.543296710 +0200
@@ -52,10 +52,16 @@
register int fd;
struct stat st;
+#ifdef O_CLOEXEC
+ if ((fd = open(path, O_RDONLY|O_CLOEXEC)) < 0) return(0);
+#else
if ((fd = open(path, O_RDONLY)) < 0) return(0);
+#endif
if (fstat(fd, &st) < 0 ||
!S_ISDIR(st.st_mode) && (errno = ENOTDIR) ||
+#ifndef O_CLOEXEC
fcntl(fd, F_SETFD, FD_CLOEXEC) ||
+#endif
!(dirp = freedirp ? freedirp :
#if defined(_DIR_PRIVATE_) || _ptr_dd_buf
newof(0, DIR, 1, DIRBLKSIZ)
diff -r -u src/lib/libast/vmalloc/malloc.c src/lib/libast/vmalloc/malloc.c
--- src/lib/libast/vmalloc/malloc.c 2012-05-29 14:53:33.000000000 +0200
+++ src/lib/libast/vmalloc/malloc.c 2012-06-16 22:32:05.679028040 +0200
@@ -1227,7 +1227,11 @@
else if (*file)
{
#if _PACKAGE_ast
+#ifdef O_CLOEXEC
+ fd = open(file, O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, CREAT_MODE);
+#else
fd = open(file, O_WRONLY|O_CREAT|O_TRUNC, CREAT_MODE);
+#endif
#else
fd = creat(file, CREAT_MODE);
#endif
@@ -1236,11 +1240,13 @@
else
return -1;
#if _PACKAGE_ast
+#ifndef O_CLOEXEC
#ifdef FD_CLOEXEC
if (fd >= 0)
fcntl(fd, F_SETFD, FD_CLOEXEC);
#endif
#endif
+#endif
return fd;
}
diff -r -u src/lib/libcmd/Makefile src/lib/libcmd/Makefile
--- src/lib/libcmd/Makefile 2012-06-08 21:29:14.000000000 +0200
+++ src/lib/libcmd/Makefile 2012-06-16 22:52:30.018325960 +0200
@@ -25,6 +25,7 @@
mkfifo.c mktemp.c mv.c paste.c pathchk.c pids.c rev.c rm.c \
rmdir.c stty.c sum.c sync.c tail.c tee.c tty.c uname.c uniq.c \
vmstate.c wc.c revlib.c wclib.c sumlib.o \
+ grep.c xargs.c tr.c od.c \
fts_fix.c lib.c \
-lfsg -lmd -lutil
diff -r -u src/lib/libtksh/tcl/tclUnixChan.c src/lib/libtksh/tcl/tclUnixChan.c
--- src/lib/libtksh/tcl/tclUnixChan.c 2000-02-09 16:16:13.000000000 +0100
+++ src/lib/libtksh/tcl/tclUnixChan.c 2012-06-16 22:38:28.472890038 +0200
@@ -1136,7 +1136,11 @@
if (nativeName == NULL) {
return NULL;
}
+#ifdef O_CLOEXEC
+ fd = open(nativeName, mode|O_CLOEXEC, permissions);
+#else
fd = open(nativeName, mode, permissions);
+#endif
/*
* If nativeName is not NULL, the buffer is valid and we must free
@@ -1157,9 +1161,11 @@
* Set close-on-exec flag on the fd so that child processes will not
* inherit this fd.
*/
-
+
+#ifndef O_CLOEXEC
fcntl(fd, F_SETFD, FD_CLOEXEC);
-
+#endif
+
sprintf(channelName, "file%d", fd);
file = Tcl_GetFile((ClientData) fd, TCL_UNIX_FD);
diff -r -u src/lib/libtksh/tcl/tclUnixFile.c src/lib/libtksh/tcl/tclUnixFile.c
--- src/lib/libtksh/tcl/tclUnixFile.c 2004-07-23 08:54:18.000000000 +0200
+++ src/lib/libtksh/tcl/tclUnixFile.c 2012-06-16 22:37:05.936517049 +0200
@@ -243,9 +243,15 @@
{
int fd;
+#ifdef O_CLOEXEC
+ fd = open(fname, mode|O_CLOEXEC, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
+#else
fd = open(fname, mode, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
+#endif
if (fd != -1) {
+#ifndef O_CLOEXEC
fcntl(fd, F_SETFD, FD_CLOEXEC);
+#endif
return Tcl_GetFile((ClientData)fd, TCL_UNIX_FD);
}
return NULL;
_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers