trace-cmd agent: Move becoming daemon after prints and errors
PATCH 1/1 trace-cmd agent: Move becoming daemon after prints and errors
From: "Steven Rostedt (Google)" <[email protected]>
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) <[email protected]>
--- tracecmd/trace-agent.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
tracecmd/trace-agent.c +5 -5
@@ -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); }
Signature · 1 line
2.35.1