--- src/conky.h.old 2005-11-16 18:45:32.000000000 -0500 +++ src/conky.h 2005-11-24 23:06:25.046033576 -0500 @@ -209,8 +209,8 @@ int use_spacer; -char *tmpstring1; -char *tmpstring2; +char tmpstring1[TEXT_BUFFER_SIZE]; +char tmpstring2[TEXT_BUFFER_SIZE]; #ifdef X11 /* in x11.c */ --- src/conky.c.old 2005-11-16 19:32:39.000000000 -0500 +++ src/conky.c 2005-11-24 23:03:03.675646528 -0500 @@ -3,7 +3,7 @@ * * This program is licensed under BSD license, read COPYING * - * $Id: conky.c,v 1.68 2005/11/17 00:32:39 brenden1 Exp $ + * $Id: conky.c,v 1.70 2005/11/24 02:18:42 pkovacs Exp $ */ #include "conky.h" @@ -34,6 +34,9 @@ #define MAIL_FILE "$MAIL" #define MAX_IF_BLOCK_DEPTH 5 +/* #define SIGNAL_BLOCKING */ +#undef SIGNAL_BLOCKING + #ifdef X11 /* alignments */ @@ -4060,6 +4063,15 @@ static void main_loop() { +#ifdef SIGNAL_BLOCKING + sigset_t newmask, oldmask; + + sigemptyset(&newmask); + sigaddset(&newmask,SIGINT); + sigaddset(&newmask,SIGTERM); + sigaddset(&newmask,SIGUSR1); +#endif + #ifdef X11 Region region = XCreateRegion(); #endif /* X11 */ @@ -4067,6 +4079,13 @@ info.looped = 0; while (total_run_times == 0 || info.looped < total_run_times - 1) { info.looped++; + +#ifdef SIGNAL_BLOCKING + /* block signals. we will inspect for pending signals later */ + if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) + CRIT_ERR("unable to sigprocmask()"); +#endif + #ifdef X11 XFlush(display); @@ -4287,7 +4306,12 @@ } #endif /* X11 */ - /* inspect pending signal prior to entering next loop */ +#ifdef SIGNAL_BLOCKING + /* unblock signals of interest and let handler fly */ + if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) + CRIT_ERR("unable to sigprocmask()"); +#endif + switch(g_signal_pending) { case SIGUSR1: { @@ -4964,6 +4988,8 @@ int main(int argc, char **argv) { + struct sigaction act, oact; + g_signal_pending=0; memset(&info, 0, sizeof(info) ); @@ -5058,11 +5084,6 @@ init_X11(); #endif /* X11 */ - tmpstring1 = (char *) - malloc(TEXT_BUFFER_SIZE); - tmpstring2 = (char *) - malloc(TEXT_BUFFER_SIZE); - /* load current_config or CONFIG_FILE */ #ifdef CONFIG_FILE @@ -5241,16 +5262,22 @@ } /* Set signal handlers */ - if ( signal(SIGINT,signal_handler) == SIG_ERR || - signal(SIGUSR1,signal_handler) == SIG_ERR || - signal(SIGTERM,signal_handler) == SIG_ERR ) + act.sa_handler = signal_handler; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; +#ifdef SA_RESTART + act.sa_flags |= SA_RESTART; +#endif + + if ( sigaction(SIGINT,&act,&oact) < 0 || + sigaction(SIGUSR1,&act,&oact) < 0 || + sigaction(SIGTERM,&act,&oact) < 0 ) { ERR("error setting signal handler: %s", strerror(errno) ); } main_loop(); - free(tmpstring1); - free(tmpstring2); + return 0; }