mirror of
https://github.com/systemd/systemd.git
synced 2024-10-26 08:55:40 +03:00
core: honor FileDescriptorName= too for Accept=yes sockets
So far we manually hardcoded $LISTEN_FDNAMES to "varlink" in various varlink service units we ship, even though FileDescriptorName=varlink is specified in associated socket units already, because FileDescriptorName= is currently silently ignored when combined with Accept=yes. Let's step away from this, which seems saner. Note that this is technically a compat break, but a mostly negligible one as there shall be few users setting FileDescriptorName= but still expecting LISTEN_FDNAMES=connection in the actual executable. Preparation for #34080
This commit is contained in:
parent
2234032c47
commit
daa78907af
4
NEWS
4
NEWS
@ -31,6 +31,10 @@ CHANGES WITH 257 in spe:
|
||||
by default when combined with --scope, will be changed in a future
|
||||
release to be enabled by default.
|
||||
|
||||
* The FileDescriptorName= setting for socket units is now honored by
|
||||
Accept=yes sockets too, where it was previously silently ignored and
|
||||
"connection" was used unconditionally.
|
||||
|
||||
* systemd-logind now always obeys inhibitor locks, where previously it
|
||||
ignored locks taken by the caller or when the caller was root. A
|
||||
privileged caller can always close the other sessions, remove the
|
||||
|
@ -853,18 +853,15 @@
|
||||
|
||||
<varlistentry>
|
||||
<term><varname>FileDescriptorName=</varname></term>
|
||||
<listitem><para>Assigns a name to all file descriptors this
|
||||
socket unit encapsulates. This is useful to help activated
|
||||
services identify specific file descriptors, if multiple fds
|
||||
are passed. Services may use the
|
||||
<listitem><para>Assigns a name to all file descriptors this socket unit encapsulates.
|
||||
This is useful to help activated services identify specific file descriptors, if multiple fds are passed.
|
||||
Services may use the
|
||||
<citerefentry><refentrytitle>sd_listen_fds_with_names</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
||||
call to acquire the names configured for the received file
|
||||
descriptors. Names may contain any ASCII character, but must
|
||||
exclude control characters and <literal>:</literal>, and must
|
||||
be at most 255 characters in length. If this setting is not
|
||||
used, the file descriptor name defaults to the name of the
|
||||
socket unit, including its <filename>.socket</filename>
|
||||
suffix.</para>
|
||||
call to acquire the names configured for the received file descriptors. Names may contain any ASCII character,
|
||||
but must exclude control characters and <literal>:</literal>, and must be at most 255 characters in length.
|
||||
If this setting is not used, the file descriptor name defaults to the name of the socket unit
|
||||
(including its <filename>.socket</filename> suffix) when <varname>Accept=no</varname>,
|
||||
<literal>connection</literal> otherwise.</para>
|
||||
|
||||
<xi:include href="version-info.xml" xpointer="v227"/></listitem>
|
||||
</varlistentry>
|
||||
|
@ -1426,6 +1426,7 @@ static int service_collect_fds(
|
||||
assert(n_storage_fds);
|
||||
|
||||
if (s->socket_fd >= 0) {
|
||||
Socket *sock = ASSERT_PTR(SOCKET(UNIT_DEREF(s->accept_socket)));
|
||||
|
||||
/* Pass the per-connection socket */
|
||||
|
||||
@ -1433,7 +1434,7 @@ static int service_collect_fds(
|
||||
if (!rfds)
|
||||
return -ENOMEM;
|
||||
|
||||
rfd_names = strv_new("connection");
|
||||
rfd_names = strv_new(socket_fdname(sock));
|
||||
if (!rfd_names)
|
||||
return -ENOMEM;
|
||||
|
||||
|
@ -2393,10 +2393,9 @@ static void socket_enter_running(Socket *s, int cfd_in) {
|
||||
s->n_accepted++;
|
||||
|
||||
r = service_set_socket_fd(SERVICE(service), cfd, s, p, s->selinux_context_from_net);
|
||||
if (ERRNO_IS_NEG_DISCONNECT(r))
|
||||
return;
|
||||
if (r < 0) {
|
||||
if (ERRNO_IS_DISCONNECT(r))
|
||||
return;
|
||||
|
||||
log_unit_warning_errno(UNIT(s), r, "Failed to set socket on service: %m");
|
||||
goto fail;
|
||||
}
|
||||
@ -3419,17 +3418,22 @@ static int socket_get_timeout(Unit *u, usec_t *timeout) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
char* socket_fdname(Socket *s) {
|
||||
const char* socket_fdname(Socket *s) {
|
||||
assert(s);
|
||||
|
||||
/* Returns the name to use for $LISTEN_NAMES. If the user
|
||||
* didn't specify anything specifically, use the socket unit's
|
||||
* name as fallback. */
|
||||
/* Returns the name to use for $LISTEN_FDNAMES. If the user didn't specify anything specifically,
|
||||
* use the socket unit's name as fallback for Accept=no sockets, "connection" otherwise. */
|
||||
|
||||
return s->fdname ?: UNIT(s)->id;
|
||||
if (s->fdname)
|
||||
return s->fdname;
|
||||
|
||||
if (s->accept)
|
||||
return "connection";
|
||||
|
||||
return UNIT(s)->id;
|
||||
}
|
||||
|
||||
static PidRef *socket_control_pid(Unit *u) {
|
||||
static PidRef* socket_control_pid(Unit *u) {
|
||||
return &ASSERT_PTR(SOCKET(u))->control_pid;
|
||||
}
|
||||
|
||||
|
@ -185,7 +185,7 @@ int socket_port_to_address(const SocketPort *s, char **ret);
|
||||
|
||||
int socket_load_service_unit(Socket *s, int cfd, Unit **ret);
|
||||
|
||||
char* socket_fdname(Socket *s);
|
||||
const char* socket_fdname(Socket *s);
|
||||
|
||||
extern const UnitVTable socket_vtable;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user