From: Sergey Bugaev <bugaevc@gmail.com>
To: libc-alpha@sourceware.org, bug-hurd@gnu.org
Cc: Samuel Thibault <samuel.thibault@gnu.org>,
Sergey Bugaev <bugaevc@gmail.com>
Subject: [RFC PATCH 1/5] misc: Convert daemon () to GNU coding style
Date: Tue, 18 Apr 2023 01:58:53 +0300 [thread overview]
Message-ID: <20230417225857.2006561-2-bugaevc@gmail.com> (raw)
In-Reply-To: <20230417225857.2006561-1-bugaevc@gmail.com>
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>
---
misc/daemon.c | 88 ++++++++++++++++++++++++++++-----------------------
1 file changed, 49 insertions(+), 39 deletions(-)
diff --git a/misc/daemon.c b/misc/daemon.c
index 3c73ac2a..61da49b7 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;
}
--
2.39.2
next prev parent reply other threads:[~2023-04-17 22:59 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-17 22:58 [RFC PATCH 0/5] O_IGNORE_CTTY everywhere Sergey Bugaev
2023-04-17 22:58 ` Sergey Bugaev [this message]
2023-04-18 12:02 ` [RFC PATCH 1/5] misc: Convert daemon () to GNU coding style Adhemerval Zanella Netto
2023-04-18 13:48 ` Cristian Rodríguez
2023-04-18 18:49 ` Adhemerval Zanella Netto
2023-04-18 18:59 ` Sergey Bugaev
2023-04-17 22:58 ` [RFC PATCH 2/5] Use O_CLOEXEC in more places Sergey Bugaev
2023-04-18 12:05 ` Adhemerval Zanella Netto
2023-04-17 22:58 ` [RFC PATCH 3/5] hurd: Make dl-sysdep's open () cope with O_IGNORE_CTTY Sergey Bugaev
2023-04-17 22:58 ` [RFC PATCH 4/5] include/fcntl.h: Define O_IGNORE_CTTY Sergey Bugaev
2023-04-17 22:58 ` [RFC PATCH 5/5] 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=20230417225857.2006561-2-bugaevc@gmail.com \
--to=bugaevc@gmail.com \
--cc=bug-hurd@gnu.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).