From e40f0ea06fe7433eff71c4561a4776f068e97bc7 Mon Sep 17 00:00:00 2001 From: Sebastian Kemper Date: Tue, 26 Dec 2017 14:14:47 +0100 Subject: [PATCH 1/5] libre: add forgotten define "OPENWRT" needs to be defined for 001-extend-ninit-nclose-check.patch to work. Signed-off-by: Sebastian Kemper --- libs/re/Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/re/Makefile b/libs/re/Makefile index 5ce0c58..ddb51cb 100644 --- a/libs/re/Makefile +++ b/libs/re/Makefile @@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=re PKG_VERSION:=0.5.6 -PKG_RELEASE:=3 +PKG_RELEASE:=4 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=http://www.creytiv.com/pub @@ -45,6 +45,9 @@ endef # LD is changed to TARGET_CC to fix build failures on x86 32bit. Without this # there's no linking to ssp, which results in undefined references. +# used by 001-extend-ninit-nclose-check.patch +TARGET_CFLAGS+=-DOPENWRT + ifneq ($(CONFIG_USE_GLIBC)$(CONFIG_USE_MUSL),) TARGET_CFLAGS+=-D_GNU_SOURCE endif From 1c11a5925018451de19c3e5685f1cb0b406160fd Mon Sep 17 00:00:00 2001 From: Sebastian Kemper Date: Tue, 26 Dec 2017 14:26:45 +0100 Subject: [PATCH 2/5] baresip + restund: delete faulty patch The patch is wrong. It may cause errors of the "illegal instruction" variety. The libre package fix in commit e40f0ea06fe7433eff71c4561a4776f068e97bc7 makes this patch unnecessary anyway. Drop it. Signed-off-by: Sebastian Kemper --- net/baresip/Makefile | 2 +- net/baresip/patches/001-fix-linker-call.patch | 14 -------------- net/restund/Makefile | 2 +- net/restund/patches/001-fix-linker-call.patch | 14 -------------- 4 files changed, 2 insertions(+), 30 deletions(-) delete mode 100644 net/baresip/patches/001-fix-linker-call.patch delete mode 100644 net/restund/patches/001-fix-linker-call.patch diff --git a/net/baresip/Makefile b/net/baresip/Makefile index 958f124..b238271 100644 --- a/net/baresip/Makefile +++ b/net/baresip/Makefile @@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=baresip PKG_VERSION:=0.5.6 -PKG_RELEASE:=4 +PKG_RELEASE:=5 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=http://www.creytiv.com/pub diff --git a/net/baresip/patches/001-fix-linker-call.patch b/net/baresip/patches/001-fix-linker-call.patch deleted file mode 100644 index 0df5ced..0000000 --- a/net/baresip/patches/001-fix-linker-call.patch +++ /dev/null @@ -1,14 +0,0 @@ ---- a/Makefile -+++ b/Makefile -@@ -199,9 +199,9 @@ libbaresip.pc: - $(BIN): $(APP_OBJS) - @echo " LD $@" - ifneq ($(GPROF),) -- $(HIDE)$(LD) $(LFLAGS) $(APP_LFLAGS) $^ ../re/libre.a $(LIBS) -o $@ -+ $(HIDE)$(LD) $(LFLAGS) $(SH_LFLAGS) $(APP_LFLAGS) $^ ../re/libre.a $(LIBS) -o $@ - else -- $(HIDE)$(LD) $(LFLAGS) $(APP_LFLAGS) $^ \ -+ $(HIDE)$(LD) $(LFLAGS) $(SH_LFLAGS) $(APP_LFLAGS) $^ \ - -L$(LIBRE_SO) -lre $(LIBS) -o $@ - endif - diff --git a/net/restund/Makefile b/net/restund/Makefile index 21c956e..6206be4 100644 --- a/net/restund/Makefile +++ b/net/restund/Makefile @@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=restund PKG_VERSION:=0.4.12 -PKG_RELEASE:=4 +PKG_RELEASE:=5 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=http://www.creytiv.com/pub diff --git a/net/restund/patches/001-fix-linker-call.patch b/net/restund/patches/001-fix-linker-call.patch deleted file mode 100644 index abae86c..0000000 --- a/net/restund/patches/001-fix-linker-call.patch +++ /dev/null @@ -1,14 +0,0 @@ ---- a/Makefile -+++ b/Makefile -@@ -99,9 +99,9 @@ all: $(MOD_BINS) $(BIN) - $(BIN): $(OBJS) - @echo " LD $@" - ifneq ($(GPROF),) -- @$(LD) $(LFLAGS) $(APP_LFLAGS) $^ ../re/libre.a $(LIBS) -o $@ -+ @$(LD) $(LFLAGS) $(SH_LFLAGS) $(APP_LFLAGS) $^ ../re/libre.a $(LIBS) -o $@ - else -- @$(LD) $(LFLAGS) $(APP_LFLAGS) $^ -L$(LIBRE_SO) -lre $(LIBS) -o $@ -+ @$(LD) $(LFLAGS) $(SH_LFLAGS) $(APP_LFLAGS) $^ -L$(LIBRE_SO) -lre $(LIBS) -o $@ - endif - - $(BUILD)/%.o: %.c $(BUILD) Makefile $(APP_MK) From 4219368092c7d4bc84b70646aed8ab2cfe5d0668 Mon Sep 17 00:00:00 2001 From: Sebastian Kemper Date: Tue, 26 Dec 2017 14:34:45 +0100 Subject: [PATCH 3/5] baresip suite: improve MAKE_FLAGS - add CROSS_COMPILE and OS to MAKE_FLAGS; this should help when compiling on other OSes, e.g. Darwin. - move RELEASE up (alphabetical sort) Signed-off-by: Sebastian Kemper --- libs/re/Makefile | 6 ++++-- libs/rem/Makefile | 6 ++++-- net/baresip/Makefile | 4 +++- net/restund/Makefile | 4 +++- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/libs/re/Makefile b/libs/re/Makefile index ddb51cb..235587b 100644 --- a/libs/re/Makefile +++ b/libs/re/Makefile @@ -53,11 +53,13 @@ TARGET_CFLAGS+=-D_GNU_SOURCE endif MAKE_FLAGS+= \ + CROSS_COMPILE="$(TARGET_CROSS)" \ EXTRA_LFLAGS="$(TARGET_LDFLAGS)" \ LD="$(TARGET_CC)" \ + OS=linux \ + RELEASE=1 \ SYSROOT="$(shell $(FIND) $(TOOLCHAIN_DIR) -path '*/include/pthread.h' | sed -ne '1s|/include/pthread.h||p')" \ - SYSROOT_ALT="$(STAGING_DIR)/usr" \ - RELEASE=1 + SYSROOT_ALT="$(STAGING_DIR)/usr" define Build/InstallDev $(INSTALL_DIR) $(1)/usr/share/re diff --git a/libs/rem/Makefile b/libs/rem/Makefile index d50ae87..91d42ed 100644 --- a/libs/rem/Makefile +++ b/libs/rem/Makefile @@ -34,14 +34,16 @@ define Package/librem endef MAKE_FLAGS+= \ + CROSS_COMPILE="$(TARGET_CROSS)" \ EXTRA_LFLAGS="$(TARGET_LDFLAGS)" \ LD="$(TARGET_CC)" \ LIBRE_MK="$(STAGING_DIR)/usr/share/re/re.mk" \ LIBRE_INC="$(STAGING_DIR)/usr/include/re" \ LIBRE_SO="$(STAGING_DIR)/usr/lib" \ + OS=linux \ + RELEASE=1 \ SYSROOT="$(shell $(FIND) $(TOOLCHAIN_DIR) -path '*/include/pthread.h' | sed -ne '1s|/include/pthread.h||p')" \ - SYSROOT_ALT="$(STAGING_DIR)/usr" \ - RELEASE=1 + SYSROOT_ALT="$(STAGING_DIR)/usr" define Build/InstallDev $(INSTALL_DIR) $(1)/usr/include diff --git a/net/baresip/Makefile b/net/baresip/Makefile index b238271..7a27f3b 100644 --- a/net/baresip/Makefile +++ b/net/baresip/Makefile @@ -96,15 +96,17 @@ BARESIP_MOD_OPTIONS:= \ $(foreach m,$(baresip-mods),$(baresip-mod-$(m))=$(if $(CONFIG_PACKAGE_baresip-mod-$(m)),1)) MAKE_FLAGS+= \ + CROSS_COMPILE="$(TARGET_CROSS)" \ EXTRA_LFLAGS="$(TARGET_LDFLAGS)" \ LD="$(TARGET_CC)" \ LIBRE_MK="$(STAGING_DIR)/usr/share/re/re.mk" \ LIBRE_INC="$(STAGING_DIR)/usr/include/re" \ LIBRE_SO="$(STAGING_DIR)/usr/lib" \ LIBREM_PATH="$(STAGING_DIR)/usr" \ + OS=linux \ + RELEASE=1 \ SYSROOT="$(shell $(FIND) $(TOOLCHAIN_DIR) -path '*/include/pthread.h' | sed -ne '1s|/include/pthread.h||p')" \ SYSROOT_ALT="$(STAGING_DIR)/usr" \ - RELEASE=1 \ $(BARESIP_MOD_OPTIONS) TARGET_CFLAGS+=-D_GNU_SOURCE diff --git a/net/restund/Makefile b/net/restund/Makefile index 6206be4..28537e9 100644 --- a/net/restund/Makefile +++ b/net/restund/Makefile @@ -47,14 +47,16 @@ RESTUND_MOD_OPTIONS:= \ $(foreach m,$(restund-mods),$(restund-mod-$(m))=$(if $(CONFIG_PACKAGE_restund-mod-$(m)),1)) MAKE_FLAGS+= \ + CROSS_COMPILE="$(TARGET_CROSS)" \ EXTRA_LFLAGS="$(TARGET_LDFLAGS)" \ LD="$(TARGET_CC)" \ LIBRE_MK="$(STAGING_DIR)/usr/share/re/re.mk" \ LIBRE_INC="$(STAGING_DIR)/usr/include/re" \ LIBRE_SO="$(STAGING_DIR)/usr/lib" \ + OS=linux \ + RELEASE=1 \ SYSROOT="$(shell $(FIND) $(TOOLCHAIN_DIR) -path '*/include/pthread.h' | sed -ne '1s|/include/pthread.h||p')" \ SYSROOT_ALT="$(STAGING_DIR)/usr" \ - RELEASE=1 \ $(RESTUND_MOD_OPTIONS) define Package/restund/install From 1de3d36d4bad06f6bb4f6b2b2464525cb69f97e0 Mon Sep 17 00:00:00 2001 From: Sebastian Kemper Date: Tue, 26 Dec 2017 14:58:30 +0100 Subject: [PATCH 4/5] restund: add procd init script - add procd init script - script starts the daemon as user "restund" instead of root - add /etc/default/restund - declare /etc/init.d/restund a configuration file - prevent autostart after upgrade by using ENABLE_RESTUND variable in /etc/default/restund Signed-off-by: Sebastian Kemper --- net/restund/Makefile | 18 ++++++ net/restund/files/restund.default | 8 +++ net/restund/files/restund.init | 92 ++++++++++++++++++++++++++++--- 3 files changed, 110 insertions(+), 8 deletions(-) create mode 100644 net/restund/files/restund.default diff --git a/net/restund/Makefile b/net/restund/Makefile index 28537e9..fa53d2e 100644 --- a/net/restund/Makefile +++ b/net/restund/Makefile @@ -39,6 +39,7 @@ define Package/restund $(call Package/restund/Default) TITLE:=Modular STUN/TURN server DEPENDS:=+libre + USERID:=$(PKG_NAME)=373:$(PKG_NAME)=373 endef restund-mod-mysql:=USE_MYSQL @@ -78,14 +79,31 @@ define Package/restund/install $(SED) \ 's|^\(module_path\)\([ \t]\+\).*$$$$|\1\2/usr/lib/restund/modules|g' \ $(1)/etc/restund.conf + $(INSTALL_DIR) $(1)/etc/default + $(INSTALL_CONF) ./files/restund.default $(1)/etc/default/restund $(INSTALL_DIR) $(1)/etc/init.d $(INSTALL_BIN) ./files/restund.init $(1)/etc/init.d/restund endef define Package/restund/conffiles +/etc/default/restund +/etc/init.d/restund /etc/restund.conf endef +define Package/restund/postinst +#!/bin/sh +if [ -z "$${IPKG_INSTROOT}" ]; then + chown $(PKG_NAME):$(PKG_NAME) /etc/restund.conf + + # Prevent $(PKG_NAME) from auto-starting after an upgrade. The modules may + # not be upgraded yet and the user configuration may need a revision. + sed -i '/^ENABLE_RESTUND="yes"/s/^/#/' \ + /etc/default/$(PKG_NAME) +fi +exit 0 +endef + # # 1. Name # 2. Title diff --git a/net/restund/files/restund.default b/net/restund/files/restund.default new file mode 100644 index 0000000..3e7cbc6 --- /dev/null +++ b/net/restund/files/restund.default @@ -0,0 +1,8 @@ +### restund init configuration ### + +# Uncomment once you verified your configuration, otherwise the init script will +# not start restund. +#ENABLE_RESTUND="yes" + +# The following is added to the command line when starting restund: +OPTIONS="" diff --git a/net/restund/files/restund.init b/net/restund/files/restund.init index d6360ff..ee722ca 100644 --- a/net/restund/files/restund.init +++ b/net/restund/files/restund.init @@ -1,15 +1,91 @@ #!/bin/sh /etc/rc.common -# -# Copyright (C) 2010-2011 OpenWrt.org -# Copyright (C) 2010 Alfred E. Heggestad -# +# Copyright (C) 2017 OpenWrt.org START=60 -start() { - service_start /usr/sbin/restund +USE_PROCD=1 + +#PROCD_DEBUG=1 + +DAEMON=restund +DEFAULT=/etc/default/$DAEMON +LOGGER="/usr/bin/logger -p user.err -s -t $DAEMON" +OPTIONS= +PROG=/usr/sbin/$DAEMON +TIMEOUT=30 + +[ -f $DEFAULT ] && . $DEFAULT + +start_service() { + local dir= + + if [ "$ENABLE_RESTUND" != yes ]; then + $LOGGER User configuration incomplete - not starting $DAEMON + $LOGGER Check ENABLE_RESTUND in $DEFAULT + exit 1 + fi + + procd_open_instance + procd_set_param command $PROG + procd_append_param command \ + -n \ + $OPTIONS + procd_set_param pidfile /var/run/${DAEMON}.pid + # forward stderr to logd + procd_set_param stderr 1 + # forward stdout to logd + procd_set_param stdout 1 + procd_set_param user $DAEMON + procd_close_instance } -stop() { - service_stop /usr/sbin/restund +stop_service() { + local retval= + local mypid= + local timeout=$TIMEOUT + + pgrep $DAEMON &> /dev/null + [ $? -ne 0 ] && exit 0 + + [ -f /var/run/${DAEMON}.pid ] + retval=$? + + # init script could find itself in a scenario where restund was started + # very recently, so make it wait a while for a pid file to appear + while [ $retval -ne 0 -a $timeout -gt 0 ]; do + sleep 1 + [ -f /var/run/${DAEMON}.pid ] + retval=$? + timeout=$(($timeout-1)) + done + + [ $retval -eq 0 ] || { + $LOGGER PID file does not exist + exit 1 + } + + mypid=$(cat /var/run/${DAEMON}.pid) + + [ "$mypid" -gt 1 ] 2> /dev/null || { + $LOGGER PID file contains garbage + exit 1 + } + + timeout=$TIMEOUT + kill $mypid 2>/dev/null + pgrep $DAEMON | grep -w $mypid &>/dev/null + retval=$? + + while [ $retval -eq 0 -a $timeout -gt 0 ]; do + sleep 10 + pgrep $DAEMON | grep -w $mypid &>/dev/null + retval=$? + [ $retval -eq 0 ] && kill $mypid 2>/dev/null + timeout=$(($timeout-10)) + done + + [ $retval -ne 1 ] && { + $LOGGER Failed to stop $DAEMON + exit 1 + } } From 8860618e41c4f90d79eb7c6f4d7cd2edf58c1484 Mon Sep 17 00:00:00 2001 From: Sebastian Kemper Date: Tue, 26 Dec 2017 15:21:25 +0100 Subject: [PATCH 5/5] baresip: add procd init script - add procd init script - script starts the daemon as user "baresip" instead of root - add /etc/default/baresip - add example configuration into /etc/baresip - add conffiles definition - prevent autostart after upgrade by using ENABLE_BARESIP variable in /etc/default/baresip Signed-off-by: Sebastian Kemper --- net/baresip/Makefile | 29 ++++++++++ net/baresip/files/baresip.default | 10 ++++ net/baresip/files/baresip.init | 91 ++++++++++++++++++++++++++++--- 3 files changed, 123 insertions(+), 7 deletions(-) create mode 100644 net/baresip/files/baresip.default diff --git a/net/baresip/Makefile b/net/baresip/Makefile index 7a27f3b..a530821 100644 --- a/net/baresip/Makefile +++ b/net/baresip/Makefile @@ -65,6 +65,7 @@ define Package/baresip $(call Package/baresip/Default) TITLE:=Portable and modular SIP User-Agent with A/V support DEPENDS:=+libre +librem + USERID:=$(PKG_NAME)=374:$(PKG_NAME)=374 MENU:=1 endef @@ -120,10 +121,38 @@ define Package/baresip/install $(1)/usr/lib/baresip/modules $(INSTALL_DIR) $(1)/usr/share/baresip $(CP) $(PKG_INSTALL_DIR)/usr/share/baresip/* $(1)/usr/share/baresip + $(INSTALL_DIR) $(1)/etc/baresip + $(INSTALL_CONF) $(PKG_BUILD_DIR)/docs/examples/{accounts,config,contacts} $(1)/etc/baresip + $(INSTALL_DIR) $(1)/etc/default + $(INSTALL_CONF) ./files/baresip.default $(1)/etc/default/baresip $(INSTALL_DIR) $(1)/etc/init.d $(INSTALL_BIN) ./files/baresip.init $(1)/etc/init.d/baresip endef +define Package/baresip/conffiles +/etc/baresip/accounts +/etc/baresip/config +/etc/baresip/contacts +/etc/default/baresip +/etc/init.d/baresip +endef + +define Package/baresip/postinst +#!/bin/sh +if [ -z "$${IPKG_INSTROOT}" ]; then + chown $(PKG_NAME):$(PKG_NAME) \ + /etc/baresip/accounts \ + /etc/baresip/config \ + /etc/baresip/contacts + + # Prevent $(PKG_NAME) from auto-starting after an upgrade. The modules may + # not be upgraded yet and the user configuration may need a revision. + sed -i '/^ENABLE_BARESIP="yes"/s/^/#/' \ + /etc/default/$(PKG_NAME) +fi +exit 0 +endef + ################## # bareSIP modules # 1. Name diff --git a/net/baresip/files/baresip.default b/net/baresip/files/baresip.default new file mode 100644 index 0000000..b251c80 --- /dev/null +++ b/net/baresip/files/baresip.default @@ -0,0 +1,10 @@ +### bareSIP init configuration ### + +# Uncomment once you verified your configuration, otherwise the init script will +# not start bareSIP. +#ENABLE_BARESIP="yes" + +# The following is added to the command line when starting bareSIP: +OPTIONS="" + +# The configuration for the daemon is done in /etc/baresip! diff --git a/net/baresip/files/baresip.init b/net/baresip/files/baresip.init index e398595..c18c985 100644 --- a/net/baresip/files/baresip.init +++ b/net/baresip/files/baresip.init @@ -1,14 +1,91 @@ #!/bin/sh /etc/rc.common -# Copyright (C) 2010-2011 OpenWrt.org -# Copyright (C) 2010 Alfred E. Heggestad -# +# Copyright (C) 2017 OpenWrt.org START=92 -start() { - service_start /usr/bin/baresip -d +USE_PROCD=1 + +#PROCD_DEBUG=1 + +DAEMON=baresip +DEFAULT=/etc/default/$DAEMON +LOGGER="/usr/bin/logger -p user.err -s -t $DAEMON" +OPTIONS= +PROG=/usr/bin/$DAEMON +TIMEOUT=30 + +[ -f $DEFAULT ] && . $DEFAULT + +start_service() { + local dir= + + if [ "$ENABLE_BARESIP" != yes ]; then + $LOGGER User configuration incomplete - not starting $DAEMON + $LOGGER Check ENABLE_BARESIP in $DEFAULT + exit 1 + fi + + procd_open_instance + procd_set_param command $PROG + procd_append_param command \ + -f /etc/$DAEMON \ + $OPTIONS + procd_set_param pidfile /var/run/${DAEMON}.pid + # forward stderr to logd + procd_set_param stderr 1 + # forward stdout to logd + #procd_set_param stdout 1 + procd_set_param user $DAEMON + procd_close_instance } -stop() { - service_stop /usr/bin/baresip +stop_service() { + local retval= + local mypid= + local timeout=$TIMEOUT + + pgrep $DAEMON &> /dev/null + [ $? -ne 0 ] && exit 0 + + [ -f /var/run/${DAEMON}.pid ] + retval=$? + + # init script could find itself in a scenario where baresip was started + # very recently, so make it wait a while for a pid file to appear + while [ $retval -ne 0 -a $timeout -gt 0 ]; do + sleep 1 + [ -f /var/run/${DAEMON}.pid ] + retval=$? + timeout=$(($timeout-1)) + done + + [ $retval -eq 0 ] || { + $LOGGER PID file does not exist + exit 1 + } + + mypid=$(cat /var/run/${DAEMON}.pid) + + [ "$mypid" -gt 1 ] 2> /dev/null || { + $LOGGER PID file contains garbage + exit 1 + } + + timeout=$TIMEOUT + kill $mypid 2>/dev/null + pgrep $DAEMON | grep -w $mypid &>/dev/null + retval=$? + + while [ $retval -eq 0 -a $timeout -gt 0 ]; do + sleep 10 + pgrep $DAEMON | grep -w $mypid &>/dev/null + retval=$? + [ $retval -eq 0 ] && kill $mypid 2>/dev/null + timeout=$(($timeout-10)) + done + + [ $retval -ne 1 ] && { + $LOGGER Failed to stop $DAEMON + exit 1 + } }