summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog17
-rw-r--r--ext/io/console/console.c8
-rw-r--r--ext/pty/pty.c32
-rw-r--r--file.c8
-rw-r--r--process.c8
-rw-r--r--random.c6
-rw-r--r--ruby.c4
7 files changed, 50 insertions, 33 deletions
diff --git a/ChangeLog b/ChangeLog
index a222df3cb1..1470ff6bbe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+Sat Oct 29 12:57:15 2011 Tanaka Akira <akr@fsij.org>
+
+ * 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@fsij.org>
* include/ruby/intern.h (rb_cloexec_open): declared.
diff --git a/ext/io/console/console.c b/ext/io/console/console.c
index 72f507210c..1f87a31002 100644
--- a/ext/io/console/console.c
+++ b/ext/io/console/console.c
@@ -562,21 +562,21 @@ console_dev(VALUE klass)
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);
diff --git a/ext/pty/pty.c b/ext/pty/pty.c
index e3ae8fe329..032b2462d0 100644
--- a/ext/pty/pty.c
+++ b/ext/pty/pty.c
@@ -175,9 +175,9 @@ chfunc(void *data, char *errbuf, size_t errbuf_len)
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 @@ chfunc(void *data, char *errbuf, size_t errbuf_len)
/* 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 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
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 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
}
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 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
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 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
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 @@ 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_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;
diff --git a/file.c b/file.c
index 3107895037..c38ce7dc40 100644
--- a/file.c
+++ b/file.c
@@ -3914,10 +3914,10 @@ rb_file_s_truncate(VALUE klass, VALUE path, VALUE len)
{
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 @@ static int
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;
diff --git a/process.c b/process.c
index 10020f6095..1e91743648 100644
--- a/process.c
+++ b/process.c
@@ -3558,8 +3558,8 @@ ruby_setsid(void)
#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 @@ rb_daemon(int nochdir, int noclose)
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);
diff --git a/random.c b/random.c
index e55e4e7ad4..36b45a5fe5 100644
--- a/random.c
+++ b/random.c
@@ -498,15 +498,15 @@ fill_random_seed(unsigned int seed[DEFAULT_SEED_CNT])
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 */;
diff --git a/ruby.c b/ruby.c
index ef6454aa3e..2e157c0708 100644
--- a/ruby.c
+++ b/ruby.c
@@ -1524,10 +1524,10 @@ load_file_internal(VALUE arg)
}
}
#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);
}