#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)
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)
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 =