X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fuuid.c;h=89766268740aa7f7a40ab81bbdb21c40e8ed35e4;hb=ec9ed6fe4108f7fd3d4ef84e887bb6d3dc022e14;hp=9e9a7a33ba6491f4b574d418eaeb9415909f3912;hpb=f3610533206238bf4fcb72c76e9a07517d8bc64b;p=collectd.git diff --git a/src/uuid.c b/src/uuid.c index 9e9a7a33..89766268 100644 --- a/src/uuid.c +++ b/src/uuid.c @@ -114,7 +114,7 @@ uuid_get_from_dmidecode(void) return (uuid); } -#if defined(__APPLE__) +#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) static char * uuid_get_from_sysctlbyname(const char *name) { @@ -124,6 +124,21 @@ uuid_get_from_sysctlbyname(const char *name) return NULL; return (strdup (uuid)); } +#elif defined(__OpenBSD__) +static char * +uuid_get_from_sysctl(void) +{ + char uuid[UUID_PRINTABLE_NORMAL_LENGTH + 1]; + size_t len = sizeof (uuid); + int mib[2]; + + mib[0] = CTL_HW; + mib[1] = HW_UUID; + + if (sysctl(mib, 2, uuid, &len, NULL, 0) == -1) + return NULL; + return (strdup (uuid)); +} #endif #if HAVE_LIBHAL_H @@ -212,8 +227,16 @@ uuid_get_local(void) #if defined(__APPLE__) if ((uuid = uuid_get_from_sysctlbyname("kern.uuid")) != NULL) return (uuid); -#endif -#if defined(__linux__) +#elif defined(__FreeBSD__) + if ((uuid = uuid_get_from_sysctlbyname("kern.hostuuid")) != NULL) + return (uuid); +#elif defined(__NetBSD__) + if ((uuid = uuid_get_from_sysctlbyname("machdep.dmi.system-uuid")) != NULL) + return (uuid); +#elif defined(__OpenBSD__) + if ((uuid = uuid_get_from_sysctl()) != NULL) + return (uuid); +#elif defined(__linux__) if ((uuid = uuid_get_from_file("/sys/class/dmi/id/product_uuid")) != NULL) return (uuid); #endif