Another shell attribute 'unsetenv' that will cause to unsetenv("ENV")
before executing the shell. Until now this was done when the default shell was the ksh. This failed if the default shell was sh or csh and the user switched to ksh.
This commit is contained in:
parent
103db97f6e
commit
6c1f15aa0b
@ -316,6 +316,8 @@ struct Shell {
|
||||
|
||||
ArgArray builtins;
|
||||
char *meta;
|
||||
|
||||
Boolean unsetenv; /* unsetenv("ENV") before exec */
|
||||
};
|
||||
TAILQ_HEAD(Shells, Shell);
|
||||
|
||||
@ -409,7 +411,7 @@ static const char *const shells_init[] = {
|
||||
"quiet='set -' echo='set -v' filter='set -' "
|
||||
"hasErrCtl=Y check='set -e' ignore='set +e' "
|
||||
"echoFlag=v errFlag=e "
|
||||
"meta='" SH_META "' builtins='" SH_BUILTINS "'",
|
||||
"meta='" SH_META "' builtins='" SH_BUILTINS "' unsetenv=T",
|
||||
|
||||
NULL
|
||||
};
|
||||
@ -646,13 +648,6 @@ Proc_Init()
|
||||
sa.sa_flags = SA_RESTART | SA_NOCLDSTOP;
|
||||
sa.sa_handler = catch_child;
|
||||
sigaction(SIGCHLD, &sa, NULL);
|
||||
|
||||
#if DEFSHELL == 2
|
||||
/*
|
||||
* Turn off ENV to make ksh happier.
|
||||
*/
|
||||
unsetenv("ENV");
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@ -698,6 +693,11 @@ ProcExec(const ProcStuff *ps)
|
||||
Punt("Cannot dup2: %s", strerror(errno));
|
||||
}
|
||||
|
||||
if (commandShell->unsetenv) {
|
||||
/* for the benfit of ksh */
|
||||
unsetenv("ENV");
|
||||
}
|
||||
|
||||
/*
|
||||
* The file descriptors for stdin, stdout, or stderr might
|
||||
* have been marked close-on-exec. Clear the flag on all
|
||||
@ -2582,6 +2582,7 @@ JobShellDump(const struct Shell *sh)
|
||||
for (i = 1; i < sh->builtins.argc; i++)
|
||||
fprintf(stderr, " '%s'", sh->builtins.argv[i]);
|
||||
fprintf(stderr, "\n meta='%s'\n", sh->meta);
|
||||
fprintf(stderr, " unsetenv=%d\n", sh->unsetenv);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2670,6 +2671,10 @@ JobParseShellSpec(const char *spec, Boolean *fullSpec)
|
||||
free(sh->meta);
|
||||
sh->meta = estrdup(eq);
|
||||
*fullSpec = TRUE;
|
||||
} else if (strcmp(keyw, "unsetenv") == 0) {
|
||||
sh->unsetenv = (*eq == 'Y' || *eq == 'y' ||
|
||||
*eq == 'T' || *eq == 't');
|
||||
*fullSpec = TRUE;
|
||||
} else {
|
||||
Parse_Error(PARSE_FATAL, "unknown keyword in shell "
|
||||
"specification '%s'", keyw);
|
||||
|
@ -1325,6 +1325,11 @@ character not starts with a shell builtin it is executed directly without
|
||||
invoking a shell.
|
||||
When one of these strings (or both) is empty all commands are executed
|
||||
through a shell.
|
||||
.It Va unsetenv
|
||||
If true remove the
|
||||
.Ev ENV
|
||||
environment variable before executing any command.
|
||||
This is useful for the Korn-shell ksh.
|
||||
.El
|
||||
.Pp
|
||||
Values that are strings must be surrounded by double quotes.
|
||||
|
Loading…
x
Reference in New Issue
Block a user