aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2007-05-05 15:31:52 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2007-05-05 15:31:52 +0000
commit0aa7e4583600de267f6a23b1a9f32f92cab19aae (patch)
treeb0abb8cff8872b5f469ef2181e92c0bfe3d81452
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
-rw-r--r--ChangeLog11
-rw-r--r--configure.ac2
-rw-r--r--doc/mailfromd.texi1
-rw-r--r--src/mailfromd.h2
-rw-r--r--src/main.c91
5 files changed, 78 insertions, 29 deletions
diff --git a/ChangeLog b/ChangeLog
index 1d3b74a1..cd0ea7c4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2007-05-05 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ * src/mailfromd.h (DEFAULT_PIDFILE): Use file name relative to
+ the state directory
+ * src/main.c (portspec,pidfile): Initialize dynamically.
+ (init_names): New function
+ (state_dir_fixup,portspec_fixup,fixup_state_dir_names): New
+ functions
+ (main): Call init_names and fixup_state_dir_names
+ (mailfromd_show_defaults): Use variables, not defines (hmmm)
+
2007-05-04 Sergey Poznyakoff <gray@gnu.org.ua>
* src/gram.y (convert_rate): Bugfix.
diff --git a/configure.ac b/configure.ac
index 25032d94..c0f27118 100644
--- a/configure.ac
+++ b/configure.ac
@@ -383,7 +383,7 @@ AC_ARG_VAR([DEFAULT_SOCKET],
[Set default communication socket.])
if test -z "$DEFAULT_SOCKET"; then
- DEFAULT_SOCKET='unix:$(DEFAULT_STATE_DIR)/mailfrom'
+ DEFAULT_SOCKET='mailfrom'
fi
AC_MSG_RESULT($DEFAULT_SOCKET)
diff --git a/doc/mailfromd.texi b/doc/mailfromd.texi
index c7d79b38..bf2fbb64 100644
--- a/doc/mailfromd.texi
+++ b/doc/mailfromd.texi
@@ -759,7 +759,6 @@ the corresponding section below.
@node 31x-32x
@section Upgrading from 3.1.x to 3.2
@cindex Upgrading from 3.1.x to 3.2
-@UNREVISED{}
Before building this version, please re-read the chapter
@xref{Building}, especially the section @xref{syslog-async, Using
diff --git a/src/mailfromd.h b/src/mailfromd.h
index d683448a..6fc0f044 100644
--- a/src/mailfromd.h
+++ b/src/mailfromd.h
@@ -150,7 +150,7 @@ mf_status getmxip(char *ipstr, mxbuf_t mxbuf);
/* Default file names */
-#define DEFAULT_PIDFILE DEFAULT_STATE_DIR "/mailfromd.pid"
+#define DEFAULT_PIDFILE "mailfromd.pid"
#define DEFAULT_DATABASE "mailfromd.db"
#define DEFAULT_RATE_DATABASE "rates.db"
#define DEFAULT_GREYLIST_DATABASE "greylist.db"
diff --git a/src/main.c b/src/main.c
index 13b513bb..d5a2ff62 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.