Diff

Differences From Artifact [03a93dabca]:

To Artifact [f3667395ba]:


271
272
273
274
275
276
277
278
279


280
281
282
283
284
285
286
    setuid(getuid());
    raise(signum);
}
#endif

static int pty_open_slave(Pty pty)
{
    if (pty->slave_fd < 0)
	pty->slave_fd = open(pty->name, O_RDWR);



    return pty->slave_fd;
}

static void pty_open_master(Pty pty)
{
#ifdef BSD_PTYS







|

>
>







271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
    setuid(getuid());
    raise(signum);
}
#endif

static int pty_open_slave(Pty pty)
{
    if (pty->slave_fd < 0) {
	pty->slave_fd = open(pty->name, O_RDWR);
        fcntl(pty->slave_fd, F_SETFD, FD_CLOEXEC);
    }

    return pty->slave_fd;
}

static void pty_open_master(Pty pty)
{
#ifdef BSD_PTYS
302
303
304
305
306
307
308


309
310
311
312
313
314
315
		     * able to open the slave side of the pty. We
		     * wouldn't want to allocate the wrong master,
		     * get all the way down to forking, and _then_
		     * find we're unable to open the slave.
		     */
		    strcpy(pty->name, master_name);
		    pty->name[5] = 't'; /* /dev/ptyXX -> /dev/ttyXX */



		    if (pty_open_slave(pty) >= 0 &&
			access(pty->name, R_OK | W_OK) == 0)
			goto got_one;
		    if (pty->slave_fd > 0)
			close(pty->slave_fd);
		    pty->slave_fd = -1;







>
>







304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
		     * able to open the slave side of the pty. We
		     * wouldn't want to allocate the wrong master,
		     * get all the way down to forking, and _then_
		     * find we're unable to open the slave.
		     */
		    strcpy(pty->name, master_name);
		    pty->name[5] = 't'; /* /dev/ptyXX -> /dev/ttyXX */

                    fcntl(pty->master_fd, F_SETFD, FD_CLOEXEC);

		    if (pty_open_slave(pty) >= 0 &&
			access(pty->name, R_OK | W_OK) == 0)
			goto got_one;
		    if (pty->slave_fd > 0)
			close(pty->slave_fd);
		    pty->slave_fd = -1;
341
342
343
344
345
346
347


348
349
350
351
352
353
354
	exit(1);
    }
    
    if (unlockpt(pty->master_fd) < 0) {
	perror("unlockpt");
	exit(1);
    }



    pty->name[FILENAME_MAX-1] = '\0';
    strncpy(pty->name, ptsname(pty->master_fd), FILENAME_MAX-1);
#endif

    {
        /*







>
>







345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
	exit(1);
    }
    
    if (unlockpt(pty->master_fd) < 0) {
	perror("unlockpt");
	exit(1);
    }

    fcntl(pty->master_fd, F_SETFD, FD_CLOEXEC);

    pty->name[FILENAME_MAX-1] = '\0';
    strncpy(pty->name, ptsname(pty->master_fd), FILENAME_MAX-1);
#endif

    {
        /*