Skip to content

Commit 2aa8cdc

Browse files
authored
utils: add code to get the machine-id on windows machines. (#7970)
Signed-off-by: Phillip Whelan <[email protected]>
1 parent d59715e commit 2aa8cdc

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

src/flb_utils.c

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ int flb_utils_set_daemon(struct flb_config *config)
168168
pid_t pid;
169169

170170
if ((pid = fork()) < 0){
171-
flb_error("Failed creating to switch to daemon mode (fork failed)");
171+
flb_error("Failed creating to switch to daemon mode (fork failed)");
172172
exit(EXIT_FAILURE);
173-
}
173+
}
174174

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

190190
/* Our last STDOUT messages */
191191
flb_info("switching to background mode (PID=%ld)", (long) getpid());
@@ -1388,6 +1388,36 @@ int flb_utils_get_machine_id(char **out_id, size_t *out_size)
13881388
*out_size = bytes;
13891389
return 0;
13901390
}
1391+
#elif defined(FLB_SYSTEM_WINDOWS)
1392+
LSTATUS status;
1393+
HKEY hKey = 0;
1394+
DWORD dwType = REG_SZ;
1395+
char buf[255] = {0};
1396+
DWORD dwBufSize = sizeof(buf)-1;
1397+
1398+
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
1399+
TEXT("SOFTWARE\\Microsoft\\Cryptography"),
1400+
0,
1401+
KEY_QUERY_VALUE,
1402+
&hKey);
1403+
1404+
if (status != ERROR_SUCCESS) {
1405+
return -1;
1406+
}
1407+
1408+
status = RegQueryValueEx(hKey, TEXT("MachineGuid"), 0, &dwType, (LPBYTE)buf, &dwBufSize );
1409+
RegCloseKey(hKey);
1410+
1411+
if (status == ERROR_SUCCESS) {
1412+
*out_id = flb_calloc(1, dwBufSize+1);
1413+
1414+
if (*out_id == NULL) {
1415+
return -1;
1416+
}
1417+
1418+
*out_size = dwBufSize;
1419+
return 0;
1420+
}
13911421
#endif
13921422

13931423
/* generate a random uuid */

0 commit comments

Comments
 (0)