[gnome-logs/wip/test: 5/33] Remove libsystemd function calls.
- From: Rashi Aswani <aswanirashi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-logs/wip/test: 5/33] Remove libsystemd function calls.
- Date: Wed, 19 Aug 2015 05:49:12 +0000 (UTC)
commit 6ed71c13e45c14a80da8cb8d72981747e8cf4283
Author: Rashi Aswani <aswanirashi19 gmail com>
Date: Thu Jun 4 05:26:23 2015 +0530
Remove libsystemd function calls.
tests/gl-journal-mock.c | 267 +----------------------------------------------
1 files changed, 1 insertions(+), 266 deletions(-)
---
diff --git a/tests/gl-journal-mock.c b/tests/gl-journal-mock.c
index 57b6fe1..f0fa533 100644
--- a/tests/gl-journal-mock.c
+++ b/tests/gl-journal-mock.c
@@ -42,7 +42,6 @@ G_DEFINE_TYPE (MockGlJournalEntry, gl_journal_entry, G_TYPE_OBJECT);
typedef struct
{
- sd_journal *journal;
gint fd;
guint source_id;
gchar **mandatory_fields;
@@ -56,36 +55,6 @@ mock_gl_journal_error_quark (void)
return g_quark_from_static_string ("gl-journal-error-quark");
}
-static gboolean
-mock_on_journal_changed (gint fd,
- GIOCondition condition,
- GlJournal *self)
-{
- gint ret;
- MockGlJournalPrivate *priv = gl_journal_get_instance_private (self);
-
- ret = sd_journal_process (priv->journal);
-
- switch (ret)
- {
- case SD_JOURNAL_NOP:
- g_debug ("Journal change was a no-op");
- break;
- case SD_JOURNAL_APPEND:
- g_debug ("New journal entries added");
- break;
- case SD_JOURNAL_INVALIDATE:
- g_debug ("Journal files added or removed");
- break;
- default:
- g_warning ("Error processing events from systemd journal: %s",
- g_strerror (-ret));
- break;
- }
-
- return G_SOURCE_CONTINUE;
-}
-
static void
mock_gl_journal_finalize (GObject *object)
{
@@ -93,7 +62,6 @@ mock_gl_journal_finalize (GObject *object)
MockGlJournalPrivate *priv = gl_journal_get_instance_private (journal);
g_source_remove (priv->source_id);
- g_clear_pointer (&priv->journal, sd_journal_close);
g_clear_pointer (&priv->mandatory_fields, g_strfreev);
}
@@ -108,56 +76,6 @@ mock_gl_journal_class_init (GlJournalClass *klass)
static void
mock_gl_journal_init (GlJournal *self)
{
- MockGlJournalPrivate *priv;
- sd_journal *journal;
- gint ret;
-
- priv = gl_journal_get_instance_private (self);
-
- ret = sd_journal_open (&journal, 0);
- priv->journal = journal;
-
- if (ret < 0)
- {
- g_critical ("Error opening systemd journal: %s", g_strerror (-ret));
- }
-
- ret = sd_journal_get_fd (journal);
-
- if (ret < 0)
- {
- g_warning ("Error getting polling fd from systemd journal: %s",
- g_strerror (-ret));
- }
-
- priv->fd = ret;
- ret = sd_journal_get_events (journal);
-
- if (ret < 0)
- {
- g_warning ("Error getting poll events from systemd journal: %s",
- g_strerror (-ret));
- }
-
- priv->source_id = g_unix_fd_add (priv->fd, ret,
- (GUnixFDSourceFunc) on_journal_changed,
- self);
- ret = sd_journal_reliable_fd (journal);
-
- if (ret < 0)
- {
- g_warning ("Error checking reliability of systemd journal poll fd: %s",
- g_strerror (-ret));
- }
- else if (ret == 0)
- {
- g_debug ("Latency expected while polling for systemd journal activity");
- }
- else
- {
- g_debug ("Immediate wakeups expected for systemd journal activity");
- }
-
}
static gchar *
@@ -165,8 +83,6 @@ gl_journal_mock_get_data (MockGlJournal *self,
const gchar *field,
GError **error)
{
- MockGlJournalPrivate *priv;
- gint ret;
gconstpointer data;
gsize length;
gsize prefix_len;
@@ -174,33 +90,6 @@ gl_journal_mock_get_data (MockGlJournal *self,
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
g_return_val_if_fail (field != NULL, NULL);
- priv = gl_journal_get_instance_private (self);
- ret = sd_journal_get_data (priv->journal, field, &data, &length);
-
- if (ret < 0)
- {
- gint code;
-
- switch (-ret)
- {
- case ENOENT:
- code = GL_JOURNAL_ERROR_NO_FIELD;
- break;
- case EADDRNOTAVAIL:
- code = GL_JOURNAL_ERROR_INVALID_POINTER;
- break;
- default:
- code = GL_JOURNAL_ERROR_FAILED;
- break;
- }
-
- g_set_error (error, GL_JOURNAL_ERROR, code,
- "Unable to get field ā%sā from systemd journal: %s",
- field, g_strerror (-ret));
-
- return NULL;
- }
-
/* Field data proper starts after the first '='. */
prefix_len = strchr (data, '=') - (const gchar *)data + 1;
@@ -214,64 +103,13 @@ gl_journal_mock_query_entry (GlJournal *self)
MockGlJournalPrivate *priv;
MockGlJournalEntry *entry;
gint ret;
- sd_journal *journal;
GError *error = NULL;
gchar *priority;
priv = gl_journal_get_instance_private (self);
- journal = priv->journal;
entry = g_object_new (GL_TYPE_JOURNAL_ENTRY, NULL);
- ret = sd_journal_get_realtime_usec (journal, &entry->timestamp);
-
- if (ret < 0)
- {
- g_warning ("Error getting timestamp from systemd journal: %s",
- g_strerror (-ret));
- goto out;
- }
-
- ret = sd_journal_get_cursor (journal, &entry->cursor);
-
- if (ret < 0)
- {
- g_warning ("Error getting cursor for current journal entry: %s",
- g_strerror (-ret));
- goto out;
- }
-
- ret = sd_journal_test_cursor (journal, entry->cursor);
-
- if (ret < 0)
- {
- g_warning ("Error testing cursor string: %s", g_strerror (-ret));
- free (entry->cursor);
- entry->cursor = NULL;
- goto out;
- }
- 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. */
- }
-
- ret = sd_journal_get_catalog (journal, &entry->catalog);
-
- if (ret == -ENOENT)
- {
- g_debug ("No message for this log entry was found in the catalog");
- entry->catalog = NULL;
- }
- else if (ret < 0)
- {
- g_warning ("Error while getting message from catalog: %s",
- g_strerror (-ret));
- free (entry->cursor);
- goto out;
- }
-
entry->message = gl_journal_get_data (self, "MESSAGE", NULL);
if (error != NULL)
@@ -298,7 +136,7 @@ gl_journal_mock_query_entry (GlJournal *self)
entry->priority = priority ? atoi (priority) : LOG_INFO;
g_free (priority);
- entry->comm = gl_journal_get_data (self, "_COMM", &error);
+ entry->comm = gl_journal_get_data (self, "_COMM", &error);
if (error != NULL)
{
@@ -325,63 +163,6 @@ out:
}
/**
- * gl_journal_query_match:
- * @query: a @query to match against the current log entry
- *
- * systemd's matching doesn't allow checking for the existance of
- * fields. This function checks if fields in @query that don't have a
- * value (and thus no '=' delimiter) are present at all in the current
- * log entry.
- *
- * Returns: %TRUE if the current log entry contains all fields in @query
- */
-static gboolean
-gl_journal_mock_query_match (sd_journal *journal,
- const gchar * const *query)
-{
- gint i;
-
- for (i = 0; query[i]; i++)
- {
- int r;
- const void *data;
- size_t len;
-
- /* don't check fields that match on a value */
- if (strchr (query[i], '='))
- continue;
-
- r = sd_journal_get_data (journal, query[i], &data, &len);
-
- if (r == -ENOENT) /* field doesn't exist */
- return FALSE;
-
- else if (r < 0)
- g_warning ("Failed to read log entry: %s", g_strerror (-r));
- }
-
- return TRUE;
-}
-
-static gchar *
-create_boot_id_match_string (void)
-{
- sd_id128_t boot_id;
- gchar boot_string[33];
- int r;
-
- r = sd_id128_get_boot (&boot_id);
- if (r < 0)
- {
- g_warning ("Error getting boot ID of running kernel: %s", g_strerror (-r));
- return NULL;
- }
-
- sd_id128_to_string (boot_id, boot_string);
- return g_strconcat ("_BOOT_ID=", boot_string, NULL);
-}
-
-/**
* gl_journal_set_matches:
* @journal: a #GlJournal
* @matches: new matches to set
@@ -404,8 +185,6 @@ gl_journal_mock_set_matches (GlJournal *journal,
if (priv->mandatory_fields)
g_clear_pointer (&priv->mandatory_fields, g_strfreev);
- sd_journal_flush_matches (priv->journal);
-
mandatory_fields = g_ptr_array_new ();
for (i = 0; matches[i]; i++)
{
@@ -421,61 +200,17 @@ gl_journal_mock_set_matches (GlJournal *journal,
if (g_str_has_prefix (matches[i], "_BOOT_ID="))
has_boot_id = TRUE;
-
- r = sd_journal_add_match (priv->journal, matches[i], 0);
- if (r < 0)
- {
- g_critical ("Failed to add match '%s': %s", matches[i], g_strerror (-r));
- break;
- }
}
/* add sentinel */
g_ptr_array_add (mandatory_fields, NULL);
- /* take events from this boot only, unless _BOOT_ID was in @matches */
- if (!has_boot_id)
- {
- gchar *match;
-
- match = create_boot_id_match_string ();
- if (match)
- {
- r = sd_journal_add_match (priv->journal, match, 0);
- if (r < 0)
- g_warning ("Failed to add match '%s': %s", matches[i], g_strerror (-r));
-
- g_free (match);
- }
- }
-
priv->mandatory_fields = (gchar **) g_ptr_array_free (mandatory_fields, FALSE);
-
- r = sd_journal_seek_tail (priv->journal);
- if (r < 0)
- g_warning ("Error seeking to start of systemd journal: %s", g_strerror (-r));
}
MockGlJournalEntry *
_gl_journal_mock_previous (MockGlJournal *journal)
{
- MockGlJournalPrivate *priv = gl_journal_get_instance_private (journal);
- gint r;
-
- r = sd_journal_previous (priv->journal);
- if (r < 0)
- {
- g_warning ("Failed to fetch previous log entry: %s", g_strerror (-r));
- return NULL;
- }
-
- if (r == 0) /* end */
- return NULL;
-
- /* filter this one out because of a non-existent field */
- if (!gl_journal_query_match (priv->journal, (const gchar * const *) priv->mandatory_fields))
- return gl_journal_previous (journal);
-
return _gl_journal_query_entry (journal);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]