aboutsummaryrefslogtreecommitdiffstats
path: root/src/afb-systemd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/afb-systemd.c')
-rw-r--r--src/afb-systemd.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/afb-systemd.c b/src/afb-systemd.c
index 4faa9fc7..575d9f1b 100644
--- a/src/afb-systemd.c
+++ b/src/afb-systemd.c
@@ -22,6 +22,7 @@
#include <systemd/sd-event.h>
#include <systemd/sd-bus.h>
+#include <systemd/sd-daemon.h>
#include "afb-systemd.h"
#include "jobs.h"
@@ -62,3 +63,41 @@ struct sd_bus *afb_systemd_get_system_bus()
return sdbusopen((void*)&result, (void*)sd_bus_open_system);
}
+static char **fds_names()
+{
+ static char *null;
+ static char **names;
+
+ int rc;
+
+ if (!names) {
+ rc = sd_listen_fds_with_names(1, &names);
+ if (rc <= 0) {
+ errno = -rc;
+ names = &null;
+ }
+ }
+ return names;
+}
+
+int systemd_fds_init()
+{
+ errno = 0;
+ fds_names();
+ return -!!errno;
+}
+
+int systemd_fds_for(const char *name)
+{
+ int idx;
+ char **names;
+
+ names = fds_names();
+ for (idx = 0 ; names[idx] != NULL ; idx++)
+ if (!strcmp(name, names[idx]))
+ return idx + SD_LISTEN_FDS_START;
+
+ errno = ENOENT;
+ return -1;
+}
+