[Cluster-devel] [PATCH] cman: allow late close of stderr file descriptor and free resources
Fabio M. Di Nitto
fdinitto at redhat.com
Thu Sep 22 08:43:41 UTC 2011
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 <fdinitto at redhat.com>
---
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(-)
diff --git a/cman/cman_tool/cman_tool.h b/cman/cman_tool/cman_tool.h
index e84b491..e1250ee 100644
--- a/cman/cman_tool/cman_tool.h
+++ b/cman/cman_tool/cman_tool.h
@@ -84,6 +84,7 @@ struct commandline
int remove;
int force;
int verbose;
+ int nostderr_debug;
int nodeid;
int timeout;
unsigned int config_version;
diff --git a/cman/cman_tool/join.c b/cman/cman_tool/join.c
index caa5bf6..a33c8b4 100644
--- a/cman/cman_tool/join.c
+++ b/cman/cman_tool/join.c
@@ -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",
diff --git a/cman/cman_tool/main.c b/cman/cman_tool/main.c
index 61d29aa..88612c4 100644
--- a/cman/cman_tool/main.c
+++ b/cman/cman_tool/main.c
@@ -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;
diff --git a/cman/daemon/ais.c b/cman/daemon/ais.c
index 05cb8d7..6b5640a 100644
--- a/cman/daemon/ais.c
+++ b/cman/daemon/ais.c
@@ -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;
}
diff --git a/cman/init.d/cman.in b/cman/init.d/cman.in
index fecefea..d0c6f70 100644
--- a/cman/init.d/cman.in
+++ b/cman/init.d/cman.in
@@ -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
--
1.7.4.4
More information about the Cluster-devel
mailing list