Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mptcpize: set GODEBUG=multipathtcp=1 env var #316

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/mptcpize.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#define SYSTEMCTL_SHOW "systemctl show -p FragmentPath "
#define PRELOAD_VAR "LD_PRELOAD="
#define MPTCPWRAP_ENV PKGLIBDIR"/libmptcpwrap.so.0.0."LIBREVISION
#define GODEBUG_VAR "GODEBUG="
#define MPTCPGO_ENV "multipathtcp=1"

/* Program documentation. */
static char args_doc[] = "CMD";
Expand Down Expand Up @@ -62,7 +64,7 @@ static void help(void)

static int run(int argc, char *av[])
{
int i, nr = 0, ld, debug = 0;
int i, nr = 0, ld, go, debug = 0;
char **envp, **argv, *env;
size_t len;

Expand All @@ -81,18 +83,22 @@ static int run(int argc, char *av[])
// build environment, copying the current one ...
while (environ[nr])
nr++;
envp = calloc(nr + 3, sizeof(char *));
envp = calloc(nr + 4, sizeof(char *));
if (!envp)
error(1, errno, "can't allocate env list");

// ... filtering out any 'LD_PRELOAD' ...
// ... filtering out any 'LD_PRELOAD' and 'GODEBUG' ...
nr = 0;
i = 0;
ld = -1;
go = -1;
while (environ[nr]) {
if (strncmp(environ[nr], PRELOAD_VAR,
strlen(PRELOAD_VAR)) == 0) {
ld = nr;
} else if (strncmp(environ[nr], GODEBUG_VAR,
strlen(GODEBUG_VAR)) == 0) {
go = nr;
} else {
envp[i] = environ[nr];
i++;
Expand All @@ -110,6 +116,16 @@ static int run(int argc, char *av[])
}
envp[i++] = env;

// .. and GODEBUG=multipathtcp=1 ...
if (go >= 0) {
len = strlen(environ[go]) + strlen(MPTCPGO_ENV) + 2;
env = alloca(len);
snprintf(env, len, "%s,%s", environ[go], MPTCPGO_ENV);
} else {
env = GODEBUG_VAR MPTCPGO_ENV;
}
envp[i++] = env;

// ... and enable dbg if needed
if (debug)
envp[i++] = "MPTCPWRAP_DEBUG=1";
Expand Down
Loading