diff options
author | aalekseyev <aalekseyev@janestreet.com> | 2017-12-15 10:46:39 +0000 |
---|---|---|
committer | Xavier Leroy <xavierleroy@users.noreply.github.com> | 2017-12-15 11:46:39 +0100 |
commit | 5ec02189fdd3c4278534519cd667f46cd08c892c (patch) | |
tree | 59fcfedcd66b2d07721458058c026919bf58306d /otherlibs/unix/getpw.c | |
parent | d8b5449c5012376c398e764874118d7830cbbf3c (diff) | |
download | ocaml-5ec02189fdd3c4278534519cd667f46cd08c892c.tar.gz |
getpw* and getgr* functions raise Unix_error when interrupted (#1451)
Currently getpw* and getgr* functions raise Not_found when there's a Unix error.
This is appropriate behavior for some Unix errors e.g. ENOENT, but other Unix errors
should be reported as a Unix_error exception.
Following discussion in GPR#1451 this commit raises Unix_error on EINTR and keeps
raising Not_found on other errors.
Diffstat (limited to 'otherlibs/unix/getpw.c')
-rw-r--r-- | otherlibs/unix/getpw.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/otherlibs/unix/getpw.c b/otherlibs/unix/getpw.c index b49c23f316..0c0ec80d2d 100644 --- a/otherlibs/unix/getpw.c +++ b/otherlibs/unix/getpw.c @@ -18,6 +18,7 @@ #include <caml/memory.h> #include <caml/fail.h> #include "unixsupport.h" +#include <errno.h> #include <pwd.h> static value alloc_passwd_entry(struct passwd *entry) @@ -52,15 +53,29 @@ CAMLprim value unix_getpwnam(value name) { struct passwd * entry; if (! caml_string_is_c_safe(name)) caml_raise_not_found(); + errno = 0; entry = getpwnam(String_val(name)); - if (entry == (struct passwd *) NULL) caml_raise_not_found(); + if (entry == (struct passwd *) NULL) { + if (errno == EINTR) { + uerror("getpwnam", Nothing); + } else { + caml_raise_not_found(); + } + } return alloc_passwd_entry(entry); } CAMLprim value unix_getpwuid(value uid) { struct passwd * entry; + errno = 0; entry = getpwuid(Int_val(uid)); - if (entry == (struct passwd *) NULL) caml_raise_not_found(); + if (entry == (struct passwd *) NULL) { + if (errno == EINTR) { + uerror("getpwuid", Nothing); + } else { + caml_raise_not_found(); + } + } return alloc_passwd_entry(entry); } |