X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=server-src%2Famtrmidx.c;h=681e4ab088ad11eedc33e033a9d69d3faf878d18;hb=eefb15c5c04acb3c75f0c704ea664feb1bbae75c;hp=19e2c57ec1a712f86642fc6fa46dcf06f42663fe;hpb=c9bb64dd8260123d77b6f7be0f051f450b193e66;p=debian%2Famanda diff --git a/server-src/amtrmidx.c b/server-src/amtrmidx.c index 19e2c57..681e4ab 100644 --- a/server-src/amtrmidx.c +++ b/server-src/amtrmidx.c @@ -24,7 +24,7 @@ * file named AUTHORS, in the root directory of this distribution. */ /* - * $Id: amtrmidx.c,v 1.21.4.1.4.2.2.5.2.1 2004/02/12 18:28:37 martinea Exp $ + * $Id: amtrmidx.c,v 1.34 2006/01/14 04:37:19 paddy_s Exp $ * * trims number of index files to only those still in system. Well * actually, it keeps a few extra, plus goes back to the last level 0 @@ -43,8 +43,8 @@ #include "version.h" static int sort_by_name_reversed(a, b) -const void *a; -const void *b; + const void *a; + const void *b; { char **ap = (char **) a; char **bp = (char **) b; @@ -52,36 +52,31 @@ const void *b; return -1 * strcmp(*ap, *bp); } +int main P((int, char **)); + int main(argc, argv) int argc; char **argv; { disk_t *diskp; - disklist_t *diskl; + disklist_t diskl; int i; char *conffile; char *conf_diskfile; char *conf_tapelist; char *conf_indexdir; - int fd; find_result_t *output_find; time_t tmp_time; int amtrmidx_debug = 0; - 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); - } - + safe_fd(-1, 0); safe_cd(); set_pname("amtrmidx"); + /* Don't die when child closes pipe */ + signal(SIGPIPE, SIG_IGN); + dbopen(); dbprintf(("%s: version %s\n", argv[0], version())); @@ -100,32 +95,31 @@ char **argv; config_dir = vstralloc(CONFIG_DIR, "/", config_name, "/", NULL); conffile = stralloc2(config_dir, CONFFILE_NAME); - if(read_conffile(conffile)) { + if (read_conffile(conffile)) error("errors processing config file \"%s\"", conffile); - } amfree(conffile); + conf_diskfile = getconf_str(CNF_DISKFILE); if(*conf_diskfile == '/') { conf_diskfile = stralloc(conf_diskfile); } else { conf_diskfile = stralloc2(config_dir, conf_diskfile); } - if((diskl = read_diskfile(conf_diskfile)) == NULL) { - error("could not load disklist \"%s\".", conf_diskfile); - } + if (read_diskfile(conf_diskfile, &diskl) < 0) + error("could not load disklist \"%s\"", conf_diskfile); amfree(conf_diskfile); + conf_tapelist = getconf_str(CNF_TAPELIST); if(*conf_tapelist == '/') { conf_tapelist = stralloc(conf_tapelist); } else { conf_tapelist = stralloc2(config_dir, conf_tapelist); } - if(read_tapelist(conf_tapelist)) { + if(read_tapelist(conf_tapelist)) error("could not load tapelist \"%s\"", conf_tapelist); - } amfree(conf_tapelist); - output_find = find_dump(1, diskl); + output_find = find_dump(1, &diskl); conf_indexdir = getconf_str(CNF_INDEXDIR); if(*conf_indexdir == '/') { @@ -137,8 +131,10 @@ char **argv; /* now go through the list of disks and find which have indexes */ time(&tmp_time); tmp_time -= 7*24*60*60; /* back one week */ - for (diskp = diskl->head; diskp != NULL; diskp = diskp->next) { - if (diskp->index) { + for (diskp = diskl.head; diskp != NULL; diskp = diskp->next) + { + if (diskp->index) + { char *indexdir; DIR *d; struct dirent *f; @@ -153,13 +149,13 @@ char **argv; /* get listing of indices, newest first */ host = sanitise_filename(diskp->host->hostname); disk = sanitise_filename(diskp->name); - indexdir = vstralloc (conf_indexdir, "/", - host, "/", - disk, "/", - NULL); + indexdir = vstralloc(conf_indexdir, "/", + host, "/", + disk, "/", + NULL); amfree(host); amfree(disk); - if((d = opendir(indexdir)) == NULL) { + if ((d = opendir(indexdir)) == NULL) { dbprintf(("could not open index directory \"%s\"\n", indexdir)); amfree(indexdir); continue;