195 #include <sys/stat.h>
242 static void master_exit_event(
int unused_event,
void *unused_context)
244 msg_info(
"master exit time has arrived");
250 static NORETURN usage(
const char *me)
252 msg_fatal(
"usage: %s [-c config_dir] [-D (debug)] [-d (don't detach from terminal)] [-e exit_time] [-t (test)] [-v] [-w (wait for initialization)]", me);
259 int main(
int argc,
char **argv)
265 off_t inherited_limit;
298 signal(SIGPIPE, SIG_IGN);
337 msg_fatal(
"the master command is reserved for the superuser");
339 msg_fatal(
"the master command must not run as a set-uid process");
344 while ((ch =
GETOPT(argc, argv,
"c:Dde:itvw")) > 0) {
358 msg_fatal(
"-i is allowed only for PID 1 process");
388 if (test_lock && wait_flag)
389 msg_fatal(
"the -t and -w options cannot be used together");
391 msg_fatal(
"the -i option cannot be used with -D, -d, or -w");
399 #define MASTER_INIT_TIMEOUT 100
409 for (fd = 0; fd < 3; fd++) {
411 if (open(
"/dev/null", O_RDWR, 0) != fd)
421 && setsid() == -1 && getsid(0) != getpid())
422 msg_fatal(
"unable to set session and process group ID: %m");
433 for (n = 0; n < 5; n++) {
476 if (test_lock && access(
vstring_str(lock_path), F_OK) < 0)
480 exit(lock_fp ? 0 : 1);
498 if (data_lock_fp == 0)
501 vstream_fprintf(data_lock_fp,
"%*lu\n", (
int)
sizeof(
unsigned long) * 4,
502 (
unsigned long) var_pid);
528 msg_info(
"daemon started -- version %s, configuration %s",
534 if (monitor_fd >= 0) {
535 write(monitor_fd,
"", 1);
536 (void) close(monitor_fd);
546 #define MASTER_WATCHDOG_TIME 1000
550 #ifdef HAS_VOLATILE_LOCKS
561 msg_info(
"reload -- version %s, configuration %s",
#define MASTER_WATCHDOG_TIME
void master_reap_child(void)
const char * mail_task(const char *argv0)
char * mystrdup(const char *str)
char * var_import_environ
ARGV * argv_free(ARGV *argvp)
#define VAR_IMPORT_ENVIRON
void master_refresh(void)
#define MYFLOCK_OP_EXCLUSIVE
INET_PROTO_INFO * inet_proto_init(const char *context, const char *protocols)
VSTREAM * open_lock(const char *path, int flags, mode_t mode, VSTRING *why)
void set_file_limit(off_t limit)
int main(int argc, char **argv)
void master_flow_init(void)
void watchdog_start(WATCHDOG *wp)
void(* WATCHDOG_FN)(WATCHDOG *, char *)
off_t get_file_limit(void)
void clean_env(char **preserve_list)
void master_sigsetup(void)
#define MASTER_INIT_TIMEOUT
ARGV * mail_parm_split(const char *name, const char *value)
VSTREAM * vstream_fprintf(VSTREAM *stream, const char *fmt,...)
void event_loop(int delay)
WATCHDOG * watchdog_create(unsigned timeout, WATCHDOG_FN action, char *context)
VSTRING * vstring_alloc(ssize_t len)
int myflock(int fd, int lock_style, int operation)
#define MAIL_VERSION_STAMP_ALLOCATE
#define VAR_INET_PROTOCOLS
VSTRING * vstring_sprintf(VSTRING *vp, const char *format,...)
MAIL_VERSION_STAMP_DECLARE
NORETURN msg_fatal(const char *fmt,...)
#define MAIL_VERSION_CHECK
int vstream_fflush(VSTREAM *stream)
void set_eugid(uid_t euid, gid_t egid)
void master_vars_init(void)
#define GETOPT(argc, argv, str)
void msg_syslog_init(const char *name, int logopt, int facility)
void set_ugid(uid_t uid, gid_t gid)
VSTRING * vstring_free(VSTRING *vp)
time_t event_request_timer(EVENT_NOTIFY_TIME_FN callback, void *context, int delay)
#define vstream_fileno(vp)
char * var_inet_protocols
int close_on_exec(int fd, int on)
void msg_info(const char *fmt,...)