Re: [PATCH] getgrouplist.3: EXAMPLES: improve error handling for getpwnam(3)
From: Alejandro Colomar <alx@kernel.org>
Date: 2024-03-30 22:55:25
Attachments
- signature.asc [application/pgp-signature] 833 bytes
From: Alejandro Colomar <alx@kernel.org>
Date: 2024-03-30 22:55:25
On Fri, Mar 29, 2024 at 03:21:11AM +0300, Fedor Lapshin wrote:
Signed-off-by: Fedor Lapshin <redacted>
Hi Fedor, Patch applied, with some tweaks. Thanks! Have a lovely night! Alex
--- 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
-- <https://www.alejandro-colomar.es/>