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.25 by root, Sun Jan 1 05:08:41 2006 UTC vs.
Revision 1.26 by root, Mon Jan 2 15:10:18 2006 UTC

74get_pty (int *fd_tty, char **ttydev) 74get_pty (int *fd_tty, char **ttydev)
75{ 75{
76 int pfd; 76 int pfd;
77 77
78#ifdef PTYS_ARE_OPENPTY 78#ifdef PTYS_ARE_OPENPTY
79 char tty_name[sizeof "/dev/pts/?????\0"]; 79 char tty_name[sizeof "/dev/pts/????\0"];
80 80
81 rxvt_privileges (RESTORE);
82 int res = openpty (&pfd, fd_tty, tty_name, NULL, NULL); 81 if (openpty (&pfd, fd_tty, tty_name, NULL, NULL) != -1)
83 rxvt_privileges (IGNORE);
84
85 if (res != -1)
86 { 82 {
87 *ttydev = strdup (tty_name); 83 *ttydev = strdup (tty_name);
88 return pfd; 84 return pfd;
89 } 85 }
90#endif 86#endif
94 if (*ttydev != NULL) 90 if (*ttydev != NULL)
95 return pfd; 91 return pfd;
96#endif 92#endif
97 93
98#ifdef PTYS_ARE_GETPTY 94#ifdef PTYS_ARE_GETPTY
99
100 char *ptydev; 95 char *ptydev;
101 96
102 while ((ptydev = getpty ()) != NULL) 97 while ((ptydev = getpty ()) != NULL)
103 if ((pfd = open (ptydev, O_RDWR | O_NOCTTY, 0)) >= 0) 98 if ((pfd = open (ptydev, O_RDWR | O_NOCTTY, 0)) >= 0)
104 { 99 {
338} ttyconf; 333} ttyconf;
339 334
340void 335void
341rxvt_ptytty::privileges (rxvt_privaction action) 336rxvt_ptytty::privileges (rxvt_privaction action)
342{ 337{
343 if (pty < 0) 338 if (!name || !*name)
344 return; 339 return;
345 340
346 rxvt_privileges (RESTORE); 341 rxvt_privileges (RESTORE);
347 342
348 if (action == SAVE) 343 if (action == SAVE)
349 { 344 {
350 //next_tty_action = RESTORE;
351# ifndef RESET_TTY_TO_COMMON_DEFAULTS 345# ifndef RESET_TTY_TO_COMMON_DEFAULTS
352 /* store original tty status for restoration rxvt_clean_exit () -- rgg 04/12/95 */ 346 /* store original tty status for restoration rxvt_clean_exit () -- rgg 04/12/95 */
353 if (lstat (name, &savestat) < 0) /* you lose out */ 347 if (lstat (name, &savestat) < 0) /* you lose out */
354 ;//next_tty_action = IGNORE; 348 ;
355 else 349 else
356# endif 350# endif
357 { 351 {
352 saved = true;
358 chown (name, getuid (), ttyconf.gid); /* fail silently */ 353 chown (name, getuid (), ttyconf.gid); /* fail silently */
359 chmod (name, ttyconf.mode); 354 chmod (name, ttyconf.mode);
360# ifdef HAVE_REVOKE 355# ifdef HAVE_REVOKE
361 revoke (name); 356 revoke (name);
362# endif 357# endif
363 } 358 }
364 } 359 }
365 else 360 else
366 { /* action == RESTORE */ 361 { /* action == RESTORE */
367 //next_tty_action = IGNORE;
368# ifndef RESET_TTY_TO_COMMON_DEFAULTS 362# ifndef RESET_TTY_TO_COMMON_DEFAULTS
363 if (saved)
364 {
369 chmod (name, savestat.st_mode); 365 chmod (name, savestat.st_mode);
370 chown (name, savestat.st_uid, savestat.st_gid); 366 chown (name, savestat.st_uid, savestat.st_gid);
367 }
371# else 368# else
372 chmod (name, (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)); 369 chmod (name, (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH));
373 chown (name, 0, 0); 370 chown (name, 0, 0);
374# endif 371# endif
375 372
381 378
382rxvt_ptytty::rxvt_ptytty () 379rxvt_ptytty::rxvt_ptytty ()
383{ 380{
384 pty = tty = -1; 381 pty = tty = -1;
385 name = 0; 382 name = 0;
383#ifndef NO_SETOWNER_TTYDEV
384 saved = false;
385#endif
386} 386}
387 387
388rxvt_ptytty::~rxvt_ptytty () 388rxvt_ptytty::~rxvt_ptytty ()
389{ 389{
390 put (); 390 put ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines