add logpanic/logfatal, convert some printf()s

pull/1923/head
nick black 3 years ago committed by nick black
parent 8a3579581a
commit 7ee9ef397a

@ -193,7 +193,7 @@ launch_pipe_process(int* pipe, int* pidfd){
} }
if(p == 0){ // child if(p == 0){ // child
if(dup2(pipes[1], STDOUT_FILENO) < 0 || dup2(pipes[1], STDERR_FILENO) < 0){ 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); exit(EXIT_FAILURE);
} }
}else if(p > 0){ // parent }else if(p > 0){ // parent
@ -395,9 +395,10 @@ ncsubproc* ncsubproc_createvpe(ncplane* n, const ncsubproc_options* opts,
#else #else
exect(bin, arg, env); exect(bin, arg, env);
#endif #endif
//fprintf(stderr, "Error execv()ing %s\n", bin); logerror("Error execing %s (%s?)\n", bin, strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
}else if(ret->pid < 0){ }else if(ret->pid < 0){
logerror("Error launching process (%s?)\n", strerror(errno));
free(ret); free(ret);
return NULL; 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); //fprintf(stderr, "pid: %u pidfd: %d waittid: %u\n", n->pid, n->pidfd, n->waittid);
#ifdef USING_PIDFD #ifdef USING_PIDFD
if(n->pidfd >= 0){ if(n->pidfd >= 0){
loginfo("Sending SIGKILL to pidfd %d\n", n->pidfd);
if(syscall(__NR_pidfd_send_signal, n->pidfd, SIGKILL, NULL, 0)){ if(syscall(__NR_pidfd_send_signal, n->pidfd, SIGKILL, NULL, 0)){
kill(n->pid, SIGKILL); kill(n->pid, SIGKILL);
} }
@ -424,6 +426,7 @@ int ncsubproc_destroy(ncsubproc* n){
#else #else
pthread_mutex_lock(&n->lock); pthread_mutex_lock(&n->lock);
if(!n->waited){ if(!n->waited){
loginfo("Sending SIGKILL to PID %d\n", n->pid);
kill(n->pid, SIGKILL); kill(n->pid, SIGKILL);
} }
pthread_mutex_unlock(&n->lock); pthread_mutex_unlock(&n->lock);

@ -10,6 +10,16 @@ void nclog(const char* fmt, ...);
// logging // logging
extern int loglevel; 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{ \ #define logerror(fmt, ...) do{ \
if(loglevel >= NCLOGLEVEL_ERROR){ \ if(loglevel >= NCLOGLEVEL_ERROR){ \
nclog("%s:%d:" fmt, __func__, __LINE__, ##__VA_ARGS__); } \ nclog("%s:%d:" fmt, __func__, __LINE__, ##__VA_ARGS__); } \

@ -241,11 +241,11 @@ int update_term_dimensions(int fd, int* rows, int* cols, tinfo* tcache,
struct winsize ws; struct winsize ws;
int i = ioctl(fd, TIOCGWINSZ, &ws); int i = ioctl(fd, TIOCGWINSZ, &ws);
if(i < 0){ 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; return -1;
} }
if(ws.ws_row <= 0 || ws.ws_col <= 0){ if(ws.ws_row <= 0 || ws.ws_col <= 0){
fprintf(stderr, "Bogus return from TIOCGWINSZ on %d (%d/%d)\n", logerror("Bogus return from TIOCGWINSZ on %d (%d/%d)\n",
fd, ws.ws_row, ws.ws_col); fd, ws.ws_row, ws.ws_col);
return -1; return -1;
} }
@ -1082,7 +1082,7 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
} }
ret->ttyfd = get_tty_fd(ret->ttyfp); ret->ttyfd = get_tty_fd(ret->ttyfp);
if(recursive_lock_init(&ret->pilelock)){ if(recursive_lock_init(&ret->pilelock)){
fprintf(stderr, "Couldn't initialize pile mutex\n"); logfatal("Couldn't initialize pile mutex\n");
free(ret); free(ret);
return NULL; return NULL;
} }
@ -1113,7 +1113,7 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
loglevel = opts->loglevel; loglevel = opts->loglevel;
int termerr; int termerr;
if(setupterm(opts->termtype, ret->ttyfd, &termerr) != OK){ 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); drop_signals(ret);
fclose(ret->rstate.mstreamfp); fclose(ret->rstate.mstreamfp);
pthread_mutex_destroy(&ret->statlock); pthread_mutex_destroy(&ret->statlock);
@ -1142,7 +1142,7 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
} }
ret->stdplane = NULL; ret->stdplane = NULL;
if((ret->stdplane = create_initial_ncplane(ret, dimy, dimx)) == 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; goto err;
} }
reset_term_attributes(&ret->tcache, ret->ttyfp); reset_term_attributes(&ret->tcache, ret->ttyfp);
@ -1202,7 +1202,7 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
return ret; return ret;
err: 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? // FIXME looks like we have some memory leaks on this error path?
if(ret->rstate.mstreamfp){ if(ret->rstate.mstreamfp){
fclose(ret->rstate.mstreamfp); fclose(ret->rstate.mstreamfp);

Loading…
Cancel
Save