shithub: mc

Download patch

ref: 040b2c92820949d286a8c94b7dcb8965523549e8
parent: cc8c4835a485d7568d7e8f1187f4092dba91255e
author: Ori Bernstein <[email protected]>
date: Fri Sep 28 08:55:44 EDT 2012

Make a few changes to increase robustness.

    Exit after we fail to run a command, instead of ignoring the
    failure.

--- a/myrbuild/myrbuild.c
+++ b/myrbuild/myrbuild.c
@@ -94,7 +94,7 @@
     lappend(cmd, ncmd, NULL); 
 }
 
-int run(char **cmd)
+void run(char **cmd)
 {
     pid_t pid;
     int status;
@@ -102,7 +102,7 @@
     printl(cmd);
     pid = fork();
     if (pid == -1) {
-        die("Could not fork\n");
+        err(1, "Could not fork");
     } else if (pid == 0) {
         if (execvp(cmd[0], cmd) == -1)
             err(1, "Failed to exec %s", cmd[0]);
@@ -109,7 +109,8 @@
     } else {
         waitpid(pid, &status, 0);
     }
-    return WIFEXITED(status) && WEXITSTATUS(status) == 0;
+    if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+        die("Command failed");
 }
 
 int isfresh(char *from, char *to)
@@ -117,7 +118,7 @@
     struct stat from_sb, to_sb;
 
     if (stat(from, &from_sb))
-        die("Could not find %s\n", from);
+        err(1, "Could not find %s", from);
     if (stat(to, &to_sb) == -1)
         return 1;
 
@@ -134,7 +135,7 @@
 
     f = fopen(file, "r");
     if (!f)
-        die("Could not open file %s\n", file);
+        err(1, "Could not open file %s", file);
 
     i = 0;
     while (fgets(buf, sizeof buf, f)) {
@@ -141,7 +142,7 @@
         if (regexec(&usepat, buf, 2, m, 0) == REG_NOMATCH)
             continue;
         if (i == depsz)
-            die("Too many deps for file %s\n", file);
+            die("Too many deps for file %s", file);
         deps[i++] = strdupn(&buf[m[1].rm_so], m[1].rm_eo - m[1].rm_so);
     }
     *ndeps = i;
@@ -206,7 +207,7 @@
         else if (hassuffix(files[i], ".s"))
             swapsuffix(buf, sizeof buf, files[i], ".s", ".o");
         else
-            die("Unknown file type %s\n", files[i]);
+            die("Unknown file type %s", files[i]);
         lappend(&args, &nargs, strdup(buf));
     }
     lappend(&args, &nargs, NULL);
@@ -236,7 +237,7 @@
         else if (hassuffix(files[i], ".s"))
             swapsuffix(buf, sizeof buf, files[i], ".s", ".o");
         else
-            die("Unknown file type %s\n", files[i]);
+            die("Unknown file type %s", files[i]);
         lappend(&args, &nargs, strdup(buf));
     }
     lappend(&args, &nargs, NULL);
@@ -268,7 +269,7 @@
         else if (hassuffix(files[i], ".s"))
             swapsuffix(buf, sizeof buf, files[i], ".s", ".o");
         else
-            die("Unknown file type %s\n", files[i]);
+            die("Unknown file type %s", files[i]);
         lappend(&args, &nargs, strdup(buf));
     }
     lappend(&args, &nargs, strdup("-L"));