[gnome-logs/wip/gl-journal: 12/14] Use new journal query API for "security" category
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-logs/wip/gl-journal: 12/14] Use new journal query API for "security" category
- Date: Thu, 3 Oct 2013 12:57:08 +0000 (UTC)
commit 28bd2f2a25e06758473db6d625dc789e628a8168
Author: David King <davidk gnome org>
Date: Thu Oct 3 11:56:16 2013 +0100
Use new journal query API for "security" category
src/gl-eventview.c | 138 +++++++++++----------------------------------------
1 files changed, 30 insertions(+), 108 deletions(-)
---
diff --git a/src/gl-eventview.c b/src/gl-eventview.c
index 86ba68e..e5fdf73 100644
--- a/src/gl-eventview.c
+++ b/src/gl-eventview.c
@@ -548,18 +548,25 @@ insert_journal_query_devices (GlJournal *journal,
}
static void
-insert_journal_items_security (sd_journal *journal, GtkListBox *listbox)
+insert_journal_query_security (GlJournal *journal,
+ const GlJournalQuery *query,
+ GtkListBox *listbox)
{
- gsize i;
+ GList *results = NULL;
+ GList *l;
+ gsize n_results;
+
+ results = gl_journal_query (journal, query);
+
+ n_results = g_list_length (results);
- for (i = 0; i < 10; i++)
+ if (n_results != N_RESULTS)
+ {
+ g_warning ("Number of results different than requested");
+ }
+
+ for (l = results; l != NULL; l = g_list_next (l))
{
- gint ret;
- const gchar *audit;
- const gchar *message;
- const gchar *comm;
- gchar *cursor;
- gsize length;
GtkWidget *row;
GtkStyleContext *context;
GtkWidget *grid;
@@ -567,77 +574,25 @@ insert_journal_items_security (sd_journal *journal, GtkListBox *listbox)
gchar *markup;
gboolean rtl;
GtkWidget *image;
+ GlJournalResult result = *(GlJournalResult *)(l->data);
- ret = sd_journal_get_data (journal, "_AUDIT_SESSION",
- (const void **)&audit, &length);
-
- if (ret == -ENOENT)
- {
- g_debug ("Skipping journal entry without audit session");
- --i;
- goto out;
- }
- else if (ret < 0)
- {
- g_warning ("Error getting message from systemd journal: %s",
- g_strerror (-ret));
- break;
- }
-
- ret = sd_journal_get_data (journal, "_COMM", (const void **)&comm,
- &length);
-
- if (ret < 0)
- {
- g_debug ("Unable to get commandline from systemd journal: %s",
- g_strerror (-ret));
- comm = "_COMM=";
- }
-
- ret = sd_journal_get_data (journal, "MESSAGE", (const void **)&message,
- &length);
-
- if (ret < 0)
- {
- g_warning ("Error getting message from systemd journal: %s",
- g_strerror (-ret));
- break;
- }
-
- ret = sd_journal_get_cursor (journal, &cursor);
-
- if (ret < 0)
- {
- g_warning ("Error getting cursor for current journal entry: %s",
- g_strerror (-ret));
- break;
- }
-
- ret = sd_journal_test_cursor (journal, cursor);
-
- if (ret < 0)
+ /* Skip if the journal entry does not have an associated audit
+ * session. */
+ if (*result.audit_session == '\0')
{
- g_warning ("Error testing cursor string: %s", g_strerror (-ret));
- free (cursor);
- break;
- }
- else if (ret == 0)
- {
- g_warning ("Cursor string does not match journal entry");
- /* Not a problem at this point, but would be when seeking to the
- * cursor later on. */
+ continue;
}
row = gtk_list_box_row_new ();
context = gtk_widget_get_style_context (GTK_WIDGET (row));
gtk_style_context_add_class (context, "event");
- /* sd_journal_get_cursor allocates the cursor with libc malloc. */
- g_object_set_data_full (G_OBJECT (row), "cursor", cursor, free);
+ g_object_set_data_full (G_OBJECT (row), "cursor",
+ g_strdup (result.cursor), g_free);
grid = gtk_grid_new ();
gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
gtk_container_add (GTK_CONTAINER (row), grid);
- markup = g_markup_printf_escaped ("<b>%s</b>", strchr (comm, '=') + 1);
+ markup = g_markup_printf_escaped ("<b>%s</b>", result.comm);
label = gtk_label_new (NULL);
gtk_widget_set_hexpand (label, TRUE);
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
@@ -646,7 +601,7 @@ insert_journal_items_security (sd_journal *journal, GtkListBox *listbox)
g_free (markup);
gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
- label = gtk_label_new (strchr (message, '=') + 1);
+ label = gtk_label_new (result.message);
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1);
@@ -658,21 +613,9 @@ insert_journal_items_security (sd_journal *journal, GtkListBox *listbox)
gtk_grid_attach (GTK_GRID (grid), image, 1, 0, 1, 2);
gtk_container_add (GTK_CONTAINER (listbox), row);
-
-out:
- ret = sd_journal_previous (journal);
-
- if (ret < 0)
- {
- g_warning ("Error setting cursor to previous systemd journal entry %s",
- g_strerror (-ret));
- break;
- }
- else if (ret == 0)
- {
- g_debug ("End of systemd journal reached");
- }
}
+
+ gl_journal_results_free (journal, results);
}
static void
@@ -921,40 +864,19 @@ static void
gl_event_view_add_listbox_security (GlEventView *view)
{
GlEventViewPrivate *priv;
- gint ret;
- sd_journal *journal;
+ const GlJournalQuery query = { N_RESULTS, NULL };
GtkWidget *listbox;
GtkWidget *scrolled;
priv = gl_event_view_get_instance_private (view);
- journal = gl_journal_get_journal (priv->journal);
-
- ret = sd_journal_seek_tail (journal);
-
- if (ret < 0)
- {
- g_warning ("Error seeking to end of systemd journal: %s",
- g_strerror (-ret));
- }
-
- ret = sd_journal_previous (journal);
-
- if (ret < 0)
- {
- g_warning ("Error setting cursor to end of systemd journal: %s",
- g_strerror (-ret));
- }
- else if (ret == 0)
- {
- g_debug ("End of systemd journal reached");
- }
listbox = gtk_list_box_new ();
gtk_list_box_set_filter_func (GTK_LIST_BOX (listbox),
(GtkListBoxFilterFunc)listbox_search_filter_func,
view, NULL);
- insert_journal_items_security (journal, GTK_LIST_BOX (listbox));
+ insert_journal_query_security (priv->journal, &query,
+ GTK_LIST_BOX (listbox));
scrolled = gtk_scrolled_window_new (NULL, NULL);
gtk_container_add (GTK_CONTAINER (scrolled), listbox);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]