X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=gui.c;h=ebddd88cb20b12514e249d7a8ed2dfb771df4668;hp=8e2dee1cb56c8951f0f591910b62f75823738ad3;hb=c71f51ee5d5c2a387d0ad00d842fd390ec9944d8;hpb=b40c89e243f10560f1c8e491239ab8c07dfb7dc5 diff --git a/gui.c b/gui.c index 8e2dee1c..ebddd88c 100644 --- a/gui.c +++ b/gui.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1998-2010 Andre Noll + * Copyright (C) 1998-2011 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -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; @@ -308,9 +294,9 @@ static int align_str(WINDOW* win, char *str, unsigned int len, str[len] = '\0'; num = 0; } - /* replace newlines by spaces */ + /* replace control characters by spaces */ for (i = 0; i < len && str[i]; i++) { - if (str[i] == '\n') + if (str[i] == '\n' || str[i] == '\r' || str[i] == '\f') str[i] = ' '; } if (align == LEFT) { @@ -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; } /* @@ -1393,13 +1394,8 @@ int main(int argc, char *argv[]) _argc = argc; _argv = argv; - if (gui_cmdline_parser(argc, argv, &conf)) { - fprintf(stderr, "parse error while reading command line\n"); - exit(EXIT_FAILURE); - } + gui_cmdline_parser(argc, argv, &conf); HANDLE_VERSION_FLAG("gui", conf); - init_theme(0, &theme); - top.lines = theme.top_lines_default; if (check_key_map_args() < 0) { fprintf(stderr, "invalid key map\n"); exit(EXIT_FAILURE); @@ -1424,6 +1420,8 @@ int main(int argc, char *argv[]) fprintf(stderr, "invalid key map in config file\n"); exit(EXIT_FAILURE); } + init_theme_or_die(conf.theme_arg, &theme); + top.lines = theme.top_lines_default; setup_signal_handling(); bot_win_rb = ringbuffer_new(RINGBUFFER_SIZE); initscr(); /* needed only once, always successful */