Patch from Gennady Feldman <gfeldman@tradeline.net> to:
1. Opens redirections w/ the right access. 2. Doesn't do globbing for every single parameter (so it doesn't stat every parameter).
This commit is contained in:
parent
2aa1091130
commit
46f0beb167
55
lash.c
55
lash.c
@ -627,10 +627,10 @@ static int setupRedirections(struct childProgram *prog)
|
|||||||
mode = O_RDONLY;
|
mode = O_RDONLY;
|
||||||
break;
|
break;
|
||||||
case REDIRECT_OVERWRITE:
|
case REDIRECT_OVERWRITE:
|
||||||
mode = O_RDWR | O_CREAT | O_TRUNC;
|
mode = O_WRONLY | O_CREAT | O_TRUNC;
|
||||||
break;
|
break;
|
||||||
case REDIRECT_APPEND:
|
case REDIRECT_APPEND:
|
||||||
mode = O_RDWR | O_CREAT | O_APPEND;
|
mode = O_WRONLY | O_CREAT | O_APPEND;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -785,30 +785,42 @@ static void globLastArgument(struct childProgram *prog, int *argcPtr,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = glob(prog->argv[argc_l - 1], flags, NULL, &prog->globResult);
|
if (strpbrk(prog->argv[argc_l - 1],"*[]?")!= NULL){
|
||||||
if (rc == GLOB_NOSPACE) {
|
rc = glob(prog->argv[argc_l - 1], flags, NULL, &prog->globResult);
|
||||||
errorMsg("out of space during glob operation\n");
|
if (rc == GLOB_NOSPACE) {
|
||||||
return;
|
errorMsg("out of space during glob operation\n");
|
||||||
} else if (rc == GLOB_NOMATCH ||
|
return;
|
||||||
|
} else if (rc == GLOB_NOMATCH ||
|
||||||
(!rc && (prog->globResult.gl_pathc - i) == 1 &&
|
(!rc && (prog->globResult.gl_pathc - i) == 1 &&
|
||||||
strcmp(prog->argv[argc_l - 1],
|
strcmp(prog->argv[argc_l - 1],
|
||||||
prog->globResult.gl_pathv[i]) == 0)) {
|
prog->globResult.gl_pathv[i]) == 0)) {
|
||||||
/* we need to remove whatever \ quoting is still present */
|
/* we need to remove whatever \ quoting is still present */
|
||||||
src = dst = prog->argv[argc_l - 1];
|
src = dst = prog->argv[argc_l - 1];
|
||||||
while (*src) {
|
while (*src) {
|
||||||
if (*src != '\\')
|
if (*src != '\\')
|
||||||
*dst++ = *src;
|
*dst++ = *src;
|
||||||
src++;
|
src++;
|
||||||
|
}
|
||||||
|
*dst = '\0';
|
||||||
|
} else if (!rc) {
|
||||||
|
argcAlloced += (prog->globResult.gl_pathc - i);
|
||||||
|
prog->argv = xrealloc(prog->argv, argcAlloced * sizeof(*prog->argv));
|
||||||
|
memcpy(prog->argv + (argc_l - 1), prog->globResult.gl_pathv + i,
|
||||||
|
sizeof(*(prog->argv)) * (prog->globResult.gl_pathc - i));
|
||||||
|
argc_l += (prog->globResult.gl_pathc - i - 1);
|
||||||
}
|
}
|
||||||
*dst = '\0';
|
}else{
|
||||||
} else if (!rc) {
|
src = dst = prog->argv[argc_l - 1];
|
||||||
argcAlloced += (prog->globResult.gl_pathc - i);
|
while (*src) {
|
||||||
prog->argv = xrealloc(prog->argv, argcAlloced * sizeof(*prog->argv));
|
if (*src != '\\')
|
||||||
memcpy(prog->argv + (argc_l - 1), prog->globResult.gl_pathv + i,
|
*dst++ = *src;
|
||||||
sizeof(*(prog->argv)) * (prog->globResult.gl_pathc - i));
|
src++;
|
||||||
argc_l += (prog->globResult.gl_pathc - i - 1);
|
}
|
||||||
|
*dst = '\0';
|
||||||
|
prog->globResult.gl_pathc=0;
|
||||||
|
if (flags==0)
|
||||||
|
prog->globResult.gl_pathv=NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
*argcAllocedPtr = argcAlloced;
|
*argcAllocedPtr = argcAlloced;
|
||||||
*argcPtr = argc_l;
|
*argcPtr = argc_l;
|
||||||
}
|
}
|
||||||
@ -1143,7 +1155,6 @@ static int runCommand(struct job *newJob, struct jobSet *jobList, int inBg, int
|
|||||||
const struct BB_applet *a = applets;
|
const struct BB_applet *a = applets;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
nextin = 0, nextout = 1;
|
nextin = 0, nextout = 1;
|
||||||
for (i = 0; i < newJob->numProgs; i++) {
|
for (i = 0; i < newJob->numProgs; i++) {
|
||||||
if ((i + 1) < newJob->numProgs) {
|
if ((i + 1) < newJob->numProgs) {
|
||||||
|
55
sh.c
55
sh.c
@ -627,10 +627,10 @@ static int setupRedirections(struct childProgram *prog)
|
|||||||
mode = O_RDONLY;
|
mode = O_RDONLY;
|
||||||
break;
|
break;
|
||||||
case REDIRECT_OVERWRITE:
|
case REDIRECT_OVERWRITE:
|
||||||
mode = O_RDWR | O_CREAT | O_TRUNC;
|
mode = O_WRONLY | O_CREAT | O_TRUNC;
|
||||||
break;
|
break;
|
||||||
case REDIRECT_APPEND:
|
case REDIRECT_APPEND:
|
||||||
mode = O_RDWR | O_CREAT | O_APPEND;
|
mode = O_WRONLY | O_CREAT | O_APPEND;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -785,30 +785,42 @@ static void globLastArgument(struct childProgram *prog, int *argcPtr,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = glob(prog->argv[argc_l - 1], flags, NULL, &prog->globResult);
|
if (strpbrk(prog->argv[argc_l - 1],"*[]?")!= NULL){
|
||||||
if (rc == GLOB_NOSPACE) {
|
rc = glob(prog->argv[argc_l - 1], flags, NULL, &prog->globResult);
|
||||||
errorMsg("out of space during glob operation\n");
|
if (rc == GLOB_NOSPACE) {
|
||||||
return;
|
errorMsg("out of space during glob operation\n");
|
||||||
} else if (rc == GLOB_NOMATCH ||
|
return;
|
||||||
|
} else if (rc == GLOB_NOMATCH ||
|
||||||
(!rc && (prog->globResult.gl_pathc - i) == 1 &&
|
(!rc && (prog->globResult.gl_pathc - i) == 1 &&
|
||||||
strcmp(prog->argv[argc_l - 1],
|
strcmp(prog->argv[argc_l - 1],
|
||||||
prog->globResult.gl_pathv[i]) == 0)) {
|
prog->globResult.gl_pathv[i]) == 0)) {
|
||||||
/* we need to remove whatever \ quoting is still present */
|
/* we need to remove whatever \ quoting is still present */
|
||||||
src = dst = prog->argv[argc_l - 1];
|
src = dst = prog->argv[argc_l - 1];
|
||||||
while (*src) {
|
while (*src) {
|
||||||
if (*src != '\\')
|
if (*src != '\\')
|
||||||
*dst++ = *src;
|
*dst++ = *src;
|
||||||
src++;
|
src++;
|
||||||
|
}
|
||||||
|
*dst = '\0';
|
||||||
|
} else if (!rc) {
|
||||||
|
argcAlloced += (prog->globResult.gl_pathc - i);
|
||||||
|
prog->argv = xrealloc(prog->argv, argcAlloced * sizeof(*prog->argv));
|
||||||
|
memcpy(prog->argv + (argc_l - 1), prog->globResult.gl_pathv + i,
|
||||||
|
sizeof(*(prog->argv)) * (prog->globResult.gl_pathc - i));
|
||||||
|
argc_l += (prog->globResult.gl_pathc - i - 1);
|
||||||
}
|
}
|
||||||
*dst = '\0';
|
}else{
|
||||||
} else if (!rc) {
|
src = dst = prog->argv[argc_l - 1];
|
||||||
argcAlloced += (prog->globResult.gl_pathc - i);
|
while (*src) {
|
||||||
prog->argv = xrealloc(prog->argv, argcAlloced * sizeof(*prog->argv));
|
if (*src != '\\')
|
||||||
memcpy(prog->argv + (argc_l - 1), prog->globResult.gl_pathv + i,
|
*dst++ = *src;
|
||||||
sizeof(*(prog->argv)) * (prog->globResult.gl_pathc - i));
|
src++;
|
||||||
argc_l += (prog->globResult.gl_pathc - i - 1);
|
}
|
||||||
|
*dst = '\0';
|
||||||
|
prog->globResult.gl_pathc=0;
|
||||||
|
if (flags==0)
|
||||||
|
prog->globResult.gl_pathv=NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
*argcAllocedPtr = argcAlloced;
|
*argcAllocedPtr = argcAlloced;
|
||||||
*argcPtr = argc_l;
|
*argcPtr = argc_l;
|
||||||
}
|
}
|
||||||
@ -1143,7 +1155,6 @@ static int runCommand(struct job *newJob, struct jobSet *jobList, int inBg, int
|
|||||||
const struct BB_applet *a = applets;
|
const struct BB_applet *a = applets;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
nextin = 0, nextout = 1;
|
nextin = 0, nextout = 1;
|
||||||
for (i = 0; i < newJob->numProgs; i++) {
|
for (i = 0; i < newJob->numProgs; i++) {
|
||||||
if ((i + 1) < newJob->numProgs) {
|
if ((i + 1) < newJob->numProgs) {
|
||||||
|
55
shell/lash.c
55
shell/lash.c
@ -627,10 +627,10 @@ static int setupRedirections(struct childProgram *prog)
|
|||||||
mode = O_RDONLY;
|
mode = O_RDONLY;
|
||||||
break;
|
break;
|
||||||
case REDIRECT_OVERWRITE:
|
case REDIRECT_OVERWRITE:
|
||||||
mode = O_RDWR | O_CREAT | O_TRUNC;
|
mode = O_WRONLY | O_CREAT | O_TRUNC;
|
||||||
break;
|
break;
|
||||||
case REDIRECT_APPEND:
|
case REDIRECT_APPEND:
|
||||||
mode = O_RDWR | O_CREAT | O_APPEND;
|
mode = O_WRONLY | O_CREAT | O_APPEND;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -785,30 +785,42 @@ static void globLastArgument(struct childProgram *prog, int *argcPtr,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = glob(prog->argv[argc_l - 1], flags, NULL, &prog->globResult);
|
if (strpbrk(prog->argv[argc_l - 1],"*[]?")!= NULL){
|
||||||
if (rc == GLOB_NOSPACE) {
|
rc = glob(prog->argv[argc_l - 1], flags, NULL, &prog->globResult);
|
||||||
errorMsg("out of space during glob operation\n");
|
if (rc == GLOB_NOSPACE) {
|
||||||
return;
|
errorMsg("out of space during glob operation\n");
|
||||||
} else if (rc == GLOB_NOMATCH ||
|
return;
|
||||||
|
} else if (rc == GLOB_NOMATCH ||
|
||||||
(!rc && (prog->globResult.gl_pathc - i) == 1 &&
|
(!rc && (prog->globResult.gl_pathc - i) == 1 &&
|
||||||
strcmp(prog->argv[argc_l - 1],
|
strcmp(prog->argv[argc_l - 1],
|
||||||
prog->globResult.gl_pathv[i]) == 0)) {
|
prog->globResult.gl_pathv[i]) == 0)) {
|
||||||
/* we need to remove whatever \ quoting is still present */
|
/* we need to remove whatever \ quoting is still present */
|
||||||
src = dst = prog->argv[argc_l - 1];
|
src = dst = prog->argv[argc_l - 1];
|
||||||
while (*src) {
|
while (*src) {
|
||||||
if (*src != '\\')
|
if (*src != '\\')
|
||||||
*dst++ = *src;
|
*dst++ = *src;
|
||||||
src++;
|
src++;
|
||||||
|
}
|
||||||
|
*dst = '\0';
|
||||||
|
} else if (!rc) {
|
||||||
|
argcAlloced += (prog->globResult.gl_pathc - i);
|
||||||
|
prog->argv = xrealloc(prog->argv, argcAlloced * sizeof(*prog->argv));
|
||||||
|
memcpy(prog->argv + (argc_l - 1), prog->globResult.gl_pathv + i,
|
||||||
|
sizeof(*(prog->argv)) * (prog->globResult.gl_pathc - i));
|
||||||
|
argc_l += (prog->globResult.gl_pathc - i - 1);
|
||||||
}
|
}
|
||||||
*dst = '\0';
|
}else{
|
||||||
} else if (!rc) {
|
src = dst = prog->argv[argc_l - 1];
|
||||||
argcAlloced += (prog->globResult.gl_pathc - i);
|
while (*src) {
|
||||||
prog->argv = xrealloc(prog->argv, argcAlloced * sizeof(*prog->argv));
|
if (*src != '\\')
|
||||||
memcpy(prog->argv + (argc_l - 1), prog->globResult.gl_pathv + i,
|
*dst++ = *src;
|
||||||
sizeof(*(prog->argv)) * (prog->globResult.gl_pathc - i));
|
src++;
|
||||||
argc_l += (prog->globResult.gl_pathc - i - 1);
|
}
|
||||||
|
*dst = '\0';
|
||||||
|
prog->globResult.gl_pathc=0;
|
||||||
|
if (flags==0)
|
||||||
|
prog->globResult.gl_pathv=NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
*argcAllocedPtr = argcAlloced;
|
*argcAllocedPtr = argcAlloced;
|
||||||
*argcPtr = argc_l;
|
*argcPtr = argc_l;
|
||||||
}
|
}
|
||||||
@ -1143,7 +1155,6 @@ static int runCommand(struct job *newJob, struct jobSet *jobList, int inBg, int
|
|||||||
const struct BB_applet *a = applets;
|
const struct BB_applet *a = applets;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
nextin = 0, nextout = 1;
|
nextin = 0, nextout = 1;
|
||||||
for (i = 0; i < newJob->numProgs; i++) {
|
for (i = 0; i < newJob->numProgs; i++) {
|
||||||
if ((i + 1) < newJob->numProgs) {
|
if ((i + 1) < newJob->numProgs) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user