int status_client_ncurses(struct conf **confs) { int ret=-1; int csin=-1; int csout=-1; pid_t childpid=-1; struct async *as=NULL; const char *monitor_logfile=get_string(confs[OPT_MONITOR_LOGFILE]); struct asfd *so_asfd=NULL; struct sel *sel=NULL; if(!(sel=sel_alloc())) goto end; setup_signals(); // Fork a burp child process that will contact the server over SSL. // We will read and write from and to its stdout and stdin. if((childpid=fork_monitor(&csin, &csout, confs))<0) goto end; //printf("childpid: %d\n", childpid); if(!(as=async_alloc()) || as->init(as, 0) || !setup_asfd_linebuf_write(as, "monitor stdin", &csin) || !setup_asfd_linebuf_read(as, "monitor stdout", &csout)) goto end; //printf("ml: %s\n", monitor_logfile); #ifdef HAVE_NCURSES if(actg==ACTION_STATUS) { if(!setup_asfd_ncurses_stdin(as)) goto end; ncurses_init(); } #endif if(!(so_asfd=setup_asfd_stdout(as))) goto end; if(monitor_logfile && !(lfzp=fzp_open(monitor_logfile, "wb"))) goto end; log_fzp_set_direct(lfzp); ret=status_client_ncurses_main_loop(as, so_asfd, sel, get_string(confs[OPT_ORIG_CLIENT])); end: #ifdef HAVE_NCURSES if(actg==ACTION_STATUS) ncurses_free(); #endif if(ret) logp("%s exiting with error: %d\n", __func__, ret); fzp_close(&lfzp); async_asfd_free_all(&as); close_fd(&csin); close_fd(&csout); sel_free(&sel); return ret; }
int status_client_ncurses(enum action act, struct conf **confs) { int csin=-1; int csout=-1; int ret=-1; pid_t childpid=-1; struct async *as=NULL; const char *monitor_logfile=get_string(confs[OPT_MONITOR_LOGFILE]); #ifdef HAVE_NCURSES_H actg=act; // So that the sighandler can call endwin(). #else if(act==ACTION_STATUS) { printf("To use the live status monitor, you need to recompile with ncurses support.\n"); goto end; } #endif setup_signals(); // Fork a burp child process that will contact the server over SSL. // We will read and write from and to its stdout and stdin. if((childpid=fork_monitor(&csin, &csout, confs))<0) goto end; //printf("childpid: %d\n", childpid); set_non_blocking(csin); set_non_blocking(csout); if(!(as=async_alloc()) || as->init(as, 0) || !setup_asfd(as, "monitor stdin", &csin, NULL, ASFD_STREAM_LINEBUF, ASFD_FD_CLIENT_MONITOR_WRITE, -1, confs) || !setup_asfd(as, "monitor stdout", &csout, NULL, ASFD_STREAM_LINEBUF, ASFD_FD_CLIENT_MONITOR_READ, -1, confs)) goto end; //printf("ml: %s\n", monitor_logfile); #ifdef HAVE_NCURSES_H if(actg==ACTION_STATUS) { int stdinfd=fileno(stdin); if(!setup_asfd(as, "stdin", &stdinfd, NULL, ASFD_STREAM_NCURSES_STDIN, ASFD_FD_CLIENT_NCURSES_READ, -1, confs)) goto end; ncurses_init(); } #endif if(monitor_logfile && !(lfp=open_file(monitor_logfile, "wb"))) goto end; set_logfp_direct(lfp); ret=main_loop(as, act, confs); end: #ifdef HAVE_NCURSES_H if(actg==ACTION_STATUS) endwin(); #endif if(ret) logp("%s exiting with error: %d\n", __func__, ret); close_fp(&lfp); async_asfd_free_all(&as); close_fd(&csin); close_fd(&csout); return ret; }