Re: [patch] getgrouplist.3: tfix in example

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

 



Hi Fedor,

On Wed, Mar 06, 2024 at 07:13:31PM +0300, Fedor Lapshin wrote:
> In example of getgrouplist, if getpwnam returns NULL, the program
> exits. The exit code EXIT_SUCCESS looks like a mistake, since the
> program also calls perror right before.
> 
> This patch changes the exit code to EXIT_FAILURE.

While your patch seems correct, it's not the only problem I see with
this call to getpwnam(3): it should clear errno before the call, since
a return of NULL doesn't necessarily mean an error.  See getpwnam(3):

$ MANWIDTH=72 man getpwnam | sed -n '/^RETURN/,/^$/p'
RETURN VALUE
     The getpwnam() and getpwuid() functions return  a  pointer  to  a
     passwd  structure,  or NULL if the matching entry is not found or
     an error occurs.  If an error occurs, errno is  set  to  indicate
     the error.  If one wants to check errno after the call, it should
     be set to zero before the call.

So I would also add 'errno = 0;' before the call, and then name the
commit something like

	getgrouplist.3: EXAMPLES: Fix error handling after getpwnam(3)

> 
> Best regards, Fedor.

Would you mind signing the patch?  See <./CONTRIBUTING.d/patches>:

       -  Sign your patch with "Signed-off-by:".  Read about the
          "Developer's Certificate of Origin" at
          <https://www.kernel.org/doc/Documentation/process/submitting-patches.rst>.
          When appropriate, other tags documented in that file, such as
          "Reported-by:", "Reviewed-by:", "Acked-by:", and
          "Suggested-by:" can be added to the patch.  The man-pages
          project also uses a "Cowritten-by:" tag with the obvious
          meaning.  Example:

              Signed-off-by: Alejandro Colomar <alx@xxxxxxxxxx>


Have a lovely night!
Alex

> ---
>  man3/getgrouplist.3 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/man3/getgrouplist.3 b/man3/getgrouplist.3
> index 41389b6c3..239913ce6 100644
> --- a/man3/getgrouplist.3
> +++ b/man3/getgrouplist.3
> @@ -165,7 +165,7 @@ main(int argc, char *argv[])
>      pw = getpwnam(argv[1]);
>      if (pw == NULL) {
>          perror("getpwnam");
> -        exit(EXIT_SUCCESS);
> +        exit(EXIT_FAILURE);
>      }
>  \&
>      /* Retrieve group list. */
> -- 
> 2.34.1

-- 
<https://www.alejandro-colomar.es/>

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