cli: Add sd-notify integration

Let's make sysprof-cli send a READY=1 sd-notify message when it's
finished its setup logic. This allows starting sysprof as a systemd
service and delaying startup of other services until sysprof has
finished its setup logic. This ensures we don't miss any profiling
data when running sysprof-cli in a systemd service as part of the
bootup process.

We skip this step for now when we're running a child process so that
we don't accidentally interfere with a child process that receives
an sd-notify socket and is supposed to send notifications on it instead
of sysprof-cli.
This commit is contained in:
Daan De Meyer
2025-04-07 11:38:43 +02:00
committed by Christian Hergert
parent 2b972a3ac6
commit b2091926fe
2 changed files with 13 additions and 0 deletions

View File

@ -38,6 +38,10 @@
# include <polkitagent/polkitagent.h>
#endif
#if HAVE_LIBSYSTEMD
# include <systemd/sd-daemon.h>
#endif
#include "sysprof-capture-util-private.h"
#define DEFAULT_BUFFER_SIZE (1024L * 1024L * 8L /* 8mb */)
@ -625,6 +629,11 @@ Examples:\n\
g_printerr ("Recording, press ^C to exit\n");
#if HAVE_LIBSYSTEMD
if (command == NULL && child_argv == NULL)
sd_notify (TRUE, "READY=1");
#endif
g_main_loop_run (main_loop);
sysprof_capture_writer_flush (writer);