diff options
author | Eric Andersen <andersen@codepoet.org> | 2000-11-14 21:59:22 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2000-11-14 21:59:22 +0000 |
commit | 46f0beb16723acec0f03859ba813209e96396901 (patch) | |
tree | 60440e241f5a393651914e5006857fd23bceda0f | |
parent | 2aa1091130d86465534ab51adb42a0f33a40958b (diff) |
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).
-rw-r--r-- | lash.c | 57 | ||||
-rw-r--r-- | sh.c | 57 | ||||
-rw-r--r-- | shell/lash.c | 57 |
3 files changed, 102 insertions, 69 deletions
@@ -627,10 +627,10 @@ static int setupRedirections(struct childProgram *prog) mode = O_RDONLY; break; case REDIRECT_OVERWRITE: - mode = O_RDWR | O_CREAT | O_TRUNC; + mode = O_WRONLY | O_CREAT | O_TRUNC; break; case REDIRECT_APPEND: - mode = O_RDWR | O_CREAT | O_APPEND; + mode = O_WRONLY | O_CREAT | O_APPEND; break; } @@ -785,30 +785,42 @@ static void globLastArgument(struct childProgram *prog, int *argcPtr, #endif } - rc = glob(prog->argv[argc_l - 1], flags, NULL, &prog->globResult); - if (rc == GLOB_NOSPACE) { - errorMsg("out of space during glob operation\n"); - return; - } else if (rc == GLOB_NOMATCH || + if (strpbrk(prog->argv[argc_l - 1],"*[]?")!= NULL){ + rc = glob(prog->argv[argc_l - 1], flags, NULL, &prog->globResult); + if (rc == GLOB_NOSPACE) { + errorMsg("out of space during glob operation\n"); + return; + } else if (rc == GLOB_NOMATCH || (!rc && (prog->globResult.gl_pathc - i) == 1 && strcmp(prog->argv[argc_l - 1], prog->globResult.gl_pathv[i]) == 0)) { - /* we need to remove whatever \ quoting is still present */ - src = dst = prog->argv[argc_l - 1]; - while (*src) { - if (*src != '\\') - *dst++ = *src; - src++; + /* we need to remove whatever \ quoting is still present */ + src = dst = prog->argv[argc_l - 1]; + while (*src) { + if (*src != '\\') + *dst++ = *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 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); + }else{ + src = dst = prog->argv[argc_l - 1]; + while (*src) { + if (*src != '\\') + *dst++ = *src; + src++; + } + *dst = '\0'; + prog->globResult.gl_pathc=0; + if (flags==0) + prog->globResult.gl_pathv=NULL; } - *argcAllocedPtr = argcAlloced; *argcPtr = argc_l; } @@ -1128,7 +1140,7 @@ static int parseCommand(char **commandPtr, struct job *job, struct jobSet *jobLi } *commandPtr = returnCommand; - + return 0; } @@ -1143,7 +1155,6 @@ static int runCommand(struct job *newJob, struct jobSet *jobList, int inBg, int const struct BB_applet *a = applets; #endif - nextin = 0, nextout = 1; for (i = 0; i < newJob->numProgs; i++) { if ((i + 1) < newJob->numProgs) { @@ -627,10 +627,10 @@ static int setupRedirections(struct childProgram *prog) mode = O_RDONLY; break; case REDIRECT_OVERWRITE: - mode = O_RDWR | O_CREAT | O_TRUNC; + mode = O_WRONLY | O_CREAT | O_TRUNC; break; case REDIRECT_APPEND: - mode = O_RDWR | O_CREAT | O_APPEND; + mode = O_WRONLY | O_CREAT | O_APPEND; break; } @@ -785,30 +785,42 @@ static void globLastArgument(struct childProgram *prog, int *argcPtr, #endif } - rc = glob(prog->argv[argc_l - 1], flags, NULL, &prog->globResult); - if (rc == GLOB_NOSPACE) { - errorMsg("out of space during glob operation\n"); - return; - } else if (rc == GLOB_NOMATCH || + if (strpbrk(prog->argv[argc_l - 1],"*[]?")!= NULL){ + rc = glob(prog->argv[argc_l - 1], flags, NULL, &prog->globResult); + if (rc == GLOB_NOSPACE) { + errorMsg("out of space during glob operation\n"); + return; + } else if (rc == GLOB_NOMATCH || (!rc && (prog->globResult.gl_pathc - i) == 1 && strcmp(prog->argv[argc_l - 1], prog->globResult.gl_pathv[i]) == 0)) { - /* we need to remove whatever \ quoting is still present */ - src = dst = prog->argv[argc_l - 1]; - while (*src) { - if (*src != '\\') - *dst++ = *src; - src++; + /* we need to remove whatever \ quoting is still present */ + src = dst = prog->argv[argc_l - 1]; + while (*src) { + if (*src != '\\') + *dst++ = *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 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); + }else{ + src = dst = prog->argv[argc_l - 1]; + while (*src) { + if (*src != '\\') + *dst++ = *src; + src++; + } + *dst = '\0'; + prog->globResult.gl_pathc=0; + if (flags==0) + prog->globResult.gl_pathv=NULL; } - *argcAllocedPtr = argcAlloced; *argcPtr = argc_l; } @@ -1128,7 +1140,7 @@ static int parseCommand(char **commandPtr, struct job *job, struct jobSet *jobLi } *commandPtr = returnCommand; - + return 0; } @@ -1143,7 +1155,6 @@ static int runCommand(struct job *newJob, struct jobSet *jobList, int inBg, int const struct BB_applet *a = applets; #endif - nextin = 0, nextout = 1; for (i = 0; i < newJob->numProgs; i++) { if ((i + 1) < newJob->numProgs) { diff --git a/shell/lash.c b/shell/lash.c index b10614259..7a8810aef 100644 --- a/shell/lash.c +++ b/shell/lash.c @@ -627,10 +627,10 @@ static int setupRedirections(struct childProgram *prog) mode = O_RDONLY; break; case REDIRECT_OVERWRITE: - mode = O_RDWR | O_CREAT | O_TRUNC; + mode = O_WRONLY | O_CREAT | O_TRUNC; break; case REDIRECT_APPEND: - mode = O_RDWR | O_CREAT | O_APPEND; + mode = O_WRONLY | O_CREAT | O_APPEND; break; } @@ -785,30 +785,42 @@ static void globLastArgument(struct childProgram *prog, int *argcPtr, #endif } - rc = glob(prog->argv[argc_l - 1], flags, NULL, &prog->globResult); - if (rc == GLOB_NOSPACE) { - errorMsg("out of space during glob operation\n"); - return; - } else if (rc == GLOB_NOMATCH || + if (strpbrk(prog->argv[argc_l - 1],"*[]?")!= NULL){ + rc = glob(prog->argv[argc_l - 1], flags, NULL, &prog->globResult); + if (rc == GLOB_NOSPACE) { + errorMsg("out of space during glob operation\n"); + return; + } else if (rc == GLOB_NOMATCH || (!rc && (prog->globResult.gl_pathc - i) == 1 && strcmp(prog->argv[argc_l - 1], prog->globResult.gl_pathv[i]) == 0)) { - /* we need to remove whatever \ quoting is still present */ - src = dst = prog->argv[argc_l - 1]; - while (*src) { - if (*src != '\\') - *dst++ = *src; - src++; + /* we need to remove whatever \ quoting is still present */ + src = dst = prog->argv[argc_l - 1]; + while (*src) { + if (*src != '\\') + *dst++ = *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 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); + }else{ + src = dst = prog->argv[argc_l - 1]; + while (*src) { + if (*src != '\\') + *dst++ = *src; + src++; + } + *dst = '\0'; + prog->globResult.gl_pathc=0; + if (flags==0) + prog->globResult.gl_pathv=NULL; } - *argcAllocedPtr = argcAlloced; *argcPtr = argc_l; } @@ -1128,7 +1140,7 @@ static int parseCommand(char **commandPtr, struct job *job, struct jobSet *jobLi } *commandPtr = returnCommand; - + return 0; } @@ -1143,7 +1155,6 @@ static int runCommand(struct job *newJob, struct jobSet *jobList, int inBg, int const struct BB_applet *a = applets; #endif - nextin = 0, nextout = 1; for (i = 0; i < newJob->numProgs; i++) { if ((i + 1) < newJob->numProgs) { |