Re: [PATCH] getgrouplist.3: EXAMPLES: fix error handling for getpwnam(3)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Fedor,

On Wed, Mar 27, 2024 at 10:23:21PM +0300, Fedor Lapshin wrote:
> So sorry for the email to your personal email without the cc!

No problem!  We humans make mistakes some times (and AIs make them all
the time).  ;)

You can configure git to always send to me and the list for this
repository.  I have this in the man-pages <.git/config>, which might be
useful to you:

[sendemail]
	to = linux-man@xxxxxxxxxxxxxxx

> ср, 27 мар. 2024 г. в 22:20, Fedor Lapshin <fe.lap.prog@xxxxxxxxx>:
> >
> > Signed-off-by: Fedor Lapshin <fe.lap.prog@xxxxxxxxx>
> > ---
> >  man3/getgrouplist.3 | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/man3/getgrouplist.3 b/man3/getgrouplist.3
> > index 41389b6c3..cf23dfa78 100644
> > --- a/man3/getgrouplist.3
> > +++ b/man3/getgrouplist.3
> > @@ -162,10 +162,11 @@ main(int argc, char *argv[])
> >  \&
> >      /* Fetch passwd structure (contains first group ID for user). */
> >  \&
> > +    errno = 0;
> >      pw = getpwnam(argv[1]);
> >      if (pw == NULL) {

> >          perror("getpwnam");
> > -        exit(EXIT_SUCCESS);
> > +        exit(EXIT_FAILURE);

In case errno == NULL, there's no such user, but the call succeeded.
Calling perror(3) in that case will be weird.  I suggest:

	errno = 0;
	pw = getpwnam(argv[1]);
	if (pw == NULL) {
		if (errno == 0)
			fprintf(stderr, "'%s': No such user", argv[1]);
		else
			perror("getpwnam");

		exit(EXIT_FAILURE);
	}

Have a lovely night!
Alex

> >      }
> >  \&
> >      /* Retrieve group list. */
> > --
> > 2.34.1
> 

-- 
<https://www.alejandro-colomar.es/>
Looking for a remote C programming job at the moment.

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux