hostapd: ubus: replace ex_wrap exception handler function with global guard

Simplifies the code

Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
Felix Fietkau 2025-09-06 16:45:15 +02:00
parent 24b68023c0
commit 7aa6ea9cc1

View File

@ -4,6 +4,15 @@ import { wdev_remove, is_equal, vlist_new, phy_is_fullmac, phy_open, wdev_set_ra
let ubus = libubus.connect(null, 60);
function ex_handler(e)
{
e = split(`${e}\n${e.stacktrace[0].context}`, '\n');
for (let line in e)
hostapd.printf(line);
return libubus.STATUS_UNKNOWN_ERROR;
}
libubus.guard(ex_handler);
hostapd.data.config = {};
hostapd.data.pending_config = {};
@ -958,18 +967,6 @@ function iface_load_config(phy, radio, filename)
return config;
}
function ex_wrap(func) {
return (req) => {
try {
let ret = func(req);
return ret;
} catch(e) {
hostapd.printf(`Exception in ubus function: ${e}\n${e.stacktrace[0].context}`);
}
return libubus.STATUS_UNKNOWN_ERROR;
};
}
function phy_name(phy, radio)
{
if (!phy)
@ -1126,7 +1123,7 @@ let main_obj = {
phy: "",
radio: 0,
},
call: ex_wrap(function(req) {
call: function(req) {
let phy_list = req.args.phy ? [ phy_name(req.args.phy, req.args.radio) ] : keys(hostapd.data.config);
for (let phy_name in phy_list) {
let phy = hostapd.data.config[phy_name];
@ -1135,7 +1132,7 @@ let main_obj = {
}
return 0;
})
}
},
apsta_state: {
args: {
@ -1147,7 +1144,7 @@ let main_obj = {
csa: true,
csa_count: 0,
},
call: ex_wrap(function(req) {
call: function(req) {
let phy = phy_name(req.args.phy, req.args.radio);
if (req.args.up == null || !phy)
return libubus.STATUS_INVALID_ARGUMENT;
@ -1183,14 +1180,14 @@ let main_obj = {
return libubus.STATUS_UNKNOWN_ERROR;
return 0;
})
}
},
config_get_macaddr_list: {
args: {
phy: "",
radio: 0,
},
call: ex_wrap(function(req) {
call: function(req) {
let phy = phy_name(req.args.phy, req.args.radio);
if (!phy)
return libubus.STATUS_INVALID_ARGUMENT;
@ -1205,13 +1202,13 @@ let main_obj = {
ret.macaddr = map(config.bss, (bss) => bss.bssid);
return ret;
})
}
},
mld_set: {
args: {
config: {}
},
call: ex_wrap(function(req) {
call: function(req) {
if (!req.args.config)
return libubus.STATUS_INVALID_ARGUMENT;
@ -1220,17 +1217,17 @@ let main_obj = {
return {
pid: hostapd.getpid()
};
})
}
},
config_reset: {
args: {
},
call: ex_wrap(function(req) {
call: function(req) {
for (let name in hostapd.data.config)
iface_set_config(name);
mld_set_config({});
return 0;
})
}
},
config_set: {
args: {
@ -1239,7 +1236,7 @@ let main_obj = {
config: "",
prev_config: "",
},
call: ex_wrap(function(req) {
call: function(req) {
let phy = req.args.phy;
let radio = req.args.radio;
let name = phy_name(phy, radio);
@ -1267,14 +1264,14 @@ let main_obj = {
return {
pid: hostapd.getpid()
};
})
}
},
config_add: {
args: {
iface: "",
config: "",
},
call: ex_wrap(function(req) {
call: function(req) {
if (!req.args.iface || !req.args.config)
return libubus.STATUS_INVALID_ARGUMENT;
@ -1284,25 +1281,25 @@ let main_obj = {
return {
pid: hostapd.getpid()
};
})
}
},
config_remove: {
args: {
iface: ""
},
call: ex_wrap(function(req) {
call: function(req) {
if (!req.args.iface)
return libubus.STATUS_INVALID_ARGUMENT;
hostapd.remove_iface(req.args.iface);
return 0;
})
}
},
bss_info: {
args: {
iface: ""
},
call: ex_wrap(function(req) {
call: function(req) {
if (!req.args.iface)
return libubus.STATUS_INVALID_ARGUMENT;
@ -1322,7 +1319,7 @@ let main_obj = {
}
return ret;
})
}
},
};