summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-04-19 23:42:56 -0400
committerRich Felker <dalias@aerifal.cx>2011-04-19 23:42:56 -0400
commit145c05345d6172eef1c8c274d696dbe1c01b88ab (patch)
tree7fc8c21ea494714f9dd2f4fdba344e38f71d51a3 /src
parentf0fc95d439459bac27d0d26ec151700a1579b028 (diff)
downloadmusl-145c05345d6172eef1c8c274d696dbe1c01b88ab.tar.gz
musl-145c05345d6172eef1c8c274d696dbe1c01b88ab.tar.bz2
musl-145c05345d6172eef1c8c274d696dbe1c01b88ab.tar.xz
musl-145c05345d6172eef1c8c274d696dbe1c01b88ab.zip
block cancellation in wordexp, handle more errors
Diffstat (limited to 'src')
-rw-r--r--src/misc/wordexp.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/misc/wordexp.c b/src/misc/wordexp.c
index 171f2702..4609b99f 100644
--- a/src/misc/wordexp.c
+++ b/src/misc/wordexp.c
@@ -7,6 +7,7 @@
#include <stdlib.h>
#include <sys/wait.h>
#include <signal.h>
+#include <pthread.h>
static char *getword(FILE *f)
{
@@ -14,7 +15,7 @@ static char *getword(FILE *f)
return getdelim(&s, (size_t [1]){0}, 0, f) < 0 ? 0 : s;
}
-int wordexp(const char *s, wordexp_t *we, int flags)
+static int do_wordexp(const char *s, wordexp_t *we, int flags)
{
size_t i, l;
int sq=0, dq=0;
@@ -83,8 +84,13 @@ int wordexp(const char *s, wordexp_t *we, int flags)
i += we->we_offs;
}
- pipe(p);
+ if (pipe(p) < 0) return WRDE_NOSPACE;
pid = fork();
+ if (pid < 0) {
+ close(p[0]);
+ close(p[1]);
+ return WRDE_NOSPACE;
+ }
if (!pid) {
dup2(p[1], 1);
close(p[0]);
@@ -134,6 +140,15 @@ int wordexp(const char *s, wordexp_t *we, int flags)
return err;
}
+int wordexp(const char *s, wordexp_t *we, int flags)
+{
+ int r, cs;
+ pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
+ r = do_wordexp(s, we, flags);
+ pthread_setcancelstate(cs, 0);
+ return r;
+}
+
void wordfree(wordexp_t *we)
{
size_t i;