Merge branch 'maint'
[paraslash.git] / gui.c
diff --git a/gui.c b/gui.c
index 8e2dee1cb56c8951f0f591910b62f75823738ad3..dbe0a19ced1d1da9e2d588a2498dfc931371ee65 100644 (file)
--- a/gui.c
+++ b/gui.c
@@ -191,20 +191,6 @@ static struct gui_command command_list[] = {
        }
 };
 
-static int para_open_stat_pipe(char *cmd)
-{
-       int fds[3] = {0, 1, 0};
-       pid_t pid;
-       int ret = para_exec_cmdline_pid(&pid, cmd, fds);
-       if (ret < 0)
-               return ret;
-       ret = mark_fd_nonblocking(fds[1]);
-       if (ret > 0)
-               return fds[1];
-       close(fds[1]);
-       return ret;
-}
-
 static int find_cmd_byname(char *name)
 {
        int i;
@@ -910,12 +896,27 @@ static void handle_signal(int sig)
 static int open_stat_pipe(void)
 {
        static int init = 1;
+       int ret, fds[3] = {0, 1, 0};
+       pid_t pid;
 
        if (init)
                init = 0;
        else
-               sleep(1);
-       return para_open_stat_pipe(conf.stat_cmd_arg);
+               /*
+                * Sleep a bit to avoid a busy loop. As the call to sleep() may
+                * be interrupted by SIGCHLD, we simply wait until the call
+                * succeeds.
+                */
+               while (sleep(2))
+                       ; /* nothing */
+       ret = para_exec_cmdline_pid(&pid, conf.stat_cmd_arg, fds);
+       if (ret < 0)
+               return ret;
+       ret = mark_fd_nonblocking(fds[1]);
+       if (ret >= 0)
+               return fds[1];
+       close(fds[1]);
+       return ret;
 }
 
 /*