prepare_socket_activation_environment() is a construction function that is
supposed to fill in a string_vector object from the ground up. Right now
it has its responsibilities mixed up in two ways:
- it expects the caller to pass in a previously re-set string_vector,
- if it fails, it calls set_error() internally (with a blanket reference
to "malloc").
Fix the first wart:
- pass in an *uninitialized* (only allocated) string vector from the
caller, and initialize it in prepare_socket_activation_environment().
Document the second wart:
- in the caller, add a comment about the set_error() call that's
internal to the callee.
Signed-off-by: Laszlo Ersek <lersek(a)redhat.com>
Reviewed-by: Eric Blake <eblake(a)redhat.com>
Acked-by: Richard W.M. Jones <rjones(a)redhat.com>
---
Notes:
v4:
- Pick up Eric's R-b.
- Pick up Rich's A-b for initializing the string vector (via struct
assignment) internally to prepare_socket_activation_environment().
- Keep the set_error() call internal to
prepare_socket_activation_environment(), just add a comment about it
near the prepare_socket_activation_environment() call site [Rich].
(Unfortunately, this creates a long series of rebase conflicts.)
- Update the commit message.
generator/states-connect-socket-activation.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/generator/states-connect-socket-activation.c
b/generator/states-connect-socket-activation.c
index ddbccff8240d..61d3d1900f45 100644
--- a/generator/states-connect-socket-activation.c
+++ b/generator/states-connect-socket-activation.c
@@ -51,7 +51,7 @@ prepare_socket_activation_environment (string_vector *env)
char *p;
size_t i;
- assert (env->len == 0);
+ *env = (string_vector)empty_vector;
/* Reserve slots env[0] and env[1]. */
p = strdup ("LISTEN_PID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
@@ -99,7 +99,7 @@ STATE_MACHINE {
CONNECT_SA.START:
int s;
struct sockaddr_un addr;
- string_vector env = empty_vector;
+ string_vector env;
pid_t pid;
assert (!h->sock);
@@ -156,6 +156,7 @@ CONNECT_SA.START:
if (prepare_socket_activation_environment (&env) == -1) {
SET_NEXT_STATE (%.DEAD);
+ /* prepare_socket_activation_environment() calls set_error() internally */
close (s);
return 0;
}