From: "Steven Rostedt (Google)" <rostedt@xxxxxxxxxxx> When starting the agent in daemon mode, it should be done after the connections to the vsocket, so that it can not only show the user what port it is connected to, but also show any errors that may happen. Once the task becomes a daemon, it will no longer print its error messages or normal information to the console. Thus any errors that happen after the daemon is running will go unnoticed. Signed-off-by: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx> --- tracecmd/trace-agent.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tracecmd/trace-agent.c b/tracecmd/trace-agent.c index b83d3ac1338f..a46feea3d3c7 100644 --- a/tracecmd/trace-agent.c +++ b/tracecmd/trace-agent.c @@ -236,7 +236,7 @@ static pid_t do_fork() return fork(); } -static void agent_serve(unsigned int port) +static void agent_serve(unsigned int port, bool do_daemon) { int sd, cd, nr_cpus; unsigned int cid; @@ -255,6 +255,9 @@ static void agent_serve(unsigned int port) if (!get_local_cid(&cid)) printf("listening on @%u:%u\n", cid, port); + if (do_daemon && daemon(1, 0)) + die("daemon"); + for (;;) { cd = accept(sd, NULL, NULL); if (cd < 0) { @@ -335,8 +338,5 @@ void trace_agent(int argc, char **argv) if (optind < argc-1) usage(argv); - if (do_daemon && daemon(1, 0)) - die("daemon"); - - agent_serve(port); + agent_serve(port, do_daemon); } -- 2.35.1