herdd: support updated service config layout
This commit is contained in:
+18
-10
@@ -9,7 +9,6 @@
|
|||||||
#include <fx/string.h>
|
#include <fx/string.h>
|
||||||
#include <fx/stringstream.h>
|
#include <fx/stringstream.h>
|
||||||
#include <launch.h>
|
#include <launch.h>
|
||||||
#include <magenta/log.h>
|
|
||||||
#include <rosetta/bootstrap.h>
|
#include <rosetta/bootstrap.h>
|
||||||
#include <spawn.h>
|
#include <spawn.h>
|
||||||
#include <stdio.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);
|
fx_value_get_object(description_v, &description);
|
||||||
|
|
||||||
const fx_value *exec_v = fx_hashtable_get(in_service, &FX_CSTR("exec"));
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
fx_string *exec = NULL;
|
fx_value_get_object(exec_v, &out->s_exec);
|
||||||
fx_value_get_object(exec_v, &exec);
|
fx_object_ref(out->s_exec);
|
||||||
|
|
||||||
const fx_value *roles_v
|
const fx_value *roles_v
|
||||||
= fx_hashtable_get(in_service, &FX_CSTR("roles"));
|
= 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);
|
fx_iterator_unref(it);
|
||||||
|
|
||||||
out->s_description = fx_string_steal(description);
|
out->s_description = fx_string_steal(description);
|
||||||
out->s_exec = fx_string_steal(exec);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -170,12 +168,22 @@ int service_start(struct service *svc)
|
|||||||
log("Starting %s...", svc->s_description);
|
log("Starting %s...", svc->s_description);
|
||||||
|
|
||||||
pid_t child = 0;
|
pid_t child = 0;
|
||||||
char *const argv[] = {
|
size_t nr_args = fx_array_get_size(svc->s_exec);
|
||||||
svc->s_name,
|
|
||||||
NULL,
|
|
||||||
};
|
|
||||||
|
|
||||||
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) {
|
if (err == 0) {
|
||||||
log_ok("Started %s.", svc->s_description);
|
log_ok("Started %s.", svc->s_description);
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
|
|
||||||
|
#include <fx/collections/array.h>
|
||||||
|
|
||||||
enum service_role {
|
enum service_role {
|
||||||
SVC_ROLE_NONE = 0x00u,
|
SVC_ROLE_NONE = 0x00u,
|
||||||
SVC_ROLE_NAMESPACE_PROVIDER = 0x01u,
|
SVC_ROLE_NAMESPACE_PROVIDER = 0x01u,
|
||||||
@@ -11,7 +13,7 @@ enum service_role {
|
|||||||
struct service {
|
struct service {
|
||||||
char *s_name;
|
char *s_name;
|
||||||
char *s_description;
|
char *s_description;
|
||||||
char *s_exec;
|
fx_array *s_exec;
|
||||||
enum service_role s_roles;
|
enum service_role s_roles;
|
||||||
struct queue_entry s_entry;
|
struct queue_entry s_entry;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user