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

Comparing libptytty/src/ptytty.C (file contents):
Revision 1.16 by root, Mon Jan 23 11:22:34 2006 UTC vs.
Revision 1.19 by root, Mon Jan 23 11:36:01 2006 UTC

29 29
30#include "ptytty.h" 30#include "ptytty.h"
31 31
32#include <cstdlib> 32#include <cstdlib>
33#include <cstring> 33#include <cstring>
34#include <csignal>
34 35
35#include <sys/types.h> 36#include <sys/types.h>
36#include <sys/socket.h> 37#include <sys/socket.h>
37#include <unistd.h> 38#include <unistd.h>
38#include <fcntl.h> 39#include <fcntl.h>
376///////////////////////////////////////////////////////////////////////////// 377/////////////////////////////////////////////////////////////////////////////
377// helper/proxy support 378// helper/proxy support
378 379
379#if PTYTTY_HELPER 380#if PTYTTY_HELPER
380 381
381static int sock_fd = -1; 382static int sock_fd = -1, lock_fd = -1;
382static int helper_pid, owner_pid; 383static int helper_pid, owner_pid;
383 384
384struct command 385struct command
385{ 386{
386 enum { get, login, destroy } type; 387 enum { get, login, destroy } type;
526 int sv[2]; 527 int sv[2];
527 528
528 if (socketpair (AF_UNIX, SOCK_STREAM, 0, sv)) 529 if (socketpair (AF_UNIX, SOCK_STREAM, 0, sv))
529 ptytty_fatal ("could not create socket to communicate with pty/sessiondb helper, aborting.\n"); 530 ptytty_fatal ("could not create socket to communicate with pty/sessiondb helper, aborting.\n");
530 531
532#ifdef PTYTTY_REENTRANT
533 int lv[2];
534
535 if (socketpair (AF_UNIX, SOCK_STREAM, 0, lv))
536 ptytty_fatal ("could not create socket to communicate with pty/sessiondb helper, aborting.\n");
537#endif
538
531 helper_pid = fork (); 539 helper_pid = fork ();
532 540
533 if (helper_pid < 0) 541 if (helper_pid < 0)
534 ptytty_fatal ("could not create pty/sessiondb helper process, aborting.\n"); 542 ptytty_fatal ("could not create pty/sessiondb helper process, aborting.\n");
535 543
537 { 545 {
538 // client, process 546 // client, process
539 sock_fd = sv[0]; 547 sock_fd = sv[0];
540 close (sv[1]); 548 close (sv[1]);
541 fcntl (sock_fd, F_SETFD, FD_CLOEXEC); 549 fcntl (sock_fd, F_SETFD, FD_CLOEXEC);
550#ifdef PTYTTY_REENTRANT
551 lock_fd = lv[0];
552 close (lv[1]);
553 fcntl (lock_fd, F_SETFD, FD_CLOEXEC);
554#endif
542 } 555 }
543 else 556 else
544 { 557 {
545 // server, pty-helper 558 // server, pty-helper
546 sock_fd = sv[1]; 559 sock_fd = sv[1];
560#ifdef PTYTTY_REENTRANT
561 lock_fd = lv[1];
562#endif
547 563
548 chdir ("/"); 564 chdir ("/");
549 565
566 signal (SIGHUP, SIG_IGN);
567 signal (SIGTERM, SIG_IGN);
568 signal (SIGINT, SIG_IGN);
569 signal (SIGPIPE, SIG_IGN);
570
550 for (int fd = 0; fd < 1023; fd++) 571 for (int fd = 0; fd < 1023; fd++)
551 if (fd != sock_fd) 572 if (fd != sock_fd && fd != lock_fd)
552 close (fd); 573 close (fd);
553 574
554 serve (); 575 serve ();
555 _exit (EXIT_SUCCESS); 576 _exit (EXIT_SUCCESS);
556 } 577 }
636extern "C" retval ptytty_ ## name args \ 657extern "C" retval ptytty_ ## name args \
637{ return ptytty::name args; } 658{ return ptytty::name args; }
638 659
639DEFINE_STATIC(void,drop_privileges,()) 660DEFINE_STATIC(void,drop_privileges,())
640DEFINE_STATIC(void,use_helper,()) 661DEFINE_STATIC(void,use_helper,())
641
642DEFINE_STATIC(void,init,()) 662DEFINE_STATIC(void,init,())
663
643DEFINE_STATIC(void *,create,()) 664DEFINE_STATIC(void *,create,())
644 665
645void ptytty_delete (void *ptytty) 666void ptytty_delete (void *ptytty)
646{ 667{
647 delete (struct ptytty *)ptytty; 668 delete (struct ptytty *)ptytty;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines