pkgsrc-WIP-changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

actor-framework: uses sysctl to get possible root uuids on the bsds



Module Name:	pkgsrc-wip
Committed By:	Niclas Rosenvik <nros%pkgsrc.org@localhost>
Pushed By:	nros
Date:		Tue Jan 11 21:15:46 2022 +0100
Changeset:	fe859b71738eafc1dd476b92540e0342c4c41964

Modified Files:
	actor-framework/distinfo
	actor-framework/patches/patch-libcaf__core_src_detail_get__root__uuid.cpp

Log Message:
actor-framework: uses sysctl to get possible root uuids on the bsds

use sysctl to get possible root uuids on the bsds.
use CAFs built-in uuid generator to create one if one is not found.
Remove the code that uses the bsd uuid api since it is much easier
to use the built-in CAF uuid class.

To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=fe859b71738eafc1dd476b92540e0342c4c41964

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

diffstat:
 actor-framework/distinfo                           |  2 +-
 ...tch-libcaf__core_src_detail_get__root__uuid.cpp | 84 +++++++++++++++-------
 2 files changed, 58 insertions(+), 28 deletions(-)

diffs:
diff --git a/actor-framework/distinfo b/actor-framework/distinfo
index 88e1892863..64fd259180 100644
--- a/actor-framework/distinfo
+++ b/actor-framework/distinfo
@@ -7,7 +7,7 @@ SHA1 (patch-examples_message__passing_fan__out__request.cpp) = 2039d3a58f8c4dd23
 SHA1 (patch-libcaf__core_CMakeLists.txt) = 9791d9ad4036a5eae13183e354f37f3abc98b3e9
 SHA1 (patch-libcaf__core_caf_config.hpp) = 31247b3883c0c2f4d60018606949e0d0fff691c4
 SHA1 (patch-libcaf__core_src_detail_get__mac__addresses.cpp) = f6758ab15441a830851d66fcede9cfdb185a232b
-SHA1 (patch-libcaf__core_src_detail_get__root__uuid.cpp) = 12d41ee314b3839f180d0726c5821daa27dac4db
+SHA1 (patch-libcaf__core_src_detail_get__root__uuid.cpp) = 4e34873e36d4ea5a3b1d45de279c1c9a85329f95
 SHA1 (patch-libcaf__core_src_detail_pretty__type__name.cpp) = 922423499220ba8481da6076877fb755ab49c569
 SHA1 (patch-libcaf__core_src_detail_set__thread__name.cpp) = 75fb8b7daf977e87d6c591a5f66f19b12e840a95
 SHA1 (patch-libcaf__core_src_telemetry_importer_process.cpp) = 3d01576f115ce238ea73355c4c3175208748159b
diff --git a/actor-framework/patches/patch-libcaf__core_src_detail_get__root__uuid.cpp b/actor-framework/patches/patch-libcaf__core_src_detail_get__root__uuid.cpp
index a8733d3fd3..9eb3656ca1 100644
--- a/actor-framework/patches/patch-libcaf__core_src_detail_get__root__uuid.cpp
+++ b/actor-framework/patches/patch-libcaf__core_src_detail_get__root__uuid.cpp
@@ -22,63 +22,93 @@ $NetBSD$
  
  #  include <algorithm>
  #  include <fstream>
-@@ -125,6 +126,50 @@ std::string get_root_uuid() {
+@@ -125,6 +126,80 @@ std::string get_root_uuid() {
  
  } // namespace caf::detail
  
-+#elif defined(CAF_NETBSD)
++#elif defined(CAF_NETBSD) || defined(CAF_BSD)
 +
-+#  include <uuid.h>
++#  include <sys/param.h>
++#  include <sys/types.h>
++#  include <sys/sysctl.h>
 +
 +#  include <cstdlib>
 +#  include <string>
 +
++#  include "caf/uuid.hpp"
++
 +namespace caf {
 +namespace detail {
 +
 +namespace {
-+  uuid_t s_uuid;
-+  bool s_uuid_need_init = true;
-+}
++  std::string root_uuid;
 +
-+std::string get_root_uuid()
-+{
-+  std::string uuid;
-+  char *uuid_str;
-+  uint32_t status;
-+  if(s_uuid_need_init) {
-+    uuid_create(&s_uuid, &status);
-+    if(status != uuid_s_ok) {
-+      CAF_LOG_ERROR("failed to get uuid from uuid_create in get_root_uuid");
-+      return uuid;
++  std::string get_sysctl_uuid()
++  {
++#  if defined(__FreeBSD__)
++    int mib[2];
++    u_int mib_len = 2;
++    mib[0] = CTL_KERN;
++    mib[1] = KERN_HOSTUUID;
++#  elif defined(__OpenBSD__)
++    int mib[2];
++    u_int mib_len = 2;
++    mib[0] = CTL_HW;
++    mib[1] = HW_UUID;
++#  elif defined(CAF_NETBSD)
++    int mib[3];
++    size_t mib_len = 3;
++    if (sysctlnametomib("machdep.dmi.system-uuid", mib, &mib_len)) {
++      return std::string{};
++    }
++#  endif
++    size_t uuid_len;
++    char *uuid_str;
++
++    if (sysctl(mib, mib_len, NULL, &uuid_len, NULL, (size_t)0)) {
++      return std::string{};
++    }
++
++    uuid_str = (char*)malloc(uuid_len);
++
++    if (sysctl(mib, mib_len, uuid_str, &uuid_len, NULL, (size_t)0)) {
++      free(uuid_str);
++      return std::string{};
 +    }
-+    s_uuid_need_init = false;
++
++    std::string sc_uuid{uuid_str};
++    free(uuid_str);
++
++    return sc_uuid;
 +  }
 +
-+  uuid_to_string(&s_uuid, &uuid_str, &status);
-+  if(status != uuid_s_ok) {
-+    CAF_LOG_ERROR("failed to create uuid string using uuid_to_string in get_root_uuid");
-+    return uuid;
++} // namespace
++
++std::string get_root_uuid()
++{
++  if(root_uuid.empty()) {
++    root_uuid = get_sysctl_uuid();
++
++    if(root_uuid.empty() || (root_uuid.compare("00000000-0000-0000-0000-000000000000") == 0)) {
++      root_uuid = to_string(caf::uuid::random());
++    }
 +  }
-+  uuid.assign(uuid_str);
-+  free(uuid_str);
 +
-+  return uuid;
++  return root_uuid;
 +}
 +
-+
 +} // detail
 +} // caf
 +
  #elif defined(CAF_WINDOWS)
  
  #  include <algorithm>
-@@ -192,7 +237,7 @@ std::string get_root_uuid() {
+@@ -192,7 +267,7 @@ std::string get_root_uuid() {
  } // namespace detail
  } // namespace caf
  
 -#elif defined(CAF_IOS) || defined(CAF_ANDROID)
-+#elif defined(CAF_IOS) || defined(CAF_ANDROID) || defined(CAF_SOLARIS) || defined(CAF_BSD)
++#elif defined(CAF_IOS) || defined(CAF_ANDROID) || defined(CAF_SOLARIS)
  
  // return a randomly-generated UUID on mobile devices
  


Home | Main Index | Thread Index | Old Index