summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passwd/getgr_r.c11
-rw-r--r--src/passwd/getgrent_a.c9
-rw-r--r--src/passwd/getpw_r.c11
-rw-r--r--src/passwd/getpwent_a.c10
4 files changed, 35 insertions, 6 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;
}
diff --git a/src/passwd/getgrent_a.c b/src/passwd/getgrent_a.c
index 7c63c57b..780560dd 100644
--- a/src/passwd/getgrent_a.c
+++ b/src/passwd/getgrent_a.c
@@ -1,16 +1,19 @@
#include "pwf.h"
+#include <pthread.h>
struct group *__getgrent_a(FILE *f, struct group *gr, char **line, size_t *size, char ***mem, size_t *nmem)
{
ssize_t l;
char *s, *mems;
size_t i;
-
+ int cs;
+ pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
for (;;) {
if ((l=getline(line, size, f)) < 0) {
free(*line);
*line = 0;
- return 0;
+ gr = 0;
+ goto end;
}
line[0][l-1] = 0;
@@ -46,5 +49,7 @@ struct group *__getgrent_a(FILE *f, struct group *gr, char **line, size_t *size,
mem[0][0] = 0;
}
gr->gr_mem = *mem;
+end:
+ pthread_setcancelstate(cs, 0);
return gr;
}
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;
}
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;
}