From: Timo Sirainen Date: Wed, 21 Oct 2009 00:19:05 +0000 (-0400) Subject: Moved process title init to lib-master. With Linux-hack enabled it now preserves... X-Git-Tag: 2.0.alpha2~43 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a3fe8c0c54d87822f4b4f8f0d10caac611861b2b;p=thirdparty%2Fdovecot%2Fcore.git Moved process title init to lib-master. With Linux-hack enabled it now preserves command args. --HG-- branch : HEAD --- diff --git a/src/anvil/main.c b/src/anvil/main.c index 726158d61a..31bebb1a04 100644 --- a/src/anvil/main.c +++ b/src/anvil/main.c @@ -19,7 +19,7 @@ static void client_connected(const struct master_service_connection *conn) 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 --git a/src/auth/main.c b/src/auth/main.c index 198b62c25d..4ff873ec12 100644 --- a/src/auth/main.c +++ b/src/auth/main.c @@ -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 --git a/src/config/doveconf.c b/src/config/doveconf.c index df1c83dbb2..113316a23a 100644 --- a/src/config/doveconf.c +++ b/src/config/doveconf.c @@ -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 --git a/src/config/main.c b/src/config/main.c index ddb6a09958..5cf61e28be 100644 --- a/src/config/main.c +++ b/src/config/main.c @@ -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 --git a/src/dict/main.c b/src/dict/main.c index 92c010b7ee..5f79c93bdd 100644 --- a/src/dict/main.c +++ b/src/dict/main.c @@ -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 --git a/src/doveadm/doveadm.c b/src/doveadm/doveadm.c index 6a6a1527a3..60f830a37f 100644 --- a/src/doveadm/doveadm.c +++ b/src/doveadm/doveadm.c @@ -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 --git a/src/dsync/dsync.c b/src/dsync/dsync.c index e6cdc6e8ae..abad33b697 100644 --- a/src/dsync/dsync.c +++ b/src/dsync/dsync.c @@ -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 --git a/src/imap-login/client.c b/src/imap-login/client.c index 3bcbc2d444..a7f620230a 100644 --- a/src/imap-login/client.c +++ b/src/imap-login/client.c @@ -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 --git a/src/imap/main.c b/src/imap/main.c index 2587c1de1c..aedb0ebe3c 100644 --- a/src/imap/main.c +++ b/src/imap/main.c @@ -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 struct master_service_connection *conn) } } -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 *envp[]) } 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 --git a/src/lda/main.c b/src/lda/main.c index 55d5b490ad..a17f7d9029 100644 --- a/src/lda/main.c +++ b/src/lda/main.c @@ -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 --git a/src/lib-master/master-service.c b/src/lib-master/master-service.c index 9eed3a1799..c160a2bbb7 100644 --- a/src/lib-master/master-service.c +++ b/src/lib-master/master-service.c @@ -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_version(struct master_service *service) 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, enum master_service_flags flags, 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 --git a/src/lib-master/master-service.h b/src/lib-master/master-service.h index 3250f05105..824030bfb3 100644 --- a/src/lib-master/master-service.h +++ b/src/lib-master/master-service.h @@ -43,7 +43,7 @@ const char *master_service_getopt_string(void); /* 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 --git a/src/lib/process-title.c b/src/lib/process-title.c index 2be1f059d3..69f7d56680 100644 --- a/src/lib/process-title.c +++ b/src/lib/process-title.c @@ -48,6 +48,23 @@ static void linux_proctitle_init(char *argv[], char *envp[]) 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 char *title) #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 ATTR_UNUSED) linux_proctitle_set(t_strconcat(process_name, " ", title, NULL)); #endif } - diff --git a/src/lib/process-title.h b/src/lib/process-title.h index 84c1b25c95..ef1110e8df 100644 --- a/src/lib/process-title.h +++ b/src/lib/process-title.h @@ -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 --git a/src/lmtp/main.c b/src/lmtp/main.c index 4a2329d046..bbf322fda2 100644 --- a/src/lmtp/main.c +++ b/src/lmtp/main.c @@ -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 *envp[]) } master_service = master_service_init("lmtp", service_flags, - argc, argv, NULL); + &argc, &argv, NULL); if (master_getopt(master_service) > 0) return FATAL_DEFAULT; @@ -79,8 +78,6 @@ int main(int argc, char *argv[], char *envp[]) storage_service_flags); restrict_access_allow_coredumps(TRUE); - process_title_init(argv, envp); - main_init(); master_service_run(master_service, client_connected); diff --git a/src/log/main.c b/src/log/main.c index bcf7ac3b65..2c8aaecfc0 100644 --- a/src/log/main.c +++ b/src/log/main.c @@ -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 --git a/src/login-common/main.c b/src/login-common/main.c index ec49daf76b..b757d755c0 100644 --- a/src/login-common/main.c +++ b/src/login-common/main.c @@ -5,7 +5,6 @@ #include "randgen.h" #include "restrict-access.h" #include "restrict-process-size.h" -#include "process-title.h" #include "master-auth.h" #include "master-service.h" #include "master-interface.h" @@ -166,7 +165,7 @@ static void main_deinit(void) } } -int main(int argc, char *argv[], char *envp[]) +int main(int argc, char *argv[]) { enum master_service_flags service_flags = MASTER_SERVICE_FLAG_KEEP_CONFIG_OPEN | @@ -176,7 +175,7 @@ int main(int argc, char *argv[], char *envp[]) int c; master_service = master_service_init(login_process_name, service_flags, - argc, argv, "DS"); + &argc, &argv, "DS"); master_service_init_log(master_service, t_strconcat( login_process_name, ": ", NULL)); @@ -195,7 +194,6 @@ int main(int argc, char *argv[], char *envp[]) login_process_preinit(); - process_title_init(argv, envp); set_pool = pool_alloconly_create("global login settings", 4096); global_login_settings = login_settings_read(master_service, set_pool, NULL, NULL, diff --git a/src/master/main.c b/src/master/main.c index ca59268b44..229b007906 100644 --- a/src/master/main.c +++ b/src/master/main.c @@ -606,7 +606,7 @@ int main(int argc, char *argv[]) master_service = master_service_init(MASTER_SERVICE_NAME, MASTER_SERVICE_FLAG_STANDALONE | MASTER_SERVICE_FLAG_DONT_LOG_TO_STDERR, - argc, argv, "Fanp-"); + &argc, &argv, "Fanp-"); i_set_failure_prefix(""); io_loop_set_time_moved_callback(current_ioloop, master_time_moved); diff --git a/src/plugins/convert/convert-tool.c b/src/plugins/convert/convert-tool.c index ae430f523a..bd8c99b658 100644 --- a/src/plugins/convert/convert-tool.c +++ b/src/plugins/convert/convert-tool.c @@ -27,7 +27,7 @@ int main(int argc, char *argv[]) master_service = master_service_init("convert-tool", MASTER_SERVICE_FLAG_STANDALONE, - argc, argv, NULL); + &argc, &argv, NULL); if (master_getopt(master_service) > 0) i_fatal(USAGE_STRING); diff --git a/src/plugins/expire/expire-tool.c b/src/plugins/expire/expire-tool.c index 6951b470c2..b8044dbc96 100644 --- a/src/plugins/expire/expire-tool.c +++ b/src/plugins/expire/expire-tool.c @@ -317,7 +317,7 @@ int main(int argc, char *argv[]) master_service = master_service_init("expire-tool", MASTER_SERVICE_FLAG_STANDALONE, - argc, argv, "t"); + &argc, &argv, "t"); while ((c = master_getopt(master_service)) > 0) { switch (c) { diff --git a/src/pop3/main.c b/src/pop3/main.c index b7e2efc609..9446bbc674 100644 --- a/src/pop3/main.c +++ b/src/pop3/main.c @@ -7,7 +7,6 @@ #include "ostream.h" #include "base64.h" #include "restrict-access.h" -#include "process-title.h" #include "master-service.h" #include "master-login.h" #include "master-interface.h" @@ -161,7 +160,7 @@ static void client_connected(const struct master_service_connection *conn) } } -int main(int argc, char *argv[], char *envp[]) +int main(int argc, char *argv[]) { enum master_service_flags service_flags = 0; @@ -181,10 +180,9 @@ int main(int argc, char *argv[], char *envp[]) } master_service = master_service_init("pop3", service_flags, - argc, argv, NULL); + &argc, &argv, NULL); if (master_getopt(master_service) > 0) return FATAL_DEFAULT; - process_title_init(argv, envp); master_service_init_finish(master_service); if (IS_STANDALONE()) { diff --git a/src/ssl-params/main.c b/src/ssl-params/main.c index aaa340aef1..ffa8bdd568 100644 --- a/src/ssl-params/main.c +++ b/src/ssl-params/main.c @@ -116,7 +116,8 @@ int main(int argc, char *argv[]) { const struct ssl_params_settings *set; - master_service = master_service_init("ssl-params", 0, argc, argv, NULL); + master_service = master_service_init("ssl-params", 0, + &argc, &argv, NULL); master_service_init_log(master_service, "ssl-params: "); if (master_getopt(master_service) > 0) diff --git a/src/util/rawlog.c b/src/util/rawlog.c index 21c550448a..ed080194d3 100644 --- a/src/util/rawlog.c +++ b/src/util/rawlog.c @@ -348,7 +348,7 @@ int main(int argc, char *argv[], char *envp[]) lib_init(); i_set_failure_internal(); - process_title_init(argv, envp); + process_title_init(&argv, envp); argc--; argv++;