From: Sean E. <sea...@us...> - 2002-03-28 20:07:52
|
Update of /cvsroot/gaim/gaim/src In directory usw-pr-cvs1:/tmp/cvs-serv5050/src Modified Files: aim.c gtkspell.c gtkspell.h util.c Log Message: Jabber improvements (Jim Seymour) and good handling of sigchld (Jim Seymour and Luke Schierer) Index: aim.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/aim.c,v retrieving revision 1.177 retrieving revision 1.178 diff -u -d -r1.177 -r1.178 --- aim.c 17 Mar 2002 22:23:17 -0000 1.177 +++ aim.c 28 Mar 2002 20:07:45 -0000 1.178 @@ -84,6 +84,28 @@ void BuddyTickerCreateWindow(void); +#if HAVE_SIGNAL_H +/* + * Lists of signals we wish to catch and those we wish to ignore. + * Each list terminated with -1 + */ +static int catch_sig_list[] = { + SIGSEGV, + SIGHUP, + SIGINT, + SIGTERM, + SIGQUIT, + SIGCHLD, + -1 +}; + +static int ignore_sig_list[] = { + SIGPIPE, + -1 +}; +#endif + + void cancel_logon(void) { #ifdef USE_APPLET @@ -408,6 +430,9 @@ break; case SIGCHLD: clean_pid(); +#if HAVE_SIGNAL_H + signal(SIGCHLD, sighandler); /* restore signal catching on this one! */ +#endif break; default: debug_printf("caught signal %d\n", sig); @@ -527,6 +552,10 @@ { int opt_acct = 0, opt_help = 0, opt_version = 0, opt_login = 0, do_login_ret = -1; char *opt_user_arg = NULL, *opt_login_arg = NULL; +#if HAVE_SIGNAL_H + int sig_indx; /* for setting up signal catching */ + void (*prev_sig_disp)(); +#endif #ifndef USE_APPLET int opt, opt_user = 0; int i; @@ -573,13 +602,23 @@ #if HAVE_SIGNAL_H /* Let's not violate any PLA's!!!! */ - signal(SIGSEGV, sighandler); - signal(SIGHUP, sighandler); - signal(SIGINT, sighandler); - signal(SIGTERM, sighandler); - signal(SIGQUIT, sighandler); - signal(SIGPIPE, SIG_IGN); - signal(SIGCHLD, sighandler); + /* jseymour: whatever the fsck that means */ + for(sig_indx = 0; catch_sig_list[sig_indx] != -1; ++sig_indx) { + if((prev_sig_disp = signal(catch_sig_list[sig_indx], sighandler)) == SIG_ERR) { + char errmsg[BUFSIZ]; + sprintf(errmsg, "Warning: couldn't set signal %d for catching", + catch_sig_list[sig_indx]); + perror(errmsg); + } + } + for(sig_indx = 0; ignore_sig_list[sig_indx] != -1; ++sig_indx) { + if((prev_sig_disp = signal(ignore_sig_list[sig_indx], SIG_IGN)) == SIG_ERR) { + char errmsg[BUFSIZ]; + sprintf(errmsg, "Warning: couldn't set signal %d to ignore", + ignore_sig_list[sig_indx]); + perror(errmsg); + } + } #endif Index: gtkspell.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/gtkspell.c,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- gtkspell.c 15 Nov 2001 23:32:54 -0000 1.15 +++ gtkspell.c 28 Mar 2002 20:07:45 -0000 1.16 @@ -55,7 +55,18 @@ static void set_up_signal(); int gtkspell_running() { - return (spell_pid > 0); + return (spell_pid > 0? spell_pid : 0); +} + +/* + * Set to "gtkspell not running" status + * + * May seem a bit silly, but it allows us to keep the file-global + * variable from going program-global. And if we need to do + * something else additional later, well... + */ +void gtkspell_notrunning() { + spell_pid = 0; } /* @@ -170,11 +181,6 @@ gtkspell_stop(); } - if (!signal_set_up) { - set_up_signal(); - signal_set_up = 1; - } - pipe(fd_write); pipe(fd_read); pipe(fd_error); @@ -689,21 +695,3 @@ gtkspell_uncheck_all(gtktext); } -static void sigchld(int param) { - if (gtkspell_running() && - (waitpid(spell_pid, NULL, WNOHANG) == spell_pid)) { - spell_pid = 0; - } else { - /* a default SIGCHLD handler. - * what else to do here? */ - waitpid(-1, NULL, WNOHANG); - } -} - -static void set_up_signal() { - struct sigaction sigact; - memset(&sigact, 0, sizeof(struct sigaction)); - - sigact.sa_handler = sigchld; - sigaction(SIGCHLD, &sigact, NULL); -} Index: gtkspell.h =================================================================== RCS file: /cvsroot/gaim/gaim/src/gtkspell.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- gtkspell.h 19 Jan 2001 09:11:16 -0000 1.3 +++ gtkspell.h 28 Mar 2002 20:07:45 -0000 1.4 @@ -55,12 +55,23 @@ /* Is gtkspell running? * * Return: - * nonzero if it running + * nonzero, positive pid if it's running * zero if is not running * * Example: * if (gtkspell_running()) * printf("gtkspell is running.\n"); + */ + +extern void gtkspell_notrunning(void); +/* + * Set gtkspell status to "not running" + * Intended to be used only by signal-catcher + * when the SIGCHLD signal it catches matches + * the gtkspell process i.d. + * + * Example: + * gtkspell_notrunning(); */ extern void gtkspell_attach(GtkText *text); Index: util.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/util.c,v retrieving revision 1.114 retrieving revision 1.115 diff -u -d -r1.114 -r1.115 --- util.c 17 Mar 2002 22:23:18 -0000 1.114 +++ util.c 28 Mar 2002 20:07:45 -0000 1.115 @@ -35,6 +35,7 @@ #include <math.h> #include "gaim.h" #include "prpl.h" +#include "gtkspell.h" char *full_date() { @@ -616,10 +617,18 @@ void clean_pid(void) { int status; - pid_t pid; + pid_t pid, spell_pid; - printf ("clean_pid\n"); - pid = waitpid(-1, &status, WNOHANG); + while((pid = waitpid(-1, &status, WNOHANG)) > 0) { + if((spell_pid = gtkspell_running()) != 0 && pid == spell_pid) { + gtkspell_notrunning(); + } + } + if(pid < 0 && errno != ECHILD) { + char errmsg[BUFSIZ]; + sprintf(errmsg, "Warning: waitpid() returned %d", pid); + perror(errmsg); + } } struct aim_user *find_user(const char *name, int protocol) |