summaryrefslogtreecommitdiffabout
path: root/src/main.c
authorSergey Poznyakoff <gray@gnu.org.ua>2007-05-05 15:31:52 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2007-05-05 15:31:52 (GMT)
commit0aa7e4583600de267f6a23b1a9f32f92cab19aae (patch) (side-by-side diff)
treeb0abb8cff8872b5f469ef2181e92c0bfe3d81452 /src/main.c
parentc999336a35270b773253680e84c7e234cca0b139 (diff)
downloadmailfromd-0aa7e4583600de267f6a23b1a9f32f92cab19aae.tar.gz
mailfromd-0aa7e4583600de267f6a23b1a9f32f92cab19aae.tar.bz2
Fixup pidfile and portspec according to state directory settings
git-svn-id: file:///svnroot/mailfromd/trunk@1411 7a8a7f39-df28-0410-adc6-e0d955640f24
Diffstat (limited to 'src/main.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/main.c91
1 files changed, 65 insertions, 26 deletions
diff --git a/src/main.c b/src/main.c
index 13b513b..d5a2ff6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -61,7 +61,8 @@ 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 */
+char *portspec; /* Communication socket specification.
+ See init_names() */
int force_remove; /* Remove local communication socket if it already
exists */
int foreground; /* Stay in foreground */
@@ -69,8 +70,8 @@ int single_process_option; /* Run in single process mode. */
unsigned long source_address = INADDR_ANY; /* Source address for TCP
connections */
char *syslog_tag; /* Tag to mark syslog entries with. */
-char *mailfromd_state_dir;
-char *pidfile = DEFAULT_PIDFILE;
+char *mailfromd_state_dir; /* see init_names() */
+char *pidfile; /* see init_names() */
char *user = DEFAULT_USER; /* Switch to this user privileges after
startup */
mu_list_t retain_groups; /* List of group IDs to retain when switching
@@ -1491,43 +1492,80 @@ get_db_name()
}
void
-db_format_setup()
+init_names()
{
mailfromd_state_dir = xstrdup(DEFAULT_STATE_DIR);
+ portspec = xstrdup(DEFAULT_SOCKET);
+ pidfile = xstrdup(DEFAULT_PIDFILE);
+}
+
+void
+db_format_setup()
+{
dns_cache_format = db_format_install(dns_cache_format);
cache_format = db_format_install(cache_format);
rate_format = db_format_install(rate_format);
greylist_format = db_format_install(greylist_format);
}
-static int
-db_fixup_name_enumerator(void *sym, void *data)
+static char *
+state_dir_fixup(char *name)
{
- struct db_format *fmt = sym;
- static size_t slen;
-
- if (slen == 0)
- slen = strlen(mailfromd_state_dir);
-
- if (fmt->dbname[0] != '/') {
- size_t olen = strlen(fmt->dbname);
+ if (name[0] != '/') {
+ size_t slen = strlen(mailfromd_state_dir);
+ size_t olen = strlen(name);
size_t flen = slen + 1 + olen + 1;
- char *p = xrealloc(fmt->dbname, flen);
+ char *p = xrealloc(name, flen);
memmove(p + slen + 1, p, olen + 1);
memcpy(p, mailfromd_state_dir, slen);
p[slen] = '/';
- fmt->dbname = p;
+ name = p;
}
+ return name;
+}
+
+static int
+db_fixup_name_enumerator(void *sym, void *data)
+{
+ struct db_format *fmt = sym;
+
+ fmt->dbname = state_dir_fixup(fmt->dbname);
+
return 0;
}
static void
-db_fixup_names()
+portspec_fixup()
+{
+ char *proto, *port, *path;
+
+ if (gacopyz_parse_connection(portspec, &proto, &port, &path)
+ != MI_SUCCESS)
+ return; /* No need to complain: it is left to gacopyz connect
+ routines */
+
+ if ((!proto
+ || strcmp(proto, "unix") == 0 || strcmp(proto, "local") == 0)
+ && !port
+ && path[0] != '/') {
+ portspec = state_dir_fixup(path);
+ path = NULL;
+ }
+
+ free(proto);
+ free(port);
+ free(path);
+}
+
+static void
+fixup_state_dir_names()
{
size_t slen = strlen(mailfromd_state_dir);
if (mailfromd_state_dir[slen-1] == '/')
mailfromd_state_dir[slen-1] = 0;
db_format_enumerate(db_fixup_name_enumerator, NULL);
+ pidfile = state_dir_fixup(pidfile);
+ portspec_fixup();
}
void
@@ -1631,11 +1669,11 @@ void
mailfromd_show_defaults()
{
printf("version: %s\n", VERSION);
- printf("script file: %s\n", DEFAULT_SCRIPT_FILE);
- printf("user: %s\n", DEFAULT_USER);
- printf("statedir: %s\n", DEFAULT_STATE_DIR);
- printf("socket: %s\n", DEFAULT_SOCKET);
- printf("pidfile: %s\n", DEFAULT_PIDFILE);
+ printf("script file: %s\n", script_file);
+ printf("user: %s\n", user);
+ printf("statedir: %s\n", mailfromd_state_dir);
+ printf("socket: %s\n", portspec);
+ printf("pidfile: %s\n", pidfile);
#ifdef USE_SYSLOG_ASYNC
printf("syslog: non-blocking\n");
#else
@@ -1694,14 +1732,15 @@ main(int argc, char **argv)
/* Set default logging */
log_facility = DEFAULT_LOG_FACILITY;
log_setup(!stderr_closed_p());
-
+
+ init_names();
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);
+ mu_argp_init(program_version, "<" PACKAGE_BUGREPORT ">");
+ mu_argp_parse(&argp, &argc, &argv, 0, capa, &index, NULL);
log_setup(log_to_stderr);
@@ -1737,7 +1776,7 @@ main(int argc, char **argv)
exit(EX_CONFIG);
}
process_options();
- db_fixup_names();
+ fixup_state_dir_names();
/* Process some special options */
if (expire_interval)

Return to:

Send suggestions and report system problems to the System administrator.