herdd: support updated service config layout

This commit is contained in:
2026-05-31 17:27:55 +01:00
parent a4ca7058d1
commit 4b917550f4
2 changed files with 21 additions and 11 deletions
+18 -10
View File
@@ -9,7 +9,6 @@
#include <fx/string.h>
#include <fx/stringstream.h>
#include <launch.h>
#include <magenta/log.h>
#include <rosetta/bootstrap.h>
#include <spawn.h>
#include <stdio.h>
@@ -53,11 +52,11 @@ static int parse_service_data(fx_object *in, struct service *out)
fx_value_get_object(description_v, &description);
const fx_value *exec_v = fx_hashtable_get(in_service, &FX_CSTR("exec"));
if (!exec_v || !fx_value_is_type(exec_v, FX_TYPE_STRING)) {
if (exec_v && !fx_value_is_type(exec_v, FX_TYPE_ARRAY)) {
return -1;
}
fx_string *exec = NULL;
fx_value_get_object(exec_v, &exec);
fx_value_get_object(exec_v, &out->s_exec);
fx_object_ref(out->s_exec);
const fx_value *roles_v
= fx_hashtable_get(in_service, &FX_CSTR("roles"));
@@ -95,7 +94,6 @@ static int parse_service_data(fx_object *in, struct service *out)
fx_iterator_unref(it);
out->s_description = fx_string_steal(description);
out->s_exec = fx_string_steal(exec);
return 0;
}
@@ -170,12 +168,22 @@ int service_start(struct service *svc)
log("Starting %s...", svc->s_description);
pid_t child = 0;
char *const argv[] = {
svc->s_name,
NULL,
};
size_t nr_args = fx_array_get_size(svc->s_exec);
int err = posix_spawn(&child, svc->s_exec, NULL, NULL, argv, NULL);
const char **argv = calloc(nr_args + 1, sizeof *argv);
for (size_t i = 0; i < nr_args; i++) {
const fx_value *str = fx_array_get_ref(svc->s_exec, i);
fx_value_get_cstr(str, &argv[i]);
}
int err = posix_spawn(
&child,
argv[0],
NULL,
NULL,
(char *const *)argv,
NULL);
free(argv);
if (err == 0) {
log_ok("Started %s.", svc->s_description);
+3 -1
View File
@@ -3,6 +3,8 @@
#include "queue.h"
#include <fx/collections/array.h>
enum service_role {
SVC_ROLE_NONE = 0x00u,
SVC_ROLE_NAMESPACE_PROVIDER = 0x01u,
@@ -11,7 +13,7 @@ enum service_role {
struct service {
char *s_name;
char *s_description;
char *s_exec;
fx_array *s_exec;
enum service_role s_roles;
struct queue_entry s_entry;
};