Merge pull request #489 from ecsv/batmand-procd
authorelektra42 <onelektra@gmx.net>
Mon, 29 Jul 2019 09:35:35 +0000 (11:35 +0200)
committerGitHub <noreply@github.com>
Mon, 29 Jul 2019 09:35:35 +0000 (11:35 +0200)
batmand/vis: Convert to procd based init scripts

batmand/Makefile
batmand/files/etc/init.d/batmand
batmand/patches/0001-Allow-one-to-disable-forking-to-background-in-debug_.patch [new file with mode: 0644]
vis/Makefile
vis/files/etc/init.d/vis
vis/patches/0001-Allow-one-to-disable-forking-to-background-in-debug_.patch [new file with mode: 0644]

index 47d8741da2122157c3f370e69427695ba117c95a..a6afa469007f625165b401d55838ba59c834bfaa 100644 (file)
@@ -13,7 +13,7 @@ PKG_SOURCE_PROTO:=git
 PKG_SOURCE_URL:=https://git.open-mesh.org/batmand.git
 PKG_REV:=b67a7087b51d7a5e90d27ac39116d1f57257c86e
 PKG_VERSION:=1440
-PKG_RELEASE:=0
+PKG_RELEASE:=1
 PKG_LICENSE:=GPL-2.0
 
 PKG_SOURCE_VERSION:=$(PKG_REV)
index add4ec8249fe73459c1ae9a7358aba5b4b07081a..8361e7255ca8c621023d306e38832fb6d9fb7b4f 100644 (file)
@@ -1,21 +1,39 @@
 #!/bin/sh /etc/rc.common
 START=90
+USE_PROCD=1
 
-start () {
-       interface=$(uci get batmand.general.interface)
+batmand_start() {
+       local config="$1"
+       local batman_args
+       local interface
+       local hnas
+       local gateway_class
+       local originator_interval
+       local preferred_gateway
+       local routing_class
+       local visualisation_srv
+       local local policy_routing_script
+       local disable_client_nat
+       local disable_aggregation
+
+       [ "$config" = "general" ] || return 1
+
+       config_get interface "$config" interface
        if [ "$interface" = "" ]; then
                echo $1 Error, you must specify at least a network interface
-               exit
-       fi
-       hnas=$(uci get batmand.general.hna)
-       gateway_class=$(uci get batmand.general.gateway_class)
-       originator_interval=$(uci get batmand.general.originator_interval)
-       preferred_gateway=$(uci get batmand.general.preferred_gateway)
-       routing_class=$(uci get batmand.general.routing_class)
-       visualisation_srv=$(uci get batmand.general.visualisation_srv)
-       policy_routing_script=$(uci get batmand.general.policy_routing_script)
-       disable_client_nat=$(uci get batmand.general.disable_client_nat)
-       disable_aggregation=$(uci get batmand.general.disable_aggregation)
+               return 1
+       fi
+
+       config_get hnas "$config" hna
+       config_get gateway_class "$config" gateway_class
+       config_get originator_interval "$config" originator_interval
+       config_get preferred_gateway "$config" preferred_gateway
+       config_get routing_class "$config" routing_class
+       config_get visualisation_srv "$config" visualisation_srv
+       config_get policy_routing_script "$config" policy_routing_script
+       config_get disable_client_nat "$config" disable_client_nat
+       config_get disable_aggregation "$config" disable_aggregation
+
        batman_args=""
 
        for hna in $hnas; do
@@ -54,10 +72,20 @@ start () {
                batman_args=${batman_args}'--disable-aggregation '
        fi
 
-       batman_args=${batman_args}$interface
-       batmand $batman_args >/dev/null 2>&1
+       procd_open_instance "${config}"
+       procd_set_param command /usr/sbin/batmand
+       procd_append_param command --no-detach
+       procd_append_param command ${batman_args}
+       procd_append_param command ${interface}
+       procd_set_param netdev ${interface}
+       procd_close_instance
+}
+
+start_service() {
+       config_load "batmand"
+       config_foreach batmand_start batmand
 }
 
-stop () {
-       killall batmand
+service_triggers() {
+       procd_add_reload_trigger "batmand"
 }
diff --git a/batmand/patches/0001-Allow-one-to-disable-forking-to-background-in-debug_.patch b/batmand/patches/0001-Allow-one-to-disable-forking-to-background-in-debug_.patch
new file mode 100644 (file)
index 0000000..90527e6
--- /dev/null
@@ -0,0 +1,68 @@
+From: Sven Eckelmann <sven@narfation.org>
+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(-)
+
+diff --git a/posix/init.c b/posix/init.c
+index afd409f..901c65a 100644
+--- a/posix/init.c
++++ b/posix/init.c
+@@ -44,6 +44,7 @@
+ #define IOCSETDEV 1
+ int8_t stop;
++int no_detach = 0;
+@@ -159,6 +160,7 @@ void apply_init_args( int argc, char *argv[] ) {
+               {"purge-timeout",     required_argument,       0, 'q'},
+               {"disable-aggregation",     no_argument,       0, 'x'},
+               {"disable-client-nat",     no_argument,       0, 'z'},
++              {"no-detach",     no_argument,       0, 'D'},
+               {0, 0, 0, 0}
+       };
+@@ -166,7 +168,7 @@ void apply_init_args( int argc, char *argv[] ) {
+       stop = 0;
+       prog_name = argv[0];
+-      while ( ( optchar = getopt_long( argc, argv, "a:A:bcd:hHio:g:p:r:s:vV", long_options, &option_index ) ) != -1 ) {
++      while ( ( optchar = getopt_long( argc, argv, "a:A:bcd:hHio:g:p:r:s:vVD", long_options, &option_index ) ) != -1 ) {
+               switch ( optchar ) {
+@@ -378,6 +380,11 @@ void apply_init_args( int argc, char *argv[] ) {
+                               found_args++;
+                               break;
++                      case 'D':
++                              no_detach = 1;
++                              found_args++;
++                              break;
++
+                       case 'h':
+                       default:
+                               usage();
+@@ -536,12 +543,14 @@ void apply_init_args( int argc, char *argv[] ) {
+               /* daemonize */
+               if (debug_level == 0) {
+-                      if (my_daemon() < 0) {
++                      if (!no_detach) {
++                              if (my_daemon() < 0) {
+-                              printf("Error - can't fork to background: %s\n", strerror(errno));
+-                              restore_defaults();
+-                              exit(EXIT_FAILURE);
++                                      printf("Error - can't fork to background: %s\n", strerror(errno));
++                                      restore_defaults();
++                                      exit(EXIT_FAILURE);
++                              }
+                       }
+                       openlog("batmand", LOG_PID, LOG_DAEMON);
index 5da78b8e71d689cf8ae370511dae307582c25219..d806513d0e42bbf574c7606fc31055ef88fc953c 100644 (file)
@@ -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)
index ef18eb718c7902249c7ea52a3d2adb73974a564a..8c19f135e2e7c9abce214db1182ecbbf257e7de7 100644 (file)
@@ -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 (file)
index 0000000..3f6cf49
--- /dev/null
@@ -0,0 +1,56 @@
+From: Sven Eckelmann <sven@narfation.org>
+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 <interface(s)> \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) );