X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fmisc%2Fwordexp.c;h=db83a69f37d996aa2a9f61bde18a60c06a727505;hb=711673ee772e20a74aaf301c2d7745c20c4f4d47;hp=1387b5d276c264a3d5521527f5f749cc43cd3ca8;hpb=caaf7d443d8f502a209cb5489c45ddcccbebdd34;p=musl diff --git a/src/misc/wordexp.c b/src/misc/wordexp.c index 1387b5d2..db83a69f 100644 --- a/src/misc/wordexp.c +++ b/src/misc/wordexp.c @@ -11,6 +11,12 @@ #include #include "pthread_impl.h" +static void reap(pid_t pid) +{ + int status; + while (waitpid(pid, &status, 0) < 0 && errno == EINTR); +} + static char *getword(FILE *f) { char *s = 0; @@ -24,7 +30,7 @@ static int do_wordexp(const char *s, wordexp_t *we, int flags) size_t np=0; char *w, **tmp; char *redir = (flags & WRDE_SHOWERR) ? "" : "2>/dev/null"; - int err = 0, status; + int err = 0; FILE *f; size_t wc = 0; char **wv = 0; @@ -36,7 +42,7 @@ static int do_wordexp(const char *s, wordexp_t *we, int flags) if (flags & WRDE_NOCMD) for (i=0; s[i]; i++) switch (s[i]) { case '\\': - if (!sq) i++; + if (!sq && !s[++i]) return WRDE_SYNTAX; break; case '\'': if (!dq) sq^=1; @@ -65,6 +71,7 @@ static int do_wordexp(const char *s, wordexp_t *we, int flags) if (!(sq|dq|np)) return WRDE_BADCHAR; break; case '$': + if (sq) break; if (s[i+1]=='(' && s[i+2]=='(') { i += 2; np += 2; @@ -112,7 +119,7 @@ static int do_wordexp(const char *s, wordexp_t *we, int flags) if (!f) { close(p[0]); kill(pid, SIGKILL); - waitpid(pid, &status, 0); + reap(pid); goto nospace; } @@ -121,8 +128,7 @@ static int do_wordexp(const char *s, wordexp_t *we, int flags) free(getword(f)); if (feof(f)) { fclose(f); - while ((waitpid(pid, &status, 0) < 0 && errno == EINTR) - || !WIFEXITED(status)); + reap(pid); return WRDE_SYNTAX; } @@ -139,8 +145,7 @@ static int do_wordexp(const char *s, wordexp_t *we, int flags) if (!feof(f)) err = WRDE_NOSPACE; fclose(f); - while ((waitpid(pid, &status, 0) < 0 && errno == EINTR) - || !WIFEXITED(status)); + reap(pid); if (!wv) wv = calloc(i+1, sizeof *wv);