From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x2a.google.com (mail-oa1-x2a.google.com [IPv6:2001:4860:4864:20::2a]) by sourceware.org (Postfix) with ESMTPS id 164E2385770E for ; Fri, 21 Apr 2023 12:18:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 164E2385770E 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-oa1-x2a.google.com with SMTP id 586e51a60fabf-18b1f6caf03so658531fac.2 for ; Fri, 21 Apr 2023 05:18:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1682079503; x=1684671503; 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=+RJneLrm7eLcc4qWUnGUfz1QeB3r3uuSroDBfdMuOsA=; b=de4KS+h3SISWnDLuJTtZsdMnhbHMzuHNSuytxi3DSp5zPscwIoDzE1w8H+HYvGGkUK sVzfFiA/LLf5VMFtJSv083a66b0poqlyn7WZXx3C9DOM4SrQ3njHBD+9vA8cJejkt7pJ SbMecTgsV2VpuL0N7rVz1C152QUK0NYgtDWtmh1VICzXdu1tgLaGZ85M1potFIdqsulR uEowOyZrE0LrkmV//GCL1X8MwGkcOs2Ri578ZI4ihfAWyFEpYj7qAaqnqZZBIrbdaC3c 9KLWyOgGjjr6DWD0oTKhcA+D7dYUcyRdwo6dxlRtQVNgZavujOPZ4MVKF4xxuy3xB/YF NWkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682079503; x=1684671503; 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=+RJneLrm7eLcc4qWUnGUfz1QeB3r3uuSroDBfdMuOsA=; b=ddBFNp7KmQX9rRK9nzL3YD57WkCOrX7nURiJRx9ZfQCJsfKzxNwev7KcUzo1ROA++l 9b9LD+TkNJEBM1JCmab7VrFSUEhdK/AukWClJKHxBjiWYG2VfjsndsEybd+nYoMqk173 6iaGvIK61bwQRn3ICbS3BkUrXbq1XoLtGEtCy06w9XyERMqxJVTlwFTr8pVy4Z8/3bo6 jkxb5i3QnHsmLDA2FI25LP4ibonCBmHHaIEJNdwmUOfo1g15T3SKwN4L7y9woZ2yaxMo IkslYrYfwMyMutgVT+KHzz8tTxDvXWNPI5RUUPPfYhkS4FVd0+t8VD3sR6GG8w3gwMux FcrQ== X-Gm-Message-State: AAQBX9dezHZjYTN7mCkssLqA/o/K88sdLI2wiow+JfWbtzmcozaLd8+r l4jzRptcDjJ/z8de+oi9IAPnQVEM0Bpv6Anq2o9h9Q== X-Google-Smtp-Source: AKy350bO1/4kKt3qDq/mJ/+HL0ntcWoGtS6F1cDSf/yG64mU/oIws1KoJOVKrchYj8gAXgBic4YmtA== X-Received: by 2002:a05:6870:f2a1:b0:188:c9a:f167 with SMTP id u33-20020a056870f2a100b001880c9af167mr3198536oap.46.1682079503410; Fri, 21 Apr 2023 05:18:23 -0700 (PDT) Received: from ?IPV6:2804:1b3:a7c3:333:20b7:b016:1b7f:fd25? ([2804:1b3:a7c3:333:20b7:b016:1b7f:fd25]) by smtp.gmail.com with ESMTPSA id ed16-20020a056870b79000b0018b07710d58sm1704570oab.31.2023.04.21.05.18.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 21 Apr 2023 05:18:22 -0700 (PDT) Message-ID: <1d9ec490-65e2-0756-790f-78e4e6df75d9@linaro.org> Date: Fri, 21 Apr 2023 09:18:19 -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 v2 1/7] misc: Convert daemon () to GNU coding style Content-Language: en-US To: Sergey Bugaev , libc-alpha@sourceware.org Cc: bug-hurd@gnu.org, Samuel Thibault , =?UTF-8?Q?Cristian_Rodr=c3=adguez?= References: <20230419160207.65988-1-bugaevc@gmail.com> <20230419160207.65988-2-bugaevc@gmail.com> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <20230419160207.65988-2-bugaevc@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-14.1 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 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 LGTM, thanks. I can be installed independently. Reviewed-by: Adhemerval Zanella > --- > 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; > }