aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2016-02-22 12:31:56 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2016-02-22 12:33:46 +0200
commitbfa3617a79292e3569587c65cd218b69bdfd28a2 (patch)
tree8b094ec15dbb50be7324b3aa2f0d7486146a04d3 /src
parenta9bd91de478ab29fa7bac2093479a1ccee1bbd87 (diff)
downloadpies-bfa3617a79292e3569587c65cd218b69bdfd28a2.tar.gz
pies-bfa3617a79292e3569587c65cd218b69bdfd28a2.tar.bz2
Provide a default single-user entry in init mode
This complements 6aac230c. The entry is created unless a component for runlevel S already exists. * src/comp.c (component_foreach): New function. * src/pies.h: Likewise. * src/sysvinit.c (inittab_parse): Provide default S entry unless one is already defined.
Diffstat (limited to 'src')
-rw-r--r--src/comp.c17
-rw-r--r--src/pies.h2
-rw-r--r--src/sysvinit.c14
3 files changed, 29 insertions, 4 deletions
diff --git a/src/comp.c b/src/comp.c
index 38e440e..43772c2 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -809,11 +809,28 @@ component_depmap_next (pies_depmap_pos_t pos)
{
size_t n = depmap_next (depmap, pos);
if (n == (size_t)-1)
return NULL;
return comp_array[n];
}
+
+int
+component_foreach (int (*filter) (struct component *, void *), void *data)
+{
+ struct component *comp;
+ int rc = 0;
+ struct complist *list = &comp_list[cur];
+
+ for (comp = list->head; comp; )
+ {
+ struct component *next = comp->next;
+ if ((rc = filter (comp, data)) != 0)
+ break;
+ comp = next;
+ }
+ return rc;
+}
diff --git a/src/pies.h b/src/pies.h
index 939bd4c..d4b5c6a 100644
--- a/src/pies.h
+++ b/src/pies.h
@@ -403,12 +403,14 @@ void component_config_rollback (void);
void component_config_commit (void);
int component_is_active (struct component *comp);
void component_finish (struct component *comp, grecs_locus_t *locus);
struct grecs_keyword *find_component_keyword (const char *ident);
+int component_foreach (int (*filter) (struct component *, void *),
+ void *data);
void components_dump_depmap (void);
void components_trace (char **argv, enum pies_depmap_direction dir);
struct component *component_depmap_first (enum pies_depmap_direction dir,
size_t idx, pies_depmap_pos_t *ppos);
diff --git a/src/sysvinit.c b/src/sysvinit.c
index 695a22a..cc26fa9 100644
--- a/src/sysvinit.c
+++ b/src/sysvinit.c
@@ -1089,12 +1089,19 @@ inittab_parse_line (struct inittab_ctx *ctx)
component_free (comp);
return inittab_err;
}
return inittab_ok;
}
+/* Return true if we hit a single-user component */
+static int
+is_single_user (struct component *comp, void *data)
+{
+ return is_sysvinit (comp) && comp->runlevels && strchr (comp->runlevels, 'S');
+}
+
int
inittab_parse (const char *file)
{
FILE *fp;
struct inittab_ctx ctx;
int err;
@@ -1122,19 +1129,18 @@ inittab_parse (const char *file)
logmsg (LOG_ERR,
_("cannot open configuration file %s: %s"),
file, strerror (errno));
err = 1;
}
- if (component_list_is_empty ())
+ if (!component_foreach (is_single_user, 0))
{
- /* Provide default inittab entry */
+ /* Provide single-user entry */
ctx.file = __FILE__;
ctx.line_no = __LINE__;
- grecs_asprintf (&ctx.buf, &ctx.size, "~~:%s:wait:%s\n",
- valid_runlevels, emergency_shell);
+ grecs_asprintf (&ctx.buf, &ctx.size, "~~:S:wait:%s\n", emergency_shell);
inittab_parse_line (&ctx);
}
free (ctx.buf);
return err;
}

Return to:

Send suggestions and report system problems to the System administrator.