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 4345 invoked from network); 20 Apr 2021 19:16:16 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 20 Apr 2021 19:16:16 -0000 Received: (qmail 22070 invoked by uid 550); 20 Apr 2021 19:16:05 -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 21967 invoked from network); 20 Apr 2021 19:16:04 -0000 X-Virus-Scanned: Debian amavisd-new at disroot.org From: =?UTF-8?q?=C3=89rico=20Nogueira?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1618946150; bh=bVPjRkNIAsUXOTgLhpQkW/mgBcAONqJ6exx+7SA4fZ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=IQgGeNCMRLj2k8MTF2iM9bAAhr+crPa13SNPbjTwNjV58HQvbCH1KtO78vYAUzzho xdD/SLdKtzbO5OsNUrOHWCJiJFPU8fyy8Lp/yK+7sIBdLdfYB9bho9f+toOQqwuVnE t6IESla44i/3ktNQtTEkQcbT2g9Lyxd1C29jfpzyeavB8wDtmIxoltAPxifKEo3nPY YREjdoq/ShxHfwaz16vKh0GehssqQwNTXoofRU7btXTAuTDJHAvHd9qGyZEB5X9GTH J6/Y1qGM0z7xyA/G1N5XHn64PMeAqYZ5qLLWAJElWi48hDNBo1kACoIdlyMeiU6jsx RyfqJyres+b1w== To: musl@lists.openwall.com Cc: =?UTF-8?q?=C3=89rico=20Rolim?= Date: Tue, 20 Apr 2021 16:15:17 -0300 Message-Id: <20210420191519.23822-3-ericonr@disroot.org> In-Reply-To: <20210420191519.23822-1-ericonr@disroot.org> References: <20210420191519.23822-1-ericonr@disroot.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [musl] [PATCH] 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. --- 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..d529de9c 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, sizeof(rv), 1, f) == 0) { + rv = 0; + } + fclose(f); + } + + return rv; } -- 2.31.1