herdd: update kernel and fx usage
This commit is contained in:
@@ -3,7 +3,7 @@ add_executable(herdd ${sources})
|
|||||||
target_link_libraries(herdd
|
target_link_libraries(herdd
|
||||||
libc libc-runtime
|
libc libc-runtime
|
||||||
libmagenta libpthread liblaunch librosetta
|
libmagenta libpthread liblaunch librosetta
|
||||||
fx-core fx-ds fx-serial)
|
fx.runtime fx.collections fx.serial)
|
||||||
|
|
||||||
sysroot_add_program(
|
sysroot_add_program(
|
||||||
NAME herdd
|
NAME herdd
|
||||||
|
|||||||
@@ -6,9 +6,9 @@
|
|||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <fx/ds/string.h>
|
#include <fx/string.h>
|
||||||
#include <mango/log.h>
|
#include <magenta/log.h>
|
||||||
#include <mango/task.h>
|
#include <magenta/task.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|||||||
+43
-22
@@ -4,11 +4,12 @@
|
|||||||
#include "service.h"
|
#include "service.h"
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fx/core/stringstream.h>
|
#include <fx/collections/array.h>
|
||||||
#include <fx/ds/array.h>
|
#include <fx/collections/hashtable.h>
|
||||||
#include <fx/ds/dict.h>
|
|
||||||
#include <fx/serial.h>
|
#include <fx/serial.h>
|
||||||
#include <mango/log.h>
|
#include <fx/string.h>
|
||||||
|
#include <fx/stringstream.h>
|
||||||
|
#include <magenta/log.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -22,36 +23,48 @@ struct queue *global_runlevels(void)
|
|||||||
|
|
||||||
static int parse_runlevel_data(fx_object *in, struct runlevel *out)
|
static int parse_runlevel_data(fx_object *in, struct runlevel *out)
|
||||||
{
|
{
|
||||||
if (!fx_object_is_type(in, FX_TYPE_DICT)) {
|
if (!fx_object_is_type(in, FX_TYPE_HASHTABLE)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fx_dict *in_runlevel = fx_dict_at(in, "runlevel");
|
const fx_value *runlevel_v = fx_hashtable_get(in, &FX_CSTR("runlevel"));
|
||||||
if (!in_runlevel || !fx_object_is_type(in_runlevel, FX_TYPE_DICT)) {
|
if (!runlevel_v || !fx_value_is_type(runlevel_v, FX_TYPE_HASHTABLE)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
fx_hashtable *in_runlevel = NULL;
|
||||||
|
fx_value_get_object(runlevel_v, &in_runlevel);
|
||||||
|
|
||||||
fx_string *name = fx_dict_at(in_runlevel, "name");
|
const fx_value *name_v
|
||||||
if (!name || !fx_object_is_type(name, FX_TYPE_STRING)) {
|
= fx_hashtable_get(in_runlevel, &FX_CSTR("name"));
|
||||||
|
if (!name_v || !fx_value_is_type(name_v, FX_TYPE_STRING)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
fx_string *name = NULL;
|
||||||
|
fx_value_get_object(name_v, &name);
|
||||||
|
|
||||||
fx_string *description = fx_dict_at(in_runlevel, "description");
|
const fx_value *description_v
|
||||||
if (!description || !fx_object_is_type(description, FX_TYPE_STRING)) {
|
= fx_hashtable_get(in_runlevel, &FX_CSTR("description"));
|
||||||
|
if (!description_v
|
||||||
|
|| !fx_value_is_type(description_v, FX_TYPE_STRING)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
fx_string *description = NULL;
|
||||||
|
fx_value_get_object(description_v, &description);
|
||||||
|
|
||||||
fx_array *deps = fx_dict_at(in_runlevel, "requires");
|
const fx_value *deps_v
|
||||||
if (deps && !fx_object_is_type(deps, FX_TYPE_ARRAY)) {
|
= fx_hashtable_get(in_runlevel, &FX_CSTR("requires"));
|
||||||
|
if (deps_v && !fx_value_is_type(deps_v, FX_TYPE_ARRAY)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
fx_array *deps = NULL;
|
||||||
|
fx_value_get_object(deps_v, &deps);
|
||||||
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
size_t dep_count = fx_array_size(deps);
|
size_t dep_count = fx_array_get_size(deps);
|
||||||
fx_iterator *it = fx_iterator_begin(deps);
|
const fx_iterator *it = fx_iterator_begin(deps);
|
||||||
fx_foreach_ptr(fx_string, dep, it)
|
fx_foreach(dep, it)
|
||||||
{
|
{
|
||||||
if (!fx_object_is_type(dep, FX_TYPE_STRING)) {
|
if (!fx_value_is_type(dep, FX_TYPE_STRING)) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -66,9 +79,11 @@ static int parse_runlevel_data(fx_object *in, struct runlevel *out)
|
|||||||
out->rl_requires = calloc(dep_count, sizeof(char *));
|
out->rl_requires = calloc(dep_count, sizeof(char *));
|
||||||
it = fx_iterator_begin(deps);
|
it = fx_iterator_begin(deps);
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
fx_foreach_ptr(fx_string, dep, it)
|
fx_foreach(dep, it)
|
||||||
{
|
{
|
||||||
out->rl_requires[i++] = fx_string_steal(dep);
|
fx_string *str = NULL;
|
||||||
|
fx_value_get_object(dep, &str);
|
||||||
|
out->rl_requires[i++] = fx_string_steal(str);
|
||||||
}
|
}
|
||||||
fx_iterator_unref(it);
|
fx_iterator_unref(it);
|
||||||
|
|
||||||
@@ -94,7 +109,7 @@ int runlevel_load(const char *path, struct runlevel **out)
|
|||||||
|
|
||||||
fx_stream *in = fx_stream_open_fp(fp);
|
fx_stream *in = fx_stream_open_fp(fp);
|
||||||
fx_serial_ctx *ctx = fx_toml_serial_ctx_create();
|
fx_serial_ctx *ctx = fx_toml_serial_ctx_create();
|
||||||
fx_object *data;
|
fx_value data;
|
||||||
fx_result result = fx_serial_ctx_deserialise(ctx, in, &data, 0);
|
fx_result result = fx_serial_ctx_deserialise(ctx, in, &data, 0);
|
||||||
if (fx_result_is_error(result)) {
|
if (fx_result_is_error(result)) {
|
||||||
fx_throw(result);
|
fx_throw(result);
|
||||||
@@ -103,14 +118,20 @@ int runlevel_load(const char *path, struct runlevel **out)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parse_runlevel_data(data, rl) != 0) {
|
if (!fx_value_is_type(&data, FX_TYPE_HASHTABLE)) {
|
||||||
|
free(rl);
|
||||||
|
errno = EFTYPE;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parse_runlevel_data(data.v_object, rl) != 0) {
|
||||||
free(rl);
|
free(rl);
|
||||||
errno = EFTYPE;
|
errno = EFTYPE;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fx_stream_unref(in);
|
fx_stream_unref(in);
|
||||||
fx_object_unref(data);
|
fx_value_unset(&data);
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
|
|||||||
+49
-25
@@ -3,12 +3,13 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fx/core/stringstream.h>
|
#include <fx/collections/array.h>
|
||||||
#include <fx/ds/array.h>
|
#include <fx/collections/hashtable.h>
|
||||||
#include <fx/ds/dict.h>
|
|
||||||
#include <fx/serial.h>
|
#include <fx/serial.h>
|
||||||
|
#include <fx/string.h>
|
||||||
|
#include <fx/stringstream.h>
|
||||||
#include <launch.h>
|
#include <launch.h>
|
||||||
#include <mango/log.h>
|
#include <magenta/log.h>
|
||||||
#include <rosetta/bootstrap.h>
|
#include <rosetta/bootstrap.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -23,45 +24,60 @@ struct queue *global_services(void)
|
|||||||
|
|
||||||
static int parse_service_data(fx_object *in, struct service *out)
|
static int parse_service_data(fx_object *in, struct service *out)
|
||||||
{
|
{
|
||||||
if (!fx_object_is_type(in, FX_TYPE_DICT)) {
|
if (!fx_object_is_type(in, FX_TYPE_HASHTABLE)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fx_dict *in_service = fx_dict_at(in, "service");
|
const fx_value *service_v = fx_hashtable_get(in, &FX_CSTR("service"));
|
||||||
if (!in_service || !fx_object_is_type(in_service, FX_TYPE_DICT)) {
|
if (!service_v || !fx_value_is_type(service_v, FX_TYPE_HASHTABLE)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
fx_hashtable *in_service = NULL;
|
||||||
|
fx_value_get_object(service_v, &in_service);
|
||||||
|
|
||||||
fx_dict *in_unit = fx_dict_at(in, "unit");
|
const fx_value *unit_v = fx_hashtable_get(in, &FX_CSTR("unit"));
|
||||||
if (!in_unit || !fx_object_is_type(in_unit, FX_TYPE_DICT)) {
|
if (!unit_v || !fx_value_is_type(unit_v, FX_TYPE_HASHTABLE)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
fx_hashtable *in_unit = NULL;
|
||||||
|
fx_value_get_object(unit_v, &in_unit);
|
||||||
|
|
||||||
fx_string *name = fx_dict_at(in_unit, "name");
|
const fx_value *name_v = fx_hashtable_get(in_unit, &FX_CSTR("name"));
|
||||||
if (!name || !fx_object_is_type(name, FX_TYPE_STRING)) {
|
if (!name_v || !fx_value_is_type(name_v, FX_TYPE_STRING)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
fx_string *name = NULL;
|
||||||
|
fx_value_get_object(name_v, &name);
|
||||||
|
|
||||||
fx_string *description = fx_dict_at(in_unit, "description");
|
const fx_value *description_v
|
||||||
if (!description || !fx_object_is_type(description, FX_TYPE_STRING)) {
|
= fx_hashtable_get(in_unit, &FX_CSTR("description"));
|
||||||
|
if (!description_v
|
||||||
|
|| !fx_value_is_type(description_v, FX_TYPE_STRING)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
fx_string *description = NULL;
|
||||||
|
fx_value_get_object(description_v, &description);
|
||||||
|
|
||||||
fx_string *exec = fx_dict_at(in_service, "exec");
|
const fx_value *exec_v = fx_hashtable_get(in_service, &FX_CSTR("exec"));
|
||||||
if (!description || !fx_object_is_type(description, FX_TYPE_STRING)) {
|
if (!exec_v || !fx_value_is_type(exec_v, FX_TYPE_STRING)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
fx_string *exec = NULL;
|
||||||
|
fx_value_get_object(exec_v, &exec);
|
||||||
|
|
||||||
fx_array *roles = fx_dict_at(in_service, "roles");
|
const fx_value *roles_v
|
||||||
if (roles && !fx_object_is_type(roles, FX_TYPE_ARRAY)) {
|
= fx_hashtable_get(in_service, &FX_CSTR("roles"));
|
||||||
|
if (roles_v && !fx_value_is_type(roles_v, FX_TYPE_ARRAY)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
fx_array *roles = NULL;
|
||||||
|
fx_value_get_object(roles_v, &roles);
|
||||||
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
fx_iterator *it = fx_iterator_begin(roles);
|
const fx_iterator *it = fx_iterator_begin(roles);
|
||||||
fx_foreach_ptr(fx_string, role, it)
|
fx_foreach(v, it)
|
||||||
{
|
{
|
||||||
if (!fx_object_is_type(role, FX_TYPE_STRING)) {
|
if (!fx_value_is_type(v, FX_TYPE_STRING)) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -74,9 +90,10 @@ static int parse_service_data(fx_object *in, struct service *out)
|
|||||||
|
|
||||||
it = fx_iterator_begin(roles);
|
it = fx_iterator_begin(roles);
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
fx_foreach_ptr(fx_string, role, it)
|
fx_foreach(role, it)
|
||||||
{
|
{
|
||||||
const char *role_cstr = fx_string_get_cstr(role);
|
const char *role_cstr = NULL;
|
||||||
|
fx_value_get_cstr(role, &role_cstr);
|
||||||
if (!strcmp(role_cstr, "NamespaceProvider")) {
|
if (!strcmp(role_cstr, "NamespaceProvider")) {
|
||||||
out->s_roles |= SVC_ROLE_NAMESPACE_PROVIDER;
|
out->s_roles |= SVC_ROLE_NAMESPACE_PROVIDER;
|
||||||
}
|
}
|
||||||
@@ -106,7 +123,7 @@ int service_load(const char *path, struct service **out)
|
|||||||
|
|
||||||
fx_stream *in = fx_stream_open_fp(fp);
|
fx_stream *in = fx_stream_open_fp(fp);
|
||||||
fx_serial_ctx *ctx = fx_toml_serial_ctx_create();
|
fx_serial_ctx *ctx = fx_toml_serial_ctx_create();
|
||||||
fx_object *data;
|
fx_value data;
|
||||||
fx_result result = fx_serial_ctx_deserialise(ctx, in, &data, 0);
|
fx_result result = fx_serial_ctx_deserialise(ctx, in, &data, 0);
|
||||||
if (fx_result_is_error(result)) {
|
if (fx_result_is_error(result)) {
|
||||||
fx_throw(result);
|
fx_throw(result);
|
||||||
@@ -115,14 +132,21 @@ int service_load(const char *path, struct service **out)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parse_service_data(data, rl) != 0) {
|
if (!fx_value_is_type(&data, FX_TYPE_HASHTABLE)) {
|
||||||
|
fx_value_unset(&data);
|
||||||
|
free(rl);
|
||||||
|
errno = EFTYPE;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parse_service_data(data.v_object, rl) != 0) {
|
||||||
free(rl);
|
free(rl);
|
||||||
errno = EFTYPE;
|
errno = EFTYPE;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fx_stream_unref(in);
|
fx_stream_unref(in);
|
||||||
fx_object_unref(data);
|
fx_value_unset(&data);
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define SERVICE_H_
|
#define SERVICE_H_
|
||||||
|
|
||||||
#include "queue.h"
|
#include "queue.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,
|
||||||
|
|||||||
Reference in New Issue
Block a user