From 66d1776fb85530b446dcc1f68929231849a5ad44 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 8 Jul 2018 01:16:16 -0500 Subject: Fix division by zero errors and double summary in ping. --- lib/lib.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'lib/lib.c') diff --git a/lib/lib.c b/lib/lib.c index 6d75e0f3..17a4f483 100644 --- a/lib/lib.c +++ b/lib/lib.c @@ -850,14 +850,20 @@ void exit_signal(int sig) // adds the handlers to a list, to be called in order. void sigatexit(void *handler) { - struct arg_list *al = xmalloc(sizeof(struct arg_list)); + struct arg_list *al; int i; for (i=0; signames[i].num != SIGCHLD; i++) - signal(signames[i].num, exit_signal); - al->next = toys.xexit; - al->arg = handler; - toys.xexit = al; + signal(signames[i].num, handler ? exit_signal : SIG_DFL); + if (handler) { + al = xmalloc(sizeof(struct arg_list)); + al->next = toys.xexit; + al->arg = handler; + toys.xexit = al; + } else { + llist_traverse(toys.xexit, free); + toys.xexit = 0; + } } // Convert name to signal number. If name == NULL print names. -- cgit v1.2.3