src/lib/osunix.c 1.40

1.40 2009/06/03 00:34:11 markd
added option to generate stack dumps when browser errors occur
Index: src/lib/osunix.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/lib/osunix.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -b -B -U 4 -r1.39 -r1.40
--- src/lib/osunix.c	7 Feb 2009 18:12:20 -0000	1.39
+++ src/lib/osunix.c	3 Jun 2009 00:34:11 -0000	1.40
@@ -377,45 +377,59 @@
 cmd[1] = pidStr;
 cmd[2] = NULL;
 
 // redirect stdout to stderr
-if (dup2(1, 2) < 0)
+if (dup2(2, 1) < 0)
     errAbort("dup2 failed");
 
 execvp(cmd[0], cmd);
 errAbort("exec failed: %s", cmd[0]);
 }
 
 void vaDumpStack(char *format, va_list args)
 /* debugging function to run the pstack program on the current process. In
- * prints a message, following by a new line, and then the stack track.
- * For debugging purposes only.  */
+ * prints a message, following by a new line, and then the stack track.  Just
+ * prints errors to stderr rather than aborts. For debugging purposes
+ * only.  */
 {
-fprintf(stderr, format, args);
+vfprintf(stderr, format, args);
 fputc('\n', stderr);
 fflush(stderr);
 pid_t ppid = getpid();
 pid_t pid = fork();
 if (pid < 0)
-    errnoAbort("can't fork");
+    {
+    perror("can't fork pstack");
+    return;
+    }
 if (pid == 0)
     execPStack(ppid);
 int wstat;
 if (waitpid(pid, &wstat, 0) < 0)
-    errnoAbort("waitpid failed");
+    {
+    perror("waitpid on pstack failed");
+    return;
+    }
 if (WIFEXITED(wstat))
     {
     if (WEXITSTATUS(wstat) != 0)
-        errAbort("pstack failed");
+        {
+        fprintf(stderr, "pstack failed\n");
+        return;
+        }
     }
 else if (WIFSIGNALED(wstat))
-    errAbort("pstack signaled %d", WTERMSIG(wstat));
+    {
+    fprintf(stderr, "pstack signaled %d\n", WTERMSIG(wstat));
+    return;
+    }
 }
 
 void dumpStack(char *format, ...)
 /* debugging function to run the pstack program on the current process. In
- * prints a message, following by a new line, and then the stack track.
- * For debugging purposes only.  */
+ * prints a message, following by a new line, and then the stack track.  Just
+ * prints errors to stderr rather than aborts. For debugging purposes
+ * only.  */
 {
 va_list args;
 va_start(args, format);
 vaDumpStack(format, args);