core: populate $REMOTE_ADDR for AF_UNIX sockets

Set the $REMOTE_ADDR environment variable for AF_UNIX socket connections
when using per-connection socket activation (Accept=yes). $REMOTE_ADDR
will now contain the remote socket's file system path (starting with a
slash "/") or its address in the abstract namespace (starting with an
at symbol "@").

This information is essential for identifying the remote peer in AF_UNIX
socket connections, but it's not easy to obtain in a shell script for
example without pulling in a ton of additional tools. By setting
$REMOTE_ADDR, we make this information readily available to the
activated service.
This commit is contained in:
Kamil Szczęk
2024-06-12 00:11:10 +01:00
committed by Luca Boccassi
parent bd6e5b4d93
commit 608bfe76c1
3 changed files with 36 additions and 17 deletions
+11 -2
View File
@@ -4101,8 +4101,17 @@ StandardInputData=V2XigLJyZSBubyBzdHJhbmdlcnMgdG8gbG92ZQpZb3Uga25vdyB0aGUgcnVsZX
<term><varname>$REMOTE_PORT</varname></term>
<listitem><para>If this is a unit started via per-connection socket activation (i.e. via a socket
unit with <varname>Accept=yes</varname>), these environment variables contain the IP address and
port number of the remote peer of the socket connection.</para>
unit with <varname>Accept=yes</varname>), these environment variables contain information about the
remote peer of the socket connection.</para>
<para>For IPv4 and IPv6 connections, <varname>$REMOTE_ADDR</varname> contains the IP address, and
<varname>$REMOTE_PORT</varname> contains the port number of the remote peer.</para>
<para>For <constant>AF_UNIX</constant> socket connections, <varname>$REMOTE_ADDR</varname> contains
either the remote socket's file system path starting with a slash (<literal>/</literal>), its
address in the abstract namespace starting with an at symbol (<literal>@</literal>), or is unset
in case of an unnamed socket. <varname>$REMOTE_PORT</varname> is not set for <constant>AF_UNIX</constant>
sockets.</para>
<xi:include href="version-info.xml" xpointer="v254"/></listitem>
</varlistentry>