[PATCH] [RFC] Enable systemd socket activation

walter harms wharms at bfs.de
Fri Jun 28 01:52:25 PDT 2013



Am 28.06.2013 10:02, schrieb Łukasz Stelmach:
> It was <2013-06-28 pią 07:32>, when Peter Hutterer wrote:
>> 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
> [...]
>>> @@ -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.
> 
> Fixed.
> 
>>> +    {
>>> +	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'
> 
> Fixed.
> 
>> (don't have the brain capacity to do a proper review atm, sorry)
> 
> Thak you for your comments. I will send v2 when I get some more.


These if-statement if very complex. You should revamp it and make at least 2 statements
like:
ciptr = TRANS(ReopenCOTSServer(ti, i + SD_LISTEN_FDS_START,getenv("DISPLAY"));
if (ciptr == NULL )

btw: can getenv() fail ?

re,
 wh








More information about the xorg-devel mailing list