From cbc0374251a275f1102c3576a737e45f4f4158d7 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Thu, 16 Mar 2023 19:30:50 +0100 Subject: [PATCH] mech: add support for ietf-system:system-restart and system-shutdown Shutdown depends on how the kernel is configured, on most embedded systems this just means reboot. Signed-off-by: Joachim Wiberg --- src/mech/src/ietf-system/ietf-system.c | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/mech/src/ietf-system/ietf-system.c b/src/mech/src/ietf-system/ietf-system.c index 5e7bb91c..ebca50e3 100644 --- a/src/mech/src/ietf-system/ietf-system.c +++ b/src/mech/src/ietf-system/ietf-system.c @@ -214,6 +214,26 @@ err: return err; } +static int do_rpc(clicon_handle h, /* Clicon handle */ + cxobj *xe, /* Request: */ + cbuf *cbret, /* Reply eg ... */ + void *arg, /* client_entry */ + void *regarg) /* Argument given at register */ +{ + char *namespace = NETCONF_BASE_NAMESPACE; + +// if ((namespace = xml_find_type_value(xe, NULL, "xmlns", CX_ATTR)) == NULL){ +// clicon_err(OE_XML, ENOENT, "No namespace given in RPC %s", xml_name(xe)); +// return -1; +// } + + cprintf(cbret, "", namespace); + if (regarg && !strcmp(regarg, "system-shutdown")) + return system("poweroff"); + + return system("reboot"); +} + static clixon_plugin_api ietf_system_api = { .ca_name = "ietf-system", .ca_init = clixon_plugin_init, @@ -233,5 +253,20 @@ clixon_plugin_api *clixon_plugin_init(clicon_handle h) return NULL; } + if (rpc_callback_register(h, do_rpc, NULL, + "urn:ietf:params:xml:ns:yang:ietf-system", + "system-restart") < 0) { + clicon_err(OE_PLUGIN, EINVAL, + "ietf-system: failed registering RPC callback"); + return NULL; + } + if (rpc_callback_register(h, do_rpc, NULL, + "urn:ietf:params:xml:ns:yang:ietf-system", + "system-shutdown") < 0) { + clicon_err(OE_PLUGIN, EINVAL, + "ietf-system: failed registering RPC callback"); + return NULL; + } + return &ietf_system_api; }