Merge pull request #580 from wigyori/cc-libpcap
[15.05/openwrt.git] / package / system / procd / patches / 0001-system-add-reboot-method-to-system-ubus-object.patch
1 From 02d56c03115276aa4e2203ddbd411c3e587cf08f Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
3 Date: Wed, 6 Jul 2016 13:55:48 +0200
4 Subject: [PATCH] system: add reboot method to system ubus object
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Sometimes, for various reasons, user may want to reboot a device. This
10 is a common task and it makes sense to support it with something common
11 like a procd.
12
13 Right now both: LuCI and LuCI2 implement this feature on their own with
14 luci-rpc-luci2-system reboot and luci-rpc-sys reboot. This leads to code
15 duplication and situation may become even worse with more software
16 controlling system with ubus.
17
18 Othen than that procd already has support for rebooting so one may
19 consider this ubus method even cleaner.
20
21 Once we get this patch in place we may consider switching LuCI and LuCI2
22 to this new method.
23
24 Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
25 ---
26  system.c | 10 ++++++++++
27  1 file changed, 10 insertions(+)
28
29 diff --git a/system.c b/system.c
30 index 569a75d..1e31ce6 100644
31 --- a/system.c
32 +++ b/system.c
33 @@ -18,6 +18,7 @@
34  #endif
35  #include <sys/ioctl.h>
36  #include <sys/types.h>
37 +#include <sys/reboot.h>
38  #include <sys/stat.h>
39  #include <fcntl.h>
40  #include <signal.h>
41 @@ -242,6 +243,14 @@ static int system_upgrade(struct ubus_context *ctx, struct ubus_object *obj,
42         return 0;
43  }
44  
45 +static int system_reboot(struct ubus_context *ctx, struct ubus_object *obj,
46 +                        struct ubus_request_data *req, const char *method,
47 +                        struct blob_attr *msg)
48 +{
49 +       procd_shutdown(RB_AUTOBOOT);
50 +       return 0;
51 +}
52 +
53  enum {
54         WDT_FREQUENCY,
55         WDT_TIMEOUT,
56 @@ -388,6 +397,7 @@ static const struct ubus_method system_methods[] = {
57         UBUS_METHOD_NOARG("board", system_board),
58         UBUS_METHOD_NOARG("info",  system_info),
59         UBUS_METHOD_NOARG("upgrade", system_upgrade),
60 +       UBUS_METHOD_NOARG("reboot", system_reboot),
61         UBUS_METHOD("watchdog", watchdog_set, watchdog_policy),
62         UBUS_METHOD("signal", proc_signal, signal_policy),
63  
64 -- 
65 2.7.4
66