1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-07 06:43:00 +03:00

misc: Convert daemon () to GNU coding style

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>
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
Message-Id: <20230419160207.65988-2-bugaevc@gmail.com>
This commit is contained in:
Sergey Bugaev
2023-04-19 19:02:01 +03:00
committed by Samuel Thibault
parent 0aa5b28a50
commit 28a441cc57

View File

@@ -45,48 +45,58 @@ daemon (int nochdir, int noclose)
{
int fd;
switch (__fork()) {
switch (__fork ())
{
case -1:
return (-1);
return -1;
case 0:
break;
default:
_exit (0);
}
if (__setsid () == -1)
return (-1);
return -1;
if (!nochdir)
(void) __chdir ("/");
if (!noclose) {
if (!noclose)
{
struct __stat64_t64 st;
if ((fd = __open_nocancel(_PATH_DEVNULL, O_RDWR, 0)) != -1
&& __glibc_likely (__fstat64_time64 (fd, &st) == 0)) {
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. */
}
else
{
/* We must set an errno value since no function call
actually failed. */
__close_nocancel_nostatus (fd);
__set_errno (ENODEV);
return -1;
}
} else {
}
else
{
__close_nocancel_nostatus (fd);
return -1;
}
}
return (0);
return 0;
}