Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Burton2013-04-10 16:57:18 +0000
committerFelix Burton2013-04-11 17:57:10 +0000
commit85fce6099c7721b002d88d14a3e978b4d96d3228 (patch)
tree98fe9c59c5fb3728398945d4c20c366c8d7e3008 /agent/tcf/main/main.c
parent0c0772c2fb2eeabb179286b5024db482cf793193 (diff)
downloadorg.eclipse.tcf.agent-85fce6099c7721b002d88d14a3e978b4d96d3228.tar.gz
org.eclipse.tcf.agent-85fce6099c7721b002d88d14a3e978b4d96d3228.tar.xz
org.eclipse.tcf.agent-85fce6099c7721b002d88d14a3e978b4d96d3228.zip
Enable initialization output on stdout and stderr in daemon mode and add daemon support on windows
Prior to this change it was not possible to get the output from the -S option in daemon mode. This made it hard for clients to start the TCF agent and know 1) which port is used, 2) when the started agent is ready for incoming connections and 3) if the launch was successful or if it failed.
Diffstat (limited to 'agent/tcf/main/main.c')
-rw-r--r--agent/tcf/main/main.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/agent/tcf/main/main.c b/agent/tcf/main/main.c
index e3a56619..c43bf3b9 100644
--- a/agent/tcf/main/main.c
+++ b/agent/tcf/main/main.c
@@ -195,7 +195,7 @@ int main(int argc, char ** argv) {
/* Parse arguments */
for (ind = 1; ind < argc; ind++) {
- const char * s = argv[ind];
+ char * s = argv[ind];
if (*s != '-') {
break;
}
@@ -214,6 +214,17 @@ int main(int argc, char ** argv) {
break;
case 'd':
+#if defined(_WIN32)
+ /* For Windows the only way to detach a process is to
+ * create a new process, so we patch the -d option to
+ * -D for the second time we get invoked so we don't
+ * keep on creating new processes forever. */
+ s[-1] = 'D';
+ daemon = 2;
+ break;
+
+ case 'D':
+#endif
daemon = 1;
break;
@@ -279,13 +290,13 @@ int main(int argc, char ** argv) {
}
}
- if (daemon && log_name != NULL && strcmp (log_name, LOG_NAME_STDERR) != 0) {
- fprintf(stderr, "%s: error: can only log to stderr when in daemon "
- "mode.\n", progname);
- exit (1);
+ if (daemon) {
+#if defined(_WIN32)
+ become_daemon(daemon > 1 ? argv : NULL);
+#else
+ become_daemon();
+#endif
}
-
- if (daemon) become_daemon();
open_log_file(log_name);
#endif
@@ -329,6 +340,9 @@ int main(int argc, char ** argv) {
loc_free(server_properties);
}
+ if (daemon)
+ close_out_and_err();
+
#if ENABLE_SignalHandlers
signal(SIGABRT, signal_handler);
signal(SIGILL, signal_handler);

Back to the top