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 to get the machine-id on windows machines. #7970

Merged
merged 1 commit into from
Oct 5, 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
36 changes: 33 additions & 3 deletions src/flb_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ int flb_utils_set_daemon(struct flb_config *config)
pid_t pid;

if ((pid = fork()) < 0){
flb_error("Failed creating to switch to daemon mode (fork failed)");
flb_error("Failed creating to switch to daemon mode (fork failed)");
exit(EXIT_FAILURE);
}
}

if (pid > 0) { /* parent */
exit(EXIT_SUCCESS);
Expand All @@ -185,7 +185,7 @@ int flb_utils_set_daemon(struct flb_config *config)
if (chdir("/") < 0) { /* make sure we can unmount the inherited filesystem */
flb_error("Unable to unmount the inherited filesystem");
exit(EXIT_FAILURE);
}
}

/* Our last STDOUT messages */
flb_info("switching to background mode (PID=%ld)", (long) getpid());
Expand Down Expand Up @@ -1388,6 +1388,36 @@ int flb_utils_get_machine_id(char **out_id, size_t *out_size)
*out_size = bytes;
return 0;
}
#elif defined(FLB_SYSTEM_WINDOWS)
LSTATUS status;
HKEY hKey = 0;
DWORD dwType = REG_SZ;
char buf[255] = {0};
DWORD dwBufSize = sizeof(buf)-1;

status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
TEXT("SOFTWARE\\Microsoft\\Cryptography"),
0,
KEY_QUERY_VALUE,
&hKey);

if (status != ERROR_SUCCESS) {
return -1;
}

status = RegQueryValueEx(hKey, TEXT("MachineGuid"), 0, &dwType, (LPBYTE)buf, &dwBufSize );
RegCloseKey(hKey);

if (status == ERROR_SUCCESS) {
*out_id = flb_calloc(1, dwBufSize+1);

if (*out_id == NULL) {
return -1;
}

*out_size = dwBufSize;
return 0;
}
#endif

/* generate a random uuid */
Expand Down
Loading