diff options
author | Micael Karlberg <[email protected]> | 2018-11-05 14:37:39 +0100 |
---|---|---|
committer | Micael Karlberg <[email protected]> | 2018-11-05 14:37:39 +0100 |
commit | 6fcbb97c0b7f082c4934d7765c6b63222f317ef2 (patch) | |
tree | 81a6bc18671c3ed8981e40e416719e1d5648bb19 /erts/emulator/nifs/common/socket_dbg.c | |
parent | c6767f0a6dc66971df4425c216024c47993a310b (diff) | |
download | otp-6fcbb97c0b7f082c4934d7765c6b63222f317ef2.tar.gz otp-6fcbb97c0b7f082c4934d7765c6b63222f317ef2.tar.bz2 otp-6fcbb97c0b7f082c4934d7765c6b63222f317ef2.zip |
[socket-nif] Make it possible to send (nif) debug to file
Make it possible to open a file and send debug printouts to
(instead of stdout) for debug printouts from the nif-code.
OTP-14831
Diffstat (limited to 'erts/emulator/nifs/common/socket_dbg.c')
-rw-r--r-- | erts/emulator/nifs/common/socket_dbg.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/erts/emulator/nifs/common/socket_dbg.c b/erts/emulator/nifs/common/socket_dbg.c index dd11fbca9b..fe9135e5a0 100644 --- a/erts/emulator/nifs/common/socket_dbg.c +++ b/erts/emulator/nifs/common/socket_dbg.c @@ -36,10 +36,32 @@ #define TNAME(__T__) enif_thread_name( __T__ ) #define TSNAME() TNAME(TSELF()) +static FILE* dbgout = NULL; + static int realtime(struct timespec* tsP); static int timespec2str(char *buf, unsigned int len, struct timespec *ts); +extern +void esock_dbg_init(char* filename) +{ + if (filename != NULL) { + if (strcmp(filename, ESOCK_DBGOUT_DEFAULT) == 0) { + dbgout = stdout; + } else if (strcmp(filename, ESOCK_DBGOUT_UNIQUE) == 0) { + char template[] = "/tmp/esock-dbg-XXXXXX"; + dbgout = fdopen(mkstemp(template), "w+"); + } else { + dbgout = fopen(filename, "w+"); + } + } else { + char template[] = "/tmp/esock-dbg-XXXXXX"; + dbgout = fdopen(mkstemp(template), "w+"); + } +} + + + /* * Print a debug format string *with* both a timestamp and the * the name of the *current* thread. @@ -70,7 +92,7 @@ void esock_dbg_printf( const char* prefix, const char* format, ... ) if (res > 0) { va_start (args, format); - enif_vfprintf (stdout, f, args); + enif_vfprintf (dbgout, f, args); va_end (args); fflush(stdout); } |