chiark / gitweb /
macro: rework how we define cleanup macros
[elogind.git] / src / journal / coredumpctl.c
index 4adc923..97d967d 100644 (file)
@@ -34,6 +34,8 @@
 #include "log.h"
 #include "path-util.h"
 #include "pager.h"
 #include "log.h"
 #include "path-util.h"
 #include "pager.h"
+#include "macro.h"
+#include "journal-internal.h"
 
 static enum {
         ACTION_NONE,
 
 static enum {
         ACTION_NONE,
@@ -42,7 +44,6 @@ static enum {
         ACTION_GDB,
 } arg_action = ACTION_LIST;
 
         ACTION_GDB,
 } arg_action = ACTION_LIST;
 
-static Set *matches = NULL;
 static FILE* output = NULL;
 static char* field = NULL;
 
 static FILE* output = NULL;
 static char* field = NULL;
 
@@ -139,7 +140,7 @@ fail:
         return r;
 }
 
         return r;
 }
 
-static int parse_argv(int argc, char *argv[]) {
+static int parse_argv(int argc, char *argv[], Set *matches) {
         enum {
                 ARG_VERSION = 0x100,
                 ARG_NO_PAGER,
         enum {
                 ARG_VERSION = 0x100,
                 ARG_NO_PAGER,
@@ -170,7 +171,6 @@ static int parse_argv(int argc, char *argv[]) {
 
                 case ARG_VERSION:
                         puts(PACKAGE_STRING);
 
                 case ARG_VERSION:
                         puts(PACKAGE_STRING);
-                        puts(DISTRIBUTION);
                         puts(SYSTEMD_FEATURES);
                         arg_action = ACTION_NONE;
                         return 0;
                         puts(SYSTEMD_FEATURES);
                         arg_action = ACTION_NONE;
                         return 0;
@@ -262,7 +262,7 @@ static int retrieve(const void *data,
                 return 0;
 
         *var = strndup((const char*)data + ident, len - ident);
                 return 0;
 
         *var = strndup((const char*)data + ident, len - ident);
-        if (!var)
+        if (!*var)
                 return log_oom();
 
         return 0;
                 return log_oom();
 
         return 0;
@@ -342,6 +342,11 @@ static int dump_list(sd_journal *j) {
 
         assert(j);
 
 
         assert(j);
 
+        /* The coredumps are likely to compressed, and for just
+         * listing them we don#t need to decompress them, so let's
+         * pick a fairly low data threshold here */
+        sd_journal_set_data_threshold(j, 4096);
+
         SD_JOURNAL_FOREACH(j) {
                 if (field)
                         print_field(stdout, j);
         SD_JOURNAL_FOREACH(j) {
                 if (field)
                         print_field(stdout, j);
@@ -381,6 +386,9 @@ static int dump_core(sd_journal* j) {
 
         assert(j);
 
 
         assert(j);
 
+        /* We want full data, nothing truncated. */
+        sd_journal_set_data_threshold(j, 0);
+
         r = focus(j);
         if (r < 0)
                 return r;
         r = focus(j);
         if (r < 0)
                 return r;
@@ -428,6 +436,8 @@ static int run_gdb(sd_journal *j) {
 
         assert(j);
 
 
         assert(j);
 
+        sd_journal_set_data_threshold(j, 0);
+
         r = focus(j);
         if (r < 0)
                 return r;
         r = focus(j);
         if (r < 0)
                 return r;
@@ -510,10 +520,11 @@ finish:
 }
 
 int main(int argc, char *argv[]) {
 }
 
 int main(int argc, char *argv[]) {
-        sd_journal *j = NULL;
+        sd_journal _cleanup_journal_close_ *j = NULL;
         const char* match;
         Iterator it;
         int r = 0;
         const char* match;
         Iterator it;
         int r = 0;
+        Set _cleanup_set_free_free_ *matches = NULL;
 
         setlocale(LC_ALL, "");
         log_parse_environment();
 
         setlocale(LC_ALL, "");
         log_parse_environment();
@@ -525,7 +536,7 @@ int main(int argc, char *argv[]) {
                 goto end;
         }
 
                 goto end;
         }
 
-        r = parse_argv(argc, argv);
+        r = parse_argv(argc, argv, matches);
         if (r < 0)
                 goto end;
 
         if (r < 0)
                 goto end;
 
@@ -551,7 +562,7 @@ int main(int argc, char *argv[]) {
 
         case ACTION_LIST:
                 if (!arg_no_pager)
 
         case ACTION_LIST:
                 if (!arg_no_pager)
-                        pager_open();
+                        pager_open(false);
 
                 r = dump_list(j);
                 break;
 
                 r = dump_list(j);
                 break;
@@ -569,11 +580,6 @@ int main(int argc, char *argv[]) {
         }
 
 end:
         }
 
 end:
-        if (j)
-                sd_journal_close(j);
-
-        set_free_free(matches);
-
         pager_close();
 
         if (output)
         pager_close();
 
         if (output)