Mercurial > hg
comparison mcabber/src/main.c @ 163:a8f7dc0a56cb
[/trunk] Changeset 175 by mikael
* Catch SIGCHLD signal (children for external commands).
author | mikael |
---|---|
date | Mon, 02 May 2005 14:18:55 +0000 |
parents | 44c6410b4845 |
children | b4921dbf8709 |
comparison
equal
deleted
inserted
replaced
162:43cef0f5339d | 163:a8f7dc0a56cb |
---|---|
4 #include <unistd.h> | 4 #include <unistd.h> |
5 #include <string.h> | 5 #include <string.h> |
6 #include <signal.h> | 6 #include <signal.h> |
7 #include <termios.h> | 7 #include <termios.h> |
8 #include <getopt.h> | 8 #include <getopt.h> |
9 #include <sys/types.h> | |
10 #include <sys/wait.h> | |
9 | 11 |
10 #include "jabglue.h" | 12 #include "jabglue.h" |
11 #include "screen.h" | 13 #include "screen.h" |
12 #include "parsecfg.h" | 14 #include "parsecfg.h" |
13 #include "roster.h" | 15 #include "roster.h" |
14 #include "commands.h" | 16 #include "commands.h" |
15 #include "histolog.h" | 17 #include "histolog.h" |
18 #include "hooks.h" | |
16 #include "utils.h" | 19 #include "utils.h" |
17 #include "harddefines.h" | 20 #include "harddefines.h" |
18 | 21 |
19 | 22 |
20 void sig_handler(int signum) | 23 void sig_handler(int signum) |
21 { | 24 { |
22 if (signum == SIGTERM) { | 25 if (signum == SIGCHLD) { |
26 int status; | |
27 pid_t pid; | |
28 do { | |
29 pid = waitpid (WAIT_ANY, &status, WNOHANG); | |
30 } while (pid > 0); | |
31 if (pid < 0) | |
32 ut_WriteLog("Error in waitpid: errno=%d\n", errno); | |
33 signal(SIGCHLD, sig_handler); | |
34 } else if (signum == SIGTERM) { | |
23 // bud_TerminateBuddies(); | 35 // bud_TerminateBuddies(); |
24 scr_TerminateCurses(); | 36 scr_TerminateCurses(); |
25 jb_disconnect(); | 37 jb_disconnect(); |
26 printf("Killed by SIGTERM\nBye!\n"); | 38 printf("Killed by SIGTERM\nBye!\n"); |
27 exit(EXIT_SUCCESS); | 39 exit(EXIT_SUCCESS); |
88 /* SET THIS >0 TO ENABLE LOG */ | 100 /* SET THIS >0 TO ENABLE LOG */ |
89 ut_InitDebug(0, NULL); | 101 ut_InitDebug(0, NULL); |
90 | 102 |
91 ut_WriteLog("Setting signals handlers...\n"); | 103 ut_WriteLog("Setting signals handlers...\n"); |
92 signal(SIGTERM, sig_handler); | 104 signal(SIGTERM, sig_handler); |
93 signal(SIGALRM, sig_handler); | 105 signal(SIGCHLD, sig_handler); |
94 | 106 |
95 sprintf(configFile, "%s/.mcabberrc", getenv("HOME")); | 107 sprintf(configFile, "%s/.mcabberrc", getenv("HOME")); |
96 | 108 |
97 /* Parse command line options */ | 109 /* Parse command line options */ |
98 while (1) { | 110 while (1) { |