Imported Upstream version 3.3.0
[debian/amanda] / client-src / sendbackup.c
index 9cfa39732d122407a17560461fb5338ea52fe63f..781dedb4b3cf055fca5a28b9363bb453a0767e11 100644 (file)
  */
 
 #include "amanda.h"
+#include "match.h"
 #include "sendbackup.h"
 #include "clock.h"
 #include "pipespawn.h"
 #include "amfeatures.h"
-#include "amandad.h"
 #include "arglist.h"
 #include "getfsent.h"
-#include "version.h"
 #include "conffile.h"
+#include "amandates.h"
 
-#define sendbackup_debug(i,x) do {     \
+#define sendbackup_debug(i, ...) do {  \
        if ((i) <= debug_sendbackup) {  \
-           dbprintf(x);                \
+           dbprintf(__VA_LIST__);      \
        }                               \
 } while (0)
 
@@ -53,18 +53,19 @@ pid_t dumppid = (pid_t)-1;
 pid_t tarpid = (pid_t)-1;
 pid_t encpid = (pid_t)-1;
 pid_t indexpid = (pid_t)-1;
+pid_t application_api_pid = (pid_t)-1;
 char *errorstr = NULL;
 
 int datafd;
 int mesgfd;
 int indexfd;
 
-option_t *options;
 g_option_t *g_options = NULL;
 
 long dump_size = -1;
 
 backup_program_t *program = NULL;
+dle_t *gdle = NULL;
 
 static am_feature_t *our_features = NULL;
 static char *our_feature_string = NULL;
@@ -72,110 +73,38 @@ static char *amandad_auth = NULL;
 
 /* local functions */
 int main(int argc, char **argv);
-char *optionstr(option_t *options);
 char *childstr(pid_t pid);
-int check_status(pid_t pid, amwait_t w);
+int check_status(pid_t pid, amwait_t w, int mesgfd);
 
 pid_t pipefork(void (*func)(void), char *fname, int *stdinfd,
                int stdoutfd, int stderrfd);
-void parse_backup_messages(int mesgin);
+int check_result(int mesgfd);
+void parse_backup_messages(dle_t *dle, int mesgin);
 static void process_dumpline(char *str);
 static void save_fd(int *, int);
-void backup_api_info_tapeheader(int mesgfd, char *prog, option_t *options);
+void application_api_info_tapeheader(int mesgfd, char *prog, dle_t *dle);
 
-double the_num(char *str, int pos);
+int fdprintf(int fd, char *format, ...) G_GNUC_PRINTF(2, 3);
 
-
-char *
-optionstr(
-    option_t * options)
+int
+fdprintf(
+    int   fd,
+    char *format,
+    ...)
 {
-    static char *optstr = NULL;
-    char *compress_opt;
-    char *encrypt_opt;
-    char *decrypt_opt;
-    char *record_opt = "";
-    char *index_opt = "";
-    char *auth_opt;
-    char *exclude_file_opt;
-    char *exclude_list_opt;
-    char *exc = NULL;
-    sle_t *excl;
-
-    if(options->compress == COMP_BEST)
-       compress_opt = stralloc("compress-best;");
-    else if(options->compress == COMP_FAST)
-       compress_opt = stralloc("compress-fast;");
-    else if(options->compress == COMP_SERVER_BEST)
-       compress_opt = stralloc("srvcomp-best;");
-    else if(options->compress == COMP_SERVER_FAST)
-       compress_opt = stralloc("srvcomp-fast;");
-    else if(options->compress == COMP_SERVER_CUST)
-       compress_opt = vstralloc("srvcomp-cust=", options->srvcompprog, ";", NULL);
-    else if(options->compress == COMP_CUST)
-       compress_opt = vstralloc("comp-cust=", options->clntcompprog, ";", NULL);
-    else
-       compress_opt = stralloc("");
-    
-    if(options->encrypt == ENCRYPT_CUST) {
-      encrypt_opt = vstralloc("encrypt-cust=", options->clnt_encrypt, ";", NULL);
-      if (options->clnt_decrypt_opt)
-       decrypt_opt = vstralloc("client-decrypt-option=", options->clnt_decrypt_opt, ";", NULL);
-      else
-       decrypt_opt = stralloc("");
-    }
-    else if(options->encrypt == ENCRYPT_SERV_CUST) {
-      encrypt_opt = vstralloc("encrypt-serv-cust=", options->srv_encrypt, ";", NULL);
-      if(options->srv_decrypt_opt)
-       decrypt_opt = vstralloc("server-decrypt-option=", options->srv_decrypt_opt, ";", NULL);
-      else
-       decrypt_opt = stralloc("");
-    }
-    else {
-       encrypt_opt = stralloc("");
-       decrypt_opt = stralloc("");
-    }
+    va_list  argp;
+    char    *s;
+    int      r;
 
-    if(options->no_record) record_opt = "no-record;";
-    if(options->auth) auth_opt = vstralloc("auth=", options->auth, ";", NULL);
-       else auth_opt = stralloc("");
-    if(options->createindex) index_opt = "index;";
+    arglist_start(argp, format);
+    s = g_strdup_vprintf(format, argp);
+    arglist_end(argp);
 
-    exclude_file_opt = stralloc("");
-    if(options->exclude_file) {
-       for(excl = options->exclude_file->first; excl != NULL; excl=excl->next){
-           exc = newvstralloc(exc, "exclude-file=", excl->name, ";", NULL);
-           strappend(exclude_file_opt, exc);
-       }
-    }
-    exclude_list_opt = stralloc("");
-    if(options->exclude_list) {
-       for(excl = options->exclude_list->first; excl != NULL; excl=excl->next){
-           exc = newvstralloc(exc, "exclude-list=", excl->name, ";", NULL);
-           strappend(exclude_list_opt, exc);
-       }
-    }
-    amfree(exc);
-    optstr = newvstralloc(optstr,
-                         compress_opt,
-                         encrypt_opt,
-                         decrypt_opt,
-                         record_opt,
-                         index_opt,
-                         auth_opt,
-                         exclude_file_opt,
-                         exclude_list_opt,
-                         NULL);
-    amfree(compress_opt);
-    amfree(encrypt_opt);
-    amfree(decrypt_opt);
-    amfree(auth_opt);
-    amfree(exclude_file_opt);
-    amfree(exclude_list_opt);
-    return optstr;
+    r = full_write(fd, s, strlen(s));
+    amfree(s);
+    return r;
 }
 
