cman: allow late close of stderr file descriptor and free resources
PATCH 1/1 cman: allow late close of stderr file descriptor and free resources
In case debug is enabled, and cman is executed via init script, we leak a fd associated to a file that will grow indefinetely in size.
We address this situation by adding a very specific cman_tool startup option associated to init script, to tell cman to perform a late close of stderr and freeing correctly all resources.
Resolves: rhbz#740385
Signed-off-by Fabio M. Di Nitto <[email protected]>
--- cman/cman_tool/cman_tool.h | 1 + cman/cman_tool/join.c | 4 ++++ cman/cman_tool/main.c | 7 ++++++- cman/daemon/ais.c | 11 +++++++++++ cman/init.d/cman.in | 2 +- 5 files changed, 23 insertions(+), 2 deletions(-)
cman/cman_tool/cman_tool.h +1 -0
@@ -84,6 +84,7 @@ struct commandlineint remove;int force;int verbose; +int nostderr_debug;int nodeid;int timeout;unsigned int config_version;
cman/cman_tool/join.c +4 -0
@@ -186,6 +186,10 @@ int join(commandline_t *comline, char *main_envp[])snprintf (scratch,sizeof (scratch),"CMAN_DEBUG=%d" , comline->verbose); envp[envptr++] =strdup (scratch); } +if (comline->nostderr_debug) { +snprintf (scratch,sizeof (scratch),"CMAN_NOSTDERR_DEBUG=true" ); + envp[envptr++] =strdup (scratch); + }if (comline->noconfig_opt) { envp[envptr++] =strdup ("CMAN_NOCONFIG=true" ); snprintf(config_modules, sizeof(config_modules), "cmanpreconfig%s",
cman/cman_tool/main.c +6 -1
@@ -12,7 +12,7 @@#define DEFAULT_CONFIG_MODULE "xmlconfig" -#define OPTION_STRING ("m:n:v:e:2p:c:i:N:t:o:k:F:C:VAPwfqah?XD::Sd::r::") +#define OPTION_STRING ("m:n:v:e:2p:c:i:N:t:o:k:F:C:VAPwfqazh?XD::Sd::r::")#define OP_JOIN 1#define OP_LEAVE 2#define OP_EXPECTED 3
@@ -62,6 +62,7 @@ static void print_usage(int subcmd)printf (" -D<fail|warn|none> What to do about the config. Default (without -D) is to\n" );printf (" validate the config. with -D no validation will be done.\n" );printf (" -Dwarn will print errors but allow the operation to continue.\n" ); +printf (" -z Disable stderr debugging output.\n" );printf ("\n" ); }
@@ -1047,6 +1048,10 @@ static void decode_arguments(int argc, char *argv[], commandline_t *comline) comline->verbose =255 ;break ; +case 'z' : + comline->nostderr_debug =1 ; +break ; +case 'w' : comline->wait_opt = TRUE;break ;
cman/daemon/ais.c +11 -0
@@ -14,6 +14,8 @@#include <arpa/inet.h> #include <netdb.h> #include <inttypes.h> +#include <sys/stat.h> +#include <fcntl.h> /* corosync headers */ #include <corosync/corotypes.h>
@@ -220,6 +222,15 @@ static int cman_exec_init_fn(struct corosync_api_v1 *api) api->tpg_init (&group_handle, cman_deliver_fn, cman_confchg_fn); api->tpg_join (group_handle, cman_group,1 ); +if (getenv ("CMAN_NOSTDERR_DEBUG" )) { +int tmpfd; + tmpfd =open ("/dev/null" ,O_RDWR ); +if (tmpfd >-1 && tmpfd !=STDERR_FILENO ) { +dup2 (tmpfd,STDERR_FILENO ); +close (tmpfd); + } + } +return 0 ; }
cman/init.d/cman.in +1 -1
@@ -556,7 +556,7 @@ start_cman() return 1 fi - cman_tool -t $CMAN_CLUSTER_TIMEOUT -w join $cman_join_opts > $tmpfile 2>&1 & + cman_tool -z -t $CMAN_CLUSTER_TIMEOUT -w join $cman_join_opts > $tmpfile 2>&1 & while status cman_tool >/dev/null 2>&1; do sleep 0.2
Signature · 1 line
1.7.4.4