From: Felix Fietkau Date: Sun, 16 Dec 2012 19:45:42 +0000 (+0100) Subject: add support for specifying process priority X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=c1094b622e605f206c128df704645227fd63ed07;p=oweals%2Fprocd.git add support for specifying process priority Signed-off-by: Felix Fietkau --- diff --git a/instance.c b/instance.c index b84e7c8..a25f91a 100644 --- a/instance.c +++ b/instance.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -12,6 +13,7 @@ enum { INSTANCE_ATTR_ENV, INSTANCE_ATTR_DATA, INSTANCE_ATTR_NETDEV, + INSTANCE_ATTR_NICE, __INSTANCE_ATTR_MAX }; @@ -20,6 +22,7 @@ static const struct blobmsg_policy instance_attr[__INSTANCE_ATTR_MAX] = { [INSTANCE_ATTR_ENV] = { "env", BLOBMSG_TYPE_TABLE }, [INSTANCE_ATTR_DATA] = { "data", BLOBMSG_TYPE_TABLE }, [INSTANCE_ATTR_NETDEV] = { "netdev", BLOBMSG_TYPE_ARRAY }, + [INSTANCE_ATTR_NICE] = { "nice", BLOBMSG_TYPE_INT32 }, }; struct instance_netdev { @@ -36,6 +39,9 @@ instance_run(struct service_instance *in) int argc = 1; /* NULL terminated */ int rem; + if (in->nice) + setpriority(PRIO_PROCESS, 0, in->nice); + blobmsg_for_each_attr(cur, in->command, rem) argc++; @@ -129,6 +135,9 @@ instance_config_changed(struct service_instance *in, struct service_instance *in if (!blobmsg_list_equal(&in->netdev, &in_new->netdev)) return true; + if (in->nice != in_new->nice) + return true; + return false; } @@ -176,6 +185,12 @@ instance_config_parse(struct service_instance *in) in->command = cur; + if ((cur = tb[INSTANCE_ATTR_NICE])) { + in->nice = (int8_t) blobmsg_get_u32(cur); + if (in->nice < -20 || in->nice > 20) + return false; + } + if ((cur = tb[INSTANCE_ATTR_ENV])) { if (!blobmsg_check_attr_list(cur, BLOBMSG_TYPE_STRING)) return false; diff --git a/instance.h b/instance.h index 59e887c..484c856 100644 --- a/instance.h +++ b/instance.h @@ -10,8 +10,10 @@ struct service_instance { struct service *srv; const char *name; + int8_t nice; bool valid; bool restart; + struct blob_attr *config; struct uloop_process proc; struct uloop_timeout timeout;