aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2019-04-23 21:54:59 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2019-04-23 21:54:59 +0530
commit32dde3390acf4f3cfcd9367a8875699e675db97b (patch)
tree9466be90eafa9e76faca92cdaa1e268d87b20905 /src
parente973330c91386a4bf65f04a398d14647ffb7d7be (diff)
downloadnnn-32dde3390acf4f3cfcd9367a8875699e675db97b.tar.gz
Fix #225
Diffstat (limited to 'src')
-rw-r--r--src/nnn.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/nnn.c b/src/nnn.c
index 11f201f..c0f351f 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -936,7 +936,15 @@ static int join(pid_t p, uchar flag)
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 @@ static int spawn(char *file, char *arg1, char *arg2, const char *dir, uchar flag
exitcurses();
pid = xfork(flag);
+
+ /* Child */
if (pid == 0) {
if (dir && chdir(dir) == -1)
_exit(1);
@@ -1015,18 +1025,19 @@ static int spawn(char *file, char *arg1, char *arg2, const char *dir, uchar flag
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;
}