Skip to content

Commit c78d805

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 c8f2f77 commit c78d805

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
@@ -3816,3 +3816,35 @@ int uname(struct utsname *buf)
38163816
"%u", (v >> 16) & 0x7fff);
38173817
return 0;
38183818
}
3819+
3820+
/*
3821+
* Based on https://stackoverflow.com/questions/43002803
3822+
*
3823+
* [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
3824+
* "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
3825+
* "ErrorControl"=dword:00000001
3826+
* "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
3827+
* 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
3828+
* 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
3829+
* 65,00,00,00
3830+
* "Start"=dword:00000002
3831+
* "Type"=dword:00000010
3832+
* "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
3833+
* "ObjectName"="LocalSystem"
3834+
* "ServiceSidType"=dword:00000001
3835+
*/
3836+
int is_inside_windows_container(void)
3837+
{
3838+
static int inside_container = -1; /* -1 uninitialized */
3839+
const char *key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc";
3840+
HKEY handle = NULL;
3841+
3842+
if (inside_container != -1)
3843+
return inside_container;
3844+
3845+
inside_container = ERROR_SUCCESS ==
3846+
RegOpenKeyExA(HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &handle);
3847+
RegCloseKey(handle);
3848+
3849+
return inside_container;
3850+
}

compat/mingw.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,3 +717,8 @@ void open_in_gdb(void);
717717
* Used by Pthread API implementation for Windows
718718
*/
719719
int err_win_to_posix(DWORD winerr);
720+
721+
/*
722+
* Check current process is inside Windows Container.
723+
*/
724+
int is_inside_windows_container(void);

0 commit comments

Comments
 (0)