uhttpd: support multiple Lua prefixes
[openwrt/staging/mkresin.git] / package / network / services / uhttpd / files / uhttpd.init
index 47270bcc159dad477b566f84ceb11c68148bcbb2..dc496b3e28295e330969a4fa764673cfa3270eb1 100755 (executable)
@@ -74,6 +74,18 @@ create_httpauth() {
        haveauth=1
 }
 
+append_lua_prefix() {
+       local v="$1"
+       local prefix="${v%%=*}"
+       local handler="${v#*=}"
+
+       if [ "$prefix" != "$handler" ] && [ -n "$prefix" ] && [ -f "$handler" ]; then
+               procd_append_param command -l "$prefix" -L "$handler"
+       else
+               echo "Skipping invalid Lua prefix \"$v\"" >&2
+       fi
+}
+
 start_instance()
 {
        UHTTPD_CERT=""
@@ -105,10 +117,16 @@ start_instance()
        append_arg "$cfg" config "-c"
        append_arg "$cfg" cgi_prefix "-x"
        [ -f /usr/lib/uhttpd_lua.so ] && {
-               config_get handler "$cfg" lua_handler
-               [ -f "$handler" ] && append_arg "$cfg" lua_prefix "-l" && {
-                       procd_append_param command "-L" "$handler"
-               }
+               local len
+               config_get len "$cfg" lua_prefix_LENGTH
+
+               if [ -n "$len" ]; then
+                       config_list_foreach "$cfg" lua_prefix append_lua_prefix
+               else
+                       config_get prefix "$cfg" lua_prefix
+                       config_get handler "$cfg" lua_handler
+                       append_lua_prefix "$prefix=$handler"
+               fi
        }
        [ -f /usr/lib/uhttpd_ubus.so ] && {
                append_arg "$cfg" ubus_prefix "-u"