diff --git a/src/lib/fd.c b/src/lib/fd.c index fb99eff63..5b2043b90 100644 --- a/src/lib/fd.c +++ b/src/lib/fd.c @@ -193,7 +193,7 @@ launch_pipe_process(int* pipe, int* pidfd){ } if(p == 0){ // child if(dup2(pipes[1], STDOUT_FILENO) < 0 || dup2(pipes[1], STDERR_FILENO) < 0){ - fprintf(stderr, "Couldn't dup() %d (%s)\n", pipes[1], strerror(errno)); + logerror("Couldn't dup() %d (%s)\n", pipes[1], strerror(errno)); exit(EXIT_FAILURE); } }else if(p > 0){ // parent @@ -395,9 +395,10 @@ ncsubproc* ncsubproc_createvpe(ncplane* n, const ncsubproc_options* opts, #else exect(bin, arg, env); #endif -//fprintf(stderr, "Error execv()ing %s\n", bin); + logerror("Error execing %s (%s?)\n", bin, strerror(errno)); exit(EXIT_FAILURE); }else if(ret->pid < 0){ + logerror("Error launching process (%s?)\n", strerror(errno)); free(ret); return NULL; } @@ -417,6 +418,7 @@ int ncsubproc_destroy(ncsubproc* n){ //fprintf(stderr, "pid: %u pidfd: %d waittid: %u\n", n->pid, n->pidfd, n->waittid); #ifdef USING_PIDFD if(n->pidfd >= 0){ + loginfo("Sending SIGKILL to pidfd %d\n", n->pidfd); if(syscall(__NR_pidfd_send_signal, n->pidfd, SIGKILL, NULL, 0)){ kill(n->pid, SIGKILL); } @@ -424,6 +426,7 @@ int ncsubproc_destroy(ncsubproc* n){ #else pthread_mutex_lock(&n->lock); if(!n->waited){ + loginfo("Sending SIGKILL to PID %d\n", n->pid); kill(n->pid, SIGKILL); } pthread_mutex_unlock(&n->lock); diff --git a/src/lib/logging.h b/src/lib/logging.h index f1fe36b32..d0c8225c3 100644 --- a/src/lib/logging.h +++ b/src/lib/logging.h @@ -10,6 +10,16 @@ void nclog(const char* fmt, ...); // logging extern int loglevel; +#define logpanic(fmt, ...) do{ \ + if(loglevel >= NCLOGLEVEL_PANIC){ \ + nclog("%s:%d:" fmt, __func__, __LINE__, ##__VA_ARGS__); } \ + } while(0); + +#define logfatal(fmt, ...) do{ \ + if(loglevel >= NCLOGLEVEL_FATAL){ \ + nclog("%s:%d:" fmt, __func__, __LINE__, ##__VA_ARGS__); } \ + } while(0); + #define logerror(fmt, ...) do{ \ if(loglevel >= NCLOGLEVEL_ERROR){ \ nclog("%s:%d:" fmt, __func__, __LINE__, ##__VA_ARGS__); } \ diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index a852de921..7fa7e1dd5 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -241,12 +241,12 @@ int update_term_dimensions(int fd, int* rows, int* cols, tinfo* tcache, struct winsize ws; int i = ioctl(fd, TIOCGWINSZ, &ws); if(i < 0){ - fprintf(stderr, "TIOCGWINSZ failed on %d (%s)\n", fd, strerror(errno)); + logerror("TIOCGWINSZ failed on %d (%s)\n", fd, strerror(errno)); return -1; } if(ws.ws_row <= 0 || ws.ws_col <= 0){ - fprintf(stderr, "Bogus return from TIOCGWINSZ on %d (%d/%d)\n", - fd, ws.ws_row, ws.ws_col); + logerror("Bogus return from TIOCGWINSZ on %d (%d/%d)\n", + fd, ws.ws_row, ws.ws_col); return -1; } int rowsafe; @@ -1082,7 +1082,7 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){ } ret->ttyfd = get_tty_fd(ret->ttyfp); if(recursive_lock_init(&ret->pilelock)){ - fprintf(stderr, "Couldn't initialize pile mutex\n"); + logfatal("Couldn't initialize pile mutex\n"); free(ret); return NULL; } @@ -1113,7 +1113,7 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){ loglevel = opts->loglevel; int termerr; if(setupterm(opts->termtype, ret->ttyfd, &termerr) != OK){ - fprintf(stderr, "Terminfo error %d (see terminfo(3ncurses))\n", termerr); + logpanic("Terminfo error %d (see terminfo(3ncurses))\n", termerr); drop_signals(ret); fclose(ret->rstate.mstreamfp); pthread_mutex_destroy(&ret->statlock); @@ -1142,7 +1142,7 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){ } ret->stdplane = NULL; if((ret->stdplane = create_initial_ncplane(ret, dimy, dimx)) == NULL){ - fprintf(stderr, "Couldn't create the initial plane (bad margins?)\n"); + logerror("Couldn't create the initial plane (bad margins?)\n"); goto err; } reset_term_attributes(&ret->tcache, ret->ttyfp); @@ -1202,7 +1202,7 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){ return ret; err: - fprintf(stderr, "Alas, you will not be going to space today.\n"); + logpanic("Alas, you will not be going to space today.\n"); // FIXME looks like we have some memory leaks on this error path? if(ret->rstate.mstreamfp){ fclose(ret->rstate.mstreamfp);