summaryrefslogtreecommitdiffabout
path: root/src/main.c
authorSergey Poznyakoff <gray@gnu.org.ua>2007-05-04 05:37:38 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2007-05-04 05:37:38 (GMT)
commit5663888746b3b5e15ab795a1e2bfaae7b2cf768a (patch) (side-by-side diff)
treee1ee007db83ea3832d450ae4d6e2df7010cfbed9 /src/main.c
parent076f7df5c40dbc3c791f14e5f55568e46244c0f8 (diff)
downloadmailfromd-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') (more/less context) (ignore whitespace changes)
-rw-r--r--src/main.c59
1 files changed, 45 insertions, 14 deletions
diff --git a/src/main.c b/src/main.c
index d389ec4..a954770 100644
--- a/src/main.c
+++ b/src/main.c
@@ -58,6 +58,7 @@ 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 */
@@ -813,6 +814,7 @@ enum mailfromd_option {
OPTION_LOCK_RETRY_COUNT,
OPTION_LOCK_RETRY_TIMEOUT,
OPTION_MILTER_TIMEOUT,
+ OPTION_MTASIM,
OPTION_PIDFILE,
OPTION_POSTMASTER_EMAIL,
OPTION_PREDICT_NEXT,
@@ -903,6 +905,8 @@ static struct argp_option options[] = {
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,
@@ -1221,6 +1225,10 @@ parse_opt (int key, char *arg, struct argp_state *state)
set_option("milter-timeout", arg, 1);
break;
+ case OPTION_MTASIM:
+ mtasim_option = foreground = 1;
+ break;
+
case OPTION_PIDFILE:
set_option("pidfile", arg, 1);
break;
@@ -1643,6 +1651,34 @@ mailfromd_show_defaults()
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)
{
@@ -1653,15 +1689,20 @@ main(int argc, char **argv)
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;
@@ -1689,6 +1730,8 @@ main(int argc, char **argv)
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);
}
@@ -1708,18 +1751,6 @@ main(int argc, char **argv)
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();

Return to:

Send suggestions and report system problems to the System administrator.