[prev in list] [next in list] [prev in thread] [next in thread] 

List:       libguestfs
Subject:    [Libguestfs] [libnbd PATCH v5 4/4] socket activation: set LISTEN_FDNAMES
From:       Laszlo Ersek <lersek () redhat ! com>
Date:       2023-03-25 11:39:29
Message-ID: 20230325113929.188598-5-lersek () redhat ! com
[Download RAW message or body]

Add LISTEN_FDNAMES to the child process's environment unconditionally.

- If the user calls nbd_set_socket_activation_name() with a non-empty
  string before calling nbd_connect_systemd_socket_activation(), pass the
  name down to the server through LISTEN_FDNAMES.

  This is a feature addition.

- If the user doesn't call nbd_set_socket_activation_name(), or calls it
  with the empty string, add "LISTEN_FDNAMES=unknown" to the environment,
  overwriting any potentially inherited LISTEN_FDNAMES variable.

  This is a bugfix: otherwise we could leak a confusing LISTEN_FDNAMES to
  the child process, in case the libnbd client app were itself
  socket-activated. Given "LISTEN_FDS=1", the setting
  "LISTEN_FDNAMES=unknown" has the same effect on the child as removing
  LISTEN_FDNAMES from the environment:
  <https://www.freedesktop.org/software/systemd/man/sd_listen_fds.html>.

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---

Notes:
    v5:
    
    - push LISTEN_FDNAMES unconditionally, with value "unknown" if the
      socket activation name is not set by the libnbd client application --
      rewrite patch and commit message [Eric, Laszlo]
    
    - drop Rich's R-b due to the above changes
    
    v4:
    
    - pick up Rich's R-b
    
    - resolve rebase conflict near the
      prepare_socket_activation_environment() call site, due to keeping
      set_error() internal to that callee, in patch "socket activation:
      clean up responsibilities of prep.sock.act.env.()"

 generator/states-connect-socket-activation.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/generator/states-connect-socket-activation.c b/generator/states-connect-socket-activation.c
index 10ccc3119299..b57d5d0075b0 100644
--- a/generator/states-connect-socket-activation.c
+++ b/generator/states-connect-socket-activation.c
@@ -185,7 +185,7 @@  CONNECT_SA.START:
   struct sockaddr_un addr;
   struct execvpe execvpe_ctx;
   size_t num_vars;
-  struct sact_var sact_var[2];
+  struct sact_var sact_var[3];
   size_t pid_ofs;
   string_vector env;
   pid_t pid;
@@ -245,6 +245,16 @@  CONNECT_SA.START:
                  "LISTEN_PID=", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", &pid_ofs);
   SACT_VAR_PUSH (sact_var, &num_vars,
                  "LISTEN_FDS=", "1", NULL);
+  /* Push LISTEN_FDNAMES unconditionally. This ensures we overwrite any
+   * inherited LISTEN_FDNAMES. If "h->sact_name" is NULL, then push
+   * "LISTEN_FDNAMES=unknown"; it will have the same effect on the child process
+   * as unsetting LISTEN_FDNAMES would (with LISTEN_FDS being set to 1):
+   * <https://www.freedesktop.org/software/systemd/man/sd_listen_fds.html>.
+   */
+  SACT_VAR_PUSH (sact_var, &num_vars,
+                 "LISTEN_FDNAMES=",
+                 h->sact_name == NULL ? "unknown" : h->sact_name,
+                 NULL);
   if (prepare_socket_activation_environment (&env, sact_var, num_vars) == -1)
     /* prepare_socket_activation_environment() calls set_error() internally */
     goto uninit_execvpe;
_______________________________________________
Libguestfs mailing list
Libguestfs@redhat.com
https://listman.redhat.com/mailman/listinfo/libguestfs

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic