/** * Main daemon routine */ int main(int argc, char **argv) { int c, option_index = 0; const char *bin; char config_file[MAX_OPT_LEN] = ""; int rc; char err_msg[4096]; robinhood_config_t config; int chgd = 0; char badcfg[RBH_PATH_MAX]; bin = rh_basename(argv[0]); /* parse command line options */ while ((c = getopt_long(argc, argv, SHORT_OPT_STRING, option_tab, &option_index)) != -1) { switch (c) { case 'f': rh_strncpy(config_file, optarg, MAX_OPT_LEN); break; case 'l': { int log_level = str2debuglevel(optarg); if (log_level == -1) { fprintf(stderr, "Unsupported log level '%s'. CRIT, MAJOR, EVENT, VERB, DEBUG or FULL expected.\n", optarg); exit(1); } force_debug_level(log_level); break; } case 'h': display_help(bin); exit(0); break; case 'V': display_version(bin); exit(0); break; case ':': case '?': default: display_help(bin); exit(1); break; } } /* 2 expected argument: old backend path, new path is FS */ if (optind > argc - 2) { fprintf(stderr, "Error: missing arguments on command line.\n"); display_help(bin); exit(1); } else if (optind < argc - 3) { fprintf(stderr, "Error: too many arguments on command line.\n"); display_help(bin); exit(1); } /* get default config file, if not specified */ if (SearchConfig(config_file, config_file, &chgd, badcfg, MAX_OPT_LEN) != 0) { fprintf(stderr, "No config file (or too many) found matching %s\n", badcfg); exit(2); } else if (chgd) { fprintf(stderr, "Using config file '%s'.\n", config_file); } rc = rbh_init_internals(); if (rc != 0) exit(rc); /* only read ListMgr config */ if (ReadRobinhoodConfig(0, config_file, err_msg, &config, false)) { fprintf(stderr, "Error reading configuration file '%s': %s\n", config_file, err_msg); exit(1); } /* XXX HOOK: Set logging to stderr */ strcpy(config.log_config.log_file, "stderr"); strcpy(config.log_config.report_file, "stderr"); strcpy(config.log_config.alert_file, "stderr"); /* Initialize logging */ rc = InitializeLogs(bin, &config.log_config); if (rc) { fprintf(stderr, "Error opening log files: rc=%d, errno=%d: %s\n", rc, errno, strerror(errno)); exit(rc); } /* Initialize Filesystem access */ rc = InitFS(); if (rc) exit(rc); /* Initialize status managers (XXX all or just the one used for rebind?) */ rc = smi_init_all(options.flags); if (rc) exit(rc); #ifdef _HSM_LITE rc = Backend_Start(&config.backend_config, 0); if (rc) { DisplayLog(LVL_CRIT, LOGTAG, "Error initializing backend"); exit(1); } #endif if (optind == argc - 2) rc = rebind_helper(argv[optind], argv[optind + 1], NULL); else if (optind == argc - 3) rc = rebind_helper(argv[optind], argv[optind + 1], argv[optind + 2]); return rc; }
/** * Main daemon routine */ int main(int argc, char **argv) { int c, option_index = 0; const char *bin; char config_file[MAX_OPT_LEN] = ""; int rc; char err_msg[4096]; bool chgd = false; char badcfg[RBH_PATH_MAX]; char sm_name[SM_NAME_MAX + 1] = ""; bin = rh_basename(argv[0]); /* parse command line options */ while ((c = getopt_long(argc, argv, SHORT_OPT_STRING, option_tab, &option_index)) != -1) { switch (c) { case 'f': rh_strncpy(config_file, optarg, MAX_OPT_LEN); break; case 'l': { int log_level = str2debuglevel(optarg); if (log_level == -1) { fprintf(stderr, "Unsupported log level '%s'. CRIT, MAJOR, EVENT, VERB, DEBUG or FULL expected.\n", optarg); exit(1); } force_debug_level(log_level); break; } case 's': if (!EMPTY_STRING(sm_name)) fprintf(stderr, "WARNING: only a single status manager is expected " "on command line. '%s' ignored.\n", optarg); else rh_strncpy(sm_name, optarg, sizeof(sm_name)); break; case 'h': display_help(bin); exit(EXIT_SUCCESS); break; case 'V': display_version(bin); exit(EXIT_SUCCESS); break; case ':': case '?': default: display_help(bin); exit(1); break; } } /* 2 expected argument: old backend path, new path is FS */ if (optind > argc - 3) { fprintf(stderr, "Error: missing arguments on command line.\n"); display_help(bin); exit(1); } else if (optind < argc - 4) { fprintf(stderr, "Error: too many arguments on command line.\n"); display_help(bin); exit(1); } rc = rbh_init_internals(); if (rc != 0) exit(EXIT_FAILURE); /* get default config file, if not specified */ if (SearchConfig(config_file, config_file, &chgd, badcfg, MAX_OPT_LEN) != 0) { fprintf(stderr, "No config file (or too many) found matching %s\n", badcfg); exit(2); } else if (chgd) { fprintf(stderr, "Using config file '%s'.\n", config_file); } /* only read common config (listmgr, ...) (mask=0) */ if (rbh_cfg_load(0, config_file, err_msg)) { fprintf(stderr, "Error reading configuration file '%s': %s\n", config_file, err_msg); exit(1); } if (!log_config.force_debug_level) log_config.debug_level = LVL_MAJOR; /* no event message */ /* Set logging to stderr */ strcpy(log_config.log_file, "stderr"); strcpy(log_config.report_file, "stderr"); strcpy(log_config.alert_file, "stderr"); /* Initialize logging */ rc = InitializeLogs(bin); if (rc) { fprintf(stderr, "Error opening log files: rc=%d, errno=%d: %s\n", rc, errno, strerror(errno)); exit(EXIT_FAILURE); } /* Initialize Filesystem access */ rc = InitFS(); if (rc) exit(EXIT_FAILURE); /* Initialize status managers (XXX all or just the one used for undelete?) */ rc = smi_init_all(0); if (rc) exit(EXIT_FAILURE); /* load the status manager */ if (!EMPTY_STRING(sm_name)) { rc = load_smi(sm_name, &smi); if (rc) exit(EXIT_FAILURE); } else { /* if there is a single smi that allows undelete, use it */ rc = load_single_smi(&smi); if (rc) exit(EXIT_FAILURE); } if (optind == argc - 3) rc = rebind_helper(argv[optind], argv[optind + 1], argv[optind + 2], NULL); else if (optind == argc - 4) rc = rebind_helper(argv[optind], argv[optind + 1], argv[optind + 2], argv[optind + 3]); exit(rc ? EXIT_FAILURE: EXIT_SUCCESS); }