Skip to content

Commit

Permalink
states: Use execvp instead of execvpe
Browse files Browse the repository at this point in the history
execvpe is a handy GNU extension, but it is trivial to fall back to
the POSIX-mandated execvp by manually assigning to environ.  This
allows socket activation to build on BSD systems.

Fixes: 69dd28c
  • Loading branch information
ebblake committed Nov 15, 2019
1 parent 9e11e06 commit dc64ac5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
4 changes: 0 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ AC_CHECK_HEADERS([\

AC_CHECK_HEADERS([linux/vm_sockets.h], [], [], [#include <sys/socket.h>])

dnl Check for functions, all optional.
AC_CHECK_FUNCS([\
execvpe])

dnl Check for sys_errlist (optional).
AC_MSG_CHECKING([for sys_errlist])
AC_TRY_LINK([], [extern int sys_errlist; char *p = &sys_errlist;], [
Expand Down
16 changes: 5 additions & 11 deletions generator/states-connect-socket-activation.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
/* == strlen ("LISTEN_PID=") | strlen ("LISTEN_FDS=") */
#define PREFIX_LENGTH 11

/* Prepare environment for calling execvpe when doing systemd socket
extern char **environ;

/* Prepare environment for calling execvp when doing systemd socket
* activation. Takes the current environment and copies it. Removes
* any existing LISTEN_PID or LISTEN_FDS and replaces them with new
* variables. env[0] is "LISTEN_PID=..." which is filled in by
Expand All @@ -45,7 +47,6 @@
static char **
prepare_socket_activation_environment (void)
{
extern char **environ;
char **env = NULL;
char *p0 = NULL, *p1 = NULL;
size_t i, len;
Expand Down Expand Up @@ -97,7 +98,6 @@ prepare_socket_activation_environment (void)

STATE_MACHINE {
CONNECT_SA.START:
#ifdef HAVE_EXECVPE
int s;
struct sockaddr_un addr;
char **env;
Expand Down Expand Up @@ -200,7 +200,8 @@ STATE_MACHINE {
/* Restore SIGPIPE back to SIG_DFL. */
signal (SIGPIPE, SIG_DFL);

execvpe (h->argv[0], h->argv, env);
environ = env;
execvp (h->argv[0], h->argv);
nbd_internal_fork_safe_perror (h->argv[0]);
if (errno == ENOENT)
_exit (127);
Expand All @@ -217,11 +218,4 @@ STATE_MACHINE {
memcpy (&h->connaddr, &addr, h->connaddrlen);
SET_NEXT_STATE (%^CONNECT.START);
return 0;

#else /* !HAVE_EXECVPE */
SET_NEXT_STATE (%.DEAD);
set_error (ENOTSUP, "platform does not support socket activation");
return 0;
#endif

} /* END STATE MACHINE */

0 comments on commit dc64ac5

Please sign in to comment.