fix execute to actually check for null and to actually check result of dup.
This commit is contained in:
parent
0424bf6403
commit
dfd2db7c85
@ -608,6 +608,8 @@ execute_command(void)
|
|||||||
{
|
{
|
||||||
YAP_Term ti = YAP_ARG2, to = YAP_ARG3, te = YAP_ARG4;
|
YAP_Term ti = YAP_ARG2, to = YAP_ARG3, te = YAP_ARG4;
|
||||||
int res;
|
int res;
|
||||||
|
YAP_Term AtomNull = YAP_MkAtomTerm(YAP_LookupAtom("null"));
|
||||||
|
|
||||||
#if defined(__MINGW32__) || _MSC_VER
|
#if defined(__MINGW32__) || _MSC_VER
|
||||||
HANDLE inpf, outf, errf;
|
HANDLE inpf, outf, errf;
|
||||||
DWORD CreationFlags = 0;
|
DWORD CreationFlags = 0;
|
||||||
@ -666,7 +668,7 @@ execute_command(void)
|
|||||||
#else /* UNIX CODE */
|
#else /* UNIX CODE */
|
||||||
int inpf, outf, errf;
|
int inpf, outf, errf;
|
||||||
/* process input first */
|
/* process input first */
|
||||||
if (YAP_IsAtomTerm(ti)) {
|
if (ti == AtomNull) {
|
||||||
inpf = open("/dev/null", O_RDONLY);
|
inpf = open("/dev/null", O_RDONLY);
|
||||||
} else {
|
} else {
|
||||||
int sd;
|
int sd;
|
||||||
@ -681,7 +683,7 @@ execute_command(void)
|
|||||||
return(YAP_Unify(YAP_ARG6, YAP_MkIntTerm(errno)));
|
return(YAP_Unify(YAP_ARG6, YAP_MkIntTerm(errno)));
|
||||||
}
|
}
|
||||||
/* then output stream */
|
/* then output stream */
|
||||||
if (YAP_IsAtomTerm(to)) {
|
if (to == AtomNull) {
|
||||||
outf = open("/dev/zero", O_WRONLY);
|
outf = open("/dev/zero", O_WRONLY);
|
||||||
} else {
|
} else {
|
||||||
int sd;
|
int sd;
|
||||||
@ -697,7 +699,7 @@ execute_command(void)
|
|||||||
return(YAP_Unify(YAP_ARG6, YAP_MkIntTerm(errno)));
|
return(YAP_Unify(YAP_ARG6, YAP_MkIntTerm(errno)));
|
||||||
}
|
}
|
||||||
/* then error stream */
|
/* then error stream */
|
||||||
if (YAP_IsAtomTerm(te)) {
|
if (te == AtomNull) {
|
||||||
errf = open("/dev/zero", O_WRONLY);
|
errf = open("/dev/zero", O_WRONLY);
|
||||||
} else {
|
} else {
|
||||||
int sd;
|
int sd;
|
||||||
@ -729,13 +731,16 @@ execute_command(void)
|
|||||||
/* close current streams, but not std streams */
|
/* close current streams, but not std streams */
|
||||||
YAP_CloseAllOpenStreams();
|
YAP_CloseAllOpenStreams();
|
||||||
close(0);
|
close(0);
|
||||||
dup(inpf);
|
if (dup(inpf) != 0)
|
||||||
|
exit(1);
|
||||||
close(inpf);
|
close(inpf);
|
||||||
close(1);
|
close(1);
|
||||||
dup(outf);
|
if (dup(outf) != 1)
|
||||||
|
exit(1);
|
||||||
close(outf);
|
close(outf);
|
||||||
close(2);
|
close(2);
|
||||||
dup(errf);
|
if (dup(errf) != 2)
|
||||||
|
exit(2);
|
||||||
close(errf);
|
close(errf);
|
||||||
argv[0] = "sh";
|
argv[0] = "sh";
|
||||||
argv[1] = "-c";
|
argv[1] = "-c";
|
||||||
|
Reference in New Issue
Block a user