[gnome-logs/wip/current-boot: 1/2] Allow showing all log events for the current boot



commit ccf8397b1a75c90ae7ae1b92f22d9111dd8bba31
Author: David King <davidk gnome org>
Date:   Wed Oct 30 11:09:04 2013 +0000

    Allow showing all log events for the current boot
    
    If -1 is passed as the requested number of results for a GlJournalQuery,
    return a list of all results that match since the last boot.

 src/gl-journal.c |   86 ++++++++++++++++++++++++++++++++++++++++++-----------
 src/gl-journal.h |    2 +-
 2 files changed, 69 insertions(+), 19 deletions(-)
---
diff --git a/src/gl-journal.c b/src/gl-journal.c
index 338612d..13983cc 100644
--- a/src/gl-journal.c
+++ b/src/gl-journal.c
@@ -336,36 +336,86 @@ gl_journal_query (GlJournal *self, const GlJournalQuery *query)
         }
     }
 
-    ret = sd_journal_seek_tail (journal);
-
-    if (ret < 0)
+    if (query->n_results == -1)
     {
-        g_warning ("Error seeking to end of systemd journal: %s",
-                   g_strerror (-ret));
-    }
+        /* Take events from this boot only. */
+        sd_id128_t boot_id;
 
-    for (i = 0; i < query->n_results; i++)
-    {
-        GlJournalResult *result;
+        ret = sd_id128_get_boot (&boot_id);
+
+        if (ret < 0)
+        {
+            g_warning ("Error getting boot ID of running kernel: %s",
+                       g_strerror (-ret));
+        }
 
-        ret = sd_journal_previous (journal);
+        ret = sd_journal_seek_monotonic_usec (journal, boot_id, 0);
 
         if (ret < 0)
         {
-            g_warning ("Error setting cursor to end of systemd journal: %s",
+            g_warning ("Error seeking to journal at start of current boot: %s",
                        g_strerror (-ret));
-            break;
         }
-        else if (ret == 0)
+
+        do
         {
-            g_debug ("End of systemd journal reached");
-            break;
+            GlJournalResult *result;
+
+            ret = sd_journal_next (journal);
+
+            if (ret < 0)
+            {
+                g_warning ("Error setting cursor to next position in systemd journal: %s",
+                           g_strerror (-ret));
+                break;
+            }
+            else if (ret == 0)
+            {
+                g_debug ("End of systemd journal reached");
+                break;
+            }
+
+            result = _gl_journal_query_result (self);
+
+            results = g_list_prepend (results, result);
+
+        } while (TRUE);
+    }
+    else
+    {
+        /* Take the given number of events from the end of the journal
+         * backwards. */
+        ret = sd_journal_seek_tail (journal);
+
+        if (ret < 0)
+        {
+            g_warning ("Error seeking to end of systemd journal: %s",
+                       g_strerror (-ret));
         }
 
-        result = _gl_journal_query_result (self);
+        for (i = 0; i < query->n_results; i++)
+        {
+            GlJournalResult *result;
+
+            ret = sd_journal_previous (journal);
 
-        results = g_list_prepend (results, result);
-        continue;
+            if (ret < 0)
+            {
+                g_warning ("Error setting cursor to end of systemd journal: %s",
+                           g_strerror (-ret));
+                break;
+            }
+            else if (ret == 0)
+            {
+                g_debug ("End of systemd journal reached");
+                break;
+            }
+
+            result = _gl_journal_query_result (self);
+
+            results = g_list_prepend (results, result);
+            continue;
+        }
     }
 
     sd_journal_flush_matches (journal);
diff --git a/src/gl-journal.h b/src/gl-journal.h
index e5e0b06..47f3e37 100644
--- a/src/gl-journal.h
+++ b/src/gl-journal.h
@@ -45,7 +45,7 @@ GQuark gl_journal_error_quark (void);
 
 typedef struct
 {
-    gsize n_results;
+    gssize n_results;
     gchar **matches;
 } GlJournalQuery;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]