X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-systemd.c;h=5ba695ba2633691292e95b7129037f11fc29811e;hb=a4bb03e57aa2f8b71840ec384356f6c283989d73;hp=4faa9fc7aa7d01af7b307bf7e6602f1a26add3f6;hpb=b182590a555afe093d2d6e5cdf3e1e2410d1a0f5;p=src%2Fapp-framework-binder.git diff --git a/src/afb-systemd.c b/src/afb-systemd.c index 4faa9fc7..5ba695ba 100644 --- a/src/afb-systemd.c +++ b/src/afb-systemd.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015, 2016, 2017 "IoT.bzh" + * Copyright (C) 2015-2018 "IoT.bzh" * Author José Bollo * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,6 +22,7 @@ #include #include +#include #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 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; +} +