On 1/12/22 08:51, Vasily Ulyanov wrote:
Hi Michal,
>
So I can drop --pid and --daemon args from swtpm cmd and add
virCommandSetPidFile(cmd, pidfile);
virCommandDaemonize(cmd);
Then in virPidFileReadPathIfAlive() I can add a lock check. Hm... Nice, that
seems like a good way to go.
Correct. That's common pattern. However, be aware that using
virCommandDaemonize() makes the subsequent virCommandRun() return almost
instantly, even before the actual binary that was intended to run is
executed (if scheduler aligns things "well"). Therefore, checking for
the child process is a bit trickier. But the pidfile is written before
virCommandRun() returns, which is good.
Moreover, it's not possible to use virCommandSetErrorBuffer() nor
virCommandSetOutputBuffer() with virCommandDaemonize().
However, we have examples of how to use the pattern you suggested in our
code. For instance qemuProcessStartManagedPRDaemon() or
qemuSlirpStart(). You can find more by grepping for virCommandDaemonize().
Let me know if you need any help.
Michal