+ /* just use our stderr directly for the pipe's stderr; in
+ * main() we send stderr to the debug file, or /dev/null
+ * if debugging is disabled */
+
+ /* start the uncompress process */
+ putenv(stralloc("LC_ALL=C"));
+ pid_gzip = pipespawn(UNCOMPRESS_PATH, STDOUT_PIPE|STDERR_PIPE, 0,
+ &nullfd, &pipe_from_gzip, &uncompress_errfd,
+ UNCOMPRESS_PATH, PARAM_UNCOMPRESS_OPT,
+ filename_gz, NULL);
+ aclose(nullfd);
+
+ pipe_stream = fdopen(pipe_from_gzip,"r");
+ if(pipe_stream == NULL) {
+ msg = vstrallocf(_("Can't fdopen pipe from gzip: %s"),
+ strerror(errno));
+ dbprintf("%s\n", msg);
+ g_ptr_array_add(*emsg, msg);
+ amfree(filename);
+ aclose(indexfd);
+ return NULL;
+ }
+
+ /* start the sort process */
+ putenv(stralloc("LC_ALL=C"));
+ pid_sort = pipespawn(SORT_PATH, STDIN_PIPE|STDERR_PIPE, 0,
+ &pipe_to_sort, &indexfd, &sort_errfd,
+ SORT_PATH, NULL);
+ aclose(indexfd);
+
+ /* start a subprocess */
+ /* send all ouput from uncompress process to sort process */
+ pid_index = fork();
+ switch (pid_index) {
+ case -1:
+ msg = vstrallocf(
+ _("fork error: %s"),
+ strerror(errno));
+ dbprintf("%s\n", msg);
+ g_ptr_array_add(*emsg, msg);
+ unlink(filename);
+ amfree(filename);
+ default: break;
+ case 0:
+ while (fgets(line, STR_SIZE, pipe_stream) != NULL) {
+ if (line[0] != '\0') {
+ if (strchr(line,'/')) {
+ full_write(pipe_to_sort,line,strlen(line));
+ }
+ }
+ }
+ exit(0);
+ }
+
+ fclose(pipe_stream);
+ aclose(pipe_to_sort);
+
+ uncompress_err_stream = fdopen(uncompress_errfd, "r");
+ uncompress_err = g_ptr_array_new();
+ while (fgets(line, sizeof(line), uncompress_err_stream) != NULL) {
+ if (line[strlen(line)-1] == '\n')
+ line[strlen(line)-1] = '\0';
+ g_ptr_array_add(uncompress_err, vstrallocf(" %s", line));
+ dbprintf("Uncompress: %s\n", line);
+ }
+ fclose(uncompress_err_stream);
+
+ sort_err_stream = fdopen(sort_errfd, "r");
+ sort_err = g_ptr_array_new();
+ while (fgets(line, sizeof(line), sort_err_stream) != NULL) {
+ if (line[strlen(line)-1] == '\n')
+ line[strlen(line)-1] = '\0';
+ g_ptr_array_add(sort_err, vstrallocf(" %s", line));
+ dbprintf("Sort: %s\n", line);
+ }
+ fclose(sort_err_stream);
+
+ status = get_pid_status(pid_gzip, UNCOMPRESS_PATH, emsg);
+ if (status == 0 && filename) {
+ unlink(filename);
+ amfree(filename);
+ }
+ if (uncompress_err->len > 0) {
+ p_last = uncompress_err->pdata + uncompress_err->len;
+ for (p = uncompress_err->pdata; p < p_last ;p++) {
+ g_ptr_array_add(*emsg, (char *)*p);
+ }
+ }
+ g_ptr_array_free(uncompress_err, TRUE);
+
+ status = get_pid_status(pid_index, "index", emsg);
+ if (status == 0 && filename) {
+ unlink(filename);
+ amfree(filename);
+ }
+
+ status = get_pid_status(pid_sort, SORT_PATH, emsg);
+ if (status == 0 && filename) {
+ unlink(filename);
+ amfree(filename);
+ }
+ if (sort_err->len > 0) {
+ p_last = sort_err->pdata + sort_err->len;
+ for (p = sort_err->pdata; p < p_last ;p++) {
+ g_ptr_array_add(*emsg, (char *)*p);
+ }
+ }
+ g_ptr_array_free(sort_err, TRUE);
+