Skip to content

Commit c049671

Browse files
zcubeGit for Windows Build Agent
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 f7462a6 commit c049671

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

lib/compat/mingw.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3776,3 +3776,35 @@ int mingw_have_unix_sockets(void)
37763776
return ret;
37773777
}
37783778
#endif
3779+
3780+
/*
3781+
* Based on https://stackoverflow.com/questions/43002803
3782+
*
3783+
* [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
3784+
* "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
3785+
* "ErrorControl"=dword:00000001
3786+
* "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
3787+
* 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
3788+
* 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
3789+
* 65,00,00,00
3790+
* "Start"=dword:00000002
3791+
* "Type"=dword:00000010
3792+
* "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
3793+
* "ObjectName"="LocalSystem"
3794+
* "ServiceSidType"=dword:00000001
3795+
*/
3796+
int is_inside_windows_container(void)
3797+
{
3798+
static int inside_container = -1; /* -1 uninitialized */
3799+
const char *key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc";
3800+
HKEY handle = NULL;
3801+
3802+
if (inside_container != -1)
3803+
return inside_container;
3804+
3805+
inside_container = ERROR_SUCCESS ==
3806+
RegOpenKeyExA(HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &handle);
3807+
RegCloseKey(handle);
3808+
3809+
return inside_container;
3810+
}

lib/compat/mingw.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,8 @@ int mingw_have_unix_sockets(void);
213213
#undef have_unix_sockets
214214
#define have_unix_sockets mingw_have_unix_sockets
215215
#endif
216+
217+
/*
218+
* Check current process is inside Windows Container.
219+
*/
220+
int is_inside_windows_container(void);

0 commit comments

Comments
 (0)