X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=gui.c;h=a34f27de5e40cb0adbb2d652d18586c955d88a90;hb=20e2c6a532dcb0c197062b9f97753e000eae3c6a;hp=65b2ac05d748ab1bb7d24e3b752d906d2ffca5c5;hpb=c3a930948d0512b3ff57ed2bebc2d9bdb3dcb9ad;p=paraslash.git diff --git a/gui.c b/gui.c index 65b2ac05..a34f27de 100644 --- a/gui.c +++ b/gui.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1998-2012 Andre Noll + * Copyright (C) 1998-2013 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -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(); } @@ -1486,8 +1488,7 @@ int main(int argc, char *argv[]) _argc = argc; _argv = argv; - if (gui_cmdline_parser(argc, argv, &conf) != 0) - exit(EXIT_FAILURE); + gui_cmdline_parser(argc, argv, &conf); /* exits on errors */ HANDLE_VERSION_FLAG("gui", conf); cf = configfile_exists(); if (!cf && conf.config_file_given) {