]> Sergey Matveev's repositories - nnn.git/commitdiff
Wait for child on plugin invocation
authorKlzXS <klzx+github@klzx.cf>
Wed, 12 May 2021 06:50:24 +0000 (08:50 +0200)
committerKlzXS <klzx+github@klzx.cf>
Wed, 12 May 2021 06:50:24 +0000 (08:50 +0200)
src/nnn.c

index a8c8a6ca6bd833c4f36362582790af03a282e268..5bc3829a42680ed9da8485d7d3346ac6a0b0f452 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -4785,6 +4785,8 @@ static void readpipe(int fd, char **path, char **lastname, char **lastdir)
 
 static bool run_selected_plugin(char **path, const char *file, char *runfile, char **lastname, char **lastdir)
 {
+       int status;
+       pid_t p;
        bool cmd_as_plugin = FALSE;
        uchar_t flags = 0;
 
@@ -4821,7 +4823,7 @@ static bool run_selected_plugin(char **path, const char *file, char *runfile, ch
 
        exitcurses();
 
-       if (fork() == 0) { // In child
+       if ((p = fork()) == 0) { // In child
                int wfd = open(g_pipepath, O_WRONLY | O_CLOEXEC);
 
                if (wfd == -1)
@@ -4852,6 +4854,9 @@ static bool run_selected_plugin(char **path, const char *file, char *runfile, ch
        readpipe(rfd, path, lastname, lastdir);
        close(rfd);
 
+       /* wait for the child to finish. no zombies allowed */
+       waitpid(p, &status, 0);
+
        refresh();
 
        unlink(g_pipepath);