Skip to content

Commit ea27529

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 5a28e80 commit ea27529

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

compat/mingw/compat-util.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4233,3 +4233,35 @@ int mingw_have_unix_sockets(void)
42334233
return ret;
42344234
}
42354235
#endif
4236+
4237+
/*
4238+
* Based on https://stackoverflow.com/questions/43002803
4239+
*
4240+
* [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
4241+
* "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
4242+
* "ErrorControl"=dword:00000001
4243+
* "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
4244+
* 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
4245+
* 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
4246+
* 65,00,00,00
4247+
* "Start"=dword:00000002
4248+
* "Type"=dword:00000010
4249+
* "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
4250+
* "ObjectName"="LocalSystem"
4251+
* "ServiceSidType"=dword:00000001
4252+
*/
4253+
int is_inside_windows_container(void)
4254+
{
4255+
static int inside_container = -1; /* -1 uninitialized */
4256+
const char *key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc";
4257+
HKEY handle = NULL;
4258+
4259+
if (inside_container != -1)
4260+
return inside_container;
4261+
4262+
inside_container = ERROR_SUCCESS ==
4263+
RegOpenKeyExA(HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &handle);
4264+
RegCloseKey(handle);
4265+
4266+
return inside_container;
4267+
}

compat/mingw/compat-util.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,4 +292,9 @@ int mingw_have_unix_sockets(void);
292292
#define have_unix_sockets mingw_have_unix_sockets
293293
#endif
294294

295+
/*
296+
* Check current process is inside Windows Container.
297+
*/
298+
int is_inside_windows_container(void);
299+
295300
#endif /* COMPAT_MINGW_COMPAT_UTIL_H */

0 commit comments

Comments
 (0)