* getgrgid and errno
@ 2015-06-09 12:59 Julien Ramseier
2015-06-09 19:17 ` Alex
0 siblings, 1 reply; 5+ messages in thread
From: Julien Ramseier @ 2015-06-09 12:59 UTC (permalink / raw)
To: musl
[-- Attachment #1: Type: text/plain, Size: 650 bytes --]
Hello,
I’m encountering a strange problem with getgrgid.
Calling this function with a non-existent group sets errno to ENOENT instead of 0.
This small test program below prints getgrgid: No such file or directory.
#include <sys/types.h>
#include <grp.h>
#include <stddef.h>
#include <errno.h>
int main(void) {
errno = 0;
struct group *g = getgrgid(1234);
perror("getgrgid");
}
However, when stepping through __getgr_a with gdb, errno seems to be correctly set to 0:
167 if (rv) errno = rv;
(gdb)
168 return rv;
(gdb) p rv
$6 = 0
So I really don’t know what’s going on…Am I missing something?
-
Julien
[-- Attachment #2: Type: text/html, Size: 2514 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: getgrgid and errno
2015-06-09 12:59 getgrgid and errno Julien Ramseier
@ 2015-06-09 19:17 ` Alex
2015-06-09 19:46 ` Julien Ramseier
0 siblings, 1 reply; 5+ messages in thread
From: Alex @ 2015-06-09 19:17 UTC (permalink / raw)
To: musl
[-- Attachment #1: Type: text/plain, Size: 1075 bytes --]
The code which you show says "if (rv) errno = rv". The debugger shows that
rv is 0. So the condition is false and errno is not set.
It must have been set to ENOENT somewhere above that -- as you single-step
through the code, keep printing errno on each line to find out where.
On Tue, Jun 9, 2015 at 2:59 PM, Julien Ramseier <j.ramseier@gmail.com>
wrote:
> Hello,
>
> I’m encountering a strange problem with getgrgid.
>
> Calling this function with a non-existent group sets errno to ENOENT
> instead of 0.
> This small test program below prints getgrgid: No such file or directory.
>
> #include <sys/types.h>
> #include <grp.h>
> #include <stddef.h>
> #include <errno.h>
>
> int main(void) {
> errno = 0;
> struct group *g = getgrgid(1234);
> perror("getgrgid");
> }
>
> However, when stepping through __getgr_a with gdb, errno seems to be
> correctly set to 0:
>
> 167 if (rv) errno = rv;
> (gdb)
> 168 return rv;
> (gdb) p rv
> $6 = 0
>
> So I really don’t know what’s going on…Am I missing something?
>
> -
> Julien
>
[-- Attachment #2: Type: text/html, Size: 2439 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: getgrgid and errno
2015-06-09 19:17 ` Alex
@ 2015-06-09 19:46 ` Julien Ramseier
2015-06-09 19:52 ` Rich Felker
0 siblings, 1 reply; 5+ messages in thread
From: Julien Ramseier @ 2015-06-09 19:46 UTC (permalink / raw)
To: musl
> Le 9 juin 2015 à 21:17, Alex <alexinbeijing@gmail.com> a écrit :
>
> The code which you show says "if (rv) errno = rv". The debugger shows that rv is 0. So the condition is false and errno is not set.
>
> It must have been set to ENOENT somewhere above that -- as you single-step through the code, keep printing errno on each line to find out where.
Thanks. I don’t know how I missed that.
errno is set to ENOENT by __nscd_query, since no nscd daemon is running and /var/run/nscd/socket does not exist.
So getgrgid always sets errno when the group doesn’t exist and no nscd daemon is available.
Is that expected?
Julien
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: getgrgid and errno
2015-06-09 19:46 ` Julien Ramseier
@ 2015-06-09 19:52 ` Rich Felker
2015-06-09 21:38 ` Rich Felker
0 siblings, 1 reply; 5+ messages in thread
From: Rich Felker @ 2015-06-09 19:52 UTC (permalink / raw)
To: musl
On Tue, Jun 09, 2015 at 09:46:50PM +0200, Julien Ramseier wrote:
>
> > Le 9 juin 2015 à 21:17, Alex <alexinbeijing@gmail.com> a écrit :
> >
> > The code which you show says "if (rv) errno = rv". The debugger shows that rv is 0. So the condition is false and errno is not set.
> >
> > It must have been set to ENOENT somewhere above that -- as you single-step through the code, keep printing errno on each line to find out where.
>
> Thanks. I don’t know how I missed that.
>
> errno is set to ENOENT by __nscd_query, since no nscd daemon is running and /var/run/nscd/socket does not exist.
> So getgrgid always sets errno when the group doesn’t exist and no nscd daemon is available.
> Is that expected?
No, it's a bug/oversight. There should be a fix in git master soon
(and it should safely apply to recent releases if you prefer).
Rich
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: getgrgid and errno
2015-06-09 19:52 ` Rich Felker
@ 2015-06-09 21:38 ` Rich Felker
0 siblings, 0 replies; 5+ messages in thread
From: Rich Felker @ 2015-06-09 21:38 UTC (permalink / raw)
To: musl
On Tue, Jun 09, 2015 at 03:52:52PM -0400, Rich Felker wrote:
> On Tue, Jun 09, 2015 at 09:46:50PM +0200, Julien Ramseier wrote:
> >
> > > Le 9 juin 2015 à 21:17, Alex <alexinbeijing@gmail.com> a écrit :
> > >
> > > The code which you show says "if (rv) errno = rv". The debugger shows that rv is 0. So the condition is false and errno is not set.
> > >
> > > It must have been set to ENOENT somewhere above that -- as you single-step through the code, keep printing errno on each line to find out where.
> >
> > Thanks. I don’t know how I missed that.
> >
> > errno is set to ENOENT by __nscd_query, since no nscd daemon is running and /var/run/nscd/socket does not exist.
> > So getgrgid always sets errno when the group doesn’t exist and no nscd daemon is available.
> > Is that expected?
>
> No, it's a bug/oversight. There should be a fix in git master soon
> (and it should safely apply to recent releases if you prefer).
Fixed in commit bd1eaceaa3975bd2a2a34e211cff896affaecadf.
Rich
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-06-09 21:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-09 12:59 getgrgid and errno Julien Ramseier
2015-06-09 19:17 ` Alex
2015-06-09 19:46 ` Julien Ramseier
2015-06-09 19:52 ` Rich Felker
2015-06-09 21:38 ` Rich Felker
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).