Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flb_utils: add code for getting the machineID on macOS. #8096

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading