+ /* now do the client-side compression */
+ if(dle->compress == COMP_FAST || dle->compress == COMP_BEST) {
+ compopt = skip_argument;
+#if defined(COMPRESS_BEST_OPT) && defined(COMPRESS_FAST_OPT)
+ if(dle->compress == COMP_BEST) {
+ compopt = COMPRESS_BEST_OPT;
+ } else {
+ compopt = COMPRESS_FAST_OPT;
+ }
+#endif
+ comppid = pipespawn(COMPRESS_PATH, STDIN_PIPE, 0,
+ &dumpout, &compout, &mesgfd,
+ COMPRESS_PATH, compopt, NULL);
+ dbprintf(_("gnutar: pid %ld: %s"), (long)comppid, COMPRESS_PATH);
+ if(compopt != skip_argument) {
+ dbprintf(_("pid %ld: %s %s\n"),
+ (long)comppid, COMPRESS_PATH, compopt);
+ } else {
+ dbprintf(_("pid %ld: %s\n"), (long)comppid, COMPRESS_PATH);
+ }
+ } else if (dle->compress == COMP_CUST) {
+ compopt = skip_argument;
+ comppid = pipespawn(dle->compprog, STDIN_PIPE, 0,
+ &dumpout, &compout, &mesgfd,
+ dle->compprog, compopt, NULL);
+ if(compopt != skip_argument) {
+ dbprintf(_("pid %ld: %s %s\n"),
+ (long)comppid, dle->compprog, compopt);
+ } else {
+ dbprintf(_("pid %ld: %s\n"), (long)comppid, dle->compprog);
+ }
+ } else {
+ dumpout = compout;
+ comppid = -1;
+ }
+
+ cur_dumptime = time(0);
+ bsu = backup_support_option(dle->program, g_options, dle->disk,
+ dle->device, &errarray);
+ if (!bsu) {
+ char *errmsg;
+ char *qerrmsg;
+ guint i;
+ for (i=0; i < errarray->len; i++) {
+ errmsg = g_ptr_array_index(errarray, i);
+ qerrmsg = quote_string(errmsg);
+ fdprintf(mesgfd,
+ _("sendbackup: error [Application '%s': %s]\n"),
+ dle->program, errmsg);
+ dbprintf("aa: %s\n",qerrmsg);
+ amfree(qerrmsg);
+ }
+ if (i == 0) { /* no errarray */
+ errmsg = vstrallocf(_("Can't execute application '%s'"),
+ dle->program);
+ qerrmsg = quote_string(errmsg);
+ fdprintf(mesgfd, _("sendbackup: error [%s]\n"), errmsg);
+ dbprintf(_("ERROR %s\n"), qerrmsg);
+ amfree(qerrmsg);
+ amfree(errmsg);
+ }
+ return 0;
+ }
+
+ if (pipe(errfd) < 0) {
+ char *errmsg;
+ char *qerrmsg;
+ errmsg = vstrallocf(_("Application '%s': can't create pipe"),
+ dle->program);
+ qerrmsg = quote_string(errmsg);
+ fdprintf(mesgfd, _("sendbackup: error [%s]\n"), errmsg);
+ dbprintf(_("ERROR %s\n"), qerrmsg);
+ amfree(qerrmsg);
+ amfree(errmsg);
+ return 0;
+ }
+
+ switch(application_api_pid=fork()) {
+ case 0:
+ cmd = vstralloc(APPLICATION_DIR, "/", dle->program, NULL);
+ k = application_property_argv_size(dle);
+ for (scriptlist = dle->scriptlist; scriptlist != NULL;
+ scriptlist = scriptlist->next) {
+ script = (script_t *)scriptlist->data;
+ if (script->result && script->result->proplist) {
+ k += property_argv_size(script->result->proplist);
+ }
+ }
+ argvchild = g_new0(char *, 20 + k);
+ i=0;
+ argvchild[i++] = dle->program;
+ 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 (dle->disk && bsu->disk == 1) {
+ argvchild[i++] = "--disk";
+ argvchild[i++] = dle->disk;
+ }
+ argvchild[i++] = "--device";
+ argvchild[i++] = dle->device;
+ if (level <= bsu->max_level) {
+ argvchild[i++] = "--level";
+ g_snprintf(levelstr,19,"%d",level);
+ argvchild[i++] = levelstr;
+ }
+ if (indexfd != -1 && bsu->index_line == 1) {
+ argvchild[i++] = "--index";
+ argvchild[i++] = "line";
+ }
+ if (dle->record && bsu->record == 1) {
+ argvchild[i++] = "--record";
+ }
+ i += application_property_add_to_argv(&argvchild[i], dle, bsu);
+
+ for (scriptlist = dle->scriptlist; scriptlist != NULL;
+ scriptlist = scriptlist->next) {
+ script = (script_t *)scriptlist->data;
+ if (script->result && script->result->proplist) {
+ i += property_add_to_argv(&argvchild[i],
+ script->result->proplist);
+ }
+ }
+
+ argvchild[i] = NULL;
+ dbprintf(_("%s: running \"%s\n"), get_pname(), cmd);
+ for(j=1;j<i;j++) dbprintf(" %s\n",argvchild[j]);
+ dbprintf(_("\"\n"));
+ if(dup2(dumpout, 1) == -1) {
+ error(_("Can't dup2: %s"),strerror(errno));
+ /*NOTREACHED*/
+ }
+ if (dup2(errfd[1], 2) == -1) {
+ error(_("Can't dup2: %s"),strerror(errno));
+ /*NOTREACHED*/
+ }
+ if(dup2(mesgfd, 3) == -1) {
+ error(_("Can't dup2: %s"),strerror(errno));
+ /*NOTREACHED*/
+ }
+ if(indexfd > 0) {
+ if(dup2(indexfd, 4) == -1) {
+ error(_("Can't dup2: %s"),strerror(errno));
+ /*NOTREACHED*/
+ }
+ fcntl(indexfd, F_SETFD, 0);
+ }
+ application_api_info_tapeheader(mesgfd, dle->program, dle);
+ if (indexfd != 0) {
+ safe_fd(3, 2);
+ } else {
+ safe_fd(3, 1);
+ }
+ execve(cmd, argvchild, safe_env());
+ exit(1);
+ break;
+
+ default:
+ break;
+ case -1:
+ error(_("%s: fork returned: %s"), get_pname(), strerror(errno));
+ }
+
+ close(errfd[1]);
+ dumperr = fdopen(errfd[0],"r");
+ if (!dumperr) {
+ error(_("Can't fdopen: %s"), strerror(errno));
+ /*NOTREACHED*/
+ }
+
+ result = 0;
+ while ((line = agets(dumperr)) != NULL) {
+ if (strlen(line) > 0) {
+ fdprintf(mesgfd, "sendbackup: error [%s]\n", line);
+ dbprintf("error: %s\n", line);
+ result = 1;
+ }
+ amfree(line);
+ }
+
+ result |= check_result(mesgfd);
+ if (result == 0) {
+ char *amandates_file;
+
+ amandates_file = getconf_str(CNF_AMANDATES);
+ if(start_amandates(amandates_file, 1)) {
+ amandates_updateone(dle->disk, level, cur_dumptime);
+ finish_amandates();
+ free_amandates();
+ } else {
+ if (dle->calcsize && bsu->calcsize) {
+ error(_("error [opening %s for writing: %s]"),
+ amandates_file, strerror(errno));
+ } else {
+ g_debug(_("non-fatal error opening '%s' for writing: %s]"),
+ amandates_file, strerror(errno));
+ }
+ }
+ }
+ amfree(bsu);
+ } else {
+ if(!interactive) {
+ /* redirect stderr */
+ if(dup2(mesgfd, 2) == -1) {
+ dbprintf(_("Error redirecting stderr to fd %d: %s\n"),
+ 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);
+ }
+
+ program->start_backup(dle, g_options->hostname,
+ datafd, mesgpipe[1], indexfd);
+ dbprintf(_("Started backup\n"));
+ parse_backup_messages(dle, mesgpipe[0]);
+ dbprintf(_("Parsed backup messages\n"));