aboutsummaryrefslogtreecommitdiffstats
path: root/lib/runtime_tools/c_src/trace_file_drv.c
diff options
context:
space:
mode:
authorPatrik Nyblom <[email protected]>2011-11-29 11:47:33 +0100
committerPatrik Nyblom <[email protected]>2011-12-02 15:39:44 +0100
commit6c9a067222f868564cfe3e3f8deda738cc23da31 (patch)
tree480c1ce1866a02c3bb1f84d19af45af3532ebfd3 /lib/runtime_tools/c_src/trace_file_drv.c
parent0d273c54d93fd0ddf03f98d138f302442a0f65f9 (diff)
downloadotp-6c9a067222f868564cfe3e3f8deda738cc23da31.tar.gz
otp-6c9a067222f868564cfe3e3f8deda738cc23da31.tar.bz2
otp-6c9a067222f868564cfe3e3f8deda738cc23da31.zip
Avoid inheriting trace file handles to child processes
Use CreateFile to open files in trace_file_drv
Diffstat (limited to 'lib/runtime_tools/c_src/trace_file_drv.c')
-rw-r--r--lib/runtime_tools/c_src/trace_file_drv.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/lib/runtime_tools/c_src/trace_file_drv.c b/lib/runtime_tools/c_src/trace_file_drv.c
index 668f6f4af3..116b8242f5 100644
--- a/lib/runtime_tools/c_src/trace_file_drv.c
+++ b/lib/runtime_tools/c_src/trace_file_drv.c
@@ -21,6 +21,9 @@
* Purpose: Send trace messages to a file.
*/
+#ifdef __WIN32__
+#include <windows.h>
+#endif
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
@@ -31,7 +34,6 @@
#ifdef __WIN32__
# include <io.h>
# define write _write
-# define open _open
# define close _close
# define unlink _unlink
#else
@@ -194,6 +196,10 @@ static int my_flush(TraceFileData *data);
static void put_be(unsigned n, unsigned char *s);
static void close_unlink_port(TraceFileData *data);
static int wrap_file(TraceFileData *data);
+#ifdef __WIN32__
+static int win_open(char *path, int flags, int mask);
+#define open win_open
+#endif
/*
** The driver struct
@@ -241,6 +247,7 @@ static ErlDrvData trace_file_start(ErlDrvPort port, char *buff)
int n, w;
static const char name[] = "trace_file_drv";
+
#ifdef HARDDEBUG
fprintf(stderr,"hello (%s)\r\n", buff);
#endif
@@ -636,3 +643,40 @@ static int wrap_file(TraceFileData *data) {
return 0;
}
+#ifdef __WIN32__
+static int win_open(char *path, int flags, int mask)
+{
+ DWORD access = 0;
+ DWORD creation = 0;
+ HANDLE fd;
+ int ret;
+ if (flags & O_WRONLY) {
+ access = GENERIC_WRITE;
+ } else if (flags & O_RDONLY) {
+ access = GENERIC_READ;
+ } else {
+ access = (GENERIC_READ | GENERIC_WRITE);
+ }
+
+ if (flags & O_CREAT) {
+ creation |= CREATE_ALWAYS;
+ } else {
+ creation |= OPEN_ALWAYS;
+ }
+
+ fd = CreateFileA(path, access,
+ FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+ NULL, creation, FILE_ATTRIBUTE_NORMAL, NULL);
+ if (fd == INVALID_HANDLE_VALUE) {
+
+ return -1;
+ }
+
+ if ((ret = _open_osfhandle((intptr_t)fd, (flags & O_RDONLY) ? O_RDONLY : 0))
+ < 0) {
+ CloseHandle(fd);
+ }
+
+ return ret;
+}
+#endif