X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=server-src%2Fdriverio.c;h=8e41646bdc61a827295a86664d97e8d1c7288340;hb=691567b16c13087b31ee4c2b6d038e57872fae82;hp=04ed8527b451044c38e936f35f0f647e00697e09;hpb=310f09c0f55a2fb6f3f3746d6ded20099792b773;p=debian%2Famanda diff --git a/server-src/driverio.c b/server-src/driverio.c index 04ed852..8e41646 100644 --- a/server-src/driverio.c +++ b/server-src/driverio.c @@ -1,6 +1,7 @@ /* * Amanda, The Advanced Maryland Automatic Network Disk Archiver * Copyright (c) 1991-1998 University of Maryland at College Park + * Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved. * All Rights Reserved. * * Permission to use, copy, modify, distribute, and sell this software and its @@ -25,7 +26,7 @@ * University of Maryland at College Park */ /* - * $Id: driverio.c,v 1.92.2.2 2006/12/12 14:56:39 martinea Exp $ + * $Id: driverio.c,v 1.92 2006/08/24 01:57:16 paddy_s Exp $ * * I/O-related functions for driver program */ @@ -37,7 +38,7 @@ #include "diskfile.h" #include "infofile.h" #include "logfile.h" -#include "token.h" +#include "timestamp.h" #define GLOBAL /* the global variables defined here */ #include "driverio.h" @@ -51,7 +52,7 @@ init_driverio(void) { dumper_t *dumper; - taper = -1; + taper_fd = -1; for(dumper = dmptable; dumper < dmptable + MAX_DUMPERS; dumper++) { dumper->fd = -1; @@ -66,61 +67,94 @@ childstr( static char buf[NUM_STR_SIZE + 32]; dumper_t *dumper; - if (fd == taper) + if (fd == taper_fd) return ("taper"); for (dumper = dmptable; dumper < dmptable + MAX_DUMPERS; dumper++) { if (dumper->fd == fd) return (dumper->name); - if (dumper->chunker->fd == fd) + if (dumper->chunker && dumper->chunker->fd == fd) return (dumper->chunker->name); } - snprintf(buf, SIZEOF(buf), "unknown child (fd %d)", fd); + g_snprintf(buf, SIZEOF(buf), _("unknown child (fd %d)"), fd); return (buf); } void startup_tape_process( - char *taper_program) + char *taper_program, + int taper_parallel_write, + gboolean no_taper) { - int fd[2]; - char **config_options; + int fd[2]; + int i; + char **config_options; + taper_t *taper; + + /* always allocate the tapetable */ + tapetable = calloc(sizeof(taper_t), taper_parallel_write+1); + + for (taper = tapetable, i = 0; i < taper_parallel_write; taper++, i++) { + taper->name = g_strdup_printf("worker%d", i); + taper->sendresult = 0; + taper->input_error = NULL; + taper->tape_error = NULL; + taper->result = 0; + taper->dumper = NULL; + taper->disk = NULL; + taper->first_label = NULL; + taper->first_fileno = 0; + taper->state = TAPER_STATE_DEFAULT; + taper->left = 0; + taper->written = 0; + + /* jump right to degraded mode if there's no taper */ + if (no_taper) { + taper->tape_error = g_strdup("no taper started (--no-taper)"); + taper->result = BOGUS; + } + } + + /* don't start the taper if we're not supposed to */ + if (no_taper) + return; if(socketpair(AF_UNIX, SOCK_STREAM, 0, fd) == -1) { - error("taper pipe: %s", strerror(errno)); + error(_("taper pipe: %s"), strerror(errno)); /*NOTREACHED*/ } if(fd[0] < 0 || fd[0] >= (int)FD_SETSIZE) { - error("taper socketpair 0: descriptor %d out of range (0 .. %d)\n", - fd[0], FD_SETSIZE-1); + error(_("taper socketpair 0: descriptor %d out of range (0 .. %d)\n"), + fd[0], (int)FD_SETSIZE-1); /*NOTREACHED*/ } if(fd[1] < 0 || fd[1] >= (int)FD_SETSIZE) { - error("taper socketpair 1: descriptor %d out of range (0 .. %d)\n", - fd[1], FD_SETSIZE-1); + error(_("taper socketpair 1: descriptor %d out of range (0 .. %d)\n"), + fd[1], (int)FD_SETSIZE-1); /*NOTREACHED*/ } switch(taper_pid = fork()) { case -1: - error("fork taper: %s", strerror(errno)); + error(_("fork taper: %s"), strerror(errno)); /*NOTREACHED*/ case 0: /* child process */ aclose(fd[0]); if(dup2(fd[1], 0) == -1 || dup2(fd[1], 1) == -1) - error("taper dup2: %s", strerror(errno)); + error(_("taper dup2: %s"), strerror(errno)); config_options = get_config_options(2); config_options[0] = "taper"; - config_options[1] = config_name; + config_options[1] = get_config_name(); + safe_fd(-1, 0); execve(taper_program, config_options, safe_env()); error("exec %s: %s", taper_program, strerror(errno)); /*NOTREACHED*/ default: /* parent process */ aclose(fd[1]); - taper = fd[0]; + taper_fd = fd[0]; taper_ev_read = NULL; } } @@ -134,24 +168,25 @@ startup_dump_process( char **config_options; if(socketpair(AF_UNIX, SOCK_STREAM, 0, fd) == -1) { - error("%s pipe: %s", dumper->name, strerror(errno)); + error(_("%s pipe: %s"), dumper->name, strerror(errno)); /*NOTREACHED*/ } switch(dumper->pid = fork()) { case -1: - error("fork %s: %s", dumper->name, strerror(errno)); + error(_("fork %s: %s"), dumper->name, strerror(errno)); /*NOTREACHED*/ case 0: /* child process */ aclose(fd[0]); if(dup2(fd[1], 0) == -1 || dup2(fd[1], 1) == -1) - error("%s dup2: %s", dumper->name, strerror(errno)); + error(_("%s dup2: %s"), dumper->name, strerror(errno)); config_options = get_config_options(2); config_options[0] = dumper->name ? dumper->name : "dumper", - config_options[1] = config_name; + config_options[1] = get_config_name(); + safe_fd(-1, 0); execve(dumper_program, config_options, safe_env()); - error("exec %s (%s): %s", dumper_program, + error(_("exec %s (%s): %s"), dumper_program, dumper->name, strerror(errno)); /*NOTREACHED*/ @@ -161,7 +196,7 @@ startup_dump_process( dumper->ev_read = NULL; dumper->busy = dumper->down = 0; dumper->dp = NULL; - fprintf(stderr,"driver: started %s pid %u\n", + g_fprintf(stderr,_("driver: started %s pid %u\n"), dumper->name, (unsigned)dumper->pid); fflush(stderr); } @@ -178,7 +213,7 @@ startup_dump_processes( char number[NUM_STR_SIZE]; for(dumper = dmptable, i = 0; i < inparallel; dumper++, i++) { - snprintf(number, SIZEOF(number), "%d", i); + g_snprintf(number, SIZEOF(number), "%d", i); dumper->name = stralloc2("dumper", number); dumper->chunker = &chktable[i]; chktable[i].name = stralloc2("chunker", number); @@ -186,7 +221,7 @@ startup_dump_processes( chktable[i].fd = -1; startup_dump_process(dumper, dumper_program); - dumper_cmd(dumper, START, (void *)timestamp); + dumper_cmd(dumper, START, NULL, (void *)timestamp); } } @@ -199,26 +234,27 @@ startup_chunk_process( char **config_options; if(socketpair(AF_UNIX, SOCK_STREAM, 0, fd) == -1) { - error("%s pipe: %s", chunker->name, strerror(errno)); + error(_("%s pipe: %s"), chunker->name, strerror(errno)); /*NOTREACHED*/ } switch(chunker->pid = fork()) { case -1: - error("fork %s: %s", chunker->name, strerror(errno)); + error(_("fork %s: %s"), chunker->name, strerror(errno)); /*NOTREACHED*/ case 0: /* child process */ aclose(fd[0]); if(dup2(fd[1], 0) == -1 || dup2(fd[1], 1) == -1) { - error("%s dup2: %s", chunker->name, strerror(errno)); + error(_("%s dup2: %s"), chunker->name, strerror(errno)); /*NOTREACHED*/ } config_options = get_config_options(2); config_options[0] = chunker->name ? chunker->name : "chunker", - config_options[1] = config_name; + config_options[1] = get_config_name(); + safe_fd(-1, 0); execve(chunker_program, config_options, safe_env()); - error("exec %s (%s): %s", chunker_program, + error(_("exec %s (%s): %s"), chunker_program, chunker->name, strerror(errno)); /*NOTREACHED*/ @@ -227,7 +263,7 @@ startup_chunk_process( chunker->down = 0; chunker->fd = fd[0]; chunker->ev_read = NULL; - fprintf(stderr,"driver: started %s pid %u\n", + g_fprintf(stderr,_("driver: started %s pid %u\n"), chunker->name, (unsigned)chunker->pid); fflush(stderr); } @@ -238,54 +274,135 @@ getresult( int fd, int show, int *result_argc, - char **result_argv, - int max_arg) + char ***result_argv) { - int arg; cmd_t t; char *line; if((line = areads(fd)) == NULL) { if(errno) { - error("reading result from %s: %s", childstr(fd), strerror(errno)); - /*NOTREACHED*/ + g_fprintf(stderr, _("reading result from %s: %s"), childstr(fd), strerror(errno)); } + *result_argv = NULL; *result_argc = 0; /* EOF */ } else { - *result_argc = split(line, result_argv, max_arg, " "); + *result_argv = split_quoted_strings(line); + *result_argc = g_strv_length(*result_argv); } if(show) { - printf("driver: result time %s from %s:", + g_printf(_("driver: result time %s from %s:"), walltime_str(curclock()), childstr(fd)); if(line) { - for(arg = 1; arg <= *result_argc; arg++) { - printf(" %s", result_argv[arg]); - } + g_printf(" %s", line); putchar('\n'); } else { - printf(" (eof)\n"); + g_printf(" (eof)\n"); } fflush(stdout); } amfree(line); -#ifdef DEBUG - printf("argc = %d\n", *result_argc); - for(arg = 0; arg < *result_argc; arg++) - printf("argv[%d] = \"%s\"\n", arg, result_argv[arg]); -#endif - if(*result_argc < 1) return BOGUS; for(t = (cmd_t)(BOGUS+1); t < LAST_TOK; t++) - if(strcmp(result_argv[1], cmdstr[t]) == 0) return t; + if(strcmp((*result_argv)[0], cmdstr[t]) == 0) return t; return BOGUS; } +static char * +taper_splitting_args( + disk_t *dp) +{ + GString *args = NULL; + char *q = NULL; + dumptype_t *dt = dp->config; + tapetype_t *tt; + + tt = lookup_tapetype(getconf_str(CNF_TAPETYPE)); + g_assert(tt != NULL); + + args = g_string_new(""); + + /* old dumptype-based parameters, using empty strings when not seen */ + if (dt) { /* 'dt' may be NULL for flushes */ + if (dumptype_seen(dt, DUMPTYPE_TAPE_SPLITSIZE)) { + g_string_append_printf(args, "%ju ", + (uintmax_t)dumptype_get_tape_splitsize(dt)*1024); + } else { + g_string_append(args, "\"\" "); + } + + q = quote_string(dumptype_seen(dt, DUMPTYPE_SPLIT_DISKBUFFER)? + dumptype_get_split_diskbuffer(dt) : ""); + g_string_append_printf(args, "%s ", q); + g_free(q); + + if (dumptype_seen(dt, DUMPTYPE_FALLBACK_SPLITSIZE)) { + g_string_append_printf(args, "%ju ", + (uintmax_t)dumptype_get_fallback_splitsize(dt)*1024); + } else { + g_string_append(args, "\"\" "); + } + + if (dumptype_seen(dt, DUMPTYPE_ALLOW_SPLIT)) { + g_string_append_printf(args, "%d ", + (int)dumptype_get_allow_split(dt)); + } else { + g_string_append(args, "\"\" "); + } + } else { + g_string_append(args, "\"\" \"\" \"\" \"\" "); + } + + /* new tapetype-based parameters */ + if (tapetype_seen(tt, TAPETYPE_PART_SIZE)) { + g_string_append_printf(args, "%ju ", + (uintmax_t)tapetype_get_part_size(tt)*1024); + } else { + g_string_append(args, "\"\" "); + } + + q = ""; + if (tapetype_seen(tt, TAPETYPE_PART_CACHE_TYPE)) { + switch (tapetype_get_part_cache_type(tt)) { + default: + case PART_CACHE_TYPE_NONE: + q = "none"; + break; + + case PART_CACHE_TYPE_MEMORY: + q = "memory"; + break; + + case PART_CACHE_TYPE_DISK: + q = "disk"; + break; + } + } + q = quote_string(q); + g_string_append_printf(args, "%s ", q); + g_free(q); + + q = quote_string(tapetype_seen(tt, TAPETYPE_PART_CACHE_DIR)? + tapetype_get_part_cache_dir(tt) : ""); + g_string_append_printf(args, "%s ", q); + g_free(q); + + if (tapetype_seen(tt, TAPETYPE_PART_CACHE_MAX_SIZE)) { + g_string_append_printf(args, "%ju ", + (uintmax_t)tapetype_get_part_cache_max_size(tt)*1024); + } else { + g_string_append(args, "\"\" "); + } + + + return g_string_free(args, FALSE); +} + int taper_cmd( cmd_t cmd, @@ -296,96 +413,154 @@ taper_cmd( { char *cmdline = NULL; char number[NUM_STR_SIZE]; - char splitsize[NUM_STR_SIZE]; - char fallback_splitsize[NUM_STR_SIZE]; - char *diskbuffer = NULL; + char orig_kb[NUM_STR_SIZE]; + char *data_path; disk_t *dp; - char *features; char *qname; char *qdest; + char *q; + char *splitargs; + uintmax_t origsize; switch(cmd) { case START_TAPER: - cmdline = vstralloc(cmdstr[cmd], " ", (char *)ptr, "\n", NULL); + cmdline = vstralloc(cmdstr[cmd], + " ", destname, + " ", datestamp, + "\n", NULL); + break; + case CLOSE_VOLUME: + dp = (disk_t *) ptr; + cmdline = g_strjoin(NULL, cmdstr[cmd], + " ", sched(dp)->taper->name, + "\n", NULL); break; case FILE_WRITE: dp = (disk_t *) ptr; qname = quote_string(dp->name); qdest = quote_string(destname); - snprintf(number, SIZEOF(number), "%d", level); - snprintf(splitsize, SIZEOF(splitsize), OFF_T_FMT, - (OFF_T_FMT_TYPE)dp->tape_splitsize); - features = am_feature_to_string(dp->host->features); + g_snprintf(number, SIZEOF(number), "%d", level); + if (sched(dp)->origsize >= 0) + origsize = sched(dp)->origsize; + else + origsize = 0; + g_snprintf(orig_kb, SIZEOF(orig_kb), "%ju", origsize); + splitargs = taper_splitting_args(dp); cmdline = vstralloc(cmdstr[cmd], + " ", sched(dp)->taper->name, " ", disk2serial(dp), " ", qdest, " ", dp->host->hostname, - " ", features, " ", qname, " ", number, " ", datestamp, - " ", splitsize, + " ", splitargs, + orig_kb, "\n", NULL); - amfree(features); + amfree(splitargs); amfree(qdest); amfree(qname); break; + case PORT_WRITE: dp = (disk_t *) ptr; qname = quote_string(dp->name); - snprintf(number, SIZEOF(number), "%d", level); + g_snprintf(number, SIZEOF(number), "%d", level); + data_path = data_path_to_string(dp->data_path); /* If we haven't been given a place to buffer split dumps to disk, make the argument something besides and empty string so's taper won't get confused */ - if(!dp->split_diskbuffer || dp->split_diskbuffer[0] == '\0'){ - diskbuffer = "NULL"; - } else { - diskbuffer = dp->split_diskbuffer; - } - snprintf(splitsize, SIZEOF(splitsize), OFF_T_FMT, - (OFF_T_FMT_TYPE)dp->tape_splitsize); - snprintf(fallback_splitsize, SIZEOF(fallback_splitsize), OFF_T_FMT, - (OFF_T_FMT_TYPE)dp->fallback_splitsize); - features = am_feature_to_string(dp->host->features); + splitargs = taper_splitting_args(dp); cmdline = vstralloc(cmdstr[cmd], + " ", sched(dp)->taper->name, " ", disk2serial(dp), " ", dp->host->hostname, - " ", features, " ", qname, " ", number, " ", datestamp, - " ", splitsize, - " ", diskbuffer, - " ", fallback_splitsize, + " ", splitargs, + data_path, "\n", NULL); - amfree(features); + amfree(splitargs); amfree(qname); break; + case DONE: /* handle */ + dp = (disk_t *) ptr; + if (sched(dp)->origsize >= 0) + origsize = sched(dp)->origsize; + else + origsize = 0; + g_snprintf(number, SIZEOF(number), "%ju", origsize); + cmdline = vstralloc(cmdstr[cmd], + " ", sched(dp)->taper->name, + " ", disk2serial(dp), + " ", number, + "\n", NULL); + break; + case FAILED: /* handle */ + dp = (disk_t *) ptr; + cmdline = vstralloc(cmdstr[cmd], + " ", sched(dp)->taper->name, + " ", disk2serial(dp), + "\n", NULL); + break; + case NO_NEW_TAPE: + dp = (disk_t *) ptr; + q = quote_string(destname); /* reason why no new tape */ + cmdline = vstralloc(cmdstr[cmd], + " ", sched(dp)->taper->name, + " ", disk2serial(dp), + " ", q, + "\n", NULL); + amfree(q); + break; + case NEW_TAPE: + dp = (disk_t *) ptr; + cmdline = vstralloc(cmdstr[cmd], + " ", sched(dp)->taper->name, + " ", disk2serial(dp), + "\n", NULL); + break; + case START_SCAN: + dp = (disk_t *) ptr; + cmdline = vstralloc(cmdstr[cmd], + " ", sched(dp)->taper->name, + " ", disk2serial(dp), + "\n", NULL); + break; + case TAKE_SCRIBE_FROM: + dp = (disk_t *) ptr; + cmdline = vstralloc(cmdstr[cmd], + " ", sched(dp)->taper->name, + " ", disk2serial(dp), + " ", destname, /* name of worker */ + "\n", NULL); + break; case QUIT: cmdline = stralloc2(cmdstr[cmd], "\n"); break; default: - error("Don't know how to send %s command to taper", cmdstr[cmd]); + error(_("Don't know how to send %s command to taper"), cmdstr[cmd]); /*NOTREACHED*/ } /* * Note: cmdline already has a '\n'. */ - printf("driver: send-cmd time %s to taper: %s", + g_printf(_("driver: send-cmd time %s to taper: %s"), walltime_str(curclock()), cmdline); fflush(stdout); - if ((fullwrite(taper, cmdline, strlen(cmdline))) < 0) { - printf("writing taper command '%s' failed: %s\n", + if ((full_write(taper_fd, cmdline, strlen(cmdline))) < strlen(cmdline)) { + g_printf(_("writing taper command '%s' failed: %s\n"), cmdline, strerror(errno)); fflush(stdout); amfree(cmdline); return 0; } - if(cmd == QUIT) aclose(taper); + if(cmd == QUIT) aclose(taper_fd); amfree(cmdline); return 1; } @@ -394,20 +569,22 @@ int dumper_cmd( dumper_t *dumper, cmd_t cmd, - disk_t *dp) + disk_t *dp, + char *mesg) { char *cmdline = NULL; char number[NUM_STR_SIZE]; char numberport[NUM_STR_SIZE]; - char *o; + char maxwarnings[NUM_STR_SIZE]; + char *o, *oo; char *device; char *features; char *qname; - char *qdest; + char *qmesg; switch(cmd) { case START: - cmdline = vstralloc(cmdstr[cmd], " ", (char *)dp, "\n", NULL); + cmdline = vstralloc(cmdstr[cmd], " ", mesg, "\n", NULL); break; case PORT_DUMP: if(dp && dp->device) { @@ -418,16 +595,61 @@ dumper_cmd( } if (dp != NULL) { + application_t *application = NULL; + char *plugin; + char *qplugin; + char *qamandad_path; + char *qclient_username; + char *qclient_port; + char *qssh_keys; + char *d_prop; + + if (dp->application != NULL) { + application = lookup_application(dp->application); + g_assert(application != NULL); + } + device = quote_string((dp->device) ? dp->device : "NODEVICE"); qname = quote_string(dp->name); - snprintf(number, SIZEOF(number), "%d", sched(dp)->level); - snprintf(numberport, SIZEOF(numberport), "%d", dumper->output_port); + g_snprintf(number, SIZEOF(number), "%d", sched(dp)->level); + g_snprintf(numberport, SIZEOF(numberport), "%d", dumper->output_port); + g_snprintf(maxwarnings, SIZEOF(maxwarnings), "%d", dp->max_warnings); features = am_feature_to_string(dp->host->features); - o = optionstr(dp, dp->host->features, NULL); - if ( o == NULL ) { - error("problem with option string, check the dumptype definition.\n"); + if (am_has_feature(dp->host->features, fe_req_xml)) { + o = xml_optionstr(dp, 1); + + d_prop = xml_dumptype_properties(dp); + vstrextend(&o, d_prop, NULL); + amfree(d_prop); + + if (application) { + char *xml_app; + xml_app = xml_application(dp, application, + dp->host->features); + vstrextend(&o, xml_app, NULL); + amfree(xml_app); + } + oo = quote_string(o); + amfree(o); + o = oo; + } else { + o = optionstr(dp); + } + + g_assert(dp->program); + if (0 == strcmp(dp->program, "APPLICATION")) { + g_assert(application != NULL); + plugin = application_get_plugin(application); + } else { + plugin = dp->program; } - + qplugin = quote_string(plugin); + qamandad_path = quote_string(dp->amandad_path); + qclient_username = quote_string(dp->client_username); + qclient_port = quote_string(dp->client_port); + qssh_keys = quote_string(dp->ssh_keys); + dbprintf("security_driver %s\n", dp->auth); + cmdline = vstralloc(cmdstr[cmd], " ", disk2serial(dp), " ", numberport, @@ -437,35 +659,39 @@ dumper_cmd( " ", device, " ", number, " ", sched(dp)->dumpdate, - " ", dp->program, - " ", dp->amandad_path, - " ", dp->client_username, - " ", dp->ssh_keys, + " ", qplugin, + " ", qamandad_path, + " ", qclient_username, + " ", qclient_port, + " ", qssh_keys, + " ", dp->auth, + " ", data_path_to_string(dp->data_path), + " ", dp->dataport_list, + " ", maxwarnings, " |", o, "\n", NULL); + amfree(qplugin); + amfree(qamandad_path); + amfree(qclient_username); + amfree(qclient_port); + amfree(qssh_keys); amfree(features); amfree(o); amfree(qname); amfree(device); } else { - error("PORT-DUMP without disk pointer\n"); + error(_("PORT-DUMP without disk pointer\n")); /*NOTREACHED*/ } break; case QUIT: case ABORT: - if( dp ) { - qdest = quote_string(sched(dp)->destname); - cmdline = vstralloc(cmdstr[cmd], - " ", qdest, - "\n", NULL ); - amfree(qdest); - } else { - cmdline = stralloc2(cmdstr[cmd], "\n"); - } + qmesg = quote_string(mesg); + cmdline = vstralloc(cmdstr[cmd], " ", qmesg, "\n", NULL ); + amfree(qmesg); break; default: - error("Don't know how to send %s command to dumper", cmdstr[cmd]); + error(_("Don't know how to send %s command to dumper"), cmdstr[cmd]); /*NOTREACHED*/ } @@ -473,14 +699,14 @@ dumper_cmd( * Note: cmdline already has a '\n'. */ if(dumper->down) { - printf("driver: send-cmd time %s ignored to down dumper %s: %s", + g_printf(_("driver: send-cmd time %s ignored to down dumper %s: %s"), walltime_str(curclock()), dumper->name, cmdline); } else { - printf("driver: send-cmd time %s to %s: %s", + g_printf(_("driver: send-cmd time %s to %s: %s"), walltime_str(curclock()), dumper->name, cmdline); fflush(stdout); - if (fullwrite(dumper->fd, cmdline, strlen(cmdline)) < 0) { - printf("writing %s command: %s\n", dumper->name, strerror(errno)); + if (full_write(dumper->fd, cmdline, strlen(cmdline)) < strlen(cmdline)) { + g_printf(_("writing %s command: %s\n"), dumper->name, strerror(errno)); fflush(stdout); amfree(cmdline); return 0; @@ -495,7 +721,8 @@ int chunker_cmd( chunker_t *chunker, cmd_t cmd, - disk_t *dp) + disk_t *dp, + char *mesg) { char *cmdline = NULL; char number[NUM_STR_SIZE]; @@ -510,7 +737,7 @@ chunker_cmd( switch(cmd) { case START: - cmdline = vstralloc(cmdstr[cmd], " ", (char *)dp, "\n", NULL); + cmdline = vstralloc(cmdstr[cmd], " ", mesg, "\n", NULL); break; case PORT_WRITE: if(dp && sched(dp) && sched(dp)->holdp) { @@ -521,17 +748,14 @@ chunker_cmd( if (dp && h) { qname = quote_string(dp->name); qdest = quote_string(sched(dp)->destname); - holdalloc(h[activehd]->disk)->allocated_dumpers++; - snprintf(number, SIZEOF(number), "%d", sched(dp)->level); - snprintf(chunksize, SIZEOF(chunksize), OFF_T_FMT, - (OFF_T_FMT_TYPE)holdingdisk_get_chunksize(h[0]->disk)); - snprintf(use, SIZEOF(use), OFF_T_FMT, - (OFF_T_FMT_TYPE)h[0]->reserved); + h[activehd]->disk->allocated_dumpers++; + g_snprintf(number, SIZEOF(number), "%d", sched(dp)->level); + g_snprintf(chunksize, SIZEOF(chunksize), "%lld", + (long long)holdingdisk_get_chunksize(h[0]->disk->hdisk)); + g_snprintf(use, SIZEOF(use), "%lld", + (long long)h[0]->reserved); features = am_feature_to_string(dp->host->features); - o = optionstr(dp, dp->host->features, NULL); - if ( o == NULL ) { - error("problem with option string, check the dumptype definition.\n"); - } + o = optionstr(dp); cmdline = vstralloc(cmdstr[cmd], " ", disk2serial(dp), " ", qdest, @@ -550,7 +774,7 @@ chunker_cmd( amfree(qdest); amfree(qname); } else { - error("%s command without disk and holding disk.\n", + error(_("%s command without disk and holding disk.\n"), cmdstr[cmd]); /*NOTREACHED*/ } @@ -564,11 +788,11 @@ chunker_cmd( if(dp && h) { qname = quote_string(dp->name); qdest = quote_string(h[activehd]->destname); - holdalloc(h[activehd]->disk)->allocated_dumpers++; - snprintf(chunksize, SIZEOF(chunksize), OFF_T_FMT, - (OFF_T_FMT_TYPE)holdingdisk_get_chunksize(h[activehd]->disk)); - snprintf(use, SIZEOF(use), OFF_T_FMT, - (OFF_T_FMT_TYPE)(h[activehd]->reserved - h[activehd]->used)); + h[activehd]->disk->allocated_dumpers++; + g_snprintf(chunksize, SIZEOF(chunksize), "%lld", + (long long)holdingdisk_get_chunksize(h[activehd]->disk->hdisk)); + g_snprintf(use, SIZEOF(use), "%lld", + (long long)(h[activehd]->reserved - h[activehd]->used)); cmdline = vstralloc(cmdstr[cmd], " ", disk2serial(dp), " ", qdest, @@ -583,7 +807,11 @@ chunker_cmd( break; case QUIT: case ABORT: - cmdline = stralloc2(cmdstr[cmd], "\n"); + { + char *q = quote_string(mesg); + cmdline = vstralloc(cmdstr[cmd], " ", q, "\n", NULL); + amfree(q); + } break; case DONE: case FAILED: @@ -592,22 +820,22 @@ chunker_cmd( " ", disk2serial(dp), "\n", NULL); } else { - cmdline = vstralloc(cmdstr[cmd], "\n"); + cmdline = vstralloc(cmdstr[cmd], "\n", NULL); } break; default: - error("Don't know how to send %s command to chunker", cmdstr[cmd]); + error(_("Don't know how to send %s command to chunker"), cmdstr[cmd]); /*NOTREACHED*/ } /* * Note: cmdline already has a '\n'. */ - printf("driver: send-cmd time %s to %s: %s", + g_printf(_("driver: send-cmd time %s to %s: %s"), walltime_str(curclock()), chunker->name, cmdline); fflush(stdout); - if (fullwrite(chunker->fd, cmdline, strlen(cmdline)) < 0) { - printf("writing %s command: %s\n", chunker->name, strerror(errno)); + if (full_write(chunker->fd, cmdline, strlen(cmdline)) < strlen(cmdline)) { + g_printf(_("writing %s command: %s\n"), chunker->name, strerror(errno)); fflush(stdout); amfree(cmdline); return 0; @@ -617,7 +845,7 @@ chunker_cmd( return 1; } -#define MAX_SERIAL MAX_DUMPERS+1 /* one for the taper */ +#define MAX_SERIAL MAX_DUMPERS*2 /* one for each dumper and taper */ long generation = 1; @@ -635,14 +863,14 @@ serial2disk( rc = sscanf(str, "%d-%ld", &s, &gen); if(rc != 2) { - error("error [serial2disk \"%s\" parse error]", str); + error(_("error [serial2disk \"%s\" parse error]"), str); /*NOTREACHED*/ } else if (s < 0 || s >= MAX_SERIAL) { - error("error [serial out of range 0..%d: %d]", MAX_SERIAL, s); + error(_("error [serial out of range 0..%d: %d]"), MAX_SERIAL, s); /*NOTREACHED*/ } if(gen != stable[s].gen) - printf("driver: serial2disk error time %s serial gen mismatch %s\n", + g_printf(_("driver: serial2disk error time %s serial gen mismatch %s\n"), walltime_str(curclock()), str); return stable[s].dp; } @@ -654,17 +882,17 @@ free_serial( int rc, s; long gen; - rc = sscanf(str, "%d-%ld", &s, &gen); + rc = sscanf(str, _("%d-%ld"), &s, &gen); if(!(rc == 2 && s >= 0 && s < MAX_SERIAL)) { /* nuke self to get core dump for Brett */ - fprintf(stderr, "driver: free_serial: str \"%s\" rc %d s %d\n", + g_fprintf(stderr, _("driver: free_serial: str \"%s\" rc %d s %d\n"), str, rc, s); fflush(stderr); abort(); } if(gen != stable[s].gen) - printf("driver: free_serial error time %s serial gen mismatch %s\n", + g_printf(_("driver: free_serial error time %s serial gen mismatch %s\n"), walltime_str(curclock()),str); stable[s].gen = 0; stable[s].dp = NULL; @@ -685,8 +913,8 @@ free_serial_dp( } } - printf("driver: error time %s serial not found\n", - walltime_str(curclock())); + g_printf(_("driver: error time %s serial not found for disk %s\n"), + walltime_str(curclock()), dp->name); } @@ -698,7 +926,7 @@ check_unfree_serial(void) /* find used serial number */ for(s = 0; s < MAX_SERIAL; s++) { if(stable[s].gen != 0 || stable[s].dp != NULL) { - printf("driver: error time %s bug: serial in use: %02d-%05ld\n", + g_printf(_("driver: error time %s bug: serial in use: %02d-%05ld\n"), walltime_str(curclock()), s, stable[s].gen); } } @@ -712,7 +940,7 @@ char *disk2serial( for(s = 0; s < MAX_SERIAL; s++) { if(stable[s].dp == dp) { - snprintf(str, SIZEOF(str), "%02d-%05ld", s, stable[s].gen); + g_snprintf(str, SIZEOF(str), "%02d-%05ld", s, stable[s].gen); return str; } } @@ -722,7 +950,7 @@ char *disk2serial( if(stable[s].gen == 0 && stable[s].dp == NULL) break; if(s >= MAX_SERIAL) { - printf("driver: error time %s bug: out of serial numbers\n", + g_printf(_("driver: error time %s bug: out of serial numbers\n"), walltime_str(curclock())); s = 0; } @@ -730,7 +958,7 @@ char *disk2serial( stable[s].gen = generation++; stable[s].dp = dp; - snprintf(str, SIZEOF(str), "%02d-%05ld", s, stable[s].gen); + g_snprintf(str, SIZEOF(str), "%02d-%05ld", s, stable[s].gen); return str; } @@ -749,14 +977,9 @@ update_info_dumper( level = sched(dp)->level; - conf_infofile = getconf_str(CNF_INFOFILE); - if (*conf_infofile == '/') { - conf_infofile = stralloc(conf_infofile); - } else { - conf_infofile = stralloc2(config_dir, conf_infofile); - } + conf_infofile = config_dir_relative(getconf_str(CNF_INFOFILE)); if (open_infofile(conf_infofile)) { - error("could not open info db \"%s\"", conf_infofile); + error(_("could not open info db \"%s\""), conf_infofile); /*NOTREACHED*/ } amfree(conf_infofile); @@ -781,7 +1004,11 @@ update_info_dumper( infp->size = origsize; infp->csize = dumpsize; infp->secs = dumptime; - infp->date = sched(dp)->timestamp; + if (sched(dp)->timestamp == 0) { + infp->date = 0; + } else { + infp->date = get_time_from_timestamp(sched(dp)->datestamp); + } if(level == 0) perfp = &info.full; else perfp = &info.incr; @@ -797,13 +1024,13 @@ update_info_dumper( newperf(perfp->rate, (double)dumpsize/(double)dumptime); } - if(getconf_int(CNF_RESERVE)<100) { + if(origsize >= (off_t)0 && getconf_int(CNF_RESERVE)<100) { info.command = NO_COMMAND; } - if(level == info.last_level) + if (origsize >= (off_t)0 && level == info.last_level) { info.consecutive_runs++; - else { + } else if (origsize >= (off_t)0) { info.last_level = level; info.consecutive_runs = 1; } @@ -816,12 +1043,22 @@ update_info_dumper( info.history[0].level = level; info.history[0].size = origsize; info.history[0].csize = dumpsize; - info.history[0].date = sched(dp)->timestamp; + if (sched(dp)->timestamp == 0) { + info.history[0].date = 0; + } else { + info.history[0].date = get_time_from_timestamp(sched(dp)->datestamp); + } info.history[0].secs = dumptime; } - if(put_info(dp->host->hostname, dp->name, &info)) { - error("infofile update failed (%s,'%s')\n", dp->host->hostname, dp->name); + if (put_info(dp->host->hostname, dp->name, &info)) { + int save_errno = errno; + g_fprintf(stderr, _("infofile update failed (%s,'%s'): %s\n"), + dp->host->hostname, dp->name, strerror(save_errno)); + log_add(L_ERROR, _("infofile update failed (%s,'%s'): %s\n"), + dp->host->hostname, dp->name, strerror(save_errno)); + error(_("infofile update failed (%s,'%s'): %s\n"), + dp->host->hostname, dp->name, strerror(save_errno)); /*NOTREACHED*/ } @@ -841,7 +1078,7 @@ update_info_taper( rc = open_infofile(getconf_str(CNF_INFOFILE)); if(rc) { - error("could not open infofile %s: %s (%d)", getconf_str(CNF_INFOFILE), + error(_("could not open infofile %s: %s (%d)"), getconf_str(CNF_INFOFILE), strerror(errno), rc); /*NOTREACHED*/ } @@ -856,8 +1093,14 @@ update_info_taper( info.command = NO_COMMAND; - if(put_info(dp->host->hostname, dp->name, &info)) { - error("infofile update failed (%s,'%s')\n", dp->host->hostname, dp->name); + if (put_info(dp->host->hostname, dp->name, &info)) { + int save_errno = errno; + g_fprintf(stderr, _("infofile update failed (%s,'%s'): %s\n"), + dp->host->hostname, dp->name, strerror(save_errno)); + log_add(L_ERROR, _("infofile update failed (%s,'%s'): %s\n"), + dp->host->hostname, dp->name, strerror(save_errno)); + error(_("infofile update failed (%s,'%s'): %s\n"), + dp->host->hostname, dp->name, strerror(save_errno)); /*NOTREACHED*/ } close_infofile();