diff 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
line wrap: on
line diff
--- a/svr-chansession.c	Sat Feb 03 08:09:55 2007 +0000
+++ b/svr-chansession.c	Sat Feb 03 08:20:30 2007 +0000
@@ -89,6 +89,8 @@
 
 	TRACE(("enter sigchld handler"))
 	while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
+
+		exit = NULL;
 		/* find the corresponding chansess */
 		for (i = 0; i < svr_ses.childpidsize; i++) {
 			if (svr_ses.childpids[i].pid == pid) {
@@ -100,7 +102,7 @@
 
 		/* If the pid wasn't matched, then we might have hit the race mentioned
 		 * above. So we just store the info for the parent to deal with */
-		if (i == svr_ses.childpidsize) {
+		if (exit == NULL) {
 			exit = &svr_ses.lastexit;
 		}
 
@@ -119,7 +121,6 @@
 			/* we use this to determine how pid exited */
 			exit->exitsignal = -1;
 		}
-		exit = NULL;
 	}
 
 	
@@ -588,6 +589,16 @@
 		}
 	}
 
+#ifdef LOG_COMMANDS
+	if (chansess->cmd) {
+		dropbear_log(LOG_INFO, "user %s executing '%s'", 
+						ses.authstate.printableuser, chansess->cmd);
+	} else {
+		dropbear_log(LOG_INFO, "user %s executing login shell", 
+						ses.authstate.printableuser);
+	}
+#endif
+
 	if (chansess->term == NULL) {
 		/* no pty */
 		ret = noptycommand(channel, chansess);
@@ -997,6 +1008,7 @@
 	newvar[plen] = '=';
 	memcpy(&newvar[plen+1], var, vlen);
 	newvar[plen+vlen+1] = '\0';
+	/* newvar is leaked here, but that's part of putenv()'s semantics */
 	if (putenv(newvar) < 0) {
 		dropbear_exit("environ error");
 	}