… | |
… | |
46 | # include <sys/stropts.h> /* for I_PUSH */ |
46 | # include <sys/stropts.h> /* for I_PUSH */ |
47 | #endif |
47 | #endif |
48 | #ifdef HAVE_ISASTREAM |
48 | #ifdef HAVE_ISASTREAM |
49 | # include <stropts.h> |
49 | # include <stropts.h> |
50 | #endif |
50 | #endif |
|
|
51 | #ifdef HAVE_PTY_H |
|
|
52 | # include <pty.h> |
|
|
53 | #endif |
51 | |
54 | |
52 | #if defined( __FreeBSD__) |
|
|
53 | // better do this via configure, but.... |
55 | // better do this via configure, but.... |
|
|
56 | #if defined(__FreeBSD__) |
54 | # include <libutil.h> |
57 | # include <libutil.h> |
|
|
58 | #elif defined(__DARWIN__) || (defined (__MACH__) && defined (__APPLE__)) |
|
|
59 | # include <util.h> |
55 | #endif |
60 | #endif |
56 | |
61 | |
57 | #include <cstdio> |
62 | #include <cstdio> |
58 | #include <grp.h> |
63 | #include <grp.h> |
59 | |
64 | |
… | |
… | |
69 | get_pty (int *fd_tty, char **ttydev) |
74 | get_pty (int *fd_tty, char **ttydev) |
70 | { |
75 | { |
71 | int pfd; |
76 | int pfd; |
72 | |
77 | |
73 | #ifdef PTYS_ARE_OPENPTY |
78 | #ifdef PTYS_ARE_OPENPTY |
74 | char tty_name[sizeof "/dev/pts/????\0"]; |
79 | char tty_name[sizeof "/dev/pts/?????\0"]; |
75 | |
80 | |
|
|
81 | rxvt_privileges (RESTORE); |
76 | if (openpty (&pfd, fd_tty, tty_name, NULL, NULL) != -1) |
82 | int res = openpty (&pfd, fd_tty, tty_name, NULL, NULL); |
|
|
83 | rxvt_privileges (IGNORE); |
|
|
84 | |
|
|
85 | if (res != -1) |
77 | { |
86 | { |
78 | *ttydev = strdup (tty_name); |
87 | *ttydev = strdup (tty_name); |
79 | return pfd; |
88 | return pfd; |
80 | } |
89 | } |
81 | #endif |
90 | #endif |
… | |
… | |
329 | } ttyconf; |
338 | } ttyconf; |
330 | |
339 | |
331 | void |
340 | void |
332 | rxvt_ptytty::privileges (rxvt_privaction action) |
341 | rxvt_ptytty::privileges (rxvt_privaction action) |
333 | { |
342 | { |
|
|
343 | if (tty < 0) |
|
|
344 | return; |
|
|
345 | |
334 | rxvt_privileges (RESTORE); |
346 | rxvt_privileges (RESTORE); |
335 | |
347 | |
336 | if (action == SAVE) |
348 | if (action == SAVE) |
337 | { |
349 | { |
338 | //next_tty_action = RESTORE; |
350 | //next_tty_action = RESTORE; |
… | |
… | |
340 | /* store original tty status for restoration rxvt_clean_exit () -- rgg 04/12/95 */ |
352 | /* store original tty status for restoration rxvt_clean_exit () -- rgg 04/12/95 */ |
341 | if (lstat (name, &savestat) < 0) /* you lose out */ |
353 | if (lstat (name, &savestat) < 0) /* you lose out */ |
342 | ;//next_tty_action = IGNORE; |
354 | ;//next_tty_action = IGNORE; |
343 | else |
355 | else |
344 | # endif |
356 | # endif |
345 | |
|
|
346 | { |
357 | { |
347 | chown (name, getuid (), ttyconf.gid); /* fail silently */ |
358 | chown (name, getuid (), ttyconf.gid); /* fail silently */ |
348 | chmod (name, ttyconf.mode); |
359 | chmod (name, ttyconf.mode); |
349 | # ifdef HAVE_REVOKE |
360 | # ifdef HAVE_REVOKE |
350 | revoke (name); |
361 | revoke (name); |
351 | # endif |
362 | # endif |
352 | |
|
|
353 | } |
363 | } |
354 | } |
364 | } |
355 | else |
365 | else |
356 | { /* action == RESTORE */ |
366 | { /* action == RESTORE */ |
357 | //next_tty_action = IGNORE; |
367 | //next_tty_action = IGNORE; |
… | |
… | |
434 | } |
444 | } |
435 | |
445 | |
436 | return true; |
446 | return true; |
437 | } |
447 | } |
438 | |
448 | |
|
|
449 | void |
|
|
450 | rxvt_ptytty::set_utf8_mode (bool on) |
|
|
451 | { |
|
|
452 | #ifdef IUTF8 |
|
|
453 | if (pty != -1) |
|
|
454 | { |
|
|
455 | struct termios tio; |
|
|
456 | |
|
|
457 | if (tcgetattr (pty, &tio) != -1) |
|
|
458 | { |
|
|
459 | tcflag_t new_cflag = tio.c_iflag; |
|
|
460 | |
|
|
461 | if (on) |
|
|
462 | new_cflag |= IUTF8; |
|
|
463 | else |
|
|
464 | new_cflag &= ~IUTF8; |
|
|
465 | |
|
|
466 | if (new_cflag != tio.c_iflag) |
|
|
467 | { |
|
|
468 | tio.c_iflag = new_cflag; |
|
|
469 | tcsetattr (pty, TCSANOW, &tio); |
|
|
470 | } |
|
|
471 | } |
|
|
472 | } |
|
|
473 | #endif |
|
|
474 | } |
|
|
475 | |
439 | /*----------------------- end-of-file (C source) -----------------------*/ |
476 | /*----------------------- end-of-file (C source) -----------------------*/ |
440 | |
477 | |