/*
- * Copyright (C) 2015, 2016, 2017 "IoT.bzh"
+ * Copyright (C) 2015-2018 "IoT.bzh"
* Author José Bollo <jose.bollo@iot.bzh>
*
* Licensed under the Apache License, Version 2.0 (the "License");
#include <systemd/sd-event.h>
#include <systemd/sd-bus.h>
+#include <systemd/sd-daemon.h>
#include "afb-systemd.h"
#include "jobs.h"
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 afb_systemd_fds_init()
+{
+ errno = 0;
+ fds_names();
+ return -!!errno;
+}
+
+int afb_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;
+}
+