Linux-man Archive mirror
 help / color / mirror / Atom feed
From: Fedor Lapshin <fe.lap.prog@gmail.com>
To: Alejandro Colomar <alx@kernel.org>
Cc: linux-man@vger.kernel.org
Subject: [PATCH] getgrouplist.3: EXAMPLES: improve error handling for getpwnam(3)
Date: Fri, 29 Mar 2024 03:21:11 +0300	[thread overview]
Message-ID: <CAJ_gjBoqD2mWoJF0QH7YB=Z0Wy00XFO2yRJ0VQDxPmp3niisYg@mail.gmail.com> (raw)

Signed-off-by: Fedor Lapshin <fe.lap.prog@gmail.com>
---
 man3/getgrouplist.3 | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/man3/getgrouplist.3 b/man3/getgrouplist.3
index 41389b6c3..e2e640d56 100644
--- a/man3/getgrouplist.3
+++ b/man3/getgrouplist.3
@@ -162,10 +162,12 @@ 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);
+        if (errno) perror("getpwnam");
+        else fprintf(stderr, "no such user\en");
+        exit(EXIT_FAILURE);
     }
 \&
     /* Retrieve group list. */
--
2.34.1

             reply	other threads:[~2024-03-29  0:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-29  0:21 Fedor Lapshin [this message]
2024-03-29  0:24 ` [PATCH] getgrouplist.3: EXAMPLES: improve error handling for getpwnam(3) Fedor Lapshin
2024-03-30 22:55 ` Alejandro Colomar

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='CAJ_gjBoqD2mWoJF0QH7YB=Z0Wy00XFO2yRJ0VQDxPmp3niisYg@mail.gmail.com' \
    --to=fe.lap.prog@gmail.com \
    --cc=alx@kernel.org \
    --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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).