0001-system-add-reboot-method-to-system-ubus-object.patch 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. Sometimes, for various reasons, user may want to reboot a device. This
  9. is a common task and it makes sense to support it with something common
  10. like a procd.
  11. Right now both: LuCI and LuCI2 implement this feature on their own with
  12. luci-rpc-luci2-system reboot and luci-rpc-sys reboot. This leads to code
  13. duplication and situation may become even worse with more software
  14. controlling system with ubus.
  15. Othen than that procd already has support for rebooting so one may
  16. consider this ubus method even cleaner.
  17. Once we get this patch in place we may consider switching LuCI and LuCI2
  18. to this new method.
  19. Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
  20. ---
  21. system.c | 10 ++++++++++
  22. 1 file changed, 10 insertions(+)
  23. diff --git a/system.c b/system.c
  24. index 569a75d..1e31ce6 100644
  25. --- a/system.c
  26. +++ b/system.c
  27. @@ -18,6 +18,7 @@
  28. #endif
  29. #include <sys/ioctl.h>
  30. #include <sys/types.h>
  31. +#include <sys/reboot.h>
  32. #include <sys/stat.h>
  33. #include <fcntl.h>
  34. #include <signal.h>
  35. @@ -242,6 +243,14 @@ static int system_upgrade(struct ubus_context *ctx, struct ubus_object *obj,
  36. return 0;
  37. }
  38. +static int system_reboot(struct ubus_context *ctx, struct ubus_object *obj,
  39. + struct ubus_request_data *req, const char *method,
  40. + struct blob_attr *msg)
  41. +{
  42. + procd_shutdown(RB_AUTOBOOT);
  43. + return 0;
  44. +}
  45. +
  46. enum {
  47. WDT_FREQUENCY,
  48. WDT_TIMEOUT,
  49. @@ -388,6 +397,7 @@ static const struct ubus_method system_methods[] = {
  50. UBUS_METHOD_NOARG("board", system_board),
  51. UBUS_METHOD_NOARG("info", system_info),
  52. UBUS_METHOD_NOARG("upgrade", system_upgrade),
  53. + UBUS_METHOD_NOARG("reboot", system_reboot),
  54. UBUS_METHOD("watchdog", watchdog_set, watchdog_policy),
  55. UBUS_METHOD("signal", proc_signal, signal_policy),
  56. --
  57. 2.7.4