src/nnn.c | 29 ++++++++++++++++++++--------- diff --git a/src/nnn.c b/src/nnn.c index 11f201ff8f8bb02fdd2dae1e072eb7013c188e7a..c0f351f0bab8e4532d6b5c2d7185a41652630e12 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -936,7 +936,15 @@ if (!(flag & F_NOWAIT)) { /* wait for the child to exit */ do { - } while (waitpid(p, &status, 0) == -1); + /* Exit if parent has exited */ + if (getppid() == 1) { + /* Kill child */ + kill(p, SIGKILL); + + /* Exit */ + _exit(0); + } + } while (waitpid(p, &status, WNOHANG) <= 0); if (WIFEXITED(status)) { status = WEXITSTATUS(status); @@ -1000,6 +1008,8 @@ if (flag & F_NORMAL) exitcurses(); pid = xfork(flag); + + /* Child */ if (pid == 0) { if (dir && chdir(dir) == -1) _exit(1); @@ -1015,17 +1025,18 @@ } execvp(*argv, argv); _exit(1); - } else { - retstatus = join(pid, flag); + } - DPRINTF_D(pid); - if (flag & F_NORMAL) { - nonl(); - noecho(); - } + /* Parent */ + retstatus = join(pid, flag); - free(cmd); + DPRINTF_D(pid); + if (flag & F_NORMAL) { + nonl(); + noecho(); } + + free(cmd); return retstatus; }