diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-07-17 15:52:27 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-07-17 15:52:27 +0200 |
| commit | 37ab187408799ba3f3f9107bdc5a72fea0b4b608 (patch) | |
| tree | b4a0a376ba97b573e8e52cdae8893a136fa8b8e2 /src/Daemon/Daemon.cpp | |
| parent | 27967b17597a24e76f06871332d7a44eeb790a80 (diff) | |
| download | abrt-37ab187408799ba3f3f9107bdc5a72fea0b4b608.tar.gz abrt-37ab187408799ba3f3f9107bdc5a72fea0b4b608.tar.xz abrt-37ab187408799ba3f3f9107bdc5a72fea0b4b608.zip | |
rework unsafe handling of SIGINT/SIGTERM
Signals are asynchronous. It is unsafe to perform such complex
operations in a signal handler. I changed signal handler
to just set a flag, and added an event source which returns an event
when this variable is set. The action is to stop event loop.
Execution then falls through to program exit.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'src/Daemon/Daemon.cpp')
| -rw-r--r-- | src/Daemon/Daemon.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index ea769c5..c28331f 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -25,15 +25,15 @@ #include <sys/stat.h> #include <fcntl.h> -CCrashWatcher *g_pCrashWatcher = NULL; +uint8_t sig_caught; -void terminate(int signal) +static void handle_fatal_signal(int signal) { - fprintf(stderr, "Got SIGINT/SIGTERM, cleaning up..\n"); - delete g_pCrashWatcher; - exit(0); + sig_caught = signal; } +CCrashWatcher *g_pCrashWatcher = NULL; + void print_help() { @@ -43,8 +43,8 @@ int main(int argc, char** argv) { int daemonize = 1; /*signal handlers */ - signal(SIGTERM, terminate); - signal(SIGINT, terminate); + signal(SIGTERM, handle_fatal_signal); + signal(SIGINT, handle_fatal_signal); try { @@ -97,7 +97,7 @@ int main(int argc, char** argv) { std::cerr << "Cannot create daemon: " << e.what() << std::endl; } - //do we need this? delete g_pCrashWatcher; + delete g_pCrashWatcher; return 1; /* Any exit is a failure. Normally we don't exit at all */ } |
