From aa050789feab2da5c2ab4565e2a470d306b78e2f Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Sat, 27 Jul 2019 23:33:35 +0200 Subject: [PATCH] vis: Convert to procd based init script The legacy init script had various problems in comparison with procd based init scripts. It wasn't able to correctly track the running process instance and thus could: * accidentally kill another (non init controlled) daemon instance when stop is used * not restart the daemon depending on config changes when reload is used * not automatically start/restart daemon when the used netdev was created/recreated The information about a running instance and its parameters can now be handled by a global controller (procd). The process must not fork anymore and leave the control to procd. The process with its parameters can then be used by procd to trigger the stop/start of the process at the right time. Signed-off-by: Sven Eckelmann --- vis/Makefile | 2 +- vis/files/etc/init.d/vis | 33 ++++++++--- ...able-forking-to-background-in-debug_.patch | 56 +++++++++++++++++++ 3 files changed, 82 insertions(+), 9 deletions(-) create mode 100644 vis/patches/0001-Allow-one-to-disable-forking-to-background-in-debug_.patch diff --git a/vis/Makefile b/vis/Makefile index af58f5e..abd0a60 100644 --- a/vis/Makefile +++ b/vis/Makefile @@ -13,7 +13,7 @@ PKG_SOURCE_PROTO:=git PKG_SOURCE_URL:=https://git.open-mesh.org/vis.git PKG_REV:=e141311c6a4fc824efbad536c137ed279905d825 PKG_VERSION:=1440 -PKG_RELEASE:=0 +PKG_RELEASE:=2 PKG_LICENSE:=GPL-2.0 PKG_SOURCE_VERSION:=$(PKG_REV) diff --git a/vis/files/etc/init.d/vis b/vis/files/etc/init.d/vis index ef18eb7..8c19f13 100644 --- a/vis/files/etc/init.d/vis +++ b/vis/files/etc/init.d/vis @@ -1,19 +1,36 @@ #!/bin/sh /etc/rc.common START=90 +USE_PROCD=1 -start () { - interface=$(uci get vis.general.interface) +vis_start() { + local config="$1" + local interface + + [ "$config" = "general" ] || return 1 + + config_get interface "$config" interface if [ "$interface" = "" ]; then echo $1 Error, you must specify at least a network interface - exit + return 1 fi - vis_args=$interface - vis $vis_args >/dev/null 2>&1 + procd_open_instance "${config}" + procd_set_param command /usr/sbin/vis + procd_append_param command -D + procd_append_param command ${interface} + procd_set_param netdev $interface + procd_close_instance } -stop () { - killall vis +start_service() { + config_load "vis" + config_foreach vis_start vis } - +service_triggers() { + procd_add_reload_trigger "vis" + + procd_open_trigger + procd_add_raw_trigger "interface.*" 1000 /etc/init.d/vis reload + procd_close_trigger +} diff --git a/vis/patches/0001-Allow-one-to-disable-forking-to-background-in-debug_.patch b/vis/patches/0001-Allow-one-to-disable-forking-to-background-in-debug_.patch new file mode 100644 index 0000000..3f6cf49 --- /dev/null +++ b/vis/patches/0001-Allow-one-to-disable-forking-to-background-in-debug_.patch @@ -0,0 +1,56 @@ +From: Sven Eckelmann +Date: Sun, 1 Dec 2013 14:39:00 +0100 +Subject: Allow one to disable forking to background in debug_mode 0 + +--- + posix/init.c | 19 ++++++++++++++----- + 1 file changed, 14 insertions(+), 5 deletions(-) + +--- a/vis.c ++++ b/vis.c +@@ -58,6 +58,7 @@ buffer_t *fillme = NULL; + + static int8_t stop; + uint8_t debug_level = 0; ++static int no_detach = 0; + + formats selected_formats = dot_draw; + +@@ -716,6 +717,7 @@ void print_usage() { + printf( "Usage: vis \n" ); + printf( "\t-j output mesh topology as json on port %d\n", JSON_PORT ); + printf( "\t-d debug level\n" ); ++ printf( "\t-D run in foreground\n" ); + printf( "\t-h help\n" ); + printf( "\t-v Version\n\n" ); + printf( "Olsrs3d / Meshs3d is an application to visualize a mesh network.\nIt is a part of s3d, have a look at s3d.berlios.de\n\n" ); +@@ -736,7 +738,7 @@ int main( int argc, char **argv ) { + fd_set wait_sockets, tmp_wait_sockets; + + +- while ( ( optchar = getopt ( argc, argv, "jd:hv" ) ) != -1 ) { ++ while ( ( optchar = getopt ( argc, argv, "jd:hvD" ) ) != -1 ) { + + switch( optchar ) { + +@@ -771,6 +773,11 @@ int main( int argc, char **argv ) { + selected_formats |= json; + found_args++; + break; ++ ++ case 'D': ++ no_detach = 1; ++ found_args++; ++ break; + + default: + print_usage(); +@@ -889,7 +896,7 @@ int main( int argc, char **argv ) { + + + /* daemonize */ +- if ( debug_level == 0 ) { ++ if ( debug_level == 0 && !no_detach) { + + if ( my_daemon() < 0 ) + exit_error( "Error - can't fork to background: %s\n", strerror(errno) ); -- 2.30.2