Skip to content

Commit 0d2a92e

Browse files
committed
* include/ruby/intern.h (rb_cloexec_pipe): declared.
* io.c (rb_cloexec_pipe): new function. (rb_pipe): use rb_cloexec_pipe. * thread_pthread.c (rb_thread_create_timer_thread): use rb_cloexec_pipe. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33572 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 6e0ed04 commit 0d2a92e

File tree

4 files changed

+37
-21
lines changed

4 files changed

+37
-21
lines changed

ChangeLog

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
Sun Oct 30 21:12:47 2011 Tanaka Akira <[email protected]>
2+
3+
* include/ruby/intern.h (rb_cloexec_pipe): declared.
4+
5+
* io.c (rb_cloexec_pipe): new function.
6+
(rb_pipe): use rb_cloexec_pipe.
7+
8+
* thread_pthread.c (rb_thread_create_timer_thread): use
9+
rb_cloexec_pipe.
10+
111
Sun Oct 30 20:06:07 2011 Tanaka Akira <[email protected]>
212

313
* io.c (rb_cloexec_dup): refine control flow.

include/ruby/intern.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ int rb_reserved_fd_p(int fd);
505505
int rb_cloexec_open(const char *pathname, int flags, mode_t mode);
506506
int rb_cloexec_dup(int oldfd);
507507
int rb_cloexec_dup2(int oldfd, int newfd);
508+
int rb_cloexec_pipe(int fildes[2]);
508509
#define RB_RESERVED_FD_P(fd) rb_reserved_fd_p(fd)
509510
void rb_update_max_fd(int fd);
510511
void rb_fd_set_cloexec(int fd);

io.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,25 @@ rb_cloexec_dup2(int oldfd, int newfd)
262262
return ret;
263263
}
264264

265+
int
266+
rb_cloexec_pipe(int fildes[2])
267+
{
268+
int ret;
269+
ret = pipe(fildes);
270+
if (ret == -1) return -1;
271+
#ifdef __CYGWIN__
272+
if (ret == 0 && fildes[1] == -1) {
273+
close(fildes[0]);
274+
fildes[0] = -1;
275+
errno = ENFILE;
276+
return -1;
277+
}
278+
#endif
279+
fd_set_cloexec(fildes[0]);
280+
fd_set_cloexec(fildes[1]);
281+
return ret;
282+
}
283+
265284
#define argf_of(obj) (*(struct argf *)DATA_PTR(obj))
266285
#define ARGF argf_of(argf)
267286

@@ -5008,24 +5027,16 @@ int
50085027
rb_pipe(int *pipes)
50095028
{
50105029
int ret;
5011-
ret = pipe(pipes);
5030+
ret = rb_cloexec_pipe(pipes);
50125031
if (ret == -1) {
50135032
if (errno == EMFILE || errno == ENFILE) {
50145033
rb_gc();
5015-
ret = pipe(pipes);
5034+
ret = rb_cloexec_pipe(pipes);
50165035
}
50175036
}
5018-
#ifdef __CYGWIN__
5019-
if (ret == 0 && pipes[1] == -1) {
5020-
close(pipes[0]);
5021-
pipes[0] = -1;
5022-
errno = ENFILE;
5023-
return -1;
5024-
}
5025-
#endif
50265037
if (ret == 0) {
5027-
rb_fd_set_cloexec(pipes[0]);
5028-
rb_fd_set_cloexec(pipes[1]);
5038+
rb_update_max_fd(pipes[0]);
5039+
rb_update_max_fd(pipes[1]);
50295040
}
50305041
return ret;
50315042
}

thread_pthread.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,12 +1210,12 @@ rb_thread_create_timer_thread(void)
12101210
close_communication_pipe();
12111211
}
12121212

1213-
err = pipe(timer_thread_pipe);
1213+
err = rb_cloexec_pipe(timer_thread_pipe);
12141214
if (err != 0) {
12151215
rb_bug_errno("thread_timer: Failed to create communication pipe for timer thread", errno);
12161216
}
1217-
rb_fd_set_cloexec(timer_thread_pipe[0]);
1218-
rb_fd_set_cloexec(timer_thread_pipe[1]);
1217+
rb_update_max_fd(timer_thread_pipe[0]);
1218+
rb_update_max_fd(timer_thread_pipe[1]);
12191219
#if defined(HAVE_FCNTL) && defined(F_GETFL) && defined(F_SETFL)
12201220
{
12211221
int oflags;
@@ -1224,12 +1224,6 @@ rb_thread_create_timer_thread(void)
12241224
oflags |= O_NONBLOCK;
12251225
fcntl(timer_thread_pipe[1], F_SETFL, oflags);
12261226
#endif /* defined(O_NONBLOCK) */
1227-
#if defined(FD_CLOEXEC)
1228-
oflags = fcntl(timer_thread_pipe[0], F_GETFD);
1229-
fcntl(timer_thread_pipe[0], F_SETFD, oflags | FD_CLOEXEC);
1230-
oflags = fcntl(timer_thread_pipe[1], F_GETFD);
1231-
fcntl(timer_thread_pipe[1], F_SETFD, oflags | FD_CLOEXEC);
1232-
#endif /* defined(FD_CLOEXEC) */
12331227
}
12341228
#endif /* defined(HAVE_FCNTL) && defined(F_GETFL) && defined(F_SETFL) */
12351229

0 commit comments

Comments
 (0)