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 30673 invoked from network); 3 Aug 2020 20:56:11 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 3 Aug 2020 20:56:11 -0000 Received: (qmail 8104 invoked by uid 550); 3 Aug 2020 20:56:09 -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 8074 invoked from network); 3 Aug 2020 20:56:08 -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=1596488155; bh=whFT0jrR397T3tAu14s2s7Hh4jNmzY62Vg46C/NALyA=; h=From:To:Cc:Subject:Date; b=UoBjlB+zCppGxgm9S2+6KF4wd8+a86ZdkzdzVRX+4wDjf7J2d59+ZVsx0yom5BLmr mDpvxn6Ks/x7QaBJWqn1m8I8kXI+RjtTuqnpnjaXiknX4rEPgnCgj1VcsnihXWbMwO xwGmiMqRioxHP9NHf1Hpmz/3M42M76uaSygslO9w6emD38WSc1ZnkpBvQ7J7u1KZ0+ R5/Aopz8CyrJ+7w1arYfw8i5s6vdvO0FvblbxO62iIz9OhoTrnAVoqjQ2O/uEfLjFZ fdEPiKf+zsekJhgq23UvwQn1smrDOeyrhu6xhUsHVg1CK235uVMGPOorPQnf1pUsX6 uQmacTnORDztw== To: musl@lists.openwall.com Cc: =?UTF-8?q?=C3=89rico=20Rolim?= Date: Mon, 3 Aug 2020 17:55:29 -0300 Message-Id: <20200803205529.2232-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..e2e98b99 100644 --- a/src/misc/gethostid.c +++ b/src/misc/gethostid.c @@ -1,6 +1,19 @@ #include +#include long gethostid() { - return 0; + FILE *f; + unsigned char hostid[4]; + long rv = 0; + + f = fopen("/etc/hostid", "reb"); + if (f) { + if (fread(hostid, 1, 4, f) == 4) { + rv = (hostid[3] << 24) | (hostid[2] << 16) | (hostid[1] << 8) | hostid[0]; + } + fclose(f); + } + + return rv; } -- 2.28.0