diff --git a/src/flb_utils.c b/src/flb_utils.c index 86085f33192..dad0855df6f 100644 --- a/src/flb_utils.c +++ b/src/flb_utils.c @@ -46,6 +46,11 @@ extern struct flb_aws_error_reporter *error_reporter; #include #endif +#ifdef FLB_SYSTEM_MACOS +#include +#include +#endif + /* * The following block descriptor describes the private use unicode character range * used for denoting invalid utf-8 fragments. Invalid fragment 0xCE would become @@ -1416,6 +1421,46 @@ int flb_utils_get_machine_id(char **out_id, size_t *out_size) } *out_size = dwBufSize; + return 0; + } +#elif defined (FLB_SYSTEM_MACOS) + bool bret; + CFStringRef serialNumber; + io_service_t platformExpert = IOServiceGetMatchingService(kIOMainPortDefault, + IOServiceMatching("IOPlatformExpertDevice")); + + if (platformExpert) { + CFTypeRef serialNumberAsCFString = + IORegistryEntryCreateCFProperty(platformExpert, + CFSTR(kIOPlatformSerialNumberKey), + kCFAllocatorDefault, 0); + if (serialNumberAsCFString) { + serialNumber = (CFStringRef)serialNumberAsCFString; + } + else { + IOObjectRelease(platformExpert); + return -1; + } + IOObjectRelease(platformExpert); + + *out_size = CFStringGetLength(serialNumber); + *out_id = flb_malloc(CFStringGetLength(serialNumber)+1); + + if (*out_id == NULL) { + return -1; + } + + bret = CFStringGetCString(serialNumber, *out_id, + CFStringGetLength(serialNumber)+1, + kCFStringEncodingUTF8); + CFRelease(serialNumber); + + if (bret == false) { + flb_free(*out_size); + *out_size = 0; + return -1; + } + return 0; } #endif