Skip to content

Commit 7eda2b4

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 ad16484 commit 7eda2b4

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
@@ -3668,3 +3668,35 @@ int uname(struct utsname *buf)
36683668
"%u", (v >> 16) & 0x7fff);
36693669
return 0;
36703670
}
3671+
3672+
/*
3673+
* Based on https://stackoverflow.com/questions/43002803
3674+
*
3675+
* [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
3676+
* "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
3677+
* "ErrorControl"=dword:00000001
3678+
* "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
3679+
* 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
3680+
* 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
3681+
* 65,00,00,00
3682+
* "Start"=dword:00000002
3683+
* "Type"=dword:00000010
3684+
* "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
3685+
* "ObjectName"="LocalSystem"
3686+
* "ServiceSidType"=dword:00000001
3687+
*/
3688+
int is_inside_windows_container(void)
3689+
{
3690+
static int inside_container = -1; /* -1 uninitialized */
3691+
const char *key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc";
3692+
HKEY handle = NULL;
3693+
3694+
if (inside_container != -1)
3695+
return inside_container;
3696+
3697+
inside_container = ERROR_SUCCESS ==
3698+
RegOpenKeyExA(HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &handle);
3699+
RegCloseKey(handle);
3700+
3701+
return inside_container;
3702+
}

compat/mingw.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,3 +704,8 @@ void open_in_gdb(void);
704704
* Used by Pthread API implementation for Windows
705705
*/
706706
int err_win_to_posix(DWORD winerr);
707+
708+
/*
709+
* Check current process is inside Windows Container.
710+
*/
711+
int is_inside_windows_container(void);

0 commit comments

Comments
 (0)