summaryrefslogtreecommitdiff
path: root/src/passwd/getpwent_a.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2012-02-01 23:51:19 -0500
committerRich Felker <dalias@aerifal.cx>2012-02-01 23:51:19 -0500
commit4948a24df21c1e80bedc1f302547c9cb26e4dbfe (patch)
tree851caa5682e2dfdf753177c0e36f25f3e25f2c44 /src/passwd/getpwent_a.c
parent147f355cb698fc90a07e48048275831de73d0fc4 (diff)
downloadmusl-4948a24df21c1e80bedc1f302547c9cb26e4dbfe.tar.gz
musl-4948a24df21c1e80bedc1f302547c9cb26e4dbfe.tar.bz2
musl-4948a24df21c1e80bedc1f302547c9cb26e4dbfe.tar.xz
musl-4948a24df21c1e80bedc1f302547c9cb26e4dbfe.zip
make passwd/group functions safe against cancellation in stdio
these changes are a prerequisite to making stdio cancellable.
Diffstat (limited to 'src/passwd/getpwent_a.c')
-rw-r--r--src/passwd/getpwent_a.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/passwd/getpwent_a.c b/src/passwd/getpwent_a.c
index aaf84edd..1bd7f4fc 100644
--- a/src/passwd/getpwent_a.c
+++ b/src/passwd/getpwent_a.c
@@ -1,14 +1,18 @@
#include "pwf.h"
+#include <pthread.h>
struct passwd *__getpwent_a(FILE *f, struct passwd *pw, char **line, size_t *size)
{
ssize_t l;
char *s;
+ int cs;
+ pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
for (;;) {
if ((l=getline(line, size, f)) < 0) {
free(*line);
*line = 0;
- return 0;
+ pw = 0;
+ break;
}
line[0][l-1] = 0;
@@ -32,6 +36,8 @@ struct passwd *__getpwent_a(FILE *f, struct passwd *pw, char **line, size_t *siz
if (!(s = strchr(s, ':'))) continue;
*s++ = 0; pw->pw_shell = s;
- return pw;
+ break;
}
+ pthread_setcancelstate(cs, 0);
+ return pw;
}