summaryrefslogtreecommitdiffstats
path: root/service
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2015-11-28 14:58:01 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2015-11-30 09:53:36 +0100
commit13590ca98ac2fd4939b683adbfdd63392b559f3f (patch)
tree37a267d3ac4ca067fea1d2a1789c1a055ed7b707 /service
parent890ac34c460fbb753bd4303b201d11aebd27a570 (diff)
downloadunitd-13590ca98ac2fd4939b683adbfdd63392b559f3f.tar
unitd-13590ca98ac2fd4939b683adbfdd63392b559f3f.zip
Strip down procd to the necessary code, update copyright
Diffstat (limited to 'service')
-rw-r--r--service/instance.c1
-rw-r--r--service/instance.h1
-rw-r--r--service/service.c57
-rw-r--r--service/service.h17
-rw-r--r--service/setlbf.c6
-rw-r--r--service/trigger.c1
-rw-r--r--service/validate.c163
-rw-r--r--service/watch.c1
8 files changed, 6 insertions, 241 deletions
diff --git a/service/instance.c b/service/instance.c
index 40ff021..3c98ff7 100644
--- a/service/instance.c
+++ b/service/instance.c
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
* Copyright (C) 2013 John Crispin <blogic@openwrt.org>
+ * Copyright (C) 2015 Matthias Schiffer <mschiffer@universe-factory.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 2.1
diff --git a/service/instance.h b/service/instance.h
index 3fb33e9..cdf0bf7 100644
--- a/service/instance.h
+++ b/service/instance.h
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
* Copyright (C) 2013 John Crispin <blogic@openwrt.org>
+ * Copyright (C) 2015 Matthias Schiffer <mschiffer@universe-factory.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 2.1
diff --git a/service/service.c b/service/service.c
index 2702dc3..90f4d7c 100644
--- a/service/service.c
+++ b/service/service.c
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
* Copyright (C) 2013 John Crispin <blogic@openwrt.org>
+ * Copyright (C) 2015 Matthias Schiffer <mschiffer@universe-factory.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 2.1
@@ -83,7 +84,6 @@ service_alloc(const char *name)
s->instances.keep_old = true;
s->name = new_name;
s->avl.key = s->name;
- INIT_LIST_HEAD(&s->validators);
return s;
}
@@ -93,7 +93,6 @@ enum {
SERVICE_SET_SCRIPT,
SERVICE_SET_INSTANCES,
SERVICE_SET_TRIGGER,
- SERVICE_SET_VALIDATE,
__SERVICE_SET_MAX
};
@@ -102,7 +101,6 @@ static const struct blobmsg_policy service_set_attrs[__SERVICE_SET_MAX] = {
[SERVICE_SET_SCRIPT] = { "script", BLOBMSG_TYPE_STRING },
[SERVICE_SET_INSTANCES] = { "instances", BLOBMSG_TYPE_TABLE },
[SERVICE_SET_TRIGGER] = { "triggers", BLOBMSG_TYPE_ARRAY },
- [SERVICE_SET_VALIDATE] = { "validate", BLOBMSG_TYPE_ARRAY },
};
static int
@@ -117,8 +115,6 @@ service_update(struct service *s, struct blob_attr **tb, bool add)
s->trigger = NULL;
}
- service_validate_del(s);
-
if (tb[SERVICE_SET_TRIGGER] && blobmsg_data_len(tb[SERVICE_SET_TRIGGER])) {
s->trigger = blob_memdup(tb[SERVICE_SET_TRIGGER]);
if (!s->trigger)
@@ -126,11 +122,6 @@ service_update(struct service *s, struct blob_attr **tb, bool add)
trigger_add(s->trigger, s);
}
- if (tb[SERVICE_SET_VALIDATE] && blobmsg_data_len(tb[SERVICE_SET_VALIDATE])) {
- blobmsg_for_each_attr(cur, tb[SERVICE_SET_VALIDATE], rem)
- service_validate_add(s, cur);
- }
-
if (tb[SERVICE_SET_INSTANCES]) {
if (!add)
vlist_update(&s->instances);
@@ -155,7 +146,6 @@ service_delete(struct service *s)
trigger_del(s);
free(s->trigger);
free(s);
- service_validate_del(s);
}
enum {
@@ -201,19 +191,6 @@ static const struct blobmsg_policy event_policy[__EVENT_MAX] = {
};
enum {
- VALIDATE_PACKAGE,
- VALIDATE_TYPE,
- VALIDATE_SERVICE,
- __VALIDATE_MAX
-};
-
-static const struct blobmsg_policy validate_policy[__VALIDATE_MAX] = {
- [VALIDATE_PACKAGE] = { .name = "package", .type = BLOBMSG_TYPE_STRING },
- [VALIDATE_TYPE] = { .name = "type", .type = BLOBMSG_TYPE_STRING },
- [VALIDATE_SERVICE] = { .name = "service", .type = BLOBMSG_TYPE_STRING },
-};
-
-enum {
DATA_NAME,
DATA_INSTANCE,
DATA_TYPE,
@@ -282,8 +259,6 @@ service_dump(struct service *s, bool verbose)
}
if (verbose && s->trigger)
blobmsg_add_blob(&b, s->trigger);
- if (verbose && !list_empty(&s->validators))
- service_validate_dump(&b, s);
blobmsg_close_table(&b, c);
}
@@ -399,34 +374,6 @@ service_handle_event(struct ubus_context *ctx, struct ubus_object *obj,
}
static int
-service_handle_validate(struct ubus_context *ctx, struct ubus_object *obj,
- struct ubus_request_data *req, const char *method,
- struct blob_attr *msg)
-{
- struct blob_attr *tb[__VALIDATE_MAX];
- char *p = NULL, *t = NULL;
-
- if (!msg)
- return UBUS_STATUS_INVALID_ARGUMENT;
-
- blobmsg_parse(validate_policy, __VALIDATE_MAX, tb, blob_data(msg), blob_len(msg));
- if (tb[VALIDATE_SERVICE]) {
- return 0;
- }
- if (tb[VALIDATE_PACKAGE])
- p = blobmsg_get_string(tb[VALIDATE_PACKAGE]);
-
- if (tb[VALIDATE_TYPE])
- t = blobmsg_get_string(tb[VALIDATE_TYPE]);
-
- blob_buf_init(&b, 0);
- service_validate_dump_all(&b, p, t);
- ubus_send_reply(ctx, req, b.head);
-
- return 0;
-}
-
-static int
service_get_data(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method,
struct blob_attr *msg)
@@ -493,7 +440,6 @@ static struct ubus_method main_object_methods[] = {
UBUS_METHOD("update_start", service_handle_update, service_attrs),
UBUS_METHOD("update_complete", service_handle_update, service_attrs),
UBUS_METHOD("event", service_handle_event, event_policy),
- UBUS_METHOD("validate", service_handle_validate, validate_policy),
UBUS_METHOD("get_data", service_get_data, get_data_policy),
};
@@ -557,6 +503,5 @@ void
service_init(void)
{
avl_init(&services, avl_strcmp, false, NULL);
- service_validate_init();
}
diff --git a/service/service.h b/service/service.h
index 892a147..e346058 100644
--- a/service/service.h
+++ b/service/service.h
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
* Copyright (C) 2013 John Crispin <blogic@openwrt.org>
+ * Copyright (C) 2015 Matthias Schiffer <mschiffer@universe-factory.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 2.1
@@ -27,31 +28,15 @@ struct vrule {
char *rule;
};
-struct validate {
- struct avl_node avl;
- struct list_head list;
-
- char *package;
- char *type;
-
- struct avl_tree rules;
-};
-
struct service {
struct avl_node avl;
const char *name;
struct blob_attr *trigger;
struct vlist_tree instances;
- struct list_head validators;
};
-void service_validate_add(struct service *s, struct blob_attr *attr);
-void service_validate_dump(struct blob_buf *b, struct service *s);
-void service_validate_dump_all(struct blob_buf *b, char *p, char *s);
int service_start_early(char *name, char *cmdline);
-void service_validate_del(struct service *s);
-void service_validate_init(void);
void service_init(void);
void service_event(const char *type, const char *service, const char *instance);
diff --git a/service/setlbf.c b/service/setlbf.c
deleted file mode 100644
index 94c251e..0000000
--- a/service/setlbf.c
+++ /dev/null
@@ -1,6 +0,0 @@
-#include <stdio.h>
-
-static void __attribute__((constructor)) setlbf(void)
-{
- setbuf(stdout, NULL);
-}
diff --git a/service/trigger.c b/service/trigger.c
index 97a06bb..9c7115c 100644
--- a/service/trigger.c
+++ b/service/trigger.c
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
* Copyright (C) 2013 John Crispin <blogic@openwrt.org>
+ * Copyright (C) 2015 Matthias Schiffer <mschiffer@universe-factory.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 2.1
diff --git a/service/validate.c b/service/validate.c
deleted file mode 100644
index 6a449f4..0000000
--- a/service/validate.c
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 2.1
- * as published by the Free Software Foundation
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
-
-#include <libubox/blobmsg_json.h>
-#include <libubox/avl-cmp.h>
-#include <json-c/json.h>
-
-#include "../procd.h"
-
-#include "service.h"
-
-enum {
- SERVICE_VAL_PACKAGE,
- SERVICE_VAL_TYPE,
- SERVICE_VAL_DATA,
- __SERVICE_VAL_MAX
-};
-
-static const struct blobmsg_policy service_validate_attrs[__SERVICE_VAL_MAX] = {
- [SERVICE_VAL_PACKAGE] = { "package", BLOBMSG_TYPE_STRING },
- [SERVICE_VAL_TYPE] = { "type", BLOBMSG_TYPE_STRING },
- [SERVICE_VAL_DATA] = { "data", BLOBMSG_TYPE_TABLE },
-};
-
-static struct avl_tree validators;
-
-void
-service_validate_dump_all(struct blob_buf *b, char *p, char *s)
-{
- struct json_object *r = json_object_new_object();
- struct validate *v;
-
- if (!r)
- return;
-
- avl_for_each_element(&validators, v, avl) {
- struct json_object *o, *t;
- struct vrule *vr;
-
- if (p && strcmp(p, v->package))
- continue;
-
- if (s && strcmp(s, v->type))
- continue;
-
- json_object_object_get_ex(r, v->package, &o);
- if (!o) {
- o = json_object_new_object();
- json_object_object_add(r, v->package, o);
- }
- json_object_object_get_ex(o, v->type, &t);
- if (!t) {
- t = json_object_new_object();
- json_object_object_add(o, v->type, t);
- }
- avl_for_each_element(&v->rules, vr, avl)
- json_object_object_add(t, vr->option, json_object_new_string(vr->rule));
- }
- blobmsg_add_object(b, r);
- json_object_put(r);
-}
-
-void
-service_validate_dump(struct blob_buf *b, struct service *s)
-{
- struct validate *v;
- void *i = blobmsg_open_array(b, "validate");
-
- list_for_each_entry(v, &s->validators, list) {
- struct vrule *vr;
- void *k, *j = blobmsg_open_table(b, "validate");
-
- blobmsg_add_string(b, "package", v->package);
- blobmsg_add_string(b, "type", v->type);
- k = blobmsg_open_table(b, "rules");
- avl_for_each_element(&v->rules, vr, avl)
- blobmsg_add_string(b, vr->option, vr->rule);
- blobmsg_close_table(b, k);
- blobmsg_close_table(b, j);
- }
- blobmsg_close_array(b, i);
-}
-
-void
-service_validate_del(struct service *s)
-{
- struct validate *v, *n;
-
- if (list_empty(&s->validators))
- return;
-
- list_for_each_entry_safe(v, n, &s->validators, list) {
- struct vrule *vr, *a;
-
- avl_remove_all_elements(&v->rules, vr, avl, a)
- free(vr);
-
- avl_delete(&validators, &v->avl);
- list_del(&v->list);
- free(v);
- }
-}
-
-void
-service_validate_add(struct service *s, struct blob_attr *msg)
-{
- struct blob_attr *tb[__SERVICE_VAL_MAX];
- struct validate *v;
- char *type, *package;
- struct blob_attr *cur;
- int rem;
-
- blobmsg_parse(service_validate_attrs, __SERVICE_VAL_MAX, tb, blobmsg_data(msg), blobmsg_data_len(msg));
- if (!tb[SERVICE_VAL_PACKAGE] || !tb[SERVICE_VAL_TYPE] || !tb[SERVICE_VAL_DATA])
- return;
-
- v = calloc_a(sizeof(*v), &package, blobmsg_data_len(tb[SERVICE_VAL_PACKAGE]) + 1,
- &type, blobmsg_data_len(tb[SERVICE_VAL_TYPE]) + 1);
- if (!v)
- return;
-
- v->type = type;
- v->avl.key = v->package = package;
- strcpy(v->package, blobmsg_get_string(tb[SERVICE_VAL_PACKAGE]));
- strcpy(v->type, blobmsg_get_string(tb[SERVICE_VAL_TYPE]));
-
- list_add(&v->list, &s->validators);
- if (avl_insert(&validators, &v->avl)) {
- free(v);
- return;
- }
- avl_init(&v->rules, avl_strcmp, false, NULL);
-
- blobmsg_for_each_attr(cur, tb[SERVICE_VAL_DATA], rem) {
- char *option;
- char *rule;
- struct vrule *vr = calloc_a(sizeof(*vr), &option, strlen(blobmsg_name(cur)) + 1,
- &rule, strlen(blobmsg_get_string(cur)) + 1);
-
- vr->avl.key = vr->option = option;
- vr->rule = rule;
- strcpy(vr->option, blobmsg_name(cur));
- strcpy(vr->rule, blobmsg_get_string(cur));
- if (avl_insert(&v->rules, &vr->avl))
- free(vr);
- }
-}
-
-void
-service_validate_init(void)
-{
- avl_init(&validators, avl_strcmp, true, NULL);
-}
diff --git a/service/watch.c b/service/watch.c
index 349b484..cc0b2ee 100644
--- a/service/watch.c
+++ b/service/watch.c
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
* Copyright (C) 2013 John Crispin <blogic@openwrt.org>
+ * Copyright (C) 2015 Matthias Schiffer <mschiffer@universe-factory.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 2.1