1
0
Fork 0
mirror of https://github.com/pygos/init.git synced 2024-11-25 12:30:42 +01:00

Don't split dependencies into argument vector, keep list of strings

Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
This commit is contained in:
David Oberhollenzer 2018-04-11 16:07:20 +02:00
parent 4ee0ea9754
commit 71d98c150f
5 changed files with 44 additions and 38 deletions

View file

@ -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 */

View file

@ -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);

View file

@ -122,14 +122,17 @@ 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)
return -1;
svc->before = try_split_argv(svc->raw_before, rd);
svc->before = try_strdup(arg, rd);
if (svc->before == NULL)
return -1;
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,14 +144,17 @@ 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)
return -1;
svc->after = try_split_argv(svc->raw_after, rd);
svc->after = try_strdup(arg, rd);
if (svc->after == NULL)
return -1;
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;
}

View file

@ -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))
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))
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;

View file

@ -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;
}
}
}
}