Skip to content

Commit adf3061

Browse files
ZCubedscho
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 746c2fd commit adf3061

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
@@ -3867,3 +3867,35 @@ int uname(struct utsname *buf)
38673867
"%u", (v >> 16) & 0x7fff);
38683868
return 0;
38693869
}
3870+
3871+
/*
3872+
* Based on https://stackoverflow.com/questions/43002803
3873+
*
3874+
* [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
3875+
* "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
3876+
* "ErrorControl"=dword:00000001
3877+
* "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
3878+
* 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
3879+
* 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
3880+
* 65,00,00,00
3881+
* "Start"=dword:00000002
3882+
* "Type"=dword:00000010
3883+
* "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
3884+
* "ObjectName"="LocalSystem"
3885+
* "ServiceSidType"=dword:00000001
3886+
*/
3887+
int is_inside_windows_container(void)
3888+
{
3889+
static int inside_container = -1; /* -1 uninitialized */
3890+
const char *key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc";
3891+
HKEY handle = NULL;
3892+
3893+
if (inside_container != -1)
3894+
return inside_container;
3895+
3896+
inside_container = ERROR_SUCCESS ==
3897+
RegOpenKeyExA(HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &handle);
3898+
RegCloseKey(handle);
3899+
3900+
return inside_container;
3901+
}

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)