-
 int
 main(
     int                argc,
@@ -184,26 +113,31 @@ main(
     int interactive = 0;
     int level = 0;
     int mesgpipe[2];
-    char *prog, *dumpdate, *stroptions;
-    int program_is_backup_api;
-    char *disk = NULL;
+    dle_t *dle = NULL;
+    char *dumpdate, *stroptions;
     char *qdisk = NULL;
-    char *amdevice = NULL;
     char *qamdevice = NULL;
     char *line = NULL;
     char *err_extra = NULL;
     char *s;
-    char *conffile;
     int i;
     int ch;
-    unsigned long malloc_hist_1, malloc_size_1;
-    unsigned long malloc_hist_2, malloc_size_2;
-    FILE *toolin;
-    int status;
+    GSList *errlist;
+    FILE   *mesgstream;
+    level_t *alevel;
 
     /* initialize */
+    /*
+     * Configure program for internationalization:
+     *   1) Only set the message locale for now.
+     *   2) Set textdomain for all amanda related programs to "amanda"
+     *      We don't want to be forced to support dozens of message catalogs.
+     */  
+    setlocale(LC_MESSAGES, "C");
+    textdomain("amanda"); 
 
     safe_fd(DATA_FD_OFFSET, DATA_FD_COUNT*2);
+    openbsd_fd_inform();
 
     safe_cd();
 
@@ -215,8 +149,6 @@ main(
     /* Don't die when interrupt received */
     signal(SIGINT, SIG_IGN);
 
-    malloc_size_1 = malloc_inuse(&malloc_hist_1);
-
     if(argc > 1 && strcmp(argv[1],"-t") == 0) {
        interactive = 1;
        argc--;
@@ -225,10 +157,11 @@ main(
        interactive = 0;
     }
 
-    erroutput_type = (ERR_INTERACTIVE|ERR_SYSLOG);
+    add_amanda_log_handler(amanda_log_stderr);
+    add_amanda_log_handler(amanda_log_syslog);
     dbopen(DBG_SUBDIR_CLIENT);
     startclock();
-    dbprintf(("%s: version %s\n", get_pname(), version()));
+    dbprintf(_("Version %s\n"), VERSION);
 
     if(argc > 2 && strcmp(argv[1], "amandad") == 0) {
        amandad_auth = stralloc(argv[2]);
@@ -237,12 +170,10 @@ main(
     our_features = am_init_feature_set();
     our_feature_string = am_feature_to_string(our_features);
 
-    conffile = vstralloc(CONFIG_DIR, "/", "amanda-client.conf", NULL);
-    if (read_clientconf(conffile) > 0) {
-       error("error reading conffile: %s", conffile);
-       /*NOTREACHED*/
-    }
-    amfree(conffile);
+    config_init(CONFIG_INIT_CLIENT, NULL);
+    /* (check for config errors comes later) */
+
+    check_running_as(RUNNING_AS_CLIENT_LOGIN);
 
     if(interactive) {
        /*
@@ -251,23 +182,19 @@ main(
         * programs on the tape host are set up.  The index service is
         * run and goes to stdout.
         */
-       fprintf(stderr, "%s: running in interactive test mode\n", get_pname());
+       g_fprintf(stderr, _("%s: running in interactive test mode\n"), get_pname());
        fflush(stderr);
     }
 
-    prog = NULL;
-    disk = NULL;
     qdisk = NULL;
-    amdevice = NULL;
     dumpdate = NULL;
     stroptions = NULL;
-    program_is_backup_api=0;
 
     for(; (line = agets(stdin)) != NULL; free(line)) {
        if (line[0] == '\0')
            continue;
        if(interactive) {
-           fprintf(stderr, "%s> ", get_pname());
+           g_fprintf(stderr, "%s> ", get_pname());
            fflush(stderr);
        }
        if(strncmp_const(line, "OPTIONS ") == 0) {
@@ -279,95 +206,106 @@ main(
            }
 
            if (g_options->config) {
-               conffile = vstralloc(CONFIG_DIR, "/", g_options->config, "/",
-                                    "amanda-client.conf", NULL);
-               if (read_clientconf(conffile) > 0) {
-                   error("error reading conffile: %s", conffile);
-                   /*NOTREACHED*/
-               }
-               amfree(conffile);
+               /* overlay this configuration on the existing (nameless) configuration */
+               config_init(CONFIG_INIT_CLIENT | CONFIG_INIT_EXPLICIT_NAME | CONFIG_INIT_OVERLAY,
+                           g_options->config);
 
-               dbrename(g_options->config, DBG_SUBDIR_CLIENT);
+               dbrename(get_config_name(), DBG_SUBDIR_CLIENT);
+           }
+
+           /* check for any config errors now */
+           if (config_errors(&errlist) >= CFGERR_ERRORS) {
+               char *errstr = config_errors_to_error_string(errlist);
+               g_printf("%s\n", errstr);
+               dbclose();
+               return 1;
+           }
+
+           if (am_has_feature(g_options->features, fe_req_xml)) {
+               break;
            }
            continue;
        }
 
-       if (prog != NULL) {
-           err_extra = "multiple requests";
+       if (dle && dle->program != NULL) {
+           err_extra = _("multiple requests");
            goto err;
        }
 
-       dbprintf(("  sendbackup req: <%s>\n", line));
+       dbprintf(_("  sendbackup req: <%s>\n"), line);
+       dle = alloc_dle();
+
        s = line;
        ch = *s++;
 
        skip_whitespace(s, ch);                 /* find the program name */
        if(ch == '\0') {
-           err_extra = "no program name";
+           err_extra = _("no program name");
            goto err;                           /* no program name */
        }
-       prog = s - 1;
+       dle->program = s - 1;
        skip_non_whitespace(s, ch);
        s[-1] = '\0';
 
-       if(strcmp(prog,"BACKUP")==0) {
-           program_is_backup_api=1;
-           skip_whitespace(s, ch);             /* find dumper name */
-           if (ch == '\0') {
-               goto err;                       /* no program */
-           }
-           prog = s - 1;
-           skip_non_whitespace(s, ch);
-           s[-1] = '\0';
-       }
-       prog = stralloc(prog);
+        if (strcmp(dle->program, "APPLICATION")==0) {
+            dle->program_is_application_api=1;
+            skip_whitespace(s, ch);             /* find dumper name */
+            if (ch == '\0') {
+                goto err;                       /* no program */
+            }
+            dle->program = s - 1;
+            skip_non_whitespace(s, ch);
+            s[-1] = '\0';
+        }
+       dle->program = stralloc(dle->program);
 
        skip_whitespace(s, ch);                 /* find the disk name */
        if(ch == '\0') {
-           err_extra = "no disk name";
+           err_extra = _("no disk name");
            goto err;                           /* no disk name */
        }
 
-       amfree(disk);
        amfree(qdisk);
        qdisk = s - 1;
        ch = *qdisk;
        skip_quoted_string(s, ch);
        s[-1] = '\0';
        qdisk = stralloc(qdisk);
-       disk = unquote_string(qdisk);
+       dle->disk = unquote_string(qdisk);
 
        skip_whitespace(s, ch);                 /* find the device or level */
        if (ch == '\0') {
-           err_extra = "bad level";
+           err_extra = _("bad level");
            goto err;
        }
 
        if(!isdigit((int)s[-1])) {
-           amfree(amdevice);
            amfree(qamdevice);
            qamdevice = s - 1;
            ch = *qamdevice;
            skip_quoted_string(s, ch);
            s[-1] = '\0';
            qamdevice = stralloc(qamdevice);
-           amdevice = unquote_string(qamdevice);
+           dle->device = unquote_string(qamdevice);
            skip_whitespace(s, ch);             /* find level number */
        }
        else {
-           amdevice = stralloc(disk);
+           dle->device = stralloc(dle->disk);
            qamdevice = stralloc(qdisk);
        }
                                                /* find the level number */
        if(ch == '\0' || sscanf(s - 1, "%d", &level) != 1) {
-           err_extra = "bad level";
+           err_extra = _("bad level");
            goto err;                           /* bad level */
        }
        skip_integer(s, ch);
+       alevel = g_new0(level_t, 1);
+       alevel->level = level;
+       dle->levellist = g_slist_append(dle->levellist, alevel);
 
        skip_whitespace(s, ch);                 /* find the dump date */
        if(ch == '\0') {
-           err_extra = "no dumpdate";
+           err_extra = _("no dumpdate");
            goto err;                           /* no dumpdate */
        }
        amfree(dumpdate);
@@ -378,100 +316,144 @@ main(
 
        skip_whitespace(s, ch);                 /* find the options keyword */
        if(ch == '\0') {
-           err_extra = "no options";
+           err_extra = _("no options");
            goto err;                           /* no options */
        }
        if(strncmp_const_skip(s - 1, "OPTIONS ", s, ch) != 0) {
-           err_extra = "no OPTIONS keyword";
+           err_extra = _("no OPTIONS keyword");
            goto err;                           /* no options */
        }
        skip_whitespace(s, ch);                 /* find the options string */
        if(ch == '\0') {
-           err_extra = "bad options string";
+           err_extra = _("bad options string");
            goto err;                           /* no options */
        }
        amfree(stroptions);
        stroptions = stralloc(s - 1);
     }
     amfree(line);
+    if (g_options == NULL) {
+       g_printf(_("ERROR [Missing OPTIONS line in sendbackup input]\n"));
+       error(_("Missing OPTIONS line in sendbackup input\n"));
+       /*NOTREACHED*/
+    }
+
+    if (am_has_feature(g_options->features, fe_req_xml)) {
+       char *errmsg = NULL;
 
-    if (prog       == NULL ||
-       disk       == NULL ||
-       amdevice   == NULL ||
-       dumpdate   == NULL ||
-       stroptions == NULL) {
-       err_extra = "no valid sendbackup request";
+       dle = amxml_parse_node_FILE(stdin, &errmsg);
+       if (errmsg) {
+           err_extra = errmsg;
+           goto err;
+       }
+       if (!dle) {
+           err_extra = _("One DLE required");
+           goto err;
+       } else if (dle->next) {
+           err_extra = _("Only one DLE allowed");
+           goto err;
+       }
+
+       qdisk = quote_string(dle->disk);
+       if (dle->device == NULL)
+           dle->device = stralloc(dle->disk);
+       qamdevice = quote_string(dle->device);
+       dumpdate = stralloc("NODATE");
+       stroptions = stralloc("");
+    } else {
+       parse_options(stroptions, dle, g_options->features, 0);
+    }
+    gdle = dle;
+
+    if (dle->program   == NULL ||
+       dle->disk      == NULL ||
+       dle->device    == NULL ||
+       dle->levellist == NULL ||
+       dumpdate       == NULL) {
+       err_extra = _("no valid sendbackup request");
        goto err;
     }
-       
-    dbprintf(("  parsed request as: program `%s'\n", prog));
-    dbprintf(("                     disk `%s'\n", qdisk));
-    dbprintf(("                     device `%s'\n", qamdevice));
-    dbprintf(("                     level %d\n", level));
-    dbprintf(("                     since %s\n", dumpdate));
-    dbprintf(("                     options `%s'\n", stroptions));
-
-    if(program_is_backup_api==1) {
-       /* check that the backup_api exist */
+
+    if (g_slist_length(dle->levellist) != 1) {
+       err_extra = _("Too many level");
+       goto err;
     }
-    else {
+
+    alevel = (level_t *)dle->levellist->data;
+    level = alevel->level;
+    dbprintf(_("  Parsed request as: program `%s'\n"), dle->program);
+    dbprintf(_("                     disk `%s'\n"), qdisk);
+    dbprintf(_("                     device `%s'\n"), qamdevice);
+    dbprintf(_("                     level %d\n"), level);
+    dbprintf(_("                     since %s\n"), dumpdate);
+    dbprintf(_("                     options `%s'\n"), stroptions);
+    dbprintf(_("                     datapath `%s'\n"),
+                           data_path_to_string(dle->data_path));
+
+    if (dle->program_is_application_api==1) {
+       /* check that the application_api exist */
+    } else {
        for(i = 0; programs[i]; i++) {
-           if (strcmp(programs[i]->name, prog) == 0) {
+           if (strcmp(programs[i]->name, dle->program) == 0) {
                break;
            }
        }
        if (programs[i] == NULL) {
-           dbprintf(("ERROR [%s: unknown program %s]\n", get_pname(), prog));
-           error("ERROR [%s: unknown program %s]", get_pname(), prog);
+           dbprintf(_("ERROR [%s: unknown program %s]\n"), get_pname(),
+                    dle->program);
+           error(_("ERROR [%s: unknown program %s]"), get_pname(),
+                 dle->program);
            /*NOTREACHED*/
        }
        program = programs[i];
     }
 
-    options = parse_options(stroptions, disk, amdevice, g_options->features, 0);
-
     if(!interactive) {
        datafd = DATA_FD_OFFSET + 0;
        mesgfd = DATA_FD_OFFSET + 2;
        indexfd = DATA_FD_OFFSET + 4;
     }
-    if (!options->createindex)
+    if (!dle->create_index)
        indexfd = -1;
 
-    if(options->auth && amandad_auth) {
-       if(strcasecmp(options->auth, amandad_auth) != 0) {
-           printf("ERROR [client configured for auth=%s while server requested '%s']\n",
-                  amandad_auth, options->auth);
+    if (dle->auth && amandad_auth) {
+       if(strcasecmp(dle->auth, amandad_auth) != 0) {
+           g_printf(_("ERROR [client configured for auth=%s while server requested '%s']\n"),
+                  amandad_auth, dle->auth);
            exit(-1);
        }
     }
 
-    printf("CONNECT DATA %d MESG %d INDEX %d\n",
+    if (dle->kencrypt) {
+       g_printf("KENCRYPT\n");
+    }
+
+    g_printf(_("CONNECT DATA %d MESG %d INDEX %d\n"),
           DATA_FD_OFFSET, DATA_FD_OFFSET+1,
           indexfd == -1 ? -1 : DATA_FD_OFFSET+2);
-    printf("OPTIONS ");
+    g_printf(_("OPTIONS "));
     if(am_has_feature(g_options->features, fe_rep_options_features)) {
-       printf("features=%s;", our_feature_string);
+       g_printf("features=%s;", our_feature_string);
     }
     if(am_has_feature(g_options->features, fe_rep_options_hostname)) {
-       printf("hostname=%s;", g_options->hostname);
+       g_printf("hostname=%s;", g_options->hostname);
     }
-    if(am_has_feature(g_options->features, fe_rep_options_sendbackup_options)) {
-       printf("%s", optionstr(options));
+    if (!am_has_feature(g_options->features, fe_rep_options_features) &&
+       !am_has_feature(g_options->features, fe_rep_options_hostname)) {
+       g_printf(";");
     }
-    printf("\n");
+    g_printf("\n");
     fflush(stdout);
     if (freopen("/dev/null", "w", stdout) == NULL) {
-       dbprintf(("%s: error redirecting stdout to /dev/null: %s\n",
-           debug_prefix_time(NULL), strerror(errno)));
+       dbprintf(_("Error redirecting stdout to /dev/null: %s\n"),
+                strerror(errno));
         exit(1);
     }
 
     if(interactive) {
       if((datafd = open("/dev/null", O_RDWR)) < 0) {
-       s = strerror(errno);
-       error("ERROR [%s: open of /dev/null for debug data stream: %s]\n",
-                 get_pname(), s);
+       error(_("ERROR [open of /dev/null for debug data stream: %s]\n"),
+               strerror(errno));
        /*NOTREACHED*/
       }
       mesgfd = 2;
@@ -479,124 +461,255 @@ main(
     }
 
     if(!interactive) {
-      if(datafd == -1 || mesgfd == -1 || (options->createindex && indexfd == -1)) {
+      if(datafd == -1 || mesgfd == -1 || (dle->create_index && indexfd == -1)) {
         dbclose();
         exit(1);
       }
     }
 
-    if(program_is_backup_api==1) {
-       pid_t backup_api_pid;
-       int i, j;
+    if (merge_dles_properties(dle, 1) == 0) {
+       g_debug("merge_dles_properties failed");
+       exit(1);
+    }
+    mesgstream = fdopen(mesgfd,"w");
+    run_client_scripts(EXECUTE_ON_PRE_DLE_BACKUP, g_options, dle, mesgstream);
+    fflush(mesgstream);
+
+    if (dle->program_is_application_api==1) {
+       guint j;
        char *cmd=NULL;
-       char *argvchild[20];
+       GPtrArray *argv_ptr;
        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*/
+       char *compopt = NULL;
+       char *encryptopt = skip_argument;
+       int compout, dumpout;
+       GSList    *scriptlist;
+       script_t  *script;
+       time_t     cur_dumptime;
+       int        result;
+       GPtrArray *errarray;
+       int        errfd[2];
+       FILE      *dumperr;
+
+       /*  apply client-side encryption here */
+       if ( dle->encrypt == ENCRYPT_CUST ) {
+           encpid = pipespawn(dle->clnt_encrypt, STDIN_PIPE, 0,
+                              &compout, &datafd, &mesgfd,
+                              dle->clnt_encrypt, encryptopt, NULL);
+           dbprintf(_("encrypt: pid %ld: %s\n"), (long)encpid, dle->clnt_encrypt);
+       } else {
+           compout = datafd;
+           encpid = -1;
        }
-       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*/
+       /*  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;
            }
-           if(dup2(datafd, 1) == -1) {
-               error("Can't dup2: %s",strerror(errno));
-               /*NOTREACHED*/
+#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);
            }
-           if(dup2(mesgfd, 2) == -1) {
-               error("Can't dup2: %s",strerror(errno));
-               /*NOTREACHED*/
+       } 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);
            }
-           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);
+       } 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);
            }
-           cmd = vstralloc(DUMPER_DIR, "/", prog, NULL);
-           i=0;
-           argvchild[i++] = prog;
-           argvchild[i++] = "backup";
+           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:
+           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) {
-               argvchild[i++] = "--message";
-               argvchild[i++] = "line";
+               g_ptr_array_add(argv_ptr, stralloc("--message"));
+               g_ptr_array_add(argv_ptr, stralloc("line"));
            }
            if (g_options->config && bsu->config == 1) {
-               argvchild[i++] = "--config";
-               argvchild[i++] = g_options->config;
+               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) {
-               argvchild[i++] = "--host";
-               argvchild[i++] = g_options->hostname;
+               g_ptr_array_add(argv_ptr, stralloc("--host"));
+               g_ptr_array_add(argv_ptr, stralloc(g_options->hostname));
            }
-           if (disk && bsu->disk == 1) {
-               argvchild[i++] = "--disk";
-               argvchild[i++] = disk;
+           if (dle->disk && bsu->disk == 1) {
+               g_ptr_array_add(argv_ptr, stralloc("--disk"));
+               g_ptr_array_add(argv_ptr, stralloc(dle->disk));
            }
-           argvchild[i++] = "--device";
-           argvchild[i++] = amdevice;
+           g_ptr_array_add(argv_ptr, stralloc("--device"));
+           g_ptr_array_add(argv_ptr, stralloc(dle->device));
            if (level <= bsu->max_level) {
-               argvchild[i++] = "--level";
-               snprintf(levelstr,19,"%d",level);
-               argvchild[i++] = levelstr;
+               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 && bsu->index_line == 1) {
-               argvchild[i++] = "--index";
-               argvchild[i++] = "line";
+           if(indexfd > 0) {
+               if(dup2(indexfd, 4) == -1) {
+                   error(_("Can't dup2: %s"),strerror(errno));
+                   /*NOTREACHED*/
+               }
+               fcntl(indexfd, F_SETFD, 0);
            }
-           if (!options->no_record && bsu->record == 1) {
-               argvchild[i++] = "--record";
+           application_api_info_tapeheader(mesgfd, dle->program, dle);
+           if (indexfd != 0) {
+               safe_fd(3, 2);
+           } else {
+               safe_fd(3, 1);
            }
-           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());
+           execve(cmd, (char **)argv_ptr->pdata, 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));
+           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)));
+
+       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 {
-               dbprintf(("waitpid returned negative value"));
+               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));
+               }
            }
        }
-     }
-    else {
+       amfree(bsu);
+     } 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)));
+               dbprintf(_("Error redirecting stderr to fd %d: %s\n"),
+                        mesgfd, strerror(errno));
                dbclose();
                exit(1);
            }
@@ -604,49 +717,48 @@ main(
  
        if(pipe(mesgpipe) == -1) {
            s = strerror(errno);
-           dbprintf(("error [opening mesg pipe: %s]\n", s));
-           error("error [opening mesg pipe: %s]", s);
+           dbprintf(_("error [opening mesg pipe: %s]\n"), s);
+           error(_("error [opening mesg pipe: %s]"), s);
        }
 
-       program->start_backup(g_options->hostname, disk, amdevice, level,
-                             dumpdate, datafd, mesgpipe[1], indexfd);
-       dbprintf(("%s: started backup\n", debug_prefix_time(NULL)));
-       parse_backup_messages(mesgpipe[0]);
-       dbprintf(("%s: parsed backup messages\n", debug_prefix_time(NULL)));
+       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"));
     }
 
-    amfree(prog);
-    amfree(disk);
+    run_client_scripts(EXECUTE_ON_POST_DLE_BACKUP, g_options, dle, mesgstream);
+    fflush(mesgstream);
+
     amfree(qdisk);
-    amfree(amdevice);
     amfree(qamdevice);
     amfree(dumpdate);
     amfree(stroptions);
     amfree(our_feature_string);
     am_release_feature_set(our_features);
     our_features = NULL;
-    am_release_feature_set(g_options->features);
-    g_options->features = NULL;
-    amfree(g_options->hostname);
-    amfree(g_options->str);
-    amfree(g_options);
+    free_g_options(g_options);
 
     dbclose();
 
-    malloc_size_2 = malloc_inuse(&malloc_hist_2);
+    return 0;
 
-    if(malloc_size_1 != malloc_size_2) {
-       malloc_list(fileno(stderr), malloc_hist_1, malloc_hist_2);
+ err:
+    if (err_extra) {
+       g_printf(_("ERROR FORMAT ERROR IN REQUEST PACKET '%s'\n"), err_extra);
+       dbprintf(_("REQ packet is bogus: %s\n"), err_extra);
+    } else {
+       g_printf(_("ERROR FORMAT ERROR IN REQUEST PACKET\n"));
+       dbprintf(_("REQ packet is bogus\n"));
     }
 
-    return 0;
+    amfree(qdisk);
+    amfree(qamdevice);
+    amfree(dumpdate);
+    amfree(stroptions);
+    amfree(our_feature_string);
 
- err:
-    printf("FORMAT ERROR IN REQUEST PACKET\n");
-    dbprintf(("%s: REQ packet is bogus%s%s\n",
-             debug_prefix_time(NULL),
-             err_extra ? ": " : "",
-             err_extra ? err_extra : ""));
     dbclose();
     return 1;
 }
@@ -665,6 +777,13 @@ childstr(
     if(pid == comppid) return "compress";
     if(pid == encpid) return "encrypt";
     if(pid == indexpid) return "index";
+    if(pid == application_api_pid) {
+       if (!gdle) {
+           dbprintf("gdle == NULL\n");
+           return "gdle == NULL";
+       }
+       return gdle->program;
+    }
     return "unknown";
 }
 
@@ -678,13 +797,12 @@ childstr(
 int
 check_status(
     pid_t      pid,
-    amwait_t   w)
+    amwait_t   w,
+    int                mesgfd)
 {
     char *thiserr = NULL;
     char *str, *strX;
     int ret, sig, rc;
-    char number[NUM_STR_SIZE];
-    char numberpid[NUM_STR_SIZE];
 
     str = childstr(pid);
 
@@ -703,11 +821,11 @@ check_status(
         * but the failure is noted.
         */
        if(ret != 0) {
-           fprintf(stderr, "? index %s returned %d\n", str, ret);
+           fdprintf(mesgfd, _("? index %s returned %d\n"), str, ret);
            rc = 0;
        }
        indexpid = -1;
-       strX = "index ";
+       strX = "index";
     } else if(pid == comppid) {
        /*
         * compress returns 2 sometimes, but it is ok.
@@ -718,7 +836,7 @@ check_status(
        }
 #endif
        comppid = -1;
-       strX = "compress ";
+       strX = "compress";
     } else if(pid == dumppid && tarpid == -1) {
         /*
         * Ultrix dump returns 1 sometimes, but it is ok.
@@ -729,7 +847,7 @@ check_status(
        }
 #endif
        dumppid = -1;
-       strX = "dump ";
+       strX = "dump";
     } else if(pid == tarpid) {
        if (ret == 1) {
            rc = 0;
@@ -743,27 +861,28 @@ check_status(
        }
 #endif
        dumppid = tarpid = -1;
-       strX = "dump ";
+       strX = "dump";
+    } else if(pid == application_api_pid) {
+       strX = "Application";
     } else {
-       strX = "unknown ";
+       strX = "unknown";
     }
 
     if(rc == 0) {
        return 0;                               /* normal exit */
     }
 
-    snprintf(numberpid, SIZEOF(number), "%d", (int)pid);
     if(ret == 0) {
-       snprintf(number, SIZEOF(number), "%d", sig);
-       thiserr = vstralloc(strX, "(", numberpid, ") ", str, " got signal ", number, NULL);
+       thiserr = vstrallocf(_("%s (%d) %s got signal %d"), strX, (int)pid, str,
+                            sig);
     } else {
-       snprintf(number, SIZEOF(number), "%d", ret);
-       thiserr = vstralloc(strX, "(", numberpid, ") ", str, " returned ", number, NULL);
+       thiserr = vstrallocf(_("%s (%d) %s returned %d"), strX, (int)pid, str, ret);
     }
 
+    fdprintf(mesgfd, "? %s\n", thiserr);
+
     if(errorstr) {
-       strappend(errorstr, ", ");
-       strappend(errorstr, thiserr);
+       errorstr =  newvstrallocf(errorstr, "%s, %s", errorstr, thiserr);
        amfree(thiserr);
     } else {
        errorstr = thiserr;
@@ -777,13 +896,14 @@ check_status(
  *Send header info to the message file.
  */
 void
-info_tapeheader(void)
+info_tapeheader(
+    dle_t *dle)
 {
-    fprintf(stderr, "%s: info BACKUP=%s\n", get_pname(), program->backup_name);
+    g_fprintf(stderr, "%s: info BACKUP=%s\n", get_pname(), program->backup_name);
 
-    fprintf(stderr, "%s: info RECOVER_CMD=", get_pname());
-    if (options->compress == COMP_FAST || options->compress == COMP_BEST)
-       fprintf(stderr, "%s %s |", UNCOMPRESS_PATH,
+    g_fprintf(stderr, "%s: info RECOVER_CMD=", get_pname());
+    if (dle->compress == COMP_FAST || dle->compress == COMP_BEST)
+       g_fprintf(stderr, "%s %s |", UNCOMPRESS_PATH,
 #ifdef UNCOMPRESS_OPT
                UNCOMPRESS_OPT
 #else
@@ -791,72 +911,73 @@ info_tapeheader(void)
 #endif
                );
 
-    fprintf(stderr, "%s -xpGf - ...\n", program->restore_name);
+    g_fprintf(stderr, "%s -xpGf - ...\n", program->restore_name);
 
-    if (options->compress == COMP_FAST || options->compress == COMP_BEST)
-       fprintf(stderr, "%s: info COMPRESS_SUFFIX=%s\n",
+    if (dle->compress == COMP_FAST || dle->compress == COMP_BEST)
+       g_fprintf(stderr, "%s: info COMPRESS_SUFFIX=%s\n",
                        get_pname(), COMPRESS_SUFFIX);
 
-    fprintf(stderr, "%s: info end\n", get_pname());
+    g_fprintf(stderr, "%s: info end\n", get_pname());
 }
 
 void
-backup_api_info_tapeheader(
+application_api_info_tapeheader(
     int       mesgfd,
     char     *prog,
-    option_t *options)
+    dle_t *dle)
 {
     char line[1024];
 
-    snprintf(line, 1024, "%s: info BACKUP=DUMPER\n", get_pname());
-    if (fullwrite(mesgfd, line, strlen(line)) != (ssize_t)strlen(line)) {
-       dbprintf(("error writing to mesgfd socket: %s", strerror(errno)));
+    g_snprintf(line, 1024, "%s: info BACKUP=APPLICATION\n", get_pname());
+    if (full_write(mesgfd, line, strlen(line)) != strlen(line)) {
+       dbprintf(_("error writing to mesgfd socket: %s"), strerror(errno));
        return;
     }
 
-    snprintf(line, 1024, "%s: info DUMPER=%s\n", get_pname(), prog);
-    if (fullwrite(mesgfd, line, strlen(line)) != (ssize_t)strlen(line)) {
-       dbprintf(("error writing to mesgfd socket: %s", strerror(errno)));
+    g_snprintf(line, 1024, "%s: info APPLICATION=%s\n", get_pname(), prog);
+    if (full_write(mesgfd, line, strlen(line)) != strlen(line)) {
+       dbprintf(_("error writing to mesgfd socket: %s"), strerror(errno));
        return;
     }
 
-    snprintf(line, 1024, "%s: info RECOVER_CMD=", get_pname());
-    if (fullwrite(mesgfd, line, strlen(line)) != (ssize_t)strlen(line)) {
-       dbprintf(("error writing to mesgfd socket: %s", strerror(errno)));
+    g_snprintf(line, 1024, "%s: info RECOVER_CMD=", get_pname());
+    if (full_write(mesgfd, line, strlen(line)) != strlen(line)) {
+       dbprintf(_("error writing to mesgfd socket: %s"), strerror(errno));
        return;
     }
 
-    if (options->compress) {
-       snprintf(line, 1024, "%s %s |", UNCOMPRESS_PATH,
+    if (dle->compress == COMP_FAST || dle->compress == COMP_BEST) {
+       g_snprintf(line, 1024, "%s %s |", UNCOMPRESS_PATH,
 #ifdef UNCOMPRESS_OPT
                 UNCOMPRESS_OPT
 #else
                 ""
 #endif
                 );
-       if (fullwrite(mesgfd, line, strlen(line)) != (ssize_t)strlen(line)) {
-           dbprintf(("error writing to mesgfd socket: %s", strerror(errno)));
+       if (full_write(mesgfd, line, strlen(line)) != strlen(line)) {
+           dbprintf(_("error writing to mesgfd socket: %s"), strerror(errno));
            return;
        }
     }
-    snprintf(line, 1024, "%s -f... -\n", prog);
-    if (fullwrite(mesgfd, line, strlen(line)) != (ssize_t)strlen(line)) {
-       dbprintf(("error writing to mesgfd socket: %s", strerror(errno)));
+    g_snprintf(line, 1024, "%s/%s restore [./file-to-restore]+\n",
+              APPLICATION_DIR, prog);
+    if (full_write(mesgfd, line, strlen(line)) != strlen(line)) {
+       dbprintf(_("error writing to mesgfd socket: %s"), strerror(errno));
        return;
     }
 
-    if (options->compress) {
-       snprintf(line, 1024, "%s: info COMPRESS_SUFFIX=%s\n",
+    if (dle->compress) {
+       g_snprintf(line, 1024, "%s: info COMPRESS_SUFFIX=%s\n",
                 get_pname(), COMPRESS_SUFFIX);
-       if (fullwrite(mesgfd, line, strlen(line)) != (ssize_t)strlen(line)) {
-           dbprintf(("error writing to mesgfd socket: %s", strerror(errno)));
+       if (full_write(mesgfd, line, strlen(line)) != strlen(line)) {
+           dbprintf(_("error writing to mesgfd socket: %s"), strerror(errno));
            return;
        }
     }
 
-    snprintf(line, 1024, "%s: info end\n", get_pname());
-    if (fullwrite(mesgfd, line, strlen(line)) != (ssize_t)strlen(line)) {
-       dbprintf(("error writing to mesgfd socket: %s", strerror(errno)));
+    g_snprintf(line, 1024, "%s: info end\n", get_pname());
+    if (full_write(mesgfd, line, strlen(line)) != strlen(line)) {
+       dbprintf(_("error writing to mesgfd socket: %s"), strerror(errno));
        return;
     }
 }
@@ -872,17 +993,16 @@ pipefork(
     int inpipe[2];
     pid_t pid;
 
-    dbprintf(("%s: forking function %s in pipeline\n",
-       debug_prefix_time(NULL), fname));
+    dbprintf(_("Forking function %s in pipeline\n"), fname);
 
     if(pipe(inpipe) == -1) {
-       error("error [open pipe to %s: %s]", fname, strerror(errno));
+       error(_("error [open pipe to %s: %s]"), fname, strerror(errno));
        /*NOTREACHED*/
     }
 
     switch(pid = fork()) {
     case -1:
-       error("error [fork %s: %s]", fname, strerror(errno));
+       error(_("error [fork %s: %s]"), fname, strerror(errno));
        /*NOTREACHED*/
     default:   /* parent process */
        aclose(inpipe[0]);      /* close input side of pipe */
@@ -892,17 +1012,17 @@ pipefork(
        aclose(inpipe[1]);      /* close output side of pipe */
 
        if(dup2(inpipe[0], 0) == -1) {
-           error("error [fork %s: dup2(%d, in): %s]",
+           error(_("error [fork %s: dup2(%d, in): %s]"),
                  fname, inpipe[0], strerror(errno));
            /*NOTRACHED*/
        }
        if(dup2(stdoutfd, 1) == -1) {
-           error("error [fork %s: dup2(%d, out): %s]",
+           error(_("error [fork %s: dup2(%d, out): %s]"),
                  fname, stdoutfd, strerror(errno));
            /*NOTRACHED*/
        }
        if(dup2(stderrfd, 2) == -1) {
-           error("error [fork %s: dup2(%d, err): %s]",
+           error(_("error [fork %s: dup2(%d, err): %s]"),
                  fname, stderrfd, strerror(errno));
            /*NOTRACHED*/
        }
@@ -914,109 +1034,94 @@ pipefork(
     return pid;
 }
 
-void
-parse_backup_messages(
-    int                mesgin)
+int
+check_result(
+    int mesgfd)
 {
     int goterror;
     pid_t wpid;
     amwait_t retstat;
-    char *line;
 
     goterror = 0;
-    amfree(errorstr);
-
-    for(; (line = areads(mesgin)) != NULL; free(line)) {
-       process_dumpline(line);
-    }
 
-    if(errno) {
-       error("error [read mesg pipe: %s]", strerror(errno));
-       /*NOTREACHED*/
-    }
 
     while((wpid = waitpid((pid_t)-1, &retstat, WNOHANG)) > 0) {
-       if(check_status(wpid, retstat)) goterror = 1;
+       if(check_status(wpid, retstat, mesgfd)) goterror = 1;
     }
 
     if (dumppid != -1) {
        sleep(5);
        while((wpid = waitpid((pid_t)-1, &retstat, WNOHANG)) > 0) {
-           if(check_status(wpid, retstat)) goterror = 1;
+           if(check_status(wpid, retstat, mesgfd)) goterror = 1;
        }
     }
     if (dumppid != -1) {
-       dbprintf(("%s: Sending SIGHUP to dump process %d\n",
-                 debug_prefix_time(NULL), (int)dumppid));
+       dbprintf(_("Sending SIGHUP to dump process %d\n"),
+                 (int)dumppid);
        if(dumppid != -1) {
            if(kill(dumppid, SIGHUP) == -1) {
-               dbprintf(("%s: Can't send SIGHUP to %d: %s\n",
-                         debug_prefix_time(NULL), (int)dumppid,
-                         strerror(errno)));
+               dbprintf(_("Can't send SIGHUP to %d: %s\n"),
+                         (int)dumppid,
+                         strerror(errno));
            }
        }
        sleep(5);
        while((wpid = waitpid((pid_t)-1, &retstat, WNOHANG)) > 0) {
-           if(check_status(wpid, retstat)) goterror = 1;
+           if(check_status(wpid, retstat, mesgfd)) goterror = 1;
        }
     }
     if (dumppid != -1) {
-       dbprintf(("%s: Sending SIGKILL to dump process %d\n",
-                 debug_prefix_time(NULL), (int)dumppid));
+       dbprintf(_("Sending SIGKILL to dump process %d\n"),
+                 (int)dumppid);
        if(dumppid != -1) {
            if(kill(dumppid, SIGKILL) == -1) {
-               dbprintf(("%s: Can't send SIGKILL to %d: %s\n",
-                         debug_prefix_time(NULL), (int)dumppid,
-                         strerror(errno)));
+               dbprintf(_("Can't send SIGKILL to %d: %s\n"),
+                         (int)dumppid,
+                         strerror(errno));
            }
        }
        sleep(5);
        while((wpid = waitpid((pid_t)-1, &retstat, WNOHANG)) > 0) {
-           if(check_status(wpid, retstat)) goterror = 1;
+           if(check_status(wpid, retstat, mesgfd)) goterror = 1;
        }
     }
 
+    return goterror;
+}
+
+void
+parse_backup_messages(
+    dle_t      *dle,
+    int                mesgin)
+{
+    int goterror;
+    char *line;
+
+    amfree(errorstr);
+
+    for(; (line = areads(mesgin)) != NULL; free(line)) {
+       process_dumpline(line);
+    }
+
+    if(errno) {
+       error(_("error [read mesg pipe: %s]"), strerror(errno));
+       /*NOTREACHED*/
+    }
+
+    goterror = check_result(mesgfd);
+
     if(errorstr) {
-       error("error [%s]", errorstr);
+       error(_("error [%s]"), errorstr);
        /*NOTREACHED*/
     } else if(dump_size == -1) {
-       error("error [no backup size line]");
+       error(_("error [no backup size line]"));
        /*NOTREACHED*/
     }
 
-    program->end_backup(goterror);
+    program->end_backup(dle, goterror);
 
-    fprintf(stderr, "%s: size %ld\n", get_pname(), dump_size);
-    fprintf(stderr, "%s: end\n", get_pname());
-}
-
-
-/*
- * Returns the value of the first integer in a string.
- */
-
-double
-the_num(
-    char *     str,
-    int         pos)
-{
-    char *num;
-    int ch;
-    double d;
-
-    do {
-       ch = *str++;
-       while(ch && !isdigit(ch)) ch = *str++;
-       if (pos == 1) break;
-       pos--;
-       while(ch && (isdigit(ch) || ch == '.')) ch = *str++;
-    } while (ch);
-    num = str - 1;
-    while(isdigit(ch) || ch == '.') ch = *str++;
-    str[-1] = '\0';
-    d = atof(num);
-    str[-1] = (char)ch;
-    return d;
+    fdprintf(mesgfd, _("%s: size %ld\n"), get_pname(), dump_size);
+    fdprintf(mesgfd, _("%s: end\n"), get_pname());
 }
 
 
@@ -1061,13 +1166,12 @@ process_dumpline(
        startchr = '!';
        break;
     }
-    dbprintf(("%s: %3d: %7s(%c): %s\n",
-             debug_prefix_time(NULL),
+    dbprintf("%3d: %7s(%c): %s\n",
              rp->srcline,
              type,
              startchr,
-             str));
-    fprintf(stderr, "%c %s\n", startchr, str);
+             str);
+    fdprintf(mesgfd, "%c %s\n", startchr, str);
 }
 
 
@@ -1101,13 +1205,11 @@ save_fd(
   while (*fd >= 0 && *fd < min) {
     int newfd = dup(*fd);
     if (newfd == -1)
-      dbprintf(("%s: unable to save file descriptor [%s]\n",
-       debug_prefix_time(NULL), strerror(errno)));
+      dbprintf(_("Unable to save file descriptor [%s]\n"), strerror(errno));
     *fd = newfd;
   }
   if (origfd != *fd)
-    dbprintf(("%s: dupped file descriptor %i to %i\n",
-      debug_prefix_time(NULL), origfd, *fd));
+    dbprintf(_("Dupped file descriptor %i to %i\n"), origfd, *fd);
 }
 
 void
@@ -1126,19 +1228,19 @@ start_index(
     return;
 
   if (pipe(pipefd) != 0) {
-    error("creating index pipe: %s", strerror(errno));
+    error(_("creating index pipe: %s"), strerror(errno));
     /*NOTREACHED*/
   }
 
   switch(indexpid = fork()) {
   case -1:
-    error("forking index tee process: %s", strerror(errno));
+    error(_("forking index tee process: %s"), strerror(errno));
     /*NOTREACHED*/
 
   default:
     aclose(pipefd[0]);
     if (dup2(pipefd[1], input) == -1) {
-      error("dup'ping index tee output: %s", strerror(errno));
+      error(_("dup'ping index tee output: %s"), strerror(errno));
       /*NOTREACHED*/
     }
     aclose(pipefd[1]);
@@ -1157,31 +1259,30 @@ start_index(
   dup2(index, 1);
   dup2(mesg, 2);
   dup2(input, 3);
-  for(index = 4; index < FD_SETSIZE; index++) {
+  for(index = 4; index < (int)FD_SETSIZE; index++) {
     if (index != dbfd()) {
       close(index);
     }
   }
 
   if ((pipe_fp = popen(cmd, "w")) == NULL) {
-    error("couldn't start index creator [%s]", strerror(errno));
+    error(_("couldn't start index creator [%s]"), strerror(errno));
     /*NOTREACHED*/
   }
 
-  dbprintf(("%s: started index creator: \"%s\"\n",
-    debug_prefix_time(NULL), cmd));
+  dbprintf(_("Started index creator: \"%s\"\n"), cmd);
   while(1) {
     char buffer[BUFSIZ], *ptr;
     ssize_t bytes_read;
     size_t bytes_written;
-    ssize_t just_written;
+    size_t just_written;
 
     do {
        bytes_read = read(0, buffer, SIZEOF(buffer));
     } while ((bytes_read < 0) && ((errno == EINTR) || (errno == EAGAIN)));
 
     if (bytes_read < 0) {
-      error("index tee cannot read [%s]", strerror(errno));
+      error(_("index tee cannot read [%s]"), strerror(errno));
       /*NOTREACHED*/
     }
 
@@ -1191,14 +1292,14 @@ start_index(
     /* write the stuff to the subprocess */
     ptr = buffer;
     bytes_written = 0;
-    just_written = fullwrite(fileno(pipe_fp), ptr, (size_t)bytes_read);
-    if (just_written < 0) {
+    just_written = full_write(fileno(pipe_fp), ptr, (size_t)bytes_read);
+    if (just_written < (size_t)bytes_read) {
        /* 
         * just as we waited for write() to complete.
         */
        if (errno != EPIPE) {
-           dbprintf(("%s: index tee cannot write to index creator [%s]\n",
-                           debug_prefix_time(NULL), strerror(errno)));
+           dbprintf(_("Index tee cannot write to index creator [%s]\n"),
+                           strerror(errno));
        }
     } else {
        bytes_written += just_written;
@@ -1209,9 +1310,9 @@ start_index(
        occurs */
     ptr = buffer;
     bytes_written = 0;
-    just_written = fullwrite(3, ptr, (size_t)bytes_read);
-    if (just_written < 0) {
-       error("index tee cannot write [%s]", strerror(errno));
+    just_written = full_write(3, ptr, bytes_read);
+    if (just_written < (size_t)bytes_read) {
+       error(_("index tee cannot write [%s]"), strerror(errno));
        /*NOTREACHED*/
     } else {
        bytes_written += just_written;
@@ -1224,10 +1325,11 @@ start_index(
   /* finished */
   /* check the exit code of the pipe and moan if not 0 */
   if ((exitcode = pclose(pipe_fp)) != 0) {
-    dbprintf(("%s: index pipe returned %d\n",
-      debug_prefix_time(NULL), exitcode));
+    char *exitstr = str_exit_status("Index pipe", exitcode);
+    dbprintf("%s\n", exitstr);
+    amfree(exitstr);
   } else {
-    dbprintf(("%s: index created successfully\n", debug_prefix_time(NULL)));
+    dbprintf(_("Index created successfully\n"));
   }
   pipe_fp = NULL;