summaryrefslogtreecommitdiffstats
path: root/src/daemon/Daemon.cpp
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2011-04-20 13:55:19 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2011-04-20 13:55:19 +0200
commit13a19b78ba45353f9a6a59c8dbb02336c339db35 (patch)
treea3a8fb95a6d4ba1ab52db4da81ee3b277b0306a8 /src/daemon/Daemon.cpp
parent2b2f3018bd91e50c874cfab4df4a847941cb140c (diff)
downloadabrt-13a19b78ba45353f9a6a59c8dbb02336c339db35.tar.gz
abrt-13a19b78ba45353f9a6a59c8dbb02336c339db35.tar.xz
abrt-13a19b78ba45353f9a6a59c8dbb02336c339db35.zip
daemon: simplify parsing of settings; remove remaining c++isms in daemon
This change will not compile, because in C++, void* cannot be automatically cast to char*. Next change renames Settings.cpp to *.c and fixes this. Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'src/daemon/Daemon.cpp')
-rw-r--r--src/daemon/Daemon.cpp163
1 files changed, 63 insertions, 100 deletions
diff --git a/src/daemon/Daemon.cpp b/src/daemon/Daemon.cpp
index 3ac53aeb..6b894f01 100644
--- a/src/daemon/Daemon.cpp
+++ b/src/daemon/Daemon.cpp
@@ -21,7 +21,6 @@
#endif
#include <sys/un.h>
#include <syslog.h>
-#include <string>
#include <sys/inotify.h>
#include <sys/ioctl.h> /* ioctl(FIONREAD) */
#include "abrtlib.h"
@@ -33,9 +32,6 @@
#define PROGNAME "abrtd"
-using namespace std;
-
-
#define VAR_RUN_PIDFILE VAR_RUN"/abrtd.pid"
#define SOCKET_FILE VAR_RUN"/abrt/abrt.socket"
@@ -64,7 +60,6 @@ static volatile sig_atomic_t s_sig_caught;
static int s_signal_pipe[2];
static int s_signal_pipe_write = -1;
static int s_upload_watch = -1;
-static pid_t log_scanner_pid = -1;
static unsigned s_timeout;
static bool s_exiting;
@@ -241,12 +236,6 @@ static gboolean handle_signal_cb(GIOChannel *gio, GIOCondition condition, gpoint
pid_t pid;
while ((pid = waitpid(-1, NULL, WNOHANG)) > 0)
{
- if (pid == log_scanner_pid)
- {
- log("log scanner exited");
- log_scanner_pid = -1;
- continue;
- }
if (socket_client_count)
socket_client_count--;
if (!socket_channel_cb_id)
@@ -597,81 +586,69 @@ int main(int argc, char** argv)
bool pidfile_created = false;
/* Initialization */
- try
- {
- init_daemon_logging();
+ init_daemon_logging();
- VERB1 log("Loading settings");
- if (load_settings() != 0)
- throw 1;
+ VERB1 log("Loading settings");
+ if (load_settings() != 0)
+ goto init_error;
- sanitize_dump_dir_rights();
+ sanitize_dump_dir_rights();
- VERB1 log("Creating glib main loop");
- pMainloop = g_main_loop_new(NULL, FALSE);
+ VERB1 log("Creating glib main loop");
+ pMainloop = g_main_loop_new(NULL, FALSE);
- VERB1 log("Initializing inotify");
- errno = 0;
- int inotify_fd = inotify_init();
- if (inotify_fd == -1)
- perror_msg_and_die("inotify_init failed");
- close_on_exec_on(inotify_fd);
+ VERB1 log("Initializing inotify");
+ errno = 0;
+ int inotify_fd = inotify_init();
+ if (inotify_fd == -1)
+ perror_msg_and_die("inotify_init failed");
+ close_on_exec_on(inotify_fd);
- /* Watching DEBUG_DUMPS_DIR for new files... */
- if (inotify_add_watch(inotify_fd, DEBUG_DUMPS_DIR, IN_CREATE | IN_MOVED_TO) < 0)
- {
- perror_msg("inotify_add_watch failed on '%s'", DEBUG_DUMPS_DIR);
- throw 1;
- }
- if (g_settings_sWatchCrashdumpArchiveDir)
- {
- s_upload_watch = inotify_add_watch(inotify_fd, g_settings_sWatchCrashdumpArchiveDir, IN_CLOSE_WRITE|IN_MOVED_TO);
- if (s_upload_watch < 0)
- {
- perror_msg("inotify_add_watch failed on '%s'", g_settings_sWatchCrashdumpArchiveDir);
- throw 1;
- }
- }
- VERB1 log("Adding inotify watch to glib main loop");
- channel_inotify = g_io_channel_unix_new(inotify_fd);
- channel_inotify_event_id = g_io_add_watch(channel_inotify,
- G_IO_IN,
- handle_inotify_cb,
- NULL);
-
- /* Add an event source which waits for INT/TERM signal */
- VERB1 log("Adding signal pipe watch to glib main loop");
- channel_signal = g_io_channel_unix_new(s_signal_pipe[0]);
- channel_signal_event_id = g_io_add_watch(channel_signal,
- G_IO_IN,
- handle_signal_cb,
- NULL);
-
- /* Mark the territory */
- VERB1 log("Creating pid file");
- if (create_pidfile() != 0)
- throw 1;
- pidfile_created = true;
-
- /* Open socket to receive new crashes. */
- dumpsocket_init();
-
- /* Note: this already may process a few dbus messages,
- * therefore it should be the last thing to initialize.
- */
- VERB1 log("Initializing dbus");
- if (init_dbus() != 0)
- throw 1;
+ /* Watching DEBUG_DUMPS_DIR for new files... */
+ if (inotify_add_watch(inotify_fd, DEBUG_DUMPS_DIR, IN_CREATE | IN_MOVED_TO) < 0)
+ {
+ perror_msg("inotify_add_watch failed on '%s'", DEBUG_DUMPS_DIR);
+ goto init_error;
}
- catch (...)
+ if (g_settings_sWatchCrashdumpArchiveDir)
{
- /* Initialization error */
- error_msg("Error while initializing daemon");
- /* Inform parent that initialization failed */
- if (!(opts & OPT_d))
- kill(parent_pid, SIGINT);
- goto cleanup;
+ s_upload_watch = inotify_add_watch(inotify_fd, g_settings_sWatchCrashdumpArchiveDir, IN_CLOSE_WRITE|IN_MOVED_TO);
+ if (s_upload_watch < 0)
+ {
+ perror_msg("inotify_add_watch failed on '%s'", g_settings_sWatchCrashdumpArchiveDir);
+ goto init_error;
+ }
}
+ VERB1 log("Adding inotify watch to glib main loop");
+ channel_inotify = g_io_channel_unix_new(inotify_fd);
+ channel_inotify_event_id = g_io_add_watch(channel_inotify,
+ G_IO_IN,
+ handle_inotify_cb,
+ NULL);
+
+ /* Add an event source which waits for INT/TERM signal */
+ VERB1 log("Adding signal pipe watch to glib main loop");
+ channel_signal = g_io_channel_unix_new(s_signal_pipe[0]);
+ channel_signal_event_id = g_io_add_watch(channel_signal,
+ G_IO_IN,
+ handle_signal_cb,
+ NULL);
+
+ /* Mark the territory */
+ VERB1 log("Creating pid file");
+ if (create_pidfile() != 0)
+ goto init_error;
+ pidfile_created = true;
+
+ /* Open socket to receive new crashes. */
+ dumpsocket_init();
+
+ /* Note: this already may process a few dbus messages,
+ * therefore it should be the last thing to initialize.
+ */
+ VERB1 log("Initializing dbus");
+ if (init_dbus() != 0)
+ goto init_error;
/* Inform parent that we initialized ok */
if (!(opts & OPT_d))
@@ -685,22 +662,6 @@ int main(int argc, char** argv)
/* Only now we want signal pipe to work */
s_signal_pipe_write = s_signal_pipe[1];
- if (g_settings_sLogScanners)
- {
- const char *scanner_argv[] = {
- "/bin/sh", "-c",
- g_settings_sLogScanners,
- NULL
- };
- log_scanner_pid = fork_execv_on_steroids(EXECFLG_INPUT_NUL,
- (char**)scanner_argv,
- /*pipefds:*/ NULL,
- /*env_vec:*/ NULL,
- /*dir:*/ NULL,
- /*uid:*/ 0);
- VERB1 log("Started log scanner, pid:%d", (int)log_scanner_pid);
- }
-
/* Enter the event loop */
log("Init complete, entering main loop");
run_main_loop(pMainloop);
@@ -729,12 +690,6 @@ int main(int argc, char** argv)
free_settings();
- if (log_scanner_pid > 0)
- {
- VERB2 log("Sending SIGTERM to %d", log_scanner_pid);
- kill(log_scanner_pid, SIGTERM);
- }
-
/* Exiting */
if (s_sig_caught && s_sig_caught != SIGALRM && s_sig_caught != SIGCHLD)
{
@@ -743,4 +698,12 @@ int main(int argc, char** argv)
raise(s_sig_caught);
}
error_msg_and_die("Exiting");
+
+ init_error:
+ /* Initialization error */
+ error_msg("Error while initializing daemon");
+ /* Inform parent that initialization failed */
+ if (!(opts & OPT_d))
+ kill(parent_pid, SIGINT);
+ goto cleanup;
}