Imported Upstream version 2.5.1
[debian/amanda] / server-src / amcleanupdisk.c
index e73af4cd94f3c1ecea55880875b478bc48398af8..9092313c304a6070de14251d43b186903d8f7914 100644 (file)
@@ -24,7 +24,7 @@
  * file named AUTHORS, in the root directory of this distribution.
  */
 /*
- * $Id: amcleanupdisk.c,v 1.16 2006/01/14 04:37:19 paddy_s Exp $
+ * $Id: amcleanupdisk.c,v 1.22 2006/07/25 18:27:57 martinea Exp $
  */
 #include "amanda.h"
 
@@ -40,13 +40,14 @@ sl_t *holding_list;
 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;
@@ -60,29 +61,39 @@ char **main_argv;
 
     set_pname("amcleanupdisk");
 
+    dbopen(DBG_SUBDIR_SERVER);
+
     /* Don't die when child closes pipe */
     signal(SIGPIPE, SIG_IGN);
 
-    if(main_argc != 2)
+    if(main_argc != 2) {
        error("Usage: amcleanupdisk%s <confdir>", 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))
+    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 (read_diskfile(conf_diskfile, &diskq) < 0)
+    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);
@@ -91,17 +102,24 @@ char **main_argv;
     } else {
        conf_infofile = stralloc2(config_dir, conf_infofile);
     }
-    if (open_infofile(conf_infofile) < 0)
+    if (open_infofile(conf_infofile) < 0) {
        error("could not open info db \"%s\"", conf_infofile);
+       /*NOTREACHED*/
+    }
     amfree(conf_infofile);
 
     datestamp = construct_datestamp(NULL);
 
     dumpuser = getconf_str(CNF_DUMPUSER);
-    if((pw = getpwnam(dumpuser)) == NULL)
+    if((pw = getpwnam(dumpuser)) == NULL) {
        error("dumpuser %s not found in password file", dumpuser);
-    if(pw->pw_uid != getuid())
+       /*NOTREACHED*/
+    }
+
+    if(pw->pw_uid != getuid()) {
        error("must run amcleanupdisk as user %s", dumpuser);
+       /*NOTREACHED*/
+    }
 
     holding_list = pick_all_datestamp(1);
 
@@ -116,8 +134,10 @@ char **main_argv;
 }
 
 
-void check_holdingdisk(diskdir, datestamp)
-char *diskdir, *datestamp;
+void
+check_holdingdisk(
+    char *     diskdir,
+    char *     datestamp)
 {
     DIR *workdir;
     struct dirent *entry;
@@ -130,7 +150,7 @@ char *diskdir, *datestamp;
     filetype_t filetype;
     info_t info;
     int level;
-    int dl, l;
+    size_t dl, l;
 
     dirname = vstralloc(diskdir, "/", datestamp, NULL);
     dl = strlen(dirname);
@@ -163,6 +183,7 @@ char *diskdir, *datestamp;
        amfree(hostname);
        amfree(diskname);
        filetype = get_amanda_names(tmpname, &hostname, &diskname, &level);
+       amfree(tmpname);
        if(filetype != F_DUMPFILE) {
            continue;
        }
@@ -184,6 +205,7 @@ char *diskdir, *datestamp;
            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);
@@ -202,13 +224,14 @@ char *diskdir, *datestamp;
 }
 
 
-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);
     }
 }