+ if (threads && thread == 0) { /* parent process */
+ int live_threads = threads;
+
+ while (live_threads > 0) {
+ int status;
+ pid_t ret;
+
+ ret = waitpid(0, &status, 0);
+ if (ret == 0)
+ continue;
+
+ if (ret < 0) {
+ if (!rc)
+ rc = errno;
+ fprintf(stderr, "error: %s: wait - %s\n",
+ argv[0], strerror(rc));
+ } else {
+ /*
+ * This is a hack. We _should_ be able to use
+ * WIFEXITED(status) to see if there was an
+ * error, but it appears to be broken and it
+ * always returns 1 (OK). See wait(2).
+ */
+ int err = WEXITSTATUS(status);
+ if (err || WIFSIGNALED(status))
+ fprintf(stderr,
+ "%s: PID %d had rc=%d\n",
+ argv[0], ret, err);
+ if (!rc)
+ rc = err;
+ }
+ live_threads--;
+ }
+ } else {
+ if (threads)
+ sprintf(filename, "%s-%d", argv[1], thread);
+ else
+ strcpy(filename, argv[1]);
+
+ fd = open(filename, O_RDWR|O_CREAT, 0644);