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.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, 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 29565 invoked from network); 4 Aug 2020 22:43:18 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 4 Aug 2020 22:43:18 -0000 Received: (qmail 30431 invoked by uid 550); 4 Aug 2020 22:43:16 -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 30401 invoked from network); 4 Aug 2020 22:43:15 -0000 X-Virus-Scanned: Debian amavisd-new at disroot.org From: =?UTF-8?q?=C3=89rico=20Rolim?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1596580983; bh=oQXtsqP9Hb5U0ijGiGOT8+CcUPtEqYTp34gpEAhsVCo=; h=From:To:Cc:Subject:Date; b=LyuEJL/+kl/f/nM6REGTmTrI1yzuMw7pe/by+Xwcm/ZUKXGf9zfg0BCAO7ru+Xt/X R3Kfppbi4W7bhMhio6jN38KKFSGG4Xd4e5pVESSjENmJtjHIozEVLmPQUmbXkfMwoM g2IIDb1blp+ErwkJ4hDfbftM7y0BeuFcJgfmGXeN97c2Vu+VZYR3BfCWNZxIJ5PTyh o248ln8GWrpUKJjnlR+769XzvKg819llr5MbeILAlQeyMNU1l7ssATqH7XKlKh3/hq FuaayH03L7xYfpptWEkAYbdWj4JgvscEa3003ikzVBjPS227H1lgtexQ2ni5XK4x/a GN2I7rTrY+Ebw== To: musl@lists.openwall.com Cc: =?UTF-8?q?=C3=89rico=20Rolim?= Date: Tue, 4 Aug 2020 19:42:30 -0300 Message-Id: <20200804224230.27774-1-ericonr@disroot.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [musl] [PATCH v3] extend gethostid beyond a stub From: Érico 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. --- Andre McCurdy, thanks for the review. src/misc/gethostid.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/misc/gethostid.c b/src/misc/gethostid.c index 25bb35db..ac84b82d 100644 --- a/src/misc/gethostid.c +++ b/src/misc/gethostid.c @@ -1,6 +1,19 @@ #include +#include +#include long gethostid() { - return 0; + FILE *f; + int32_t rv = 0; + + f = fopen("/etc/hostid", "reb"); + if (f) { + if (fread(&rv, 4, 1, f) == 0) { + rv = 0; + } + fclose(f); + } + + return rv; } -- 2.28.0