From 7f10181be367d77e5f3203e938ab24cf722119df Mon Sep 17 00:00:00 2001 From: Nikola Pajkovsky Date: Thu, 29 Oct 2009 15:20:56 +0100 Subject: Normal user can see kerneloops and report it Bugzilla memory leaks fix --- src/Daemon/Daemon.cpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'src/Daemon/Daemon.cpp') diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index d1ab188e..a6a4f93c 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #if HAVE_CONFIG_H #include #endif @@ -555,14 +556,34 @@ static gboolean handle_event_cb(GIOChannel *gio, GIOCondition condition, gpointe log("New crash, saving..."); RunActionsAndReporters(crashinfo[CD_MWDDD][CD_CONTENT]); /* Send dbus signal */ - g_pCommLayer->Crash(crashinfo[CD_PACKAGE][CD_CONTENT], crashinfo[CD_UID][CD_CONTENT]); + if(crashinfo[CD_MWANALYZER][CD_CONTENT] == "Kerneloops") + { + // When Kerneloops comes it will be sent uid with -1 + // Applet will detected and show normal user + std::cout << "New: package|kerneloops" << crashinfo[CD_PACKAGE][CD_CONTENT] << std::endl; + g_pCommLayer->Crash(crashinfo[CD_PACKAGE][CD_CONTENT], to_string(UINT_MAX)); + } + else + { + g_pCommLayer->Crash(crashinfo[CD_PACKAGE][CD_CONTENT], crashinfo[CD_UID][CD_CONTENT]); + } break; case MW_REPORTED: case MW_OCCURED: log("Already saved crash, deleting..."); /* Send dbus signal */ - g_pCommLayer->Crash(crashinfo[CD_PACKAGE][CD_CONTENT], crashinfo[CD_UID][CD_CONTENT]); - DeleteDebugDumpDir(std::string(DEBUG_DUMPS_DIR) + "/" + name); + if(crashinfo[CD_MWANALYZER][CD_CONTENT] == "Kerneloops") + { + // When Kerneloops comes it will be sent uid with -1 + // Applet will detected and show normal user + std::cout << "New: package|kerneloops" << crashinfo[CD_PACKAGE][CD_CONTENT] << std::endl; + g_pCommLayer->Crash(crashinfo[CD_PACKAGE][CD_CONTENT], to_string(UINT_MAX)); + } + else + { + g_pCommLayer->Crash(crashinfo[CD_PACKAGE][CD_CONTENT], crashinfo[CD_UID][CD_CONTENT]); + } + //DeleteDebugDumpDir(std::string(DEBUG_DUMPS_DIR) + "/" + name); break; case MW_BLACKLISTED: case MW_CORRUPTED: -- cgit From c67fbecc1958fdc47d9614e971c9936c446d911e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 30 Oct 2009 11:12:44 +0100 Subject: reenable sanitization of /var/cache/abrt; create abrt-di (debuginfo cache) too Signed-off-by: Denys Vlasenko --- src/Daemon/Daemon.cpp | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'src/Daemon/Daemon.cpp') diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index a6a4f93c..c33806bb 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -632,23 +632,28 @@ static void start_syslog_logging() logmode = LOGMODE_SYSLOG; } -static void sanitize_dump_dir_rights() +static void ensure_root_writable_dir(const char *dir) { struct stat sb; - if (mkdir(DEBUG_DUMPS_DIR, 0755) != 0 && errno != EEXIST) - perror_msg_and_die("Can't create '%s'", DEBUG_DUMPS_DIR); - if (stat(DEBUG_DUMPS_DIR, &sb) != 0 || !S_ISDIR(sb.st_mode)) - error_msg_and_die("'%s' is not a directory", DEBUG_DUMPS_DIR); - - if (sb.st_uid != 0 || sb.st_gid != 0 || chown(DEBUG_DUMPS_DIR, 0, 0) != 0) - perror_msg_and_die("Can't set owner 0:0 on '%s'", DEBUG_DUMPS_DIR); + if (mkdir(dir, 0755) != 0 && errno != EEXIST) + perror_msg_and_die("Can't create '%s'", dir); + if (stat(dir, &sb) != 0 || !S_ISDIR(sb.st_mode)) + error_msg_and_die("'%s' is not a directory", dir); + if (sb.st_uid != 0 || sb.st_gid != 0 || chown(dir, 0, 0) != 0) + perror_msg_and_die("Can't set owner 0:0 on '%s'", dir); /* We can't allow anyone to create dumps: otherwise users can flood * us with thousands of bogus or malicious dumps */ /* 07000 bits are setuid, setgit, and sticky, and they must be unset */ - /* 00777 bits are usual "rwx" access rights */ - if ((sb.st_mode & 07777) != 0755 && chmod(DEBUG_DUMPS_DIR, 0755) != 0) - perror_msg_and_die("Can't set mode rwxr-xr-x on '%s'", DEBUG_DUMPS_DIR); + /* 00777 bits are usual "rwxrwxrwx" access rights */ + if ((sb.st_mode & 07777) != 0755 && chmod(dir, 0755) != 0) + perror_msg_and_die("Can't set mode rwxr-xr-x on '%s'", dir); +} + +static void sanitize_dump_dir_rights() +{ + ensure_root_writable_dir(DEBUG_DUMPS_DIR); + ensure_root_writable_dir(DEBUG_DUMPS_DIR"-di"); /* debuginfo cache */ } int main(int argc, char** argv) @@ -740,11 +745,12 @@ int main(int argc, char** argv) g_pMainloop = g_main_loop_new(NULL, FALSE); /* Watching DEBUG_DUMPS_DIR for new files... */ VERB1 log("Initializing inotify"); - /*FIXME: python hook runs with ordinary user privileges, - so it fails if everyone doesn't have write acces - to DEBUG_DUMPS_DIR - */ - //sanitize_dump_dir_rights(); +// Enabled again since we have new abrt-pyhook-helper, remove comment when verified to work + /* FIXME: python hook runs with ordinary user privileges, + * so it fails if everyone doesn't have write acces + * to DEBUG_DUMPS_DIR + */ + sanitize_dump_dir_rights(); errno = 0; int inotify_fd = inotify_init(); if (inotify_fd == -1) -- cgit From 06671bee8dbf4c5f7f633e3bd6ae7e5135cac0f1 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 30 Oct 2009 12:35:13 +0100 Subject: fix incorrect logic for checking/correcting directory owner Signed-off-by: Denys Vlasenko --- src/Daemon/Daemon.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Daemon/Daemon.cpp') diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index c33806bb..9615ce8a 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -640,7 +640,7 @@ static void ensure_root_writable_dir(const char *dir) perror_msg_and_die("Can't create '%s'", dir); if (stat(dir, &sb) != 0 || !S_ISDIR(sb.st_mode)) error_msg_and_die("'%s' is not a directory", dir); - if (sb.st_uid != 0 || sb.st_gid != 0 || chown(dir, 0, 0) != 0) + if ((sb.st_uid != 0 || sb.st_gid != 0) && chown(dir, 0, 0) != 0) perror_msg_and_die("Can't set owner 0:0 on '%s'", dir); /* We can't allow anyone to create dumps: otherwise users can flood * us with thousands of bogus or malicious dumps */ -- cgit From 97b4cfbb26c87a79f5cf74fd67781486616f4541 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 30 Oct 2009 14:50:03 +0100 Subject: *: wire up /var/run/abrt in a few more places Signed-off-by: Denys Vlasenko --- src/Daemon/Daemon.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/Daemon/Daemon.cpp') diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index 9615ce8a..b509b9fc 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -654,6 +654,7 @@ static void sanitize_dump_dir_rights() { ensure_root_writable_dir(DEBUG_DUMPS_DIR); ensure_root_writable_dir(DEBUG_DUMPS_DIR"-di"); /* debuginfo cache */ + ensure_root_writable_dir(VAR_RUN"/abrt"); /* temp dir */ } int main(int argc, char** argv) -- cgit From bc2da7891acc79a77de00e89f2fe39660dee228e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 31 Oct 2009 02:26:59 +0100 Subject: implement abrtd -t TIMEOUT_IN_SEC Signed-off-by: Denys Vlasenko --- src/Daemon/Daemon.cpp | 167 +++++++++++++++++++++++++++++--------------------- 1 file changed, 96 insertions(+), 71 deletions(-) (limited to 'src/Daemon/Daemon.cpp') diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index b509b9fc..4a4f6918 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -107,12 +107,12 @@ typedef struct cron_callback_data_t static uint8_t s_sig_caught; -static GMainLoop* g_pMainloop; +static int s_signal_pipe[2]; +static unsigned s_timeout; +static bool s_exiting; CCommLayerServer* g_pCommLayer; -pthread_mutex_t g_pJobsMutex; - /* Is it "." or ".."? */ /* abrtlib candidate */ @@ -323,13 +323,13 @@ static int SetUpCron() vector_pair_string_string_t::iterator it_ar = it_c->second.begin(); for (; it_ar != it_c->second.end(); it_ar++) { - cron_callback_data_t* cronOneCallbackData = new cron_callback_data_t((*it_ar).first, (*it_ar).second, timeout); + cron_callback_data_t* cronOneCallbackData = new cron_callback_data_t(it_ar->first, it_ar->second, timeout); g_timeout_add_seconds_full(G_PRIORITY_DEFAULT, timeout, cron_activation_one_cb, static_cast(cronOneCallbackData), cron_delete_callback_data_cb); - cron_callback_data_t* cronResheduleCallbackData = new cron_callback_data_t((*it_ar).first, (*it_ar).second, 24 * 60 * 60); + cron_callback_data_t* cronResheduleCallbackData = new cron_callback_data_t(it_ar->first, it_ar->second, 24 * 60 * 60); g_timeout_add_seconds_full(G_PRIORITY_DEFAULT, timeout, cron_activation_reshedule_cb, @@ -457,60 +457,38 @@ static int Lock() static void handle_fatal_signal(int signal) { s_sig_caught = signal; + write(s_signal_pipe[1], &s_sig_caught, 1); } -/* One of our event sources is s_sig_caught when it becomes != 0. - * glib machinery we need to hook it up to the main loop: - * prepare(): - * If the source can determine that it is ready here (without waiting - * for the results of the poll() call) it should return TRUE. It can also - * return a timeout_ value which should be the maximum timeout (in milliseconds) - * which should be passed to the poll() call. - * check(): - * Called after all the file descriptors are polled. The source should - * return TRUE if it is ready to be dispatched. - * dispatch(): - * Called to dispatch the event source, after it has returned TRUE - * in either its prepare or its check function. The dispatch function - * is passed in a callback function and data. The callback function - * may be NULL if the source was never connected to a callback using - * g_source_set_callback(). The dispatch function should - * call the callback function with user_data and whatever additional - * parameters are needed for this type of event source. - */ -static gboolean waitsignal_prepare(GSource *source, gint *timeout_) -{ - /* We depend on the fact that in Unix, poll() is interrupted - * by caught signals (in returns EINTR). Thus we do not need to set - * a small timeout here: infinite timeout (-1) works too */ - *timeout_ = -1; - return s_sig_caught != 0; -} -static gboolean waitsignal_check(GSource *source) -{ - return s_sig_caught != 0; -} -static gboolean waitsignal_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) +/* Signal pipe handler */ +static gboolean handle_signal_cb(GIOChannel *gio, GIOCondition condition, gpointer ptr_unused) { - g_main_quit(g_pMainloop); - return 1; + char signo; + gsize len = 0; + g_io_channel_read(gio, &signo, 1, &len); + if (len == 1) + { + /* we did receive a signal */ + s_exiting = 1; + return TRUE; + } + return FALSE; } /* Inotify handler */ -static gboolean handle_event_cb(GIOChannel *gio, GIOCondition condition, gpointer ptr_unused) +static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpointer ptr_unused) { /* 128 simultaneous actions */ #define INOTIFY_BUFF_SIZE ((sizeof(struct inotify_event) + FILENAME_MAX)*128) - GIOError err; - char *buf = new char[INOTIFY_BUFF_SIZE]; + char *buf = (char*)xmalloc(INOTIFY_BUFF_SIZE); gsize len; gsize i = 0; errno = 0; - err = g_io_channel_read(gio, buf, INOTIFY_BUFF_SIZE, &len); + GIOError err = g_io_channel_read(gio, buf, INOTIFY_BUFF_SIZE, &len); if (err != G_IO_ERROR_NONE) { perror_msg("Error reading inotify fd"); - delete[] buf; + free(buf); return FALSE; } /* reconstruct each event and send message to the dbus */ @@ -602,21 +580,57 @@ static gboolean handle_event_cb(GIOChannel *gio, GIOCondition condition, gpointe warn_client(e.what()); if (e.type() == EXCEP_FATAL) { - delete[] buf; + free(buf); return -1; } } catch (...) { - delete[] buf; + free(buf); throw; } } /* while */ - delete[] buf; + free(buf); return TRUE; } +/* Run main loop with idle timeout. + * Basically, almost like glib's g_main_run(loop) + */ +static void run_main_loop(GMainLoop* loop) +{ + GMainContext *context = g_main_loop_get_context(loop); + + while (!s_exiting) + { + /* we have just a handful of sources, 32 should be ample */ + const unsigned NUM_POLLFDS = 32; + GPollFD fds[NUM_POLLFDS]; + gboolean some_ready; + gint max_priority; + gint timeout; + + some_ready = g_main_context_prepare(context, &max_priority); + if (some_ready) + g_main_context_dispatch(context); + + gint nfds = g_main_context_query(context, max_priority, &timeout, fds, NUM_POLLFDS); + if (nfds > NUM_POLLFDS) + error_msg_and_die("Internal error"); + + if (s_timeout) + alarm(s_timeout); + g_poll(fds, nfds, timeout); + if (s_timeout) + alarm(0); + + some_ready = g_main_context_check(context, max_priority, fds, nfds); + if (some_ready) + g_main_context_dispatch(context); + } +} + static void start_syslog_logging() { /* Open stdin to /dev/null */ @@ -670,8 +684,10 @@ int main(int argc, char** argv) textdomain(PACKAGE); #endif - while ((opt = getopt(argc, argv, "dsv")) != -1) + while ((opt = getopt(argc, argv, "dsvt:")) != -1) { + unsigned long ul; + switch (opt) { case 'd': @@ -683,20 +699,32 @@ int main(int argc, char** argv) case 'v': g_verbose++; break; + case 't': + char *end; + errno = 0; + s_timeout = ul = strtoul(optarg, &end, 0); + if (errno == 0 && *end == '\0' && ul <= INT_MAX) + break; + /* fall through to error */ default: error_msg_and_die( "Usage: abrtd [-dv]\n" "\nOptions:" "\n\t-d\tDo not daemonize" "\n\t-s\tLog to syslog even with -d" + "\n\t-t SEC\tExit after SEC seconds of inactivity" "\n\t-v\tVerbose" ); } } msg_prefix = "abrtd: "; /* for log(), error_msg() and such */ + + xpipe(s_signal_pipe); signal(SIGTERM, handle_fatal_signal); - signal(SIGINT, handle_fatal_signal); + signal(SIGINT, handle_fatal_signal); + if (s_timeout) + signal(SIGALRM, handle_fatal_signal); /* Daemonize unless -d */ if (daemonize) @@ -732,7 +760,9 @@ int main(int argc, char** argv) start_syslog_logging(); } - GIOChannel* pGio = NULL; + GMainLoop* pMainloop = NULL; + GIOChannel* pGiochannel_inotify = NULL; + GIOChannel* pGiochannel_signal = NULL; bool lockfile_created = false; bool pidfile_created = false; CCrashWatcher watcher; @@ -740,10 +770,9 @@ int main(int argc, char** argv) /* Initialization */ try { - pthread_mutex_init(&g_pJobsMutex, NULL); /* never fails */ init_daemon_logging(&watcher); VERB1 log("Creating glib main loop"); - g_pMainloop = g_main_loop_new(NULL, FALSE); + pMainloop = g_main_loop_new(NULL, FALSE); /* Watching DEBUG_DUMPS_DIR for new files... */ VERB1 log("Initializing inotify"); // Enabled again since we have new abrt-pyhook-helper, remove comment when verified to work @@ -775,18 +804,12 @@ int main(int argc, char** argv) if (g_pCommLayer->m_init_error) throw 1; VERB1 log("Adding inotify watch to glib main loop"); - pGio = g_io_channel_unix_new(inotify_fd); - g_io_add_watch(pGio, G_IO_IN, handle_event_cb, NULL); + pGiochannel_inotify = g_io_channel_unix_new(inotify_fd); + g_io_add_watch(pGiochannel_inotify, G_IO_IN, handle_inotify_cb, NULL); /* Add an event source which waits for INT/TERM signal */ - VERB1 log("Adding signal watch to glib main loop"); - GSourceFuncs waitsignal_funcs; - memset(&waitsignal_funcs, 0, sizeof(waitsignal_funcs)); - waitsignal_funcs.prepare = waitsignal_prepare; - waitsignal_funcs.check = waitsignal_check; - waitsignal_funcs.dispatch = waitsignal_dispatch; - /*waitsignal_funcs.finalize = NULL; - already done */ - GSource *waitsignal_src = (GSource*) g_source_new(&waitsignal_funcs, sizeof(*waitsignal_src)); - g_source_attach(waitsignal_src, g_main_context_default()); + VERB1 log("Adding signal pipe watch to glib main loop"); + pGiochannel_signal = g_io_channel_unix_new(s_signal_pipe[0]); + g_io_add_watch(pGiochannel_signal, G_IO_IN, handle_signal_cb, NULL); /* Mark the territory */ VERB1 log("Creating lock file"); if (Lock() != 0) @@ -822,7 +845,7 @@ int main(int argc, char** argv) /* This may take a while, therefore we don't do it in init section */ FindNewDumps(DEBUG_DUMPS_DIR); log("Running..."); - g_main_run(g_pMainloop); + run_main_loop(pMainloop); } catch (CABRTException& e) { @@ -841,8 +864,12 @@ int main(int argc, char** argv) unlink(VAR_RUN_PIDFILE); if (lockfile_created) unlink(VAR_RUN_LOCK_FILE); - if (pGio) - g_io_channel_unref(pGio); + + if (pGiochannel_signal) + g_io_channel_unref(pGiochannel_signal); + if (pGiochannel_inotify) + g_io_channel_unref(pGiochannel_inotify); + delete g_pCommLayer; if (g_pPluginManager) { @@ -850,13 +877,11 @@ int main(int argc, char** argv) g_pPluginManager->UnLoadPlugins(); delete g_pPluginManager; } - if (g_pMainloop) - g_main_loop_unref(g_pMainloop); - if (pthread_mutex_destroy(&g_pJobsMutex) != 0) - error_msg("Threading error: job mutex locked"); + if (pMainloop) + g_main_loop_unref(pMainloop); /* Exiting */ - if (s_sig_caught) + if (s_sig_caught && s_sig_caught != SIGALRM) { error_msg_and_die("Got signal %d, exiting", s_sig_caught); signal(s_sig_caught, SIG_DFL); -- cgit From 68e616def90ece3bdde925dc106e51e8560fa05d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 2 Nov 2009 11:58:01 +0100 Subject: lib/Plugins/CCpp: respect DebugInfoCacheMB setting Signed-off-by: Denys Vlasenko --- src/Daemon/Daemon.cpp | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'src/Daemon/Daemon.cpp') diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index 4a4f6918..188cd0d1 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -114,17 +114,6 @@ static bool s_exiting; CCommLayerServer* g_pCommLayer; -/* Is it "." or ".."? */ -/* abrtlib candidate */ -static bool dot_or_dotdot(const char *filename) -{ - if (filename[0] != '.') return false; - if (filename[1] == '\0') return true; - if (filename[1] != '.') return false; - if (filename[2] == '\0') return true; - return false; -} - static double GetDirSize(const std::string &pPath, std::string *worst_dir = NULL, const char *excluded = NULL) { DIR *dp = opendir(pPath.c_str()); @@ -621,7 +610,7 @@ static void run_main_loop(GMainLoop* loop) if (s_timeout) alarm(s_timeout); - g_poll(fds, nfds, timeout); + g_poll(fds, nfds, timeout); if (s_timeout) alarm(0); @@ -709,7 +698,7 @@ int main(int argc, char** argv) default: error_msg_and_die( "Usage: abrtd [-dv]\n" - "\nOptions:" + "\nOptions:" "\n\t-d\tDo not daemonize" "\n\t-s\tLog to syslog even with -d" "\n\t-t SEC\tExit after SEC seconds of inactivity" -- cgit From e663e0abf48efb07fe7ed644ae27e624e207e5c2 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 2 Nov 2009 15:25:27 +0100 Subject: abrtd: fix bad interaction with -T SEC code and !-d Signed-off-by: Denys Vlasenko --- src/Daemon/Daemon.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/Daemon/Daemon.cpp') diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index 188cd0d1..0e81dfdc 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -106,8 +106,9 @@ typedef struct cron_callback_data_t } cron_callback_data_t; -static uint8_t s_sig_caught; +static uint8_t s_sig_caught; /* must be one byte */ static int s_signal_pipe[2]; +static int s_signal_pipe_write = -1; static unsigned s_timeout; static bool s_exiting; @@ -443,10 +444,12 @@ static int Lock() /* we leak opened lfd intentionally */ } -static void handle_fatal_signal(int signal) +static void handle_fatal_signal(int signo) { - s_sig_caught = signal; - write(s_signal_pipe[1], &s_sig_caught, 1); + s_sig_caught = signo; + VERB3 log("Got signal %d", signo); + if (s_signal_pipe_write >= 0) + write(s_signal_pipe_write, &s_sig_caught, 1); } /* Signal pipe handler */ @@ -458,6 +461,7 @@ static gboolean handle_signal_cb(GIOChannel *gio, GIOCondition condition, gpoint if (len == 1) { /* we did receive a signal */ + VERB3 log("Got signal %d through signal pipe", signo); s_exiting = 1; return TRUE; } @@ -828,6 +832,9 @@ int main(int argc, char** argv) start_syslog_logging(); } + /* Only now we want signal pipe to work */ + s_signal_pipe_write = s_signal_pipe[1]; + /* Enter the event loop */ try { -- cgit From e8eefb19c47a7f4e7481d1f6460f8632e09bd76e Mon Sep 17 00:00:00 2001 From: Nikola Pajkovsky Date: Tue, 3 Nov 2009 12:15:55 +0100 Subject: kerneloop has uid = -1 new --- src/Daemon/Daemon.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/Daemon/Daemon.cpp') diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index 0e81dfdc..ef78c6a6 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -531,8 +531,7 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin { // When Kerneloops comes it will be sent uid with -1 // Applet will detected and show normal user - std::cout << "New: package|kerneloops" << crashinfo[CD_PACKAGE][CD_CONTENT] << std::endl; - g_pCommLayer->Crash(crashinfo[CD_PACKAGE][CD_CONTENT], to_string(UINT_MAX)); + g_pCommLayer->Crash(crashinfo[CD_PACKAGE][CD_CONTENT], to_string("-1")); } else { @@ -547,8 +546,7 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin { // When Kerneloops comes it will be sent uid with -1 // Applet will detected and show normal user - std::cout << "New: package|kerneloops" << crashinfo[CD_PACKAGE][CD_CONTENT] << std::endl; - g_pCommLayer->Crash(crashinfo[CD_PACKAGE][CD_CONTENT], to_string(UINT_MAX)); + g_pCommLayer->Crash(crashinfo[CD_PACKAGE][CD_CONTENT], to_string("-1")); } else { -- cgit From 7ea8edef92be0c7812699d3e9d9a20bad8227ef3 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 3 Nov 2009 20:26:14 +0100 Subject: lib/Plugins/Bugzilla: sanitize xmlrpc init; fix bug where ssl_verify=1 always Signed-off-by: Denys Vlasenko --- src/Daemon/Daemon.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/Daemon/Daemon.cpp') diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index ef78c6a6..af4f9dc5 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -18,11 +18,13 @@ */ #include -#include -#include #include #include #include +#include +#include +#include +#include #if HAVE_CONFIG_H #include #endif @@ -762,6 +764,13 @@ int main(int argc, char** argv) try { init_daemon_logging(&watcher); + + VERB1 log("Initializing XML-RPC library"); + xmlrpc_env env; + xmlrpc_env_init(&env); + xmlrpc_client_setup_global_const(&env); + if (env.fault_occurred) + error_msg_and_die("XML-RPC Fault: %s(%d)", env.fault_string, env.fault_code); VERB1 log("Creating glib main loop"); pMainloop = g_main_loop_new(NULL, FALSE); /* Watching DEBUG_DUMPS_DIR for new files... */ -- cgit From 01f36609ba1631751e492784d95b0e6b0706cf45 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 4 Nov 2009 17:17:53 +0100 Subject: abrtd: call res_init() if /etc/resolv.conf or friends were changed Signed-off-by: Denys Vlasenko --- src/Daemon/Daemon.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/Daemon/Daemon.cpp') diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index af4f9dc5..175efe93 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -19,6 +19,7 @@ #include #include +#include /* res_init */ #include #include #include @@ -594,6 +595,8 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin static void run_main_loop(GMainLoop* loop) { GMainContext *context = g_main_loop_get_context(loop); + time_t old_time = 0; + time_t dns_conf_hash = 0; while (!s_exiting) { @@ -618,6 +621,33 @@ static void run_main_loop(GMainLoop* loop) if (s_timeout) alarm(0); + /* res_init() makes glibc reread /etc/resolv.conf. + * I'd think libc should be clever enough to do it itself + * at every name resolution attempt, but no... + * We need to guess ourself whether we want to do it. + */ + time_t now = time(NULL) >> 2; + if (old_time != now) /* check once in 4 seconds */ + { + old_time = now; + + time_t hash = 0; + struct stat sb; + if (stat("/etc/resolv.conf", &sb) == 0) + hash = sb.st_mtime; + if (stat("/etc/host.conf", &sb) == 0) + hash += sb.st_mtime; + if (stat("/etc/hosts", &sb) == 0) + hash += sb.st_mtime; + if (stat("/etc/nsswitch.conf", &sb) == 0) + hash += sb.st_mtime; + if (dns_conf_hash != hash) + { + dns_conf_hash = hash; + res_init(); + } + } + some_ready = g_main_context_check(context, max_priority, fds, nfds); if (some_ready) g_main_context_dispatch(context); -- cgit From 64c5d35aebc38f93ce5c086c15c15de5acb21b2f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 5 Nov 2009 17:21:11 +0100 Subject: InformAllUsers support. enabled by default for Kerneloops. Tested wuth CCpp. Signed-off-by: Denys Vlasenko --- src/Daemon/Daemon.cpp | 50 +++++++++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 27 deletions(-) (limited to 'src/Daemon/Daemon.cpp') diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index 175efe93..fd7951f5 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -165,6 +165,18 @@ static double GetDirSize(const std::string &pPath, std::string *worst_dir = NULL return size; } +static bool analyzer_has_InformAllUsers(const char *analyzer_name) +{ + CAnalyzer* analyzer = g_pPluginManager->GetAnalyzer(analyzer_name); + if (!analyzer) + return false; + map_plugin_settings_t settings = analyzer->GetSettings(); + map_plugin_settings_t::const_iterator it = settings.find("InformAllUsers"); + if (it == settings.end()) + return false; + return string_to_bool(it->second.c_str()); +} + static void cron_delete_callback_data_cb(gpointer data) { cron_callback_data_t* cronDeleteCallbackData = static_cast(data); @@ -369,8 +381,7 @@ static void FindNewDumps(const char* pPath) map_crash_info_t crashinfo; try { - mw_result_t res; - res = SaveDebugDump(*itt, crashinfo); + mw_result_t res = SaveDebugDump(*itt, crashinfo); switch (res) { case MW_OK: @@ -522,38 +533,23 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin map_crash_info_t crashinfo; try { - mw_result_t res; - res = SaveDebugDump(std::string(DEBUG_DUMPS_DIR) + "/" + name, crashinfo); + mw_result_t res = SaveDebugDump(std::string(DEBUG_DUMPS_DIR) + "/" + name, crashinfo); switch (res) { case MW_OK: - log("New crash, saving..."); + log("New crash, saving"); RunActionsAndReporters(crashinfo[CD_MWDDD][CD_CONTENT]); - /* Send dbus signal */ - if(crashinfo[CD_MWANALYZER][CD_CONTENT] == "Kerneloops") - { - // When Kerneloops comes it will be sent uid with -1 - // Applet will detected and show normal user - g_pCommLayer->Crash(crashinfo[CD_PACKAGE][CD_CONTENT], to_string("-1")); - } - else - { - g_pCommLayer->Crash(crashinfo[CD_PACKAGE][CD_CONTENT], crashinfo[CD_UID][CD_CONTENT]); - } - break; + /* Fall through to "send dbus signal" */ case MW_REPORTED: case MW_OCCURED: - log("Already saved crash, deleting..."); + if (res != MW_OK) + log("Already saved crash, just sending dbus signal"); /* Send dbus signal */ - if(crashinfo[CD_MWANALYZER][CD_CONTENT] == "Kerneloops") - { - // When Kerneloops comes it will be sent uid with -1 - // Applet will detected and show normal user - g_pCommLayer->Crash(crashinfo[CD_PACKAGE][CD_CONTENT], to_string("-1")); - } - else { - g_pCommLayer->Crash(crashinfo[CD_PACKAGE][CD_CONTENT], crashinfo[CD_UID][CD_CONTENT]); + const char *uid_str = analyzer_has_InformAllUsers(crashinfo[CD_MWANALYZER][CD_CONTENT].c_str()) + ? NULL + : crashinfo[CD_UID][CD_CONTENT].c_str(); + g_pCommLayer->Crash(crashinfo[CD_PACKAGE][CD_CONTENT].c_str(), uid_str); } //DeleteDebugDumpDir(std::string(DEBUG_DUMPS_DIR) + "/" + name); break; @@ -564,7 +560,7 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin case MW_IN_DB: case MW_FILE_ERROR: default: - log("Corrupted or bad crash, deleting..."); + log("Corrupted or bad crash, deleting"); DeleteDebugDumpDir(std::string(DEBUG_DUMPS_DIR) + "/" + name); break; } -- cgit From c8e9e69f96c2bd0b9248d6dfab91e2d27ab8e608 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 6 Nov 2009 12:41:24 +0100 Subject: mass replace of const string& params by const char* Signed-off-by: Denys Vlasenko --- src/Daemon/Daemon.cpp | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'src/Daemon/Daemon.cpp') diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index fd7951f5..b417cfd4 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -188,8 +188,9 @@ static gboolean cron_activation_periodic_cb(gpointer data) cron_callback_data_t* cronPeriodicCallbackData = static_cast(data); VERB1 log("Activating plugin: %s", cronPeriodicCallbackData->m_sPluginName.c_str()); RunAction(DEBUG_DUMPS_DIR, - cronPeriodicCallbackData->m_sPluginName, - cronPeriodicCallbackData->m_sPluginArgs); + cronPeriodicCallbackData->m_sPluginName.c_str(), + cronPeriodicCallbackData->m_sPluginArgs.c_str() + ); return TRUE; } static gboolean cron_activation_one_cb(gpointer data) @@ -197,8 +198,9 @@ static gboolean cron_activation_one_cb(gpointer data) cron_callback_data_t* cronOneCallbackData = static_cast(data); VERB1 log("Activating plugin: %s", cronOneCallbackData->m_sPluginName.c_str()); RunAction(DEBUG_DUMPS_DIR, - cronOneCallbackData->m_sPluginName, - cronOneCallbackData->m_sPluginArgs); + cronOneCallbackData->m_sPluginName.c_str(), + cronOneCallbackData->m_sPluginArgs.c_str() + ); return FALSE; } static gboolean cron_activation_reshedule_cb(gpointer data) @@ -212,7 +214,8 @@ static gboolean cron_activation_reshedule_cb(gpointer data) cronPeriodicCallbackData->m_nTimeout, cron_activation_periodic_cb, static_cast(cronPeriodicCallbackData), - cron_delete_callback_data_cb); + cron_delete_callback_data_cb + ); return FALSE; } @@ -238,7 +241,7 @@ static void SetUpMW() vector_pair_string_string_t::iterator it_ar = g_settings_vectorActionsAndReporters.begin(); for (; it_ar != g_settings_vectorActionsAndReporters.end(); it_ar++) { - AddActionOrReporter(it_ar->first, it_ar->second); + AddActionOrReporter(it_ar->first.c_str(), it_ar->second.c_str()); } VERB1 log("Adding analyzers, actions or reporters"); map_analyzer_actions_and_reporters_t::iterator it_aar = g_settings_mapAnalyzerActionsAndReporters.begin(); @@ -247,7 +250,7 @@ static void SetUpMW() vector_pair_string_string_t::iterator it_ar = it_aar->second.begin(); for (; it_ar != it_aar->second.end(); it_ar++) { - AddAnalyzerActionOrReporter(it_aar->first, it_ar->first, it_ar->second); + AddAnalyzerActionOrReporter(it_aar->first.c_str(), it_ar->first.c_str(), it_ar->second.c_str()); } } } @@ -381,12 +384,12 @@ static void FindNewDumps(const char* pPath) map_crash_info_t crashinfo; try { - mw_result_t res = SaveDebugDump(*itt, crashinfo); + mw_result_t res = SaveDebugDump(itt->c_str(), crashinfo); switch (res) { case MW_OK: VERB1 log("Saving into database (%s)", itt->c_str()); - RunActionsAndReporters(crashinfo[CD_MWDDD][CD_CONTENT]); + RunActionsAndReporters(crashinfo[CD_MWDDD][CD_CONTENT].c_str()); break; case MW_IN_DB: VERB1 log("Already saved in database (%s)", itt->c_str()); @@ -402,7 +405,7 @@ static void FindNewDumps(const char* pPath) //Perhaps corrupted & bad needs to be logged unconditionally, //already saved one - only on VERB1 VERB1 log("Corrupted, bad or already saved crash, deleting"); - DeleteDebugDumpDir(*itt); + DeleteDebugDumpDir(itt->c_str()); break; } } @@ -526,19 +529,21 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin ) { log("Size of '%s' >= %u MB, deleting '%s'", DEBUG_DUMPS_DIR, g_settings_nMaxCrashReportsSize, worst_dir.c_str()); g_pCommLayer->QuotaExceed(_("Report size exceeded the quota. Please check system's MaxCrashReportsSize value in abrt.conf.")); - DeleteDebugDumpDir(std::string(DEBUG_DUMPS_DIR) + "/" + worst_dir); + DeleteDebugDumpDir(concat_path_file(DEBUG_DUMPS_DIR, worst_dir.c_str()).c_str()); worst_dir = ""; } map_crash_info_t crashinfo; try { - mw_result_t res = SaveDebugDump(std::string(DEBUG_DUMPS_DIR) + "/" + name, crashinfo); + std::string fullname = concat_path_file(DEBUG_DUMPS_DIR, name); + + mw_result_t res = SaveDebugDump(fullname.c_str(), crashinfo); switch (res) { case MW_OK: log("New crash, saving"); - RunActionsAndReporters(crashinfo[CD_MWDDD][CD_CONTENT]); + RunActionsAndReporters(crashinfo[CD_MWDDD][CD_CONTENT].c_str()); /* Fall through to "send dbus signal" */ case MW_REPORTED: case MW_OCCURED: @@ -551,7 +556,7 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin : crashinfo[CD_UID][CD_CONTENT].c_str(); g_pCommLayer->Crash(crashinfo[CD_PACKAGE][CD_CONTENT].c_str(), uid_str); } - //DeleteDebugDumpDir(std::string(DEBUG_DUMPS_DIR) + "/" + name); + //DeleteDebugDumpDir(fullname.c_str()); break; case MW_BLACKLISTED: case MW_CORRUPTED: @@ -561,7 +566,7 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin case MW_FILE_ERROR: default: log("Corrupted or bad crash, deleting"); - DeleteDebugDumpDir(std::string(DEBUG_DUMPS_DIR) + "/" + name); + DeleteDebugDumpDir(fullname.c_str()); break; } } @@ -821,7 +826,7 @@ int main(int argc, char** argv) SetUpMW(); /* logging is inside */ if (SetUpCron() != 0) throw 1; -#ifdef ENABLE_DBUS +#if 1 //def ENABLE_DBUS VERB1 log("Initializing dbus"); g_pCommLayer = new CCommLayerServerDBus(); #elif ENABLE_SOCKET -- cgit From b1336faa48bee2cdb7ef0486a5a4faa5c74f4fa7 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 6 Nov 2009 17:50:26 +0100 Subject: make exception handling lighter Signed-off-by: Denys Vlasenko --- src/Daemon/Daemon.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Daemon/Daemon.cpp') diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index b417cfd4..c6d0a029 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -415,7 +415,7 @@ static void FindNewDumps(const char* pPath) { throw e; } - error_msg("%s", e.what().c_str()); + error_msg("%s", e.what()); } } } @@ -883,7 +883,7 @@ int main(int argc, char** argv) } catch (CABRTException& e) { - error_msg("Error: %s", e.what().c_str()); + error_msg("Error: %s", e.what()); } catch (std::exception& e) { -- cgit From 1202706839ec42299e8794750cec66dfa7db0206 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 6 Nov 2009 17:51:17 +0100 Subject: simplify logging a bit. warn_client() is gone, reuse error_msg() for it. Signed-off-by: Denys Vlasenko --- src/Daemon/Daemon.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Daemon/Daemon.cpp') diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index c6d0a029..67e72cca 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -572,7 +572,7 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin } catch (CABRTException& e) { - warn_client(e.what()); + error_msg(e.what()); if (e.type() == EXCEP_FATAL) { free(buf); -- cgit