summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-10-22 09:58:15 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-10-22 09:58:15 +0000
commitb574a4d4a1f1d77fa0224b02774456107cdbc932 (patch)
tree000945919a3486eb709a026a09688017e73b2ce8 /ext
parent00715f4c5aa12eec0dd88fb08bc7f46d23de8d40 (diff)
* include/ruby/intern.h (rb_fd_set_cloexec): declared.
* io.c (rb_fd_set_cloexec): new function. (ruby_dup): call rb_fd_set_cloexec to set close-on-exec flag. (rb_sysopen_internal): ditto. (rb_pipe): ditto. (io_reopen): ditto. (io_cntl): ditto. * process.c (rb_f_exec): change the default :close_others option to true. (rb_f_system): ditto. (move_fds_to_avoid_crash): call rb_fd_set_cloexec to set close-on-exec flag. (ruby_setsid): ditto. (rb_daemon): ditto. * thread_pthread.c (rb_thread_create_timer_thread): call rb_fd_set_cloexec to set close-on-exec flag. * ruby.c (load_file_internal): ditto. * file.c (rb_file_s_truncate): ditto. (file_load_ok): ditto. * random.c (fill_random_seed): ditto. * ext/pty/pty.c (chfunc): ditto. (get_device_once): ditto. * ext/openssl/ossl_bio.c (ossl_obj2bio): ditto. * ext/socket/init.c (rsock_socket): ditto. (rsock_s_accept_nonblock): ditto. (rsock_s_accept): ditto. * ext/socket/socket.c (rsock_sock_s_socketpair): ditto. * ext/socket/ancdata.c (discard_cmsg): ditto. (make_io_for_unix_rights): ditto. * ext/socket/unixsocket.c (unix_recv_io): ditto. * ext/io/console/console.c (console_dev): ditto. [ruby-core:38140] [Feature #5041] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33507 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/io/console/console.c4
-rw-r--r--ext/openssl/ossl_bio.c2
-rw-r--r--ext/pty/pty.c26
-rw-r--r--ext/socket/ancdata.c4
-rw-r--r--ext/socket/init.c6
-rw-r--r--ext/socket/socket.c4
-rw-r--r--ext/socket/unixsocket.c2
7 files changed, 24 insertions, 24 deletions
diff --git a/ext/io/console/console.c b/ext/io/console/console.c
index e7983bb..72f5072 100644
--- a/ext/io/console/console.c
+++ b/ext/io/console/console.c
@@ -564,7 +564,7 @@ console_dev(VALUE klass)
#ifdef CONSOLE_DEVICE_FOR_WRITING
fd = open(CONSOLE_DEVICE_FOR_WRITING, O_WRONLY);
if (fd < 0) return Qnil;
- rb_update_max_fd(fd);
+ rb_fd_set_cloexec(fd);
args[1] = INT2FIX(O_WRONLY);
args[0] = INT2NUM(fd);
out = rb_class_new_instance(2, args, klass);
@@ -576,7 +576,7 @@ console_dev(VALUE klass)
#endif
return Qnil;
}
- rb_update_max_fd(fd);
+ rb_fd_set_cloexec(fd);
args[1] = INT2FIX(O_RDWR);
args[0] = INT2NUM(fd);
con = rb_class_new_instance(2, args, klass);
diff --git a/ext/openssl/ossl_bio.c b/ext/openssl/ossl_bio.c
index ed7c0a7..da63c72 100644
--- a/ext/openssl/ossl_bio.c
+++ b/ext/openssl/ossl_bio.c
@@ -28,7 +28,7 @@ ossl_obj2bio(VALUE obj)
if ((fd = dup(FPTR_TO_FD(fptr))) < 0){
rb_sys_fail(0);
}
- rb_update_max_fd(fd);
+ rb_fd_set_cloexec(fd);
if (!(fp = fdopen(fd, "r"))){
close(fd);
rb_sys_fail(0);
diff --git a/ext/pty/pty.c b/ext/pty/pty.c
index b18eb68..8a6994d 100644
--- a/ext/pty/pty.c
+++ b/ext/pty/pty.c
@@ -177,7 +177,7 @@ chfunc(void *data, char *errbuf, size_t errbuf_len)
{
int i = open("/dev/tty", O_RDONLY);
if (i < 0) ERROR_EXIT("/dev/tty");
- rb_update_max_fd(i);
+ rb_fd_set_cloexec(i);
if (ioctl(i, TIOCNOTTY, (char *)0))
ERROR_EXIT("ioctl(TIOCNOTTY)");
close(i);
@@ -199,7 +199,7 @@ chfunc(void *data, char *errbuf, size_t errbuf_len)
if (slave < 0) {
ERROR_EXIT("open: pty slave");
}
- rb_update_max_fd(slave);
+ rb_fd_set_cloexec(slave);
close(master);
#endif
dup2(slave,0);
@@ -291,7 +291,7 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
sigemptyset(&dfl.sa_mask);
if ((masterfd = posix_openpt(O_RDWR|O_NOCTTY)) == -1) goto error;
- rb_update_max_fd(masterfd);
+ rb_fd_set_cloexec(masterfd);
if (sigaction(SIGCHLD, &dfl, &old) == -1) goto error;
if (grantpt(masterfd) == -1) goto grantpt_error;
if (sigaction(SIGCHLD, &old, NULL) == -1) goto error;
@@ -299,7 +299,7 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
if ((slavedevice = ptsname(masterfd)) == NULL) goto error;
if (no_mesg(slavedevice, nomesg) == -1) goto error;
if ((slavefd = open(slavedevice, O_RDWR|O_NOCTTY, 0)) == -1) goto error;
- rb_update_max_fd(slavefd);
+ rb_fd_set_cloexec(slavefd);
#if defined I_PUSH && !defined linux
if (ioctl(slavefd, I_PUSH, "ptem") == -1) goto error;
@@ -331,8 +331,8 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
if (!fail) return -1;
rb_raise(rb_eRuntimeError, "openpty() failed");
}
- rb_update_max_fd(*master);
- rb_update_max_fd(*slave);
+ rb_fd_set_cloexec(*master);
+ rb_fd_set_cloexec(*slave);
if (no_mesg(SlaveName, nomesg) == -1) {
if (!fail) return -1;
rb_raise(rb_eRuntimeError, "can't chmod slave pty");
@@ -348,11 +348,11 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
if (!fail) return -1;
rb_raise(rb_eRuntimeError, "_getpty() failed");
}
- rb_update_max_fd(*master);
+ rb_fd_set_cloexec(*master);
*slave = open(name, O_RDWR);
/* error check? */
- rb_update_max_fd(*slave);
+ rb_fd_set_cloexec(*slave);
strlcpy(SlaveName, name, DEVICELEN);
return 0;
@@ -366,7 +366,7 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
extern int grantpt(int);
if((masterfd = open("/dev/ptmx", O_RDWR, 0)) == -1) goto error;
- rb_update_max_fd(masterfd);
+ rb_fd_set_cloexec(masterfd);
s = signal(SIGCHLD, SIG_DFL);
if(grantpt(masterfd) == -1) goto error;
signal(SIGCHLD, s);
@@ -374,7 +374,7 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
if((slavedevice = ptsname(masterfd)) == NULL) goto error;
if (no_mesg(slavedevice, nomesg) == -1) goto error;
if((slavefd = open(slavedevice, O_RDWR, 0)) == -1) goto error;
- rb_update_max_fd(slavefd);
+ rb_fd_set_cloexec(slavefd);
#if defined I_PUSH && !defined linux
if(ioctl(slavefd, I_PUSH, "ptem") == -1) goto error;
if(ioctl(slavefd, I_PUSH, "ldterm") == -1) goto error;
@@ -398,11 +398,11 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
for (p = deviceNo; *p != NULL; p++) {
snprintf(MasterName, sizeof MasterName, MasterDevice, *p);
if ((masterfd = open(MasterName,O_RDWR,0)) >= 0) {
- rb_update_max_fd(masterfd);
+ rb_fd_set_cloexec(masterfd);
*master = masterfd;
snprintf(SlaveName, DEVICELEN, SlaveDevice, *p);
if ((slavefd = open(SlaveName,O_RDWR,0)) >= 0) {
- rb_update_max_fd(slavefd);
+ rb_fd_set_cloexec(slavefd);
*slave = slavefd;
if (chown(SlaveName, getuid(), getgid()) != 0) goto error;
if (chmod(SlaveName, nomesg ? 0600 : 0622) != 0) goto error;
@@ -590,7 +590,7 @@ pty_getpty(int argc, VALUE *argv, VALUE self)
wfptr->fd = dup(info.fd);
if (wfptr->fd == -1)
rb_sys_fail("dup()");
- rb_update_max_fd(wfptr->fd);
+ rb_fd_set_cloexec(wfptr->fd);
wfptr->pathv = rfptr->pathv;
res = rb_ary_new2(3);
diff --git a/ext/socket/ancdata.c b/ext/socket/ancdata.c
index 9db4426..848b332 100644
--- a/ext/socket/ancdata.c
+++ b/ext/socket/ancdata.c
@@ -1396,7 +1396,7 @@ discard_cmsg(struct cmsghdr *cmh, char *msg_end, int msg_peek_p)
int *end = (int *)((char *)cmh + cmh->cmsg_len);
while ((char *)fdp + sizeof(int) <= (char *)end &&
(char *)fdp + sizeof(int) <= msg_end) {
- rb_update_max_fd(*fdp);
+ rb_fd_set_cloexec(*fdp);
close(*fdp);
fdp++;
}
@@ -1439,7 +1439,7 @@ make_io_for_unix_rights(VALUE ctl, struct cmsghdr *cmh, char *msg_end)
VALUE io;
if (fstat(fd, &stbuf) == -1)
rb_raise(rb_eSocket, "invalid fd in SCM_RIGHTS");
- rb_update_max_fd(fd);
+ rb_fd_set_cloexec(fd);
if (S_ISSOCK(stbuf.st_mode))
io = rsock_init_sock(rb_obj_alloc(rb_cSocket), fd);
else
diff --git a/ext/socket/init.c b/ext/socket/init.c
index 0a23658..ca271f3 100644
--- a/ext/socket/init.c
+++ b/ext/socket/init.c
@@ -252,7 +252,7 @@ rsock_socket(int domain, int type, int proto)
}
}
if (0 <= fd)
- rb_update_max_fd(fd);
+ rb_fd_set_cloexec(fd);
return fd;
}
@@ -466,7 +466,7 @@ rsock_s_accept_nonblock(VALUE klass, rb_io_t *fptr, struct sockaddr *sockaddr, s
}
rb_sys_fail("accept(2)");
}
- rb_update_max_fd(fd2);
+ rb_fd_set_cloexec(fd2);
make_fd_nonblock(fd2);
return rsock_init_sock(rb_obj_alloc(klass), fd2);
}
@@ -513,7 +513,7 @@ rsock_s_accept(VALUE klass, int fd, struct sockaddr *sockaddr, socklen_t *len)
}
rb_sys_fail(0);
}
- rb_update_max_fd(fd2);
+ rb_fd_set_cloexec(fd2);
if (!klass) return INT2NUM(fd2);
return rsock_init_sock(rb_obj_alloc(klass), fd2);
}
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index 4613892..9240718 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -119,8 +119,8 @@ rsock_sock_s_socketpair(int argc, VALUE *argv, VALUE klass)
if (ret < 0) {
rb_sys_fail("socketpair(2)");
}
- rb_update_max_fd(sp[0]);
- rb_update_max_fd(sp[1]);
+ rb_fd_set_cloexec(sp[0]);
+ rb_fd_set_cloexec(sp[1]);
s1 = rsock_init_sock(rb_obj_alloc(klass), sp[0]);
s2 = rsock_init_sock(rb_obj_alloc(klass), sp[1]);
diff --git a/ext/socket/unixsocket.c b/ext/socket/unixsocket.c
index 15196e7..7f2d628 100644
--- a/ext/socket/unixsocket.c
+++ b/ext/socket/unixsocket.c
@@ -383,7 +383,7 @@ unix_recv_io(int argc, VALUE *argv, VALUE sock)
#if FD_PASSING_BY_MSG_CONTROL
memcpy(&fd, CMSG_DATA(&cmsg.hdr), sizeof(int));
#endif
- rb_update_max_fd(fd);
+ rb_fd_set_cloexec(fd);
if (klass == Qnil)
return INT2FIX(fd);