зеркало из https://github.com/github/ruby.git
* 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:
Родитель
3ae3cd741d
Коммит
da74bc7552
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>
|
||||
|
||||
* include/ruby/intern.h (rb_cloexec_open): declared.
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
8
file.c
8
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;
|
||||
|
|
|
@ -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);
|
||||
|
|
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);
|
||||
|
||||
#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 */;
|
||||
|
|
4
ruby.c
4
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);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче