#include <fcntl.h>
#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;
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;
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;
if (!(sq|dq|np)) return WRDE_BADCHAR;
break;
case '$':
+ if (sq) break;
if (s[i+1]=='(' && s[i+2]=='(') {
i += 2;
np += 2;
if (!f) {
close(p[0]);
kill(pid, SIGKILL);
- waitpid(pid, &status, 0);
+ reap(pid);
goto nospace;
}
free(getword(f));
if (feof(f)) {
fclose(f);
- while ((waitpid(pid, &status, 0) < 0 && errno == EINTR)
- || !WIFEXITED(status));
+ reap(pid);
return WRDE_SYNTAX;
}
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);