From a41ccca643364b3b1b65d7a818577dd35360fa20 Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Thu, 7 Oct 2010 22:07:32 +1100 Subject: [PATCH] - djm@cvs.openbsd.org 2010/10/06 06:39:28 [clientloop.c ssh.c sshconnect.c sshconnect.h] kill proxy command on fatal() (we already kill it on clean exit); ok markus@ --- ChangeLog | 4 ++++ clientloop.c | 3 ++- ssh.c | 13 +++---------- sshconnect.c | 16 ++++++++++++++-- sshconnect.h | 3 ++- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index f5253a431..69711b9b2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -30,6 +30,10 @@ - djm@cvs.openbsd.org 2010/10/05 05:13:18 [sftp.c sshconnect.c] use default shell /bin/sh if $SHELL is ""; ok markus@ + - djm@cvs.openbsd.org 2010/10/06 06:39:28 + [clientloop.c ssh.c sshconnect.c sshconnect.h] + kill proxy command on fatal() (we already kill it on clean exit); + ok markus@ 20100924 - (djm) OpenBSD CVS Sync diff --git a/clientloop.c b/clientloop.c index de7979366..848aacd4a 100644 --- a/clientloop.c +++ b/clientloop.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clientloop.c,v 1.222 2010/07/19 09:15:12 djm Exp $ */ +/* $OpenBSD: clientloop.c,v 1.223 2010/10/06 06:39:28 djm Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -2129,5 +2129,6 @@ cleanup_exit(int i) leave_non_blocking(); if (options.control_path != NULL && muxserver_sock != -1) unlink(options.control_path); + ssh_kill_proxy_command(); _exit(i); } diff --git a/ssh.c b/ssh.c index 20de28a64..7632cf51e 100644 --- a/ssh.c +++ b/ssh.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssh.c,v 1.352 2010/09/20 04:41:47 djm Exp $ */ +/* $OpenBSD: ssh.c,v 1.353 2010/10/06 06:39:28 djm Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -183,9 +183,6 @@ int subsystem_flag = 0; /* # of replies received for global requests */ static int remote_forward_confirms_received = 0; -/* pid of proxycommand child process */ -pid_t proxy_command_pid = 0; - /* mux.c */ extern int muxserver_sock; extern u_int muxclient_command; @@ -921,12 +918,8 @@ main(int ac, char **av) if (options.control_path != NULL && muxserver_sock != -1) unlink(options.control_path); - /* - * Send SIGHUP to proxy command if used. We don't wait() in - * case it hangs and instead rely on init to reap the child - */ - if (proxy_command_pid > 1) - kill(proxy_command_pid, SIGHUP); + /* Kill ProxyCommand if it is running. */ + ssh_kill_proxy_command(); return exit_status; } diff --git a/sshconnect.c b/sshconnect.c index 6d2f1341c..c849ca393 100644 --- a/sshconnect.c +++ b/sshconnect.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sshconnect.c,v 1.226 2010/10/05 05:13:18 djm Exp $ */ +/* $OpenBSD: sshconnect.c,v 1.227 2010/10/06 06:39:28 djm Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -66,12 +66,13 @@ char *server_version_string = NULL; static int matching_host_key_dns = 0; +static pid_t proxy_command_pid = 0; + /* import */ extern Options options; extern char *__progname; extern uid_t original_real_uid; extern uid_t original_effective_uid; -extern pid_t proxy_command_pid; static int show_other_keys(const char *, Key *); static void warn_changed_key(Key *); @@ -167,6 +168,17 @@ ssh_proxy_connect(const char *host, u_short port, const char *proxy_command) return 0; } +void +ssh_kill_proxy_command(void) +{ + /* + * Send SIGHUP to proxy command if used. We don't wait() in + * case it hangs and instead rely on init to reap the child + */ + if (proxy_command_pid > 1) + kill(SIGHUP, proxy_command_pid); +} + /* * Creates a (possibly privileged) socket for use as the ssh connection. */ diff --git a/sshconnect.h b/sshconnect.h index c59a097f4..69163afbc 100644 --- a/sshconnect.h +++ b/sshconnect.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sshconnect.h,v 1.25 2009/05/27 06:38:16 andreas Exp $ */ +/* $OpenBSD: sshconnect.h,v 1.26 2010/10/06 06:39:28 djm Exp $ */ /* * Copyright (c) 2000 Markus Friedl. All rights reserved. @@ -34,6 +34,7 @@ struct Sensitive { int ssh_connect(const char *, struct sockaddr_storage *, u_short, int, int, int *, int, int, const char *); +void ssh_kill_proxy_command(void); void ssh_login(Sensitive *, const char *, struct sockaddr *, struct passwd *, int);