Skip to content

Commit e6adbe3

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 <zcube@zcube.kr> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 3b16ce1 commit e6adbe3

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

compat/mingw.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4250,3 +4250,35 @@ int mingw_have_unix_sockets(void)
42504250
return ret;
42514251
}
42524252
#endif
4253+
4254+
/*
4255+
* Based on https://stackoverflow.com/questions/43002803
4256+
*
4257+
* [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
4258+
* "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
4259+
* "ErrorControl"=dword:00000001
4260+
* "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
4261+
* 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
4262+
* 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
4263+
* 65,00,00,00
4264+
* "Start"=dword:00000002
4265+
* "Type"=dword:00000010
4266+
* "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
4267+
* "ObjectName"="LocalSystem"
4268+
* "ServiceSidType"=dword:00000001
4269+
*/
4270+
int is_inside_windows_container(void)
4271+
{
4272+
static int inside_container = -1; /* -1 uninitialized */
4273+
const char *key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc";
4274+
HKEY handle = NULL;
4275+
4276+
if (inside_container != -1)
4277+
return inside_container;
4278+
4279+
inside_container = ERROR_SUCCESS ==
4280+
RegOpenKeyExA(HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &handle);
4281+
RegCloseKey(handle);
4282+
4283+
return inside_container;
4284+
}

compat/mingw.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,8 @@ int mingw_have_unix_sockets(void);
288288
#undef have_unix_sockets
289289
#define have_unix_sockets mingw_have_unix_sockets
290290
#endif
291+
292+
/*
293+
* Check current process is inside Windows Container.
294+
*/
295+
int is_inside_windows_container(void);

0 commit comments

Comments
 (0)