musl-1.2.2-gethostid.patch 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. Subject: [musl] [PATCH] extend gethostid beyond a stub
  2. Archived-At: <https://inbox.vuxu.org/musl/20210420191519.23822-3-ericonr@disroot.org/>
  3. List-Archive: <https://inbox.vuxu.org/musl/>
  4. List-Post: <mailto:musl@inbox.vuxu.org>
  5. From: Érico Rolim <erico.erc@gmail.com>
  6. Implement part of the glibc behavior, where the 32-bit identifier stored
  7. in /etc/hostid, if the file exists, is returned. If this file doesn't
  8. contain at least 32 bits or can't be opened for some reason, return 0.
  9. ---
  10. src/misc/gethostid.c | 15 ++++++++++++++-
  11. 1 file changed, 14 insertions(+), 1 deletion(-)
  12. diff --git a/src/misc/gethostid.c b/src/misc/gethostid.c
  13. index 25bb35db..d529de9c 100644
  14. --- a/src/misc/gethostid.c
  15. +++ b/src/misc/gethostid.c
  16. @@ -1,6 +1,19 @@
  17. #include <unistd.h>
  18. +#include <stdio.h>
  19. +#include <stdint.h>
  20. long gethostid()
  21. {
  22. - return 0;
  23. + FILE *f;
  24. + int32_t rv = 0;
  25. +
  26. + f = fopen("/etc/hostid", "reb");
  27. + if (f) {
  28. + if (fread(&rv, sizeof(rv), 1, f) == 0) {
  29. + rv = 0;
  30. + }
  31. + fclose(f);
  32. + }
  33. +
  34. + return rv;
  35. }
  36. --
  37. 2.31.1