Skip to content

Commit 081b7f5

Browse files
ZCubeGit for Windows Build Agent
authored andcommitted
mingw: introduce code to detect whether we're inside a Windows container
This will come in handy in the next commit. Signed-off-by: JiSeop Moon <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent e4313bf commit 081b7f5

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

compat/mingw.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3440,3 +3440,35 @@ int uname(struct utsname *buf)
34403440
"%u", (v >> 16) & 0x7fff);
34413441
return 0;
34423442
}
3443+
3444+
/*
3445+
* Based on https://stackoverflow.com/questions/43002803
3446+
*
3447+
* [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
3448+
* "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
3449+
* "ErrorControl"=dword:00000001
3450+
* "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
3451+
* 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
3452+
* 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
3453+
* 65,00,00,00
3454+
* "Start"=dword:00000002
3455+
* "Type"=dword:00000010
3456+
* "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
3457+
* "ObjectName"="LocalSystem"
3458+
* "ServiceSidType"=dword:00000001
3459+
*/
3460+
int is_inside_windows_container(void)
3461+
{
3462+
static int inside_container = -1; /* -1 uninitialized */
3463+
const char *key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc";
3464+
HKEY handle = NULL;
3465+
3466+
if (inside_container != -1)
3467+
return inside_container;
3468+
3469+
inside_container = ERROR_SUCCESS ==
3470+
RegOpenKeyExA(HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &handle);
3471+
RegCloseKey(handle);
3472+
3473+
return inside_container;
3474+
}

compat/mingw.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,3 +700,8 @@ extern void open_in_gdb(void);
700700
* Used by Pthread API implementation for Windows
701701
*/
702702
int err_win_to_posix(DWORD winerr);
703+
704+
/*
705+
* Check current process is inside Windows Container.
706+
*/
707+
int is_inside_windows_container(void);

0 commit comments

Comments
 (0)