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.45 by root, Tue Jan 17 18:06:14 2006 UTC vs.
Revision 1.48 by ayin, Thu Jan 19 10:44:44 2006 UTC

276static int 276static int
277control_tty (int fd_tty) 277control_tty (int fd_tty)
278{ 278{
279 setsid (); 279 setsid ();
280 280
281# if defined(PTYS_ARE_PTMX) && defined(I_PUSH) 281#if defined(PTYS_ARE_PTMX) && defined(I_PUSH)
282 /* 282 /*
283 * Push STREAMS modules: 283 * Push STREAMS modules:
284 * ptem: pseudo-terminal hardware emulation module. 284 * ptem: pseudo-terminal hardware emulation module.
285 * ldterm: standard terminal line discipline. 285 * ldterm: standard terminal line discipline.
286 * ttcompat: V7, 4BSD and XENIX STREAMS compatibility module. 286 * ttcompat: V7, 4BSD and XENIX STREAMS compatibility module.
294 * documentation is really unclear about whether it is any close () on 294 * documentation is really unclear about whether it is any close () on
295 * the master side or the last close () - i.e. a proper STREAMS dismantling 295 * the master side or the last close () - i.e. a proper STREAMS dismantling
296 * close () - on the master side which causes a hang up to be sent 296 * close () - on the master side which causes a hang up to be sent
297 * through - Geoff Wing 297 * through - Geoff Wing
298 */ 298 */
299# ifdef HAVE_ISASTREAM 299# ifdef HAVE_ISASTREAM
300 if (isastream (fd_tty) == 1) 300 if (isastream (fd_tty) == 1)
301# endif 301# endif
302 { 302 {
303 ioctl (fd_tty, I_PUSH, "ptem"); 303 ioctl (fd_tty, I_PUSH, "ptem");
304 ioctl (fd_tty, I_PUSH, "ldterm"); 304 ioctl (fd_tty, I_PUSH, "ldterm");
305 ioctl (fd_tty, I_PUSH, "ttcompat"); 305 ioctl (fd_tty, I_PUSH, "ttcompat");
306 } 306 }
307# endif 307#endif
308 308
309 ioctl (fd_tty, TIOCSCTTY, NULL); 309 ioctl (fd_tty, TIOCSCTTY, NULL);
310 310
311 int fd = open ("/dev/tty", O_WRONLY); 311 int fd = open ("/dev/tty", O_WRONLY);
312 if (fd < 0) 312 if (fd < 0)
379 } 379 }
380 else 380 else
381#endif /* TTY_GID_SUPPORT */ 381#endif /* TTY_GID_SUPPORT */
382 { 382 {
383 mode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH; 383 mode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH;
384 gid = getgid (); 384 gid = 0;
385 } 385 }
386 } 386 }
387} ttyconf; 387} ttyconf;
388 388
389///////////////////////////////////////////////////////////////////////////// 389/////////////////////////////////////////////////////////////////////////////
394 if (!name || !*name) 394 if (!name || !*name)
395 return; 395 return;
396 396
397 if (action == SAVE) 397 if (action == SAVE)
398 { 398 {
399# ifndef RESET_TTY_TO_COMMON_DEFAULTS 399 chown (name, getuid (), ttyconf.gid); /* fail silently */
400 /* store original tty status for restoration rxvt_clean_exit () -- rgg 04/12/95 */ 400 chmod (name, ttyconf.mode);
401 if (lstat (name, &savestat) < 0) /* you lose out */ 401# ifdef HAVE_REVOKE
402 ; 402 revoke (name);
403 else
404# endif 403# endif
405 {
406 saved = true;
407 chown (name, getuid (), ttyconf.gid); /* fail silently */
408 chmod (name, ttyconf.mode);
409# ifdef HAVE_REVOKE
410 revoke (name);
411# endif
412 }
413 } 404 }
414 else 405 else
415 { /* action == RESTORE */ 406 { /* action == RESTORE */
416# ifndef RESET_TTY_TO_COMMON_DEFAULTS 407 chmod (name, RESTORE_TTY_MODE);
417 if (saved)
418 {
419 chmod (name, savestat.st_mode);
420 chown (name, savestat.st_uid, savestat.st_gid);
421 }
422# else
423 chmod (name, (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH));
424 chown (name, 0, 0); 408 chown (name, 0, ttyconf.gid);
425# endif
426 } 409 }
427} 410}
428#endif 411#endif
429 412
430rxvt_ptytty_unix::rxvt_ptytty_unix () 413rxvt_ptytty_unix::rxvt_ptytty_unix ()
431{ 414{
432 pty = tty = -1; 415 pty = tty = -1;
433 name = 0; 416 name = 0;
434#ifndef NO_SETOWNER_TTYDEV
435 saved = false;
436#endif
437#if UTMP_SUPPORT 417#if UTMP_SUPPORT
438 cmd_pid = 0; 418 cmd_pid = 0;
439#endif 419#endif
440} 420}
441 421
636 close (sv[1]); 616 close (sv[1]);
637 fcntl (sock_fd, F_SETFD, FD_CLOEXEC); 617 fcntl (sock_fd, F_SETFD, FD_CLOEXEC);
638 } 618 }
639 else 619 else
640 { 620 {
641 setgid (getegid ());
642 setuid (geteuid ());
643
644 // server, pty-helper 621 // server, pty-helper
645 sock_fd = sv[1]; 622 sock_fd = sv[1];
646 623
647 for (int fd = 0; fd < 1023; fd++) 624 for (int fd = 0; fd < 1023; fd++)
648 if (fd != sock_fd && fd != 1) 625 if (fd != sock_fd)
649 close (fd); 626 close (fd);
650 627
651 serve (); 628 serve ();
652 _exit (EXIT_SUCCESS); 629 _exit (EXIT_SUCCESS);
653 } 630 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines