[gnome-logs] Add support for additional journal parameters



commit 820c6bf250e9fd79d34faf2feed130a56310e1fa
Author: Pranav Ganorkar <pranavg189 gmail com>
Date:   Thu Jul 14 19:52:48 2016 +0530

    Add support for additional journal parameters
    
    More parameters, including PID and GID, are added. The tokenizer was
    modified to detect characters encountered in these new parameters.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=768848

 src/gl-eventviewlist.c |   61 +++++++++++++++++++++++----------
 src/gl-journal-model.c |   88 ++++++++++++++++++++++++++++++++++++++++++++---
 src/gl-journal.c       |   72 +++++++++++++++++++++++++++++++++++++++
 src/gl-journal.h       |    4 ++
 4 files changed, 200 insertions(+), 25 deletions(-)
---
diff --git a/src/gl-eventviewlist.c b/src/gl-eventviewlist.c
index ec77a81..eef15c1 100644
--- a/src/gl-eventviewlist.c
+++ b/src/gl-eventviewlist.c
@@ -371,22 +371,16 @@ get_current_boot_id (const gchar *boot_match)
     return g_strdup (boot_value);
 }
 
-/* Create query object according to category and set it on journal model */
-static GlQuery *
-create_query_object (GlJournalModel *model,
-                     GlCategoryList *list,
-                     const gchar *current_boot_match,
-                     const gchar *search_text)
+static void
+query_add_category_matches (GlQuery *query,
+                            GlCategoryList *list,
+                            const gchar *boot_match)
 {
-    GlQuery *query;
     gchar *boot_id;
     GlCategoryListFilter filter;
 
-    /* Create new query object */
-    query = gl_query_new ();
-
     /* Get current boot id */
-    boot_id = get_current_boot_id (current_boot_match);
+    boot_id = get_current_boot_id (boot_match);
 
     /* Add boot match for all the categories */
     gl_query_add_match (query, "_BOOT_ID", boot_id, SEARCH_TYPE_EXACT);
@@ -452,13 +446,42 @@ create_query_object (GlJournalModel *model,
             g_assert_not_reached ();
     }
 
-    /* Add Substring Matches */
-    gl_query_add_match (query, "_MESSAGE", search_text, SEARCH_TYPE_SUBSTRING);
+    g_free (boot_id);
+}
+
+static void
+query_add_search_matches (GlQuery *query,
+                          const gchar *search_text)
+{
+    /* Add substring matches */
+    gl_query_add_match (query, "_PID", search_text, SEARCH_TYPE_SUBSTRING);
+    gl_query_add_match (query, "_UID", search_text, SEARCH_TYPE_SUBSTRING);
+    gl_query_add_match (query, "_GID", search_text, SEARCH_TYPE_SUBSTRING);
+    gl_query_add_match (query, "MESSAGE", search_text, SEARCH_TYPE_SUBSTRING);
     gl_query_add_match (query, "_COMM", search_text, SEARCH_TYPE_SUBSTRING);
+    gl_query_add_match (query, "_SYSTEMD_UNIT", search_text, SEARCH_TYPE_SUBSTRING);
     gl_query_add_match (query, "_KERNEL_DEVICE", search_text, SEARCH_TYPE_SUBSTRING);
     gl_query_add_match (query, "_AUDIT_SESSION", search_text, SEARCH_TYPE_SUBSTRING);
+    gl_query_add_match (query, "_EXE", search_text, SEARCH_TYPE_SUBSTRING);
+}
 
-    g_free (boot_id);
+/* Create query object according to selected category */
+static GlQuery *
+create_query_object (GlEventViewList *view)
+{
+    GlEventViewListPrivate *priv;
+    GlQuery *query;
+    GlCategoryList *list;
+
+    priv = gl_event_view_list_get_instance_private (view);
+    list = GL_CATEGORY_LIST (priv->categories);
+
+    /* Create new query object */
+    query = gl_query_new ();
+
+    query_add_category_matches (query, list, priv->boot_match);
+
+    query_add_search_matches (query, priv->search_text);
 
     return query;
 }
@@ -478,7 +501,7 @@ on_notify_category (GlCategoryList *list,
     priv = gl_event_view_list_get_instance_private (view);
 
     /* Create the query object */
-    query = create_query_object (priv->journal_model, list, priv->boot_match, priv->search_text);
+    query = create_query_object (view);
 
     /* Set the created query on the journal model */
     gl_journal_model_take_query (priv->journal_model, query);
@@ -593,20 +616,20 @@ static void
 on_search_entry_changed (GtkSearchEntry *entry,
                          gpointer user_data)
 {
+    GlEventViewList *view;
     GlEventViewListPrivate *priv;
-    GlCategoryList *categories;
     GlQuery *query;
 
-    priv = gl_event_view_list_get_instance_private (GL_EVENT_VIEW_LIST (user_data));
+    view = GL_EVENT_VIEW_LIST (user_data);
 
-    categories = GL_CATEGORY_LIST (priv->categories);
+    priv = gl_event_view_list_get_instance_private (view);
 
     g_free (priv->search_text);
 
     priv->search_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->search_entry)));
 
     /* Create the query object */
-    query = create_query_object (priv->journal_model, categories, priv->boot_match, priv->search_text);
+    query = create_query_object (view);
 
     /* Set the created query on the journal model */
     gl_journal_model_take_query (priv->journal_model, query);
diff --git a/src/gl-journal-model.c b/src/gl-journal-model.c
index 7b3653f..c2f95d7 100644
--- a/src/gl-journal-model.c
+++ b/src/gl-journal-model.c
@@ -449,6 +449,22 @@ tokenize_search_string (gchar *search_text)
     token_array = g_ptr_array_new_with_free_func (g_free);
     scanner = g_scanner_new (NULL);
     scanner->config->cset_skip_characters = " =\t\n";
+
+    /* All the characters used in the journal field values */
+    scanner->config->cset_identifier_first = (
+                                              G_CSET_a_2_z
+                                              G_CSET_A_2_Z
+                                              G_CSET_DIGITS
+                                              "/_.-@:\\+"
+                                              );
+
+    scanner->config->cset_identifier_nth = (
+                                            G_CSET_a_2_z
+                                            G_CSET_A_2_Z
+                                            G_CSET_DIGITS
+                                            "/_.-@:\\"
+                                            );
+
     g_scanner_input_text (scanner, search_text, strlen (search_text));
 
     do
@@ -535,39 +551,99 @@ gl_query_item_get_entry_parameter (GlQueryItem *search_match,
     const gchar *message;
     const gchar *kernel_device;
     const gchar *audit_session;
+    const gchar *pid;
+    const gchar *uid;
+    const gchar *gid;
+    const gchar *systemd_unit;
+    const gchar *executable_path;
 
     comm = gl_journal_entry_get_command_line (entry);
     message = gl_journal_entry_get_message (entry);
     kernel_device = gl_journal_entry_get_kernel_device (entry);
     audit_session = gl_journal_entry_get_audit_session (entry);
+    systemd_unit = gl_journal_entry_get_systemd_unit (entry);
+    pid = gl_journal_entry_get_pid (entry);
+    uid = gl_journal_entry_get_uid (entry);
+    gid = gl_journal_entry_get_gid (entry);
+    executable_path = gl_journal_entry_get_executable_path (entry);
 
     if (case_sensitive)
     {
         if (strstr ("_MESSAGE", search_match->field_name))
+        {
             return message;
-
+        }
         else if (strstr ("_COMM", search_match->field_name))
+        {
             return comm;
-
+        }
         else if (strstr ("_KERNEL_DEVICE", search_match->field_name))
+        {
             return kernel_device;
-
+        }
         else if (strstr ("_AUDIT_SESSION", search_match->field_name))
+        {
             return audit_session;
+        }
+        else if (strstr ("_SYSTEMD_UNIT", search_match->field_name))
+        {
+            return systemd_unit;
+        }
+        else if (strstr ("_PID", search_match->field_name))
+        {
+            return pid;
+        }
+        else if (strstr ("_UID", search_match->field_name))
+        {
+            return uid;
+        }
+        else if (strstr ("_GID", search_match->field_name))
+        {
+            return gid;
+        }
+        else if (strstr ("_EXE", search_match->field_name))
+        {
+            return executable_path;
+        }
     }
     else
     {
         if (utf8_strcasestr ("_message", search_match->field_name))
+        {
             return message;
-
+        }
         else if (utf8_strcasestr ("_comm", search_match->field_name))
+        {
             return comm;
-
+        }
         else if (utf8_strcasestr ("_kernel_device", search_match->field_name))
+        {
             return kernel_device;
-
+        }
         else if (utf8_strcasestr ("_audit_session", search_match->field_name))
+        {
             return audit_session;
+        }
+        else if (utf8_strcasestr ("_systemd_unit", search_match->field_name))
+        {
+            return systemd_unit;
+        }
+        else if (utf8_strcasestr ("_pid", search_match->field_name))
+        {
+            return pid;
+        }
+        else if (utf8_strcasestr ("_uid", search_match->field_name))
+        {
+            return uid;
+        }
+        else if (utf8_strcasestr ("_gid", search_match->field_name))
+        {
+            return gid;
+        }
+        else if (utf8_strcasestr ("_exe", search_match->field_name))
+        {
+            return executable_path;
+        }
     }
 
     return NULL;
diff --git a/src/gl-journal.c b/src/gl-journal.c
index cbbeff5..05aeaff 100644
--- a/src/gl-journal.c
+++ b/src/gl-journal.c
@@ -39,6 +39,10 @@ struct _GlJournalEntry
   gchar *catalog;
   guint priority;
   gchar *uid;
+  gchar *pid;
+  gchar *gid;
+  gchar *systemd_unit;
+  gchar *executable_path;
 };
 
 G_DEFINE_TYPE (GlJournalEntry, gl_journal_entry, G_TYPE_OBJECT);
