[OpenWrt-Devel] [PATCH luci] luci-mod-system: use ubus method for reboot

Rafał Miłecki zajec5 at gmail.com
Thu Jun 18 09:25:18 EDT 2020


From: Rafał Miłecki <rafal at milecki.pl>

It's more generic & convenient than hardcoding /sbin/reboot executable
path. procd provides "reboot" method since 2016.

Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
---
 .../luci-static/resources/view/system/reboot.js     | 13 ++++++++++---
 .../root/usr/share/rpcd/acl.d/luci-mod-system.json  |  3 ++-
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/modules/luci-mod-system/htdocs/luci-static/resources/view/system/reboot.js b/modules/luci-mod-system/htdocs/luci-static/resources/view/system/reboot.js
index 3b9f450fc..249247bab 100644
--- a/modules/luci-mod-system/htdocs/luci-static/resources/view/system/reboot.js
+++ b/modules/luci-mod-system/htdocs/luci-static/resources/view/system/reboot.js
@@ -1,9 +1,16 @@
 'use strict';
 'require view';
 'require fs';
+'require rpc';
 'require ui';
 'require uci';
 
+var callReboot = rpc.declare({
+	object: 'system',
+	method: 'reboot',
+	expect: { result: 0 }
+});
+
 return view.extend({
 	load: function() {
 		return uci.changes();
@@ -31,9 +38,9 @@ return view.extend({
 	},
 
 	handleReboot: function(ev) {
-		return fs.exec('/sbin/reboot').then(function(res) {
-			if (res.code != 0) {
-				L.ui.addNotification(null, E('p', _('The reboot command failed with code %d').format(res.code)));
+		return callReboot().then(function(res) {
+			if (res != 0) {
+				L.ui.addNotification(null, E('p', _('The reboot command failed with code %d').format(res)));
 				L.raise('Error', 'Reboot failed');
 			}
 
diff --git a/modules/luci-mod-system/root/usr/share/rpcd/acl.d/luci-mod-system.json b/modules/luci-mod-system/root/usr/share/rpcd/acl.d/luci-mod-system.json
index b29ddb8f4..38ff98dee 100644
--- a/modules/luci-mod-system/root/usr/share/rpcd/acl.d/luci-mod-system.json
+++ b/modules/luci-mod-system/root/usr/share/rpcd/acl.d/luci-mod-system.json
@@ -160,7 +160,8 @@
 				"/sbin/reboot": [ "exec" ]
 			},
 			"ubus": {
-				"file": [ "exec" ]
+				"file": [ "exec" ],
+				"system": [ "reboot" ]
 			}
 		}
 	}
-- 
2.26.1


_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list