comparison svr-chansession.c @ 398:59c7938af2bd

merge of '1250b8af44b62d8f4fe0f8d9fc7e7a1cc34e7e1c' and '7f8670ac3bb975f40967f3979d09d2199b7e90c8'
author Matt Johnston <matt@ucc.asn.au>
date Sat, 03 Feb 2007 08:20:30 +0000
parents e7c1a77d2921 a124aff0cbf1
children 173a5f89666c
comparison
equal deleted inserted replaced
396:e7c1a77d2921 398:59c7938af2bd
87 struct sigaction sa_chld; 87 struct sigaction sa_chld;
88 struct exitinfo *exit = NULL; 88 struct exitinfo *exit = NULL;
89 89
90 TRACE(("enter sigchld handler")) 90 TRACE(("enter sigchld handler"))
91 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { 91 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
92
93 exit = NULL;
92 /* find the corresponding chansess */ 94 /* find the corresponding chansess */
93 for (i = 0; i < svr_ses.childpidsize; i++) { 95 for (i = 0; i < svr_ses.childpidsize; i++) {
94 if (svr_ses.childpids[i].pid == pid) { 96 if (svr_ses.childpids[i].pid == pid) {
95 97
96 exit = &svr_ses.childpids[i].chansess->exit; 98 exit = &svr_ses.childpids[i].chansess->exit;
98 } 100 }
99 } 101 }
100 102
101 /* If the pid wasn't matched, then we might have hit the race mentioned 103 /* If the pid wasn't matched, then we might have hit the race mentioned
102 * above. So we just store the info for the parent to deal with */ 104 * above. So we just store the info for the parent to deal with */
103 if (i == svr_ses.childpidsize) { 105 if (exit == NULL) {
104 exit = &svr_ses.lastexit; 106 exit = &svr_ses.lastexit;
105 } 107 }
106 108
107 exit->exitpid = pid; 109 exit->exitpid = pid;
108 if (WIFEXITED(status)) { 110 if (WIFEXITED(status)) {
117 #endif 119 #endif
118 } else { 120 } else {
119 /* we use this to determine how pid exited */ 121 /* we use this to determine how pid exited */
120 exit->exitsignal = -1; 122 exit->exitsignal = -1;
121 } 123 }
122 exit = NULL;
123 } 124 }
124 125
125 126
126 sa_chld.sa_handler = sesssigchild_handler; 127 sa_chld.sa_handler = sesssigchild_handler;
127 sa_chld.sa_flags = SA_NOCLDSTOP; 128 sa_chld.sa_flags = SA_NOCLDSTOP;
585 m_free(chansess->cmd); 586 m_free(chansess->cmd);
586 return DROPBEAR_FAILURE; 587 return DROPBEAR_FAILURE;
587 } 588 }
588 } 589 }
589 } 590 }
591
592 #ifdef LOG_COMMANDS
593 if (chansess->cmd) {
594 dropbear_log(LOG_INFO, "user %s executing '%s'",
595 ses.authstate.printableuser, chansess->cmd);
596 } else {
597 dropbear_log(LOG_INFO, "user %s executing login shell",
598 ses.authstate.printableuser);
599 }
600 #endif
590 601
591 if (chansess->term == NULL) { 602 if (chansess->term == NULL) {
592 /* no pty */ 603 /* no pty */
593 ret = noptycommand(channel, chansess); 604 ret = noptycommand(channel, chansess);
594 } else { 605 } else {
995 newvar = m_malloc(plen + vlen + 2); /* 2 is for '=' and '\0' */ 1006 newvar = m_malloc(plen + vlen + 2); /* 2 is for '=' and '\0' */
996 memcpy(newvar, param, plen); 1007 memcpy(newvar, param, plen);
997 newvar[plen] = '='; 1008 newvar[plen] = '=';
998 memcpy(&newvar[plen+1], var, vlen); 1009 memcpy(&newvar[plen+1], var, vlen);
999 newvar[plen+vlen+1] = '\0'; 1010 newvar[plen+vlen+1] = '\0';
1011 /* newvar is leaked here, but that's part of putenv()'s semantics */
1000 if (putenv(newvar) < 0) { 1012 if (putenv(newvar) < 0) {
1001 dropbear_exit("environ error"); 1013 dropbear_exit("environ error");
1002 } 1014 }
1003 } 1015 }