gui: Rename do_exit().
[paraslash.git] / gui.c
diff --git a/gui.c b/gui.c
index a4ee72758d6944cbd28aa8476049268ebb762256..a34f27de5e40cb0adbb2d652d18586c955d88a90 100644 (file)
--- a/gui.c
+++ b/gui.c
@@ -50,7 +50,7 @@ static struct ringbuffer *bot_win_rb;
 
 static unsigned scroll_position;
 
-static int cmd_died, curses_active;
+static int curses_active;
 static pid_t cmd_pid;
 
 static int command_fds[2];
@@ -533,7 +533,8 @@ static void setup_signal_handling(void)
        para_sigaction(SIGHUP, SIG_IGN);
 }
 
-__noreturn static void do_exit(int ret)
+/* kill every process in the process group and exit */
+__noreturn static void kill_pg_and_die(int ret)
 {
        para_sigaction(SIGTERM, SIG_IGN);
        kill(0, SIGTERM);
@@ -552,7 +553,7 @@ static void shutdown_curses(void)
 __noreturn static void finish(int ret)
 {
        shutdown_curses();
-       do_exit(ret);
+       kill_pg_and_die(ret);
 }
 
 /*
@@ -567,7 +568,7 @@ __noreturn __printf_2_3 static void msg_n_exit(int ret, const char* fmt, ...)
        va_start(argp, fmt);
        vfprintf(outfd, fmt, argp);
        va_end(argp);
-       do_exit(ret);
+       kill_pg_and_die(ret);
 }
 
 static void print_welcome(void)
@@ -834,10 +835,8 @@ reap_next_child:
        ret = para_reap_child(&pid);
        if (ret <= 0)
                return;
-       if (pid == cmd_pid) {
+       if (pid == cmd_pid)
                cmd_pid = 0;
-               cmd_died = 1;
-       }
        goto reap_next_child;
 }
 
@@ -951,7 +950,7 @@ static int open_stat_pipe(void)
        return ret;
 }
 
-#define COMMAND_BUF_SIZE 4096
+#define COMMAND_BUF_SIZE 32768
 
 /*
  * This is the core select loop. Besides the (internal) signal
@@ -993,6 +992,8 @@ repeat:
                if (command_fds[1] >= 0)
                        para_fd_set(command_fds[1], &rfds, &max_fileno);
        }
+       if (mode == GETCH_MODE || mode == COMMAND_MODE)
+               para_fd_set(STDIN_FILENO, &rfds, &max_fileno);
        ret = para_select(max_fileno + 1, &rfds, NULL, &tv);
        if (ret <= 0)
                goto check_return; /* skip fd checks */
@@ -1023,6 +1024,10 @@ repeat:
                                if (command_fds[!i] < 0) /* both fds closed */
                                        return 0;
                        }
+                       if (cbo[i] == COMMAND_BUF_SIZE - 1) {
+                               PARA_NOTICE_LOG("discarding overlong line");
+                               cbo[i] = 0;
+                       }
                }
        }
        ret = read_stat_pipe(&rfds);
@@ -1060,10 +1065,8 @@ check_return:
                        return ret;
                break;
        case EXTERNAL_MODE:
-               if (cmd_died) {
-                       cmd_died = 0;
+               if (cmd_pid == 0)
                        return 0;
-               }
        }
        goto repeat;
 }
@@ -1137,7 +1140,6 @@ static void external_cmd(char *cmd)
        shutdown_curses();
        if (para_exec_cmdline_pid(&cmd_pid, cmd, fds) < 0)
                return;
-       cmd_died = 0;
        do_select(EXTERNAL_MODE);
        init_curses();
 }