From: Marco van Wieringen Date: Tue, 31 May 2011 17:00:08 +0000 (+0200) Subject: Tweak layout and redo comments. X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=ed4e10982930f546a150ac2c2afaef9dcee7bfdc;p=bacula%2Fbacula Tweak layout and redo comments. --- diff --git a/bacula/src/tools/dbcheck.c b/bacula/src/tools/dbcheck.c index 9312a4968b..c8d6af1e99 100644 --- a/bacula/src/tools/dbcheck.c +++ b/bacula/src/tools/dbcheck.c @@ -42,8 +42,10 @@ extern bool parse_dir_config(CONFIG *config, const char *configfile, int exit_code); -/* Dummy functions */ -int generate_daemon_event(JCR *jcr, const char *event) +/* + * Dummy functions + */ +int generate_daemon_event(JCR *jcr, const char *event) { return 1; } typedef struct s_id_ctx { @@ -62,7 +64,9 @@ typedef struct s_name_ctx { int tot_ids; /* total to process */ } NAME_LIST; -/* Global variables */ +/* + * Global variables + */ static bool fix = false; static bool batch = false; static B_DB *db; @@ -71,10 +75,13 @@ static NAME_LIST name_list; static char buf[20000]; static bool quit = false; static CONFIG *config; +static const char *idx_tmp_name; #define MAX_ID_LIST_LEN 10000000 -/* Forward referenced functions */ +/* + * Forward referenced functions + */ static void print_catalog_details(CAT *catalog, const char *working_dir); static int make_id_list(const char *query, ID_LIST *id_list); static int delete_id_list(const char *query, ID_LIST *id_list); @@ -98,17 +105,13 @@ static void repair_bad_filenames(); static void do_interactive_mode(); static bool yes_no(const char *prompt); static bool check_idx(const char *col_name); -static bool create_tmp_idx(const char *idx_name, const char *table_name, +static bool create_tmp_idx(const char *idx_name, const char *table_name, const char *col_name); static bool drop_tmp_idx(const char *idx_name, const char *table_name); #ifdef HAVE_MYSQL static int check_idx_handler(void *ctx, int num_fields, char **row); #endif - -/* Global variables */ -static const char *idx_tmp_name; - static void usage() { fprintf(stderr, @@ -142,7 +145,7 @@ int main (int argc, char *argv[]) lmgr_init_thread(); my_name_is(argc, argv, "dbcheck"); - init_msg(NULL, NULL); /* setup message handler */ + init_msg(NULL, NULL); /* setup message handler */ memset(&id_list, 0, sizeof(id_list)); memset(&name_list, 0, sizeof(name_list)); @@ -152,19 +155,15 @@ int main (int argc, char *argv[]) case 'B': print_catalog = true; /* get catalog information from config */ break; - case 'b': /* batch */ batch = true; break; - case 'C': /* CatalogName */ catalogname = optarg; break; - case 'c': /* configfile */ configfile = optarg; break; - case 'd': /* debug level */ if (*optarg == 't') { dbg_timestamp = true; @@ -175,15 +174,12 @@ int main (int argc, char *argv[]) } } break; - case 'f': /* fix inconsistencies */ fix = true; break; - case 'v': verbose++; break; - case '?': default: usage(); @@ -231,7 +227,9 @@ int main (int argc, char *argv[]) } set_working_directory(director->working_directory); - /* Print catalog information and exit (-B) */ + /* + * Print catalog information and exit (-B) + */ if (print_catalog) { print_catalog_details(catalog, director->working_directory); exit(0); @@ -257,7 +255,9 @@ int main (int argc, char *argv[]) usage(); } - /* This is needed by SQLite to find the db */ + /* + * This is needed by SQLite to find the db + */ working_directory = argv[0]; db_name = "bacula"; user = db_name; @@ -296,14 +296,18 @@ int main (int argc, char *argv[]) } } - /* Open database */ + /* + * Open database + */ db = db_init_database(NULL, NULL, db_name, user, password, dbhost, dbport, NULL, false, false); if (!db_open_database(NULL, db)) { Emsg1(M_FATAL, 0, "%s", db_strerror(db)); return 1; } - /* drop temporary index idx_tmp_name if it already exists */ + /* + * Drop temporary index idx_tmp_name if it already exists + */ drop_tmp_idx("idxPIchk", "File"); if (batch) { @@ -324,7 +328,9 @@ int main (int argc, char *argv[]) do_interactive_mode(); } - /* drop temporary index idx_tmp_name */ + /* + * Drop temporary index idx_tmp_name + */ drop_tmp_idx("idxPIchk", "File"); db_close_database(NULL, db); @@ -515,7 +521,6 @@ static int print_job_handler(void *ctx, int num_fields, char **row) return 0; } - static int print_jobmedia_handler(void *ctx, int num_fields, char **row) { printf(_("Orphaned JobMediaId=%s JobId=%s Volume=\"%s\"\n"), @@ -544,7 +549,6 @@ static int print_client_handler(void *ctx, int num_fields, char **row) return 0; } - /* * Called here with each id to be added to the list */ @@ -623,7 +627,6 @@ static int name_list_handler(void *ctx, int num_fields, char **row) return 0; } - /* * Construct name list */ @@ -650,7 +653,6 @@ static void print_name_list(NAME_LIST *name_list) } } - /* * Free names in the list */ @@ -669,7 +671,9 @@ static void eliminate_duplicate_filenames() printf(_("Checking for duplicate Filename entries.\n")); - /* Make list of duplicated names */ + /* + * Make list of duplicated names + */ query = "SELECT Name, count(Name) as Count FROM Filename GROUP BY Name " "HAVING count(Name) > 1"; @@ -684,9 +688,13 @@ static void eliminate_duplicate_filenames() return; } if (fix) { - /* Loop through list of duplicate names */ + /* + * Loop through list of duplicate names + */ for (int i=0; i 1) { @@ -698,7 +706,9 @@ static void eliminate_duplicate_filenames() if (verbose) { printf(_("Found %d for: %s\n"), id_list.num_ids, name_list.name[i]); } - /* Force all records to use the first id then delete the other ids */ + /* + * Force all records to use the first id then delete the other ids + */ for (int j=1; j 1"; @@ -742,9 +753,13 @@ static void eliminate_duplicate_paths() return; } if (fix) { - /* Loop through list of duplicate names */ + /* + * Loop through list of duplicate names + */ for (int i=0; i 1) { @@ -756,7 +771,9 @@ static void eliminate_duplicate_paths() if (verbose) { printf(_("Found %d for: %s\n"), id_list.num_ids, name_list.name[i]); } - /* Force all records to use the first id then delete the other ids */ + /* + * Force all records to use the first id then delete the other ids + */ for (int j=1; j 0 && IsPathSeparator(name[len-1]); len--) { } if (len == 0) { @@ -1255,11 +1292,15 @@ static void repair_bad_paths() if (!db_sql_query(db, buf, get_name_handler, name)) { printf("%s\n", db_strerror(db)); } - /* Strip trailing blanks */ + /* + * Strip trailing blanks + */ for (len=strlen(name); len > 0 && name[len-1]==' '; len--) { name[len-1] = 0; } - /* Add trailing slash */ + /* + * Add trailing slash + */ len = pm_strcat(&name, "/"); db_escape_string(NULL, db, esc_name, name, len); bsnprintf(buf, sizeof(buf), "UPDATE Path SET Path='%s' WHERE PathId=%s", @@ -1272,7 +1313,6 @@ static void repair_bad_paths() } } - /* * Gen next input command from the terminal */ @@ -1303,7 +1343,6 @@ static bool yes_no(const char *prompt) bool python_set_prog(JCR*, char const*) { return false; } - /* * The code below to add indexes is needed only for MySQL, and * that to improve the performance. @@ -1319,13 +1358,14 @@ typedef struct s_idx_list { static IDX_LIST idx_list[MAXIDX]; -/* +/* * Called here with each table index to be added to the list */ static int check_idx_handler(void *ctx, int num_fields, char **row) { - /* Table | Non_unique | Key_name | Seq_in_index | Column_name |... - * File | 0 | PRIMARY | 1 | FileId |... + /* + * Table | Non_unique | Key_name | Seq_in_index | Column_name |... + * File | 0 | PRIMARY | 1 | FileId |... */ char *name, *key_name, *col_name; int i, len; @@ -1343,7 +1383,9 @@ static int check_idx_handler(void *ctx, int num_fields, char **row) break; } } - /* if the new Key_name, add it to the list */ + /* + * If the new Key_name, add it to the list + */ if (!found) { len = strlen(key_name) + 1; idx_list[i].key_name = (char *)malloc(len); @@ -1375,9 +1417,13 @@ static bool check_idx(const char *col_name) } for(i = 0; (idx_list[i].key_name != NULL) && (i < MAXIDX) ; i++) { - /* NOTE : if (idx_list[i].count_key > 1) then index idx_list[i].key_name is "multiple-column" index */ + /* + * NOTE : if (idx_list[i].count_key > 1) then index idx_list[i].key_name is "multiple-column" index + */ if ((idx_list[i].count_key == 1) && (idx_list[i].count_col == 1)) { - /* "one column" index over *col_name found */ + /* + * "one column" index over *col_name found + */ found = true; } } @@ -1398,12 +1444,12 @@ static bool check_idx(const char *col_name) /* * Create temporary one-column index */ -static bool create_tmp_idx(const char *idx_name, const char *table_name, - const char *col_name) +static bool create_tmp_idx(const char *idx_name, const char *table_name, + const char *col_name) { idx_tmp_name = NULL; printf(_("Create temporary index... This may take some time!\n")); - bsnprintf(buf, sizeof(buf), "CREATE INDEX %s ON %s (%s)", idx_name, table_name, col_name); + bsnprintf(buf, sizeof(buf), "CREATE INDEX %s ON %s (%s)", idx_name, table_name, col_name); if (verbose) { printf("%s\n", buf); }