summaryrefslogtreecommitdiff
path: root/src/libsystemd
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-04-14 17:48:47 +0200
committerLennart Poettering <lennart@poettering.net>2023-04-25 17:38:57 +0200
commit4054d76151678edc7c6b77ebdebb9a32d1dc11c9 (patch)
treee72ad90b5ae27b65be43976180f0127fc74d2f8c /src/libsystemd
parent4a75704b166de533cedf8f9fab16ffae77bf2093 (diff)
downloadsystemd-4054d76151678edc7c6b77ebdebb9a32d1dc11c9.tar.gz
sd-daemon: add sd_pid_notifyf_with_fds()
I guess it was only a question of time until we need to add the final frontier of notification functions: one that combines the features of all the others: 1. specifiying a source PID 2. taking a list of fds to send along 3. accepting a format string for the status string Hence, let's add it.
Diffstat (limited to 'src/libsystemd')
-rw-r--r--src/libsystemd/libsystemd.sym1
-rw-r--r--src/libsystemd/sd-daemon/sd-daemon.c30
2 files changed, 31 insertions, 0 deletions
diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym
index 53db234a0c..76fa1e0e32 100644
--- a/src/libsystemd/libsystemd.sym
+++ b/src/libsystemd/libsystemd.sym
@@ -818,4 +818,5 @@ global:
sd_session_get_username;
sd_session_get_start_time;
sd_uid_get_login_time;
+ sd_pid_notifyf_with_fds;
} LIBSYSTEMD_253;
diff --git a/src/libsystemd/sd-daemon/sd-daemon.c b/src/libsystemd/sd-daemon/sd-daemon.c
index f2f295d6e4..eec6fb64ef 100644
--- a/src/libsystemd/sd-daemon/sd-daemon.c
+++ b/src/libsystemd/sd-daemon/sd-daemon.c
@@ -667,6 +667,36 @@ _public_ int sd_notifyf(int unset_environment, const char *format, ...) {
return sd_pid_notify(0, unset_environment, p);
}
+int sd_pid_notifyf_with_fds(
+ pid_t pid,
+ int unset_environment,
+ const int *fds, size_t n_fds,
+ const char *format, ...) {
+
+ _cleanup_free_ char *p = NULL;
+ int r;
+
+ /* Paranoia check: we traditionally used 'unsigned' as array size, but we nowadays more correctly use
+ * 'size_t'. sd_pid_notifyf_with_fds() and sd_pid_notify_with_fds() are from different eras, hence
+ * differ in this. Let's catch resulting incompatibilites early, even though they are pretty much
+ * theoretic only */
+ if (n_fds > UINT_MAX)
+ return -E2BIG;
+
+ if (format) {
+ va_list ap;
+
+ va_start(ap, format);
+ r = vasprintf(&p, format, ap);
+ va_end(ap);
+
+ if (r < 0 || !p)
+ return -ENOMEM;
+ }
+
+ return sd_pid_notify_with_fds(pid, unset_environment, p, fds, n_fds);
+}
+
_public_ int sd_booted(void) {
/* We test whether the runtime unit file directory has been
* created. This takes place in mount-setup.c, so is