mirror of
https://github.com/kernelkit/infix.git
synced 2026-08-01 05:13:01 +02:00
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 <troglobit@gmail.com>
This commit is contained in:
@@ -214,6 +214,26 @@ err:
|
||||
return err;
|
||||
}
|
||||
|
||||
static int do_rpc(clicon_handle h, /* Clicon handle */
|
||||
cxobj *xe, /* Request: <rpc><xn></rpc> */
|
||||
cbuf *cbret, /* Reply eg <rpc-reply>... */
|
||||
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, "<rpc-reply xmlns=\"%s\"><ok/></rpc-reply>", 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user