Mercurial > masqmail
changeset 251:2babd21e7c75
moved run_queue to a new function
plus various small cleanups, mostly cosmetic
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Thu, 04 Nov 2010 13:00:19 -0300 (2010-11-04) |
parents | a41c013c8458 |
children | 1b25fabdc3cb |
files | src/masqmail.c |
diffstat | 1 files changed, 54 insertions(+), 46 deletions(-) [+] |
line wrap: on
line diff
--- a/src/masqmail.c Thu Nov 04 12:32:11 2010 -0300 +++ b/src/masqmail.c Thu Nov 04 13:00:19 2010 -0300 @@ -353,38 +353,53 @@ return ok; } +static int +run_queue(gboolean do_runq, gboolean do_runq_online, char* route_name) +{ + int ret; + + /* queue runs */ + set_identity(conf.orig_uid, "queue run"); + + if (do_runq) { + ret = queue_run(); + } + + if (do_runq_online) { + if (route_name) { + conf.online_detect = g_strdup("argument"); + set_online_name(route_name); + } + ret = queue_run_online(); + } + return ret; +} + int main(int argc, char *argv[]) { - /* cmd line flags */ - gchar *conf_file = CONF_FILE; + gchar *progname; char* opt; gint arg; + mta_mode mta_mode = MODE_ACCEPT; gboolean do_listen = FALSE; gboolean do_runq = FALSE; gboolean do_runq_online = FALSE; - gboolean do_queue = FALSE; - - gboolean do_verbose = FALSE; - gint debug_level = -1; - - mta_mode mta_mode = MODE_ACCEPT; - gint queue_interval = 0; + gchar *M_cmd = NULL; gboolean opt_t = FALSE; gboolean opt_i = FALSE; gboolean exit_failure = FALSE; - - gchar *M_cmd = NULL; - gint exit_code = EXIT_SUCCESS; + gchar *conf_file = CONF_FILE; gchar *route_name = NULL; - gchar *progname; gchar *f_address = NULL; + address *return_path = NULL; /* may be changed by -f option */ gchar *full_sender_name = NULL; - address *return_path = NULL; /* may be changed by -f option */ + gboolean do_verbose = FALSE; + gint debug_level = -1; progname = get_progname(argv[0]); @@ -408,7 +423,7 @@ /* parse cmd line */ for (arg=1; arg<argc && argv[arg][0]=='-'; arg++) { - opt = argv[arg] + 1; + opt = argv[arg] + 1; /* points to the char after the dash */ if (strcmp(opt, "-") == 0) { /* everything after `--' are address arguments */ @@ -437,7 +452,8 @@ get_optarg(argv, &arg, opt+1); } else if (strncmp(opt, "C", 1) == 0) { - if (!(conf_file = get_optarg(argv, &arg, opt+1))) { + conf_file = get_optarg(argv, &arg, opt+1); + if (!conf_file) { fprintf(stderr, "-C requires a filename as argument.\n"); exit(EXIT_FAILURE); } @@ -510,7 +526,9 @@ do_runq = TRUE; mta_mode = MODE_RUNQUEUE; - if ((optarg = get_optarg(argv, &arg, opt+1))) { + optarg = get_optarg(argv, &arg, opt+1); + if (optarg) { + /* not just one single queue run but regular runs */ mta_mode = MODE_DAEMON; queue_interval = time_interval(optarg, &dummy); } @@ -556,10 +574,12 @@ { int i, max_fd = sysconf(_SC_OPEN_MAX); - if (max_fd <= 0) + if (max_fd <= 0) { max_fd = 64; - for (i = 3; i < max_fd; i++) + } + for (i=3; i<max_fd; i++) { close(i); + } } init_conf(); @@ -571,14 +591,12 @@ So it is possible for a user to run his own daemon without breaking security. */ - if (strcmp(conf_file, CONF_FILE) != 0) { - if (conf.orig_uid != 0) { - conf.run_as_user = TRUE; - seteuid(conf.orig_uid); - setegid(conf.orig_gid); - setuid(conf.orig_uid); - setgid(conf.orig_gid); - } + if ((strcmp(conf_file, CONF_FILE) != 0) && (conf.orig_uid != 0)) { + conf.run_as_user = TRUE; + seteuid(conf.orig_uid); + setegid(conf.orig_gid); + setuid(conf.orig_uid); + setgid(conf.orig_gid); } conf.log_dir = LOG_DIR; @@ -589,12 +607,15 @@ } logclose(); - if (do_queue) + if (do_queue) { conf.do_queue = TRUE; - if (do_verbose) + } + if (do_verbose) { conf.do_verbose = TRUE; - if (debug_level >= 0) /* if >= 0, it was given by argument */ + } + if (debug_level >= 0) { /* if >= 0, it was given by argument */ conf.debug_level = debug_level; + } /* It appears that changing to / ensures that we are never in a directory which we cannot access. This situation could be @@ -646,23 +667,9 @@ case MODE_DAEMON: mode_daemon(do_listen, queue_interval, argv); break; + case MODE_RUNQUEUE: - { - /* queue runs */ - set_identity(conf.orig_uid, "queue run"); - - if (do_runq) - exit_code = queue_run() ? EXIT_SUCCESS : EXIT_FAILURE; - - if (do_runq_online) { - if (route_name != NULL) { - conf.online_detect = g_strdup("argument"); - set_online_name(route_name); - } - exit_code = - queue_run_online() ? EXIT_SUCCESS : EXIT_FAILURE; - } - } + exit(run_queue(do_runq, do_runq_online, route_name) ? 0 : 1); break; case MODE_SMTP: @@ -691,6 +698,7 @@ break; case MODE_NONE: break; + default: fprintf(stderr, "unknown mode: %d\n", mta_mode); break;