ruby-changes:38111
From: akr <ko1@a...>
Date: Thu, 9 Apr 2015 20:36:14 +0900 (JST)
Subject: [ruby-changes:38111] akr:r50192 (trunk): * process.c (fd_clear_cloexec): Extracted from run_exec_dup2.
akr 2015-04-09 20:35:52 +0900 (Thu, 09 Apr 2015) New Revision: 50192 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50192 Log: * process.c (fd_clear_cloexec): Extracted from run_exec_dup2. Modified files: trunk/ChangeLog trunk/process.c Index: ChangeLog =================================================================== --- ChangeLog (revision 50191) +++ ChangeLog (revision 50192) @@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Apr 9 20:35:12 2015 Tanaka Akira <akr@f...> + + * process.c (fd_clear_cloexec): Extracted from run_exec_dup2. + Thu Apr 9 09:26:47 2015 Eric Wong <e@8...> * ccan/list/list.h: sync with ccan upstream Index: process.c =================================================================== --- process.c (revision 50191) +++ process.c (revision 50192) @@ -2515,6 +2515,29 @@ run_exec_dup2_tmpbuf_size(long n) https://github.com/ruby/ruby/blob/trunk/process.c#L2515 return sizeof(struct run_exec_dup2_fd_pair) * n; } +/* This function should be async-signal-safe. Actually it is. */ +static int +fd_clear_cloexec(int fd, char *errmsg, size_t errmsg_buflen) +{ +#ifdef F_GETFD + int ret; + ret = fcntl(fd, F_GETFD); /* async-signal-safe */ + if (ret == -1) { + ERRMSG("fcntl(F_GETFD)"); + return -1; + } + if (ret & FD_CLOEXEC) { + ret &= ~FD_CLOEXEC; + ret = fcntl(fd, F_SETFD, ret); /* async-signal-safe */ + if (ret == -1) { + ERRMSG("fcntl(F_SETFD)"); + return -1; + } + } +#endif + return 0; +} + /* This function should be async-signal-safe when sargp is NULL. Hopefully it is. */ static int run_exec_dup2(VALUE ary, VALUE tmpbuf, struct rb_execarg *sargp, char *errmsg, size_t errmsg_buflen) @@ -2584,22 +2607,8 @@ run_exec_dup2(VALUE ary, VALUE tmpbuf, s https://github.com/ruby/ruby/blob/trunk/process.c#L2607 if (pairs[i].oldfd == -1) continue; if (pairs[i].oldfd == pairs[i].newfd) { /* self cycle */ -#ifdef F_GETFD - int fd = pairs[i].oldfd; - ret = fcntl(fd, F_GETFD); /* async-signal-safe */ - if (ret == -1) { - ERRMSG("fcntl(F_GETFD)"); + if (fd_clear_cloexec(pairs[i].oldfd, errmsg, errmsg_buflen) == -1) /* async-signal-safe */ goto fail; - } - if (ret & FD_CLOEXEC) { - ret &= ~FD_CLOEXEC; - ret = fcntl(fd, F_SETFD, ret); /* async-signal-safe */ - if (ret == -1) { - ERRMSG("fcntl(F_SETFD)"); - goto fail; - } - } -#endif pairs[i].oldfd = -1; continue; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/