ruby-changes:21501
From: akr <ko1@a...>
Date: Sat, 29 Oct 2011 13:02:13 +0900 (JST)
Subject: [ruby-changes:21501] akr:r33550 (trunk): * process.c (ruby_setsid): use rb_cloexec_open.
akr 2011-10-29 13:01:54 +0900 (Sat, 29 Oct 2011) New Revision: 33550 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=33550 Log: * process.c (ruby_setsid): use rb_cloexec_open. (rb_daemon): ditto. * 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/io/console/console.c (console_dev): ditto. Modified files: trunk/ChangeLog trunk/ext/io/console/console.c trunk/ext/pty/pty.c trunk/file.c trunk/process.c trunk/random.c trunk/ruby.c Index: ChangeLog =================================================================== --- ChangeLog (revision 33549) +++ ChangeLog (revision 33550) @@ -1,3 +1,20 @@ +Sat Oct 29 12:57:15 2011 Tanaka Akira <akr@f...> + + * process.c (ruby_setsid): use rb_cloexec_open. + (rb_daemon): ditto. + + * 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/io/console/console.c (console_dev): ditto. + Sat Oct 29 10:40:19 2011 Tanaka Akira <akr@f...> * include/ruby/intern.h (rb_cloexec_open): declared. Index: process.c =================================================================== --- process.c (revision 33549) +++ process.c (revision 33550) @@ -3558,8 +3558,8 @@ #endif if (ret == -1) return -1; - if ((fd = open("/dev/tty", O_RDWR)) >= 0) { - rb_fd_set_cloexec(fd); + if ((fd = rb_cloexec_open("/dev/tty", O_RDWR, 0)) >= 0) { + rb_update_max_fd(fd); ioctl(fd, TIOCNOTTY, NULL); close(fd); } @@ -4849,8 +4849,8 @@ if (!nochdir) err = chdir("/"); - if (!noclose && (n = open("/dev/null", O_RDWR, 0)) != -1) { - rb_fd_set_cloexec(n); + if (!noclose && (n = rb_cloexec_open("/dev/null", O_RDWR, 0)) != -1) { + rb_update_max_fd(n); (void)dup2(n, 0); (void)dup2(n, 1); (void)dup2(n, 2); Index: ext/pty/pty.c =================================================================== --- ext/pty/pty.c (revision 33549) +++ ext/pty/pty.c (revision 33550) @@ -175,9 +175,9 @@ if (setpgrp(0, getpid()) == -1) ERROR_EXIT("setpgrp()"); { - int i = open("/dev/tty", O_RDONLY); + int i = rb_cloexec_open("/dev/tty", O_RDONLY, 0); if (i < 0) ERROR_EXIT("/dev/tty"); - rb_fd_set_cloexec(i); + rb_update_max_fd(i); if (ioctl(i, TIOCNOTTY, (char *)0)) ERROR_EXIT("ioctl(TIOCNOTTY)"); close(i); @@ -195,11 +195,11 @@ /* errors ignored for sun */ #else close(slave); - slave = open(carg->slavename, O_RDWR); + slave = rb_cloexec_open(carg->slavename, O_RDWR, 0); if (slave < 0) { ERROR_EXIT("open: pty slave"); } - rb_fd_set_cloexec(slave); + rb_update_max_fd(slave); close(master); #endif dup2(slave,0); @@ -306,8 +306,8 @@ if (unlockpt(masterfd) == -1) goto error; 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_fd_set_cloexec(slavefd); + if ((slavefd = rb_cloexec_open(slavedevice, O_RDWR|O_NOCTTY, 0)) == -1) goto error; + rb_update_max_fd(slavefd); #if defined I_PUSH && !defined linux if (ioctl(slavefd, I_PUSH, "ptem") == -1) goto error; @@ -358,9 +358,9 @@ } rb_fd_set_cloexec(*master); - *slave = open(name, O_RDWR); + *slave = rb_cloexec_open(name, O_RDWR, 0); /* error check? */ - rb_fd_set_cloexec(*slave); + rb_update_max_fd(*slave); strlcpy(SlaveName, name, DEVICELEN); return 0; @@ -380,8 +380,8 @@ if(grantpt(masterfd) == -1) goto error; rb_fd_set_cloexec(masterfd); #else - if((masterfd = open("/dev/ptmx", O_RDWR, 0)) == -1) goto error; - rb_fd_set_cloexec(masterfd); + if((masterfd = rb_cloexec_open("/dev/ptmx", O_RDWR, 0)) == -1) goto error; + rb_update_max_fd(masterfd); s = signal(SIGCHLD, SIG_DFL); if(grantpt(masterfd) == -1) goto error; #endif @@ -389,8 +389,8 @@ if(unlockpt(masterfd) == -1) goto error; 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_fd_set_cloexec(slavefd); + if((slavefd = rb_cloexec_open(slavedevice, O_RDWR, 0)) == -1) goto error; + rb_update_max_fd(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; @@ -413,12 +413,12 @@ for (p = deviceNo; *p != NULL; p++) { snprintf(MasterName, sizeof MasterName, MasterDevice, *p); - if ((masterfd = open(MasterName,O_RDWR,0)) >= 0) { - rb_fd_set_cloexec(masterfd); + if ((masterfd = rb_cloexec_open(MasterName,O_RDWR,0)) >= 0) { + rb_update_max_fd(masterfd); *master = masterfd; snprintf(SlaveName, DEVICELEN, SlaveDevice, *p); - if ((slavefd = open(SlaveName,O_RDWR,0)) >= 0) { - rb_fd_set_cloexec(slavefd); + if ((slavefd = rb_cloexec_open(SlaveName,O_RDWR,0)) >= 0) { + rb_update_max_fd(slavefd); *slave = slavefd; if (chown(SlaveName, getuid(), getgid()) != 0) goto error; if (chmod(SlaveName, nomesg ? 0600 : 0622) != 0) goto error; Index: ext/io/console/console.c =================================================================== --- ext/io/console/console.c (revision 33549) +++ ext/io/console/console.c (revision 33550) @@ -562,21 +562,21 @@ int fd; #ifdef CONSOLE_DEVICE_FOR_WRITING - fd = open(CONSOLE_DEVICE_FOR_WRITING, O_WRONLY); + fd = rb_cloexec_open(CONSOLE_DEVICE_FOR_WRITING, O_WRONLY, 0); if (fd < 0) return Qnil; - rb_fd_set_cloexec(fd); + rb_update_max_fd(fd); args[1] = INT2FIX(O_WRONLY); args[0] = INT2NUM(fd); out = rb_class_new_instance(2, args, klass); #endif - fd = open(CONSOLE_DEVICE_FOR_READING, O_RDWR); + fd = rb_cloexec_open(CONSOLE_DEVICE_FOR_READING, O_RDWR, 0); if (fd < 0) { #ifdef CONSOLE_DEVICE_FOR_WRITING rb_io_close(out); #endif return Qnil; } - rb_fd_set_cloexec(fd); + rb_update_max_fd(fd); args[1] = INT2FIX(O_RDWR); args[0] = INT2NUM(fd); con = rb_class_new_instance(2, args, klass); Index: ruby.c =================================================================== --- ruby.c (revision 33549) +++ ruby.c (revision 33550) @@ -1524,10 +1524,10 @@ } } #endif - if ((fd = open(fname, mode)) < 0) { + if ((fd = rb_cloexec_open(fname, mode, 0)) < 0) { rb_load_fail(fname); } - rb_fd_set_cloexec(fd); + rb_update_max_fd(fd); f = rb_io_fdopen(fd, mode, fname); } Index: file.c =================================================================== --- file.c (revision 33549) +++ file.c (revision 33550) @@ -3914,10 +3914,10 @@ { int tmpfd; - if ((tmpfd = open(StringValueCStr(path), 0)) < 0) { + if ((tmpfd = rb_cloexec_open(StringValueCStr(path), 0, 0)) < 0) { rb_sys_fail(RSTRING_PTR(path)); } - rb_fd_set_cloexec(tmpfd); + rb_update_max_fd(tmpfd); if (chsize(tmpfd, pos) < 0) { close(tmpfd); rb_sys_fail(RSTRING_PTR(path)); @@ -5063,9 +5063,9 @@ file_load_ok(const char *path) { int ret = 1; - int fd = open(path, O_RDONLY); + int fd = rb_cloexec_open(path, O_RDONLY, 0); if (fd == -1) return 0; - rb_fd_set_cloexec(fd); + rb_update_max_fd(fd); #if !defined DOSISH { struct stat st; Index: random.c =================================================================== --- random.c (revision 33549) +++ random.c (revision 33550) @@ -498,15 +498,15 @@ memset(seed, 0, DEFAULT_SEED_LEN); #if USE_DEV_URANDOM - if ((fd = open("/dev/urandom", O_RDONLY + if ((fd = rb_cloexec_open("/dev/urandom", O_RDONLY #ifdef O_NONBLOCK |O_NONBLOCK #endif #ifdef O_NOCTTY |O_NOCTTY #endif - )) >= 0) { - rb_fd_set_cloexec(fd); + , 0)) >= 0) { + rb_update_max_fd(fd); if (fstat(fd, &statbuf) == 0 && S_ISCHR(statbuf.st_mode)) { if (read(fd, seed, DEFAULT_SEED_LEN) < DEFAULT_SEED_LEN) { /* abandon */; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/