Skip to content

Commit 44d9078

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 721b645 commit 44d9078

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
@@ -4003,3 +4003,35 @@ int mingw_have_unix_sockets(void)
40034003
return ret;
40044004
}
40054005
#endif
4006+
4007+
/*
4008+
* Based on https://stackoverflow.com/questions/43002803
4009+
*
4010+
* [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
4011+
* "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
4012+
* "ErrorControl"=dword:00000001
4013+
* "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
4014+
* 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
4015+
* 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
4016+
* 65,00,00,00
4017+
* "Start"=dword:00000002
4018+
* "Type"=dword:00000010
4019+
* "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
4020+
* "ObjectName"="LocalSystem"
4021+
* "ServiceSidType"=dword:00000001
4022+
*/
4023+
int is_inside_windows_container(void)
4024+
{
4025+
static int inside_container = -1; /* -1 uninitialized */
4026+
const char *key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc";
4027+
HKEY handle = NULL;
4028+
4029+
if (inside_container != -1)
4030+
return inside_container;
4031+
4032+
inside_container = ERROR_SUCCESS ==
4033+
RegOpenKeyExA(HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &handle);
4034+
RegCloseKey(handle);
4035+
4036+
return inside_container;
4037+
}

compat/mingw.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,3 +728,8 @@ int mingw_have_unix_sockets(void);
728728
#undef have_unix_sockets
729729
#define have_unix_sockets mingw_have_unix_sockets
730730
#endif
731+
732+
/*
733+
* Check current process is inside Windows Container.
734+
*/
735+
int is_inside_windows_container(void);

0 commit comments

Comments
 (0)