mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33550 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3ae3cd741d
commit
da74bc7552
7 changed files with 50 additions and 33 deletions
17
ChangeLog
17
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>
|
Sat Oct 29 10:40:19 2011 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* include/ruby/intern.h (rb_cloexec_open): declared.
|
* include/ruby/intern.h (rb_cloexec_open): declared.
|
||||||
|
|
|
@ -562,21 +562,21 @@ console_dev(VALUE klass)
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
#ifdef CONSOLE_DEVICE_FOR_WRITING
|
#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;
|
if (fd < 0) return Qnil;
|
||||||
rb_fd_set_cloexec(fd);
|
rb_update_max_fd(fd);
|
||||||
args[1] = INT2FIX(O_WRONLY);
|
args[1] = INT2FIX(O_WRONLY);
|
||||||
args[0] = INT2NUM(fd);
|
args[0] = INT2NUM(fd);
|
||||||
out = rb_class_new_instance(2, args, klass);
|
out = rb_class_new_instance(2, args, klass);
|
||||||
#endif
|
#endif
|
||||||
fd = open(CONSOLE_DEVICE_FOR_READING, O_RDWR);
|
fd = rb_cloexec_open(CONSOLE_DEVICE_FOR_READING, O_RDWR, 0);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
#ifdef CONSOLE_DEVICE_FOR_WRITING
|
#ifdef CONSOLE_DEVICE_FOR_WRITING
|
||||||
rb_io_close(out);
|
rb_io_close(out);
|
||||||
#endif
|
#endif
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
rb_fd_set_cloexec(fd);
|
rb_update_max_fd(fd);
|
||||||
args[1] = INT2FIX(O_RDWR);
|
args[1] = INT2FIX(O_RDWR);
|
||||||
args[0] = INT2NUM(fd);
|
args[0] = INT2NUM(fd);
|
||||||
con = rb_class_new_instance(2, args, klass);
|
con = rb_class_new_instance(2, args, klass);
|
||||||
|
|
|
@ -175,9 +175,9 @@ chfunc(void *data, char *errbuf, size_t errbuf_len)
|
||||||
if (setpgrp(0, getpid()) == -1)
|
if (setpgrp(0, getpid()) == -1)
|
||||||
ERROR_EXIT("setpgrp()");
|
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");
|
if (i < 0) ERROR_EXIT("/dev/tty");
|
||||||
rb_fd_set_cloexec(i);
|
rb_update_max_fd(i);
|
||||||
if (ioctl(i, TIOCNOTTY, (char *)0))
|
if (ioctl(i, TIOCNOTTY, (char *)0))
|
||||||
ERROR_EXIT("ioctl(TIOCNOTTY)");
|
ERROR_EXIT("ioctl(TIOCNOTTY)");
|
||||||
close(i);
|
close(i);
|
||||||
|
@ -195,11 +195,11 @@ chfunc(void *data, char *errbuf, size_t errbuf_len)
|
||||||
/* errors ignored for sun */
|
/* errors ignored for sun */
|
||||||
#else
|
#else
|
||||||
close(slave);
|
close(slave);
|
||||||
slave = open(carg->slavename, O_RDWR);
|
slave = rb_cloexec_open(carg->slavename, O_RDWR, 0);
|
||||||
if (slave < 0) {
|
if (slave < 0) {
|
||||||
ERROR_EXIT("open: pty slave");
|
ERROR_EXIT("open: pty slave");
|
||||||
}
|
}
|
||||||
rb_fd_set_cloexec(slave);
|
rb_update_max_fd(slave);
|
||||||
close(master);
|
close(master);
|
||||||
#endif
|
#endif
|
||||||
dup2(slave,0);
|
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 (unlockpt(masterfd) == -1) goto error;
|
||||||
if ((slavedevice = ptsname(masterfd)) == NULL) goto error;
|
if ((slavedevice = ptsname(masterfd)) == NULL) goto error;
|
||||||
if (no_mesg(slavedevice, nomesg) == -1) goto error;
|
if (no_mesg(slavedevice, nomesg) == -1) goto error;
|
||||||
if ((slavefd = open(slavedevice, O_RDWR|O_NOCTTY, 0)) == -1) goto error;
|
if ((slavefd = rb_cloexec_open(slavedevice, O_RDWR|O_NOCTTY, 0)) == -1) goto error;
|
||||||
rb_fd_set_cloexec(slavefd);
|
rb_update_max_fd(slavefd);
|
||||||
|
|
||||||
#if defined I_PUSH && !defined linux
|
#if defined I_PUSH && !defined linux
|
||||||
if (ioctl(slavefd, I_PUSH, "ptem") == -1) goto error;
|
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);
|
rb_fd_set_cloexec(*master);
|
||||||
|
|
||||||
*slave = open(name, O_RDWR);
|
*slave = rb_cloexec_open(name, O_RDWR, 0);
|
||||||
/* error check? */
|
/* error check? */
|
||||||
rb_fd_set_cloexec(*slave);
|
rb_update_max_fd(*slave);
|
||||||
strlcpy(SlaveName, name, DEVICELEN);
|
strlcpy(SlaveName, name, DEVICELEN);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -380,8 +380,8 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
|
||||||
if(grantpt(masterfd) == -1) goto error;
|
if(grantpt(masterfd) == -1) goto error;
|
||||||
rb_fd_set_cloexec(masterfd);
|
rb_fd_set_cloexec(masterfd);
|
||||||
#else
|
#else
|
||||||
if((masterfd = open("/dev/ptmx", O_RDWR, 0)) == -1) goto error;
|
if((masterfd = rb_cloexec_open("/dev/ptmx", O_RDWR, 0)) == -1) goto error;
|
||||||
rb_fd_set_cloexec(masterfd);
|
rb_update_max_fd(masterfd);
|
||||||
s = signal(SIGCHLD, SIG_DFL);
|
s = signal(SIGCHLD, SIG_DFL);
|
||||||
if(grantpt(masterfd) == -1) goto error;
|
if(grantpt(masterfd) == -1) goto error;
|
||||||
#endif
|
#endif
|
||||||
|
@ -389,8 +389,8 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
|
||||||
if(unlockpt(masterfd) == -1) goto error;
|
if(unlockpt(masterfd) == -1) goto error;
|
||||||
if((slavedevice = ptsname(masterfd)) == NULL) goto error;
|
if((slavedevice = ptsname(masterfd)) == NULL) goto error;
|
||||||
if (no_mesg(slavedevice, nomesg) == -1) goto error;
|
if (no_mesg(slavedevice, nomesg) == -1) goto error;
|
||||||
if((slavefd = open(slavedevice, O_RDWR, 0)) == -1) goto error;
|
if((slavefd = rb_cloexec_open(slavedevice, O_RDWR, 0)) == -1) goto error;
|
||||||
rb_fd_set_cloexec(slavefd);
|
rb_update_max_fd(slavefd);
|
||||||
#if defined I_PUSH && !defined linux
|
#if defined I_PUSH && !defined linux
|
||||||
if(ioctl(slavefd, I_PUSH, "ptem") == -1) goto error;
|
if(ioctl(slavefd, I_PUSH, "ptem") == -1) goto error;
|
||||||
if(ioctl(slavefd, I_PUSH, "ldterm") == -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++) {
|
for (p = deviceNo; *p != NULL; p++) {
|
||||||
snprintf(MasterName, sizeof MasterName, MasterDevice, *p);
|
snprintf(MasterName, sizeof MasterName, MasterDevice, *p);
|
||||||
if ((masterfd = open(MasterName,O_RDWR,0)) >= 0) {
|
if ((masterfd = rb_cloexec_open(MasterName,O_RDWR,0)) >= 0) {
|
||||||
rb_fd_set_cloexec(masterfd);
|
rb_update_max_fd(masterfd);
|
||||||
*master = masterfd;
|
*master = masterfd;
|
||||||
snprintf(SlaveName, DEVICELEN, SlaveDevice, *p);
|
snprintf(SlaveName, DEVICELEN, SlaveDevice, *p);
|
||||||
if ((slavefd = open(SlaveName,O_RDWR,0)) >= 0) {
|
if ((slavefd = rb_cloexec_open(SlaveName,O_RDWR,0)) >= 0) {
|
||||||
rb_fd_set_cloexec(slavefd);
|
rb_update_max_fd(slavefd);
|
||||||
*slave = slavefd;
|
*slave = slavefd;
|
||||||
if (chown(SlaveName, getuid(), getgid()) != 0) goto error;
|
if (chown(SlaveName, getuid(), getgid()) != 0) goto error;
|
||||||
if (chmod(SlaveName, nomesg ? 0600 : 0622) != 0) goto error;
|
if (chmod(SlaveName, nomesg ? 0600 : 0622) != 0) goto error;
|
||||||
|
|
8
file.c
8
file.c
|
@ -3914,10 +3914,10 @@ rb_file_s_truncate(VALUE klass, VALUE path, VALUE len)
|
||||||
{
|
{
|
||||||
int tmpfd;
|
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_sys_fail(RSTRING_PTR(path));
|
||||||
}
|
}
|
||||||
rb_fd_set_cloexec(tmpfd);
|
rb_update_max_fd(tmpfd);
|
||||||
if (chsize(tmpfd, pos) < 0) {
|
if (chsize(tmpfd, pos) < 0) {
|
||||||
close(tmpfd);
|
close(tmpfd);
|
||||||
rb_sys_fail(RSTRING_PTR(path));
|
rb_sys_fail(RSTRING_PTR(path));
|
||||||
|
@ -5063,9 +5063,9 @@ static int
|
||||||
file_load_ok(const char *path)
|
file_load_ok(const char *path)
|
||||||
{
|
{
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
int fd = open(path, O_RDONLY);
|
int fd = rb_cloexec_open(path, O_RDONLY, 0);
|
||||||
if (fd == -1) return 0;
|
if (fd == -1) return 0;
|
||||||
rb_fd_set_cloexec(fd);
|
rb_update_max_fd(fd);
|
||||||
#if !defined DOSISH
|
#if !defined DOSISH
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
|
@ -3558,8 +3558,8 @@ ruby_setsid(void)
|
||||||
#endif
|
#endif
|
||||||
if (ret == -1) return -1;
|
if (ret == -1) return -1;
|
||||||
|
|
||||||
if ((fd = open("/dev/tty", O_RDWR)) >= 0) {
|
if ((fd = rb_cloexec_open("/dev/tty", O_RDWR, 0)) >= 0) {
|
||||||
rb_fd_set_cloexec(fd);
|
rb_update_max_fd(fd);
|
||||||
ioctl(fd, TIOCNOTTY, NULL);
|
ioctl(fd, TIOCNOTTY, NULL);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
@ -4849,8 +4849,8 @@ rb_daemon(int nochdir, int noclose)
|
||||||
if (!nochdir)
|
if (!nochdir)
|
||||||
err = chdir("/");
|
err = chdir("/");
|
||||||
|
|
||||||
if (!noclose && (n = open("/dev/null", O_RDWR, 0)) != -1) {
|
if (!noclose && (n = rb_cloexec_open("/dev/null", O_RDWR, 0)) != -1) {
|
||||||
rb_fd_set_cloexec(n);
|
rb_update_max_fd(n);
|
||||||
(void)dup2(n, 0);
|
(void)dup2(n, 0);
|
||||||
(void)dup2(n, 1);
|
(void)dup2(n, 1);
|
||||||
(void)dup2(n, 2);
|
(void)dup2(n, 2);
|
||||||
|
|
6
random.c
6
random.c
|
@ -498,15 +498,15 @@ fill_random_seed(unsigned int seed[DEFAULT_SEED_CNT])
|
||||||
memset(seed, 0, DEFAULT_SEED_LEN);
|
memset(seed, 0, DEFAULT_SEED_LEN);
|
||||||
|
|
||||||
#if USE_DEV_URANDOM
|
#if USE_DEV_URANDOM
|
||||||
if ((fd = open("/dev/urandom", O_RDONLY
|
if ((fd = rb_cloexec_open("/dev/urandom", O_RDONLY
|
||||||
#ifdef O_NONBLOCK
|
#ifdef O_NONBLOCK
|
||||||
|O_NONBLOCK
|
|O_NONBLOCK
|
||||||
#endif
|
#endif
|
||||||
#ifdef O_NOCTTY
|
#ifdef O_NOCTTY
|
||||||
|O_NOCTTY
|
|O_NOCTTY
|
||||||
#endif
|
#endif
|
||||||
)) >= 0) {
|
, 0)) >= 0) {
|
||||||
rb_fd_set_cloexec(fd);
|
rb_update_max_fd(fd);
|
||||||
if (fstat(fd, &statbuf) == 0 && S_ISCHR(statbuf.st_mode)) {
|
if (fstat(fd, &statbuf) == 0 && S_ISCHR(statbuf.st_mode)) {
|
||||||
if (read(fd, seed, DEFAULT_SEED_LEN) < DEFAULT_SEED_LEN) {
|
if (read(fd, seed, DEFAULT_SEED_LEN) < DEFAULT_SEED_LEN) {
|
||||||
/* abandon */;
|
/* abandon */;
|
||||||
|
|
4
ruby.c
4
ruby.c
|
@ -1524,10 +1524,10 @@ load_file_internal(VALUE arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if ((fd = open(fname, mode)) < 0) {
|
if ((fd = rb_cloexec_open(fname, mode, 0)) < 0) {
|
||||||
rb_load_fail(fname);
|
rb_load_fail(fname);
|
||||||
}
|
}
|
||||||
rb_fd_set_cloexec(fd);
|
rb_update_max_fd(fd);
|
||||||
|
|
||||||
f = rb_io_fdopen(fd, mode, fname);
|
f = rb_io_fdopen(fd, mode, fname);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue