From: "Érico Rolim" <ericonr@disroot.org>
To: musl@lists.openwall.com
Cc: "Érico Rolim" <erico.erc@gmail.com>
Subject: [musl] [PATCH v2] extend gethostid beyond a stub
Date: Tue, 4 Aug 2020 10:32:56 -0300 [thread overview]
Message-ID: <20200804133256.13494-1-ericonr@disroot.org> (raw)
From: Érico Rolim <erico.erc@gmail.com>
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?
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 <unistd.h>
+#include <stdio.h>
long gethostid()
{
- return 0;
+ FILE *f;
+ long 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
next reply other threads:[~2020-08-04 13:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-04 13:32 Érico Rolim [this message]
2020-08-04 18:41 ` Andre McCurdy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200804133256.13494-1-ericonr@disroot.org \
--to=ericonr@disroot.org \
--cc=erico.erc@gmail.com \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).