luci2: implement process_signal call
This commit is contained in:
parent
e0bb659e62
commit
0b1a426e79
1 changed files with 41 additions and 1 deletions
42
luci2.c
42
luci2.c
|
@ -23,12 +23,24 @@
|
|||
#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 =
|
||||
|
|
Loading…
Add table
Reference in a new issue