@@ -258,13 +258,19 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
258
258
/* Unix98 PTY */
259
259
int masterfd = -1 , slavefd = -1 ;
260
260
char * slavedevice ;
261
+ struct sigaction dfl , old ;
262
+
263
+ dfl .sa_handler = SIG_DFL ;
264
+ dfl .sa_flags = 0 ;
265
+ sigemptyset (& dfl .sa_mask );
261
266
262
267
#if defined(__sun ) || defined(__OpenBSD__ ) || (defined(__FreeBSD__ ) && __FreeBSD_version < 902000 )
263
268
/* workaround for Solaris 10: grantpt() doesn't work if FD_CLOEXEC is set. [ruby-dev:44688] */
264
269
/* FreeBSD 9.2 or later supports O_CLOEXEC
265
270
* http://www.freebsd.org/cgi/query-pr.cgi?pr=162374 */
266
271
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 ;
268
274
rb_fd_fix_cloexec (masterfd );
269
275
#else
270
276
{
@@ -278,8 +284,10 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
278
284
if ((masterfd = posix_openpt (flags )) == -1 ) goto error ;
279
285
}
280
286
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 ;
282
289
#endif
290
+ if (sigaction (SIGCHLD , & old , NULL ) == -1 ) goto error ;
283
291
if (unlockpt (masterfd ) == -1 ) goto error ;
284
292
if ((slavedevice = ptsname (masterfd )) == NULL ) goto error ;
285
293
if (no_mesg (slavedevice , nomesg ) == -1 ) goto error ;
@@ -297,6 +305,8 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
297
305
strlcpy (SlaveName , slavedevice , DEVICELEN );
298
306
return 0 ;
299
307
308
+ grantpt_error :
309
+ sigaction (SIGCHLD , & old , NULL );
300
310
error :
301
311
if (slavefd != -1 ) close (slavefd );
302
312
if (masterfd != -1 ) close (masterfd );
@@ -348,17 +358,21 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
348
358
349
359
extern char * ptsname (int );
350
360
extern int unlockpt (int );
361
+ extern int grantpt (int );
351
362
352
363
#if defined(__sun )
353
364
/* workaround for Solaris 10: grantpt() doesn't work if FD_CLOEXEC is set. [ruby-dev:44688] */
354
365
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 ;
356
368
rb_fd_fix_cloexec (masterfd );
357
369
#else
358
370
if ((masterfd = rb_cloexec_open ("/dev/ptmx" , O_RDWR , 0 )) == -1 ) goto error ;
359
371
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 ;
361
374
#endif
375
+ signal (SIGCHLD , s );
362
376
if (unlockpt (masterfd ) == -1 ) goto error ;
363
377
if ((slavedevice = ptsname (masterfd )) == NULL ) goto error ;
364
378
if (no_mesg (slavedevice , nomesg ) == -1 ) goto error ;
0 commit comments