diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-05-04 05:37:38 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-05-04 05:37:38 +0000 |
commit | 5663888746b3b5e15ab795a1e2bfaae7b2cf768a (patch) | |
tree | e1ee007db83ea3832d450ae4d6e2df7010cfbed9 /src/main.c | |
parent | 076f7df5c40dbc3c791f14e5f55568e46244c0f8 (diff) | |
download | mailfromd-5663888746b3b5e15ab795a1e2bfaae7b2cf768a.tar.gz mailfromd-5663888746b3b5e15ab795a1e2bfaae7b2cf768a.tar.bz2 |
SIGHUP instructs `mailfromd' to restart itself.
Remove UNIX socket after closing it.
git-svn-id: file:///svnroot/mailfromd/trunk@1405 7a8a7f39-df28-0410-adc6-e0d955640f24
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 59 |
1 files changed, 45 insertions, 14 deletions
@@ -55,12 +55,13 @@ int script_ydebug; /* Enable tracing the parser */ int script_dump_tree; /* Dump created config tree to stdout */ int script_dump_code; /* Dump disassembled code to stdout */ int script_dump_macros; /* Dump used Sendmail macros */ int script_dump_xref; /* Dump cross-reference */ int do_transcript; /* Enable session transript */ int do_trace; /* Enable tracing configuration */ +int mtasim_option; /* mtasim compatibility mode */ unsigned optimization_level = 1; /* Optimization level */ int log_to_stderr; /* Use stderr for logging */ char *portspec = DEFAULT_SOCKET; /* Communication socket specification */ int force_remove; /* Remove local communication socket if it already exists */ int foreground; /* Stay in foreground */ @@ -810,12 +811,13 @@ enum mailfromd_option { OPTION_LINT, OPTION_LOG_TAG, OPTION_LIST, OPTION_LOCK_RETRY_COUNT, OPTION_LOCK_RETRY_TIMEOUT, OPTION_MILTER_TIMEOUT, + OPTION_MTASIM, OPTION_PIDFILE, OPTION_POSTMASTER_EMAIL, OPTION_PREDICT_NEXT, OPTION_SHOW_DEFAULTS, OPTION_SINGLE_PROCESS, OPTION_STACK_TRACE, @@ -900,12 +902,14 @@ static struct argp_option options[] = { N_("Set communication socket"), GRP+1 }, { "remove", 'r', NULL, 0, N_("Force removing local socket file, if it already exists"), GRP+1 }, { "foreground", OPTION_FOREGROUND, NULL, 0, N_("Stay in foreground"), GRP+1 }, + { "mtasim", OPTION_MTASIM, NULL, 0, + N_("Run in mtasim compatibility mode"), GRP+1 }, { "single-process", OPTION_SINGLE_PROCESS, NULL, 0, N_("Run in single-process mode"), GRP+1 }, { "pidfile", OPTION_PIDFILE, N_("FILE"), 0, N_("Set pidfile name"), GRP+1 }, { "user", 'u', N_("NAME"), 0, N_("Switch to this user privileges after startup"), GRP+1 }, @@ -1218,12 +1222,16 @@ parse_opt (int key, char *arg, struct argp_state *state) break; case OPTION_MILTER_TIMEOUT: set_option("milter-timeout", arg, 1); break; + case OPTION_MTASIM: + mtasim_option = foreground = 1; + break; + case OPTION_PIDFILE: set_option("pidfile", arg, 1); break; case OPTION_POSTMASTER_EMAIL: set_option("mailfrom", arg, 1); @@ -1640,31 +1648,64 @@ mailfromd_show_defaults() #endif printf("\n"); db_format_enumerate(db_format_enumerator, NULL); } +void +log_setup(int want_stderr) +{ + /* Set up logging */ + if (!want_stderr) { +#ifdef USE_SYSLOG_ASYNC + openlog_async(syslog_tag, LOG_PID, log_facility); + gacopyz_set_logger (mf_gacopyz_syslog_async_log_printer); +#else + openlog(syslog_tag, LOG_PID, log_facility); +#endif + mu_error_set_print(syslog_error_printer); + } else { + gacopyz_set_logger(gacopyz_stderr_log_printer); + mu_error_set_print(stderr_error_printer); + } +} + +static int +stderr_closed_p() +{ + int fd = dup(0); + if (fd < 0) + return 1; + close(fd); + return fd <= 2; +} + int main(int argc, char **argv) { int index; mu_license_text = license; MU_AUTH_REGISTER_ALL_MODULES(); mu_register_all_mailer_formats(); if (!program_invocation_short_name) program_invocation_short_name = argv[0]; + + /* Set default logging */ log_facility = DEFAULT_LOG_FACILITY; - mu_error_set_print(stderr_error_printer); + log_setup(!stderr_closed_p()); + init_string_space(); builtin_setup(); db_format_setup(); lex_setup(); + save_cmdline(argc, argv); mu_argp_init (program_version, "<" PACKAGE_BUGREPORT ">"); - mu_argp_parse (&argp, &argc, &argv, 0, capa, &index, NULL); + + log_setup(log_to_stderr); argv += index; argc -= index; if (need_config) { if (argc) { @@ -1686,12 +1727,14 @@ main(int argc, char **argv) script_file = argv[n]; memmove(argv + n, argv + n + 1, (argc - n + 1) * sizeof argv[0]); argc--; } } + if (script_file[0] != '/') + save_cmdline(0, NULL); /* Clear saved command line */ if (parse_program(script_file, script_ydebug, script_ldebug)) exit(EX_CONFIG); } process_options(); db_fixup_names(); @@ -1705,24 +1748,12 @@ main(int argc, char **argv) if (script_dump_code) print_code(); if (script_dump_xref) print_xref(); - /* Set up default values */ - if (!log_to_stderr) { -#ifdef USE_SYSLOG_ASYNC - openlog_async(syslog_tag, LOG_PID, log_facility); - gacopyz_set_logger (mf_gacopyz_syslog_async_log_printer); -#else - openlog(syslog_tag, LOG_PID, log_facility); -#endif - mu_error_set_print(syslog_error_printer); - } else - gacopyz_set_logger (gacopyz_stderr_log_printer); - if (script_dump_macros) print_used_macros(); fixup_code(); if (script_check || script_dump_macros |