On 05/07/2016 17:12, Rafał Miłecki wrote:
> Sometimes, for various reasons, user may want to reboot a device. This
> is a common task and it makes sense to support it with something common
> like a procd.
>
> Right now both: LuCI and LuCI2 implement this feature on their own with
> luci-rpc-luci2-system reboot and luci-rpc-sys reboot. This leads to code
> duplication and situation may become even worse with more software
> controlling system with ubus.
>
> Once we get this patch in place we may consider switching LuCI and LuCI2
> to this new method.
>
> Signed-off-by: Rafał Miłecki
> ---
> I wrote a simple app for my own purposes (and a bit of fun) that uses
> ubus over HTTP. I wanted to add support for rebooting device and I hit
> this issue. I didn't want another deamon or rpcd plugin adding reboot
> support so I decided to come with this procd patch.
>
> If you would like to take a look at trivial usage of this, you may check
> my small python script at:
> http://files.zajec.net/lede/diagedel/
> ---
> system.c | 20
> 1 file changed, 20 insertions(+)
>
> diff --git a/system.c b/system.c
> index 569a75d..ac34d12 100644
> --- a/system.c
> +++ b/system.c
> @@ -18,6 +18,7 @@
> #endif
> #include
> #include
> +#include
> #include
> #include
> #include
> @@ -242,6 +243,24 @@ static int system_upgrade(struct ubus_context *ctx,
> struct ubus_object *obj,
> return 0;
> }
>
> +static int system_reboot(struct ubus_context *ctx, struct ubus_object *obj,
> + struct ubus_request_data *req, const char *method,
> + struct blob_attr *msg)
> +{
> + switch (fork()) {
> + case -1:
> + return UBUS_STATUS_UNKNOWN_ERROR;
> + case 0:
> + sync();
> + sleep(1);
> + reboot(RB_AUTOBOOT);
> + while (1)
> + sleep(1);
please use procd_shutdown(RB_AUTOBOOT) instead of rebooting manually
John
> + default:
> + return 0;
> + }
> +}
> +
> enum {
> WDT_FREQUENCY,
> WDT_TIMEOUT,
> @@ -388,6 +407,7 @@ static const struct ubus_method system_methods[] = {
> UBUS_METHOD_NOARG("board", system_board),
> UBUS_METHOD_NOARG("info", system_info),
> UBUS_METHOD_NOARG("upgrade", system_upgrade),
> + UBUS_METHOD_NOARG("reboot", system_reboot),
> UBUS_METHOD("watchdog", watchdog_set, watchdog_policy),
> UBUS_METHOD("signal", proc_signal, signal_policy),
>
>
___
Lede-dev mailing list
Lede-dev@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/lede-dev