+ /* 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);
+ if(compopt != skip_argument) {
+ dbprintf(_("compress pid %ld: %s %s\n"),
+ (long)comppid, COMPRESS_PATH, compopt);
+ } else {
+ dbprintf(_("compress 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:
+ application_api_info_tapeheader(mesgfd, dle->program, dle);
+
+ /* find directt-tcp address from indirect direct-tcp */
+ if (dle->data_path == DATA_PATH_DIRECTTCP &&
+ bsu->data_path_set & DATA_PATH_DIRECTTCP &&
+ strncmp(dle->directtcp_list->data, "255.255.255.255:", 16) == 0) {
+ char *indirect_tcp;
+ char *str_port;
+ in_port_t port;
+ int fd;
+ char buffer[32770];
+ int size;
+ char *s, *s1;
+
+ indirect_tcp = g_strdup(dle->directtcp_list->data);
+ g_slist_free(dle->directtcp_list);
+ dle->directtcp_list = NULL;
+ str_port = strchr(indirect_tcp, ':');
+ str_port++;
+ port = atoi(str_port);
+ fd = stream_client("localhost", port, 32768, 32768, NULL, 0);
+ if (fd <= 0) {
+ g_debug("Failed to connect to indirect-direct-tcp port: %s",
+ strerror(errno));
+ exit(1);
+ }
+ size = full_read(fd, buffer, 32768);
+ if (size <= 0) {
+ g_debug("Failed to read from indirect-direct-tcp port: %s",
+ strerror(errno));
+ exit(1);
+ }
+ buffer[size++] = ' ';
+ buffer[size] = '\0';
+ s1 = buffer;
+ while ((s = strchr(s1, ' ')) != NULL) {
+ *s++ = '\0';
+ dle->directtcp_list = g_slist_append(dle->directtcp_list, g_strdup(s1));
+ s1 = s;
+ }
+ amfree(indirect_tcp);
+ }
+
+ argv_ptr = g_ptr_array_new();
+ cmd = vstralloc(APPLICATION_DIR, "/", dle->program, NULL);
+ g_ptr_array_add(argv_ptr, stralloc(dle->program));
+ g_ptr_array_add(argv_ptr, stralloc("backup"));
+ if (bsu->message_line == 1) {
+ g_ptr_array_add(argv_ptr, stralloc("--message"));
+ g_ptr_array_add(argv_ptr, stralloc("line"));
+ }
+ if (g_options->config && bsu->config == 1) {
+ g_ptr_array_add(argv_ptr, stralloc("--config"));
+ g_ptr_array_add(argv_ptr, stralloc(g_options->config));
+ }
+ if (g_options->hostname && bsu->host == 1) {
+ g_ptr_array_add(argv_ptr, stralloc("--host"));
+ g_ptr_array_add(argv_ptr, stralloc(g_options->hostname));
+ }
+ if (dle->disk && bsu->disk == 1) {
+ g_ptr_array_add(argv_ptr, stralloc("--disk"));
+ g_ptr_array_add(argv_ptr, stralloc(dle->disk));
+ }
+ g_ptr_array_add(argv_ptr, stralloc("--device"));
+ g_ptr_array_add(argv_ptr, stralloc(dle->device));
+ if (level <= bsu->max_level) {
+ g_ptr_array_add(argv_ptr, stralloc("--level"));
+ g_snprintf(levelstr,19,"%d",level);
+ g_ptr_array_add(argv_ptr, stralloc(levelstr));
+ }
+ if (indexfd != -1 && bsu->index_line == 1) {
+ g_ptr_array_add(argv_ptr, stralloc("--index"));
+ g_ptr_array_add(argv_ptr, stralloc("line"));
+ }
+ if (dle->record && bsu->record == 1) {
+ g_ptr_array_add(argv_ptr, stralloc("--record"));
+ }
+ application_property_add_to_argv(argv_ptr, dle, bsu,
+ g_options->features);
+
+ for (scriptlist = dle->scriptlist; scriptlist != NULL;
+ scriptlist = scriptlist->next) {
+ script = (script_t *)scriptlist->data;
+ if (script->result && script->result->proplist) {
+ property_add_to_argv(argv_ptr, script->result->proplist);
+ }
+ }
+
+ g_ptr_array_add(argv_ptr, NULL);
+ dbprintf(_("%s: running \"%s\n"), get_pname(), cmd);
+ for (j = 1; j < argv_ptr->len - 1; j++)
+ dbprintf(" %s\n", (char *)g_ptr_array_index(argv_ptr,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);
+ }
+ if (indexfd != 0) {
+ safe_fd(3, 2);
+ } else {
+ safe_fd(3, 1);
+ }
+ execve(cmd, (char **)argv_ptr->pdata, 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 (GPOINTER_TO_INT(dle->estimatelist->data) == ES_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"));