summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Zeuthen <davidz@redhat.com>2010-10-04 15:50:01 -0400
committerDavid Zeuthen <davidz@redhat.com>2010-10-04 15:50:01 -0400
commitcdfc1a7732a9cda1fcf87f79232717aaabaa1ad0 (patch)
treebab0a1e61c15154cd1238fd6c8721f7c86bc836e
parent7620487167d851324cadce8775c4e70baa46d3f3 (diff)
Implement Depends, 'list' verb in stc(1) and add default stc.conf file
Signed-off-by: David Zeuthen <davidz@redhat.com>
-rw-r--r--configure.ac1
-rw-r--r--doc/stc-sections.txt1
-rw-r--r--stc/Makefile.am14
-rw-r--r--stc/stc.c184
-rw-r--r--stc/stc.conf.in6
-rw-r--r--stc/stcenums.h4
-rw-r--r--stc/stcitem.c89
-rw-r--r--stc/stcitem.h2
-rw-r--r--stc/stcmonitor.c76
-rw-r--r--stc/stcmonitor.h2
-rw-r--r--stc/stcprivate.h17
-rw-r--r--stc/test.c134
-rw-r--r--stc/testdata/semi_valid_conf/stc.conf4
13 files changed, 455 insertions, 79 deletions
diff --git a/configure.ac b/configure.ac
index c2d263e..068f15d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -98,6 +98,7 @@ AC_OUTPUT([
Makefile
stc/Makefile
stc/stc-1.pc
+stc/stc.conf
doc/Makefile
])
diff --git a/doc/stc-sections.txt b/doc/stc-sections.txt
index 129e6da..ebe982b 100644
--- a/doc/stc-sections.txt
+++ b/doc/stc-sections.txt
@@ -7,6 +7,7 @@ stc_monitor_new
stc_monitor_new_for_config_dir
stc_monitor_get_config_dir
stc_monitor_get_items
+stc_monitor_get_item_by_id
<SUBSECTION Standard>
STC_TYPE_MONITOR
STC_MONITOR
diff --git a/stc/Makefile.am b/stc/Makefile.am
index 8442330..b89827b 100644
--- a/stc/Makefile.am
+++ b/stc/Makefile.am
@@ -126,12 +126,26 @@ pkgconfig_DATA = stc-1.pc
# ----------------------------------------------------------------------------------------------------
+configdir = $(sysconfdir)
+config_DATA = stc.conf
+
+# ----------------------------------------------------------------------------------------------------
+
CLEANFILES =
EXTRA_DIST = \
$(profile_SCRIPTS) \
+ stc.conf.in \
stc-1.pc.in \
$(NULL)
clean-local :
rm -f *~ $(BUILT_SOURCES)
+
+# By default, /etc/stc.conf and /etc/stc.conf.d are world-readable. Individual files
+# in /etc/stc.conf.d can be made readable only by uid 0 etc.
+#
+install-exec-hook:
+ -chmod 644 $(DESTDIR)$(sysconfdir)/stc.conf
+ mkdir -p $(DESTDIR)$(sysconfdir)/stc.conf.d
+ -chmod 755 $(DESTDIR)$(sysconfdir)/stc.conf.d
diff --git a/stc/stc.c b/stc/stc.c
index bac1f5b..c757f90 100644
--- a/stc/stc.c
+++ b/stc/stc.c
@@ -24,6 +24,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "stc.h"
@@ -37,6 +38,33 @@ static GMainLoop *loop = NULL;
/* ---------------------------------------------------------------------------------------------------- */
+static const gchar *
+item_type_to_str (StcItemType type)
+{
+ GEnumClass *klass;
+ GEnumValue *value;
+ const gchar *ret;
+
+ ret = "<Unregistered enum type>";
+ klass = g_type_class_ref (STC_TYPE_ITEM_TYPE);
+ if (klass == NULL)
+ goto out;
+
+ ret = "<Invalid enum value>";
+ value = g_enum_get_value (klass, type);
+ if (value == NULL)
+ goto out;
+
+ ret = value->value_nick;
+
+ out:
+ if (klass != NULL)
+ g_type_class_unref (klass);
+ return ret;
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
G_GNUC_UNUSED static void completion_debug (const gchar *format, ...);
static void remove_arg (gint num, gint *argc, gchar **argv[]);
@@ -160,6 +188,41 @@ _color_run_pager (void)
/* ---------------------------------------------------------------------------------------------------- */
+static void
+error_handler (StcMonitor *monitor,
+ const gchar *filename,
+ gint line_no,
+ GError *error,
+ gpointer user_data)
+{
+ GString *str;
+
+ str = g_string_new (NULL);
+ g_string_append_printf (str, "%s%s", _color_get (_COLOR_BOLD_ON), _color_get (_COLOR_FG_YELLOW));
+ if (filename != NULL)
+ {
+ if (line_no >= 0)
+ g_string_append_printf (str, "%s:%d: ", filename, line_no);
+ else
+ g_string_append_printf (str, "%s: ", filename);
+ }
+ g_string_append_printf (str, "%s", _color_get (_COLOR_RESET));
+ g_string_append_printf (str, "%s%s", _color_get (_COLOR_BOLD_ON), _color_get (_COLOR_FG_RED));
+ g_string_append_printf (str, "%s", error->message);
+ g_string_append_printf (str, "%s", _color_get (_COLOR_RESET));
+ g_string_append_printf (str, "%s", _color_get (_COLOR_FG_BLUE));
+ g_string_append_printf (str, " (%s, %d)", g_quark_to_string (error->domain), error->code);
+ g_string_append_printf (str, "%s", _color_get (_COLOR_RESET));
+
+ if (_color_stdin_is_tty)
+ g_print ("%s\n", str->str);
+ else
+ g_printerr ("%s\n", str->str);
+ g_string_free (str, TRUE);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
static const GOptionEntry command_list_entries[] =
{
{ NULL }
@@ -175,8 +238,13 @@ handle_command_list (gint *argc,
gint ret;
GOptionContext *o;
gchar *s;
+ StcMonitor *monitor;
+ GList *items;
+ GList *l;
+ guint n;
ret = 1;
+ monitor = NULL;
modify_argv0_for_command (argc, argv, "list");
@@ -204,13 +272,123 @@ handle_command_list (gint *argc,
_color_run_pager ();
- g_print ("%sfoo%s\n",
- _color_get (_COLOR_FG_RED),
- _color_get (_COLOR_RESET));
+ monitor = stc_monitor_new (error_handler, NULL);
+
+ items = stc_monitor_get_items (monitor);
+
+ for (l = items; l != NULL; l = l->next)
+ {
+ StcItem *item = STC_ITEM (l->data);
+ StcItemType type;
+ const gchar *id;
+ const gchar *nick_name;
+ const gchar *target;
+ const gchar *const *options;
+ const gchar *const *deps;
+
+ type = stc_item_get_item_type (item);
+ id = stc_item_get_id (item);
+ nick_name = stc_item_get_nick_name (item);
+ target = stc_item_get_target (item);
+
+ g_print ("%s%s%s:%s\n",
+ _color_get (_COLOR_FG_BLUE),
+ _color_get (_COLOR_BOLD_ON),
+ id,
+ _color_get (_COLOR_RESET));
+
+ g_print (" %sType:%s %s%s%s\n",
+ _color_get (_COLOR_FG_WHITE),
+ _color_get (_COLOR_RESET),
+ _color_get (_COLOR_FG_GREEN),
+ item_type_to_str (type),
+ _color_get (_COLOR_RESET));
+
+ g_print (" %sTarget:%s %s%s%s\n",
+ _color_get (_COLOR_FG_WHITE),
+ _color_get (_COLOR_RESET),
+ _color_get (_COLOR_FG_GREEN),
+ target,
+ _color_get (_COLOR_RESET));
+
+ if (nick_name != NULL)
+ {
+ g_print (" %sNick Name:%s %s%s%s\n",
+ _color_get (_COLOR_FG_WHITE),
+ _color_get (_COLOR_RESET),
+ _color_get (_COLOR_FG_GREEN),
+ nick_name,
+ _color_get (_COLOR_RESET));
+ }
+
+ options = stc_item_get_option_keys (item);
+ if (options != NULL && g_strv_length ((gchar **) options) > 0)
+ {
+ g_print (" %sOptions:%s ",
+ _color_get (_COLOR_FG_WHITE),
+ _color_get (_COLOR_RESET));
+
+ for (n = 0; options[n] != NULL; n++)
+ {
+ if (n > 0)
+ g_print ("\n ");
+ g_print ("%s%s%s%s=%s%s%s%s",
+ _color_get (_COLOR_BOLD_ON),
+ _color_get (_COLOR_FG_WHITE),
+ options[n],
+ _color_get (_COLOR_RESET),
+ _color_get (_COLOR_FG_CYAN),
+ _color_get (_COLOR_BOLD_ON),
+ stc_item_get_option (item, options[n]),
+ _color_get (_COLOR_RESET));
+ }
+ g_print ("\n");
+ }
+
+ deps = stc_item_get_dependencies (item);
+ if (deps != NULL)
+ {
+ g_print (" %sDependencies:%s ",
+ _color_get (_COLOR_FG_WHITE),
+ _color_get (_COLOR_RESET));
+ for (n = 0; deps[n] != NULL; n++)
+ {
+ StcItem *dep_item;
+
+ if (n != 0)
+ g_print ("\n ");
+ dep_item = stc_monitor_get_item_by_id (monitor, deps[n]);
+ if (dep_item == NULL)
+ {
+ g_print ("%s%s%s (missing)%s",
+ _color_get (_COLOR_BOLD_ON),
+ _color_get (_COLOR_FG_RED),
+ deps[n],
+ _color_get (_COLOR_RESET));
+ }
+ else
+ {
+ g_print ("%s%s%s%s",
+ _color_get (_COLOR_BOLD_ON),
+ _color_get (_COLOR_FG_BLUE),
+ deps[n],
+ _color_get (_COLOR_RESET));
+ g_object_unref (dep_item);
+ }
+ }
+ g_print ("\n");
+ }
+
+ g_print ("\n");
+ }
+ g_list_foreach (items, (GFunc) g_object_unref, NULL);
+ g_list_free (items);
ret = 0;
out:
+ if (monitor != NULL)
+ g_object_unref (monitor);
g_option_context_free (o);
return ret;
}
diff --git a/stc/stc.conf.in b/stc/stc.conf.in
new file mode 100644
index 0000000..3292a60
--- /dev/null
+++ b/stc/stc.conf.in
@@ -0,0 +1,6 @@
+# @sysconfdir@/stc.conf
+#
+# Mountable filesystems and startable devices.
+# See man page stc.conf(5) for more info.
+#
+
diff --git a/stc/stcenums.h b/stc/stcenums.h
index d92d081..4523503 100644
--- a/stc/stcenums.h
+++ b/stc/stcenums.h
@@ -36,6 +36,7 @@ G_BEGIN_DECLS
* @STC_ERROR_FAILED: The operation failed / Generic error.
* @STC_ERROR_PARSE_ERROR: A configurtion item is invalid.
* @STC_ERROR_DUPLICATE_ITEM: A configuration item with an existing identifier was encountered.
+ * @STC_ERROR_UNRESOLVED_DEPENDENCY: A configuration item has a dependency that cannot be resolved.
*
* Error codes for the #STC_ERROR error domain.
*/
@@ -43,7 +44,8 @@ typedef enum
{
STC_ERROR_FAILED,
STC_ERROR_PARSE_ERROR,
- STC_ERROR_DUPLICATE_ITEM
+ STC_ERROR_DUPLICATE_ITEM,
+ STC_ERROR_UNRESOLVED_DEPENDENCY
} StcError;
/**
diff --git a/stc/stcitem.c b/stc/stcitem.c
index a736429..224c6ff 100644
--- a/stc/stcitem.c
+++ b/stc/stcitem.c
@@ -23,6 +23,7 @@
#include "config.h"
#include "stcitem.h"
+#include "stcmonitor.h"
#include "stcprivate.h"
/**
@@ -46,11 +47,15 @@ struct _StcItem
{
GObject parent_instance;
+ StcMonitor *monitor;
+
StcItemType type;
gchar *id;
gchar *nick_name;
gchar *target;
GHashTable *options;
+ gchar **depends;
+
gboolean can_apply;
gboolean is_applied;
@@ -59,6 +64,8 @@ struct _StcItem
/* private */
gchar *sort_key;
+ gchar *path;
+ gint line_no;
};
typedef struct _StcItemClass StcItemClass;
@@ -88,9 +95,12 @@ stc_item_finalize (GObject *object)
g_free (item->nick_name);
g_free (item->target);
g_hash_table_unref (item->options);
+ g_strfreev (item->depends);
+
g_free (item->option_keys);
g_free (item->sort_key);
+ g_free (item->path);
if (G_OBJECT_CLASS (stc_item_parent_class)->finalize)
G_OBJECT_CLASS (stc_item_parent_class)->finalize (object);
@@ -162,14 +172,6 @@ stc_item_get_target (StcItem *item)
return item->target;
}
-GList *
-stc_item_get_dependencies (StcItem *item)
-{
- g_return_val_if_fail (STC_IS_ITEM (item), FALSE);
- /* TODO */
- return NULL;
-}
-
gboolean
stc_item_get_can_apply (StcItem *item)
{
@@ -186,12 +188,15 @@ stc_item_get_is_applied (StcItem *item)
StcItem *
-_stc_item_new (StcItemType type,
- const gchar *id,
- const gchar *target,
- const gchar *nick_name,
- GHashTable *options,
- const gchar *sort_key)
+_stc_item_new (StcItemType type,
+ const gchar *id,
+ const gchar *target,
+ const gchar *nick_name,
+ GHashTable *options,
+ const gchar *const *depends,
+ const gchar *sort_key,
+ const gchar *path,
+ gint line_no)
{
StcItem *item;
@@ -202,12 +207,40 @@ _stc_item_new (StcItemType type,
item->nick_name = g_strdup (nick_name);
item->type = type;
item->options = g_hash_table_ref (options);
+ item->depends = g_strdupv ((gchar **) depends);
+
item->sort_key = g_strdup (sort_key);
+ item->path = g_strdup (path);
+ item->line_no = line_no;
return item;
}
static gboolean
+strv_equal (gchar **a, gchar **b)
+{
+ guint n;
+
+ if (a == NULL && b != NULL)
+ return FALSE;
+ if (a != NULL && b == NULL)
+ return FALSE;
+ if (a == NULL && b == NULL)
+ return TRUE;
+
+ g_assert (a != NULL);
+ g_assert (b != NULL);
+
+ for (n = 0; a[n] != NULL || b[n] != NULL; n++)
+ {
+ if (g_strcmp0 (a[n], b[n]) != 0)
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean
hash_tables_equal (GHashTable *a, GHashTable *b)
{
gboolean ret;
@@ -273,6 +306,13 @@ _stc_item_update (StcItem *item, StcItem *other)
changed = TRUE;
}
+ if (!strv_equal (item->depends, other->depends))
+ {
+ g_strfreev (item->depends);
+ item->depends = g_strdupv (other->depends);
+ changed = TRUE;
+ }
+
return changed;
}
@@ -283,6 +323,27 @@ _stc_item_get_sort_key (StcItem *item)
return item->sort_key;
}
+const gchar *
+_stc_item_get_path (StcItem *item)
+{
+ g_return_val_if_fail (STC_IS_ITEM (item), NULL);
+ return item->path;
+}
+
+gint
+_stc_item_get_line_no (StcItem *item)
+{
+ g_return_val_if_fail (STC_IS_ITEM (item), -1);
+ return item->line_no;
+}
+
+const gchar * const *
+stc_item_get_dependencies (StcItem *item)
+{
+ g_return_val_if_fail (STC_IS_ITEM (item), NULL);
+ return (const gchar * const *) item->depends;
+}
+
const gchar* const *
stc_item_get_option_keys (StcItem *item)
{
diff --git a/stc/stcitem.h b/stc/stcitem.h
index 057404f..c993189 100644
--- a/stc/stcitem.h
+++ b/stc/stcitem.h
@@ -44,7 +44,7 @@ const gchar *stc_item_get_target (StcItem *item);
const gchar* const *stc_item_get_option_keys (StcItem *item);
const gchar *stc_item_get_option (StcItem *item,
const gchar *key);
-GList *stc_item_get_dependencies (StcItem *item);
+const gchar* const *stc_item_get_dependencies (StcItem *item);
gboolean stc_item_get_can_apply (StcItem *item);
gboolean stc_item_get_is_applied (StcItem *item);
diff --git a/stc/stcmonitor.c b/stc/stcmonitor.c
index 8fc5bf6..afbfe7c 100644
--- a/stc/stcmonitor.c
+++ b/stc/stcmonitor.c
@@ -516,6 +516,22 @@ is_valid_item_id (const gchar *str)
return ret;
}
+StcItem *
+stc_monitor_get_item_by_id (StcMonitor *monitor,
+ const gchar *item_id)
+{
+ StcItem *ret;
+
+ g_return_val_if_fail (STC_IS_MONITOR (monitor), NULL);
+ g_return_val_if_fail (item_id != NULL && is_valid_item_id (item_id), NULL);
+
+ ret = g_hash_table_lookup (monitor->map_id_to_item, item_id);
+ if (ret != NULL)
+ g_object_ref (ret);
+
+ return ret;
+}
+
static GList *
stc_monitor_load_one_file (StcMonitor *monitor,
const gchar *path,
@@ -549,12 +565,14 @@ stc_monitor_load_one_file (StcMonitor *monitor,
gchar **options_strv;
StcItem *item;
GHashTable *options;
+ gchar **depends_strv;
tokens = NULL;
target = NULL;
nick_name = NULL;
sort_key = NULL;
options = NULL;
+ depends_strv = NULL;
tokens = g_strsplit (group, " ", 0);
if (g_strv_length (tokens) != 2)
@@ -658,8 +676,19 @@ stc_monitor_load_one_file (StcMonitor *monitor,
/* NickName is optional */
nick_name = g_key_file_get_string (key_file, group, "NickName", NULL);
+ /* Depends is optional */
+ depends_strv = g_key_file_get_string_list (key_file, group, "Depends", NULL, NULL);
+
sort_key = g_strdup_printf ("%s:%s", path, item_id);
- item = _stc_item_new (item_type, item_id, target, nick_name, options, sort_key);
+ item = _stc_item_new (item_type,
+ item_id,
+ target,
+ nick_name,
+ options,
+ (const gchar *const *) depends_strv,
+ sort_key,
+ path,
+ -1);
ret = g_list_prepend (ret, item);
process_next_item:
@@ -667,6 +696,7 @@ stc_monitor_load_one_file (StcMonitor *monitor,
g_free (target);
g_free (nick_name);
g_free (sort_key);
+ g_strfreev (depends_strv);
if (options != NULL)
g_hash_table_unref (options);
}
@@ -734,12 +764,15 @@ stc_monitor_load_all_files (StcMonitor *monitor)
GList *ret;
GDir *dir;
guint n;
+ guint m;
GHashTable *id_to_item;
GList *l;
+ GList *ll;
GPtrArray *paths;
+ const gchar *const *deps;
ret = NULL;
- /* hash used to weed out duplicates */
+ /* hash used to weed out duplicates and check deps */
id_to_item = g_hash_table_new (g_str_hash, g_str_equal);
paths = g_ptr_array_new ();
@@ -774,8 +807,7 @@ stc_monitor_load_all_files (StcMonitor *monitor)
for (n = 0; n < paths->len; n++)
{
- path = paths->pdata[n];
- loaded_items = stc_monitor_load_one_file_emit_error (monitor, path);
+ loaded_items = stc_monitor_load_one_file_emit_error (monitor, paths->pdata[n]);
for (l = loaded_items; l != NULL; l = l->next)
{
StcItem *item;
@@ -787,8 +819,8 @@ stc_monitor_load_all_files (StcMonitor *monitor)
if ((duplicate_item = g_hash_table_lookup (id_to_item, id)) != NULL)
{
stc_monitor_emit_stc_error (monitor,
- path,
- -1,
+ _stc_item_get_path (item),
+ _stc_item_get_line_no (item),
STC_ERROR_DUPLICATE_ITEM,
"Encountered item with duplicate id `%s'. Ignoring previous items.",
id);
@@ -802,6 +834,38 @@ stc_monitor_load_all_files (StcMonitor *monitor)
g_ptr_array_foreach (paths, (GFunc) g_free, NULL);
g_ptr_array_free (paths, TRUE);
+ /* warn if dependencies does not check out */
+ for (l = ret; l != NULL; l = ll)
+ {
+ StcItem *item;
+ const gchar *id;
+
+ ll = l->next;
+
+ item = STC_ITEM (l->data);
+ id = stc_item_get_id (item);
+
+ deps = stc_item_get_dependencies (item);
+ for (m = 0; deps != NULL && deps[m] != NULL; m++)
+ {
+ const gchar *dep_id = deps[m];
+ StcItem *dep_item;
+
+ dep_item = g_hash_table_lookup (id_to_item, dep_id);
+ if (dep_item == NULL)
+ {
+ stc_monitor_emit_stc_error (monitor,
+ _stc_item_get_path (item),
+ _stc_item_get_line_no (item),
+ STC_ERROR_UNRESOLVED_DEPENDENCY,
+ "Item %s has unresolved dependency %s.",
+ id,
+ dep_id);
+ /* don't remove the item */
+ }
+ }
+ }
+
g_hash_table_unref (id_to_item);
ret = g_list_reverse (ret);
diff --git a/stc/stcmonitor.h b/stc/stcmonitor.h
index c2599ed..66057d0 100644
--- a/stc/stcmonitor.h
+++ b/stc/stcmonitor.h
@@ -64,6 +64,8 @@ StcMonitor *stc_monitor_new_for_config_dir (const gchar *config_dir,
gpointer error_handler_user_data);
const gchar *stc_monitor_get_config_dir (StcMonitor *monitor);
GList *stc_monitor_get_items (StcMonitor *monitor);
+StcItem *stc_monitor_get_item_by_id (StcMonitor *monitor,
+ const gchar *item_id);
G_END_DECLS
diff --git a/stc/stcprivate.h b/stc/stcprivate.h
index f56021b..0e100ac 100644
--- a/stc/stcprivate.h
+++ b/stc/stcprivate.h
@@ -32,14 +32,19 @@
G_BEGIN_DECLS
-StcItem *_stc_item_new (StcItemType type,
- const gchar *id,
- const gchar *target,
- const gchar *nick_name,
- GHashTable *options,
- const gchar *sort_key);
+StcItem *_stc_item_new (StcItemType type,
+ const gchar *id,
+ const gchar *target,
+ const gchar *nick_name,
+ GHashTable *options,
+ const gchar *const *depends,
+ const gchar *sort_key,
+ const gchar *path,
+ gint line_no);
const gchar *_stc_item_get_sort_key (StcItem *item);
+const gchar *_stc_item_get_path (StcItem *item);
+gint _stc_item_get_line_no (StcItem *item);
gboolean _stc_item_update (StcItem *item, StcItem *other);
diff --git a/stc/test.c b/stc/test.c
index 9144bc8..68b4ebe 100644
--- a/stc/test.c
+++ b/stc/test.c
@@ -60,15 +60,17 @@ static void item_append_str (StcItem *item,
GString *str)
{
const gchar* const *keys;
+ const gchar* const *deps;
keys = stc_item_get_option_keys (item);
+ deps = stc_item_get_dependencies (item);
g_string_append_printf (str,
- "id `%s'\n"
- "target `%s'\n"
- "nick-name `%s'\n"
- "type %s\n"
- "options ",
+ "id `%s'\n"
+ "target `%s'\n"
+ "nick-name `%s'\n"
+ "type %s\n"
+ "options ",
stc_item_get_id (item) != NULL ? stc_item_get_id (item) : "(none)",
stc_item_get_target (item) != NULL ? stc_item_get_target (item) : "(none)",
stc_item_get_nick_name (item) != NULL ? stc_item_get_nick_name (item) : "(none)",
@@ -85,13 +87,31 @@ static void item_append_str (StcItem *item,
{
const gchar *value;
if (n > 0)
- g_string_append (str, "\n ");
+ g_string_append (str, "\n ");
value = stc_item_get_option (item, keys[n]);
g_string_append_printf (str, "%s -> `%s'", keys[n], value);
}
}
g_string_append (str, "\n");
+ g_string_append (str,
+ "dependencies ");
+ if (deps == NULL || g_strv_length ((gchar **) deps) == 0)
+ {
+ g_string_append (str, "(none)");
+ }
+ else
+ {
+ guint n;
+ for (n = 0; deps[n] != NULL; n++)
+ {
+ if (n > 0)
+ g_string_append (str, "\n ");
+ g_string_append (str, deps[n]);
+ }
+ }
+ g_string_append (str, "\n");
+
g_string_append (str, "\n");
}
@@ -168,7 +188,9 @@ test_stc_semi_valid_conf (void)
SRCDIR "/testdata/semi_valid_conf/stc.conf: Error parsing group name `Filesystem with space' (stc-error-quark, 1)\n"
SRCDIR "/testdata/semi_valid_conf/stc.conf: Element 0 of Options, `foo', for item foo of type MDRaid is malformed (no equal sign found). (stc-error-quark, 1)\n"
SRCDIR "/testdata/semi_valid_conf/stc.conf.d/91.conf: Encountered item with duplicate id `multiple_instances_same_id'. Ignoring previous items. (stc-error-quark, 2)\n"
+ SRCDIR "/testdata/semi_valid_conf/stc.conf: Item ZItemWithUnresolved has unresolved dependency NonExisting. (stc-error-quark, 3)\n"
);
+
str2 = g_string_new (NULL);
items = stc_monitor_get_items (monitor);
for (l = items; l != NULL; l = l->next)
@@ -177,55 +199,71 @@ test_stc_semi_valid_conf (void)
item_append_str (item, str2);
}
g_assert_cmpstr (str2->str, ==,
- "id `in_pri_10'\n"
- "target `Device=/dev/sda'\n"
- "nick-name `(none)'\n"
- "type filesystem\n"
- "options (none)\n"
+ "id `in_pri_10'\n"
+ "target `Device=/dev/sda'\n"
+ "nick-name `(none)'\n"
+ "type filesystem\n"
+ "options (none)\n"
+ "dependencies (none)\n"
+ "\n"
+ "id `in_pri_50'\n"
+ "target `Device=/dev/sda'\n"
+ "nick-name `(none)'\n"
+ "type filesystem\n"
+ "options (none)\n"
+ "dependencies (none)\n"
"\n"
- "id `in_pri_50'\n"
- "target `Device=/dev/sda'\n"
- "nick-name `(none)'\n"
- "type filesystem\n"
- "options (none)\n"
+ "id `in_pri_90'\n"
+ "target `Device=/dev/sda'\n"
+ "nick-name `(none)'\n"
+ "type filesystem\n"
+ "options (none)\n"
+ "dependencies (none)\n"
"\n"
- "id `in_pri_90'\n"
- "target `Device=/dev/sda'\n"
- "nick-name `(none)'\n"
- "type filesystem\n"
- "options (none)\n"
+ "id `multiple_instances_same_id'\n"
+ "target `Device=/dev/multiple_instances_same_id/second'\n"
+ "nick-name `(none)'\n"
+ "type filesystem\n"
+ "options (none)\n"
+ "dependencies (none)\n"
"\n"
- "id `multiple_instances_same_id'\n"
- "target `Device=/dev/multiple_instances_same_id/second'\n"
- "nick-name `(none)'\n"
- "type filesystem\n"
- "options (none)\n"
+ "id `BigStorage'\n"
+ "target `Device=/dev/disk/md-uuid-01234:56789'\n"
+ "nick-name `BigStorage'\n"
+ "type filesystem\n"
+ "options (none)\n"
+ "dependencies BigStorage_mdraid\n"
"\n"
- "id `BigStorage'\n"
- "target `Device=/dev/disk/md-uuid-01234:56789'\n"
- "nick-name `BigStorage'\n"
- "type filesystem\n"
- "options (none)\n"
+ "id `BigStorage_mdraid'\n"
+ "target `UUID=01234:56789'\n"
+ "nick-name `BigStorage RAID Array'\n"
+ "type md-raid\n"
+ "options (none)\n"
+ "dependencies (none)\n"
"\n"
- "id `BigStorage_mdraid'\n"
- "target `UUID=01234:56789'\n"
- "nick-name `BigStorage RAID Array'\n"
- "type md-raid\n"
- "options (none)\n"
+ "id `SekritStuff'\n"
+ "target `Device=/dev/disk/by-uuid/1234'\n"
+ "nick-name `My Secret Stuff'\n"
+ "type filesystem\n"
+ "options Filesystem:mount_path -> `/mnt/SekritStuff'\n"
+ " Filesystem:options -> `noatime,dirsync'\n"
+ "dependencies SekritStuff_LUKS\n"
"\n"
- "id `SekritStuff'\n"
- "target `Device=/dev/disk/by-uuid/1234'\n"
- "nick-name `My Secret Stuff'\n"
- "type filesystem\n"
- "options Filesystem:mount_path -> `/mnt/SekritStuff'\n"
- " Filesystem:options -> `noatime,dirsync'\n"
+ "id `SekritStuff_LUKS'\n"
+ "target `Device=/dev/disk/by-uuid/12345'\n"
+ "nick-name `My Secret Stuff (Encrypted)'\n"
+ "type luks\n"
+ "options LUKS:password -> `xyz123'\n"
+ "dependencies (none)\n"
"\n"
- "id `SekritStuff_LUKS'\n"
- "target `Device=/dev/disk/by-uuid/12345'\n"
- "nick-name `My Secret Stuff (Encrypted)'\n"
- "type luks\n"
- "options LUKS:password -> `xyz123'\n"
- "\n");
+ "id `ZItemWithUnresolved'\n"
+ "target `Device=/dev/sda'\n"
+ "nick-name `(none)'\n"
+ "type filesystem\n"
+ "options (none)\n"
+ "dependencies NonExisting\n"
+ "\n"
+ );
g_string_free (str2, TRUE);
g_object_unref (monitor);
diff --git a/stc/testdata/semi_valid_conf/stc.conf b/stc/testdata/semi_valid_conf/stc.conf
index acfcd9b..a99a2d2 100644
--- a/stc/testdata/semi_valid_conf/stc.conf
+++ b/stc/testdata/semi_valid_conf/stc.conf
@@ -23,6 +23,10 @@ NickName=My Secret Stuff (Encrypted)
Device=/dev/disk/by-uuid/12345
Options=LUKS:password=xyz123
+[Filesystem ZItemWithUnresolved]
+Device=/dev/sda
+Depends=NonExisting
+
# ...and that we reject invalid items
#