#include <libubox/avl-cmp.h>
#include "procd.h"
#include "service.h"
+#include "instance.h"
struct avl_tree services;
static struct blob_buf b;
static void
-service_instance_update(struct vlist_tree *tree, struct vlist_node *node_new,
- struct vlist_node *node_old)
-{
- struct service_instance *in_o = NULL, *in_n = NULL;
-
- if (node_old)
- in_o = container_of(node_old, struct service_instance, node);
-
- if (node_new)
- in_n = container_of(node_new, struct service_instance, node);
-
- do {
- if (!in_o || !in_n)
- break;
-
- /* full match, nothing to do */
- return;
- } while (0);
-
- if (in_o) {
- /* kill old process */
- free(in_o);
- }
-
- if (in_n) {
- /* start new process */
- }
-}
-
-static void
service_instance_add(struct service *s, struct blob_attr *attr)
{
struct service_instance *in;
if (!in)
return;
- in->config = attr;
+ instance_init(in, attr);
vlist_add(&s->instances, &in->node, (void *) name);
}
+static void
+service_instance_update(struct vlist_tree *tree, struct vlist_node *node_new,
+ struct vlist_node *node_old)
+{
+ struct service_instance *in_o = NULL, *in_n = NULL;
+
+ if (node_old)
+ in_o = container_of(node_old, struct service_instance, node);
+
+ if (node_new)
+ in_n = container_of(node_new, struct service_instance, node);
+
+ if (in_o && in_n) {
+ instance_update(in_o, in_n);
+ instance_free(in_n);
+ } else if (in_o) {
+ instance_stop(in_o, false);
+ instance_free(in_o);
+ } else if (in_n) {
+ instance_start(in_n);
+ }
+}
+
static struct service *
service_alloc(const char *name)
{
s = calloc(1, sizeof(*s));
vlist_init(&s->instances, avl_strcmp, service_instance_update);
+ s->instances.keep_old = true;
return s;
}