From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 4937 invoked from network); 4 Aug 2020 18:41:34 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 4 Aug 2020 18:41:34 -0000 Received: (qmail 3550 invoked by uid 550); 4 Aug 2020 18:41:32 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 3532 invoked from network); 4 Aug 2020 18:41:32 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=F11WIfgxfXF3geewVUVjWjjEuEUdqJcKQrJnCfqQ6gE=; b=TgYLT4O/i2JE51NwyS1WoXDNONJM7MlWDtUyUJqCkFKPG80KZ+IXGO3xLyyQKh7rzF gqpUidRvuoxDf+eLgngT6kXxUWlFZs/k1HEfE956PCOxn3hcaZKQWkRQSt2cnbpJi5ZA eZ4HhlHLLMHdpgxyIn/n05d7w6bhdWmba8xhhYdUCqGBgCkaBOwptIAAYDCNMGvFy+It GDE3qChVywiW7DRRy+5E6fbSwbg0Ea2CdmaIE3GNsyG2KyLQkRA57b12qrHn10N/zYes Iy3Y62OwRjqw769oZlKEqaZk/wn0SxVYBJctwmkmthMX4AlmdABFUtPqV6HCw6+Pz40R 1G4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=F11WIfgxfXF3geewVUVjWjjEuEUdqJcKQrJnCfqQ6gE=; b=BURGjEe4/OMytwwrC1Ws6lgQ3ovhCZd/Gq0YpL57gs8F+8yFqq57VE6Vd0BromKJri ybEKRLup7JhT1U96Xxgb28fxmlLGGgFin1i3krEv332ywNat/ekgYhHYUGBECiqTVy13 1nYytVtKSu8lTiGK36DsYKyaA8iz4yWz/gXZAphE50cYlI/C/KIulre5pyzzZ/OWlfXn AIDkPhMTWCa7MxOjUtVfUr4AcoRGVTzn4xuQ2We8oHIE+ir0Gac0K/GkCBYL0qHOHhv1 QBSZoEs0Bm37UgFFPdd3w2YU3Sx2f2KdYic26yW7YirYqTqMuPiSdhJ6HLbNjaQgN4xc IaIw== X-Gm-Message-State: AOAM532MuEFzTkkkTHlhTyMwozpvWBG9asieIXrCgDbowU8zBHbFGMm6 j+0Z/qyzai0TJ2adBswsANBr4dkR+GzkKfilf14g1DPP X-Google-Smtp-Source: ABdhPJyfKuE2/KudgtMS1Q6mpULjDz31bD7HYKOKmvpzAgof53+BJx0Uh7mzNegmgguug+xE/fuPzvKzYFD1XmhlM0c= X-Received: by 2002:a67:33d3:: with SMTP id z202mr16989255vsz.130.1596566479636; Tue, 04 Aug 2020 11:41:19 -0700 (PDT) MIME-Version: 1.0 References: <20200804133256.13494-1-ericonr@disroot.org> In-Reply-To: <20200804133256.13494-1-ericonr@disroot.org> From: Andre McCurdy Date: Tue, 4 Aug 2020 11:41:09 -0700 Message-ID: To: musl@lists.openwall.com Cc: =?UTF-8?B?w4lyaWNvIFJvbGlt?= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [musl] [PATCH v2] extend gethostid beyond a stub On Tue, Aug 4, 2020 at 6:33 AM =C3=89rico Rolim wrote= : > > From: =C3=89rico Rolim > > Implement part of the glibc behavior, where the 32-bit identifier stored > in /etc/hostid, if the file exists, is returned. If this file doesn't > contain at least 32 bits or can't be opened for some reason, return 0. > --- > > > The glibc implementation appears to read and write directly into an > > int32_t variable, without any endianness conversion. To be > > interoperable with /etc/hostid files created by glibc shouldn't musl > > skip the ntohl() and just return x ? > > I have changed it to directly read the file into a variable. Given that > the return type is long, should I still use int32_t inside the function? Yes. Consider what happens on a big-endian 64bit system. For reference, the glibc code is basically: long int gethostid (void) { int32_t id; int fd; /* First try to get the ID from a former invocation of sethostid. */ fd =3D __open_nocancel (HOSTIDFILE, O_RDONLY|O_LARGEFILE, 0); if (fd >=3D 0) { ssize_t n =3D __read_nocancel (fd, &id, sizeof (id)); __close_nocancel_nostatus (fd); if (n =3D=3D sizeof (id)) return id; } ... } > src/misc/gethostid.c | 14 +++++++++++++- > 1 file changed, 13 insertions(+), 1 deletion(-) > > diff --git a/src/misc/gethostid.c b/src/misc/gethostid.c > index 25bb35db..2877842f 100644 > --- a/src/misc/gethostid.c > +++ b/src/misc/gethostid.c > @@ -1,6 +1,18 @@ > #include > +#include > > long gethostid() > { > - return 0; > + FILE *f; > + long rv =3D 0; > + > + f =3D fopen("/etc/hostid", "reb"); > + if (f) { > + if (fread(&rv, 4, 1, f) =3D=3D 0) { > + rv =3D 0; > + } > + fclose(f); > + } > + > + return rv; > } > -- > 2.28.0 >