From: "Alejandro Colomar (man-pages)" <alx.manpages@gmail.com>
To: наб <nabijaczleweli@nabijaczleweli.xyz>
Cc: linux-man@vger.kernel.org
Subject: Re: [PATCH 3/3] tee.2: always fail after perror(), use for(;;) instead of do{}while(1)
Date: Mon, 3 Jan 2022 17:40:51 +0100 [thread overview]
Message-ID: <c9779348-f3f4-b621-4f09-e6f4c0d2cfc6@gmail.com> (raw)
In-Reply-To: <c68f0d3beba927e3417807201c335d7449fc18b2.1641224016.git.nabijaczleweli@nabijaczleweli.xyz>
Hi наб,
Man pages extensively use exit(EXIT_ERROR) and exit(EXIT_SUCCESS)
instead of return EXIT_ERROR and return EXIT_SUCCESS or even nothing at
the end of main(). I never used that myself, and don't see much
difference between exit(3) and return, but if only for consistency, and
for keeping the status quo in case of doubt, I'll keep using exit(3).
However, I like the change to for(;;). At least a while (1) would be
sane, but do ... while (1) seems a bit weird to me :)
Could you please write a separate patch for that?
Also, please see an inline comment below.
Cheers,
Alex
On 1/3/22 16:34, наб wrote:
> ---
> man2/tee.2 | 11 +++++------
> 1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/man2/tee.2 b/man2/tee.2
> index 17b93882d..4b410ecad 100644
> --- a/man2/tee.2
> +++ b/man2/tee.2
> @@ -171,10 +171,10 @@ main(int argc, char *argv[])
> int fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0644);
> if (fd == \-1) {
> perror("open");
> - exit(EXIT_FAILURE);
> + return EXIT_FAILURE;
> }
>
> - do {
> + for (;;) {
> /*
> * tee stdin to stdout.
> */
> @@ -184,7 +184,7 @@ main(int argc, char *argv[])
> if (errno == EAGAIN)
> continue;
> perror("tee");
> - exit(EXIT_FAILURE);
> + return EXIT_FAILURE;
> } else
> if (len == 0)
> break;
> @@ -197,14 +197,13 @@ main(int argc, char *argv[])
> len, SPLICE_F_MOVE);
> if (slen < 0) {
> perror("splice");
> - break;
> + return EXIT_FAILURE;
This seems like a bug in the example program, so a separate patch for it
would be better.
This makes me think that the loop wasn't originally a do ... while (1)
but something different, and in a rewrite, a few things were forgotten,
maybe.
> }
> len \-= slen;
> }
> - } while (1);
> + }
>
> close(fd);
> - exit(EXIT_SUCCESS);
> }
> .EE
> .SH SEE ALSO
--
Alejandro Colomar
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/
next prev parent reply other threads:[~2022-01-03 16:40 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-03 15:33 [PATCH 1/3] tee.2: ffix наб
2022-01-03 15:34 ` [PATCH 2/3] tee.2: use proper types in example, declare variables at point-of-use наб
2022-01-03 16:25 ` Alejandro Colomar (man-pages)
2022-01-03 15:34 ` [PATCH 3/3] tee.2: always fail after perror(), use for(;;) instead of do{}while(1) наб
2022-01-03 16:40 ` Alejandro Colomar (man-pages) [this message]
2022-01-03 17:03 ` [PATCH v2 2/4] tee.2: use proper types in example наб
2022-01-03 17:27 ` Alejandro Colomar (man-pages)
2022-01-03 17:35 ` наб
2022-01-03 17:51 ` Alejandro Colomar (man-pages)
2022-01-03 17:03 ` [PATCH v2 3/4] tee.2: use for(;;) instead of do{}while(1) наб
2022-01-03 17:03 ` [PATCH v2 4/4] tee.2: always fail after perror() in example наб
2022-01-03 16:49 ` [PATCH 1/3] tee.2: ffix Alejandro Colomar (man-pages)
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=c9779348-f3f4-b621-4f09-e6f4c0d2cfc6@gmail.com \
--to=alx.manpages@gmail.com \
--cc=linux-man@vger.kernel.org \
--cc=nabijaczleweli@nabijaczleweli.xyz \
/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