summaryrefslogtreecommitdiff
path: root/debian/patches/ssh-sigchld.patch
blob: 21d286b210f7c4f448c064b3e1267b86bd623a99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Description: Install a SIGCHLD handler to reap expired child processes
Origin: upstream, http://bazaar.launchpad.net/~vcs-imports/openssh/main/revision/6166
Bug-Debian: http://bugs.debian.org/594687
Bug: https://bugzilla.mindrot.org/show_bug.cgi?id=1812
Forwarded: not-needed
Last-Update: 2010-10-26

Index: b/ssh.c
===================================================================
--- a/ssh.c
+++ b/ssh.c
@@ -50,6 +50,7 @@
 #include <sys/ioctl.h>
 #include <sys/param.h>
 #include <sys/socket.h>
+#include <sys/wait.h>
 
 #include <ctype.h>
 #include <errno.h>
@@ -210,6 +211,7 @@
 static int ssh_session(void);
 static int ssh_session2(void);
 static void load_public_identity_files(void);
+static void main_sigchld_handler(int);
 
 /* from muxclient.c */
 void muxclient(const char *);
@@ -849,6 +851,7 @@
 	    tilde_expand_filename(options.user_hostfile2, original_real_uid);
 
 	signal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE early */
+	signal(SIGCHLD, main_sigchld_handler);
 
 	/* Log into the remote system.  Never returns if the login fails. */
 	ssh_login(&sensitive_data, host, (struct sockaddr *)&hostaddr,
@@ -1532,3 +1535,19 @@
 	bzero(pwdir, strlen(pwdir));
 	xfree(pwdir);
 }
+
+static void
+main_sigchld_handler(int sig)
+{
+	int save_errno = errno;
+	pid_t pid;
+	int status;
+
+	while ((pid = waitpid(-1, &status, WNOHANG)) > 0 ||
+	    (pid < 0 && errno == EINTR))
+		;
+
+	signal(sig, main_sigchld_handler);
+	errno = save_errno;
+}
+