Skip to content

Commit da6368c

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 e776c28 commit da6368c

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
@@ -2981,3 +2981,35 @@ const char *program_data_config(void)
29812981
}
29822982
return *path.buf ? path.buf : NULL;
29832983
}
2984+
2985+
/*
2986+
* Based on https://stackoverflow.com/questions/43002803
2987+
*
2988+
* [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
2989+
* "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
2990+
* "ErrorControl"=dword:00000001
2991+
* "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
2992+
* 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
2993+
* 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
2994+
* 65,00,00,00
2995+
* "Start"=dword:00000002
2996+
* "Type"=dword:00000010
2997+
* "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
2998+
* "ObjectName"="LocalSystem"
2999+
* "ServiceSidType"=dword:00000001
3000+
*/
3001+
int is_inside_windows_container(void)
3002+
{
3003+
static int inside_container = -1; /* -1 uninitialized */
3004+
const char *key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc";
3005+
HKEY handle = NULL;
3006+
3007+
if (inside_container != -1)
3008+
return inside_container;
3009+
3010+
inside_container = ERROR_SUCCESS ==
3011+
RegOpenKeyExA(HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &handle);
3012+
RegCloseKey(handle);
3013+
3014+
return inside_container;
3015+
}

compat/mingw.h

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

0 commit comments

Comments
 (0)