From 0b1a426e7919eee34529267ad6f56ae9d690634c Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Wed, 12 Jun 2013 16:44:15 +0200 Subject: [PATCH] luci2: implement process_signal call --- luci2.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/luci2.c b/luci2.c index 4d66be1..4420658 100644 --- a/luci2.c +++ b/luci2.c @@ -23,12 +23,24 @@ #include #include #include +#include #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 = -- 2.30.2