* file named AUTHORS, in the root directory of this distribution.
*/
/*
- * $Id: amtrmidx.c,v 1.21.4.1.4.2.2.6 2004/02/12 18:28:42 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
#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;
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()));
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 == '/') {
/* 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;
/* 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;