Esempio n. 1
0
/*===================================================
 * show_open_error -- Display database opening error
 *=================================================*/
static void
show_open_error (INT dberr)
{
	char buffer[256];
	describe_dberror(dberr, buffer, ARRSIZE(buffer));
	llwprintf(buffer);
	llwprintf("\n");
	sleep(5);
}
Esempio n. 2
0
/*===========================================
 * main -- Main procedure of dbverify command
 *=========================================*/
int
main (int argc, char **argv)
{
    char *flags, *dbname;
    char *ptr;
    char * msg;
    BOOLEAN cflag=FALSE; /* create new db if not found */
    INT writ=1; /* request write access to database */
    BOOLEAN immut=FALSE; /* immutable access to database */
    BOOLEAN allchecks=FALSE; /* if user requested all checks */
    INT returnvalue=1;
    STRING crashlog=NULL;
    INT lldberrnum=0;
    int i=0;

    /* initialize all the low-level library code */
    init_stdlib();

    validate_errs();

#if HAVE_SETLOCALE
    /* initialize locales */
    setlocale(LC_ALL, "");
#endif /* HAVE_SETLOCALE */

#if ENABLE_NLS
    ll_bindtextdomain(PACKAGE, LOCALEDIR);
    textdomain(PACKAGE);
#endif

    save_original_locales();

#ifdef WIN32
    /* TO DO - research if this is necessary */
    _fmode = O_BINARY;	/* default to binary rather than TEXT mode */
#endif

    /* handle conventional arguments --version and --help */
    /* needed for help2man to synthesize manual pages */
    for (i=1; i<argc; ++i) {
        if (!strcmp(argv[i], "--version")) {
            print_version("dbverify");
            return 0;
        }
        if (!strcmp(argv[i], "--help")
                || !strcmp(argv[i], "-?")) {
            print_usage();
            return 0;
        }
    }

    if (argc != 3 || argv[1][0] != '-' || argv[1][1] == '\0') {
        print_usage();
        goto done;
    }
    flags = argv[1];
    dbname = argv[2];
    for (ptr=&flags[1]; *ptr; ++ptr) {
        switch(*ptr) {
        case 'l':
            todo.check_dbstructure=TRUE;
            break;
        case 'g':
            todo.find_ghosts=TRUE;
            break;
        case 'G':
            todo.fix_ghosts=TRUE;
            break;
        case 'i':
            todo.check_indis=TRUE;
            break;
        case 'f':
            todo.check_fams=TRUE;
            break;
        case 's':
            todo.check_sours=TRUE;
            break;
        case 'e':
            todo.check_evens=TRUE;
            break;
        case 'x':
            todo.check_othes=TRUE;
            break;
        case 'n':
            noisy=TRUE;
            break;
        case 'a':
            allchecks=TRUE;
            break;
        case 'F':
            todo.fix_alter_pointers=TRUE;
            break;
        case 'm':
            todo.check_missing_data_records=TRUE;
            break;
        case 'M':
            todo.fix_missing_data_records=TRUE;
            break;
        case 'D':
            todo.fix_deletes=TRUE;
            break;
        case 'v':
            print_version("llexec");
            goto done;
        case 'h':
        default:
            print_usage();
            goto done;
        }
    }

    /* Turn off Memory Debugging */
    /* This is unnecessary -- it is off anyway, Perry, 2001/10/28 */
    alloclog  = FALSE;

    /* Enable any checks needed for fixes selected */
    if (todo.fix_missing_data_records)
        todo.check_missing_data_records = 1;

    /* initialize options & misc. stuff */
    llgettext_set_default_localedir(LOCALEDIR);
    if (!init_lifelines_global(0, &msg, 0)) {
        printf("%s\n", msg);
        goto done;
    }

    /* setup crashlog in case init_screen fails (eg, bad menu shortcuts) */
    crashlog = getlloptstr("CrashLog_dbverify", NULL);
    if (!crashlog) {
        crashlog = "Crashlog_dbverify.log";
    }
    crash_setcrashlog(crashlog);

    /* NB: This assumes btree database */
    if (!(BTR = bt_openbtree(dbname, cflag, writ, immut, &lldberrnum))) {
        char buffer[256];
        describe_dberror(lldberrnum, buffer, ARRSIZE(buffer));
        puts(buffer);
        goto done;
    }

    /*
    Do low-level checks before initializing lifelines database layer,
    because lifelines database init traverses btree for user options
    and translation tables, and here we check the infrastructure of
    the btree itself.
    */
    if (todo.check_dbstructure || allchecks) {
        if (!check_btree(BTR))
            goto done;
    }

    if (!init_lifelines_postdb()) {
        printf(_(qSbaddb));
        goto done;
    }
    printf(_("Checking %s"), dbname);
    puts("");

    /* all checks - if any new ones, have to update this */
    if (allchecks) {
        todo.check_indis=todo.check_fams=todo.check_sours=TRUE;
        todo.check_evens=todo.check_othes=TRUE;
        todo.find_ghosts=TRUE;
    }

    if (todo.find_ghosts || todo.fix_ghosts)
        check_ghosts();


    if (!(bwrite(BTR))) {
        todo.fix_alter_pointers = FALSE;
        todo.fix_ghosts = FALSE;
    }

    if (todo.check_indis
            || todo.check_fams
            || todo.check_sours
            || todo.check_evens
            || todo.check_othes) {
        check_and_fix_records();
    }

    if (todo.check_missing_data_records) {
        check_missing_data_records();
    }

    report_results();

    closebtree(BTR);

    /* TODO: probably should call lldb_close, Perry 2005-10-07 */

    BTR = 0;
    returnvalue = 0;

done:
    return returnvalue;
}