diff options
Diffstat (limited to 'modules/programs')
-rw-r--r-- | modules/programs/gpg-agent/agent-wrapper.c | 21 | ||||
-rw-r--r-- | modules/programs/gpg-agent/default.nix | 3 |
2 files changed, 22 insertions, 2 deletions
diff --git a/modules/programs/gpg-agent/agent-wrapper.c b/modules/programs/gpg-agent/agent-wrapper.c index 84b4f80b..86e44c1a 100644 --- a/modules/programs/gpg-agent/agent-wrapper.c +++ b/modules/programs/gpg-agent/agent-wrapper.c @@ -23,7 +23,23 @@ static int get_sd_fd_for(const struct sockaddr_un *addr) if (main_fd == 0 && ssh_fd == 0 && scdaemon_fd == 0) { int num_fds; char **fdmap = NULL; - num_fds = sd_listen_fds_with_names(0, &fdmap); + void *libsystemd = NULL; + int (*_sd_listen_fds_with_names)(int, char ***); + + if ((libsystemd = dlopen(LIBSYSTEMD, RTLD_LAZY)) == NULL) { + fprintf(stderr, "dlopen %s\n", dlerror()); + return -1; + } + + _sd_listen_fds_with_names = + dlsym(libsystemd, "sd_listen_fds_with_names"); + + if (_sd_listen_fds_with_names == NULL) { + fprintf(stderr, "dlsym %s\n", dlerror()); + return -1; + } + + num_fds = _sd_listen_fds_with_names(0, &fdmap); if (num_fds <= 0) { fputs("No suitable file descriptors in LISTEN_FDS.\n", stderr); @@ -44,6 +60,9 @@ static int get_sd_fd_for(const struct sockaddr_un *addr) } free(fdmap); } + + if (dlclose(libsystemd) != 0) + return -1; } if (addr->sun_path == NULL || *(addr->sun_path) == 0) diff --git a/modules/programs/gpg-agent/default.nix b/modules/programs/gpg-agent/default.nix index 81a113f7..139813d0 100644 --- a/modules/programs/gpg-agent/default.nix +++ b/modules/programs/gpg-agent/default.nix @@ -23,8 +23,9 @@ let inherit pinentryWrapper; } '' cc -Wall -shared -std=c11 \ - $(pkg-config --cflags --libs libsystemd) -ldl \ + -DLIBSYSTEMD=\"${pkgs.systemd}/lib/libsystemd.so\" \ -DPINENTRY_WRAPPER=\"$pinentryWrapper\" \ + $(pkg-config --cflags libsystemd) -ldl \ "${./agent-wrapper.c}" -o "$out" -fPIC ''; |