[darwinbuild-changes] [650] branches/PR-7461534/darwinup/Utils.cpp
source_changes at macosforge.org
source_changes at macosforge.org
Thu Dec 10 14:05:25 PST 2009
Revision: 650
http://trac.macosforge.org/projects/darwinbuild/changeset/650
Author: wsiegrist at apple.com
Date: 2009-12-10 14:05:22 -0800 (Thu, 10 Dec 2009)
Log Message:
-----------
Convert from fork/exec to posix_spawn. Print a more useful error message when spawning fails.
Modified Paths:
--------------
branches/PR-7461534/darwinup/Utils.cpp
Modified: branches/PR-7461534/darwinup/Utils.cpp
===================================================================
--- branches/PR-7461534/darwinup/Utils.cpp 2009-12-10 20:38:21 UTC (rev 649)
+++ branches/PR-7461534/darwinup/Utils.cpp 2009-12-10 22:05:22 UTC (rev 650)
@@ -29,6 +29,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <spawn.h>
#include <sys/stat.h>
extern char** environ;
@@ -123,12 +124,13 @@
pid_t pid;
int status;
- pid = fork();
- assert(pid != -1);
- if (pid == 0) {
- assert(execve(args[0], (char**)args, environ) != -1);
- // NOT REACHED
- }
+ IF_DEBUG("Spawning %s \n", args[0]);
+
+ res = posix_spawn(&pid, args[0], NULL, NULL, (char**)args, environ);
+ if (res != 0) fprintf(stderr, "Error: Failed to spawn %s: %s (%d)\n", args[0], strerror(res), res);
+
+ IF_DEBUG("Running %s on pid %d \n", args[0], (int)pid);
+
do {
res = waitpid(pid, &status, 0);
} while (res == -1 && errno == EINTR);
@@ -139,6 +141,9 @@
res = -1;
}
}
+
+ IF_DEBUG("Done running %s \n", args[0]);
+
return res;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/darwinbuild-changes/attachments/20091210/f27802b1/attachment.html>
More information about the darwinbuild-changes
mailing list