Skip to content

Commit 1bcec54

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 <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent a51eee8 commit 1bcec54

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
@@ -3107,3 +3107,35 @@ const char *program_data_config(void)
31073107
}
31083108
return *path.buf ? path.buf : NULL;
31093109
}
3110+
3111+
/*
3112+
* Based on https://stackoverflow.com/questions/43002803
3113+
*
3114+
* [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
3115+
* "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
3116+
* "ErrorControl"=dword:00000001
3117+
* "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
3118+
* 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
3119+
* 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
3120+
* 65,00,00,00
3121+
* "Start"=dword:00000002
3122+
* "Type"=dword:00000010
3123+
* "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
3124+
* "ObjectName"="LocalSystem"
3125+
* "ServiceSidType"=dword:00000001
3126+
*/
3127+
int is_inside_windows_container(void)
3128+
{
3129+
static int inside_container = -1; /* -1 uninitialized */
3130+
const char *key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc";
3131+
HKEY handle = NULL;
3132+
3133+
if (inside_container != -1)
3134+
return inside_container;
3135+
3136+
inside_container = ERROR_SUCCESS ==
3137+
RegOpenKeyExA(HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &handle);
3138+
RegCloseKey(handle);
3139+
3140+
return inside_container;
3141+
}

compat/mingw.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,3 +676,8 @@ extern void open_in_gdb(void);
676676
* Used by Pthread API implementation for Windows
677677
*/
678678
extern int err_win_to_posix(DWORD winerr);
679+
680+
/*
681+
* Check current process is inside Windows Container.
682+
*/
683+
extern int is_inside_windows_container(void);

0 commit comments

Comments
 (0)