summaryrefslogtreecommitdiffhomepage
path: root/cli-session.c
diff options
context:
space:
mode:
authorKonstantin Tokarev <ktokarev@smartlabs.tv>2015-12-03 16:22:29 +0300
committerKonstantin Tokarev <ktokarev@smartlabs.tv>2015-12-03 16:22:29 +0300
commit960364d953fb64ecfe017a05cfa745e5b271161d (patch)
treebdf3581b1be7b586995e9330c5ca770a7fa61203 /cli-session.c
parentf64a50f31995dc12bba316f3649e3e5f6ee64f90 (diff)
Client: kill proxy command when exiting application.
Diffstat (limited to 'cli-session.c')
-rw-r--r--cli-session.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/cli-session.c b/cli-session.c
index 10244a7..9be958e 100644
--- a/cli-session.c
+++ b/cli-session.c
@@ -41,7 +41,7 @@
static void cli_remoteclosed() ATTRIB_NORETURN;
static void cli_sessionloop();
-static void cli_session_init();
+static void cli_session_init(pid_t proxy_cmd_pid);
static void cli_finished() ATTRIB_NORETURN;
static void recv_msg_service_accept(void);
static void cli_session_cleanup(void);
@@ -104,7 +104,7 @@ void cli_connected(int result, int sock, void* userdata, const char *errstring)
update_channel_prio();
}
-void cli_session(int sock_in, int sock_out, struct dropbear_progress_connection *progress) {
+void cli_session(int sock_in, int sock_out, struct dropbear_progress_connection *progress, pid_t proxy_cmd_pid) {
common_session_init(sock_in, sock_out);
@@ -115,8 +115,7 @@ void cli_session(int sock_in, int sock_out, struct dropbear_progress_connection
chaninitialise(cli_chantypes);
/* Set up cli_ses vars */
- cli_session_init();
-
+ cli_session_init(proxy_cmd_pid);
/* Ready to go */
sessinitdone = 1;
@@ -140,7 +139,7 @@ static void cli_send_kex_first_guess() {
}
#endif
-static void cli_session_init() {
+static void cli_session_init(pid_t proxy_cmd_pid) {
cli_ses.state = STATE_NOTHING;
cli_ses.kex_state = KEX_NOTHING;
@@ -159,6 +158,8 @@ static void cli_session_init() {
cli_ses.retval = EXIT_SUCCESS; /* Assume it's clean if we don't get a
specific exit status */
+ cli_ses.proxy_cmd_pid = proxy_cmd_pid;
+ TRACE(("proxy command PID='%d'", proxy_cmd_pid));
/* Auth */
cli_ses.lastprivkey = NULL;
@@ -334,12 +335,25 @@ static void cli_sessionloop() {
}
+void 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 (cli_ses.proxy_cmd_pid > 1) {
+ TRACE(("killing proxy command with PID='%d'", cli_ses.proxy_cmd_pid));
+ kill(cli_ses.proxy_cmd_pid, SIGHUP);
+ }
+}
+
static void cli_session_cleanup(void) {
if (!sessinitdone) {
return;
}
+ kill_proxy_command();
+
/* Set std{in,out,err} back to non-blocking - busybox ash dies nastily if
* we don't revert the flags */
fcntl(cli_ses.stdincopy, F_SETFL, cli_ses.stdinflags);