X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=server-src%2Finfofile.c;h=8df21b93acf6500f742e877a45cc132c0e566fb7;hb=HEAD;hp=ae41ff61940dc414b33afe63e712177b0df7672c;hpb=3ab887b9bc819a846c75dd7f2ee5d41fac22b19f;p=debian%2Famanda diff --git a/server-src/infofile.c b/server-src/infofile.c index ae41ff6..8df21b9 100644 --- a/server-src/infofile.c +++ b/server-src/infofile.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,56 +26,57 @@ * University of Maryland at College Park */ /* - * $Id: infofile.c,v 1.44.4.4 1999/11/10 14:36:10 oliva Exp $ + * $Id: infofile.c,v 1.64 2006/07/25 18:18:48 martinea Exp $ * * manage current info file */ #include "amanda.h" #include "conffile.h" #include "infofile.h" -#include "token.h" +#include "util.h" -#ifdef TEXTDB - static char *infodir = (char *)0; - static char *infofile = (char *)0; +static void zero_info(info_t *); + + static char *infodir = NULL; + static char *infofile = NULL; static char *newinfofile; static int writing; -#else -# define MAX_KEY 256 -/*# define HEADER (sizeof(info_t)-DUMP_LEVELS*sizeof(stats_t))*/ - - static DBM *infodb = NULL; - static lockfd = -1; -#endif - -#ifdef TEXTDB -FILE *open_txinfofile(host, disk, mode) -char *host; -char *disk; -char *mode; + static FILE *open_txinfofile(char *, char *, char *); + static int close_txinfofile(FILE *); + static int read_txinfofile(FILE *, info_t *); + static int write_txinfofile(FILE *, info_t *); + static int delete_txinfofile(char *, char *); + +static FILE * +open_txinfofile( + char * host, + char * disk, + char * mode) { FILE *infof; + char *myhost; + char *mydisk; assert(infofile == (char *)0); writing = (*mode == 'w'); - host = sanitise_filename(host); - disk = sanitise_filename(disk); + myhost = sanitise_filename(host); + mydisk = sanitise_filename(disk); infofile = vstralloc(infodir, - "/", host, - "/", disk, + "/", myhost, + "/", mydisk, "/info", NULL); - amfree(host); - amfree(disk); + amfree(myhost); + amfree(mydisk); /* create the directory structure if in write mode */ if (writing) { - if (mkpdir(infofile, 02755, (uid_t)-1, (gid_t)-1) == -1) { + if (mkpdir(infofile, 0755, (uid_t)-1, (gid_t)-1) == -1) { amfree(infofile); return NULL; } @@ -101,8 +103,9 @@ char *mode; return infof; } -int close_txinfofile(infof) -FILE *infof; +static int +close_txinfofile( + FILE *infof) { int rc = 0; @@ -124,9 +127,11 @@ FILE *infof; return rc; } -int read_txinfofile(infof, info) /* XXX - code assumes AVG_COUNT == 3 */ -FILE *infof; -info_t *info; +/* XXX - code assumes AVG_COUNT == 3 */ +static int +read_txinfofile( + FILE * infof, + info_t * info) { char *line = NULL; int version; @@ -134,16 +139,28 @@ info_t *info; perf_t *pp; char *s; int ch; + int nb_history; + int i; /* get version: command: lines */ - if((line = agets(infof)) == NULL) return -1; - rc = sscanf(line, "version: %d", &version); + while ((line = agets(infof)) != NULL) { + if (line[0] != '\0') + break; + amfree(line); + } + if (line == NULL) return -1; + rc = sscanf(line, _("version: %d"), &version); amfree(line); if(rc != 1) return -2; - if((line = agets(infof)) == NULL) return -1; - rc = sscanf(line, "command: %d", &info->command); + while ((line = agets(infof)) != NULL) { + if (line[0] != '\0') + break; + amfree(line); + } + if (line == NULL) return -1; + rc = sscanf(line, _("command: %u"), &info->command); amfree(line); if(rc != 1) return -2; @@ -151,14 +168,24 @@ info_t *info; pp = &info->full; - if((line = agets(infof)) == NULL) return -1; - rc = sscanf(line, "full-rate: %f %f %f", + while ((line = agets(infof)) != NULL) { + if (line[0] != '\0') + break; + amfree(line); + } + if (line == NULL) return -1; + rc = sscanf(line, "full-rate: %lf %lf %lf", &pp->rate[0], &pp->rate[1], &pp->rate[2]); amfree(line); if(rc > 3) return -2; - if((line = agets(infof)) == NULL) return -1; - rc = sscanf(line, "full-comp: %f %f %f", + while ((line = agets(infof)) != NULL) { + if (line[0] != '\0') + break; + amfree(line); + } + if (line == NULL) return -1; + rc = sscanf(line, "full-comp: %lf %lf %lf", &pp->comp[0], &pp->comp[1], &pp->comp[2]); amfree(line); if(rc > 3) return -2; @@ -167,14 +194,24 @@ info_t *info; pp = &info->incr; - if((line = agets(infof)) == NULL) return -1; - rc = sscanf(line, "incr-rate: %f %f %f", + while ((line = agets(infof)) != NULL) { + if (line[0] != '\0') + break; + amfree(line); + } + if (line == NULL) return -1; + rc = sscanf(line, "incr-rate: %lf %lf %lf", &pp->rate[0], &pp->rate[1], &pp->rate[2]); amfree(line); if(rc > 3) return -2; - if((line = agets(infof)) == NULL) return -1; - rc = sscanf(line, "incr-comp: %f %f %f", + while ((line = agets(infof)) != NULL) { + if (line[0] != '\0') + break; + amfree(line); + } + if (line == NULL) return -1; + rc = sscanf(line, "incr-comp: %lf %lf %lf", &pp->comp[0], &pp->comp[1], &pp->comp[2]); amfree(line); if(rc > 3) return -2; @@ -183,78 +220,85 @@ info_t *info; for(rc = -2; (line = agets(infof)) != NULL; free(line)) { stats_t onestat; /* one stat record */ - long date; - int level; + int level = 0; + long long off_t_tmp; + if (line[0] == '\0') + continue; if(line[0] == '/' && line[1] == '/') { rc = 0; amfree(line); return 0; /* normal end of record */ } - else if (strncmp(line,"last_level:",11) == 0) { + else if (strncmp_const(line,"last_level:") == 0) { break; /* normal */ } - memset(&onestat, 0, sizeof(onestat)); + else if (strncmp_const(line,"history:") == 0) { + break; /* normal */ + } + memset(&onestat, 0, SIZEOF(onestat)); s = line; ch = *s++; -#define sc "stats:" - if(strncmp(line, sc, sizeof(sc)-1) != 0) { - break; + /* from here on, we had better be parsing a 'stats' line */ + if(strncmp_const_skip(line, "stats:", s, ch) != 0) { + return -1; } - s += sizeof(sc)-1; - ch = s[-1]; -#undef sc skip_whitespace(s, ch); if(ch == '\0' || sscanf((s - 1), "%d", &level) != 1) { - break; + return -1; } skip_integer(s, ch); skip_whitespace(s, ch); - if(ch == '\0' || sscanf((s - 1), "%ld", &onestat.size) != 1) { - break; + if(ch == '\0' || sscanf((s - 1), "%lld", &off_t_tmp) != 1) { + return -1; } + onestat.size = (off_t)off_t_tmp; skip_integer(s, ch); skip_whitespace(s, ch); - if(ch == '\0' || sscanf((s - 1), "%ld", &onestat.csize) != 1) { - break; + if(ch == '\0' || sscanf((s - 1), "%lld", &off_t_tmp) != 1) { + return -1; } + onestat.csize = (off_t)off_t_tmp; skip_integer(s, ch); + /* assume that the time fits in a long long */ skip_whitespace(s, ch); - if(ch == '\0' || sscanf((s - 1), "%ld", &onestat.secs) != 1) { - break; + if(ch == '\0' || sscanf((s - 1), "%lld", &off_t_tmp) != 1) { + return -1; } + onestat.secs = (time_t)off_t_tmp; skip_integer(s, ch); skip_whitespace(s, ch); - if(ch == '\0' || sscanf((s - 1), "%ld", &date) != 1) { - break; + if(ch == '\0' || sscanf((s - 1), "%lld", &off_t_tmp) != 1) { + return -1; } + onestat.date = (time_t)off_t_tmp; skip_integer(s, ch); skip_whitespace(s, ch); if(ch != '\0') { - if(sscanf((s - 1), "%d", &onestat.filenum) != 1) { - break; + if(sscanf((s - 1), "%lld", &off_t_tmp) != 1) { + return -1; } + onestat.filenum = (off_t)off_t_tmp; skip_integer(s, ch); skip_whitespace(s, ch); if(ch == '\0') { - break; + return -1; } - strncpy(onestat.label, s-1, sizeof(onestat.label)-1); - onestat.label[sizeof(onestat.label)-1] = '\0'; + strncpy(onestat.label, s-1, SIZEOF(onestat.label)-1); + onestat.label[SIZEOF(onestat.label)-1] = '\0'; } - onestat.date = date; /* time_t not guarranteed to be long */ - - if(level < 0 || level > DUMP_LEVELS-1) break; + if(level < 0 || level > DUMP_LEVELS-1) + return -1; info->inf[level] = onestat; } @@ -263,94 +307,187 @@ info_t *info; rc = sscanf(line, "last_level: %d %d", &info->last_level, &info->consecutive_runs); - + amfree(line); if(rc > 2) return -2; rc = 0; - if((line = agets(infof)) == NULL) return -1; + nb_history = 0; + for(i=0;i<=NB_HISTORY;i++) { + info->history[i].level = -2; + } + + for(rc = -2; (line = agets(infof)) != NULL; free(line)) { + history_t onehistory; /* one history record */ + long long off_t_tmp; + + if (line[0] == '\0') + continue; + if(line[0] == '/' && line[1] == '/') { + info->history[nb_history].level = -2; + rc = 0; + amfree(line); + return 0; /* normal end of record */ + } + + memset(&onehistory, 0, SIZEOF(onehistory)); + + s = line; + ch = *s++; + + if(strncmp_const_skip(line, "history:", s, ch) != 0) { + amfree(line); + break; + } + + skip_whitespace(s, ch); + if(ch == '\0' || sscanf((s - 1), "%d", &onehistory.level) != 1) { + amfree(line); + break; + } + skip_integer(s, ch); + + skip_whitespace(s, ch); + if(ch == '\0' || sscanf((s - 1), "%lld", &off_t_tmp) != 1) { + amfree(line); + break; + } + onehistory.size = (off_t)off_t_tmp; + skip_integer(s, ch); + + skip_whitespace(s, ch); + if(ch == '\0' || sscanf((s - 1), "%lld", &off_t_tmp) != 1) { + amfree(line); + break; + } + onehistory.csize = (off_t)off_t_tmp; + skip_integer(s, ch); + + skip_whitespace(s, ch); + if(ch == '\0' || sscanf((s - 1), "%lld", &off_t_tmp) != 1) { + amfree(line); + break; + } + onehistory.date = (time_t)off_t_tmp; + skip_integer(s, ch); + + onehistory.secs = (unsigned long)-1; + skip_whitespace(s, ch); + if(ch != '\0') { + if(sscanf((s - 1), "%lld", &off_t_tmp) != 1) { + amfree(line); + break; + } + onehistory.secs = (time_t)off_t_tmp; + skip_integer(s, ch); + } + + info->history[nb_history++] = onehistory; + } + amfree(line); + + while ((line = agets(infof)) != NULL) { + if (line[0] != '\0') + break; + amfree(line); + } + if (line == NULL) return -1; amfree(line); return rc; } -int write_txinfofile(infof, info) -FILE *infof; -info_t *info; +static int +write_txinfofile( + FILE * infof, + info_t * info) { int i; stats_t *sp; perf_t *pp; int level; - fprintf(infof, "version: %d\n", 0); + g_fprintf(infof, _("version: %d\n"), 0); - fprintf(infof, "command: %d\n", info->command); + g_fprintf(infof, _("command: %u\n"), info->command); pp = &info->full; - fprintf(infof, "full-rate:"); + g_fprintf(infof, "full-rate:"); for(i=0; irate[i] >= 0.0) - fprintf(infof, " %f", pp->rate[i]); - fprintf(infof, "\n"); + g_fprintf(infof, " %lf", pp->rate[i]); + g_fprintf(infof, "\n"); - fprintf(infof, "full-comp:"); + g_fprintf(infof, "full-comp:"); for(i=0; icomp[i] >= 0.0) - fprintf(infof, " %f", pp->comp[i]); - fprintf(infof, "\n"); + g_fprintf(infof, " %lf", pp->comp[i]); + g_fprintf(infof, "\n"); pp = &info->incr; - fprintf(infof, "incr-rate:"); + g_fprintf(infof, "incr-rate:"); for(i=0; irate[i] >= 0.0) - fprintf(infof, " %f", pp->rate[i]); - fprintf(infof, "\n"); + g_fprintf(infof, " %lf", pp->rate[i]); + g_fprintf(infof, "\n"); - fprintf(infof, "incr-comp:"); + g_fprintf(infof, "incr-comp:"); for(i=0; icomp[i] >= 0.0) - fprintf(infof, " %f", pp->comp[i]); - fprintf(infof, "\n"); + g_fprintf(infof, " %lf", pp->comp[i]); + g_fprintf(infof, "\n"); for(level=0; levelinf[level]; if(sp->date < (time_t)0 && sp->label[0] == '\0') continue; - fprintf(infof, "stats: %d %ld %ld %ld %ld", level, - sp->size, sp->csize, sp->secs, (long)sp->date); + g_fprintf(infof, "stats: %d %lld %lld %jd %lld", + level, (long long)sp->size, (long long)sp->csize, + (intmax_t)sp->secs, (long long)sp->date); if(sp->label[0] != '\0') - fprintf(infof, " %d %s", sp->filenum, sp->label); - fprintf(infof, "\n"); + g_fprintf(infof, " %lld %s", (long long)sp->filenum, sp->label); + g_fprintf(infof, "\n"); } - fprintf(infof, "last_level: %d %d\n", info->last_level, info->consecutive_runs); - fprintf(infof, "//\n"); + g_fprintf(infof, _("last_level: %d %d\n"), info->last_level, info->consecutive_runs); + + for(i=0;info->history[i].level > -1;i++) { + g_fprintf(infof, _("history: %d %lld %lld %jd %jd\n"), + info->history[i].level, + (long long)info->history[i].size, + (long long)info->history[i].csize, + (intmax_t)info->history[i].date, + (intmax_t)info->history[i].secs); + } + g_fprintf(infof, "//\n"); return 0; } -int delete_txinfofile(host, disk) -char *host; -char *disk; +static int +delete_txinfofile( + char * host, + char * disk) { char *fn = NULL, *fn_new = NULL; int rc; + char *myhost; + char *mydisk; - host = sanitise_filename(host); - disk = sanitise_filename(disk); + myhost = sanitise_filename(host); + mydisk = sanitise_filename(disk); fn = vstralloc(infodir, - "/", host, - "/", disk, + "/", myhost, + "/", mydisk, "/info", NULL); fn_new = stralloc2(fn, ".new"); - amfree(host); - amfree(disk); + amfree(myhost); + amfree(mydisk); unlink(fn_new); amfree(fn_new); @@ -360,68 +497,31 @@ char *disk; return rc; } -#endif - -#ifndef TEXTDB -static char *lockname = NULL; -#endif -int open_infofile(filename) -char *filename; +int +open_infofile( + char * filename) { -#ifdef TEXTDB - assert(infodir == (char *)0); + assert(infodir == NULL); infodir = stralloc(filename); return 0; /* success! */ -#else - /* lock the dbm file */ - - lockname = newstralloc2(lockname, filename, ".lck"); - if((lockfd = open(lockname, O_CREAT|O_RDWR, 0644)) == -1) - return 2; - - if(amflock(lockfd, "info") == -1) { - aclose(lockfd); - unlink(lockname); - return 3; - } - - if(!(infodb = dbm_open(filename, O_CREAT|O_RDWR, 0644))) { - amfunlock(lockfd, "info"); - aclose(lockfd); - unlink(lockname); - return 1; - } - - return (infodb == NULL); /* return 1 on error */ -#endif } -void close_infofile() +void +close_infofile(void) { -#ifdef TEXTDB - assert(infodir != (char *)0); + assert(infodir != NULL); amfree(infodir); -#else - dbm_close(infodb); - - if(amfunlock(lockfd, "info") == -1) - error("could not unlock infofile: %s", strerror(errno)); - - aclose(lockfd); - lockfd = -1; - - unlink(lockname); -#endif } /* Convert a dump level to a GMT based time stamp */ -char *get_dumpdate(info, lev) -info_t *info; -int lev; +char * +get_dumpdate( + info_t * info, + int lev) { static char stamp[20]; /* YYYY:MM:DD:hh:mm:ss */ int l; @@ -436,17 +536,20 @@ int lev; } t = gmtime(&last); - ap_snprintf(stamp, sizeof(stamp), "%d:%d:%d:%d:%d:%d", + g_snprintf(stamp, SIZEOF(stamp), "%d:%d:%d:%d:%d:%d", t->tm_year+1900, t->tm_mon+1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); return stamp; } -double perf_average(a, d) -/* Weighted average */ -float *a; /* array of items to average */ -double d; /* default value */ +/* + * Weighted average + */ +double +perf_average( + double * a, /* array of items to average */ + double d) /* default value */ { double sum; /* running total */ int n; /* number of items in sum */ @@ -468,12 +571,13 @@ double d; /* default value */ return sum / n; } -void zero_info(info) -info_t *info; +static void +zero_info( + info_t *info) { int i; - memset(info, '\0', sizeof(info_t)); + memset(info, '\0', SIZEOF(info_t)); for(i = 0; i < AVG_COUNT; i++) { info->full.comp[i] = info->incr.comp[i] = -1.0; @@ -487,19 +591,26 @@ info_t *info; info->last_level = -1; info->consecutive_runs = -1; + for(i=0;i<=NB_HISTORY;i++) { + info->history[i].level = -2; + info->history[i].size = (off_t)0; + info->history[i].csize = (off_t)0; + info->history[i].date = 0UL; + } return; } -int get_info(hostname, diskname, info) -char *hostname, *diskname; -info_t *info; +int +get_info( + char * hostname, + char * diskname, + info_t * info) { int rc; (void) zero_info(info); { -#ifdef TEXTDB FILE *infof; infof = open_txinfofile(hostname, diskname, "r"); @@ -512,123 +623,18 @@ info_t *info; close_txinfofile(infof); } -#else - datum k, d; - - /* setup key */ - - k.dptr = vstralloc(hostname, ":", diskname, NULL); - k.dsize = strlen(k.dptr)+1; - - /* lookup record */ - - d = dbm_fetch(infodb, k); - amfree(k.dptr); - if(d.dptr == NULL) { - rc = -1; /* record not found */ - } - else { - memcpy(info, d.dptr, d.dsize); - rc = 0; - } -#endif } return rc; } -int get_firstkey(hostname, hostname_size, diskname, diskname_size) -char *hostname, *diskname; -int hostname_size, diskname_size; -{ -#ifdef TEXTDB - assert(0); - return 0; -#else - datum k; - int rc; - char *s, *fp; - int ch; - - k = dbm_firstkey(infodb); - if(k.dptr == NULL) return 0; - - s = k.dptr; - ch = *s++; - - skip_whitespace(s, ch); - if(ch == '\0') return 0; - fp = hostname; - while(ch && ch != ':') { - if(fp >= hostname+hostname_size-1) { - fp = NULL; - break; - } - *fp = ch; - ch = *s++; - } - if(fp == NULL) return 0; - *fp = '\0'; - - if(ch != ':') return 0; - ch = *s++; - copy_string(s, ch, diskname, diskname_size, fp); - if(fp == NULL) return 0; - - return 1; -#endif -} - - -int get_nextkey(hostname, hostname_size, diskname, diskname_size) -char *hostname, *diskname; -int hostname_size, diskname_size; -{ -#ifdef TEXTDB - assert(0); - return 0; -#else - datum k; - int rc; - char *s, *fp; - int ch; - - k = dbm_nextkey(infodb); - if(k.dptr == NULL) return 0; - - s = k.dptr; - ch = *s++; - - skip_whitespace(s, ch); - if(ch == '\0') return 0; - fp = hostname; - while(ch && ch != ':') { - if(fp >= hostname+hostname_size-1) { - fp = NULL; - break; - } - *fp = ch; - ch = *s++; - } - if(fp == NULL) return 0; - *fp = '\0'; - - if(ch != ':') return 0; - ch = *s++; - copy_string(s, ch, diskname, diskname_size, fp); - if(fp == NULL) return 0; - - return 1; -#endif -} - - -int put_info(hostname, diskname, info) - char *hostname, *diskname; - info_t *info; +int +put_info( + char * hostname, + char * diskname, + info_t * info) { -#ifdef TEXTDB FILE *infof; int rc; @@ -641,90 +647,57 @@ int put_info(hostname, diskname, info) rc = rc || close_txinfofile(infof); return rc; -#else - datum k, d; - int maxlev; - - /* setup key */ - - k.dptr = vstralloc(hostname, ":", diskname, NULL); - k.dsize = strlen(k.dptr)+1; - - d.dptr = (char *)info; - d.dsize = sizeof(info_t); - - /* store record */ - - if(dbm_store(infodb, k, d, DBM_REPLACE) != 0) { - amfree(k.dptr); - return -1; - } - - amfree(k.dptr); - return 0; -#endif } -int del_info(hostname, diskname) -char *hostname, *diskname; +int +del_info( + char * hostname, + char * diskname) { -#ifdef TEXTDB return delete_txinfofile(hostname, diskname); -#else - char key[MAX_KEY]; - datum k; - - /* setup key */ - - k.dptr = vstralloc(hostname, ":", diskname, NULL); - k.dsize = strlen(key)+1; - - /* delete key and record */ - - if(dbm_delete(infodb, k) != 0) { - amfree(k.dptr); - return -1; - } - amfree(k.dptr); - return 0; -#endif } #ifdef TEST -void dump_rec(info) -info_t *info; +void dump_rec(info_t *info); + +void +dump_rec( + info_t * info) { int i; stats_t *sp; - printf("command word: %d\n", info->command); - printf("full dump rate (K/s) %5.1f, %5.1f, %5.1f\n", + g_printf(_("command word: %d\n"), info->command); + g_printf(_("full dump rate (K/s) %5.1lf, %5.1lf, %5.1lf\n"), info->full.rate[0],info->full.rate[1],info->full.rate[2]); - printf("full comp rate %5.1f, %5.1f, %5.1f\n", + g_printf(_("full comp rate %5.1lf, %5.1lf, %5.1lf\n"), info->full.comp[0]*100,info->full.comp[1]*100,info->full.comp[2]*100); - printf("incr dump rate (K/s) %5.1f, %5.1f, %5.1f\n", + g_printf(_("incr dump rate (K/s) %5.1lf, %5.1lf, %5.1lf\n"), info->incr.rate[0],info->incr.rate[1],info->incr.rate[2]); - printf("incr comp rate %5.1f, %5.1f, %5.1f\n", + g_printf(_("incr comp rate %5.1lf, %5.1lf, %5.1lf\n"), info->incr.comp[0]*100,info->incr.comp[1]*100,info->incr.comp[2]*100); for(i = 0; i < DUMP_LEVELS; i++) { sp = &info->inf[i]; if( sp->size != -1) { - printf("lev %d date %ld tape %s filenum %d size %ld csize %ld secs %ld\n", + g_printf(_("lev %d date %ld tape %s filenum %lld size %ld csize %ld secs %ld\n"), i, (long)sp->date, sp->label, sp->filenum, sp->size, sp->csize, sp->secs); } } putchar('\n'); - printf("last_level: %d %d\n", info->last_level, info->consecutive_runs); + g_printf(_("last_level: %d %d\n"), info->last_level, info->consecutive_runs); } -#ifdef TEXTDB -void dump_db(host, disk) -char *host, *disk; +void dump_db( char *host, char *disk); + +void +dump_db( + char * host, + char * disk) { info_t info; int rc; @@ -732,85 +705,44 @@ char *host, *disk; if((rc = get_info(host, disk, &info)) == 0) { dump_rec(&info); } else { - printf("cannot fetch information for %s:%s rc=%d\n", host, disk, rc); + g_printf(_("cannot fetch information for %s:%s rc=%d\n"), host, disk, rc); } } -#else -void dump_db(str) -char *str; -{ - datum k,d; - int rec,r,num; - info_t info; - - - printf("info database %s:\n--------\n", str); - rec = 0; - k = dbm_firstkey(infodb); - while(k.dptr != NULL) { - - printf("%3d: KEY %s =\n", rec, k.dptr); - - d = dbm_fetch(infodb, k); - memset(&info, '\0', sizeof(info)); - memcpy(&info, d.dptr, d.dsize); - - num = (d.dsize-HEADER)/sizeof(stats_t); - dump_rec(&info); - - k = dbm_nextkey(infodb); - rec++; - } - puts("--------\n"); -} -#endif int -main(argc, argv) -int argc; -char *argv[]; +main( + int argc, + char ** argv) { int i; - int fd; - unsigned long malloc_hist_1, malloc_size_1; - unsigned long malloc_hist_2, malloc_size_2; - - for(fd = 3; fd < FD_SETSIZE; fd++) { - /* - * Make sure nobody spoofs us with a lot of extra open files - * that would cause an open we do to get a very high file - * descriptor, which in turn might be used as an index into - * an array (e.g. an fd_set). - */ - close(fd); - } + + /* + * 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); set_pname("infofile"); - malloc_size_1 = malloc_inuse(&malloc_hist_1); + dbopen(DBG_SUBDIR_SERVER); for(i = 1; i < argc; ++i) { -#ifdef TEXTDB if(i+1 >= argc) { - fprintf(stderr,"usage: %s host disk [host disk ...]\n",argv[0]); + g_fprintf(stderr,_("usage: %s host disk [host disk ...]\n"),argv[0]); return 1; } open_infofile("curinfo"); dump_db(argv[i], argv[i+1]); i++; -#else - open_infofile(argv[i]); - dump_db(argv[i]); -#endif close_infofile(); } - malloc_size_2 = malloc_inuse(&malloc_hist_2); - - if(malloc_size_1 != malloc_size_2) { - malloc_list(fileno(stderr), malloc_hist_1, malloc_hist_2); - } - + dbclose(); return 0; }