Drop ".exe" exetention from eventlog file name
authorDuncan Coutts <duncan@well-typed.com>
Mon, 21 Nov 2011 11:32:15 +0000 (11:32 +0000)
committerIan Lynagh <igloo@earth.li>
Tue, 22 Nov 2011 20:06:48 +0000 (20:06 +0000)
Fixes ticket #5472

rts/eventlog/EventLog.c

index 9547e7c..2e2209d 100644 (file)
@@ -196,8 +196,22 @@ initEventLogging(void)
 {
     StgWord8 t, c;
     nat n_caps;
+    char *prog;
 
-    event_log_filename = stgMallocBytes(strlen(prog_name)
+    prog = stgMallocBytes(strlen(prog_name) + 1, "initEventLogging");
+    strcpy(prog, prog_name);
+#ifdef mingw32_HOST_OS
+    // on Windows, drop the .exe suffix if there is one
+    {
+        char *suff;
+        suff = strrchr(prog,'.');
+        if (suff != NULL && !strcmp(suff,".exe")) {
+            *suff = '\0';
+        }
+    }
+#endif
+
+    event_log_filename = stgMallocBytes(strlen(prog)
                                         + 10 /* .%d */
                                         + 10 /* .eventlog */,
                                         "initEventLogging");
@@ -208,14 +222,15 @@ initEventLogging(void)
 
     if (event_log_pid == -1) { // #4512
         // Single process
-        sprintf(event_log_filename, "%s.eventlog", prog_name);
+        sprintf(event_log_filename, "%s.eventlog", prog);
         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);
+        sprintf(event_log_filename, "%s.%d.eventlog", prog, event_log_pid);
     }
+    stgFree(prog);
 
     /* Open event log file for writing. */
     if ((event_log_file = fopen(event_log_filename, "wb")) == NULL) {