[openwrt/openwrt] hostapd: ubus: replace ex_wrap exception handler function with global guard

LEDE Commits lede-commits at lists.infradead.org
Wed Sep 24 04:49:30 PDT 2025


nbd pushed a commit to openwrt/openwrt.git, branch main:
https://git.openwrt.org/7aa6ea9cc16181d23cad058ee0ed5241670d4089

commit 7aa6ea9cc16181d23cad058ee0ed5241670d4089
Author: Felix Fietkau <nbd at nbd.name>
AuthorDate: Sat Sep 6 16:45:15 2025 +0200

    hostapd: ubus: replace ex_wrap exception handler function with global guard
    
    Simplifies the code
    
    Signed-off-by: Felix Fietkau <nbd at nbd.name>
---
 package/network/services/hostapd/files/hostapd.uc | 57 +++++++++++------------
 1 file changed, 27 insertions(+), 30 deletions(-)

diff --git a/package/network/services/hostapd/files/hostapd.uc b/package/network/services/hostapd/files/hostapd.uc
index 7b3862e0e2..671502720e 100644
--- a/package/network/services/hostapd/files/hostapd.uc
+++ b/package/network/services/hostapd/files/hostapd.uc
@@ -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;
-		})
+		}
 	},
 };
 




More information about the lede-commits mailing list