X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=client-src%2Fsendsize.c;h=8c64f63ac1563ebac01affcedd07486bc79520a0;hb=6c1f39091444e58c33362f0cc086375d9d273e77;hp=abd30d3ac86d2247a1c44cedabbf317fb293a7bb;hpb=71325c297e0436e9930a3e129a26696e78c27f62;p=debian%2Famanda diff --git a/client-src/sendsize.c b/client-src/sendsize.c index abd30d3..8c64f63 100644 --- a/client-src/sendsize.c +++ b/client-src/sendsize.c @@ -24,7 +24,7 @@ * file named AUTHORS, in the root directory of this distribution. */ /* - * $Id: sendsize.c,v 1.171.2.1 2006/09/22 11:51:32 martinea Exp $ + * $Id: sendsize.c,v 1.171 2006/08/24 01:57:15 paddy_s Exp $ * * send estimated backup sizes using dump */ @@ -38,32 +38,38 @@ #include "getfsent.h" #include "version.h" #include "client_util.h" -#include "clientconf.h" +#include "conffile.h" #include "amandad.h" #ifdef SAMBA_CLIENT #include "findpass.h" #endif +#define sendsize_debug(i, ...) do { \ + if ((i) <= debug_sebdsize) { \ + dbprintf(__VA_ARGS__); \ + } \ +} while (0) + #ifdef HAVE_SETPGID # define SETPGRP setpgid(getpid(), getpid()) # define SETPGRP_FAILED() do { \ - dbprintf(("setpgid(%ld,%ld) failed: %s\n", \ - (long)getpid(), (long)getpid(), strerror(errno))); \ + dbprintf(_("setpgid(%ld,%ld) failed: %s\n"), \ + (long)getpid(), (long)getpid(), strerror(errno)); \ } while(0) #else /* () line 0 */ #if defined(SETPGRP_VOID) # define SETPGRP setpgrp() # define SETPGRP_FAILED() do { \ - dbprintf(("setpgrp() failed: %s\n", strerror(errno))); \ + dbprintf(_("setpgrp() failed: %s\n"), strerror(errno)); \ } while(0) #else # define SETPGRP setpgrp(0, getpid()) # define SETPGRP_FAILED() do { \ - dbprintf(("setpgrp(0,%ld) failed: %s\n", \ - (long)getpid(), strerror(errno))); \ + dbprintf(_("setpgrp(0,%ld) failed: %s\n"), \ + (long)getpid(), strerror(errno)); \ } while(0) #endif @@ -85,7 +91,7 @@ typedef struct disk_estimates_s { char *qdirname; char *program; char *calcprog; - int program_is_wrapper; + int program_is_backup_api; int spindle; pid_t child; int done; @@ -102,7 +108,7 @@ static g_option_t *g_options = NULL; /* local functions */ int main(int argc, char **argv); void add_diskest(char *disk, char *amdevice, int level, int spindle, - int program_is_wrapper, char *prog, char *calcprog, + int program_is_backup_api, char *prog, char *calcprog, option_t *options); void calc_estimates(disk_estimates_t *est); void free_estimates(disk_estimates_t *est); @@ -110,7 +116,7 @@ void dump_calc_estimates(disk_estimates_t *); void star_calc_estimates(disk_estimates_t *); void smbtar_calc_estimates(disk_estimates_t *); void gnutar_calc_estimates(disk_estimates_t *); -void wrapper_calc_estimates(disk_estimates_t *); +void backup_api_calc_estimate(disk_estimates_t *); void generic_calc_estimates(disk_estimates_t *); @@ -122,7 +128,7 @@ main( int level, spindle; char *prog, *calcprog, *dumpdate; option_t *options = NULL; - int program_is_wrapper; + int program_is_backup_api; disk_estimates_t *est; disk_estimates_t *est1; disk_estimates_t *est_prev; @@ -138,18 +144,23 @@ main( char *qlist = NULL; char *amdevice = NULL; char *qamdevice = NULL; - char *conffile; char *amandates_file; -#if defined(USE_DBMALLOC) - unsigned long malloc_hist_1, malloc_size_1; - unsigned long malloc_hist_2, malloc_size_2; -#endif + int amandates_read = 0; (void)argc; /* Quiet unused parameter warning */ (void)argv; /* Quiet unused parameter warning */ /* 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(-1, 0); safe_cd(); @@ -165,32 +176,21 @@ main( erroutput_type = (ERR_INTERACTIVE|ERR_SYSLOG); dbopen(DBG_SUBDIR_CLIENT); startclock(); - dbprintf(("%s: version %s\n", get_pname(), version())); + dbprintf(_("version %s\n"), version()); our_features = am_init_feature_set(); our_feature_string = am_feature_to_string(our_features); - set_debug_prefix_pid(getpid()); + config_init(CONFIG_INIT_CLIENT, NULL); - conffile = vstralloc(CONFIG_DIR, "/", "amanda-client.conf", NULL); - if (read_clientconf(conffile) > 0) { - error("error reading conffile: %s", conffile); - /*NOTREACHED*/ - } - amfree(conffile); + check_running_as(RUNNING_AS_CLIENT_LOGIN); /* handle all service requests */ - amandates_file = client_getconf_str(CLN_AMANDATES); - if(!start_amandates(amandates_file, 0)) - error("error [opening %s: %s]", amandates_file, strerror(errno)); - for(; (line = agets(stdin)) != NULL; free(line)) { if (line[0] == '\0') continue; -#define sc "OPTIONS " - if(strncmp(line, sc, SIZEOF(sc)-1) == 0) { -#undef sc + if(strncmp_const(line, "OPTIONS ") == 0) { g_options = parse_g_options(line+8, 1); if(!g_options->hostname) { g_options->hostname = alloc(MAX_HOSTNAME_LENGTH+1); @@ -198,75 +198,88 @@ main( g_options->hostname[MAX_HOSTNAME_LENGTH] = '\0'; } - 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_maxdumps)) { - printf("maxdumps=%d;", g_options->maxdumps); + g_printf("maxdumps=%d;", g_options->maxdumps); } if(am_has_feature(g_options->features, fe_rep_options_hostname)) { - printf("hostname=%s;", g_options->hostname); + g_printf("hostname=%s;", g_options->hostname); } - printf("\n"); + g_printf("\n"); fflush(stdout); 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(config_name, DBG_SUBDIR_CLIENT); } continue; } + if (amandates_read == 0) { + amandates_file = getconf_str(CNF_AMANDATES); + if(!start_amandates(amandates_file, 0)) + error("error [opening %s: %s]", amandates_file, + strerror(errno)); + amandates_read = 1; + } + s = line; ch = *s++; skip_whitespace(s, ch); /* find the program name */ if(ch == '\0') { - err_extra = stralloc("no program name"); + err_extra = stralloc(_("no program name")); goto err; /* no program name */ } prog = s - 1; skip_non_whitespace(s, ch); s[-1] = '\0'; - program_is_wrapper=0; - if(strcmp(prog,"DUMPER")==0) { - program_is_wrapper=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'; - } - - if(strncmp(prog, "CALCSIZE", 8) == 0) { + program_is_backup_api=0; + if(strncmp_const(prog, "CALCSIZE") == 0) { skip_whitespace(s, ch); /* find the program name */ if(ch == '\0') { - err_extra = stralloc("no program name"); + err_extra = stralloc(_("no program name")); goto err; } calcprog = s - 1; skip_non_whitespace(s, ch); s[-1] = '\0'; + if (strcmp(calcprog,"BACKUP") == 0) { + program_is_backup_api=1; + skip_whitespace(s, ch); /* find dumper name */ + if (ch == '\0') { + goto err; /* no program */ + } + calcprog = s - 1; + skip_non_whitespace(s, ch); + s[-1] = '\0'; + } } else { calcprog = NULL; + 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'; + } } skip_whitespace(s, ch); /* find the disk name */ if(ch == '\0') { - err_extra = stralloc("no disk name"); + err_extra = stralloc(_("no disk name")); goto err; /* no disk name */ } @@ -283,7 +296,7 @@ main( skip_whitespace(s, ch); /* find the device or level */ if (ch == '\0') { - err_extra = stralloc("bad level"); + err_extra = stralloc(_("bad level")); goto err; } if(!isdigit((int)s[-1])) { @@ -301,18 +314,18 @@ main( /* find the level number */ if(ch == '\0' || sscanf(s - 1, "%d", &level) != 1) { - err_extra = stralloc("bad level"); + err_extra = stralloc(_("bad level")); goto err; /* bad level */ } if (level < 0 || level >= DUMP_LEVELS) { - err_extra = stralloc("bad level"); + err_extra = stralloc(_("bad level")); goto err; } skip_integer(s, ch); skip_whitespace(s, ch); /* find the dump date */ if(ch == '\0') { - err_extra = stralloc("no dumpdate"); + err_extra = stralloc(_("no dumpdate")); goto err; /* no dumpdate */ } dumpdate = s - 1; @@ -325,14 +338,14 @@ main( skip_whitespace(s, ch); /* find the spindle */ if(ch != '\0') { if(sscanf(s - 1, "%d", &spindle) != 1) { - err_extra = stralloc("bad spindle"); + err_extra = stralloc(_("bad spindle")); goto err; /* bad spindle */ } skip_integer(s, ch); skip_whitespace(s, ch); /* find the parameters */ if(ch != '\0') { - if(strncmp(s-1, "OPTIONS |;",10) == 0) { + if(strncmp_const(s-1, "OPTIONS |;") == 0) { options = parse_options(s + 8, disk, amdevice, @@ -343,29 +356,28 @@ main( options = alloc(SIZEOF(option_t)); init_options(options); while (ch != '\0') { - if(strncmp(s-1, "exclude-file=", 13) == 0) { + if(strncmp_const(s-1, "exclude-file=") == 0) { qlist = unquote_string(s+12); options->exclude_file = append_sl(options->exclude_file, qlist); amfree(qlist); - } else if(strncmp(s-1, "exclude-list=", 13) == 0) { + } else if(strncmp_const(s-1, "exclude-list=") == 0) { + qlist = unquote_string(s+12); options->exclude_list = append_sl(options->exclude_list, qlist); - qlist = unquote_string(s+12); amfree(qlist); - } else if(strncmp(s-1, "include-file=", 13) == 0) { + } else if(strncmp_const(s-1, "include-file=") == 0) { + qlist = unquote_string(s+12); options->include_file = append_sl(options->include_file, qlist); - qlist = unquote_string(s+12); amfree(qlist); - } else if(strncmp(s-1, "include-list=", 13) == 0) { + } else if(strncmp_const(s-1, "include-list=") == 0) { + qlist = unquote_string(s+12); options->include_list = append_sl(options->include_list, qlist); - qlist = unquote_string(s+12); amfree(qlist); } else { - err_extra = vstralloc("Invalid parameter (", - s-1, ")", NULL); + err_extra = vstrallocf(_("Invalid parameter (%s)"), s-1); goto err; /* should have gotten to end */ } skip_quoted_string(s, ch); @@ -385,7 +397,7 @@ main( } /*@ignore@*/ - add_diskest(disk, amdevice, level, spindle, program_is_wrapper, prog, calcprog, options); + add_diskest(disk, amdevice, level, spindle, program_is_backup_api, prog, calcprog, options); /*@end@*/ amfree(disk); amfree(qdisk); @@ -393,7 +405,8 @@ main( amfree(qamdevice); } if (g_options == NULL) { - error("Missing OPTIONS line in sendsize input\n"); + printf(_("ERROR [Missing OPTIONS line in sendsize input]\n")); + error(_("Missing OPTIONS line in sendsize input\n")); /*NOTREACHED*/ } amfree(line); @@ -413,31 +426,24 @@ main( if(need_wait) { pid_t child_pid; amwait_t child_status; - int exit_code; need_wait = 0; - dbprintf(("%s: waiting for any estimate child: %d running\n", - debug_prefix_time(NULL), dumpsrunning)); + dbprintf(_("waiting for any estimate child: %d running\n"), + dumpsrunning); child_pid = wait(&child_status); if(child_pid == -1) { - error("wait failed: %s", strerror(errno)); + error(_("wait failed: %s"), strerror(errno)); /*NOTREACHED*/ } - if(WIFSIGNALED(child_status)) { - dbprintf(("%s: child %ld terminated with signal %d\n", - debug_prefix_time(NULL), - (long) child_pid, WTERMSIG(child_status))); - } else { - exit_code = WEXITSTATUS(child_status); - if(exit_code == 0) { - dbprintf(("%s: child %ld terminated normally\n", - debug_prefix_time(NULL), (long) child_pid)); - } else { - dbprintf(("%s: child %ld terminated with code %d\n", - debug_prefix_time(NULL), - (long) child_pid, exit_code)); - } + + if (!WIFEXITED(child_status) || WEXITSTATUS(child_status) != 0) { + char *child_name = vstrallocf(_("child %ld"), (long)child_pid); + char *child_status_str = str_exit_status(child_name, child_status); + dbprintf("%s\n", child_status_str); + amfree(child_status_str); + amfree(child_name); } + /* * Find the child and mark it done. */ @@ -447,8 +453,7 @@ main( } } if(est == NULL) { - dbprintf(("%s: unexpected child %ld\n", - debug_prefix_time(NULL), (long)child_pid)); + dbprintf(_("unexpected child %ld\n"), (long)child_pid); } else { est->done = 1; est->child = 0; @@ -503,11 +508,10 @@ main( } else { done = 0; if((est->child = fork()) == 0) { - set_debug_prefix_pid(getpid()); calc_estimates(est); /* child does the estimate */ exit(0); } else if(est->child == -1) { - error("calc_estimates fork failed: %s", strerror(errno)); + error(_("calc_estimates fork failed: %s"), strerror(errno)); /*NOTREACHED*/ } dumpsrunning++; /* parent */ @@ -524,29 +528,18 @@ main( 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); - -#if defined(USE_DBMALLOC) - malloc_size_2 = malloc_inuse(&malloc_hist_2); - - if(malloc_size_1 != malloc_size_2) { - malloc_list(dbfd(), malloc_hist_1, malloc_hist_2); - } -#endif + free_g_options(g_options); dbclose(); return 0; 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 : "")); - amfree(err_extra); + g_printf(_("FORMAT ERROR IN REQUEST PACKET\n")); + if (err_extra) { + dbprintf(_("REQ packet is bogus: %s\n"), err_extra); + amfree(err_extra); + } else { + dbprintf(_("REQ packet is bogus\n")); + } dbclose(); return 1; } @@ -558,7 +551,7 @@ add_diskest( char * amdevice, int level, int spindle, - int program_is_wrapper, + int program_is_backup_api, char * prog, char * calcprog, option_t * options) @@ -605,7 +598,7 @@ add_diskest( newp->calcprog = stralloc(calcprog); else newp->calcprog = NULL; - newp->program_is_wrapper = program_is_wrapper; + newp->program_is_backup_api = program_is_backup_api; newp->spindle = spindle; newp->est[level].needestimate = 1; newp->options = options; @@ -656,12 +649,11 @@ void calc_estimates( disk_estimates_t * est) { - dbprintf(("%s: calculating for amname %s, dirname %s, spindle %d\n", - debug_prefix_time(NULL), - est->qamname, est->qdirname, est->spindle)); + dbprintf(_("calculating for amname %s, dirname %s, spindle %d\n"), + est->qamname, est->qdirname, est->spindle); - if(est->program_is_wrapper == 1) - wrapper_calc_estimates(est); + if(est->program_is_backup_api == 1) + backup_api_calc_estimate(est); else #ifndef USE_GENERIC_CALCSIZE if(strcmp(est->program, "DUMP") == 0) @@ -681,16 +673,14 @@ calc_estimates( #endif #ifdef SAMBA_CLIENT if (est->amdevice[0] == '/' && est->amdevice[1] == '/') - dbprintf(("%s: Can't use CALCSIZE for samba estimate: %s %s\n", - debug_prefix_time(NULL), - est->qamname, est->qdirname)); + dbprintf(_("Can't use CALCSIZE for samba estimate: %s %s\n"), + est->qamname, est->qdirname); else #endif generic_calc_estimates(est); - dbprintf(("%s: done with amname %s dirname %s spindle %d\n", - debug_prefix_time(NULL), - est->qamname, est->qdirname, est->spindle)); + dbprintf(_("done with amname %s dirname %s spindle %d\n"), + est->qamname, est->qdirname, est->spindle); } /* @@ -699,45 +689,53 @@ calc_estimates( */ /* local functions */ -off_t getsize_dump(char *disk, char *amdevice, int level, option_t *options); -off_t getsize_star(char *disk, char *amdevice, int level, - option_t *options, time_t dumpsince); -off_t getsize_smbtar(char *disk, char *amdevice, int level, option_t *options); +off_t getsize_dump(char *disk, char *amdevice, int level, option_t *options, + char **errmsg); +off_t getsize_smbtar(char *disk, char *amdevice, int level, option_t *options, + char **errmsg); off_t getsize_gnutar(char *disk, char *amdevice, int level, - option_t *options, time_t dumpsince); -off_t getsize_wrapper(char *program, char *disk, char *amdevice, int level, - option_t *options, time_t dumpsince); + option_t *options, time_t dumpsince, char **errmsg); +off_t getsize_backup_api(char *program, char *disk, char *amdevice, int level, + option_t *options, time_t dumpsince, char **errmsg); off_t handle_dumpline(char *str); double first_num(char *str); void -wrapper_calc_estimates( +backup_api_calc_estimate( disk_estimates_t * est) { - int level; - off_t size; - - for(level = 0; level < DUMP_LEVELS; level++) { - if (est->est[level].needestimate) { - dbprintf(("%s: getting size via wrapper for %s level %d\n", - debug_prefix_time(NULL), est->qamname, level)); - size = getsize_wrapper(est->program, est->amname, est->amdevice, - level, est->options, est->est[level].dumpsince); - - amflock(1, "size"); - - if (fseek(stdout, 0L, SEEK_END) < 0) { - dbprintf(("wrapper_calc_estimates: warning - seek failed: %s\n", - strerror(errno))); - } - - printf("%s %d SIZE " OFF_T_FMT "\n", est->qamname, level, - (OFF_T_FMT_TYPE)size); - fflush(stdout); - - amfunlock(1, "size"); - } - } + int level; + off_t size; + char *errmsg = NULL, *qerrmsg; + + for(level = 0; level < DUMP_LEVELS; level++) { + if (est->est[level].needestimate) { + dbprintf(_("getting size via application API for %s %s level %d\n"), + est->qamname, est->qamdevice, level); + size = getsize_backup_api(est->program, est->amname, est->amdevice, + level, est->options, + est->est[level].dumpsince, &errmsg); + + amflock(1, "size"); + + g_printf(_("%s %d SIZE %lld\n"), est->qamname, level, + (long long)size); + if (errmsg && errmsg[0] != '\0') { + if(am_has_feature(g_options->features, + fe_rep_sendsize_quoted_error)) { + qerrmsg = quote_string(errmsg); + dbprintf(_("errmsg is %s\n"), errmsg); + g_printf(_("%s %d ERROR %s\n"), + est->qamname, level, qerrmsg); + amfree(qerrmsg); + } + } + amfree(errmsg); + fflush(stdout); + + amfunlock(1, "size"); + } + } } @@ -747,9 +745,10 @@ generic_calc_estimates( { int pipefd = -1, nullfd = -1; char *cmd; + char *cmdline; char *my_argv[DUMP_LEVELS*2+22]; char number[NUM_STR_SIZE]; - int i, level, my_argc, status; + int i, level, my_argc; pid_t calcpid; int nb_exclude = 0; int nb_include = 0; @@ -760,8 +759,11 @@ generic_calc_estimates( off_t size = (off_t)1; char *line = NULL; char *match_expr; + amwait_t wait_status; + char *errmsg = NULL, *qerrmsg; + char tmppath[PATH_MAX]; - cmd = vstralloc(libexecdir, "/", "calcsize", versionsuffix(), NULL); + cmd = vstralloc(amlibexecdir, "/", "calcsize", versionsuffix(), NULL); my_argc = 0; @@ -774,7 +776,8 @@ generic_calc_estimates( my_argv[my_argc++] = stralloc(est->calcprog); my_argv[my_argc++] = stralloc(est->amname); - my_argv[my_argc++] = stralloc(est->dirname); + canonicalize_pathname(est->dirname, tmppath); + my_argv[my_argc++] = stralloc(tmppath); if(est->options->exclude_file) @@ -804,28 +807,32 @@ generic_calc_estimates( } start_time = curclock(); - dbprintf(("%s: running cmd: %s", debug_prefix_time(NULL), my_argv[0])); - for(i=0; iest[level].needestimate) { - snprintf(number, SIZEOF(number), "%d", level); + g_snprintf(number, SIZEOF(number), "%d", level); my_argv[my_argc++] = stralloc(number); - dbprintf((" %s", number)); - snprintf(number, SIZEOF(number), + dbprintf(" %s", number); + g_snprintf(number, SIZEOF(number), "%ld", (long)est->est[level].dumpsince); my_argv[my_argc++] = stralloc(number); - dbprintf((" %s", number)); + dbprintf(" %s", number); } } my_argv[my_argc] = NULL; - dbprintf(("\n")); + dbprintf("\n"); fflush(stderr); fflush(stdout); if ((nullfd = open("/dev/null", O_RDWR)) == -1) { - dbprintf(("Cannot access /dev/null : %s\n", strerror(errno))); + errmsg = vstrallocf(_("Cannot access /dev/null : %s"), + strerror(errno)); + dbprintf("%s\n", errmsg); goto common_exit; } @@ -834,38 +841,64 @@ generic_calc_estimates( dumpout = fdopen(pipefd,"r"); if (!dumpout) { - error("Can't fdopen: %s", strerror(errno)); + error(_("Can't fdopen: %s"), strerror(errno)); /*NOTREACHED*/ } - match_expr = vstralloc(est->qamname," %d SIZE " OFF_T_FMT, NULL); + match_expr = vstralloc(est->qamname," %d SIZE %lld", NULL); for(size = (off_t)-1; (line = agets(dumpout)) != NULL; free(line)) { + long long size_ = (long long)0; if (line[0] == '\0') continue; - if(sscanf(line, match_expr, &level, &size) == 2) { - printf("%s\n", line); /* write to amandad */ - dbprintf(("%s: estimate size for %s level %d: " OFF_T_FMT " KB\n", - debug_prefix(NULL), + if(sscanf(line, match_expr, &level, &size_) == 2) { + g_printf("%s\n", line); /* write to amandad */ + dbprintf(_("estimate size for %s level %d: %lld KB\n"), est->qamname, level, - size)); + size_); } + size = (off_t)size_; } amfree(match_expr); - dbprintf(("%s: waiting for %s %s child (pid=%d)\n", - debug_prefix_time(NULL), my_argv[0], est->qamdevice, calcpid)); - wait(&status); - dbprintf(("%s: after %s %s wait: child pid=%d status=%d\n", - debug_prefix_time(NULL), my_argv[0], est->qamdevice, - calcpid, WEXITSTATUS(status))); + dbprintf(_("waiting for %s %s child (pid=%d)\n"), + my_argv[0], est->qamdevice, (int)calcpid); + waitpid(calcpid, &wait_status, 0); + if (WIFSIGNALED(wait_status)) { + errmsg = vstrallocf(_("%s terminated with signal %d: see %s"), + "calcsize", WTERMSIG(wait_status), + dbfn()); + } else if (WIFEXITED(wait_status)) { + if (WEXITSTATUS(wait_status) != 0) { + errmsg = vstrallocf(_("%s exited with status %d: see %s"), + "calcsize", WEXITSTATUS(wait_status), + dbfn()); + } else { + /* Normal exit */ + } + } else { + errmsg = vstrallocf(_("%s got bad exit: see %s"), + "calcsize", dbfn()); + } + dbprintf(_("after %s %s wait: child pid=%d status=%d\n"), + my_argv[0], est->qamdevice, + (int)calcpid, WEXITSTATUS(wait_status)); - dbprintf(("%s: .....\n", debug_prefix_time(NULL))); - dbprintf(("%s: estimate time for %s: %s\n", - debug_prefix(NULL), + dbprintf(_(".....\n")); + dbprintf(_("estimate time for %s: %s\n"), est->qamname, - walltime_str(timessub(curclock(), start_time)))); + walltime_str(timessub(curclock(), start_time))); common_exit: + if (errmsg && errmsg[0] != '\0') { + if(am_has_feature(g_options->features, fe_rep_sendsize_quoted_error)) { + qerrmsg = quote_string(errmsg); + dbprintf(_("errmsg is %s\n"), errmsg); + g_printf("%s %d ERROR %s\n", + est->qamname, 0, qerrmsg); + amfree(qerrmsg); + } + } + amfree(errmsg); for(i = 0; i < my_argc; i++) { amfree(my_argv[i]); } @@ -879,23 +912,30 @@ dump_calc_estimates( { int level; off_t size; + char *errmsg=NULL, *qerrmsg; for(level = 0; level < DUMP_LEVELS; level++) { if(est->est[level].needestimate) { - dbprintf(("%s: getting size via dump for %s level %d\n", - debug_prefix_time(NULL), est->qamname, level)); + dbprintf(_("getting size via dump for %s level %d\n"), + est->qamname, level); size = getsize_dump(est->amname, est->amdevice, - level, est->options); + level, est->options, &errmsg); amflock(1, "size"); - if (fseek(stdout, 0L, SEEK_END) < 0) { - dbprintf(("dump_calc_estimates: warning - seek failed: %s\n", - strerror(errno))); + g_printf(_("%s %d SIZE %lld\n"), + est->qamname, level, (long long)size); + if (errmsg && errmsg[0] != '\0') { + if(am_has_feature(g_options->features, + fe_rep_sendsize_quoted_error)) { + qerrmsg = quote_string(errmsg); + dbprintf(_("errmsg is %s\n"), errmsg); + g_printf("%s %d ERROR %s\n", + est->qamname, level, qerrmsg); + amfree(qerrmsg); + } } - - printf("%s %d SIZE " OFF_T_FMT "\n", - est->qamname, level, (OFF_T_FMT_TYPE)size); + amfree(errmsg); fflush(stdout); amfunlock(1, "size"); @@ -910,22 +950,30 @@ smbtar_calc_estimates( { int level; off_t size; + char *errmsg = NULL, *qerrmsg; for(level = 0; level < DUMP_LEVELS; level++) { if(est->est[level].needestimate) { - dbprintf(("%s: getting size via smbclient for %s level %d\n", - debug_prefix_time(NULL), est->qamname, level)); - size = getsize_smbtar(est->amname, est->amdevice, level, est->options); + dbprintf(_("getting size via smbclient for %s level %d\n"), + est->qamname, level); + size = getsize_smbtar(est->amname, est->amdevice, level, + est->options, &errmsg); amflock(1, "size"); - if (fseek(stdout, 0L, SEEK_END) < 0) { - dbprintf(("smbtar_calc_estimates: warning - seek failed: %s\n", - strerror(errno))); + g_printf(_("%s %d SIZE %lld\n"), + est->qamname, level, (long long)size); + if (errmsg && errmsg[0] != '\0') { + if(am_has_feature(g_options->features, + fe_rep_sendsize_quoted_error)) { + qerrmsg = quote_string(errmsg); + dbprintf(_("errmsg is %s\n"), errmsg); + g_printf("%s %d ERROR %s\n", + est->qamname, level, qerrmsg); + amfree(qerrmsg); + } } - - printf("%s %d SIZE " OFF_T_FMT "\n", - est->qamname, level, (OFF_T_FMT_TYPE)size); + amfree(errmsg); fflush(stdout); amfunlock(1, "size"); @@ -939,40 +987,48 @@ void gnutar_calc_estimates( disk_estimates_t * est) { - int level; - off_t size; - - for(level = 0; level < DUMP_LEVELS; level++) { - if (est->est[level].needestimate) { - dbprintf(("%s: getting size via gnutar for %s level %d\n", - debug_prefix_time(NULL), est->qamname, level)); - size = getsize_gnutar(est->amname, est->amdevice, level, - est->options, est->est[level].dumpsince); - - amflock(1, "size"); - - if (fseek(stdout, 0L, SEEK_END) < 0) { - dbprintf(("gnutar_calc_estimates: warning - seek failed: %s\n", - strerror(errno))); - } - - printf("%s %d SIZE " OFF_T_FMT "\n", - est->qamname, level, (OFF_T_FMT_TYPE)size); - fflush(stdout); - - amfunlock(1, "size"); - } - } + int level; + off_t size; + char *errmsg = NULL, *qerrmsg; + + for(level = 0; level < DUMP_LEVELS; level++) { + if (est->est[level].needestimate) { + dbprintf(_("getting size via gnutar for %s level %d\n"), + est->qamname, level); + size = getsize_gnutar(est->amname, est->amdevice, level, + est->options, est->est[level].dumpsince, + &errmsg); + + amflock(1, "size"); + + g_printf(_("%s %d SIZE %lld\n"), + est->qamname, level, (long long)size); + if (errmsg && errmsg[0] != '\0') { + if(am_has_feature(g_options->features, + fe_rep_sendsize_quoted_error)) { + qerrmsg = quote_string(errmsg); + dbprintf(_("errmsg is %s\n"), errmsg); + g_printf(_("%s %d ERROR %s\n"), + est->qamname, level, qerrmsg); + amfree(qerrmsg); + } + } + amfree(errmsg); + fflush(stdout); + + amfunlock(1, "size"); + } + } } #endif typedef struct regex_s { char *regex; int scale; -} regex_t; +} regex_scale_t; /*@ignore@*/ -regex_t re_size[] = { +regex_scale_t re_size[] = { #ifdef DUMP {" DUMP: estimated -*[0-9][0-9]* tape blocks", 1024}, {" DUMP: [Ee]stimated [0-9][0-9]* blocks", 512}, @@ -1032,10 +1088,11 @@ regex_t re_size[] = { off_t getsize_dump( - char *disk, - char *amdevice, + char *disk, + char *amdevice, int level, - option_t * options) + option_t *options G_GNUC_UNUSED, + char **errmsg) { int pipefd[2], nullfd, stdoutfd, killctl[2]; pid_t dumppid; @@ -1054,32 +1111,30 @@ getsize_dump( char *qdisk = quote_string(disk); char *qdevice; char *config; -#ifdef DUMP + amwait_t wait_status; +#if defined(DUMP) || defined(VDUMP) || defined(VXDUMP) || defined(XFSDUMP) int is_rundump = 1; #endif - (void)options; /* Quiet unused parameter warning */ - - (void)getsize_smbtar; /* Quiet unused parameter warning */ - - snprintf(level_str, SIZEOF(level_str), "%d", level); + g_snprintf(level_str, SIZEOF(level_str), "%d", level); device = amname_to_devname(amdevice); qdevice = quote_string(device); fstype = amname_to_fstype(amdevice); - dbprintf(("%s: calculating for device %s with %s\n", - debug_prefix_time(NULL), qdevice, fstype)); + dbprintf(_("calculating for device %s with %s\n"), + qdevice, fstype); - cmd = vstralloc(libexecdir, "/rundump", versionsuffix(), NULL); + cmd = vstralloc(amlibexecdir, "/rundump", versionsuffix(), NULL); rundump_cmd = stralloc(cmd); if (g_options->config) config = g_options->config; else config = "NOCONFIG"; if ((stdoutfd = nullfd = open("/dev/null", O_RDWR)) == -1) { - dbprintf(("getsize_dump could not open /dev/null: %s\n", - strerror(errno))); + *errmsg = vstrallocf(_("getsize_dump could not open /dev/null: %s"), + strerror(errno)); + dbprintf("%s\n", *errmsg); amfree(cmd); amfree(rundump_cmd); amfree(fstype); @@ -1090,8 +1145,9 @@ getsize_dump( } pipefd[0] = pipefd[1] = killctl[0] = killctl[1] = -1; if (pipe(pipefd) < 0) { - dbprintf(("getsize_dump could create data pipes: %s\n", - strerror(errno))); + *errmsg = vstrallocf(_("getsize_dump could create data pipes: %s"), + strerror(errno)); + dbprintf("%s\n", *errmsg); amfree(cmd); amfree(rundump_cmd); amfree(fstype); @@ -1109,8 +1165,8 @@ getsize_dump( #endif /* } */ { name = stralloc(" (xfsdump)"); - dbprintf(("%s: running \"%s%s -F -J -l %s - %s\"\n", - debug_prefix_time(NULL), cmd, name, level_str, qdevice)); + dbprintf(_("running \"%s%s -F -J -l %s - %s\"\n"), + cmd, name, level_str, qdevice); } else #endif /* } */ @@ -1130,8 +1186,8 @@ getsize_dump( is_rundump = 0; #endif dumpkeys = vstralloc(level_str, "s", "f", NULL); - dbprintf(("%s: running \"%s%s %s 1048576 - %s\"\n", - debug_prefix_time(NULL), cmd, name, dumpkeys, qdevice)); + dbprintf(_("running \"%s%s %s 1048576 - %s\"\n"), + cmd, name, dumpkeys, qdevice); } else #endif /* } */ @@ -1148,8 +1204,8 @@ getsize_dump( device = amname_to_dirname(amdevice); qdevice = quote_string(device); dumpkeys = vstralloc(level_str, "b", "f", NULL); - dbprintf(("%s: running \"%s%s %s 60 - %s\"\n", - debug_prefix_time(NULL), cmd, name, dumpkeys, qdevice)); + dbprintf(_("running \"%s%s %s 60 - %s\"\n"), + cmd, name, dumpkeys, qdevice); } else #endif /* } */ @@ -1170,16 +1226,22 @@ getsize_dump( # ifdef AIX_BACKUP /* { */ dumpkeys = vstralloc("-", level_str, "f", NULL); - dbprintf(("%s: running \"%s%s %s - %s\"\n", - debug_prefix_time(NULL), cmd, name, dumpkeys, qdevice)); + dbprintf(_("running \"%s%s %s - %s\"\n"), + cmd, name, dumpkeys, qdevice); # else /* } { */ +# ifdef HAVE_DUMP_ESTIMATE +# define PARAM_DUMP_ESTIMATE HAVE_DUMP_ESTIMATE +# else +# define PARAM_DUMP_ESTIMATE "" +# endif +# ifdef HAVE_HONOR_NODUMP +# define PARAM_HONOR_NODUMP "h" +# else +# define PARAM_HONOR_NODUMP "" +# endif dumpkeys = vstralloc(level_str, -# ifdef HAVE_DUMP_ESTIMATE /* { */ - HAVE_DUMP_ESTIMATE, -# endif /* } */ -# ifdef HAVE_HONOR_NODUMP /* { */ - "h", -# endif /* } */ + PARAM_DUMP_ESTIMATE, + PARAM_HONOR_NODUMP, "s", "f", NULL); # ifdef HAVE_DUMP_ESTIMATE @@ -1187,24 +1249,23 @@ getsize_dump( # endif # ifdef HAVE_HONOR_NODUMP /* { */ - dbprintf(("%s: running \"%s%s %s 0 1048576 - %s\"\n", - debug_prefix_time(NULL), cmd, name, dumpkeys, qdevice)); + dbprintf(_("running \"%s%s %s 0 1048576 - %s\"\n"), + cmd, name, dumpkeys, qdevice); # else /* } { */ - dbprintf(("%s: running \"%s%s %s 1048576 - %s\"\n", - debug_prefix_time(NULL), cmd, name, dumpkeys, qdevice)); + dbprintf(_("running \"%s%s %s 1048576 - %s\"\n"), + cmd, name, dumpkeys, qdevice); # endif /* } */ # endif /* } */ } else #endif /* } */ { - error("no dump program available"); + error(_("no dump program available")); /*NOTREACHED*/ } if (pipe(killctl) < 0) { - dbprintf(("%s: Could not create pipe: %s\n", - debug_prefix(NULL), strerror(errno))); + dbprintf(_("Could not create pipe: %s\n"), strerror(errno)); /* Message will be printed later... */ killctl[0] = killctl[1] = -1; } @@ -1212,8 +1273,9 @@ getsize_dump( start_time = curclock(); switch(dumppid = fork()) { case -1: - dbprintf(("%s: cannot fork for killpgrp: %s\n", - debug_prefix(NULL), strerror(errno))); + *errmsg = vstrallocf(_("cannot fork for killpgrp: %s"), + strerror(errno)); + dbprintf("%s\n", *errmsg); amfree(dumpkeys); amfree(cmd); amfree(rundump_cmd); @@ -1229,21 +1291,19 @@ getsize_dump( if(SETPGRP == -1) SETPGRP_FAILED(); else if (killctl[0] == -1 || killctl[1] == -1) - dbprintf(("%s: Trying without killpgrp\n", debug_prefix(NULL))); + dbprintf(_("Trying without killpgrp\n")); else { switch(fork()) { case -1: - dbprintf(("%s: fork failed, trying without killpgrp\n", - debug_prefix(NULL))); + dbprintf(_("fork failed, trying without killpgrp\n")); break; default: { char *config; - char *killpgrp_cmd = vstralloc(libexecdir, "/killpgrp", + char *killpgrp_cmd = vstralloc(amlibexecdir, "/killpgrp", versionsuffix(), NULL); - dbprintf(("%s: running %s\n", - debug_prefix_time(NULL), killpgrp_cmd)); + dbprintf(_("running %s\n"), killpgrp_cmd); dup2(killctl[0], 0); dup2(nullfd, 1); dup2(nullfd, 2); @@ -1255,10 +1315,11 @@ getsize_dump( config = g_options->config; else config = "NOCONFIG"; + safe_fd(-1, 0); execle(killpgrp_cmd, killpgrp_cmd, config, (char *)0, safe_env()); - dbprintf(("%s: cannot execute %s: %s\n", - debug_prefix(NULL), killpgrp_cmd, strerror(errno))); + dbprintf(_("cannot execute %s: %s\n"), + killpgrp_cmd, strerror(errno)); exit(-1); } @@ -1275,6 +1336,7 @@ getsize_dump( aclose(killctl[0]); if (killctl[1] != -1) aclose(killctl[1]); + safe_fd(-1, 0); #ifdef XFSDUMP #ifdef DUMP @@ -1343,7 +1405,7 @@ getsize_dump( # endif #endif { - error("exec %s failed or no dump program available: %s", + error(_("exec %s failed or no dump program available: %s"), cmd, strerror(errno)); /*NOTREACHED*/ } @@ -1357,14 +1419,14 @@ getsize_dump( aclose(killctl[0]); dumpout = fdopen(pipefd[0],"r"); if (!dumpout) { - error("Can't fdopen: %s", strerror(errno)); + error(_("Can't fdopen: %s"), strerror(errno)); /*NOTREACHED*/ } for(size = (off_t)-1; (line = agets(dumpout)) != NULL; free(line)) { if (line[0] == '\0') continue; - dbprintf(("%s: %s\n", debug_prefix_time(NULL), line)); + dbprintf("%s\n", line); size = handle_dumpline(line); if(size > (off_t)-1) { amfree(line); @@ -1374,40 +1436,40 @@ getsize_dump( amfree(line); } if (line != NULL) { - dbprintf(("%s: %s\n", debug_prefix_time(NULL), line)); + dbprintf("%s\n", line); } break; } } amfree(line); - dbprintf(("%s: .....\n", debug_prefix_time(NULL))); - dbprintf(("%s: estimate time for %s level %d: %s\n", - debug_prefix(NULL), + dbprintf(".....\n"); + dbprintf(_("estimate time for %s level %d: %s\n"), qdisk, level, - walltime_str(timessub(curclock(), start_time)))); + walltime_str(timessub(curclock(), start_time))); if(size == (off_t)-1) { - dbprintf(("%s: no size line match in %s%s output for \"%s\"\n", - debug_prefix(NULL), cmd, name, disk)); - dbprintf(("%s: .....\n", debug_prefix(NULL))); - dbprintf(("%s: Run %s%s manually to check for errors\n", - debug_prefix(NULL), cmd, name)); + *errmsg = vstrallocf(_("no size line match in %s%s output"), + cmd, name); + dbprintf(_("%s for %s\n"), + *errmsg, qdisk); + + dbprintf(".....\n"); + dbprintf(_("Run %s%s manually to check for errors\n"), + cmd, name); } else if(size == (off_t)0 && level == 0) { - dbprintf(("%s: possible %s%s problem -- is \"%s\" really empty?\n", - debug_prefix(NULL), cmd, name, disk)); - dbprintf(("%s: .....\n", debug_prefix(NULL))); + dbprintf(_("possible %s%s problem -- is \"%s\" really empty?\n"), + cmd, name, disk); + dbprintf(".....\n"); } else { - dbprintf(("%s: estimate size for %s level %d: %ld KB\n", - debug_prefix(NULL), + dbprintf(_("estimate size for %s level %d: %lld KB\n"), qdisk, level, - size)); + (long long)size); } if (killctl[1] != -1) { - dbprintf(("%s: asking killpgrp to terminate\n", - debug_prefix_time(NULL))); + dbprintf(_("asking killpgrp to terminate\n")); aclose(killctl[1]); for(s = 5; s > 0; --s) { sleep(1); @@ -1420,11 +1482,9 @@ getsize_dump( * First, try to kill the dump process nicely. If it ignores us * for several seconds, hit it harder. */ - dbprintf(("%s: sending SIGTERM to process group %ld\n", - debug_prefix_time(NULL), (long)dumppid)); + dbprintf(_("sending SIGTERM to process group %ld\n"), (long)dumppid); if (kill(-dumppid, SIGTERM) == -1) { - dbprintf(("%s: kill failed: %s\n", - debug_prefix(NULL), strerror(errno))); + dbprintf(_("kill failed: %s\n"), strerror(errno)); } /* Now check whether it dies */ for(s = 5; s > 0; --s) { @@ -1433,11 +1493,9 @@ getsize_dump( goto terminated; } - dbprintf(("%s: sending SIGKILL to process group %ld\n", - debug_prefix_time(NULL), (long)dumppid)); + dbprintf(_("sending SIGKILL to process group %ld\n"), (long)dumppid); if (kill(-dumppid, SIGKILL) == -1) { - dbprintf(("%s: kill failed: %s\n", - debug_prefix(NULL), strerror(errno))); + dbprintf(_("kill failed: %s\n"), strerror(errno)); } for(s = 5; s > 0; --s) { sleep(1); @@ -1445,11 +1503,23 @@ getsize_dump( goto terminated; } - dbprintf(("%s: waiting for %s%s \"%s\" child\n", - debug_prefix_time(NULL), cmd, name, qdisk)); - wait(NULL); - dbprintf(("%s: after %s%s %s wait\n", - debug_prefix_time(NULL), cmd, name, qdisk)); + dbprintf(_("waiting for %s%s \"%s\" child\n"), cmd, name, qdisk); + waitpid(dumppid, &wait_status, 0); + if (WIFSIGNALED(wait_status)) { + *errmsg = vstrallocf(_("%s terminated with signal %d: see %s"), + cmd, WTERMSIG(wait_status), dbfn()); + } else if (WIFEXITED(wait_status)) { + if (WEXITSTATUS(wait_status) != 0) { + *errmsg = vstrallocf(_("%s exited with status %d: see %s"), + cmd, WEXITSTATUS(wait_status), dbfn()); + } else { + /* Normal exit */ + } + } else { + *errmsg = vstrallocf(_("%s got bad exit: see %s"), + cmd, dbfn()); + } + dbprintf(_("after %s%s %s wait\n"), cmd, name, qdisk); terminated: @@ -1470,10 +1540,11 @@ getsize_dump( #ifdef SAMBA_CLIENT off_t getsize_smbtar( - char *disk, - char *amdevice, + char *disk, + char *amdevice, int level, - option_t * options) + option_t *options, + char **errmsg) { int pipefd = -1, nullfd = -1, passwdfd = -1; pid_t dumppid; @@ -1489,6 +1560,7 @@ getsize_smbtar( times_t start_time; char *error_pn = NULL; char *qdisk = quote_string(disk); + amwait_t wait_status; (void)options; /* Quiet unused parameter warning */ @@ -1500,7 +1572,7 @@ getsize_smbtar( amfree(subdir); set_pname(error_pn); amfree(error_pn); - error("cannot parse disk entry %s for share/subdir", qdisk); + error(_("cannot parse disk entry %s for share/subdir"), qdisk); /*NOTREACHED*/ } if ((subdir) && (SAMBA_VERSION < 2)) { @@ -1508,7 +1580,7 @@ getsize_smbtar( amfree(subdir); set_pname(error_pn); amfree(error_pn); - error("subdirectory specified for share %s but samba not v2 or better", qdisk); + error(_("subdirectory specified for share %s but samba not v2 or better"), qdisk); /*NOTREACHED*/ } if ((user_and_password = findpass(share, &domain)) == NULL) { @@ -1519,7 +1591,7 @@ getsize_smbtar( } set_pname(error_pn); amfree(error_pn); - error("cannot find password for %s", disk); + error(_("cannot find password for %s"), disk); /*NOTREACHED*/ } lpass = strlen(user_and_password); @@ -1532,7 +1604,7 @@ getsize_smbtar( } set_pname(error_pn); amfree(error_pn); - error("password field not \'user%%pass\' for %s", disk); + error(_("password field not \'user%%pass\' for %s"), disk); /*NOTREACHED*/ } *pwtext++ = '\0'; @@ -1546,7 +1618,7 @@ getsize_smbtar( } set_pname(error_pn); amfree(error_pn); - error("cannot make share name of %s", share); + error(_("cannot make share name of %s"), share); /*NOTREACHED*/ } if ((nullfd = open("/dev/null", O_RDWR)) == -1) { @@ -1559,7 +1631,7 @@ getsize_smbtar( set_pname(error_pn); amfree(error_pn); amfree(sharename); - error("could not open /dev/null: %s\n", + error(_("could not open /dev/null: %s\n"), strerror(errno)); /*NOTREACHED*/ } @@ -1613,7 +1685,7 @@ getsize_smbtar( aclose(passwdfd); set_pname(error_pn); amfree(error_pn); - error("password write failed: %s", strerror(save_errno)); + error(_("password write failed: %s"), strerror(save_errno)); /*NOTREACHED*/ } memset(user_and_password, '\0', (size_t)lpass); @@ -1625,14 +1697,14 @@ getsize_smbtar( amfree(error_pn); dumpout = fdopen(pipefd,"r"); if (!dumpout) { - error("Can't fdopen: %s", strerror(errno)); + error(_("Can't fdopen: %s"), strerror(errno)); /*NOTREACHED*/ } for(size = (off_t)-1; (line = agets(dumpout)) != NULL; free(line)) { if (line[0] == '\0') continue; - dbprintf(("%s: %s\n", debug_prefix_time(NULL), line)); + dbprintf("%s\n", line); size = handle_dumpline(line); if(size > -1) { amfree(line); @@ -1642,41 +1714,54 @@ getsize_smbtar( amfree(line); } if(line != NULL) { - dbprintf(("%s: %s\n", debug_prefix_time(NULL), line)); + dbprintf("%s\n", line); } break; } } amfree(line); - dbprintf(("%s: .....\n", debug_prefix_time(NULL))); - dbprintf(("%s: estimate time for %s level %d: %s\n", - debug_prefix(NULL), + dbprintf(".....\n"); + dbprintf(_("estimate time for %s level %d: %s\n"), qdisk, level, - walltime_str(timessub(curclock(), start_time)))); + walltime_str(timessub(curclock(), start_time))); if(size == (off_t)-1) { - dbprintf(("%s: no size line match in %s output for \"%s\"\n", - debug_prefix(NULL), SAMBA_CLIENT, disk)); - dbprintf(("%s: .....\n", debug_prefix(NULL))); + *errmsg = vstrallocf(_("no size line match in %s output"), + SAMBA_CLIENT); + dbprintf(_("%s for %s\n"), + *errmsg, qdisk); + dbprintf(".....\n"); } else if(size == (off_t)0 && level == 0) { - dbprintf(("%s: possible %s problem -- is \"%s\" really empty?\n", - debug_prefix(NULL), SAMBA_CLIENT, disk)); - dbprintf(("%s: .....\n", debug_prefix(NULL))); + dbprintf(_("possible %s problem -- is \"%s\" really empty?\n"), + SAMBA_CLIENT, disk); + dbprintf(".....\n"); } - dbprintf(("%s: estimate size for %s level %d: %ld KB\n", - debug_prefix(NULL), + dbprintf(_("estimate size for %s level %d: %lld KB\n"), qdisk, level, - size)); + (long long)size); kill(-dumppid, SIGTERM); - dbprintf(("%s: waiting for %s \"%s\" child\n", - debug_prefix_time(NULL), SAMBA_CLIENT, qdisk)); - wait(NULL); - dbprintf(("%s: after %s %s wait\n", - debug_prefix_time(NULL), SAMBA_CLIENT, qdisk)); + dbprintf(_("waiting for %s \"%s\" child\n"), SAMBA_CLIENT, qdisk); + waitpid(dumppid, &wait_status, 0); + if (WIFSIGNALED(wait_status)) { + *errmsg = vstrallocf(_("%s terminated with signal %d: see %s"), + SAMBA_CLIENT, WTERMSIG(wait_status), dbfn()); + } else if (WIFEXITED(wait_status)) { + if (WEXITSTATUS(wait_status) != 0) { + *errmsg = vstrallocf(_("%s exited with status %d: see %s"), + SAMBA_CLIENT, WEXITSTATUS(wait_status), + dbfn()); + } else { + /* Normal exit */ + } + } else { + *errmsg = vstrallocf(_("%s got bad exit: see %s"), + SAMBA_CLIENT, dbfn()); + } + dbprintf(_("after %s %s wait\n"), SAMBA_CLIENT, qdisk); afclose(dumpout); pipefd = -1; @@ -1691,11 +1776,12 @@ getsize_smbtar( #ifdef GNUTAR off_t getsize_gnutar( - char *disk, - char *amdevice, + char *disk, + char *amdevice, int level, - option_t * options, - time_t dumpsince) + option_t *options, + time_t dumpsince, + char **errmsg) { int pipefd = -1, nullfd = -1; pid_t dumppid; @@ -1723,6 +1809,8 @@ getsize_gnutar( char buf[32768]; char *qdisk = quote_string(disk); char *gnutar_list_dir; + amwait_t wait_status; + char tmppath[PATH_MAX]; if(options->exclude_file) nb_exclude += options->exclude_file->nb_element; if(options->exclude_list) nb_exclude += options->exclude_list->nb_element; @@ -1735,30 +1823,22 @@ getsize_gnutar( my_argv = alloc(SIZEOF(char *) * 22); i = 0; - gnutar_list_dir = client_getconf_str(CLN_GNUTAR_LIST_DIR); + gnutar_list_dir = getconf_str(CNF_GNUTAR_LIST_DIR); if (strlen(gnutar_list_dir) == 0) gnutar_list_dir = NULL; if (gnutar_list_dir) { char number[NUM_STR_SIZE]; - char *s; - int ch; int baselevel; + char *sdisk = sanitise_filename(disk); basename = vstralloc(gnutar_list_dir, "/", g_options->hostname, - disk, + sdisk, NULL); - /* - * The loop starts at the first character of the host name, - * not the '/'. - */ - s = basename + strlen(gnutar_list_dir) + 1; - while((ch = *s++) != '\0') { - if(ch == '/' || isspace(ch)) s[-1] = '_'; - } + amfree(sdisk); - snprintf(number, SIZEOF(number), "%d", level); + g_snprintf(number, SIZEOF(number), "%d", level); incrname = vstralloc(basename, "_", number, ".new", NULL); unlink(incrname); @@ -1771,20 +1851,21 @@ getsize_gnutar( infd = -1; while (infd == -1) { if (--baselevel >= 0) { - snprintf(number, SIZEOF(number), "%d", baselevel); + g_snprintf(number, SIZEOF(number), "%d", baselevel); inputname = newvstralloc(inputname, basename, "_", number, NULL); } else { inputname = newstralloc(inputname, "/dev/null"); } if ((infd = open(inputname, O_RDONLY)) == -1) { - int save_errno = errno; - dbprintf(("%s: gnutar: error opening %s: %s\n", - debug_prefix(NULL), inputname, strerror(save_errno))); + *errmsg = vstrallocf(_("gnutar: error opening %s: %s"), + inputname, strerror(errno)); + dbprintf("%s\n", *errmsg); if (baselevel < 0) { goto common_exit; } + amfree(*errmsg); } } @@ -1792,33 +1873,38 @@ getsize_gnutar( * Copy the previous listed incremental file to the new one. */ if ((outfd = open(incrname, O_WRONLY|O_CREAT, 0600)) == -1) { - dbprintf(("%s: opening %s: %s\n", - debug_prefix(NULL), incrname, strerror(errno))); + *errmsg = vstrallocf(_("opening %s: %s"), + incrname, strerror(errno)); + dbprintf("%s\n", *errmsg); goto common_exit; } while ((nb = read(infd, &buf, SIZEOF(buf))) > 0) { if (fullwrite(outfd, &buf, (size_t)nb) < nb) { - dbprintf(("%s: writing to %s: %s\n", - debug_prefix(NULL), incrname, strerror(errno))); + *errmsg = vstrallocf(_("writing to %s: %s"), + incrname, strerror(errno)); + dbprintf("%s\n", *errmsg); goto common_exit; } } if (nb < 0) { - dbprintf(("%s: reading from %s: %s\n", - debug_prefix(NULL), inputname, strerror(errno))); + *errmsg = vstrallocf(_("reading from %s: %s"), + inputname, strerror(errno)); + dbprintf("%s\n", *errmsg); goto common_exit; } if (close(infd) != 0) { - dbprintf(("%s: closing %s: %s\n", - debug_prefix(NULL), inputname, strerror(errno))); + *errmsg = vstrallocf(_("closing %s: %s"), + inputname, strerror(errno)); + dbprintf("%s\n", *errmsg); goto common_exit; } if (close(outfd) != 0) { - dbprintf(("%s: closing %s: %s\n", - debug_prefix(NULL), incrname, strerror(errno))); + *errmsg = vstrallocf(_("closing %s: %s"), + incrname, strerror(errno)); + dbprintf("%s\n", *errmsg); goto common_exit; } @@ -1827,14 +1913,14 @@ getsize_gnutar( } gmtm = gmtime(&dumpsince); - snprintf(dumptimestr, SIZEOF(dumptimestr), + g_snprintf(dumptimestr, SIZEOF(dumptimestr), "%04d-%02d-%02d %2d:%02d:%02d GMT", gmtm->tm_year + 1900, gmtm->tm_mon+1, gmtm->tm_mday, gmtm->tm_hour, gmtm->tm_min, gmtm->tm_sec); dirname = amname_to_dirname(amdevice); - cmd = vstralloc(libexecdir, "/", "runtar", versionsuffix(), NULL); + cmd = vstralloc(amlibexecdir, "/", "runtar", versionsuffix(), NULL); my_argv[i++] = "runtar"; if (g_options->config) my_argv[i++] = g_options->config; @@ -1850,7 +1936,8 @@ getsize_gnutar( my_argv[i++] = "--file"; my_argv[i++] = "/dev/null"; my_argv[i++] = "--directory"; - my_argv[i++] = dirname; + canonicalize_pathname(dirname, tmppath); + my_argv[i++] = tmppath; my_argv[i++] = "--one-file-system"; if (gnutar_list_dir) { my_argv[i++] = "--listed-incremental"; @@ -1889,7 +1976,9 @@ getsize_gnutar( start_time = curclock(); if ((nullfd = open("/dev/null", O_RDWR)) == -1) { - dbprintf(("Cannot access /dev/null : %s\n", strerror(errno))); + *errmsg = vstrallocf(_("Cannot access /dev/null : %s"), + strerror(errno)); + dbprintf("%s\n", *errmsg); goto common_exit; } @@ -1897,14 +1986,14 @@ getsize_gnutar( dumpout = fdopen(pipefd,"r"); if (!dumpout) { - error("Can't fdopen: %s", strerror(errno)); + error(_("Can't fdopen: %s"), strerror(errno)); /*NOTREACHED*/ } for(size = (off_t)-1; (line = agets(dumpout)) != NULL; free(line)) { if (line[0] == '\0') continue; - dbprintf(("%s: %s\n", debug_prefix_time(NULL), line)); + dbprintf("%s\n", line); size = handle_dumpline(line); if(size > (off_t)-1) { amfree(line); @@ -1915,7 +2004,7 @@ getsize_gnutar( amfree(line); } if (line != NULL) { - dbprintf(("%s: %s\n", debug_prefix_time(NULL), line)); + dbprintf("%s\n", line); break; } break; @@ -1923,34 +2012,44 @@ getsize_gnutar( } amfree(line); - dbprintf(("%s: .....\n", debug_prefix_time(NULL))); - dbprintf(("%s: estimate time for %s level %d: %s\n", - debug_prefix(NULL), + dbprintf(".....\n"); + dbprintf(_("estimate time for %s level %d: %s\n"), qdisk, level, - walltime_str(timessub(curclock(), start_time)))); + walltime_str(timessub(curclock(), start_time))); if(size == (off_t)-1) { - dbprintf(("%s: no size line match in %s output for \"%s\"\n", - debug_prefix(NULL), my_argv[0], disk)); - dbprintf(("%s: .....\n", debug_prefix(NULL))); + *errmsg = vstrallocf(_("no size line match in %s output"), my_argv[0]); + dbprintf(_("%s for %s\n"), *errmsg, qdisk); + dbprintf(".....\n"); } else if(size == (off_t)0 && level == 0) { - dbprintf(("%s: possible %s problem -- is \"%s\" really empty?\n", - debug_prefix(NULL), my_argv[0], disk)); - dbprintf(("%s: .....\n", debug_prefix(NULL))); + dbprintf(_("possible %s problem -- is \"%s\" really empty?\n"), + my_argv[0], disk); + dbprintf(".....\n"); } - dbprintf(("%s: estimate size for %s level %d: %ld KB\n", - debug_prefix(NULL), + dbprintf(_("estimate size for %s level %d: %lld KB\n"), qdisk, level, - size)); + (long long)size); kill(-dumppid, SIGTERM); - dbprintf(("%s: waiting for %s \"%s\" child\n", - debug_prefix_time(NULL), my_argv[0], qdisk)); - wait(NULL); - dbprintf(("%s: after %s %s wait\n", - debug_prefix_time(NULL), my_argv[0], qdisk)); + dbprintf(_("waiting for %s \"%s\" child\n"), my_argv[0], qdisk); + waitpid(dumppid, &wait_status, 0); + if (WIFSIGNALED(wait_status)) { + *errmsg = vstrallocf(_("%s terminated with signal %d: see %s"), + cmd, WTERMSIG(wait_status), dbfn()); + } else if (WIFEXITED(wait_status)) { + if (WEXITSTATUS(wait_status) != 0) { + *errmsg = vstrallocf(_("%s exited with status %d: see %s"), + cmd, WEXITSTATUS(wait_status), dbfn()); + } else { + /* Normal exit */ + } + } else { + *errmsg = vstrallocf(_("%s got bad exit: see %s"), + cmd, dbfn()); + } + dbprintf(_("after %s %s wait\n"), my_argv[0], qdisk); common_exit: @@ -1977,20 +2076,22 @@ common_exit: #endif off_t -getsize_wrapper( +getsize_backup_api( char *program, char *disk, char *amdevice, - int level, - option_t * options, - time_t dumpsince) + int level, + option_t *options, + time_t dumpsince, + char **errmsg) { - int pipefd[2], nullfd; + int pipeinfd[2], pipeoutfd[2], nullfd; pid_t dumppid; off_t size = (off_t)-1; - FILE *dumpout; + FILE *dumpout, *toolin; char *line = NULL; char *cmd = NULL; + char *cmdline; char dumptimestr[80]; struct tm *gmtm; int i, j; @@ -2000,45 +2101,74 @@ getsize_wrapper( times_t start_time; char *qdisk = quote_string(disk); char *qamdevice = quote_string(amdevice); + amwait_t wait_status; + char levelstr[NUM_STR_SIZE]; + backup_support_option_t *bsu; + (void)options; gmtm = gmtime(&dumpsince); - snprintf(dumptimestr, SIZEOF(dumptimestr), + g_snprintf(dumptimestr, SIZEOF(dumptimestr), "%04d-%02d-%02d %2d:%02d:%02d GMT", gmtm->tm_year + 1900, gmtm->tm_mon+1, gmtm->tm_mday, gmtm->tm_hour, gmtm->tm_min, gmtm->tm_sec); cmd = vstralloc(DUMPER_DIR, "/", program, NULL); + bsu = backup_support_option(program, g_options, disk, amdevice); + i=0; argvchild[i++] = program; argvchild[i++] = "estimate"; - if(level == 0) - argvchild[i++] = "full"; - else { - char levelstr[NUM_STR_SIZE]; - snprintf(levelstr,SIZEOF(levelstr),"%d",level); - argvchild[i++] = "level"; - argvchild[i++] = levelstr; + 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; + } + argvchild[i++] = "--device"; argvchild[i++] = amdevice; - newoptstr = vstralloc(options->str,"estimate-direct;", NULL); - argvchild[i++] = newoptstr; + if (disk && bsu->disk == 1) { + argvchild[i++] = "--disk"; + argvchild[i++] = disk; + } + if (level <= bsu->max_level) { + argvchild[i++] = "--level"; + g_snprintf(levelstr,SIZEOF(levelstr),"%d",level); + argvchild[i++] = levelstr; + } + argvchild[i] = NULL; - dbprintf(("%s: running %s", debug_prefix_time(NULL), cmd)); - for(j = 1; j < i; j++) { - dbprintf((" %s", argvchild[j])); - } - dbprintf(("\n")); + cmdline = stralloc(cmd); + for(j = 1; j < i; j++) + cmdline = vstrextend(&cmdline, " ", argvchild[i], NULL); + dbprintf("running: \"%s\"\n", cmdline); + amfree(cmdline); if ((nullfd = open("/dev/null", O_RDWR)) == -1) { - dbprintf(("Cannot access /dev/null : %s\n", strerror(errno))); + *errmsg = vstrallocf(_("Cannot access /dev/null : %s"), + strerror(errno)); + dbprintf("%s\n", *errmsg); goto common_exit; } - if (pipe(pipefd) < 0) { - dbprintf(("getsize_wrapper could create data pipes: %s\n", - strerror(errno))); + if (pipe(pipeinfd) < 0) { + *errmsg = vstrallocf(_("getsize_backup_api could create data pipes: %s"), + strerror(errno)); + dbprintf("%s\n", *errmsg); + goto common_exit; + } + + if (pipe(pipeoutfd) < 0) { + *errmsg = vstrallocf(_("getsize_backup_api could create data pipes: %s"), + strerror(errno)); + dbprintf("%s\n", *errmsg); goto common_exit; } @@ -2051,31 +2181,47 @@ getsize_wrapper( default: break; /* parent */ case 0: - dup2(nullfd, 0); + dup2(pipeinfd[0], 0); + dup2(pipeoutfd[1], 1); dup2(nullfd, 2); - dup2(pipefd[1], 1); - aclose(pipefd[0]); + aclose(pipeinfd[1]); + aclose(pipeoutfd[0]); + safe_fd(-1, 0); execve(cmd, argvchild, safe_env()); - error("exec %s failed: %s", cmd, strerror(errno)); + error(_("exec %s failed: %s"), cmd, strerror(errno)); /*NOTREACHED*/ } amfree(newoptstr); - aclose(pipefd[1]); - dumpout = fdopen(pipefd[0],"r"); - if (!dumpout) { + aclose(pipeinfd[0]); + aclose(pipeoutfd[1]); + + toolin = fdopen(pipeinfd[1],"w"); + if (!toolin) { error("Can't fdopen: %s", strerror(errno)); /*NOTREACHED*/ } + output_tool_property(toolin, options); + fflush(toolin); + fclose(toolin); + + dumpout = fdopen(pipeoutfd[0],"r"); + if (!dumpout) { + error(_("Can't fdopen: %s"), strerror(errno)); + /*NOTREACHED*/ + } + for(size = (off_t)-1; (line = agets(dumpout)) != NULL; free(line)) { + long long size1_ = (long long)0; + long long size2_ = (long long)0; if (line[0] == '\0') continue; - dbprintf(("%s: %s\n", debug_prefix_time(NULL), line)); - i = sscanf(line, OFF_T_FMT " " OFF_T_FMT, - (OFF_T_FMT_TYPE *)&size1, - (OFF_T_FMT_TYPE *)&size2); + dbprintf("%s\n", line); + i = sscanf(line, "%lld %lld", &size1_, &size2_); + size1 = (off_t)size1_; + size2 = (off_t)size2_; if(i == 2) { size = size1 * size2; } @@ -2087,41 +2233,49 @@ getsize_wrapper( amfree(line); } if(line != NULL) { - dbprintf(("%s: %s\n", debug_prefix_time(NULL), line)); + dbprintf(_("%s\n"), line); } break; } } amfree(line); - dbprintf(("%s: .....\n", debug_prefix_time(NULL))); - dbprintf(("%s: estimate time for %s level %d: %s\n", - debug_prefix(NULL), - qamdevice, - level, - walltime_str(timessub(curclock(), start_time)))); + dbprintf(".....\n"); + dbprintf(_("estimate time for %s level %d: %s\n"), qamdevice, level, + walltime_str(timessub(curclock(), start_time))); if(size == (off_t)-1) { - dbprintf(("%s: no size line match in %s output for \"%s\"\n", - debug_prefix(NULL), cmd, qdisk)); - dbprintf(("%s: .....\n", debug_prefix(NULL))); + *errmsg = vstrallocf(_("no size line match in %s output"), cmd); + dbprintf(_("%s for %s\n"), cmd, qdisk); + dbprintf(".....\n"); } else if(size == (off_t)0 && level == 0) { - dbprintf(("%s: possible %s problem -- is \"%s\" really empty?\n", - debug_prefix(NULL), cmd, qdisk)); - dbprintf(("%s: .....\n", debug_prefix(NULL))); + dbprintf(_("possible %s problem -- is \"%s\" really empty?\n"), + cmd, qdisk); + dbprintf(".....\n"); } - dbprintf(("%s: estimate size for %s level %d: " OFF_T_FMT " KB\n", - debug_prefix(NULL), + dbprintf(_("estimate size for %s level %d: %lld KB\n"), qamdevice, level, - size)); + (long long)size); kill(-dumppid, SIGTERM); - dbprintf(("%s: waiting for %s \"%s\" child\n", - debug_prefix_time(NULL), cmd, qdisk)); - wait(NULL); - dbprintf(("%s: after %s %s wait\n", - debug_prefix_time(NULL), cmd, qdisk)); + dbprintf(_("waiting for %s \"%s\" child\n"), cmd, qdisk); + waitpid(dumppid, &wait_status, 0); + if (WIFSIGNALED(wait_status)) { + *errmsg = vstrallocf(_("%s terminated with signal %d: see %s"), + cmd, WTERMSIG(wait_status), dbfn()); + } else if (WIFEXITED(wait_status)) { + if (WEXITSTATUS(wait_status) != 0) { + *errmsg = vstrallocf(_("%s exited with status %d: see %s"), cmd, + WEXITSTATUS(wait_status), dbfn()); + } else { + /* Normal exit */ + } + } else { + *errmsg = vstrallocf(_("%s got bad exit: see %s"), + cmd, dbfn()); + } + dbprintf(_("after %s %s wait\n"), cmd, qdisk); aclose(nullfd); afclose(dumpout); @@ -2167,7 +2321,7 @@ off_t handle_dumpline( char * str) { - regex_t *rp; + regex_scale_t *rp; double size; /* check for size match */