[lttng-dev] [RFC PATCH lttng-tools] relayd pipes and error handling
Christian Babeux
christian.babeux at efficios.com
Tue Jul 17 15:15:35 EDT 2012
Hi,
The current relayd employ two set of pipes for command relaying and
thread quit signalling.
The relay_cmd_pipe pipes are never closed. Also, the thread_quit_pipe
pipes are not closed in
some error cases (fail to parse args, fail to daemonize, etc.). Here
is a proposed way to cleanup
and handle error cases.
Thoughts?
Thanks,
Christian
Fix: relayd relay_cmd_pipe/thread_quit_pipe should be closed on exit/error.
diff --git a/src/bin/lttng-relayd/main.c b/src/bin/lttng-relayd/main.c
index acc6ca8..55452b3 100644
--- a/src/bin/lttng-relayd/main.c
+++ b/src/bin/lttng-relayd/main.c
@@ -231,14 +231,26 @@ void cleanup(void)
DBG("Cleaning up");
+ /* Close thread quit pipes */
for (i = 0; i < 2; i++) {
if (thread_quit_pipe[i] >= 0) {
ret = close(thread_quit_pipe[i]);
if (ret) {
- PERROR("close");
+ PERROR("close quit pipe");
}
}
}
+
+ /* Close relay cmd pipes */
+ for (i = 0; i < 2; i++) {
+ if (relay_cmd_pipe[i] >= 0) {
+ ret = close(relay_cmd_pipe[i]);
+ if (ret) {
+ PERROR("close cmd pipe");
+ }
+ }
+ }
+
}
/*
@@ -1479,7 +1491,7 @@ int main(int argc, char **argv)
/* Parse arguments */
progname = argv[0];
if ((ret = parse_args(argc, argv) < 0)) {
- goto error;
+ goto exit;
}
if ((ret = set_signal_handler()) < 0) {
@@ -1491,7 +1503,7 @@ int main(int argc, char **argv)
ret = daemon(0, 0);
if (ret < 0) {
PERROR("daemon");
- goto error;
+ goto exit;
}
}
@@ -1502,7 +1514,7 @@ int main(int argc, char **argv)
if (control_uri->port < 1024 || data_uri->port < 1024) {
ERR("Need to be root to use ports < 1024");
ret = -1;
- goto error;
+ goto exit;
}
}
@@ -1567,6 +1579,7 @@ exit:
if (!ret) {
exit(EXIT_SUCCESS);
}
+
error:
exit(EXIT_FAILURE);
}
More information about the lttng-dev
mailing list