From 8013e49cd4bfc0434104c799a260544d6c1549bb Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Mon, 18 Jul 2011 14:52:46 +0200 Subject: [PATCH] waitpid in libpurple backend --- backends/libpurple/main.cpp | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/backends/libpurple/main.cpp b/backends/libpurple/main.cpp index c54fa02d..c942e284 100644 --- a/backends/libpurple/main.cpp +++ b/backends/libpurple/main.cpp @@ -21,6 +21,8 @@ #include "log4cxx/propertyconfigurator.h" #include "log4cxx/helpers/properties.h" #include "log4cxx/helpers/fileinputstream.h" +#include "sys/wait.h" +#include "sys/signal.h" using namespace log4cxx; @@ -1006,6 +1008,21 @@ static bool initPurple(Config &cfg) { return ret; } +static void spectrum_sigchld_handler(int sig) +{ + int status; + pid_t pid; + + do { + pid = waitpid(-1, &status, WNOHANG); + } while (pid != 0 && pid != (pid_t)-1); + + if ((pid == (pid_t) - 1) && (errno != ECHILD)) { + char errmsg[BUFSIZ]; + snprintf(errmsg, BUFSIZ, "Warning: waitpid() returned %d", pid); + perror(errmsg); + } +} int main(int argc, char **argv) { GError *error = NULL; @@ -1040,13 +1057,13 @@ int main(int argc, char **argv) { } else { #ifndef WIN32 -// signal(SIGPIPE, SIG_IGN); -// -// if (signal(SIGCHLD, spectrum_sigchld_handler) == SIG_ERR) { -// std::cout << "SIGCHLD handler can't be set\n"; -// g_option_context_free(context); -// return -1; -// } + signal(SIGPIPE, SIG_IGN); + + if (signal(SIGCHLD, spectrum_sigchld_handler) == SIG_ERR) { + std::cout << "SIGCHLD handler can't be set\n"; + g_option_context_free(context); + return -1; + } // // if (signal(SIGINT, spectrum_sigint_handler) == SIG_ERR) { // std::cout << "SIGINT handler can't be set\n";