diff options
author | Dmitry Astapov <dastapov@gmail.com> | 2010-12-03 13:39:50 +0000 |
---|---|---|
committer | Dmitry Astapov <dastapov@gmail.com> | 2010-12-03 13:39:50 +0000 |
commit | c50bc4658e3801442b4581bd1d9a19f67567cdda (patch) | |
tree | bf3cd0dd7431bac982f21a8aaee3121d8a9ebef5 /rts/eventlog | |
parent | 75cd9c50ea68a5e426e3105735713b8015d63413 (diff) | |
download | haskell-c50bc4658e3801442b4581bd1d9a19f67567cdda.tar.gz |
Fixes for #4512: EventLog.c - provides ability to terminate event logging, Schedule.c - uses them in forkProcess.
Diffstat (limited to 'rts/eventlog')
-rw-r--r-- | rts/eventlog/EventLog.c | 42 | ||||
-rw-r--r-- | rts/eventlog/EventLog.h | 2 |
2 files changed, 40 insertions, 4 deletions
diff --git a/rts/eventlog/EventLog.c b/rts/eventlog/EventLog.c index ef512281ec..71b348488f 100644 --- a/rts/eventlog/EventLog.c +++ b/rts/eventlog/EventLog.c @@ -17,8 +17,17 @@ #include "Stats.h" #include "EventLog.h" -#include <string.h> +#include <string.h> #include <stdio.h> +#ifdef HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif + +// PID of the process that writes to event_log_filename (#4512) +static pid_t event_log_pid = -1; static char *event_log_filename = NULL; @@ -171,9 +180,18 @@ initEventLogging(void) if (sizeof(EventDesc) / sizeof(char*) != NUM_EVENT_TAGS) { barf("EventDesc array has the wrong number of elements"); } - - sprintf(event_log_filename, "%s.eventlog", prog_name); - + + if (event_log_pid == -1) { // #4512 + // Single process + sprintf(event_log_filename, "%s.eventlog", prog_name); + event_log_pid = getpid(); + } else { + // Forked process, eventlog already started by the parent + // before fork + event_log_pid = getpid(); + sprintf(event_log_filename, "%s.%d.eventlog", prog_name, event_log_pid); + } + /* Open event log file for writing. */ if ((event_log_file = fopen(event_log_filename, "wb")) == NULL) { sysErrorBelch("initEventLogging: can't open %s", event_log_filename); @@ -338,6 +356,22 @@ freeEventLogging(void) } } +void +flushEventLog(void) +{ + if (event_log_file != NULL) { + fflush(event_log_file); + } +} + +void +abortEventLogging(void) +{ + freeEventLogging(); + if (event_log_file != NULL) { + fclose(event_log_file); + } +} /* * Post an event message to the capability's eventlog buffer. * If the buffer is full, prints out the buffer and clears it. diff --git a/rts/eventlog/EventLog.h b/rts/eventlog/EventLog.h index 0f31509e68..7dc249d35d 100644 --- a/rts/eventlog/EventLog.h +++ b/rts/eventlog/EventLog.h @@ -24,6 +24,8 @@ extern char *EventTagDesc[]; void initEventLogging(void); void endEventLogging(void); void freeEventLogging(void); +void abortEventLogging(void); // #4512 - after fork child needs to abort +void flushEventLog(void); // event log inherited from parent /* * Post a scheduler event to the capability's event buffer (an event |