From: Pierre-Marc Fournier Date: Tue, 13 Oct 2009 23:16:33 +0000 (-0400) Subject: usttrace: use ustd in daemon mode, sparing a sleep and removing a race X-Git-Tag: v0.1~84 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=b924c127ff931e20e6de9c88aafad0829c97de29;p=ust.git usttrace: use ustd in daemon mode, sparing a sleep and removing a race The race was that usttrace waited for 0.5s for the daemon (started in background) to settle before starting the command to trace. If the daemon needed more than 0.5s to settle, the connection would fail. Now, it is guaranteed to succeed. --- diff --git a/usttrace b/usttrace index 689cdde..fe8a5cd 100755 --- a/usttrace +++ b/usttrace @@ -77,21 +77,14 @@ SOCKPATH="/tmp/ust-sock-$$" if [ "$arg_syswide_daemon" != "1" ]; then + pidfilepath="/tmp/usttrace-$USER-$(date +%Y%m%d%H%M%S%N)-ustd-pid" + # Start daemon - $USTD -s "$SOCKPATH" -o "$OUTDIR" 2>&1 >"$OUTDIR/ustd.log" & - USTDPID="$!" + $USTD -d --pidfile "$pidfilepath" -s "$SOCKPATH" -o "$OUTDIR" >"$OUTDIR/ustd.log" 2>&1 & + USTDPID="$(<$pidfilepath)" export UST_DAEMON_SOCKET="$SOCKPATH" fi -# Wait for the daemon to settle -# If we don't, the process may try to connect to its socket before -# it's ready. -# FIXME: is there a way to make sure this works every time? Yes, -# we could have a mode where ustd daemonizes itself. Therefore -# by the time the control returns to the console, it's ready. - -sleep 0.5 - # Establish the environment for the command export UST_TRACE=1 export UST_AUTOPROBE=1 @@ -137,6 +130,8 @@ then echo "Waiting for ustd to shutdown..." wait "$USTDPID" + + rm "$pidfilepath" fi echo "Trace was output in: " $OUTDIR