From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oo1-xc36.google.com (mail-oo1-xc36.google.com [IPv6:2607:f8b0:4864:20::c36]) by sourceware.org (Postfix) with ESMTPS id 89A043858D28 for ; Tue, 18 Apr 2023 12:02:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 89A043858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oo1-xc36.google.com with SMTP id 006d021491bc7-541b5ee8a8cso181256eaf.0 for ; Tue, 18 Apr 2023 05:02:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681819326; x=1684411326; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=UvKZkpxFY3LTo9NVuEtSG2lKQ7voQV/5VOmHUeZlGFk=; b=keT5zYqnLM+nI/0RqwK/BlceryZAAbOpyHtGd0QWnZF9B1Xlvzs7KhCYaodVPVzm+F VtIOne7iTYiSl/bf+gFADLq0ppFXwExFuQZOyFqL34DP0Qt3rGLd7IVQA5lEA4lm3/+g B/dcWOLJbpqCd4JjdRDWLwWzSPyrPK1mmiMYnstu/jQU/A5mR1JBel4gaJZCnLy111bs x7sZOndNXpfjVDAE9vkyhINF0n7Vvb+qePTqOvgbSR1SvTqIqF4qE0uuu2u+rNpnwT9m 53bA2j/7FOrvGn88yPw9hp2g1DVCQpUqMWjS4UGhJaKdPSD/YVG+odmBamhYkO2Lspmy Bbcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681819326; x=1684411326; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=UvKZkpxFY3LTo9NVuEtSG2lKQ7voQV/5VOmHUeZlGFk=; b=hQ7tw79VLa6YfcHbnMuTFMm9EIn6GcNIpDVSlIU4UKOnSsS2Ij6UbLRKFnYXs4JoUw 94k8eBhA8HhaE6TdQ9vu4NawaF3hf9K3UkFPMoeFku83fZVT0aPVUXQOZLe7U+mFJlwj cjjfaVDJiI1zgNJ/0UYISnAGJD044775xMhu4NRj/pKSf4UEM0P2wihNj/Fl7CpRq7oB 5+4cYiOEgwuxr8IMZdZxJMAuBjzkODVwmLpgpQMJR7wo2VCJZ6QpuzNYBsxJUzxjgNzG RQ8V5ty01Bn3vtpwZCqe5lscyQ0VExIa3Lvk4PSkX/5pAzRq1I0n3mu8gl+fBuq1BZHR ZTFQ== X-Gm-Message-State: AAQBX9fZsKRVsU3pmv8ZAoNnmK+u4m/afTozbGGJPOlowuNDXmQuP1iO CI5wTGXl5mnuL2Nz0auxkneLDw== X-Google-Smtp-Source: AKy350aFKS+F9YslRK6S9BtnTyBXtfEDedDFVGh87puO1A8de/A2e0zbjrcvgqSu2QsMkh1ABMqpwQ== X-Received: by 2002:a05:6808:ec9:b0:38d:fa2c:b9ea with SMTP id q9-20020a0568080ec900b0038dfa2cb9eamr724646oiv.47.1681819325708; Tue, 18 Apr 2023 05:02:05 -0700 (PDT) Received: from ?IPV6:2804:1b3:a7c3:333:6c1b:2ac3:fde1:4edf? ([2804:1b3:a7c3:333:6c1b:2ac3:fde1:4edf]) by smtp.gmail.com with ESMTPSA id z12-20020a056808064c00b0038cabdbe3a7sm3336944oih.3.2023.04.18.05.02.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 18 Apr 2023 05:02:04 -0700 (PDT) Message-ID: <19b6b831-49c5-4db4-292c-349d36bb16ce@linaro.org> Date: Tue, 18 Apr 2023 09:02:02 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [RFC PATCH 1/5] misc: Convert daemon () to GNU coding style Content-Language: en-US To: Sergey Bugaev , libc-alpha@sourceware.org, bug-hurd@gnu.org Cc: Samuel Thibault References: <20230417225857.2006561-1-bugaevc@gmail.com> <20230417225857.2006561-2-bugaevc@gmail.com> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <20230417225857.2006561-2-bugaevc@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-14.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 17/04/23 19:58, Sergey Bugaev via Libc-alpha 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 LGTM, some minor nits below. > --- > 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 ("/"); I think there is no need to ignore return code. > + > + if (!noclose) > + { > + struct __stat64_t64 st; > + > + fd = __open_nocancel(_PATH_DEVNULL, O_RDWR, 0); Missing space before '('. > + 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; > }