ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/ptytty.C
(Generate patch)

Comparing rxvt-unicode/src/ptytty.C (file contents):
Revision 1.16 by root, Sun Aug 15 03:30:04 2004 UTC vs.
Revision 1.29 by root, Fri Jan 6 02:11:15 2006 UTC

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
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
85 if (*ttydev != NULL) 94 if (*ttydev != NULL)
86 return pfd; 95 return pfd;
87#endif 96#endif
88 97
89#ifdef PTYS_ARE_GETPTY 98#ifdef PTYS_ARE_GETPTY
90
91 char *ptydev; 99 char *ptydev;
92 100
93 while ((ptydev = getpty ()) != NULL) 101 while ((ptydev = getpty ()) != NULL)
94 if ((pfd = open (ptydev, O_RDWR | O_NOCTTY, 0)) >= 0) 102 if ((pfd = open (ptydev, O_RDWR | O_NOCTTY, 0)) >= 0)
95 { 103 {
329} ttyconf; 337} ttyconf;
330 338
331void 339void
332rxvt_ptytty::privileges (rxvt_privaction action) 340rxvt_ptytty::privileges (rxvt_privaction action)
333{ 341{
342 if (!name || !*name)
343 return;
344
334 rxvt_privileges (RESTORE); 345 rxvt_privileges (RESTORE);
335 346
336 if (action == SAVE) 347 if (action == SAVE)
337 { 348 {
338 //next_tty_action = RESTORE;
339# ifndef RESET_TTY_TO_COMMON_DEFAULTS 349# ifndef RESET_TTY_TO_COMMON_DEFAULTS
340 /* store original tty status for restoration rxvt_clean_exit () -- rgg 04/12/95 */ 350 /* store original tty status for restoration rxvt_clean_exit () -- rgg 04/12/95 */
341 if (lstat (name, &savestat) < 0) /* you lose out */ 351 if (lstat (name, &savestat) < 0) /* you lose out */
342 ;//next_tty_action = IGNORE; 352 ;
343 else 353 else
344# endif 354# endif
345
346 { 355 {
356 saved = true;
347 chown (name, getuid (), ttyconf.gid); /* fail silently */ 357 chown (name, getuid (), ttyconf.gid); /* fail silently */
348 chmod (name, ttyconf.mode); 358 chmod (name, ttyconf.mode);
349# ifdef HAVE_REVOKE 359# ifdef HAVE_REVOKE
350 revoke (name); 360 revoke (name);
351# endif 361# endif
352
353 } 362 }
354 } 363 }
355 else 364 else
356 { /* action == RESTORE */ 365 { /* action == RESTORE */
357 //next_tty_action = IGNORE;
358# ifndef RESET_TTY_TO_COMMON_DEFAULTS 366# ifndef RESET_TTY_TO_COMMON_DEFAULTS
367 if (saved)
368 {
359 chmod (name, savestat.st_mode); 369 chmod (name, savestat.st_mode);
360 chown (name, savestat.st_uid, savestat.st_gid); 370 chown (name, savestat.st_uid, savestat.st_gid);
371 }
361# else 372# else
362 chmod (name, (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)); 373 chmod (name, (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH));
363 chown (name, 0, 0); 374 chown (name, 0, 0);
364# endif 375# endif
365 376
371 382
372rxvt_ptytty::rxvt_ptytty () 383rxvt_ptytty::rxvt_ptytty ()
373{ 384{
374 pty = tty = -1; 385 pty = tty = -1;
375 name = 0; 386 name = 0;
387#ifndef NO_SETOWNER_TTYDEV
388 saved = false;
389#endif
376} 390}
377 391
378rxvt_ptytty::~rxvt_ptytty () 392rxvt_ptytty::~rxvt_ptytty ()
379{ 393{
380 put (); 394 put ();
382 396
383void 397void
384 398
385rxvt_ptytty::close_tty () 399rxvt_ptytty::close_tty ()
386{ 400{
387 if (tty >= 0) close (tty); 401 if (tty < 0)
402 return;
403
404 close (tty);
388 tty = -1; 405 tty = -1;
389} 406}
390 407
391void 408void
392rxvt_ptytty::put () 409rxvt_ptytty::put ()
393{ 410{
394#ifndef NO_SETOWNER_TTYDEV 411#ifndef NO_SETOWNER_TTYDEV
395 if (tty >= 0)
396 privileges (RESTORE); 412 privileges (RESTORE);
397#endif 413#endif
398 414
399 if (pty >= 0) close (pty); 415 if (pty >= 0) close (pty);
400 close_tty (); 416 close_tty ();
401 free (name); 417 free (name);
434 } 450 }
435 451
436 return true; 452 return true;
437} 453}
438 454
455void
456rxvt_ptytty::set_utf8_mode (bool on)
457{
458#ifdef IUTF8
459 if (pty < 0)
460 return;
461
462 struct termios tio;
463
464 if (tcgetattr (pty, &tio) != -1)
465 {
466 tcflag_t new_cflag = tio.c_iflag;
467
468 if (on)
469 new_cflag |= IUTF8;
470 else
471 new_cflag &= ~IUTF8;
472
473 if (new_cflag != tio.c_iflag)
474 {
475 tio.c_iflag = new_cflag;
476 tcsetattr (pty, TCSANOW, &tio);
477 }
478 }
479#endif
480}
481
439/*----------------------- end-of-file (C source) -----------------------*/ 482/*----------------------- end-of-file (C source) -----------------------*/
440 483

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines