summaryrefslogtreecommitdiffhomepage
path: root/cli-main.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-main.c
parentf64a50f31995dc12bba316f3649e3e5f6ee64f90 (diff)
Client: kill proxy command when exiting application.
Diffstat (limited to 'cli-main.c')
-rw-r--r--cli-main.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/cli-main.c b/cli-main.c
index c7c9035..dfb94fd 100644
--- a/cli-main.c
+++ b/cli-main.c
@@ -36,7 +36,8 @@ static void cli_dropbear_exit(int exitcode, const char* format, va_list param) A
static void cli_dropbear_log(int priority, const char* format, va_list param);
#ifdef ENABLE_CLI_PROXYCMD
-static void cli_proxy_cmd(int *sock_in, int *sock_out);
+static void cli_proxy_cmd(int *sock_in, int *sock_out, pid_t *pid_out);
+static void killchild(int signo);
#endif
#if defined(DBMULTI_dbclient) || !defined(DROPBEAR_MULTI)
@@ -66,10 +67,16 @@ int main(int argc, char ** argv) {
dropbear_exit("signal() error");
}
+ pid_t proxy_cmd_pid = 0;
#ifdef ENABLE_CLI_PROXYCMD
if (cli_opts.proxycmd) {
- cli_proxy_cmd(&sock_in, &sock_out);
+ cli_proxy_cmd(&sock_in, &sock_out, &proxy_cmd_pid);
m_free(cli_opts.proxycmd);
+ if (signal(SIGINT, killchild) == SIG_ERR ||
+ signal(SIGTERM, killchild) == SIG_ERR ||
+ signal(SIGHUP, killchild) == SIG_ERR) {
+ dropbear_exit("signal() error");
+ }
} else
#endif
{
@@ -77,7 +84,7 @@ int main(int argc, char ** argv) {
sock_in = sock_out = -1;
}
- cli_session(sock_in, sock_out, progress);
+ cli_session(sock_in, sock_out, progress, proxy_cmd_pid);
/* not reached */
return -1;
@@ -132,16 +139,24 @@ static void exec_proxy_cmd(void *user_data_cmd) {
}
#ifdef ENABLE_CLI_PROXYCMD
-static void cli_proxy_cmd(int *sock_in, int *sock_out) {
+static void cli_proxy_cmd(int *sock_in, int *sock_out, pid_t *pid_out) {
int ret;
fill_passwd(cli_opts.own_user);
ret = spawn_command(exec_proxy_cmd, cli_opts.proxycmd,
- sock_out, sock_in, NULL, NULL);
+ sock_out, sock_in, NULL, pid_out);
if (ret == DROPBEAR_FAILURE) {
dropbear_exit("Failed running proxy command");
*sock_in = *sock_out = -1;
}
}
+
+static void killchild(int signo)
+{
+ kill_proxy_command();
+ if (signo)
+ _exit(1);
+ exit(1);
+}
#endif /* ENABLE_CLI_PROXYCMD */