From: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
To: Sergey Bugaev <bugaevc@gmail.com>, libc-alpha@sourceware.org
Cc: bug-hurd@gnu.org, "Samuel Thibault" <samuel.thibault@gnu.org>,
"Cristian Rodríguez" <crrodriguez@opensuse.org>
Subject: Re: [RFC PATCH v2 1/7] misc: Convert daemon () to GNU coding style
Date: Fri, 21 Apr 2023 09:18:19 -0300 [thread overview]
Message-ID: <1d9ec490-65e2-0756-790f-78e4e6df75d9@linaro.org> (raw)
In-Reply-To: <20230419160207.65988-2-bugaevc@gmail.com>
On 19/04/23 13:02, Sergey Bugaev wrote:
> This is nicer, and is going to be required for the following changes
> to reasonably stay within the 79 column limit.
>
> No functional change.
>
> Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
LGTM, thanks. I can be installed independently.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> ---
> misc/daemon.c | 88 ++++++++++++++++++++++++++++-----------------------
> 1 file changed, 49 insertions(+), 39 deletions(-)
>
> diff --git a/misc/daemon.c b/misc/daemon.c
> index 3c73ac2a..14577e40 100644
> --- a/misc/daemon.c
> +++ b/misc/daemon.c
> @@ -43,50 +43,60 @@ static char sccsid[] = "@(#)daemon.c 8.1 (Berkeley) 6/4/93";
> int
> daemon (int nochdir, int noclose)
> {
> - int fd;
> + int fd;
>
> - switch (__fork()) {
> - case -1:
> - return (-1);
> - case 0:
> - break;
> - default:
> - _exit(0);
> - }
> + switch (__fork ())
> + {
> + case -1:
> + return -1;
>
> - if (__setsid() == -1)
> - return (-1);
> + case 0:
> + break;
>
> - if (!nochdir)
> - (void)__chdir("/");
> + default:
> + _exit (0);
> + }
>
> - if (!noclose) {
> - struct __stat64_t64 st;
> + if (__setsid () == -1)
> + return -1;
>
> - if ((fd = __open_nocancel(_PATH_DEVNULL, O_RDWR, 0)) != -1
> - && __glibc_likely (__fstat64_time64 (fd, &st) == 0)) {
> - if (__builtin_expect (S_ISCHR (st.st_mode), 1) != 0
> + if (!nochdir)
> + (void) __chdir ("/");
> +
> + if (!noclose)
> + {
> + struct __stat64_t64 st;
> +
> + fd = __open_nocancel (_PATH_DEVNULL, O_RDWR, 0);
> + if (fd != -1 && __glibc_likely (__fstat64_time64 (fd, &st) == 0))
> + {
> + if (__builtin_expect (S_ISCHR (st.st_mode), 1) != 0
> #if defined DEV_NULL_MAJOR && defined DEV_NULL_MINOR
> - && (st.st_rdev
> - == makedev (DEV_NULL_MAJOR, DEV_NULL_MINOR))
> + && (st.st_rdev == makedev (DEV_NULL_MAJOR, DEV_NULL_MINOR))
> #endif
> - ) {
> - (void)__dup2(fd, STDIN_FILENO);
> - (void)__dup2(fd, STDOUT_FILENO);
> - (void)__dup2(fd, STDERR_FILENO);
> - if (fd > 2)
> - (void)__close (fd);
> - } else {
> - /* We must set an errno value since no
> - function call actually failed. */
> - __close_nocancel_nostatus (fd);
> - __set_errno (ENODEV);
> - return -1;
> - }
> - } else {
> - __close_nocancel_nostatus (fd);
> - return -1;
> - }
> - }
> - return (0);
> + )
> + {
> + (void) __dup2 (fd, STDIN_FILENO);
> + (void) __dup2 (fd, STDOUT_FILENO);
> + (void) __dup2 (fd, STDERR_FILENO);
> + if (fd > 2)
> + (void) __close (fd);
> + }
> + else
> + {
> + /* We must set an errno value since no function call
> + actually failed. */
> + __close_nocancel_nostatus (fd);
> + __set_errno (ENODEV);
> + return -1;
> + }
> + }
> + else
> + {
> + __close_nocancel_nostatus (fd);
> + return -1;
> + }
> + }
> +
> + return 0;
> }
next prev parent reply other threads:[~2023-04-21 12:18 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-19 16:02 [RFC PATCH v2 0/7] O_IGNORE_CTTY everywhere & misc fixes Sergey Bugaev
2023-04-19 16:02 ` [RFC PATCH v2 1/7] misc: Convert daemon () to GNU coding style Sergey Bugaev
2023-04-21 12:18 ` Adhemerval Zanella Netto [this message]
2023-04-22 11:47 ` Samuel Thibault
2023-04-19 16:02 ` [RFC PATCH v2 2/7] misc: Ignore SIGHUP in daemon () while forking Sergey Bugaev
2023-04-21 12:55 ` Adhemerval Zanella Netto
2023-04-19 16:02 ` [RFC PATCH v2 3/7] Use O_CLOEXEC in more places (BZ #15722) Sergey Bugaev
2023-04-21 12:55 ` Adhemerval Zanella Netto
2023-04-22 11:50 ` Samuel Thibault
2023-04-19 16:02 ` [RFC PATCH v2 4/7] csu: Fix standard fds' mode Sergey Bugaev
2023-04-19 19:13 ` Cristian Rodríguez
2023-04-19 19:40 ` Sergey Bugaev
2023-04-19 20:45 ` Adhemerval Zanella Netto
2023-04-19 21:16 ` Sergey Bugaev
2023-04-20 11:47 ` Adhemerval Zanella Netto
2023-04-20 12:06 ` Cristian Rodríguez
2023-04-20 15:13 ` Adhemerval Zanella Netto
2023-04-21 17:16 ` Paul Eggert
2023-04-19 16:02 ` [RFC PATCH v2 5/7] hurd: Make dl-sysdep's open () cope with O_IGNORE_CTTY Sergey Bugaev
2023-04-20 21:06 ` Samuel Thibault
2023-04-19 16:02 ` [RFC PATCH v2 6/7] include/fcntl.h: Define O_IGNORE_CTTY Sergey Bugaev
2023-04-19 16:02 ` [RFC PATCH v2 7/7] Use O_IGNORE_CTTY where appropriate Sergey Bugaev
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=1d9ec490-65e2-0756-790f-78e4e6df75d9@linaro.org \
--to=adhemerval.zanella@linaro.org \
--cc=bug-hurd@gnu.org \
--cc=bugaevc@gmail.com \
--cc=crrodriguez@opensuse.org \
--cc=libc-alpha@sourceware.org \
--cc=samuel.thibault@gnu.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).