uhttpd: do not attempt to configure Lua handler if referenced file does not exist
[openwrt.git] / package / network / services / uhttpd / files / uhttpd.init
index 51f7547ca88c1dcd4bf45d720f771db0e46602d6..608aa9d36b4908190510d1cb4bcd19cbc6e1992d 100755 (executable)
@@ -57,19 +57,26 @@ start_instance()
 
        local cfg="$1"
        local realm="$(uci_get system.@system[0].hostname)"
-       local listen http https interpreter indexes path
+       local listen http https interpreter indexes path handler
 
        procd_open_instance
+       procd_set_param respawn
        procd_set_param command "$UHTTPD_BIN" -f
 
        append_arg "$cfg" home "-h"
        append_arg "$cfg" realm "-r" "${realm:-OpenWrt}"
        append_arg "$cfg" config "-c"
        append_arg "$cfg" cgi_prefix "-x"
-       append_arg "$cfg" lua_prefix "-l"
-       append_arg "$cfg" lua_handler "-L"
-       append_arg "$cfg" ubus_prefix "-u"
-       append_arg "$cfg" ubus_socket "-U"
+       [ -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"
+               }
+       }
+       [ -f /usr/lib/uhttpd_ubus.so ] && {
+               append_arg "$cfg" ubus_prefix "-u"
+               append_arg "$cfg" ubus_socket "-U"
+       }
        append_arg "$cfg" script_timeout "-t"
        append_arg "$cfg" network_timeout "-T"
        append_arg "$cfg" http_keepalive "-k"
@@ -112,7 +119,7 @@ start_instance()
                        append_arg "$cfg" key  "-K"
 
                        for listen in $https; do
-                               append UHTTPD_ARGS "-s $listen"
+                               procd_append_param command -s "$listen"
                        done
                }
        }