diff options
author | Steven Rostedt (Google) <rostedt@goodmis.org> | 2022-03-14 17:37:14 -0400 |
---|---|---|
committer | Steven Rostedt (Google) <rostedt@goodmis.org> | 2022-03-15 12:14:41 -0400 |
commit | 37623725105f54a0708f692dca2ffaa169e652f6 (patch) | |
tree | 1dfcb8ece6a2db804345e077b3dc9a669c9f9f3a | |
parent | d38cbfc863bc762296995fb9ac18f2c43f5ed8a5 (diff) | |
download | trace-cmd-37623725105f54a0708f692dca2ffaa169e652f6.tar.gz |
trace-cmd agent: Move becoming daemon after prints and errors
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.
Link: https://lore.kernel.org/linux-trace-devel/20220314173714.01f226d6@gandalf.local.home
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
-rw-r--r-- | tracecmd/trace-agent.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/tracecmd/trace-agent.c b/tracecmd/trace-agent.c index b83d3ac1..a46feea3 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); } |