diff options
Diffstat (limited to 'sftp.c')
-rw-r--r-- | sftp.c | 35 |
1 files changed, 19 insertions, 16 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: sftp.c,v 1.195 2019/10/02 00:42:30 djm Exp $ */ | 1 | /* $OpenBSD: sftp.c,v 1.197 2020/01/23 07:10:22 dtucker Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> | 3 | * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> |
4 | * | 4 | * |
@@ -220,9 +220,12 @@ static const struct CMD cmds[] = { | |||
220 | static void | 220 | static void |
221 | killchild(int signo) | 221 | killchild(int signo) |
222 | { | 222 | { |
223 | if (sshpid > 1) { | 223 | pid_t pid; |
224 | kill(sshpid, SIGTERM); | 224 | |
225 | waitpid(sshpid, NULL, 0); | 225 | pid = sshpid; |
226 | if (pid > 1) { | ||
227 | kill(pid, SIGTERM); | ||
228 | waitpid(pid, NULL, 0); | ||
226 | } | 229 | } |
227 | 230 | ||
228 | _exit(1); | 231 | _exit(1); |
@@ -2240,7 +2243,7 @@ interactive_loop(struct sftp_conn *conn, char *file1, char *file2) | |||
2240 | interactive = !batchmode && isatty(STDIN_FILENO); | 2243 | interactive = !batchmode && isatty(STDIN_FILENO); |
2241 | err = 0; | 2244 | err = 0; |
2242 | for (;;) { | 2245 | for (;;) { |
2243 | signal(SIGINT, SIG_IGN); | 2246 | ssh_signal(SIGINT, SIG_IGN); |
2244 | 2247 | ||
2245 | if (el == NULL) { | 2248 | if (el == NULL) { |
2246 | if (interactive) | 2249 | if (interactive) |
@@ -2272,14 +2275,14 @@ interactive_loop(struct sftp_conn *conn, char *file1, char *file2) | |||
2272 | 2275 | ||
2273 | /* Handle user interrupts gracefully during commands */ | 2276 | /* Handle user interrupts gracefully during commands */ |
2274 | interrupted = 0; | 2277 | interrupted = 0; |
2275 | signal(SIGINT, cmd_interrupt); | 2278 | ssh_signal(SIGINT, cmd_interrupt); |
2276 | 2279 | ||
2277 | err = parse_dispatch_command(conn, cmd, &remote_path, | 2280 | err = parse_dispatch_command(conn, cmd, &remote_path, |
2278 | startdir, batchmode, !interactive && el == NULL); | 2281 | startdir, batchmode, !interactive && el == NULL); |
2279 | if (err != 0) | 2282 | if (err != 0) |
2280 | break; | 2283 | break; |
2281 | } | 2284 | } |
2282 | signal(SIGCHLD, SIG_DFL); | 2285 | ssh_signal(SIGCHLD, SIG_DFL); |
2283 | free(remote_path); | 2286 | free(remote_path); |
2284 | free(startdir); | 2287 | free(startdir); |
2285 | free(conn); | 2288 | free(conn); |
@@ -2336,20 +2339,20 @@ connect_to_server(char *path, char **args, int *in, int *out) | |||
2336 | * kill it too. Contrawise, since sftp sends SIGTERMs to the | 2339 | * kill it too. Contrawise, since sftp sends SIGTERMs to the |
2337 | * underlying ssh, it must *not* ignore that signal. | 2340 | * underlying ssh, it must *not* ignore that signal. |
2338 | */ | 2341 | */ |
2339 | signal(SIGINT, SIG_IGN); | 2342 | ssh_signal(SIGINT, SIG_IGN); |
2340 | signal(SIGTERM, SIG_DFL); | 2343 | ssh_signal(SIGTERM, SIG_DFL); |
2341 | execvp(path, args); | 2344 | execvp(path, args); |
2342 | fprintf(stderr, "exec: %s: %s\n", path, strerror(errno)); | 2345 | fprintf(stderr, "exec: %s: %s\n", path, strerror(errno)); |
2343 | _exit(1); | 2346 | _exit(1); |
2344 | } | 2347 | } |
2345 | 2348 | ||
2346 | signal(SIGTERM, killchild); | 2349 | ssh_signal(SIGTERM, killchild); |
2347 | signal(SIGINT, killchild); | 2350 | ssh_signal(SIGINT, killchild); |
2348 | signal(SIGHUP, killchild); | 2351 | ssh_signal(SIGHUP, killchild); |
2349 | signal(SIGTSTP, suspchild); | 2352 | ssh_signal(SIGTSTP, suspchild); |
2350 | signal(SIGTTIN, suspchild); | 2353 | ssh_signal(SIGTTIN, suspchild); |
2351 | signal(SIGTTOU, suspchild); | 2354 | ssh_signal(SIGTTOU, suspchild); |
2352 | signal(SIGCHLD, sigchld_handler); | 2355 | ssh_signal(SIGCHLD, sigchld_handler); |
2353 | close(c_in); | 2356 | close(c_in); |
2354 | close(c_out); | 2357 | close(c_out); |
2355 | } | 2358 | } |