comparison svr-chansession.c @ 427:5df05d0a5366 channel-fix

Revert to default sigchld handler after forking, don't exit on error writing to the signal_pipe.
author Matt Johnston <matt@ucc.asn.au>
date Mon, 12 Feb 2007 13:32:30 +0000
parents b2b67cfcd66e
children 1009980436c2 4317be8b7cf9
comparison
equal deleted inserted replaced
424:db976892c67f 427:5df05d0a5366
124 exit->exitsignal = -1; 124 exit->exitsignal = -1;
125 } 125 }
126 126
127 /* Make sure that the main select() loop wakes up */ 127 /* Make sure that the main select() loop wakes up */
128 while (1) { 128 while (1) {
129 /* EAGAIN means the pipe's full, so don't need to write anything */ 129 /* isserver is just a random byte to write. We can't do anything
130 /* isserver is just a random byte to write */ 130 about an error so should just ignore it */
131 if (write(ses.signal_pipe[1], &ses.isserver, 1) == 1 131 if (write(ses.signal_pipe[1], &ses.isserver, 1) == 1
132 || errno == EAGAIN) { 132 || errno != EINTR) {
133 break; 133 break;
134 } 134 }
135 if (errno == EINTR) {
136 continue;
137 }
138 dropbear_exit("error writing signal pipe");
139 } 135 }
140 } 136 }
141 137
142 sa_chld.sa_handler = sesssigchild_handler; 138 sa_chld.sa_handler = sesssigchild_handler;
143 sa_chld.sa_flags = SA_NOCLDSTOP; 139 sa_chld.sa_flags = SA_NOCLDSTOP;
660 return DROPBEAR_FAILURE; 656 return DROPBEAR_FAILURE;
661 657
662 if (!pid) { 658 if (!pid) {
663 /* child */ 659 /* child */
664 660
661 TRACE(("back to normal sigchld"))
662 /* Revert to normal sigchld handling */
663 if (signal(SIGCHLD, SIG_DFL) == SIG_ERR) {
664 dropbear_exit("signal() error");
665 }
666
665 /* redirect stdin/stdout */ 667 /* redirect stdin/stdout */
666 #define FDIN 0 668 #define FDIN 0
667 #define FDOUT 1 669 #define FDOUT 1
668 if ((dup2(infds[FDIN], STDIN_FILENO) < 0) || 670 if ((dup2(infds[FDIN], STDIN_FILENO) < 0) ||
669 (dup2(outfds[FDOUT], STDOUT_FILENO) < 0) || 671 (dup2(outfds[FDOUT], STDOUT_FILENO) < 0) ||
756 if (pid < 0) 758 if (pid < 0)
757 return DROPBEAR_FAILURE; 759 return DROPBEAR_FAILURE;
758 760
759 if (pid == 0) { 761 if (pid == 0) {
760 /* child */ 762 /* child */
763
764 TRACE(("back to normal sigchld"))
765 /* Revert to normal sigchld handling */
766 if (signal(SIGCHLD, SIG_DFL) == SIG_ERR) {
767 dropbear_exit("signal() error");
768 }
761 769
762 /* redirect stdin/stdout/stderr */ 770 /* redirect stdin/stdout/stderr */
763 close(chansess->master); 771 close(chansess->master);
764 772
765 pty_make_controlling_tty(&chansess->slave, chansess->tty); 773 pty_make_controlling_tty(&chansess->slave, chansess->tty);