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.49 by ayin, Thu Jan 19 16:40:42 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
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 pty = tty = -1;
391 name = 0;
392#if UTMP_SUPPORT
393 cmd_pid = 0;
394#endif
395}
396
397rxvt_ptytty_unix::~rxvt_ptytty_unix ()
398{
399#if UTMP_SUPPORT
400 logout ();
401#endif
402 put ();
403}
390 404
391void 405void
392rxvt_ptytty_unix::privileges (rxvt_privaction action) 406rxvt_ptytty_unix::put ()
393{ 407{
394 if (!name || !*name) 408 chmod (name, RESTORE_TTY_MODE);
409 chown (name, 0, ttyconf.gid);
410
411 if (pty >= 0) close (pty);
412 close_tty ();
413 free (name);
414
415 pty = tty = -1;
416 name = 0;
417}
418
419bool
420rxvt_ptytty_unix::get ()
421{
422 /* get master (pty) */
423 if ((pty = get_pty (&tty, &name)) < 0)
395 return; 424 return false;
396 425
397 if (action == SAVE) 426 fcntl (pty, F_SETFL, O_NONBLOCK);
427
428 /* get slave (tty) */
429 if (tty < 0)
398 { 430 {
431#ifndef NO_SETOWNER_TTYDEV
399 chown (name, getuid (), ttyconf.gid); /* fail silently */ 432 chown (name, getuid (), ttyconf.gid); /* fail silently */
400 chmod (name, ttyconf.mode); 433 chmod (name, ttyconf.mode);
401# ifdef HAVE_REVOKE 434# ifdef HAVE_REVOKE
402 revoke (name); 435 revoke (name);
403# endif 436# 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 437#endif
460 438
461 if ((tty = get_tty (name)) < 0) 439 if ((tty = get_tty (name)) < 0)
462 { 440 {
463 put (); 441 put ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines