chiark / gitweb /
systemctl: limit logs in status to current boot
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 3 Jun 2013 22:28:12 +0000 (18:28 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 4 Jun 2013 13:59:06 +0000 (09:59 -0400)
Also reworded a few debug messages for brevity, and added a log
statement which prints out the filter at debug level:

Journal filter: (((UNIT=sys-module-configfs.device AND _PID=1) OR (COREDUMP_UNIT=sys-module-configfs.device AND MESSAGE_ID=fc2e22bc6ee647b6b90729ab34a250b1) OR _SYSTEMD_UNIT=sys-module-configfs.device) AND _BOOT_ID=4e3c518ab0474c12ac8de7896fe6b154)

TODO
src/journal/journalctl.c
src/journal/sd-journal.c
src/shared/logs-show.c
src/shared/logs-show.h

diff --git a/TODO b/TODO
index 9ba1de01cb1935a02402663d34d50a7797944337..ecc5748c63510a8fc81a489609a8d846eecb1e4f 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,7 +1,4 @@
 Bugfixes:
-* systemctl status *.path shows all logs, not only the ones since the unit is
-  active
-
 * check systemd-tmpfiles for selinux context hookup for mknod(), symlink() and similar
 
 * swap units that are activated by one name but shown in the kernel under another are semi-broken
index 2e672fa09655fb93dd26774c5acb6b73ebfc5e49..eb79c4d8537e192d61b4f31537fa339ac510b2b6 100644 (file)
@@ -591,33 +591,10 @@ static int add_matches(sd_journal *j, char **args) {
 }
 
 static int add_this_boot(sd_journal *j) {
-        char match[9+32+1] = "_BOOT_ID=";
-        sd_id128_t boot_id;
-        int r;
-
-        assert(j);
-
         if (!arg_this_boot)
                 return 0;
 
-        r = sd_id128_get_boot(&boot_id);
-        if (r < 0) {
-                log_error("Failed to get boot id: %s", strerror(-r));
-                return r;
-        }
-
-        sd_id128_to_string(boot_id, match + 9);
-        r = sd_journal_add_match(j, match, strlen(match));
-        if (r < 0) {
-                log_error("Failed to add match: %s", strerror(-r));
-                return r;
-        }
-
-        r = sd_journal_add_conjunction(j);
-        if (r < 0)
-                return r;
-
-        return 0;
+        return add_match_this_boot(j);
 }
 
 static int add_dmesg(sd_journal *j) {
index 779af62b518bff9eb6831a1c64233dcb2b00c01d..cf60ebcee2756e4fe096c31c565d3cdb336fbc8c 100644 (file)
@@ -1302,7 +1302,7 @@ static int add_file(sd_journal *j, const char *prefix, const char *filename) {
                 return r;
         }
 
-        log_debug("File %s got added.", f->path);
+        log_debug("File %s added.", f->path);
 
         check_network(j, f->fd);
 
@@ -1330,7 +1330,7 @@ static int remove_file(sd_journal *j, const char *prefix, const char *filename)
 
         hashmap_remove(j->files, f->path);
 
-        log_debug("File %s got removed.", f->path);
+        log_debug("File %s removed.", f->path);
 
         if (j->current_file == f) {
                 j->current_file = NULL;
@@ -1397,7 +1397,7 @@ static int add_directory(sd_journal *j, const char *prefix, const char *dirname)
                 path = NULL; /* avoid freeing in cleanup */
                 j->current_invalidate_counter ++;
 
-                log_debug("Directory %s got added.", m->path);
+                log_debug("Directory %s added.", m->path);
 
         } else if (m->is_root)
                 return 0;
@@ -1476,7 +1476,7 @@ static int add_root_directory(sd_journal *j, const char *p) {
 
                 j->current_invalidate_counter ++;
 
-                log_debug("Root directory %s got added.", m->path);
+                log_debug("Root directory %s added.", m->path);
 
         } else if (!m->is_root)
                 return 0;
@@ -1537,9 +1537,9 @@ static int remove_directory(sd_journal *j, Directory *d) {
         hashmap_remove(j->directories_by_path, d->path);
 
         if (d->is_root)
-                log_debug("Root directory %s got removed.", d->path);
+                log_debug("Root directory %s removed.", d->path);
         else
-                log_debug("Directory %s got removed.", d->path);
+                log_debug("Directory %s removed.", d->path);
 
         free(d->path);
         free(d);
index 116dc8a36ceabd2e0cf5890237a7579f9cdbdabb..79a977c156e6c675fbc948d2860169af8d40a2ad 100644 (file)
@@ -931,6 +931,33 @@ int add_matches_for_user_unit(sd_journal *j, const char *unit, uid_t uid) {
         return r;
 }
 
+int add_match_this_boot(sd_journal *j) {
+        char match[9+32+1] = "_BOOT_ID=";
+        sd_id128_t boot_id;
+        int r;
+
+        assert(j);
+
+        r = sd_id128_get_boot(&boot_id);
+        if (r < 0) {
+                log_error("Failed to get boot id: %s", strerror(-r));
+                return r;
+        }
+
+        sd_id128_to_string(boot_id, match + 9);
+        r = sd_journal_add_match(j, match, strlen(match));
+        if (r < 0) {
+                log_error("Failed to add match: %s", strerror(-r));
+                return r;
+        }
+
+        r = sd_journal_add_conjunction(j);
+        if (r < 0)
+                return r;
+
+        return 0;
+}
+
 int show_journal_by_unit(
                 FILE *f,
                 const char *unit,
@@ -957,6 +984,10 @@ int show_journal_by_unit(
         if (r < 0)
                 return r;
 
+        r = add_match_this_boot(j);
+        if (r < 0)
+                return r;
+
         if (system)
                 r = add_matches_for_unit(j, unit);
         else
@@ -964,6 +995,8 @@ int show_journal_by_unit(
         if (r < 0)
                 return r;
 
+        log_debug("Journal filter: %s", journal_make_match_string(j));
+
         r = show_journal(f, j, mode, n_columns, not_before, how_many, flags);
         if (r < 0)
                 return r;
index b0f93a661a55ac0ce74361314d5ee5e41154711e..c9a9ad3e9195413239bc3b062d031aa4c3c3c601 100644 (file)
@@ -37,6 +37,8 @@ int output_journal(
                 unsigned n_columns,
                 OutputFlags flags);
 
+int add_match_this_boot(sd_journal *j);
+
 int add_matches_for_unit(
                 sd_journal *j,
                 const char *unit);