luci-mod-system: use ubus method for reboot
authorRafał Miłecki <rafal@milecki.pl>
Thu, 18 Jun 2020 13:25:18 +0000 (15:25 +0200)
committerRafał Miłecki <rafal@milecki.pl>
Thu, 10 Sep 2020 15:35:07 +0000 (17:35 +0200)
It's more generic & convenient than hardcoding /sbin/reboot executable
path. procd provides "reboot" method since 2016.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
modules/luci-mod-system/htdocs/luci-static/resources/view/system/reboot.js
modules/luci-mod-system/root/usr/share/rpcd/acl.d/luci-mod-system.json

index 3b9f450fcd9f8336ac7249b45da88e0176258f19..92e1dd49208f465f0d91099fa69c64b74b800161 100644 (file)
@@ -1,9 +1,15 @@
 '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 +37,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');
                        }
 
index b29ddb8f4e164c93097d9bf002cdd3424a52775e..38ff98dee6efe5abef770d36bc3234b1ee619911 100644 (file)
                                "/sbin/reboot": [ "exec" ]
                        },
                        "ubus": {
-                               "file": [ "exec" ]
+                               "file": [ "exec" ],
+                               "system": [ "reboot" ]
                        }
                }
        }