Skip to content

Commit 3ac6a03

Browse files
committed
Revert "hijack SIGCHLD handler for internal use"
This reverts commit 054a412. SIGCHLD `waidpid`, `waitpid_lock` and related code, have been removed at #7527.
1 parent cfd48ad commit 3ac6a03

File tree

4 files changed

+18
-24
lines changed

4 files changed

+18
-24
lines changed

configure.ac

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2099,7 +2099,6 @@ AC_CHECK_FUNCS(gettimeofday) # for making ac_cv_func_gettimeofday
20992099
AC_CHECK_FUNCS(getuid)
21002100
AC_CHECK_FUNCS(getuidx)
21012101
AC_CHECK_FUNCS(gmtime_r)
2102-
AC_CHECK_FUNCS(grantpt)
21032102
AC_CHECK_FUNCS(initgroups)
21042103
AC_CHECK_FUNCS(ioctl)
21052104
AC_CHECK_FUNCS(isfinite)

ext/pty/pty.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,19 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
258258
/* Unix98 PTY */
259259
int masterfd = -1, slavefd = -1;
260260
char *slavedevice;
261+
struct sigaction dfl, old;
262+
263+
dfl.sa_handler = SIG_DFL;
264+
dfl.sa_flags = 0;
265+
sigemptyset(&dfl.sa_mask);
261266

262267
#if defined(__sun) || defined(__OpenBSD__) || (defined(__FreeBSD__) && __FreeBSD_version < 902000)
263268
/* workaround for Solaris 10: grantpt() doesn't work if FD_CLOEXEC is set. [ruby-dev:44688] */
264269
/* FreeBSD 9.2 or later supports O_CLOEXEC
265270
* http://www.freebsd.org/cgi/query-pr.cgi?pr=162374 */
266271
if ((masterfd = posix_openpt(O_RDWR|O_NOCTTY)) == -1) goto error;
267-
if (rb_grantpt(masterfd) == -1) goto error;
272+
if (sigaction(SIGCHLD, &dfl, &old) == -1) goto error;
273+
if (grantpt(masterfd) == -1) goto grantpt_error;
268274
rb_fd_fix_cloexec(masterfd);
269275
#else
270276
{
@@ -278,8 +284,10 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
278284
if ((masterfd = posix_openpt(flags)) == -1) goto error;
279285
}
280286
rb_fd_fix_cloexec(masterfd);
281-
if (rb_grantpt(masterfd) == -1) goto error;
287+
if (sigaction(SIGCHLD, &dfl, &old) == -1) goto error;
288+
if (grantpt(masterfd) == -1) goto grantpt_error;
282289
#endif
290+
if (sigaction(SIGCHLD, &old, NULL) == -1) goto error;
283291
if (unlockpt(masterfd) == -1) goto error;
284292
if ((slavedevice = ptsname(masterfd)) == NULL) goto error;
285293
if (no_mesg(slavedevice, nomesg) == -1) goto error;
@@ -297,6 +305,8 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
297305
strlcpy(SlaveName, slavedevice, DEVICELEN);
298306
return 0;
299307

308+
grantpt_error:
309+
sigaction(SIGCHLD, &old, NULL);
300310
error:
301311
if (slavefd != -1) close(slavefd);
302312
if (masterfd != -1) close(masterfd);
@@ -348,17 +358,21 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
348358

349359
extern char *ptsname(int);
350360
extern int unlockpt(int);
361+
extern int grantpt(int);
351362

352363
#if defined(__sun)
353364
/* workaround for Solaris 10: grantpt() doesn't work if FD_CLOEXEC is set. [ruby-dev:44688] */
354365
if((masterfd = open("/dev/ptmx", O_RDWR, 0)) == -1) goto error;
355-
if(rb_grantpt(masterfd) == -1) goto error;
366+
s = signal(SIGCHLD, SIG_DFL);
367+
if(grantpt(masterfd) == -1) goto error;
356368
rb_fd_fix_cloexec(masterfd);
357369
#else
358370
if((masterfd = rb_cloexec_open("/dev/ptmx", O_RDWR, 0)) == -1) goto error;
359371
rb_update_max_fd(masterfd);
360-
if(rb_grantpt(masterfd) == -1) goto error;
372+
s = signal(SIGCHLD, SIG_DFL);
373+
if(grantpt(masterfd) == -1) goto error;
361374
#endif
375+
signal(SIGCHLD, s);
362376
if(unlockpt(masterfd) == -1) goto error;
363377
if((slavedevice = ptsname(masterfd)) == NULL) goto error;
364378
if (no_mesg(slavedevice, nomesg) == -1) goto error;

internal/signal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ void (*ruby_posix_signal(int, void (*)(int)))(int);
1919

2020
RUBY_SYMBOL_EXPORT_BEGIN
2121
/* signal.c (export) */
22-
int rb_grantpt(int fd);
2322
RUBY_SYMBOL_EXPORT_END
2423

2524
#endif /* INTERNAL_SIGNAL_H */

signal.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,21 +1548,3 @@ Init_signal(void)
15481548

15491549
rb_enable_interrupt();
15501550
}
1551-
1552-
#if defined(HAVE_GRANTPT)
1553-
extern int grantpt(int);
1554-
#else
1555-
static int
1556-
fake_grantfd(int masterfd)
1557-
{
1558-
errno = ENOSYS;
1559-
return -1;
1560-
}
1561-
#define grantpt(fd) fake_grantfd(fd)
1562-
#endif
1563-
1564-
int
1565-
rb_grantpt(int masterfd)
1566-
{
1567-
return grantpt(masterfd);
1568-
}

0 commit comments

Comments
 (0)