diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2006-09-05 15:05:14 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2006-09-05 15:05:14 +0000 |
commit | f7ccfc943750f39a24cd746a33577bc83cc0d066 (patch) | |
tree | 9cf7f7bf80e94df8960939ed19974f6b7eed3027 /src/main.c | |
parent | d172d8bf70bead6f90d17fbcfc925253be2c3946 (diff) | |
download | mailfromd-f7ccfc943750f39a24cd746a33577bc83cc0d066.tar.gz mailfromd-f7ccfc943750f39a24cd746a33577bc83cc0d066.tar.bz2 |
New option --all
(stderr_error_printer): Use program_invocation_short_name
(main): Set stderr_error_printer early, before parsing command
line.
git-svn-id: file:///svnroot/mailfromd/trunk@534 7a8a7f39-df28-0410-adc6-e0d955640f24
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 111 |
1 files changed, 79 insertions, 32 deletions
@@ -94,7 +94,9 @@ time_t expire_interval = 0; /* When set, overrides all the three above int predict_next_option; double predict_rate; /* Prediction rate for --list --format=rates*/ -int ignore_failed_reads_option; +int ignore_failed_reads_option; /* Ignore failed reads while compacting or + expiring */ +int all_option; /* Process all databases */ #endif int source_info_option; /* Debug messages include source locations */ @@ -256,7 +258,7 @@ syslog_error_printer (const char *fmt, va_list ap) int stderr_error_printer (const char *fmt, va_list ap) { - fprintf(stderr, "%s: ", program_invocation_name); + fprintf(stderr, "%s: ", program_invocation_short_name); vfprintf(stderr, fmt, ap); fputc ('\n', stderr); return 0; @@ -1601,8 +1603,9 @@ const char *program_version = "mailfromd (" PACKAGE_STRING ")"; static char doc[] = N_("mailfromd -- MAIL FROM milter checker"); static char args_doc[] = "[var=value...]"; -enum mailfromd_option { - OPTION_COMPACT = 256, +enum mailfromd_option { + OPTION_ALL = 256, + OPTION_COMPACT, OPTION_DAEMON, OPTION_DELETE, OPTION_DOMAIN_FILE, @@ -1669,6 +1672,11 @@ static struct argp_option options[] = { N_("Set maximum number of attempts to acquire the lock"), GRP+1 }, { "lock-retry-timeout", OPTION_LOCK_RETRY_TIMEOUT, N_("TIME"), 0, N_("Set timeout for acquiring the lockfile"), GRP+1 }, + { "expire-interval", 'e', N_("NUMBER"), 0, + N_("Set cache expiration interval to NUMBER seconds"), GRP+1 }, + { "all", OPTION_ALL, NULL, 0, + N_("With --compact or --expire: apply the operation to all " + "available databases"), GRP+1 }, #endif #undef GRP @@ -1700,10 +1708,6 @@ static struct argp_option options[] = { GRP+1 }, { "source", 'S', N_("ADDRESS"), 0, N_("Set source address for TCP connections"), GRP+1 }, -#ifdef USE_DBM - { "expire-interval", 'e', N_("NUMBER"), 0, - N_("Set cache expiration interval to NUMBER seconds"), GRP+1 }, -#endif #undef GRP #undef GRP @@ -1751,6 +1755,19 @@ static struct argp_option options[] = { { NULL } }; +static int +validate_options() +{ + if (all_option && + !(mode == MAILFROMD_COMPACT || mode == MAILFROMD_EXPIRE)) { + mu_error("--all is meaningful only with --expire or --compact option"); + return 1; + } + if (all_option && format_option) + mu_error("--format is incompatible with --all"); + return 0; +} + static error_t parse_opt (int key, char *arg, struct argp_state *state) @@ -1768,16 +1785,11 @@ parse_opt (int key, char *arg, struct argp_state *state) set_option("debug", arg, 1); break; -#ifdef USE_DBM +#ifdef USE_DBM case 'e': set_option("expire-interval", arg, 1); break; - case OPTION_PREDICT_NEXT: - if (convert_rate(arg, &predict_rate) == 0) - predict_next_option = 1; - break; - case 'f': file_option = arg; break; @@ -1788,6 +1800,10 @@ parse_opt (int key, char *arg, struct argp_state *state) argp_error(state, "unknown DB format"); break; + case OPTION_ALL: + all_option = 1; + break; + case OPTION_IGNORE_FAILED_READS: ignore_failed_reads_option = 1; break; @@ -1799,6 +1815,12 @@ parse_opt (int key, char *arg, struct argp_state *state) case OPTION_LOCK_RETRY_TIMEOUT: set_option("lock-retry-timeout", arg, 1); break; + + case OPTION_PREDICT_NEXT: + if (convert_rate(arg, &predict_rate) == 0) + predict_next_option = 1; + mode = MAILFROMD_LIST; + break; #endif case 'L': @@ -1883,7 +1905,7 @@ parse_opt (int key, char *arg, struct argp_state *state) break; case OPTION_EXPIRE: - need_config = 1; + need_config = 0; log_to_stderr = 1; mode = MAILFROMD_EXPIRE; break; @@ -1940,6 +1962,12 @@ parse_opt (int key, char *arg, struct argp_state *state) break; case ARGP_KEY_FINI: + if (validate_options()) + exit(EX_USAGE); + + if (!syslog_tag) + syslog_tag = program_invocation_short_name; + if (!format_option) format_option = db_format_lookup("cache"); break; @@ -2320,29 +2348,46 @@ mailfromd_list(int argc, char **argv) exit(rc != 0); } +static int +db_proc_enumerator(void *sym, void *data) +{ + struct db_format *fmt = sym; + int (*func)(char *name, db_expire_t exp) = data; + + if (fmt->expire) + func(fmt->dbname, fmt->expire); + return 0; +} + void mailfromd_expire() { - char *name = get_db_name(); - - if (!format_option->expire) { - mu_error("expire is not applicable to this DB format"); - exit(EX_USAGE); - } - exit(db_expire(name, format_option->expire) != 0); + priv_setup(); + if (all_option) + symbol_enumerate(SYM_DB_FORMAT, db_proc_enumerator, db_expire); + else { + if (!format_option->expire) { + mu_error("expire is not applicable to this DB format"); + exit(EX_USAGE); + } + exit(db_expire(get_db_name(), format_option->expire) != 0); + } } void mailfromd_compact() { - char *name = get_db_name(); - - if (!format_option->expire) { - mu_error("compact is not applicable to this DB format"); - exit(EX_USAGE); - } priv_setup(); - exit(db_compact(name, format_option->expire) != 0); + if (all_option) + symbol_enumerate(SYM_DB_FORMAT, db_proc_enumerator, + db_compact); + else { + if (!format_option->expire) { + mu_error("compact is not applicable to this DB format"); + exit(EX_USAGE); + } + exit(db_compact(get_db_name(), format_option->expire) != 0); + } } static int @@ -2386,10 +2431,13 @@ main(int argc, char **argv) mu_license_text = license; MU_AUTH_REGISTER_ALL_MODULES(); - syslog_tag = program_invocation_short_name; + if (!program_invocation_short_name) + program_invocation_short_name = argv[0]; + mu_error_set_print(stderr_error_printer); builtin_setup(); db_format_setup(); mu_argp_init (program_version, PACKAGE_BUGREPORT); + mu_argp_parse (&argp, &argc, &argv, 0, capa, &index, NULL); argv += index; @@ -2421,8 +2469,7 @@ main(int argc, char **argv) if (!log_to_stderr) { openlog(syslog_tag, LOG_PID, log_facility); mu_error_set_print(syslog_error_printer); - } else - mu_error_set_print(stderr_error_printer); + } if (config_dump_code || config_dump_tree || config_ldebug || config_ydebug) |