gui: Avoid busy loop if audiod is down.
[paraslash.git] / gui.c
diff --git a/gui.c b/gui.c
index 4862df5ed9595459e8beed9cfa76946f71c54f9d..01cca6e6d08eac45ae3fbf63b999d453e40e14e3 100644 (file)
--- a/gui.c
+++ b/gui.c
@@ -521,13 +521,12 @@ static void setup_signal_handling(void)
        para_install_sighandler(SIGCHLD);
        para_install_sighandler(SIGWINCH);
        para_install_sighandler(SIGUSR1);
-//     signal(SIGPIPE, SIG_IGN);
-       signal(SIGHUP, SIG_IGN);
+       para_sigaction(SIGHUP, SIG_IGN);
 }
 
 __noreturn static void do_exit(int ret)
 {
-       signal(SIGTERM, SIG_IGN);
+       para_sigaction(SIGTERM, SIG_IGN);
        kill(0, SIGTERM);
        exit(ret);
 }
@@ -881,7 +880,13 @@ static int open_audiod_pipe(void)
        if (init)
                init = 0;
        else
-               sleep(1);
+               /*
+                * 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 */
        return para_open_audiod_pipe(conf.stat_cmd_arg);
 }
 
@@ -1092,13 +1097,14 @@ static void com_page_up(void)
 {
        unsigned lines;
        int fvr = first_visible_rbe(&lines);
+
        if (fvr < 0 || fvr + 1 >= ringbuffer_filled(bot_win_rb)) {
                print_in_bar(COLOR_ERRMSG, "top of buffer is shown\n");
                return;
        }
        scroll_position = fvr + 1;
        for (; scroll_position > 0; scroll_position--) {
-               fvr = first_visible_rbe(&lines);
+               first_visible_rbe(&lines);
                if (lines == bot.lines)
                        break;
        }