stdout and stderr need to be open in shared mode
diff --git a/src/native/windows/apps/prunsrv/prunsrv.c b/src/native/windows/apps/prunsrv/prunsrv.c
index 5cb816a..47abbe4 100644
--- a/src/native/windows/apps/prunsrv/prunsrv.c
+++ b/src/native/windows/apps/prunsrv/prunsrv.c
@@ -32,6 +32,7 @@
#include <stddef.h>
#include <fcntl.h>
#include <io.h> /* _open_osfhandle */
+#include <share.h>
#ifndef MIN
#define MIN(a,b) (((a)<(b)) ? (a) : (b))
@@ -321,16 +322,16 @@
*/
if (!aOut)
DeleteFileW(lpWrapper->szStdOutFilename);
- if ((_wfopen_s(&lpWrapper->fpStdOutFile,
- lpWrapper->szStdOutFilename,
- L"a"))) {
- lpWrapper->szStdOutFilename = NULL;
- }
- else {
+ if ((lpWrapper->fpStdOutFile = _wfsopen(lpWrapper->szStdOutFilename,
+ L"a",
+ _SH_DENYNO))) {
_dup2(_fileno(lpWrapper->fpStdOutFile), 1);
*stdout = *lpWrapper->fpStdOutFile;
setvbuf(stdout, NULL, _IONBF, 0);
}
+ else {
+ lpWrapper->szStdOutFilename = NULL;
+ }
}
if (lpWrapper->szStdErrFilename) {
if (lstrcmpiW(lpWrapper->szStdErrFilename, PRSRV_AUTO) == 0) {
@@ -347,16 +348,16 @@
}
if (!aErr)
DeleteFileW(lpWrapper->szStdErrFilename);
- if ((_wfopen_s(&lpWrapper->fpStdErrFile,
- lpWrapper->szStdErrFilename,
- L"a"))) {
- lpWrapper->szStdOutFilename = NULL;
- }
- else {
+ if ((lpWrapper->fpStdErrFile = _wfsopen(lpWrapper->szStdErrFilename,
+ L"a",
+ _SH_DENYNO))) {
_dup2(_fileno(lpWrapper->fpStdErrFile), 2);
*stderr = *lpWrapper->fpStdErrFile;
setvbuf(stderr, NULL, _IONBF, 0);
}
+ else {
+ lpWrapper->szStdOutFilename = NULL;
+ }
}
else if (lpWrapper->fpStdOutFile) {
_dup2(_fileno(lpWrapper->fpStdOutFile), 2);