mirror of
https://github.com/fosslinux/live-bootstrap.git
synced 2026-03-23 11:36:32 +01:00
Only add variables to environment if they are already set
This commit is contained in:
parent
c4e12161b7
commit
53d1c416be
1 changed files with 25 additions and 8 deletions
33
sysa/wrap.c
33
sysa/wrap.c
|
|
@ -225,18 +225,35 @@ int main(int argc, char **argv, char **envp) {
|
||||||
chroot (".");
|
chroot (".");
|
||||||
}
|
}
|
||||||
free(cwd);
|
free(cwd);
|
||||||
|
|
||||||
|
|
||||||
char **newenv = malloc(3 * sizeof(char *));
|
char **newenv = malloc(3 * sizeof(char *));
|
||||||
|
int newenv_index = 0;
|
||||||
|
require(newenv != NULL, "Failed to allocate space for new environment.");
|
||||||
|
|
||||||
char *ARCH = getenv("ARCH");
|
char *ARCH = getenv("ARCH");
|
||||||
newenv[0] = malloc(6 + strlen(ARCH));
|
if (ARCH != NULL) {
|
||||||
strcpy(newenv[0], "ARCH=");
|
newenv[0] = malloc(6 + strlen(ARCH));
|
||||||
strcpy(newenv[0] + 5, ARCH);
|
require(newenv[0] != NULL, "Failed to allocate space for new environment.");
|
||||||
|
strcpy(newenv[0], "ARCH=");
|
||||||
|
strcpy(newenv[0] + 5, ARCH);
|
||||||
|
newenv_index += 1;
|
||||||
|
}
|
||||||
|
|
||||||
char *ARCH_DIR = getenv("ARCH_DIR");
|
char *ARCH_DIR = getenv("ARCH_DIR");
|
||||||
newenv[1] = malloc(10 + strlen(ARCH_DIR));
|
if (ARCH_DIR != NULL) {
|
||||||
strcpy(newenv[1], "ARCH_DIR=");
|
newenv[newenv_index] = malloc(10 + strlen(ARCH_DIR));
|
||||||
strcpy(newenv[1] + 9, ARCH_DIR);
|
require(newenv[newenv_index] != NULL, "Failed to allocate space for new environment.");
|
||||||
newenv[2] = NULL;
|
strcpy(newenv[newenv_index], "ARCH_DIR=");
|
||||||
|
strcpy(newenv[newenv_index] + 9, ARCH_DIR);
|
||||||
|
newenv_index += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
newenv[newenv_index] = NULL;
|
||||||
|
|
||||||
|
|
||||||
#ifdef __M2__
|
#ifdef __M2__
|
||||||
return execve (argv[1], argv + sizeof(char *) , newenv);
|
return execve (argv[1], argv + sizeof(char *), newenv);
|
||||||
#else
|
#else
|
||||||
return execve (argv[1], argv + 1, newenv);
|
return execve (argv[1], argv + 1, newenv);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue