summaryrefslogtreecommitdiff
path: root/src/passwd/getgr_r.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/getgr_r.c
parent147f355cb698fc90a07e48048275831de73d0fc4 (diff)
downloadmusl-4948a24df21c1e80bedc1f302547c9cb26e4dbfe.tar.gz
make passwd/group functions safe against cancellation in stdio
these changes are a prerequisite to making stdio cancellable.
Diffstat (limited to 'src/passwd/getgr_r.c')
-rw-r--r--src/passwd/getgr_r.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/passwd/getgr_r.c b/src/passwd/getgr_r.c
index 33e35d3a..1dc5f7e0 100644
--- a/src/passwd/getgr_r.c
+++ b/src/passwd/getgr_r.c
@@ -1,4 +1,5 @@
#include "pwf.h"
+#include <pthread.h>
#define FIX(x) (gr->gr_##x = gr->gr_##x-line+buf)
@@ -11,9 +12,15 @@ static int getgr_r(const char *name, gid_t gid, struct group *gr, char *buf, siz
size_t nmem = 0;
int rv = 0;
size_t i;
+ int cs;
+
+ pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
f = fopen("/etc/group", "rb");
- if (!f) return errno;
+ if (!f) {
+ rv = errno;
+ goto done;
+ }
*res = 0;
while (__getgrent_a(f, gr, &line, &len, &mem, &nmem)) {
@@ -39,6 +46,8 @@ static int getgr_r(const char *name, gid_t gid, struct group *gr, char *buf, siz
free(mem);
free(line);
fclose(f);
+done:
+ pthread_setcancelstate(cs, 0);
return rv;
}