* file named AUTHORS, in the root directory of this distribution.
*/
/*
- * $Id: amcleanupdisk.c,v 1.1.2.6.4.3.2.2.2.1 2005/09/20 21:31:52 jrjackson Exp $
+ * $Id: amcleanupdisk.c,v 1.22.2.1 2006/10/03 18:57:25 martinea Exp $
*/
#include "amanda.h"
char *datestamp;
/* local functions */
-int main P((int argc, char **argv));
-void check_holdingdisk P((char *diskdir, char *datestamp));
-void check_disks P((void));
-
-int main(main_argc, main_argv)
-int main_argc;
-char **main_argv;
+int main(int argc, char **argv);
+void check_holdingdisk(char *diskdir, char *datestamp);
+void check_disks(void);
+
+int
+main(
+ int main_argc,
+ char ** main_argv)
{
struct passwd *pw;
char *dumpuser;
- disklist_t *diskqp;
+ disklist_t diskq;
char *conffile;
char *conf_diskfile;
char *conf_infofile;
set_pname("amcleanupdisk");
- if(main_argc != 2) {
- error("Usage: amcleanupdisk%s <confdir>", versionsuffix());
+ dbopen(DBG_SUBDIR_SERVER);
+
+ /* Don't die when child closes pipe */
+ signal(SIGPIPE, SIG_IGN);
+
+ if(main_argc < 2) {
+ error("Usage: amcleanupdisk%s <config>", versionsuffix());
+ /*NOTREACHED*/
}
config_name = main_argv[1];
config_dir = vstralloc(CONFIG_DIR, "/", config_name, "/", NULL);
+
conffile = stralloc2(config_dir, CONFFILE_NAME);
if(read_conffile(conffile)) {
error("errors processing config file \"%s\"", conffile);
+ /*NOTREACHED*/
}
amfree(conffile);
+
+ dbrename(config_name, DBG_SUBDIR_SERVER);
+
conf_diskfile = getconf_str(CNF_DISKFILE);
if (*conf_diskfile == '/') {
conf_diskfile = stralloc(conf_diskfile);
} else {
conf_diskfile = stralloc2(config_dir, conf_diskfile);
}
- if((diskqp = read_diskfile(conf_diskfile)) == NULL) {
+ if (read_diskfile(conf_diskfile, &diskq) < 0) {
error("could not load disklist %s", conf_diskfile);
+ /*NOTREACHED*/
}
amfree(conf_diskfile);
+
conf_infofile = getconf_str(CNF_INFOFILE);
if (*conf_infofile == '/') {
conf_infofile = stralloc(conf_infofile);
} else {
conf_infofile = stralloc2(config_dir, conf_infofile);
}
- if(open_infofile(conf_infofile)) {
+ if (open_infofile(conf_infofile) < 0) {
error("could not open info db \"%s\"", conf_infofile);
+ /*NOTREACHED*/
}
amfree(conf_infofile);
dumpuser = getconf_str(CNF_DUMPUSER);
if((pw = getpwnam(dumpuser)) == NULL) {
error("dumpuser %s not found in password file", dumpuser);
+ /*NOTREACHED*/
}
+
if(pw->pw_uid != getuid()) {
error("must run amcleanupdisk as user %s", dumpuser);
+ /*NOTREACHED*/
}
holding_list = pick_all_datestamp(1);
}
-void check_holdingdisk(diskdir, datestamp)
-char *diskdir, *datestamp;
+void
+check_holdingdisk(
+ char * diskdir,
+ char * datestamp)
{
DIR *workdir;
struct dirent *entry;
filetype_t filetype;
info_t info;
int level;
- int dl, l;
+ size_t dl, l;
dirname = vstralloc(diskdir, "/", datestamp, NULL);
dl = strlen(dirname);
amfree(hostname);
amfree(diskname);
filetype = get_amanda_names(tmpname, &hostname, &diskname, &level);
+ amfree(tmpname);
if(filetype != F_DUMPFILE) {
continue;
}
if(put_info(dp->host->hostname, dp->name, &info)) {
error("could not put info record for %s:%s: %s",
dp->host->hostname, dp->name, strerror(errno));
+ /*NOTREACHED*/
}
} else {
fprintf(stderr,"rename_tmp_holding(%s) failed\n", destname);
}
-void check_disks()
+void
+check_disks(void)
{
holdingdisk_t *hdisk;
sle_t *dir;
for(dir = holding_list->first; dir !=NULL; dir = dir->next) {
for(hdisk = getconf_holdingdisks(); hdisk != NULL; hdisk = hdisk->next)
- check_holdingdisk(hdisk->diskdir, dir->name);
+ check_holdingdisk(holdingdisk_get_diskdir(hdisk), dir->name);
}
}