herdd: rename runlevels to targets

This commit is contained in:
2026-05-30 19:47:49 +01:00
parent 97facbed6f
commit 277d87adb0
6 changed files with 74 additions and 77 deletions
+11 -17
View File
@@ -43,13 +43,6 @@ static int parse_service_data(fx_object *in, struct service *out)
fx_hashtable *in_unit = NULL;
fx_value_get_object(unit_v, &in_unit);
const fx_value *name_v = fx_hashtable_get(in_unit, &FX_CSTR("name"));
if (!name_v || !fx_value_is_type(name_v, FX_TYPE_STRING)) {
return -1;
}
fx_string *name = NULL;
fx_value_get_object(name_v, &name);
const fx_value *description_v
= fx_hashtable_get(in_unit, &FX_CSTR("description"));
if (!description_v
@@ -101,24 +94,23 @@ static int parse_service_data(fx_object *in, struct service *out)
}
fx_iterator_unref(it);
out->s_name = fx_string_steal(name);
out->s_description = fx_string_steal(description);
out->s_exec = fx_string_steal(exec);
return 0;
}
int service_load(const char *path, struct service **out)
int service_load(const char *name, const char *path, struct service **out)
{
struct service *rl = malloc(sizeof *rl);
if (!rl) {
struct service *svc = malloc(sizeof *svc);
if (!svc) {
errno = ENOMEM;
return -1;
}
FILE *fp = fopen(path, "r");
if (!fp) {
free(rl);
free(svc);
return -1;
}
@@ -128,30 +120,32 @@ int service_load(const char *path, struct service **out)
fx_result result = fx_serial_ctx_deserialise(ctx, in, &data, 0);
if (fx_result_is_error(result)) {
fx_throw(result);
free(rl);
free(svc);
errno = EFTYPE;
return -1;
}
if (!fx_value_is_type(&data, FX_TYPE_HASHTABLE)) {
fx_value_unset(&data);
free(rl);
free(svc);
errno = EFTYPE;
return -1;
}
if (parse_service_data(data.v_object, rl) != 0) {
free(rl);
if (parse_service_data(data.v_object, svc) != 0) {
free(svc);
errno = EFTYPE;
return -1;
}
svc->s_name = fx_strdup(name);
fx_stream_unref(in);
fx_value_unset(&data);
fclose(fp);
*out = rl;
*out = svc;
return 0;
}