From: Ruben Kerkhof Date: Fri, 25 Dec 2015 10:10:16 +0000 (+0100) Subject: uuid plugin: make it work on OSX X-Git-Tag: collectd-5.6.0~87^2~3 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=f3610533206238bf4fcb72c76e9a07517d8bc64b;p=collectd.git uuid plugin: make it work on OSX --- diff --git a/src/uuid.c b/src/uuid.c index e837ca72..9e9a7a33 100644 --- a/src/uuid.c +++ b/src/uuid.c @@ -1,6 +1,7 @@ /** * collectd - src/uuid.c * Copyright (C) 2007 Red Hat Inc. + * Copyright (C) 2015 Ruben Kerkhof * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -29,6 +30,10 @@ #include "configfile.h" #include "plugin.h" +#if HAVE_SYS_SYSCTL_H +#include +#endif + #if HAVE_LIBHAL_H #include #endif @@ -109,6 +114,18 @@ uuid_get_from_dmidecode(void) return (uuid); } +#if defined(__APPLE__) +static char * +uuid_get_from_sysctlbyname(const char *name) +{ + char uuid[UUID_PRINTABLE_NORMAL_LENGTH + 1]; + size_t len = sizeof (uuid); + if (sysctlbyname(name, &uuid, &len, NULL, 0) == -1) + return NULL; + return (strdup (uuid)); +} +#endif + #if HAVE_LIBHAL_H #define UUID_PATH "/org/freedesktop/Hal/devices/computer" @@ -192,6 +209,10 @@ uuid_get_local(void) if ((uuid = uuid_get_from_file(uuidfile ? uuidfile : "/etc/uuid")) != NULL) return (uuid); +#if defined(__APPLE__) + if ((uuid = uuid_get_from_sysctlbyname("kern.uuid")) != NULL) + return (uuid); +#endif #if defined(__linux__) if ((uuid = uuid_get_from_file("/sys/class/dmi/id/product_uuid")) != NULL) return (uuid);