[PATCH] [RFC] Enable systemd socket activation

Peter Hutterer peter.hutterer at who-t.net
Thu Jun 27 22:32:01 PDT 2013


On Wed, Jun 26, 2013 at 06:18:04PM +0200, Łukasz Stelmach wrote:
> Receive file descriptors of open sockets from systemd instead of
> creating them.
> 
> Signed-off-by: Łukasz Stelmach <l.stelmach at samsung.com>
> ---
>  Xtrans.c |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 50 insertions(+)
> 
> diff --git a/Xtrans.c b/Xtrans.c
> index 0799f04..a96e901 100644
> --- a/Xtrans.c
> +++ b/Xtrans.c
> @@ -48,6 +48,9 @@ from The Open Group.
>   */
>  
>  #include <ctype.h>
> +#ifdef HAVE_SYSTEMD
> +#include <systemd/sd-daemon.h>
> +#endif
>  
>  /*
>   * The transport table contains a definition for every transport (protocol)
> @@ -1025,6 +1028,10 @@ TRANS(MakeAllCOTSServerListeners) (char *port, int *partial, int *count_ret,
>  #if defined(IPv6) && defined(AF_INET6)
>      int		ipv6_succ = 0;
>  #endif
> +#ifdef HAVE_SYSTEMD
> +    int		systemd_listen_fds;
> +#endif /* HAVE_SYSTEMD */
> +
>      prmsg (2,"MakeAllCOTSServerListeners(%s,%p)\n",
>  	   port ? port : "NULL", ciptrs_ret);
>  
> @@ -1040,6 +1047,49 @@ TRANS(MakeAllCOTSServerListeners) (char *port, int *partial, int *count_ret,
>              temp_ciptrs[(*count_ret)++] = ciptr;
>      }
>  #endif
> +#ifdef HAVE_SYSTEMD
> +    systemd_listen_fds = sd_listen_fds(1);
> +    if (systemd_listen_fds < 0)
> +    {
> +	return -1;
> +    }
> +    else if (sd_listen_fds > 0)

this doesn't look right.

> +    {
> +	for (i = 0; i < systemd_listen_fds; i++)
> +	{
> +	    struct sockaddr_storage a;
> +	    int ti;
> +	    socklen_t al;
> +
> +	    al = sizeof(a);
> +	    if (getsockname(i + SD_LISTEN_FDS_START, (struct sockaddr*)&a, &al) < 0)
> +		return -1;
> +
> +	    switch (a.ss_family)
> +	    {
> +	    case AF_UNIX:
> +		ti = TRANS_SOCKET_UNIX_INDEX;
> +		break;
> +	    case AF_INET:
> +		ti = TRANS_SOCKET_INET_INDEX;
> +		break;
> +#if defined(IPv6) && defined(AF_INET6)
> +	    case AF_INET6:
> +		ti = TRANS_SOCKET_INET6_INDEX;
> +		break;
> +#endif /* IPv6 */
> +	    default:
> +		return -1;
> +	    }
> +
> +	    if ((ciptr = TRANS(ReopenCOTSServer(ti, i + SD_LISTEN_FDS_START,
> +						getenv("DISPLAY"))))==NULL)
> +		fprintf(stderr, "Got NULL while trying to Reopen socket received from systemd.\n");

lowercase 'reopen'

(don't have the brain capacity to do a proper review atm, sorry)

Cheers,
   Peter

> +	    else
> +		temp_ciptrs[(*count_ret)++] = ciptr;
> +	}
> +    }
> +#endif /* HAVE_SYSTEMD */
>  
>      for (i = 0; i < NUMTRANS; i++)
>      {
> -- 
> 1.7.9.5
> 
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
> 


More information about the xorg-devel mailing list