@@ -486,6 +490,38 @@ _gl_journal_query_entry (GlJournal *self)
         g_clear_error (&error);
     }
 
+    entry->pid = gl_journal_get_data (self, "_PID", &error);
+
+    if (error != NULL)
+    {
+        g_debug ("Error while getting pid from journal: %s", error->message);
+        g_clear_error (&error);
+    }
+
+    entry->gid = gl_journal_get_data (self, "_GID", &error);
+
+    if (error != NULL)
+    {
+        g_debug ("Error while getting gid from journal: %s", error->message);
+        g_clear_error (&error);
+    }
+
+    entry->systemd_unit = gl_journal_get_data (self, "_SYSTEMD_UNIT", &error);
+
+    if (error != NULL)
+    {
+        g_debug ("Error while getting systemd unit from journal: %s", error->message);
+        g_clear_error (&error);
+    }
+
+    entry->executable_path = gl_journal_get_data (self, "_EXE", &error);
+
+    if (error != NULL)
+    {
+        g_debug ("Error while getting executable path from journal: %s", error->message);
+        g_clear_error (&error);
+    }
+
     return entry;
 
 out:
@@ -677,6 +713,10 @@ gl_journal_entry_finalize (GObject *object)
   g_free (entry->audit_session);
   g_free (entry->transport);
   g_free (entry->uid);
+  g_free (entry->pid);
+  g_free (entry->gid);
+  g_free (entry->systemd_unit);
+  g_free (entry->executable_path);
 
   G_OBJECT_CLASS (gl_journal_entry_parent_class)->finalize (object);
 }
@@ -760,3 +800,35 @@ gl_journal_entry_get_uid (GlJournalEntry *entry)
 
   return entry->uid;
 }
+
+const gchar *
+gl_journal_entry_get_pid (GlJournalEntry *entry)
+{
+  g_return_val_if_fail (GL_IS_JOURNAL_ENTRY (entry), NULL);
+
+  return entry->pid;
+}
+
+const gchar *
+gl_journal_entry_get_gid (GlJournalEntry *entry)
+{
+  g_return_val_if_fail (GL_IS_JOURNAL_ENTRY (entry), NULL);
+
+  return entry->gid;
+}
+
+const gchar *
+gl_journal_entry_get_systemd_unit (GlJournalEntry *entry)
+{
+  g_return_val_if_fail (GL_IS_JOURNAL_ENTRY (entry), NULL);
+
+  return entry->systemd_unit;
+}
+
+const gchar *
+gl_journal_entry_get_executable_path (GlJournalEntry *entry)
+{
+  g_return_val_if_fail (GL_IS_JOURNAL_ENTRY (entry), NULL);
+
+  return entry->executable_path;
+}
diff --git a/src/gl-journal.h b/src/gl-journal.h
index 4173eac..c140703 100644
--- a/src/gl-journal.h
+++ b/src/gl-journal.h
@@ -87,6 +87,10 @@ const gchar *           gl_journal_entry_get_transport                  (GlJourn
 const gchar *           gl_journal_entry_get_catalog                    (GlJournalEntry *entry);
 guint                   gl_journal_entry_get_priority                   (GlJournalEntry *entry);
 const gchar *           gl_journal_entry_get_uid                        (GlJournalEntry *entry);
+const gchar *           gl_journal_entry_get_pid                        (GlJournalEntry *entry);
+const gchar *           gl_journal_entry_get_gid                        (GlJournalEntry *entry);
+const gchar *           gl_journal_entry_get_systemd_unit               (GlJournalEntry *entry);
+const gchar *           gl_journal_entry_get_executable_path            (GlJournalEntry *entry);
 
 G_END_DECLS
 


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