Skip to content

Commit

Permalink
Check if systemd has sd_varlink_server_listen_name()
Browse files Browse the repository at this point in the history
  • Loading branch information
thkukuk committed Jan 8, 2025
1 parent 39a971b commit 305f718
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
6 changes: 6 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ if have_systemd257 == false
endif
else
have_systemd = true
# check if we have functions from 258 already
if cc.has_function('sd_varlink_server_listen_name',
prefix: '#include <systemd/sd-varlink.h>',
dependencies: [libsystemd])
conf.set('HAVE_SD_VARLINK_SERVER_LISTEN_NAME', 1)
endif
endif
conf.set10('HAVE_SYSTEMD', have_systemd)

Expand Down
17 changes: 10 additions & 7 deletions src/wtmpdbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,9 @@ announce_ready (void)
}


/* clone of sd_varlink_server_listen_auto, just that the socket name "varlink"
is configureable */
#if !HAVE_SD_VARLINK_SERVER_LISTEN_NAME
/* clone of sd_varlink_server_listen_name in the case we have systemd
v257 and not v258. */
static char **
strv_free(char **v)
{
Expand All @@ -505,12 +506,13 @@ strv_free(char **v)

static inline void strv_freep(char ***p) { strv_free(*p); }

static int
varlink_server_listen_name(sd_varlink_server *s, const char *fdname) {
int
sd_varlink_server_listen_name(sd_varlink_server *s, const char *name)
{
_cleanup_(strv_freep) char **names = NULL;
int r, n = 0;

/* Adds all passed fds marked as "varlink" to our varlink server. These fds can either refer to a
/* Adds all passed fds marked as "name" to our varlink server. These fds can either refer to a
* listening socket or to a connection socket.
*
* See https://varlink.org/#activation for the environment variables this is backed by and the
Expand All @@ -524,7 +526,7 @@ varlink_server_listen_name(sd_varlink_server *s, const char *fdname) {
int b, fd;
socklen_t l = sizeof(b);

if (strcmp(names[i], fdname) != 0)
if (strcmp(names[i], name) != 0)
continue;

fd = SD_LISTEN_FDS_START + i;
Expand All @@ -544,6 +546,7 @@ varlink_server_listen_name(sd_varlink_server *s, const char *fdname) {

return n;
}
#endif

static int
init_varlink_server(sd_varlink_server **varlink_server, int flags,
Expand Down Expand Up @@ -593,7 +596,7 @@ init_varlink_server(sd_varlink_server **varlink_server, int flags,
return r;
}

r = varlink_server_listen_name (*varlink_server, name);
r = sd_varlink_server_listen_name (*varlink_server, name);
if (r < 0)
{
log_msg (LOG_ERR, "Failed to listen to %s events: %s",
Expand Down

0 comments on commit 305f718

Please sign in to comment.