On Fri, Feb 14, 2025 at 11:10:05PM +0100, Martin Wilck wrote:
> This feature is only used by multipathd.

We should probably move all of ux_socket_listen() to multipathd, since
it's only used there. But I see why you split out this code, and moving
ux_socket_listen() can happen whenever.

Reviewed-by: Benjamin Marzinski <bmarz...@redhat.com>
 
> Signed-off-by: Martin Wilck <mwi...@suse.com>
> ---
>  libmpathutil/uxsock.c | 15 ---------------
>  multipathd/main.c     | 28 +++++++++++++++++++++++++++-
>  2 files changed, 27 insertions(+), 16 deletions(-)
> 
> diff --git a/libmpathutil/uxsock.c b/libmpathutil/uxsock.c
> index 889d7a1..59c4717 100644
> --- a/libmpathutil/uxsock.c
> +++ b/libmpathutil/uxsock.c
> @@ -46,23 +46,8 @@ int ux_socket_listen(const char *name)
>  {
>       int fd;
>       size_t len;
> -#ifdef USE_SYSTEMD
> -     int num;
> -#endif
>       struct sockaddr_un addr;
>  
> -#ifdef USE_SYSTEMD
> -     num = sd_listen_fds(0);
> -     if (num > 1) {
> -             condlog(3, "sd_listen_fds returned %d fds", num);
> -             return -1;
> -     } else if (num == 1) {
> -             fd = SD_LISTEN_FDS_START + 0;
> -             condlog(3, "using fd %d from sd_listen_fds", fd);
> -             return fd;
> -     }
> -#endif
> -
>       /* This is after the PID check, so unlinking should be fine */
>       if (name[0] != '@' && unlink(name) == -1 && errno != ENOENT)
>               condlog(1, "Failed to unlink %s", name);
> diff --git a/multipathd/main.c b/multipathd/main.c
> index 52630f7..5455bdf 100644
> --- a/multipathd/main.c
> +++ b/multipathd/main.c
> @@ -1863,15 +1863,41 @@ uevqloop (void * ap)
>       pthread_cleanup_pop(1);
>       return NULL;
>  }
> +
> +#ifdef USE_SYSTEMD
> +static int get_systemd_sockets(long *ux_sock)
> +{
> +     int num = sd_listen_fds(0);
> +
> +     if (num > 1) {
> +             condlog(3, "sd_listen_fds returned %d fds", num);
> +             return -1;
> +     } else if (num == 1) {
> +             ux_sock[0] = SD_LISTEN_FDS_START + 0;
> +             condlog(3, "using fd %ld from sd_listen_fds", ux_sock[0]);
> +     }
> +     return num;
> +}
> +#else
> +static int get_systemd_sockets(long *ux_sock __attribute__((unused)))
> +{
> +     return 0;
> +}
> +#endif
> +
> +
>  static void *
>  uxlsnrloop (void * ap)
>  {
>       long ux_sock;
> +     int num;
>  
>       pthread_cleanup_push(rcu_unregister, NULL);
>       rcu_register_thread();
>  
> -     ux_sock = ux_socket_listen(DEFAULT_SOCKET);
> +     num = get_systemd_sockets(&ux_sock);
> +     if (num < 1)
> +             ux_sock = ux_socket_listen(DEFAULT_SOCKET);
>       if (ux_sock == -1) {
>               condlog(1, "could not create uxsock: %d", errno);
>               exit_daemon();
> -- 
> 2.48.1


Reply via email to