Skip to content

Commit

Permalink
utils: add code for getting the machineID on macOS. (#8096)
Browse files Browse the repository at this point in the history
Signed-off-by: Phillip Whelan <[email protected]>
  • Loading branch information
pwhelan authored Nov 7, 2023
1 parent 5be576e commit 14bba1f
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/flb_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ extern struct flb_aws_error_reporter *error_reporter;
#include <openssl/rand.h>
#endif

#ifdef FLB_SYSTEM_MACOS
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
#endif

/*
* The following block descriptor describes the private use unicode character range
* used for denoting invalid utf-8 fragments. Invalid fragment 0xCE would become
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 14bba1f

Please sign in to comment.