src/lib/common.c 1.142

1.142 2009/12/24 04:55:40 markd
correctly check return status of system; removed confusing function that is no longer used
Index: src/lib/common.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/lib/common.c,v
retrieving revision 1.141
retrieving revision 1.142
diff -b -B -U 4 -r1.141 -r1.142
--- src/lib/common.c	19 Dec 2009 00:23:21 -0000	1.141
+++ src/lib/common.c	24 Dec 2009 04:55:40 -0000	1.142
@@ -2163,28 +2163,25 @@
     }
 }
 
 
-void maybeSystem(char *cmd)
-/* Execute cmd using "sh -c" or die.  (See man 3 system.) warn on errors */
-{
-if (cmd == NULL) // don't allow (system() supports testing for shell this way)
-    errAbort("mustSystem: called with NULL command.");
-int status = system(cmd);
-if (status != 0)
-    warn("maybeSystem: system(%s) failed (exit status %d): %s",
-	     cmd, WEXITSTATUS(status), strerror(errno));
-}
-
 void mustSystem(char *cmd)
 /* Execute cmd using "sh -c" or die.  (See man 3 system.) fail on errors */
 {
 if (cmd == NULL) // don't allow (system() supports testing for shell this way)
     errAbort("mustSystem: called with NULL command.");
 int status = system(cmd);
-if (status != 0)
-    errAbort("mustSystem: system(%s) failed (exit status %d): %s",
-	     cmd, WEXITSTATUS(status), strerror(errno));
+if (status == -1) 
+    errnoAbort("error starting command: %s", cmd);
+else if (WIFSIGNALED(status))
+    errAbort("command terminated by signal %d: %s", WTERMSIG(status), cmd);
+else if (WIFEXITED(status))
+    {
+    if (WEXITSTATUS(status) != 0)
+        errAbort("command exited with %d: %s", WEXITSTATUS(status), cmd);
+    }
+else
+    errAbort("bug: invalid exit status for command: %s", cmd);
 }
 
 int roundingScale(int a, int p, int q)
 /* returns rounded a*p/q */