From 4bf52615bb6efd673408691d512cb37758e126bd Mon Sep 17 00:00:00 2001 From: Auke Kok Date: Mon, 2 Aug 2010 16:51:29 -0700 Subject: [PATCH] Bugfix: remove \n of submit URL (broke submissions) Bugfix: re-use curl handle (keeps http port open if possible) Refine debug output for readability, put all of it to stderr --- configfile.c | 8 ++++++++ coredump.c | 6 +++--- corewatcher-applet.c | 2 +- corewatcher.c | 33 +++++++++++++++++++-------------- find_file.c | 4 ++-- submit.c | 16 ++++++++-------- 6 files changed, 41 insertions(+), 28 deletions(-) diff --git a/configfile.c b/configfile.c index e6a65d2..12e19e9 100644 --- a/configfile.c +++ b/configfile.c @@ -49,6 +49,8 @@ void read_config_file(char *filename) return; while (!feof(file)) { char *c; + char *n; + line = NULL; if (getline(&line, &dummy, file) <= 0) { free(line); @@ -58,6 +60,11 @@ void read_config_file(char *filename) free(line); continue; } + + /* remove trailing\n */ + n = strchr(line, '\n'); + if (n) *n = 0; + c = strstr(line, "allow-submit "); if (c) { c += 13; @@ -89,4 +96,5 @@ void read_config_file(char *filename) fclose(file); if (!submit_url) submit_url = strdup("http://crashdb.meego.com/submitbug.php"); + fprintf(stderr, "+ submit url=\"%s\"\n", submit_url); } diff --git a/coredump.c b/coredump.c index 9e1782e..dc1b8db 100644 --- a/coredump.c +++ b/coredump.c @@ -115,7 +115,7 @@ void process_corefile(char *filename) return; queue_backtrace(ptr); - printf("-%s-\n", ptr); + fprintf(stderr, "---[start of coredump]---\n%s\n---[end of coredump]---\n", ptr); sprintf(newfile,"%s.processed", filename); if (do_unlink) unlink(filename); @@ -136,7 +136,7 @@ int scan_dmesg(void __unused *unused) if (!dir) return 1; - printf("Scanning..\n"); + fprintf(stderr, "+ scanning..\n"); do { entry = readdir(dir); if (!entry) @@ -148,7 +148,7 @@ int scan_dmesg(void __unused *unused) if (strncmp(entry->d_name, "core.", 5)) continue; sprintf(path, "/tmp/%s", entry->d_name); - printf("Looking at %s\n", path); + fprintf(stderr, "+ Looking at %s\n", path); process_corefile(path); } while (entry); diff --git a/corewatcher-applet.c b/corewatcher-applet.c index b37c67a..2579d9a 100644 --- a/corewatcher-applet.c +++ b/corewatcher-applet.c @@ -79,7 +79,7 @@ static void write_config(char *permission) sprintf(filename, "%s/.corewatcher", getenv("HOME")); file = fopen(filename, "w"); if (!file) { - printf("error is %s \n", strerror(errno)); + fprintf(stderr, "+ error is %s \n", strerror(errno)); return; } fprintf(file, "allow-submit = %s\n", permission); diff --git a/corewatcher.c b/corewatcher.c index 1a3c5b0..5e5bd69 100644 --- a/corewatcher.c +++ b/corewatcher.c @@ -56,6 +56,7 @@ static struct option opts[] = { { "nodaemon", 0, NULL, 'n' }, { "debug", 0, NULL, 'd' }, { "always", 0, NULL, 'a' }, + { "test", 0, NULL, 't' }, { "help", 0, NULL, 'h' }, { 0, 0, NULL, 0 } }; @@ -68,11 +69,12 @@ int testmode; static void usage(const char *name) { - printf("Usage: %s [OPTIONS...]\n", name); - printf(" -n, --nodaemon Do not daemonize, run in foreground\n"); - printf(" -d, --debug Enable debug mode\n"); - printf(" -a, --always Always send core dumps\n"); - printf(" -h, --help Display this help message\n"); + fprintf(stderr, "Usage: %s [OPTIONS...]\n", name); + fprintf(stderr, " -n, --nodaemon Do not daemonize, run in foreground\n"); + fprintf(stderr, " -d, --debug Enable debug mode\n"); + fprintf(stderr, " -a, --always Always send core dumps\n"); + fprintf(stderr, " -t, --test Do not send anything\n"); + fprintf(stderr, " -h, --help Display this help message\n"); } static DBusHandlerResult got_message( @@ -153,6 +155,7 @@ int main(int argc, char**argv) GMainLoop *loop; DBusError error; int godaemon = 1; + int debug = 0; /* * Signal the kernel that we're not timing critical @@ -173,18 +176,20 @@ int main(int argc, char**argv) switch(c) { case 'n': - printf("Not running as daemon\n"); + fprintf(stderr, "+ Not running as daemon\n"); godaemon = 0; break; case 'd': - printf("Starting corewatcher in debug mode\n"); - godaemon = 0; - testmode = 1; + fprintf(stderr, "+ Starting corewatcher in debug mode\n"); + debug = 1; break; case 'a': - printf("Sending All report\n"); + fprintf(stderr, "+ Sending All reports\n"); opted_in = 2; break; + case 't': + fprintf(stderr, "+ Test mode enabled: not sending anything\n"); + break; case 'h': usage(argv[0]); return EXIT_SUCCESS; @@ -194,7 +199,7 @@ int main(int argc, char**argv) } if (!opted_in && !testmode) { - fprintf(stderr, " [Inactive by user preference]\n"); + fprintf(stderr, "+ Inactive by user preference\n"); return EXIT_SUCCESS; } @@ -211,7 +216,7 @@ int main(int argc, char**argv) */ if (godaemon && daemon(0, 0)) { - printf("corewatcher failed to daemonize.. exiting \n"); + fprintf(stderr, "corewatcher failed to daemonize.. exiting \n"); return EXIT_FAILURE; } sched_yield(); @@ -226,7 +231,7 @@ int main(int argc, char**argv) dbus_connection_add_filter(bus, got_message, NULL, NULL); } - if (!testmode) + if (!debug) sleep(20); /* we scan dmesg before /var/log/messages; dmesg is a more accurate source normally */ @@ -238,7 +243,7 @@ int main(int argc, char**argv) dbus_bus_remove_match(bus, "type='signal',interface='org.corewatcher.submit.ping'", &error); dbus_bus_remove_match(bus, "type='signal',interface='org.corewatcher.submit.permission'", &error); free(submit_url); - printf("Exiting from testmode\n"); + fprintf(stderr, "+ Exiting from testmode\n"); return EXIT_SUCCESS; } diff --git a/find_file.c b/find_file.c index d175114..8dd2ca9 100644 --- a/find_file.c +++ b/find_file.c @@ -25,7 +25,7 @@ char *find_executable(char *fragment) char *path, *c1, *c2; static char filename[PATH_MAX*2]; - printf("Looking for %s\n", fragment); + fprintf(stderr, "+ Looking for %s\n", fragment); path = strdup(getenv("PATH")); @@ -86,7 +86,7 @@ char *find_coredump(char *corefile) strcpy(core, c); c2 = strchr(core, ' '); if (c2) *c2 = 0; - printf("Causing app: %s\n", core); + fprintf(stderr,"+ causing app: %s\n", core); out: pclose(file); free(line); diff --git a/submit.c b/submit.c index 9947de9..954cdab 100644 --- a/submit.c +++ b/submit.c @@ -165,7 +165,7 @@ static void print_queue(void) while (oops) { struct oops *next; - printf("Submit text is:\n---[start of oops]---\n%s\n---[end of oops]---\n", oops->text); + fprintf(stderr, "+ Submit text is:\n---[start of oops]---\n%s\n---[end of oops]---\n", oops->text); next = oops->next; free(oops->text); free(oops); @@ -206,6 +206,7 @@ void submit_queue(void) int result; struct oops *oops; struct oops *queue; + CURL *handle; int count = 0; memset(result_url, 0, 4096); @@ -215,21 +216,19 @@ void submit_queue(void) return; } + handle = curl_easy_init(); + curl_easy_setopt(handle, CURLOPT_URL, submit_url); + queue = queued_backtraces; queued_backtraces = NULL; barrier(); + oops = queue; while (oops) { - CURL *handle; struct curl_httppost *post = NULL; struct curl_httppost *last = NULL; struct oops *next; - handle = curl_easy_init(); - - printf("DEBUG SUBMIT URL is %s \n", submit_url); - curl_easy_setopt(handle, CURLOPT_URL, submit_url); - /* set up the POST data */ curl_formadd(&post, &last, CURLFORM_COPYNAME, "backtracedata", @@ -246,7 +245,6 @@ void submit_queue(void) result = curl_easy_perform(handle); curl_formfree(post); - curl_easy_cleanup(handle); next = oops->next; free(oops->text); free(oops); @@ -254,6 +252,8 @@ void submit_queue(void) count++; } + curl_easy_cleanup(handle); + if (count && !testmode) write_logfile(count); -- 2.7.4