aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/include/service.h11
-rw-r--r--lib/src/delsvc.c3
-rw-r--r--lib/src/rdsvc.c22
-rw-r--r--lib/src/svc_tsort.c21
-rw-r--r--servicecmd/list.c21
5 files changed, 42 insertions, 36 deletions
diff --git a/lib/include/service.h b/lib/include/service.h
index fee3ea3..471ccbb 100644
--- a/lib/include/service.h
+++ b/lib/include/service.h
@@ -62,14 +62,11 @@ typedef struct service_t {
/* linked list of command lines to execute */
exec_t *exec;
- /* NULL terminated array of services that must be executed later */
- char **before;
+ char *before; /* services that must be executed later */
+ char *after; /* services that must be executed first */
- /* NULL terminated array of services that must be executed first */
- char **after;
-
- char *raw_before; /* backing store for 'before' contents */
- char *raw_after; /* backing store for 'after' contents */
+ int num_before;
+ int num_after;
pid_t pid;
int status; /* process exit status */
diff --git a/lib/src/delsvc.c b/lib/src/delsvc.c
index d13c97f..f4f9c76 100644
--- a/lib/src/delsvc.c
+++ b/lib/src/delsvc.c
@@ -34,9 +34,6 @@ void delsvc(service_t *svc)
free(e);
}
- free(svc->raw_before);
- free(svc->raw_after);
-
free(svc->before);
free(svc->after);
free(svc->desc);
diff --git a/lib/src/rdsvc.c b/lib/src/rdsvc.c
index 4b87312..c8ba590 100644
--- a/lib/src/rdsvc.c
+++ b/lib/src/rdsvc.c
@@ -122,13 +122,16 @@ static int svc_before(service_t *svc, char *arg, rdline_t *rd)
return -1;
}
- svc->raw_before = try_strdup(arg, rd);
- if (svc->raw_before == NULL)
+ svc->before = try_strdup(arg, rd);
+ if (svc->before == NULL)
return -1;
- svc->before = try_split_argv(svc->raw_before, rd);
- if (svc->before == NULL)
+ svc->num_before = pack_argv(svc->before);
+ if (svc->num_before < 0) {
+ fprintf(stderr, "%s: %zu: malformed string constant\n",
+ rd->filename, rd->lineno);
return -1;
+ }
return 0;
}
@@ -141,13 +144,16 @@ static int svc_after(service_t *svc, char *arg, rdline_t *rd)
return -1;
}
- svc->raw_after = try_strdup(arg, rd);
- if (svc->raw_after == NULL)
+ svc->after = try_strdup(arg, rd);
+ if (svc->after == NULL)
return -1;
- svc->after = try_split_argv(svc->raw_after, rd);
- if (svc->after == NULL)
+ svc->num_after = pack_argv(svc->after);
+ if (svc->num_after < 0) {
+ fprintf(stderr, "%s: %zu: malformed string constant\n",
+ rd->filename, rd->lineno);
return -1;
+ }
return 0;
}
diff --git a/lib/src/svc_tsort.c b/lib/src/svc_tsort.c
index dcd1b4c..5f83fa0 100644
--- a/lib/src/svc_tsort.c
+++ b/lib/src/svc_tsort.c
@@ -24,21 +24,20 @@
static bool has_dependencies(service_t *list, service_t *svc)
{
- size_t i;
+ const char *ptr;
+ int i;
while (list != NULL) {
- if (svc->after != NULL) {
- for (i = 0; svc->after[i] != NULL; ++i) {
- if (!strcmp(svc->after[i], list->name))
- return true;
- }
+ for (ptr = svc->after, i = 0; i < svc->num_after; ++i) {
+ if (!strcmp(ptr, list->name))
+ return true;
+ ptr += strlen(ptr) + 1;
}
- if (list->before != NULL) {
- for (i = 0; list->before[i] != NULL; ++i) {
- if (!strcmp(list->before[i], svc->name))
- return true;
- }
+ for (ptr = list->before, i = 0; i < list->num_before; ++i) {
+ if (!strcmp(ptr, svc->name))
+ return true;
+ ptr += strlen(ptr) + 1;
}
list = list->next;
diff --git a/servicecmd/list.c b/servicecmd/list.c
index 404bddc..b9e342a 100644
--- a/servicecmd/list.c
+++ b/servicecmd/list.c
@@ -21,7 +21,8 @@
static void print_services(service_t *svc)
{
- size_t i;
+ const char *ptr;
+ int i;
for (; svc != NULL; svc = svc->next) {
printf("Name: %s\n", svc->name);
@@ -32,18 +33,24 @@ static void print_services(service_t *svc)
if (svc->type == SVC_RESPAWN && svc->rspwn_limit > 0)
printf("\tRespawn limit: %d\n", svc->rspwn_limit);
- if (svc->before != NULL) {
+ ptr = svc->before;
+ if (ptr != NULL && svc->num_before > 0) {
fputs("\tMust be run before:\n", stdout);
- for (i = 0; svc->before[i] != NULL; ++i)
- printf("\t\t%s\n", svc->before[i]);
+ for (i = 0; i < svc->num_before; ++i) {
+ printf("\t\t%s\n", ptr);
+ ptr += strlen(ptr) + 1;
+ }
}
- if (svc->after != NULL) {
+ ptr = svc->after;
+ if (ptr != NULL && svc->num_after > 0) {
fputs("\tMust be run after:\n", stdout);
- for (i = 0; svc->after[i] != NULL; ++i)
- printf("\t\t%s\n", svc->after[i]);
+ for (i = 0; i < svc->num_after; ++i) {
+ printf("\t\t%s\n", ptr);
+ ptr += strlen(ptr) + 1;
+ }
}
}
}