luci2: implement process_signal call
authorJo-Philipp Wich <jow@openwrt.org>
Wed, 12 Jun 2013 14:44:15 +0000 (16:44 +0200)
committerJo-Philipp Wich <jow@openwrt.org>
Wed, 12 Jun 2013 14:49:03 +0000 (16:49 +0200)
luci2.c

diff --git a/luci2.c b/luci2.c
index 4d66be12e38fb41dbbbc29bd47a985594eb2bb27..4420658b4f5e2498b792496a9f45e24a70c0693e 100644 (file)
--- a/luci2.c
+++ b/luci2.c
 #include <string.h>
 #include <sys/stat.h>
 #include <arpa/inet.h>
+#include <signal.h>
 
 #include "luci2.h"
 
 static struct blob_buf buf;
 static struct uci_context *cursor;
 
+enum {
+       RPC_S_PID,
+       RPC_S_SIGNAL,
+       __RPC_S_MAX,
+};
+
+static const struct blobmsg_policy rpc_signal_policy[__RPC_S_MAX] = {
+       [RPC_S_PID]    = { .name = "pid",    .type = BLOBMSG_TYPE_INT32 },
+       [RPC_S_SIGNAL] = { .name = "signal", .type = BLOBMSG_TYPE_INT32 },
+};
+
 
 static int
 rpc_errno_status(void)
@@ -247,6 +259,32 @@ rpc_luci2_process_list(struct ubus_context *ctx, struct ubus_object *obj,
        return 0;
 }
 
+static int
+rpc_luci2_process_signal(struct ubus_context *ctx, struct ubus_object *obj,
+                         struct ubus_request_data *req, const char *method,
+                         struct blob_attr *msg)
+{
+       int pid, sig;
+       struct blob_attr *tb[__RPC_S_MAX];
+
+       blobmsg_parse(rpc_signal_policy, __RPC_S_MAX, tb,
+                     blob_data(msg), blob_len(msg));
+
+       if (!tb[RPC_S_SIGNAL] || !tb[RPC_S_PID])
+       {
+               errno = EINVAL;
+               return rpc_errno_status();
+       }
+
+       pid = blobmsg_get_u32(tb[RPC_S_PID]);
+       sig = blobmsg_get_u32(tb[RPC_S_SIGNAL]);
+
+       if (kill(pid, sig))
+               return rpc_errno_status();
+
+       return 0;
+}
+
 
 static FILE *
 dnsmasq_leasefile(void)
@@ -773,7 +811,9 @@ int rpc_luci2_api_init(struct ubus_context *ctx)
        static const struct ubus_method luci2_system_methods[] = {
                UBUS_METHOD_NOARG("syslog",       rpc_luci2_system_log),
                UBUS_METHOD_NOARG("dmesg",        rpc_luci2_system_dmesg),
-               UBUS_METHOD_NOARG("process_list", rpc_luci2_process_list)
+               UBUS_METHOD_NOARG("process_list", rpc_luci2_process_list),
+               UBUS_METHOD("process_signal",     rpc_luci2_process_signal,
+                                                 rpc_signal_policy),
        };
 
        static struct ubus_object_type luci2_system_type =