From 7000746a30d6136a178e3a4f0a4ecf60b569b51d Mon Sep 17 00:00:00 2001 From: Marcin Jurkowski Date: Wed, 6 Mar 2013 09:30:36 +0000 Subject: [PATCH 1/5] owfs: Add init scripts and config files Owfs daemons lack control scripts. This patch adds init.d scripts for owfs, owserver, owhttpd and owftpd packages. Most daemon options (both common libow and program-specific parameters) are reflected as uci config variables. Signed-off-by: Marcin Jurkowski --- utils/owfs/Makefile | 32 +++++++++++++++ utils/owfs/files/owfs.conf | 11 +++++ utils/owfs/files/owfs.init | 75 ++++++++++++++++++++++++++++++++++ utils/owfs/files/owftpd.conf | 9 ++++ utils/owfs/files/owftpd.init | 72 ++++++++++++++++++++++++++++++++ utils/owfs/files/owhttpd.conf | 9 ++++ utils/owfs/files/owhttpd.init | 71 ++++++++++++++++++++++++++++++++ utils/owfs/files/owserver.conf | 9 ++++ utils/owfs/files/owserver.init | 70 +++++++++++++++++++++++++++++++ 9 files changed, 358 insertions(+) create mode 100644 utils/owfs/files/owfs.conf create mode 100644 utils/owfs/files/owfs.init create mode 100644 utils/owfs/files/owftpd.conf create mode 100644 utils/owfs/files/owftpd.init create mode 100644 utils/owfs/files/owhttpd.conf create mode 100644 utils/owfs/files/owhttpd.init create mode 100644 utils/owfs/files/owserver.conf create mode 100644 utils/owfs/files/owserver.init diff --git a/utils/owfs/Makefile b/utils/owfs/Makefile index bec087f89..b939d618e 100644 --- a/utils/owfs/Makefile +++ b/utils/owfs/Makefile @@ -198,6 +198,15 @@ endef define Package/owfs/install $(INSTALL_DIR) $(1)/usr/bin $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/owfs $(1)/usr/bin/ + $(INSTALL_DIR) $(1)/etc/config + $(INSTALL_DATA) ./files/owfs.conf $(1)/etc/config/owfs + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_BIN) ./files/owfs.init $(1)/etc/init.d/owfs + mkdir -p $(1)/mnt/owfs +endef + +define Package/owfs/conffiles +/etc/config/owfs endef define Package/owshell/install @@ -213,18 +222,41 @@ endef define Package/owserver/install $(INSTALL_DIR) $(1)/usr/bin $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/owserver $(1)/usr/bin/ + $(INSTALL_DIR) $(1)/etc/config + $(INSTALL_DATA) ./files/owserver.conf $(1)/etc/config/owserver + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_BIN) ./files/owserver.init $(1)/etc/init.d/owserver +endef + +define Package/owserver/conffiles +/etc/config/owserver endef define Package/owhttpd/install $(INSTALL_DIR) $(1)/usr/bin $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/owhttpd $(1)/usr/bin/ + $(INSTALL_DIR) $(1)/etc/config + $(INSTALL_DATA) ./files/owhttpd.conf $(1)/etc/config/owhttpd + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_BIN) ./files/owhttpd.init $(1)/etc/init.d/owhttpd +endef + +define Package/owhttpd/conffiles +/etc/config/owhttpd endef define Package/owftpd/install $(INSTALL_DIR) $(1)/usr/bin $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/owftpd $(1)/usr/bin/ + $(INSTALL_DIR) $(1)/etc/config + $(INSTALL_DATA) ./files/owftpd.conf $(1)/etc/config/owftpd + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_BIN) ./files/owftpd.init $(1)/etc/init.d/owftpd endef +define Package/owftpd/conffiles +/etc/config/owftpd +endef define Package/libow/install $(INSTALL_DIR) $(1)/usr/lib diff --git a/utils/owfs/files/owfs.conf b/utils/owfs/files/owfs.conf new file mode 100644 index 000000000..3bb30a542 --- /dev/null +++ b/utils/owfs/files/owfs.conf @@ -0,0 +1,11 @@ +config owfs 'owfs' + option enabled 0 + option uid 0 + option gid 0 + option readonly 0 + option mountpoint '/mnt/owfs' + option fuse_allow_other 0 + option fuse_open_opt '' + option error_level 0 + option options '' + list devices '-s localhost:4304' diff --git a/utils/owfs/files/owfs.init b/utils/owfs/files/owfs.init new file mode 100644 index 000000000..e70820fee --- /dev/null +++ b/utils/owfs/files/owfs.init @@ -0,0 +1,75 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2009-2012 OpenWrt.org + +START=99 + +SERVICE_WRITE_PID=1 +SERVICE_DAEMONIZE=1 + +# Workaround insufficient /dev/fuse permissions and the lack of /etc/fuse.conf +DEFAULT_SERVICE_UID=0 +DEFAULT_SERVICE_GID=0 + +append_device() { + append devices "$1" +} + + +start_owfs_daemon() { + local program="$1" + local config="$1" + local args="--foreground --error_print=1 $2" + + + local enabled + config_get_bool enabled "$config" enabled 0 + [ "${enabled}" -eq 0 ] && return 1 + + local readonly + config_get_bool readonly "$config" readonly 0 + [ "${readonly}" -eq 1 ] && append args "--readonly" + + local error_level + config_get error_level "$config" error_level + [ -n "${error_level}" ] && append args "--error_level=${error_level}" + + local options + config_get options "$config" options + + devices="" + config_list_foreach "$config" devices append_device + + config_get SERVICE_UID "$config" uid "$DEFAULT_SERVICE_UID" + config_get SERVICE_GID "$config" gid "$DEFAULT_SERVICE_GID" + + service_start "/usr/bin/$program" $args $options $devices +} + +start_owfs() { + local config="owfs" + local args="" + + config_load "$config" + + local mountpoint + config_get mountpoint "$config" mountpoint /mnt/owfs + append args "--mountpoint=${mountpoint}" + + local fuse_allow_other + config_get_bool fuse_allow_other "$config" fuse_allow_other 0 + [ "${fuse_allow_other}" -eq 1 ] && append args "--allow_other" + + local fuse_open_opt + config_get fuse_open_opt "$config" fuse_open_opt + [ -n "${fuse_open_opt}" ] && append args "--fuse_open_opt=\"${fuse_open_opt}\"" + + start_owfs_daemon "$config" "$args" +} + +start() { + start_owfs +} + +stop() { + service_stop /usr/bin/owfs +} diff --git a/utils/owfs/files/owftpd.conf b/utils/owfs/files/owftpd.conf new file mode 100644 index 000000000..88322c941 --- /dev/null +++ b/utils/owfs/files/owftpd.conf @@ -0,0 +1,9 @@ +config owftpd 'owftpd' + option enabled 0 + option uid 0 + option gid 0 + option readonly 0 + option port 21 + option error_level 0 + option options '' + list devices '-s localhost:4304' diff --git a/utils/owfs/files/owftpd.init b/utils/owfs/files/owftpd.init new file mode 100644 index 000000000..010b2b939 --- /dev/null +++ b/utils/owfs/files/owftpd.init @@ -0,0 +1,72 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2009-2012 OpenWrt.org + +START=99 + +SERVICE_WRITE_PID=1 +SERVICE_DAEMONIZE=1 + +# Needed for restricted TCP port 21 +DEFAULT_SERVICE_UID=0 +DEFAULT_SERVICE_GID=0 + +append_device() { + append devices "$1" +} + + +start_owfs_daemon() { + local program="$1" + local config="$1" + local args="--foreground --error_print=1 $2" + + + local enabled + config_get_bool enabled "$config" enabled 0 + [ "${enabled}" -eq 0 ] && return 1 + + local readonly + config_get_bool readonly "$config" readonly 0 + [ "${readonly}" -eq 1 ] && append args "--readonly" + + local error_level + config_get error_level "$config" error_level + [ -n "${error_level}" ] && append args "--error_level=${error_level}" + + local options + config_get options "$config" options + + devices="" + config_list_foreach "$config" devices append_device + + config_get SERVICE_UID "$config" uid "$DEFAULT_SERVICE_UID" + config_get SERVICE_GID "$config" gid "$DEFAULT_SERVICE_GID" + + service_start "/usr/bin/$program" $args $options $devices +} + +start_owftpd() { + local config="owftpd" + local args="" + + config_load "$config" + + local port + config_get port "$config" port + [ -n "${port}" ] && append args "--port=${port}" + + local max_connections + config_get max_connections "$config" max_connections + [ -n "${max_connections}" ] && append args "--max_connections=${max_connections}" + + start_owfs_daemon "$config" "$args" +} + + +start() { + start_owftpd +} + +stop() { + service_stop /usr/bin/owftpd +} diff --git a/utils/owfs/files/owhttpd.conf b/utils/owfs/files/owhttpd.conf new file mode 100644 index 000000000..e49e4ceb3 --- /dev/null +++ b/utils/owfs/files/owhttpd.conf @@ -0,0 +1,9 @@ +config owhttpd 'owhttpd' + option enabled 0 + option uid 65534 + option gid 65534 + option readonly 0 + option port 3001 + option error_level 0 + option options '' + list devices '-s localhost:4304' diff --git a/utils/owfs/files/owhttpd.init b/utils/owfs/files/owhttpd.init new file mode 100644 index 000000000..fdabdbc26 --- /dev/null +++ b/utils/owfs/files/owhttpd.init @@ -0,0 +1,71 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2009-2012 OpenWrt.org + +START=99 + +SERVICE_WRITE_PID=1 +SERVICE_DAEMONIZE=1 + +DEFAULT_SERVICE_UID=65534 +DEFAULT_SERVICE_GID=65534 + +append_device() { + append devices "$1" +} + + +start_owfs_daemon() { + local program="$1" + local config="$1" + local args="--foreground --error_print=1 $2" + + + local enabled + config_get_bool enabled "$config" enabled 0 + [ "${enabled}" -eq 0 ] && return 1 + + local readonly + config_get_bool readonly "$config" readonly 0 + [ "${readonly}" -eq 1 ] && append args "--readonly" + + local error_level + config_get error_level "$config" error_level + [ -n "${error_level}" ] && append args "--error_level=${error_level}" + + local options + config_get options "$config" options + + devices="" + config_list_foreach "$config" devices append_device + + config_get SERVICE_UID "$config" uid "$DEFAULT_SERVICE_UID" + config_get SERVICE_GID "$config" gid "$DEFAULT_SERVICE_GID" + + service_start "/usr/bin/$program" $args $options $devices +} + +start_owhttpd() { + local config="owhttpd" + local args="" + + config_load "$config" + + local port + config_get port "$config" port + [ -n "${port}" ] && append args "--port=${port}" + + local max_connections + config_get max_connections "$config" max_connections + [ -n "${max_connections}" ] && append args "--max_connections=${max_connections}" + + start_owfs_daemon "$config" "$args" +} + + +start() { + start_owhttpd +} + +stop() { + service_stop /usr/bin/owhttpd +} diff --git a/utils/owfs/files/owserver.conf b/utils/owfs/files/owserver.conf new file mode 100644 index 000000000..e00089462 --- /dev/null +++ b/utils/owfs/files/owserver.conf @@ -0,0 +1,9 @@ +config owserver 'owserver' + option enabled 0 + option uid 65534 + option gid 65534 + option readonly 0 + option port 4304 + option error_level 0 + option options '' + list devices '-d /dev/ttyUSB0' diff --git a/utils/owfs/files/owserver.init b/utils/owfs/files/owserver.init new file mode 100644 index 000000000..bbf870d04 --- /dev/null +++ b/utils/owfs/files/owserver.init @@ -0,0 +1,70 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2009-2012 OpenWrt.org + +START=98 + +SERVICE_WRITE_PID=1 +SERVICE_DAEMONIZE=1 + +DEFAULT_SERVICE_UID=65534 +DEFAULT_SERVICE_GID=65534 + +append_device() { + append devices "$1" +} + + +start_owfs_daemon() { + local program="$1" + local config="$1" + local args="--foreground --error_print=1 $2" + + + local enabled + config_get_bool enabled "$config" enabled 0 + [ "${enabled}" -eq 0 ] && return 1 + + local readonly + config_get_bool readonly "$config" readonly 0 + [ "${readonly}" -eq 1 ] && append args "--readonly" + + local error_level + config_get error_level "$config" error_level + [ -n "${error_level}" ] && append args "--error_level=${error_level}" + + local options + config_get options "$config" options + + devices="" + config_list_foreach "$config" devices append_device + + config_get SERVICE_UID "$config" uid "$DEFAULT_SERVICE_UID" + config_get SERVICE_GID "$config" gid "$DEFAULT_SERVICE_GID" + + service_start "/usr/bin/$program" $args $options $devices +} + +start_owserver() { + local config="owserver" + local args="" + + config_load "$config" + + local port + config_get port "$config" port + [ -n "${port}" ] && append args "--port=${port}" + + local max_connections + config_get max_connections "$config" max_connections + [ -n "${max_connections}" ] && append args "--max_connections=${max_connections}" + + start_owfs_daemon "$config" "$args" +} + +start() { + start_owserver +} + +stop() { + service_stop /usr/bin/owserver +} From d6fe15a85c4690f34a73af77c6cf6f316acf75b6 Mon Sep 17 00:00:00 2001 From: Marcin Jurkowski Date: Wed, 6 Mar 2013 09:31:17 +0000 Subject: [PATCH 2/5] owfs: make libow features configurable Owfs shared library is quite large (700+ kB) by embedded devices standards. The code for many different bus master and slave devices is compiled into single big .so library. Had it been designed as modular, dynamic-loadable plugins, we could split them into separate packages, allowing user to install only the plugins he needs. It's however possible to enable or disable libow features at compile time. Here are some examples how much space can be saved turning off support for unneeded devices and features: - By disabling USB adapter support libusb and libusb-compat is no longer needed, saving ~70kB of space. Bus masters using usbserial.ko kernel driver don't need this. - By disabling debug messages it's possible to reduce shared library size by 130kB. This patch adds a menu allowing user to select libow features one wants built in: - Bus master support: USB adapters through libusb, i2c adapters, kernel w1 adapters - General features: zeroconf device announcement, debug messages, owtraffic bus reports Default config options preserve previous library configuration i.e. everything is selected except for owtraffic (which was disabled) and kernel w1 driver (whose netlink interface has been broken since 2011). Signed-off-by: Marcin Jurkowski --- utils/owfs/Config.in | 49 ++++++++++++++++++++++++++++++++++++++++++++ utils/owfs/Makefile | 24 ++++++++++++++++++++-- 2 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 utils/owfs/Config.in diff --git a/utils/owfs/Config.in b/utils/owfs/Config.in new file mode 100644 index 000000000..a6508e85e --- /dev/null +++ b/utils/owfs/Config.in @@ -0,0 +1,49 @@ + menu "Customize libow" + depends on PACKAGE_libow + + menu "Bus master and adapter support" + config LIBOW_MASTER_USB + bool "USB bus master support (requires libusb)" + help + Include support for USB adapters (NOT usb-serial adapters, which use + kernel driver and are supported anyway). + Turning this off will save ~13kB (and ~50kB weighting libusb dependency). + default y + + config LIBOW_MASTER_I2C + bool "I2C bus master (DS2482) support" + default y + help + Include support for I2C adapters. + Turning this feature off will save ~6kB. + + config LIBOW_MASTER_W1 + bool "Kernel W1 bus master support (requires kmod-w1)" + help + Support kernel 1-Wire bus masters (requires KConfig CONFIG_CONNECTOR=y + and CONFIG_W1_CON=y). + Turning this on will increase libow size by about 10kB. + default n + endmenu + + config LIBOW_ZEROCONF + bool "Zeroconf/bonjour support" + default y + help + Enable server process announcement using Zeroconf (Bonjour) protocol. + Turning this feature on will increase owlib size by about 12kB. + + config LIBOW_DEBUG + bool "Enable debug output (100+ kB)" + default y + help + If you don't need to debug your 1-wire network, you can save as much as + 137kB disabling debug output. + + config LIBOW_OWTRAFFIC + bool "Enable bus traffic reports" + default n + help + Enable owfs traffic monitor. It's here purely for debugging purposes. + Turning this on will increase libow size by about 3kB. + endmenu diff --git a/utils/owfs/Makefile b/utils/owfs/Makefile index b939d618e..d4cc4cb24 100644 --- a/utils/owfs/Makefile +++ b/utils/owfs/Makefile @@ -20,6 +20,14 @@ PKG_LICENSE:=GPL-2.0 PKG_FIXUP:=autoreconf PKG_INSTALL:=1 +PKG_CONFIG_DEPENDS:= \ + CONFIG_LIBOW_MASTER_USB \ + CONFIG_LIBOW_MASTER_I2C \ + CONFIG_LIBOW_MASTER_W1 \ + CONFIG_LIBOW_ZEROCONF \ + CONFIG_LIBOW_DEBUG \ + CONFIG_LIBOW_OWTRAFFIC + include $(INCLUDE_DIR)/package.mk # @@ -74,10 +82,17 @@ endef define Package/libow $(call Package/owfs/Library) - DEPENDS:=+libusb-compat +libpthread + DEPENDS:= \ + +libpthread \ + +LIBOW_MASTER_USB:libusb-compat \ + +LIBOW_MASTER_W1:kmod-w1 TITLE:=OWFS - common shared library endef +define Package/libow/config + source "$(SOURCE)/Config.in" +endef + define Package/libow/description $(call Package/$(PKG_NAME)/Default/description) @@ -170,13 +185,18 @@ CONFIGURE_ARGS += \ --with-fuseinclude="$(STAGING_DIR)/usr/include" \ --with-fuselib="$(STAGING_DIR)/usr/lib" \ --enable-shared \ - --enable-zero \ --disable-parport \ --disable-ownet \ --disable-owpython \ --disable-owphp \ --disable-owtcl \ --disable-swig \ + $(if $(CONFIG_LIBOW_MASTER_USB),--enable-usb,--disable-usb) \ + $(if $(CONFIG_LIBOW_MASTER_W1),--enable-w1,--disable-w1) \ + $(if $(CONFIG_LIBOW_MASTER_I2C),--enable-i2c,--disable-i2c) \ + $(if $(CONFIG_LIBOW_ZEROCONF),--enable-zero,--disable-zero) \ + $(if $(CONFIG_LIBOW_DEBUG),--enable-debug,--disable-debug) \ + $(if $(CONFIG_LIBOW_OWTRAFFIC),--enable-owtraffic,--disable-owtraffic) CONFIGURE_VARS += \ LDFLAGS="$(TARGET_LDFLAGS) -Wl,-rpath-link=$(STAGING_DIR)/usr/lib -Wl,-rpath-link=$(TOOLCHAIN_DIR)/usr/lib" \ From 2d537bc98fc365e466b7aff0b10855051d9b0783 Mon Sep 17 00:00:00 2001 From: Marcin Jurkowski Date: Mon, 29 Jun 2015 00:58:06 +0200 Subject: [PATCH 3/5] owfs: fix the last netlink message recognition This fixes the endless loop waiting for w1 subsystem connector status message. According to the 8a0427d kernel commit, the last (status) netlink msg should have ack=seq, whereas all the others messages should have ack=seq+1. This patch has been submitted upstream: https://sourceforge.net/p/owfs/bugs/66/. For independent problem report, see this thread: https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=98772 Signed-off-by: Marcin Jurkowski --- ...-netlink-w1-status-message-detection.patch | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 utils/owfs/patches/100-fix-netlink-w1-status-message-detection.patch diff --git a/utils/owfs/patches/100-fix-netlink-w1-status-message-detection.patch b/utils/owfs/patches/100-fix-netlink-w1-status-message-detection.patch new file mode 100644 index 000000000..251065fa2 --- /dev/null +++ b/utils/owfs/patches/100-fix-netlink-w1-status-message-detection.patch @@ -0,0 +1,30 @@ +AaAA +--- a/module/owlib/src/c/ow_w1_parse.c ++++ b/module/owlib/src/c/ow_w1_parse.c +@@ -237,7 +237,7 @@ enum Netlink_Read_Status W1_Process_Resp + owfree(nlp.nlm) ; + return nrs_nodev ; + } +- if ( nrs_callback == NULL ) { // status message ++ if ( nrs_callback == NULL ) { // bus reset + owfree(nlp.nlm) ; + return nrs_complete ; + } +@@ -246,7 +246,7 @@ enum Netlink_Read_Status W1_Process_Resp + nrs_callback( &nlp, v, pn ) ; + LEVEL_DEBUG("Called nrs_callback"); + owfree(nlp.nlm) ; +- if ( nlp.cn->ack != 0 ) { ++ if ( nlp.cn->seq != nlp.cn->ack ) { + if ( nlp.w1m->type == W1_LIST_MASTERS ) { + continue ; // look for more data + } +@@ -254,7 +254,7 @@ enum Netlink_Read_Status W1_Process_Resp + continue ; // look for more data + } + } +- nrs_callback = NULL ; // now look for status message ++ return nrs_complete ; // status message + } + return nrs_timeout ; + } From 101fc3047c187265a1fcf35b9b1efaad98c5082e Mon Sep 17 00:00:00 2001 From: Marcin Jurkowski Date: Mon, 29 Jun 2015 21:01:04 +0200 Subject: [PATCH 4/5] owfs: avoid npe in BUS_reset function Monitor adapters (zeroconf, enet, usb and w1) don't have the reset routine, causing null pointer dereference in BUS_reset function. This patch has been submitted upstream: https://sourceforge.net/p/owfs/bugs/67/ Signed-off-by: Marcin Jurkowski --- .../patches/101-fix-no-reset-routine-segfault.patch | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 utils/owfs/patches/101-fix-no-reset-routine-segfault.patch diff --git a/utils/owfs/patches/101-fix-no-reset-routine-segfault.patch b/utils/owfs/patches/101-fix-no-reset-routine-segfault.patch new file mode 100644 index 000000000..731c4a04e --- /dev/null +++ b/utils/owfs/patches/101-fix-no-reset-routine-segfault.patch @@ -0,0 +1,13 @@ +--- a/module/owlib/src/c/ow_reset.c ++++ b/module/owlib/src/c/ow_reset.c +@@ -21,6 +21,10 @@ RESET_TYPE BUS_reset(const struct parsed + struct connection_in * in = pn->selected_connection ; + STAT_ADD1_BUS(e_bus_resets, in); + ++ if ( in->iroutines.reset == NO_RESET_ROUTINE ) { ++ return BUS_RESET_OK; ++ } ++ + switch ( (in->iroutines.reset) (pn) ) { + case BUS_RESET_OK: + in->reconnect_state = reconnect_ok; // Flag as good! From a240aa95791893bf623dcb5279074b4cf16506ce Mon Sep 17 00:00:00 2001 From: Marcin Jurkowski Date: Wed, 2 Sep 2015 23:58:13 +0200 Subject: [PATCH 5/5] owfs: convert init scripts to procd style Convert init.d scripts to use procd and take advantage of respawn feature. Signed-off-by: Marcin Jurkowski --- utils/owfs/files/owfs.conf | 7 +- utils/owfs/files/owfs.init | 113 +++++++++++++++++---------------- utils/owfs/files/owftpd.conf | 7 +- utils/owfs/files/owftpd.init | 109 ++++++++++++++++--------------- utils/owfs/files/owhttpd.conf | 7 +- utils/owfs/files/owhttpd.init | 108 +++++++++++++++++-------------- utils/owfs/files/owserver.conf | 7 +- utils/owfs/files/owserver.init | 107 +++++++++++++++++-------------- 8 files changed, 249 insertions(+), 216 deletions(-) diff --git a/utils/owfs/files/owfs.conf b/utils/owfs/files/owfs.conf index 3bb30a542..b4859897a 100644 --- a/utils/owfs/files/owfs.conf +++ b/utils/owfs/files/owfs.conf @@ -1,11 +1,10 @@ config owfs 'owfs' option enabled 0 - option uid 0 - option gid 0 + option user root option readonly 0 option mountpoint '/mnt/owfs' option fuse_allow_other 0 option fuse_open_opt '' option error_level 0 - option options '' - list devices '-s localhost:4304' + list devices '-s' + list devices 'localhost:4304' diff --git a/utils/owfs/files/owfs.init b/utils/owfs/files/owfs.init index e70820fee..83c8913a0 100644 --- a/utils/owfs/files/owfs.init +++ b/utils/owfs/files/owfs.init @@ -1,75 +1,82 @@ #!/bin/sh /etc/rc.common -# Copyright (C) 2009-2012 OpenWrt.org +# Copyright (C) 2009-2015 OpenWrt.org -START=99 +START=95 +USE_PROCD=1 -SERVICE_WRITE_PID=1 -SERVICE_DAEMONIZE=1 +PROG=/usr/bin/owfs -# Workaround insufficient /dev/fuse permissions and the lack of /etc/fuse.conf -DEFAULT_SERVICE_UID=0 -DEFAULT_SERVICE_GID=0 +append_arg() { + local cfg="$1" + local var="$2" + local opt="$3" + local def="$4" + local val -append_device() { - append devices "$1" + config_get val "$cfg" "$var" + [ -n "$val" -o -n "$def" ] && procd_append_param command $opt "${val:-$def}" } +append_bool() { + local cfg="$1" + local var="$2" + local opt="$3" + local def="$4" + local val -start_owfs_daemon() { - local program="$1" - local config="$1" - local args="--foreground --error_print=1 $2" + config_get_bool val "$cfg" "$var" "$def" + [ "$val" = 1 ] && procd_append_param command "$opt" +} +append_plain() { + procd_append_param command "$1" +} +append_param() { + local cfg="$1" + local var="$2" + local opt="$3" + local def="$4" + local val + + config_get val "$cfg" "$var" + [ -n "$val" -o -n "$def" ] && procd_append_param "$opt" "${val:-$def}" +} + +start_instance() { + local cfg="$1" local enabled - config_get_bool enabled "$config" enabled 0 - [ "${enabled}" -eq 0 ] && return 1 - local readonly - config_get_bool readonly "$config" readonly 0 - [ "${readonly}" -eq 1 ] && append args "--readonly" + config_get_bool enabled "$cfg" 'enabled' '0' + [ "$enabled" = 0 ] && return 1 - local error_level - config_get error_level "$config" error_level - [ -n "${error_level}" ] && append args "--error_level=${error_level}" + procd_open_instance - local options - config_get options "$config" options + procd_set_param command "$PROG" --foreground --error_print=1 - devices="" - config_list_foreach "$config" devices append_device + # common parameters + append_bool "$cfg" readonly "--readonly" + append_arg "$cfg" error_level "--error_level" + config_list_foreach "$cfg" options append_plain + config_list_foreach "$cfg" devices append_plain + append_param "$cfg" user user - config_get SERVICE_UID "$config" uid "$DEFAULT_SERVICE_UID" - config_get SERVICE_GID "$config" gid "$DEFAULT_SERVICE_GID" + # owfs-specific + append_arg "$cfg" mountpoint "--mountpoint" /mnt/owfs + append_bool "$cfg" fuse_allow_other "--allow_other" + append_arg "$cfg" fuse_open_opt "--fuse_open_opt" + + # don't respawn fuse + + procd_close_instance - service_start "/usr/bin/$program" $args $options $devices } -start_owfs() { - local config="owfs" - local args="" - - config_load "$config" - - local mountpoint - config_get mountpoint "$config" mountpoint /mnt/owfs - append args "--mountpoint=${mountpoint}" - - local fuse_allow_other - config_get_bool fuse_allow_other "$config" fuse_allow_other 0 - [ "${fuse_allow_other}" -eq 1 ] && append args "--allow_other" - - local fuse_open_opt - config_get fuse_open_opt "$config" fuse_open_opt - [ -n "${fuse_open_opt}" ] && append args "--fuse_open_opt=\"${fuse_open_opt}\"" - - start_owfs_daemon "$config" "$args" +service_triggers() { + procd_add_reload_trigger owfs } -start() { - start_owfs -} - -stop() { - service_stop /usr/bin/owfs +start_service() { + config_load owfs + config_foreach start_instance owfs } diff --git a/utils/owfs/files/owftpd.conf b/utils/owfs/files/owftpd.conf index 88322c941..100162e2a 100644 --- a/utils/owfs/files/owftpd.conf +++ b/utils/owfs/files/owftpd.conf @@ -1,9 +1,8 @@ config owftpd 'owftpd' option enabled 0 - option uid 0 - option gid 0 + option user root option readonly 0 option port 21 option error_level 0 - option options '' - list devices '-s localhost:4304' + list devices '-s' + list devices 'localhost:4304' diff --git a/utils/owfs/files/owftpd.init b/utils/owfs/files/owftpd.init index 010b2b939..a7e17c938 100644 --- a/utils/owfs/files/owftpd.init +++ b/utils/owfs/files/owftpd.init @@ -1,72 +1,81 @@ #!/bin/sh /etc/rc.common -# Copyright (C) 2009-2012 OpenWrt.org +# Copyright (C) 2009-2015 OpenWrt.org -START=99 +START=95 +USE_PROCD=1 -SERVICE_WRITE_PID=1 -SERVICE_DAEMONIZE=1 +PROG=/usr/bin/owftpd -# Needed for restricted TCP port 21 -DEFAULT_SERVICE_UID=0 -DEFAULT_SERVICE_GID=0 +append_arg() { + local cfg="$1" + local var="$2" + local opt="$3" + local def="$4" + local val -append_device() { - append devices "$1" + config_get val "$cfg" "$var" + [ -n "$val" -o -n "$def" ] && procd_append_param command $opt "${val:-$def}" } +append_bool() { + local cfg="$1" + local var="$2" + local opt="$3" + local def="$4" + local val -start_owfs_daemon() { - local program="$1" - local config="$1" - local args="--foreground --error_print=1 $2" + config_get_bool val "$cfg" "$var" "$def" + [ "$val" = 1 ] && procd_append_param command "$opt" +} +append_plain() { + procd_append_param command "$1" +} +append_param() { + local cfg="$1" + local var="$2" + local opt="$3" + local def="$4" + local val + + config_get val "$cfg" "$var" + [ -n "$val" -o -n "$def" ] && procd_append_param "$opt" "${val:-$def}" +} + +start_instance() { + local cfg="$1" local enabled - config_get_bool enabled "$config" enabled 0 - [ "${enabled}" -eq 0 ] && return 1 - local readonly - config_get_bool readonly "$config" readonly 0 - [ "${readonly}" -eq 1 ] && append args "--readonly" + config_get_bool enabled "$cfg" 'enabled' '0' + [ "$enabled" = 0 ] && return 1 - local error_level - config_get error_level "$config" error_level - [ -n "${error_level}" ] && append args "--error_level=${error_level}" + procd_open_instance - local options - config_get options "$config" options + procd_set_param command "$PROG" --foreground --error_print=1 - devices="" - config_list_foreach "$config" devices append_device + # common parameters + append_bool "$cfg" readonly "--readonly" + append_arg "$cfg" error_level "--error_level" + config_list_foreach "$cfg" options append_plain + config_list_foreach "$cfg" devices append_plain + append_param "$cfg" user user - config_get SERVICE_UID "$config" uid "$DEFAULT_SERVICE_UID" - config_get SERVICE_GID "$config" gid "$DEFAULT_SERVICE_GID" + # owftpd-specific + append_arg "$cfg" port "--port" + append_arg "$cfg" max_connections "--max_connections" + + procd_set_param respawn + + procd_close_instance - service_start "/usr/bin/$program" $args $options $devices } -start_owftpd() { - local config="owftpd" - local args="" - - config_load "$config" - - local port - config_get port "$config" port - [ -n "${port}" ] && append args "--port=${port}" - - local max_connections - config_get max_connections "$config" max_connections - [ -n "${max_connections}" ] && append args "--max_connections=${max_connections}" - - start_owfs_daemon "$config" "$args" +service_triggers() { + procd_add_reload_trigger owftpd } - -start() { - start_owftpd -} - -stop() { - service_stop /usr/bin/owftpd +start_service() { + config_load owftpd + config_foreach start_instance owftpd } diff --git a/utils/owfs/files/owhttpd.conf b/utils/owfs/files/owhttpd.conf index e49e4ceb3..a314cd1ea 100644 --- a/utils/owfs/files/owhttpd.conf +++ b/utils/owfs/files/owhttpd.conf @@ -1,9 +1,8 @@ config owhttpd 'owhttpd' option enabled 0 - option uid 65534 - option gid 65534 + option user root option readonly 0 option port 3001 option error_level 0 - option options '' - list devices '-s localhost:4304' + list devices '-s' + list devices 'localhost:4304' diff --git a/utils/owfs/files/owhttpd.init b/utils/owfs/files/owhttpd.init index fdabdbc26..868c9b419 100644 --- a/utils/owfs/files/owhttpd.init +++ b/utils/owfs/files/owhttpd.init @@ -1,71 +1,81 @@ #!/bin/sh /etc/rc.common -# Copyright (C) 2009-2012 OpenWrt.org +# Copyright (C) 2009-2015 OpenWrt.org -START=99 +START=95 +USE_PROCD=1 -SERVICE_WRITE_PID=1 -SERVICE_DAEMONIZE=1 +PROG=/usr/bin/owhttpd -DEFAULT_SERVICE_UID=65534 -DEFAULT_SERVICE_GID=65534 +append_arg() { + local cfg="$1" + local var="$2" + local opt="$3" + local def="$4" + local val -append_device() { - append devices "$1" + config_get val "$cfg" "$var" + [ -n "$val" -o -n "$def" ] && procd_append_param command $opt "${val:-$def}" } +append_bool() { + local cfg="$1" + local var="$2" + local opt="$3" + local def="$4" + local val -start_owfs_daemon() { - local program="$1" - local config="$1" - local args="--foreground --error_print=1 $2" + config_get_bool val "$cfg" "$var" "$def" + [ "$val" = 1 ] && procd_append_param command "$opt" +} +append_plain() { + procd_append_param command "$1" +} +append_param() { + local cfg="$1" + local var="$2" + local opt="$3" + local def="$4" + local val + + config_get val "$cfg" "$var" + [ -n "$val" -o -n "$def" ] && procd_append_param "$opt" "${val:-$def}" +} + +start_instance() { + local cfg="$1" local enabled - config_get_bool enabled "$config" enabled 0 - [ "${enabled}" -eq 0 ] && return 1 - local readonly - config_get_bool readonly "$config" readonly 0 - [ "${readonly}" -eq 1 ] && append args "--readonly" + config_get_bool enabled "$cfg" 'enabled' '0' + [ "$enabled" = 0 ] && return 1 - local error_level - config_get error_level "$config" error_level - [ -n "${error_level}" ] && append args "--error_level=${error_level}" + procd_open_instance - local options - config_get options "$config" options + procd_set_param command "$PROG" --foreground --error_print=1 - devices="" - config_list_foreach "$config" devices append_device + # common parameters + append_bool "$cfg" readonly "--readonly" + append_arg "$cfg" error_level "--error_level" + config_list_foreach "$cfg" options append_plain + config_list_foreach "$cfg" devices append_plain + append_param "$cfg" user user - config_get SERVICE_UID "$config" uid "$DEFAULT_SERVICE_UID" - config_get SERVICE_GID "$config" gid "$DEFAULT_SERVICE_GID" + # owhttpd-specific + append_arg "$cfg" port "--port" + append_arg "$cfg" max_connections "--max_connections" + + procd_set_param respawn + + procd_close_instance - service_start "/usr/bin/$program" $args $options $devices } -start_owhttpd() { - local config="owhttpd" - local args="" - - config_load "$config" - - local port - config_get port "$config" port - [ -n "${port}" ] && append args "--port=${port}" - - local max_connections - config_get max_connections "$config" max_connections - [ -n "${max_connections}" ] && append args "--max_connections=${max_connections}" - - start_owfs_daemon "$config" "$args" +service_triggers() { + procd_add_reload_trigger owhttpd } - -start() { - start_owhttpd -} - -stop() { - service_stop /usr/bin/owhttpd +start_service() { + config_load owhttpd + config_foreach start_instance owhttpd } diff --git a/utils/owfs/files/owserver.conf b/utils/owfs/files/owserver.conf index e00089462..ceb8a61e6 100644 --- a/utils/owfs/files/owserver.conf +++ b/utils/owfs/files/owserver.conf @@ -1,9 +1,8 @@ config owserver 'owserver' option enabled 0 - option uid 65534 - option gid 65534 + option user root option readonly 0 option port 4304 option error_level 0 - option options '' - list devices '-d /dev/ttyUSB0' + list devices '-d' + list devices '/dev/ttyUSB0' diff --git a/utils/owfs/files/owserver.init b/utils/owfs/files/owserver.init index bbf870d04..7f91aeec0 100644 --- a/utils/owfs/files/owserver.init +++ b/utils/owfs/files/owserver.init @@ -1,70 +1,81 @@ #!/bin/sh /etc/rc.common -# Copyright (C) 2009-2012 OpenWrt.org +# Copyright (C) 2009-2015 OpenWrt.org -START=98 +START=90 +USE_PROCD=1 -SERVICE_WRITE_PID=1 -SERVICE_DAEMONIZE=1 +PROG=/usr/bin/owserver -DEFAULT_SERVICE_UID=65534 -DEFAULT_SERVICE_GID=65534 +append_arg() { + local cfg="$1" + local var="$2" + local opt="$3" + local def="$4" + local val -append_device() { - append devices "$1" + config_get val "$cfg" "$var" + [ -n "$val" -o -n "$def" ] && procd_append_param command $opt "${val:-$def}" } +append_bool() { + local cfg="$1" + local var="$2" + local opt="$3" + local def="$4" + local val -start_owfs_daemon() { - local program="$1" - local config="$1" - local args="--foreground --error_print=1 $2" + config_get_bool val "$cfg" "$var" "$def" + [ "$val" = 1 ] && procd_append_param command "$opt" +} +append_plain() { + procd_append_param command "$1" +} +append_param() { + local cfg="$1" + local var="$2" + local opt="$3" + local def="$4" + local val + + config_get val "$cfg" "$var" + [ -n "$val" -o -n "$def" ] && procd_append_param "$opt" "${val:-$def}" +} + +start_instance() { + local cfg="$1" local enabled - config_get_bool enabled "$config" enabled 0 - [ "${enabled}" -eq 0 ] && return 1 - local readonly - config_get_bool readonly "$config" readonly 0 - [ "${readonly}" -eq 1 ] && append args "--readonly" + config_get_bool enabled "$cfg" 'enabled' '0' + [ "$enabled" = 0 ] && return 1 - local error_level - config_get error_level "$config" error_level - [ -n "${error_level}" ] && append args "--error_level=${error_level}" + procd_open_instance - local options - config_get options "$config" options + procd_set_param command "$PROG" --foreground --error_print=1 - devices="" - config_list_foreach "$config" devices append_device + # common parameters + append_bool "$cfg" readonly "--readonly" + append_arg "$cfg" error_level "--error_level" + config_list_foreach "$cfg" options append_plain + config_list_foreach "$cfg" devices append_plain + append_param "$cfg" user user - config_get SERVICE_UID "$config" uid "$DEFAULT_SERVICE_UID" - config_get SERVICE_GID "$config" gid "$DEFAULT_SERVICE_GID" + # owserver-specific + append_arg "$cfg" port "--port" + append_arg "$cfg" max_connections "--max_connections" + + procd_set_param respawn + + procd_close_instance - service_start "/usr/bin/$program" $args $options $devices } -start_owserver() { - local config="owserver" - local args="" - - config_load "$config" - - local port - config_get port "$config" port - [ -n "${port}" ] && append args "--port=${port}" - - local max_connections - config_get max_connections "$config" max_connections - [ -n "${max_connections}" ] && append args "--max_connections=${max_connections}" - - start_owfs_daemon "$config" "$args" +service_triggers() { + procd_add_reload_trigger owserver } -start() { - start_owserver -} - -stop() { - service_stop /usr/bin/owserver +start_service() { + config_load owserver + config_foreach start_instance owserver }