[systemd-devel] [PATCH] core/socket: Add REMOTE_IP environment variable for Accept=true

Lennart Poettering lennart at poettering.net
Thu Mar 5 03:16:46 PST 2015


On Thu, 05.03.15 01:27, Zbigniew Jędrzejewski-Szmek (zbyszek at in.waw.pl) wrote:

> >        </varlistentry>
> >  
> >        <varlistentry>
> > diff --git a/src/core/service.c b/src/core/service.c
> > index a89ff3f..0942072 100644
> > --- a/src/core/service.c
> > +++ b/src/core/service.c
> > @@ -1119,6 +1119,30 @@ static int service_spawn(
> >                          goto fail;
> >                  }
> >  
> > +        if (s->accept_socket.unit) {
> > +                union sockaddr_union pn;
> > +                socklen_t pnlen = sizeof(pn);
> > +                _cleanup_free_ char *remote_addr = NULL;
> > +
> > +                r = getpeername(s->socket_fd, &pn.sa, &pnlen);
> This happens before the fork, right? You cannot call a blocking function
> like this in PID 1. This could be called either asynchronously, or
> after the fork, in the child thread. The latter seems easier.

getpeername() just gets the peer sockaddr, it's not slow. It should be
OK to invoke it, and we actually do already, to generate instantiated
service names.

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list