about summary refs log tree commit diff
path: root/src/passwd/getpw_r.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/passwd/getpw_r.c')
-rw-r--r--src/passwd/getpw_r.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/passwd/getpw_r.c b/src/passwd/getpw_r.c
index 7b331e8a..39744959 100644
--- a/src/passwd/getpw_r.c
+++ b/src/passwd/getpw_r.c
@@ -1,4 +1,5 @@
 #include "pwf.h"
+#include <pthread.h>
 
 #define FIX(x) (pw->pw_##x = pw->pw_##x-line+buf)
 
@@ -8,9 +9,15 @@ static int getpw_r(const char *name, uid_t uid, struct passwd *pw, char *buf, si
 	char *line = 0;
 	size_t len = 0;
 	int rv = 0;
+	int cs;
+
+	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
 
 	f = fopen("/etc/passwd", "rb");
-	if (!f) return errno;
+	if (!f) {
+		rv = errno;
+		goto done;
+	}
 
 	*res = 0;
 	while (__getpwent_a(f, pw, &line, &len)) {
@@ -32,6 +39,8 @@ static int getpw_r(const char *name, uid_t uid, struct passwd *pw, char *buf, si
 	}
  	free(line);
 	fclose(f);
+done:
+	pthread_setcancelstate(cs, 0);
 	return rv;
 }