[gnome-logs/wip/current-boot: 1/2] Allow showing all log events for the current boot
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-logs/wip/current-boot: 1/2] Allow showing all log events for the current boot
- Date: Wed, 30 Oct 2013 12:55:49 +0000 (UTC)
commit 3caf1571ac19df6cd4cdd2669362597543e72e4d
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-eventview.c | 8 ++--
src/gl-journal.c | 97 +++++++++++++++++++++++++++++++++++++++++----------
src/gl-journal.h | 2 +-
3 files changed, 83 insertions(+), 24 deletions(-)
---
diff --git a/src/gl-eventview.c b/src/gl-eventview.c
index 74cf4a2..6a85b0a 100644
--- a/src/gl-eventview.c
+++ b/src/gl-eventview.c
@@ -480,7 +480,7 @@ insert_journal_query_devices (GlEventView *view,
n_results = g_list_length (results);
- if (n_results != N_RESULTS)
+ if ((n_results != -1) && (n_results != N_RESULTS))
{
g_debug ("Number of results different than requested");
}
@@ -559,7 +559,7 @@ insert_journal_query_security (GlEventView *view,
n_results = g_list_length (results);
- if (n_results != N_RESULTS)
+ if ((n_results != -1) && (n_results != N_RESULTS))
{
g_debug ("Number of results different than requested");
}
@@ -650,7 +650,7 @@ insert_journal_query_simple (GlEventView *view,
n_results = g_list_length (results);
- if (n_results != N_RESULTS)
+ if ((n_results != -1) && (n_results != N_RESULTS))
{
g_debug ("Number of results different than requested");
}
@@ -723,7 +723,7 @@ insert_journal_query_cmdline (GlEventView *view,
n_results = g_list_length (results);
- if (n_results != N_RESULTS)
+ if ((n_results != -1) && (n_results != N_RESULTS))
{
g_debug ("Number of results different than requested");
}
diff --git a/src/gl-journal.c b/src/gl-journal.c
index 338612d..146e6d4 100644
--- a/src/gl-journal.c
+++ b/src/gl-journal.c
@@ -336,41 +336,100 @@ 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;
+ gchar boot_string[33];
+ gchar *match_string;
- for (i = 0; i < query->n_results; i++)
- {
- GlJournalResult *result;
+ ret = sd_id128_get_boot (&boot_id);
- ret = sd_journal_previous (journal);
+ if (ret < 0)
+ {
+ g_warning ("Error getting boot ID of running kernel: %s",
+ g_strerror (-ret));
+ }
+
+ sd_id128_to_string (boot_id, boot_string);
+
+ match_string = g_strconcat ("_BOOT_ID=", boot_string, NULL);
+
+ ret = sd_journal_add_match (journal, match_string, 0);
if (ret < 0)
{
- g_warning ("Error setting cursor to end of systemd journal: %s",
+ g_warning ("Error adding match '%s': %s", match_string,
g_strerror (-ret));
- break;
}
- else if (ret == 0)
+
+ g_free (match_string);
+
+ 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);
+
+ 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;
+ }
- results = g_list_prepend (results, result);
- continue;
+ results = g_list_reverse (results);
}
sd_journal_flush_matches (journal);
- return g_list_reverse (results);
+ return results;
}
GlJournalResult *
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]