From 00a96b4ad9552181ee7a2122f74d2d87b24619ee Mon Sep 17 00:00:00 2001 From: Tim Pepper Date: Tue, 11 Sep 2012 13:53:14 -0700 Subject: [PATCH] Change from /tmp to /var/lib/corewatcher We want dumps to be persistent across reboots, so tmpfs isn't the best place for them. Plus /tmp is a wild west of writability. We'll allow full writing of /var/lib/corewatcher, but not /var/lib/corewatcher/processed. Still need a tmp watcher on this area to prune files. Also this directory is an editorial choice by the distro maker, not a user configurable option...remove user configurability. Signed-off-by: Tim Pepper --- corewatcher.conf | 6 ------ src/configfile.c | 12 ----------- src/coredump.c | 63 ++++++++++++++++++++++--------------------------------- src/corewatcher.c | 28 +++++++++++++++++++++++++ src/corewatcher.h | 3 ++- 5 files changed, 55 insertions(+), 57 deletions(-) diff --git a/corewatcher.conf b/corewatcher.conf index 5bc54a4..61cc9ab 100644 --- a/corewatcher.conf +++ b/corewatcher.conf @@ -40,9 +40,3 @@ allow-pass-on=yes submit-url=http://kojibuild7.jf.intel.com/crash_submit/ -# -# Location to store coredumps after they are processed -# - -core-folder=/var/lib/corewatcher/ - diff --git a/src/configfile.c b/src/configfile.c index 1bfcb0c..3f2cb6f 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -34,7 +34,6 @@ char *submit_url[MAX_URLS]; char *build_release = NULL; -char *core_folder = NULL; int url_count = 0; void read_config_file(char *filename) @@ -80,15 +79,6 @@ void read_config_file(char *filename) } } } - c = strstr(line, "core-folder"); - if (c) { - c += 11; - if (c < line_end) { - c = strstr(c, "/"); - if (c) - core_folder = strdup(c); - } - } } fclose(file); @@ -101,8 +91,6 @@ void read_config_file(char *filename) else url_count++; } - if (!core_folder) - core_folder = strdup("/var/lib/corewatcher/"); /* Distribution editorial choice, not end-user choice: */ build_release = strdup("/etc/os-release"); diff --git a/src/coredump.c b/src/coredump.c index 555d8fa..8325250 100644 --- a/src/coredump.c +++ b/src/coredump.c @@ -45,6 +45,9 @@ int uid = 0; int sig = 0; +const char *core_folder = "/var/lib/corewatcher/"; +const char *processed_folder = "/var/lib/corewatcher/processed/"; + /* Always pick up the processing_mtx and then the processing_queue_mtx, reverse for setting down */ /* Always pick up the gdb_mtx and then the @@ -202,33 +205,27 @@ char *strip_directories(char *fullpath) } /* - * Move corefile from /tmp to core_folder. - * Add extension if given and attempt to create core_folder. + * Move corefile from core_folder to processed_folder subdir. + * Add extension if given and attempt to create directories if needed. */ int move_core(char *fullpath, char *extension) { - char *corefn = NULL, newpath[8192]; + char *corefilename = NULL, newpath[8192]; - if (!core_folder || !fullpath) + if (!fullpath) return -1; - if (!(corefn = strip_directories(fullpath))) { + if (!(corefilename = strip_directories(fullpath))) { unlink(fullpath); return -ENOMEM; } - if (!mkdir(core_folder, S_IRWXU | S_IRWXG | S_IRWXO) - && errno != EEXIST) { - free(corefn); - return -errno; - } - if (extension) - snprintf(newpath, 8192, "%s%s.%s", core_folder, corefn, extension); + snprintf(newpath, 8192, "%s%s.%s", processed_folder, corefilename, extension); else - snprintf(newpath, 8192, "%s%s", core_folder, corefn); + snprintf(newpath, 8192, "%s%s", processed_folder, corefilename); - free(corefn); + free(corefilename); rename(fullpath, newpath); return 0; @@ -237,7 +234,7 @@ int move_core(char *fullpath, char *extension) /* * Finds the full path for the application that crashed, * and depending on what opted_in was configured as will: - * opted_in 2 (always submit) -> move file to core_folder + * opted_in 2 (always submit) -> move file to processed_folder * to be processed further * opted_in 1 (ask user) -> ask user if we should submit * the crash and add to asked_oops hash so we don't get @@ -413,13 +410,13 @@ char *get_core_filename(char *filename, char *ext) if (ext) { /* causes valgrind whining because we copy from middle of a string */ - if ((asprintf(&detail_filename, "%s%s.%s", core_folder, pid, ext)) == -1) { + if ((asprintf(&detail_filename, "%s%s.%s", processed_folder, pid, ext)) == -1) { free(pid); return NULL; } } else { /* causes valgrind whining because we copy from middle of a string */ - if ((asprintf(&detail_filename, "%s%s", core_folder, pid)) == -1) { + if ((asprintf(&detail_filename, "%s%s", processed_folder, pid)) == -1) { free(pid); return NULL; } @@ -747,18 +744,17 @@ int scan_corefolders(void __unused *unused) DIR *dir = NULL; struct dirent *entry = NULL; char *fullpath = NULL, *appfile = NULL; - char tmp_folder[] = "/tmp/"; int r = 0; pthread_mutex_init(&core_status.processing_mtx, NULL); pthread_mutex_init(&core_status.queued_mtx, NULL); pthread_mutex_init(&core_status.asked_mtx, NULL); - dir = opendir(tmp_folder); + /* scan for new crash data */ + dir = opendir(core_folder); if (!dir) return 1; - - fprintf(stderr, "+ scanning %s...\n", tmp_folder); + fprintf(stderr, "+ scanning %s...\n", core_folder); while(1) { free(fullpath); fullpath = NULL; @@ -772,11 +768,11 @@ int scan_corefolders(void __unused *unused) continue; /* matched core_#### where #### is the pid of the process */ - r = asprintf(&fullpath, "%s%s", tmp_folder, entry->d_name); + r = asprintf(&fullpath, "%s%s", core_folder, entry->d_name); if (r == -1) { fullpath = NULL; continue; - } else if (((unsigned int)r) != strlen(tmp_folder) + strlen(entry->d_name)) { + } else if (((unsigned int)r) != strlen(core_folder) + strlen(entry->d_name)) { continue; } /* already found, waiting for response from user */ @@ -798,20 +794,11 @@ int scan_corefolders(void __unused *unused) } closedir(dir); - if (!core_folder) + /* scan for partially processed crash data */ + dir = opendir(processed_folder); + if (!dir) return 1; - dir = opendir(core_folder); - if (!dir) { - if (!mkdir(core_folder, S_IRWXU | S_IRWXG | S_IRWXO) - && errno != EEXIST) { - return 1; - } - dir = opendir(core_folder); - if (!dir) - return 1; - } - - fprintf(stderr, "+ scanning %s...\n", core_folder); + fprintf(stderr, "+ scanning %s...\n", processed_folder); while(1) { free(fullpath); fullpath = NULL; @@ -824,11 +811,11 @@ int scan_corefolders(void __unused *unused) if (!strstr(entry->d_name, "process")) continue; - r = asprintf(&fullpath, "%s%s", core_folder, entry->d_name); + r = asprintf(&fullpath, "%s%s", processed_folder, entry->d_name); if (r == -1) { fullpath = NULL; continue; - } else if (((unsigned int)r) != strlen(core_folder) + strlen(entry->d_name)) { + } else if (((unsigned int)r) != strlen(processed_folder) + strlen(entry->d_name)) { continue; } diff --git a/src/corewatcher.c b/src/corewatcher.c index 536b098..e4a7bfc 100644 --- a/src/corewatcher.c +++ b/src/corewatcher.c @@ -35,6 +35,9 @@ #include #include #include +#include +#include +#include #include @@ -77,6 +80,7 @@ int main(int argc, char**argv) int godaemon = 1; int debug = 0; int j = 0; + DIR *dir = NULL; core_status.asked_oops = g_hash_table_new_full(g_str_hash, g_str_equal, free, free); core_status.processing_oops = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL); @@ -103,6 +107,30 @@ int main(int argc, char**argv) read_config_file("/etc/corewatcher/corewatcher.conf"); + /* insure our directories exist */ + dir = opendir(core_folder); + if (!dir) { + if (!mkdir(core_folder, S_IRWXU | S_IRWXG | S_IRWXO) + && errno != EEXIST) { + return 1; + } + dir = opendir(core_folder); + if (!dir) + return 1; + } + closedir(dir); + dir = opendir(processed_folder); + if (!dir) { + if (!mkdir(processed_folder, S_IRWXU) + && errno != EEXIST) { + return 1; + } + dir = opendir(processed_folder); + if (!dir) + return 1; + } + closedir(dir); + while (1) { int c; int i; diff --git a/src/corewatcher.h b/src/corewatcher.h index 7a94baa..2070238 100644 --- a/src/corewatcher.h +++ b/src/corewatcher.h @@ -80,6 +80,8 @@ extern char *get_core_filename(char *filename, char *ext); extern void remove_pid_from_hash(char *fullpath, GHashTable *ht); extern int uid; extern int sig; +extern const char *core_folder; +extern const char *processed_folder; /* configfile.c */ extern void read_config_file(char *filename); @@ -87,7 +89,6 @@ extern int opted_in; extern int allow_distro_to_pass_on; extern char *submit_url[MAX_URLS]; extern char *build_release; -extern char *core_folder; extern int url_count; /* corewatcher.c */ -- 2.7.4