public inbox for linux-man@vger.kernel.org
 help / color / mirror / Atom feed
From: Alejandro Colomar <alx@kernel.org>
To: Fedor Lapshin <fe.lap.prog@gmail.com>
Cc: linux-man@vger.kernel.org
Subject: Re: [PATCH] getgrouplist.3: EXAMPLES: fix error handling for getpwnam(3)
Date: Wed, 27 Mar 2024 21:14:26 +0100	[thread overview]
Message-ID: <ZgR-KSd7GnuegUNf@debian> (raw)
In-Reply-To: <CAJ_gjBon2AS+j830RBe_FmvBtYqkiR8eQeLAz_+VfcmoPZh-2A@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1717 bytes --]

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@vger.kernel.org

> ср, 27 мар. 2024 г. в 22:20, Fedor Lapshin <fe.lap.prog@gmail.com>:
> >
> > Signed-off-by: Fedor Lapshin <fe.lap.prog@gmail.com>
> > ---
> >  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 #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      reply	other threads:[~2024-03-27 20:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-06 16:13 [patch] getgrouplist.3: tfix in example Fedor Lapshin
2024-03-16  0:27 ` Alejandro Colomar
2024-03-27 19:20   ` [PATCH] getgrouplist.3: EXAMPLES: fix error handling for getpwnam(3) Fedor Lapshin
2024-03-27 19:23     ` Fedor Lapshin
2024-03-27 20:14       ` Alejandro Colomar [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZgR-KSd7GnuegUNf@debian \
    --to=alx@kernel.org \
    --cc=fe.lap.prog@gmail.com \
    --cc=linux-man@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox