+ if(program_is_backup_api==1) {
+ pid_t backup_api_pid;
+ int i, j;
+ char *cmd=NULL;
+ char *argvchild[20];
+ char levelstr[20];
+ int property_pipe[2];
+ backup_support_option_t *bsu;
+
+ if (pipe(property_pipe) < 0) {
+ error("Can't create pipe: %s",strerror(errno));
+ /*NOTREACHED*/
+ }
+ bsu = backup_support_option(prog, g_options, disk, amdevice);
+
+ switch(backup_api_pid=fork()) {
+ case 0:
+ aclose(property_pipe[1]);
+ if(dup2(property_pipe[0], 0) == -1) {
+ error("Can't dup2: %s",strerror(errno));
+ /*NOTREACHED*/
+ }
+ if(dup2(datafd, 1) == -1) {
+ error("Can't dup2: %s",strerror(errno));
+ /*NOTREACHED*/
+ }
+ if(dup2(mesgfd, 2) == -1) {
+ error("Can't dup2: %s",strerror(errno));
+ /*NOTREACHED*/
+ }
+ if(indexfd != 0) {
+ if(dup2(indexfd, 3) == -1) {
+ error("Can't dup2: %s",strerror(errno));
+ /*NOTREACHED*/
+ }
+ fcntl(indexfd, F_SETFD, 0);
+ fcntl(3, F_SETFD, 0);
+ }
+ cmd = vstralloc(DUMPER_DIR, "/", prog, NULL);
+ i=0;
+ argvchild[i++] = prog;
+ argvchild[i++] = "backup";
+ if (bsu->message_line == 1) {
+ argvchild[i++] = "--message";
+ argvchild[i++] = "line";
+ }
+ if (g_options->config && bsu->config == 1) {
+ argvchild[i++] = "--config";
+ argvchild[i++] = g_options->config;
+ }
+ if (g_options->hostname && bsu->host == 1) {
+ argvchild[i++] = "--host";
+ argvchild[i++] = g_options->hostname;
+ }
+ if (disk && bsu->disk == 1) {
+ argvchild[i++] = "--disk";
+ argvchild[i++] = disk;
+ }
+ argvchild[i++] = "--device";
+ argvchild[i++] = amdevice;
+ if (level <= bsu->max_level) {
+ argvchild[i++] = "--level";
+ snprintf(levelstr,19,"%d",level);
+ argvchild[i++] = levelstr;
+ }
+ if (indexfd != 0 && bsu->index_line == 1) {
+ argvchild[i++] = "--index";
+ argvchild[i++] = "line";
+ }
+ if (!options->no_record && bsu->record == 1) {
+ argvchild[i++] = "--record";
+ }
+ argvchild[i] = NULL;
+ dbprintf(("%s: running \"%s", get_pname(), cmd));
+ for(j=1;j<i;j++) dbprintf((" %s",argvchild[j]));
+ dbprintf(("\"\n"));
+ backup_api_info_tapeheader(mesgfd, prog, options);
+ execve(cmd, argvchild, safe_env());
+ exit(1);
+ break;
+
+ default:
+ aclose(property_pipe[0]);
+ toolin = fdopen(property_pipe[1],"w");
+ if (!toolin) {
+ error("Can't fdopen: %s", strerror(errno));
+ /*NOTREACHED*/
+ }
+ output_tool_property(toolin, options);
+ fflush(toolin);
+ fclose(toolin);
+ break;
+ case -1:
+ error("%s: fork returned: %s", get_pname(), strerror(errno));
+ }
+ amfree(bsu);
+ if (waitpid(backup_api_pid, &status, 0) < 0) {
+ if (!WIFEXITED(status)) {
+ dbprintf(("Tool exited with signal %d", WTERMSIG(status)));
+ } else if (WEXITSTATUS(status) != 0) {
+ dbprintf(("Tool exited with status %d", WEXITSTATUS(status)));
+ } else {
+ dbprintf(("waitpid returned negative value"));
+ }
+ }
+ }
+ else {
+ if(!interactive) {
+ /* redirect stderr */
+ if(dup2(mesgfd, 2) == -1) {
+ dbprintf(("%s: error redirecting stderr to fd %d: %s\n",
+ debug_prefix_time(NULL), mesgfd, strerror(errno)));
+ dbclose();
+ exit(1);
+ }
+ }
+
+ if(pipe(mesgpipe) == -1) {
+ s = strerror(errno);
+ dbprintf(("error [opening mesg pipe: %s]\n", s));
+ error("error [opening mesg pipe: %s]", s);
+ }