dovecot-2.0: Moved process title init to lib-master. With Linux-...
dovecot at dovecot.org
dovecot at dovecot.org
Wed Oct 21 03:20:37 EEST 2009
details: http://hg.dovecot.org/dovecot-2.0/rev/b584904d3bc7
changeset: 10120:b584904d3bc7
user: Timo Sirainen <tss at iki.fi>
date: Tue Oct 20 20:19:05 2009 -0400
description:
Moved process title init to lib-master. With Linux-hack enabled it now preserves command args.
diffstat:
23 files changed, 54 insertions(+), 42 deletions(-)
src/anvil/main.c | 2 +-
src/auth/main.c | 2 +-
src/config/doveconf.c | 2 +-
src/config/main.c | 2 +-
src/dict/main.c | 2 +-
src/doveadm/doveadm.c | 2 +-
src/dsync/dsync.c | 2 +-
src/imap-login/client.c | 1 -
src/imap/main.c | 6 ++----
src/lda/main.c | 2 +-
src/lib-master/master-service.c | 12 ++++++++----
src/lib-master/master-service.h | 2 +-
src/lib/process-title.c | 25 +++++++++++++++++++++----
src/lib/process-title.h | 2 +-
src/lmtp/main.c | 7 ++-----
src/log/main.c | 2 +-
src/login-common/main.c | 6 ++----
src/master/main.c | 2 +-
src/plugins/convert/convert-tool.c | 2 +-
src/plugins/expire/expire-tool.c | 2 +-
src/pop3/main.c | 6 ++----
src/ssl-params/main.c | 3 ++-
src/util/rawlog.c | 2 +-
diffs (truncated from 429 to 300 lines):
diff -r 1e63221f5c83 -r b584904d3bc7 src/anvil/main.c
--- a/src/anvil/main.c Tue Oct 20 20:07:45 2009 -0400
+++ b/src/anvil/main.c Tue Oct 20 20:19:05 2009 -0400
@@ -19,7 +19,7 @@ static void client_connected(const struc
int main(int argc, char *argv[])
{
- master_service = master_service_init("anvil", 0, argc, argv, NULL);
+ master_service = master_service_init("anvil", 0, &argc, &argv, NULL);
if (master_getopt(master_service) > 0)
return FATAL_DEFAULT;
diff -r 1e63221f5c83 -r b584904d3bc7 src/auth/main.c
--- a/src/auth/main.c Tue Oct 20 20:07:45 2009 -0400
+++ b/src/auth/main.c Tue Oct 20 20:19:05 2009 -0400
@@ -159,7 +159,7 @@ int main(int argc, char *argv[])
{
int c;
- master_service = master_service_init("auth", 0, argc, argv, "w");
+ master_service = master_service_init("auth", 0, &argc, &argv, "w");
master_service_init_log(master_service, "auth: ");
while ((c = master_getopt(master_service)) > 0) {
diff -r 1e63221f5c83 -r b584904d3bc7 src/config/doveconf.c
--- a/src/config/doveconf.c Tue Oct 20 20:07:45 2009 -0400
+++ b/src/config/doveconf.c Tue Oct 20 20:19:05 2009 -0400
@@ -233,7 +233,7 @@ int main(int argc, char *argv[])
memset(&filter, 0, sizeof(filter));
master_service = master_service_init("config",
MASTER_SERVICE_FLAG_STANDALONE,
- argc, argv, "af:m:nNe");
+ &argc, &argv, "af:m:nNe");
i_set_failure_prefix("doveconf: ");
while ((c = master_getopt(master_service)) > 0) {
if (c == 'e')
diff -r 1e63221f5c83 -r b584904d3bc7 src/config/main.c
--- a/src/config/main.c Tue Oct 20 20:07:45 2009 -0400
+++ b/src/config/main.c Tue Oct 20 20:19:05 2009 -0400
@@ -17,7 +17,7 @@ int main(int argc, char *argv[])
{
const char *path, *error;
- master_service = master_service_init("config", 0, argc, argv, NULL);
+ master_service = master_service_init("config", 0, &argc, &argv, NULL);
if (master_getopt(master_service) > 0)
return FATAL_DEFAULT;
diff -r 1e63221f5c83 -r b584904d3bc7 src/dict/main.c
--- a/src/dict/main.c Tue Oct 20 20:07:45 2009 -0400
+++ b/src/dict/main.c Tue Oct 20 20:19:05 2009 -0400
@@ -75,7 +75,7 @@ int main(int argc, char *argv[])
};
const char *error;
- master_service = master_service_init("dict", 0, argc, argv, NULL);
+ master_service = master_service_init("dict", 0, &argc, &argv, NULL);
if (master_getopt(master_service) > 0)
return FATAL_DEFAULT;
diff -r 1e63221f5c83 -r b584904d3bc7 src/doveadm/doveadm.c
--- a/src/doveadm/doveadm.c Tue Oct 20 20:07:45 2009 -0400
+++ b/src/doveadm/doveadm.c Tue Oct 20 20:19:05 2009 -0400
@@ -74,7 +74,7 @@ int main(int argc, char *argv[])
master_service = master_service_init("doveadm",
MASTER_SERVICE_FLAG_STANDALONE,
- argc, argv, "+");
+ &argc, &argv, "+");
i_array_init(&doveadm_cmds, 32);
doveadm_mail_init();
doveadm_register_cmd(&doveadm_cmd_help);
diff -r 1e63221f5c83 -r b584904d3bc7 src/dsync/dsync.c
--- a/src/dsync/dsync.c Tue Oct 20 20:07:45 2009 -0400
+++ b/src/dsync/dsync.c Tue Oct 20 20:19:05 2009 -0400
@@ -79,7 +79,7 @@ int main(int argc, char *argv[])
master_service = master_service_init("dsync",
MASTER_SERVICE_FLAG_STANDALONE |
MASTER_SERVICE_FLAG_STD_CLIENT,
- argc, argv, "b:e:fu:v");
+ &argc, &argv, "b:e:fu:v");
username = getenv("USER");
while ((c = master_getopt(master_service)) > 0) {
diff -r 1e63221f5c83 -r b584904d3bc7 src/imap-login/client.c
--- a/src/imap-login/client.c Tue Oct 20 20:07:45 2009 -0400
+++ b/src/imap-login/client.c Tue Oct 20 20:19:05 2009 -0400
@@ -5,7 +5,6 @@
#include "ioloop.h"
#include "istream.h"
#include "ostream.h"
-#include "process-title.h"
#include "safe-memset.h"
#include "str.h"
#include "strescape.h"
diff -r 1e63221f5c83 -r b584904d3bc7 src/imap/main.c
--- a/src/imap/main.c Tue Oct 20 20:07:45 2009 -0400
+++ b/src/imap/main.c Tue Oct 20 20:19:05 2009 -0400
@@ -8,7 +8,6 @@
#include "base64.h"
#include "restrict-access.h"
#include "fd-close-on-exec.h"
-#include "process-title.h"
#include "master-interface.h"
#include "master-service.h"
#include "master-login.h"
@@ -198,7 +197,7 @@ static void client_connected(const struc
}
}
-int main(int argc, char *argv[], char *envp[])
+int main(int argc, char *argv[])
{
enum master_service_flags service_flags = 0;
@@ -218,10 +217,9 @@ int main(int argc, char *argv[], char *e
}
master_service = master_service_init("imap", service_flags,
- argc, argv, NULL);
+ &argc, &argv, NULL);
if (master_getopt(master_service) > 0)
exit(FATAL_DEFAULT);
- process_title_init(argv, envp);
master_service_init_finish(master_service);
/* plugins may want to add commands, so this needs to be called early */
diff -r 1e63221f5c83 -r b584904d3bc7 src/lda/main.c
--- a/src/lda/main.c Tue Oct 20 20:07:45 2009 -0400
+++ b/src/lda/main.c Tue Oct 20 20:19:05 2009 -0400
@@ -287,7 +287,7 @@ int main(int argc, char *argv[])
master_service = master_service_init("lda",
MASTER_SERVICE_FLAG_STANDALONE |
MASTER_SERVICE_FLAG_DONT_LOG_TO_STDERR,
- argc, argv, "a:d:p:ekm:nsf:");
+ &argc, &argv, "a:d:p:ekm:nsf:");
memset(&ctx, 0, sizeof(ctx));
ctx.pool = pool_alloconly_create("mail deliver context", 256);
diff -r 1e63221f5c83 -r b584904d3bc7 src/lib-master/master-service.c
--- a/src/lib-master/master-service.c Tue Oct 20 20:07:45 2009 -0400
+++ b/src/lib-master/master-service.c Tue Oct 20 20:19:05 2009 -0400
@@ -6,6 +6,7 @@
#include "array.h"
#include "env-util.h"
#include "home-expand.h"
+#include "process-title.h"
#include "restrict-access.h"
#include "fd-close-on-exec.h"
#include "settings-parser.h"
@@ -78,8 +79,9 @@ static void master_service_verify_versio
struct master_service *
master_service_init(const char *name, enum master_service_flags flags,
- int argc, char *argv[], const char *getopt_str)
-{
+ int *argc, char **argv[], const char *getopt_str)
+{
+ extern char **environ;
struct master_service *service;
const char *str;
@@ -106,9 +108,11 @@ master_service_init(const char *name, en
if (getenv(MASTER_UID_ENV) == NULL)
flags |= MASTER_SERVICE_FLAG_STANDALONE;
+ process_title_init(argv, environ);
+
service = i_new(struct master_service, 1);
- service->argc = argc;
- service->argv = argv;
+ service->argc = *argc;
+ service->argv = *argv;
service->name = i_strdup(name);
service->getopt_str =
i_strconcat(master_service_getopt_string(), getopt_str, NULL);
diff -r 1e63221f5c83 -r b584904d3bc7 src/lib-master/master-service.h
--- a/src/lib-master/master-service.h Tue Oct 20 20:07:45 2009 -0400
+++ b/src/lib-master/master-service.h Tue Oct 20 20:19:05 2009 -0400
@@ -43,7 +43,7 @@ const char *master_service_getopt_string
/* Start service initialization. */
struct master_service *
master_service_init(const char *name, enum master_service_flags flags,
- int argc, char *argv[], const char *getopt_str);
+ int *argc, char **argv[], const char *getopt_str);
/* Call getopt() and handle internal parameters. Return values are the same as
getopt()'s. */
int master_getopt(struct master_service *service);
diff -r 1e63221f5c83 -r b584904d3bc7 src/lib/process-title.c
--- a/src/lib/process-title.c Tue Oct 20 20:07:45 2009 -0400
+++ b/src/lib/process-title.c Tue Oct 20 20:19:05 2009 -0400
@@ -48,6 +48,23 @@ static void linux_proctitle_init(char *a
process_title_len = (size_t) (envp[i-1] - argv[0]) + strlen(envp[i-1]);
}
+static char **argv_dup(char *old_argv[])
+{
+ char **new_argv;
+ unsigned int i, count;
+
+ for (count = 0; old_argv[count] != NULL; count++) ;
+
+ new_argv = malloc(sizeof(char *) * (count + 1));
+ for (i = 0; i < count; i++) {
+ new_argv[i] = strdup(old_argv[i]);
+ if (new_argv[i] == NULL)
+ i_fatal_status(FATAL_OUTOFMEM, "strdup() failed: %m");
+ }
+ new_argv[i] = NULL;
+ return new_argv;
+}
+
static void linux_proctitle_set(const char *title)
{
i_strocpy(process_title, title, process_title_len);
@@ -55,12 +72,13 @@ static void linux_proctitle_set(const ch
#endif
-void process_title_init(char *argv[], char *envp[] ATTR_UNUSED)
+void process_title_init(char **argv[], char *envp[] ATTR_UNUSED)
{
#ifdef LINUX_PROCTITLE_HACK
- linux_proctitle_init(argv, envp);
+ *argv = argv_dup(*argv);
+ linux_proctitle_init(*argv, envp);
#endif
- process_name = argv[0];
+ process_name = (*argv)[0];
}
void process_title_set(const char *title ATTR_UNUSED)
@@ -76,4 +94,3 @@ void process_title_set(const char *title
linux_proctitle_set(t_strconcat(process_name, " ", title, NULL));
#endif
}
-
diff -r 1e63221f5c83 -r b584904d3bc7 src/lib/process-title.h
--- a/src/lib/process-title.h Tue Oct 20 20:07:45 2009 -0400
+++ b/src/lib/process-title.h Tue Oct 20 20:19:05 2009 -0400
@@ -2,7 +2,7 @@
#define PROCESS_TITLE_H
/* Initialize title changing. */
-void process_title_init(char *argv[], char *envp[]);
+void process_title_init(char **argv[], char *envp[]);
/* Change the process title if possible. */
void process_title_set(const char *title);
diff -r 1e63221f5c83 -r b584904d3bc7 src/lmtp/main.c
--- a/src/lmtp/main.c Tue Oct 20 20:07:45 2009 -0400
+++ b/src/lmtp/main.c Tue Oct 20 20:19:05 2009 -0400
@@ -5,7 +5,6 @@
#include "ioloop.h"
#include "restrict-access.h"
#include "fd-close-on-exec.h"
-#include "process-title.h"
#include "master-service.h"
#include "master-service-settings.h"
#include "master-interface.h"
@@ -52,7 +51,7 @@ static void main_deinit(void)
clients_destroy();
}
-int main(int argc, char *argv[], char *envp[])
+int main(int argc, char *argv[])
{
const struct setting_parser_info *set_roots[] = {
&lda_setting_parser_info,
@@ -70,7 +69,7 @@ int main(int argc, char *argv[], char *e
}
master_service = master_service_init("lmtp", service_flags,
- argc, argv, NULL);
+ &argc, &argv, NULL);
if (master_getopt(master_service) > 0)
return FATAL_DEFAULT;
@@ -78,8 +77,6 @@ int main(int argc, char *argv[], char *e
set_roots,
storage_service_flags);
restrict_access_allow_coredumps(TRUE);
-
- process_title_init(argv, envp);
main_init();
master_service_run(master_service, client_connected);
diff -r 1e63221f5c83 -r b584904d3bc7 src/log/main.c
--- a/src/log/main.c Tue Oct 20 20:07:45 2009 -0400
+++ b/src/log/main.c Tue Oct 20 20:19:05 2009 -0400
@@ -39,7 +39,7 @@ int main(int argc, char *argv[])
{
const char *error;
- master_service = master_service_init("log", 0, argc, argv, NULL);
+ master_service = master_service_init("log", 0, &argc, &argv, NULL);
/* use log prefix and log to stderr until we've configured the real
logging */
diff -r 1e63221f5c83 -r b584904d3bc7 src/login-common/main.c
More information about the dovecot-cvs
mailing list