aboutsummaryrefslogtreecommitdiff
path: root/src/comp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/comp.c')
-rw-r--r--src/comp.c110
1 files changed, 104 insertions, 6 deletions
diff --git a/src/comp.c b/src/comp.c
index 4d6c9f7..d823739 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -1,3 +1,3 @@
/* This file is part of GNU Pies.
- Copyright (C) 2016-2020 Sergey Poznyakoff
+ Copyright (C) 2016-2023 Sergey Poznyakoff
@@ -159,2 +159,3 @@ component_create (const char *name)
comp->socket_type = SOCK_STREAM;
+ comp->sigterm = SIGTERM;
component_append (comp);
@@ -220,4 +221,6 @@ argvcmp (char **a, char **b)
- if (!a != !b)
- return 1;
+ if (!a)
+ return !!b;
+ else if (!b)
+ return !!a;
@@ -273,4 +276,6 @@ component_match (struct component *comp, struct component *ref)
FN (program, safe_strcmp);
+ FN (command, safe_strcmp);
EQ (argc);
FN (argv, argvcmp);
+ FN (envop, envop_cmp);
FN (dir, safe_strcmp);
@@ -282,2 +287,3 @@ component_match (struct component *comp, struct component *ref)
FNP (privs, pies_privs_cmp);
+ EQ (umask);
FN (limits, limits_cmp);
@@ -480,2 +486,21 @@ component_build_depmap (void)
+/*
+ * Recursively increase shutdown sequence numbers for all prerequisites
+ * of the given component.
+ */
+static void
+compute_shutdown_sequence (struct component *comp)
+{
+ pies_depmap_pos_t pos;
+ struct component *dep;
+ for (dep = component_depmap_first (depmap_col, comp->arridx, &pos);
+ dep;
+ dep = component_depmap_next (pos))
+ {
+ dep->shutdown_seqno++;
+ compute_shutdown_sequence (dep);
+ }
+ depmap_end (pos);
+}
+
void
@@ -529,6 +554,79 @@ component_config_commit (void)
- /* Register new progs */
+ /* Register new progs and assign shutdown sequence numbers */
for (comp = comp_list[cur].head; comp; comp = comp->next)
- if (!comp->prog)
- register_prog (comp);
+ {
+ if (!comp->prog)
+ register_prog (comp);
+ compute_shutdown_sequence (comp);
+ }
+}
+
+static int
+shutdown_seqno_comp (void const *a, void const *b)
+{
+ struct component const *ca = *(struct component const **) a;
+ struct component const *cb = *(struct component const **) b;
+ if (ca->shutdown_seqno < cb->shutdown_seqno)
+ return -1;
+ else if (ca->shutdown_seqno > cb->shutdown_seqno)
+ return 1;
+ return 0;
+}
+
+/*
+ * Returns a list of components in shutdown sequence order.
+ */
+struct component **
+component_shutdown_list (void)
+{
+ struct component **a;
+ size_t i;
+
+ a = grecs_calloc (comp_count, sizeof (a[0]));
+ memcpy (a, comp_array, comp_count * sizeof (a[0]));
+ qsort (a, comp_count, sizeof (a[0]), shutdown_seqno_comp);
+ return a;
+}
+
+/*
+ * Prints on stdout the list of components in shutdown sequence
+ * order.
+ */
+void
+components_list_shutdown_sequence (void)
+{
+ struct component **a = component_shutdown_list ();
+ size_t i;
+
+ for (i = 0; i < comp_count; i++)
+ {
+ printf ("%lu: %s\n", a[i]->shutdown_seqno, a[i]->tag);
+ }
+ free (a);
+}
+
+/*
+ * Computes array if shutdown sequence numbers and stores it in RET.
+ * Returns number of elements in the computed array.
+ */
+size_t
+components_shutdown_sequence_numbers (unsigned long **ret)
+{
+ struct component **a = component_shutdown_list ();
+ unsigned long *idx = grecs_calloc (comp_count, sizeof (idx[0]));
+ size_t i;
+ size_t j;
+
+ for (i = j = 0; i < comp_count; i++)
+ {
+ unsigned long seqno = idx[i] = a[j]->shutdown_seqno;
+ while (a[j]->shutdown_seqno == seqno)
+ {
+ if (++j == comp_count)
+ goto end;
+ }
+ }
+ end:
+ *ret = idx;
+ return i + 1;
}

Return to:

Send suggestions and report system problems to the System administrator.