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.48 by ayin, Thu Jan 19 10:44:44 2006 UTC vs.
Revision 1.52 by root, Thu Jan 19 20:30:36 2006 UTC

67 * fd_tty _may_ also be set to an open fd to the slave device 67 * fd_tty _may_ also be set to an open fd to the slave device
68 */ 68 */
69static inline int 69static inline int
70get_pty_streams (int *fd_tty, char **ttydev) 70get_pty_streams (int *fd_tty, char **ttydev)
71{ 71{
72#ifdef NO_SETOWNER_TTYDEV 72#if defined(HAVE_GRANTPT) && defined(HAVE_UNLOCKPT)
73# if defined(PTYS_ARE_GETPT) || defined(PTYS_ARE_POSIX) || defined(PTYS_ARE_PTMX)
73 int pfd; 74 int pfd;
74 75
75# if defined(PTYS_ARE_GETPT) 76# if defined(PTYS_ARE_GETPT)
76 pfd = getpt(); 77 pfd = getpt();
77# elif defined(PTYS_ARE_POSIX) 78# elif defined(PTYS_ARE_POSIX)
88 return pfd; 89 return pfd;
89 } 90 }
90 91
91 close (pfd); 92 close (pfd);
92 } 93 }
94# endif
93#endif 95#endif
94 96
95 return -1; 97 return -1;
96} 98}
97 99
99get_pty_openpty (int *fd_tty, char **ttydev) 101get_pty_openpty (int *fd_tty, char **ttydev)
100{ 102{
101#ifdef PTYS_ARE_OPENPTY 103#ifdef PTYS_ARE_OPENPTY
102 int pfd; 104 int pfd;
103 int res; 105 int res;
104 char tty_name[sizeof "/dev/pts/????\0"]; 106 char tty_name[32];
105 107
106 res = openpty (&pfd, fd_tty, tty_name, NULL, NULL); 108 res = openpty (&pfd, fd_tty, tty_name, NULL, NULL);
107 if (res != -1) 109 if (res != -1)
108 { 110 {
109 *ttydev = strdup (tty_name); 111 *ttydev = strdup (tty_name);
358 } 360 }
359 } 361 }
360#endif 362#endif
361} 363}
362 364
363/////////////////////////////////////////////////////////////////////////////
364
365#ifndef NO_SETOWNER_TTYDEV
366static struct ttyconf { 365static struct ttyconf {
367 gid_t gid; 366 gid_t gid;
368 mode_t mode; 367 mode_t mode;
369 368
370 ttyconf () 369 ttyconf ()
384 gid = 0; 383 gid = 0;
385 } 384 }
386 } 385 }
387} ttyconf; 386} ttyconf;
388 387
389///////////////////////////////////////////////////////////////////////////// 388rxvt_ptytty_unix::rxvt_ptytty_unix ()
389{
390 name = 0;
391#if UTMP_SUPPORT
392 cmd_pid = 0;
393#endif
394}
395
396rxvt_ptytty_unix::~rxvt_ptytty_unix ()
397{
398#if UTMP_SUPPORT
399 logout ();
400#endif
401 put ();
402}
390 403
391void 404void
392rxvt_ptytty_unix::privileges (rxvt_privaction action) 405rxvt_ptytty_unix::put ()
393{ 406{
394 if (!name || !*name) 407 chmod (name, RESTORE_TTY_MODE);
408 chown (name, 0, ttyconf.gid);
409
410 close_tty ();
411
412 if (pty >= 0)
413 close (pty);
414
415 free (name);
416
417 pty = tty = -1;
418 name = 0;
419}
420
421bool
422rxvt_ptytty_unix::get ()
423{
424 /* get master (pty) */
425 if ((pty = get_pty (&tty, &name)) < 0)
395 return; 426 return false;
396 427
397 if (action == SAVE) 428 fcntl (pty, F_SETFL, O_NONBLOCK);
429
430 /* get slave (tty) */
431 if (tty < 0)
398 { 432 {
433#ifndef NO_SETOWNER_TTYDEV
399 chown (name, getuid (), ttyconf.gid); /* fail silently */ 434 chown (name, getuid (), ttyconf.gid); /* fail silently */
400 chmod (name, ttyconf.mode); 435 chmod (name, ttyconf.mode);
401# ifdef HAVE_REVOKE 436# ifdef HAVE_REVOKE
402 revoke (name); 437 revoke (name);
403# endif 438# endif
404 }
405 else
406 { /* action == RESTORE */
407 chmod (name, RESTORE_TTY_MODE);
408 chown (name, 0, ttyconf.gid);
409 }
410}
411#endif
412
413rxvt_ptytty_unix::rxvt_ptytty_unix ()
414{
415 pty = tty = -1;
416 name = 0;
417#if UTMP_SUPPORT
418 cmd_pid = 0;
419#endif
420}
421
422rxvt_ptytty_unix::~rxvt_ptytty_unix ()
423{
424#if UTMP_SUPPORT
425 logout ();
426#endif
427 put ();
428}
429
430void
431rxvt_ptytty_unix::put ()
432{
433#ifndef NO_SETOWNER_TTYDEV
434 privileges (RESTORE);
435#endif
436
437 if (pty >= 0) close (pty);
438 close_tty ();
439 free (name);
440
441 pty = tty = -1;
442 name = 0;
443}
444
445bool
446rxvt_ptytty_unix::get ()
447{
448 /* get master (pty) */
449 if ((pty = get_pty (&tty, &name)) < 0)
450 return false;
451
452 fcntl (pty, F_SETFL, O_NONBLOCK);
453
454 /* get slave (tty) */
455 if (tty < 0)
456 {
457#ifndef NO_SETOWNER_TTYDEV
458 privileges (SAVE);
459#endif 439#endif
460 440
461 if ((tty = get_tty (name)) < 0) 441 if ((tty = get_tty (name)) < 0)
462 { 442 {
463 put (); 443 put ();
627 607
628 serve (); 608 serve ();
629 _exit (EXIT_SUCCESS); 609 _exit (EXIT_SUCCESS);
630 } 610 }
631} 611}
612
632#endif 613#endif
633 614
634// a "factory" *g* 615// a "factory" *g*
635rxvt_ptytty * 616rxvt_ptytty *
636rxvt_new_ptytty () 617rxvt_new_ptytty ()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines