Handle sender commands in vss_post_select().
[paraslash.git] / fsck.c
diff --git a/fsck.c b/fsck.c
index bbacdf2..ee7f4ee 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1997-2007 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 1997-2008 Andre Noll <maan@systemlinux.org>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
@@ -474,7 +474,7 @@ static int dummy_compare(const struct osl_object *obj1, const struct osl_object
 
 static unsigned files_pruned;
 
-int prune_disk_storage_file(const char *path, const void *private_data)
+int prune_disk_storage_file(const char *path, void *private_data)
 {
        HASH_TYPE hash[HASH_SIZE];
        unsigned flags = *(unsigned *)private_data;
@@ -534,7 +534,8 @@ static int prune_disk_storage_files(struct osl_table *t)
        PARA_INFO_LOG("looking for unreferenced disk storage files\n");
        FOR_EACH_DISK_STORAGE_COLUMN(i, t, cd) {
                char *dirname = column_filename(t, i);
-               ret = for_each_file_in_dir(dirname, prune_disk_storage_file, &t->desc->flags);
+               ret = for_each_file_in_dir(dirname, prune_disk_storage_file,
+                       (unsigned *)&t->desc->flags);
                free(dirname);
        }
        if (files_pruned)
@@ -621,6 +622,9 @@ out:
 static void fsck_cleanup(struct osl_table *t)
 {
        int i;
+
+       if (!t)
+               return;
        if (t->desc->column_descriptions) {
                struct osl_column_description *cd;
                for (i = 0; i < t->desc->num_columns; i++) {
@@ -629,10 +633,8 @@ static void fsck_cleanup(struct osl_table *t)
                }
                free(t->desc->column_descriptions);
        }
-       if (t) {
-               free(t->columns);
-               free(t);
-       }
+       free(t->columns);
+       free(t);
 
 }
 
@@ -884,14 +886,22 @@ static int check_table(char *base_dir, char *table_name)
        };
        int ret;
 
+       PARA_INFO_LOG("checking table %s\n", table_name);
        if (!conf.no_fsck_given) {
                ret = fsck(&desc);
                if (ret < 0)
-                       return ret;
+                       goto out;
        }
+       ret = 1;
        if (!conf.dump_dir_given || !*conf.dump_dir_arg)
-               return 1;
-       return dump_table(conf.dump_dir_arg, &desc);
+               goto out;
+       ret = dump_table(conf.dump_dir_arg, &desc);
+out:
+       if (ret < 0)
+               PARA_ERROR_LOG("failed to check table %s\n", table_name);
+       else
+               PARA_NOTICE_LOG("successfully checked table %s\n", table_name);
+       return ret;
 }
 
 static int check_all_tables(char *base_dir)
@@ -938,7 +948,7 @@ int main(int argc, char **argv)
        }
        HANDLE_VERSION_FLAG("fsck", conf);
        if (conf.base_dir_given)
-               base_dir = conf.base_dir_arg;
+               base_dir = para_strdup(conf.base_dir_arg);
        else {
                char *home = para_homedir();
                base_dir = make_message("%s/.paraslash/afs_database", home);
@@ -954,9 +964,18 @@ int main(int argc, char **argv)
                        break;
        }
 out:
-       if (!conf.base_dir_given)
+       if (ret < 0) {
+               PARA_ERROR_LOG("%s%s: %s\n",
+                       base_dir? "base_dir: " : "",
+                       base_dir? base_dir : "",
+                       para_strerror(-ret)
+               );
+               if (conf.loglevel_arg > 1)
+                       PARA_EMERG_LOG("re-run with \"--loglevel %d\" to increase verbosity\n",
+                               conf.loglevel_arg - 1);
+       } else
+               PARA_NOTICE_LOG("success\n");
+       if (base_dir)
                free(base_dir);
-       if (ret < 0)
-               PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret));
        return ret < 0? EXIT_FAILURE : EXIT_SUCCESS;
 }