]> git.ipfire.org Git - thirdparty/postfix.git/commitdiff
postfix-2.10-20120308
authorWietse Venema <wietse@porcupine.org>
Thu, 8 Mar 2012 05:00:00 +0000 (00:00 -0500)
committerViktor Dukhovni <viktor@dukhovni.org>
Tue, 5 Feb 2013 06:38:04 +0000 (06:38 +0000)
15 files changed:
postfix/HISTORY
postfix/RELEASE_NOTES
postfix/conf/postfix-script
postfix/html/master.8.html
postfix/html/postconf.1.html
postfix/man/man1/postconf.1
postfix/man/man8/master.8
postfix/src/global/mail_version.h
postfix/src/master/Makefile.in
postfix/src/master/master.c
postfix/src/master/master.h
postfix/src/master/master_monitor.c [new file with mode: 0644]
postfix/src/postconf/postconf.c
postfix/src/postconf/postconf.h
postfix/src/postconf/postconf_edit.c

index de788f25a84819e680ec5bf77bee55c8c9430519..4a35978d6088f96c766d03d9925436437899f59d 100644 (file)
@@ -17668,3 +17668,19 @@ Apologies for any names omitted.
        of specific permit-like actions in Postfix SMTP server
        access lists.  Files: mantools/postlink, proto/postconf.proto,
        global/mail_params.h, smtpd/smtpd.c, smtpd/smtpd_check.c.
+
+20120306
+
+       To improve the interaction with start-up scripts, "postfix
+       start" now waits for master daemon process initialization
+       to complete, and returns a non-zero exit status if daemon
+       initialization failed or if it did not complete in a
+       reasonable amount of time. This involves a new "-w" master
+       option.  Files: conf/postfix-script, master/master.c,
+       master/master.h.  master/master_monitor.c.
+
+20120307
+
+       postconf -X option to exclude parameters from main.cf
+       (require two-finger action, because this is irreversible).
+       Files: postconf/postconf.[hc], postconf/postconf_edit.c.
index aeed5bf1072b3727e7fd39ddfcf2f4382896bedc..dea294e292f20edfd8b29889c96490d6d2419e72 100644 (file)
@@ -14,6 +14,16 @@ specifies the release date of a stable release or snapshot release.
 If you upgrade from Postfix 2.8 or earlier, read RELEASE_NOTES-2.9
 before proceeding.
 
+Major changes with snapshot 20120306
+====================================
+
+New master "-w" option, to wait for daemon process initialization
+to complete. This feature returns an error exit status if master
+daemon initialization fails, or if it does not complete in a
+reasonable amount of time. The exit status is used by "postfix
+start" to provide more accurate information to system start-up
+scripts.
+
 Major changes with snapshot 20120303
 ====================================
 
index 805e288e7d7466e21a3b9b34d95658a9f1ab11c6..68c663fd1fcba7da394bcd4f26a63e338740a0c1 100644 (file)
@@ -124,7 +124,11 @@ start)
                $daemon_directory/postfix-script check-warn
        fi
        $INFO starting the Postfix mail system
-       $daemon_directory/master &
+       # NOTE: wait in foreground process to get the initialization status.
+       $daemon_directory/master -w || {
+           $FATAL "mail system startup failed"
+           exit 1
+       }
        ;;
 
 drain)
index db08b69fe43a60d14ec13b40afe2f05604ce1ff4..87e764451228d800f966ef0bb155e80c7bdf2739 100644 (file)
@@ -10,7 +10,7 @@ MASTER(8)                                                            MASTER(8)
        master - Postfix master process
 
 <b>SYNOPSIS</b>
-       <b>master</b> [<b>-Ddtv</b>] [<b>-c</b> <i>config</i><b>_</b><i>dir</i>] [<b>-e</b> <i>exit</i><b>_</b><i>time</i>]
+       <b>master</b> [<b>-Ddtvw</b>] [<b>-c</b> <i>config</i><b>_</b><i>dir</i>] [<b>-e</b> <i>exit</i><b>_</b><i>time</i>]
 
 <b>DESCRIPTION</b>
        The  <a href="master.8.html"><b>master</b>(8)</a>  daemon  is  the resident process that runs
@@ -61,6 +61,16 @@ MASTER(8)                                                            MASTER(8)
               option is passed on to child processes. Multiple <b>-v</b>
               options make the software increasingly verbose.
 
+       <b>-w</b>     Wait  in a dummy foreground process, while the real
+              master daemon initializes in a background  process.
+              The  dummy  foreground  process returns a zero exit
+              status only if the master daemon initialization  is
+              successful,  and  if  it  completes in a reasonable
+              amount of time.
+
+              This feature  is  available  in  Postfix  2.10  and
+              later.
+
        Signals:
 
        <b>SIGHUP</b> Upon  receipt of a <b>HUP</b> signal (e.g., after "<b>postfix</b>
@@ -81,12 +91,14 @@ MASTER(8)                                                            MASTER(8)
               running processes to finish what they are doing.
 
 <b>DIAGNOSTICS</b>
-       Problems are reported to <b>syslogd</b>(8).
+       Problems  are  reported  to <b>syslogd</b>(8). The exit status is
+       non-zero in case of  problems,  including  problems  while
+       initializing as a master daemon process in the background.
 
 <b>ENVIRONMENT</b>
        <b>MAIL_DEBUG</b>
               After initialization, start a debugger as specified
-              with the <b><a href="postconf.5.html#debugger_command">debugger_command</a></b>  configuration  parameter
+              with  the  <b><a href="postconf.5.html#debugger_command">debugger_command</a></b> configuration parameter
               in the <a href="postconf.5.html"><b>main.cf</b></a> configuration file.
 
        <b>MAIL_CONFIG</b>
@@ -95,22 +107,22 @@ MASTER(8)                                                            MASTER(8)
 <b>CONFIGURATION PARAMETERS</b>
        Unlike most Postfix daemon processes, the <a href="master.8.html"><b>master</b>(8)</a> server
        does not automatically pick up changes to <a href="postconf.5.html"><b>main.cf</b></a>. Changes
-       to  <a href="master.5.html"><b>master.cf</b></a>  are never picked up automatically.  Use the
+       to <a href="master.5.html"><b>master.cf</b></a> are never picked up automatically.   Use  the
        "<b>postfix reload</b>" command after a configuration change.
 
 <b>RESOURCE AND RATE CONTROLS</b>
        <b><a href="postconf.5.html#default_process_limit">default_process_limit</a> (100)</b>
-              The default maximal number of  Postfix  child  pro-
+              The  default  maximal  number of Postfix child pro-
               cesses that provide a given service.
 
        <b><a href="postconf.5.html#max_idle">max_idle</a> (100s)</b>
-              The  maximum  amount  of  time that an idle Postfix
-              daemon process waits  for  an  incoming  connection
+              The maximum amount of time  that  an  idle  Postfix
+              daemon  process  waits  for  an incoming connection
               before terminating voluntarily.
 
        <b><a href="postconf.5.html#max_use">max_use</a> (100)</b>
-              The  maximal  number of incoming connections that a
-              Postfix daemon process will service  before  termi-
+              The maximal number of incoming connections  that  a
+              Postfix  daemon  process will service before termi-
               nating voluntarily.
 
        <b><a href="postconf.5.html#service_throttle_time">service_throttle_time</a> (60s)</b>
@@ -120,16 +132,16 @@ MASTER(8)                                                            MASTER(8)
        Available in Postfix version 2.6 and later:
 
        <b><a href="postconf.5.html#master_service_disable">master_service_disable</a> (empty)</b>
-              Selectively disable  <a href="master.8.html"><b>master</b>(8)</a>  listener  ports  by
+              Selectively  disable  <a href="master.8.html"><b>master</b>(8)</a>  listener  ports by
               service type or by service name and type.
 
 <b>MISCELLANEOUS CONTROLS</b>
        <b><a href="postconf.5.html#config_directory">config_directory</a> (see 'postconf -d' output)</b>
-              The  default  location  of  the Postfix <a href="postconf.5.html">main.cf</a> and
+              The default location of  the  Postfix  <a href="postconf.5.html">main.cf</a>  and
               <a href="master.5.html">master.cf</a> configuration files.
 
        <b><a href="postconf.5.html#daemon_directory">daemon_directory</a> (see 'postconf -d' output)</b>
-              The directory with  Postfix  support  programs  and
+              The  directory  with  Postfix  support programs and
               daemon programs.
 
        <b><a href="postconf.5.html#debugger_command">debugger_command</a> (empty)</b>
@@ -141,11 +153,11 @@ MASTER(8)                                                            MASTER(8)
               tem receives mail on.
 
        <b><a href="postconf.5.html#inet_protocols">inet_protocols</a> (all)</b>
-              The  Internet protocols Postfix will attempt to use
+              The Internet protocols Postfix will attempt to  use
               when making or accepting connections.
 
        <b><a href="postconf.5.html#import_environment">import_environment</a> (see 'postconf -d' output)</b>
-              The list of environment parameters that  a  Postfix
+              The  list  of environment parameters that a Postfix
               process  will  import  from  a  non-Postfix  parent
               process.
 
@@ -154,23 +166,23 @@ MASTER(8)                                                            MASTER(8)
               and most Postfix daemon processes.
 
        <b><a href="postconf.5.html#process_id">process_id</a> (read-only)</b>
-              The  process  ID  of  a  Postfix  command or daemon
+              The process ID  of  a  Postfix  command  or  daemon
               process.
 
        <b><a href="postconf.5.html#process_name">process_name</a> (read-only)</b>
-              The process name of a  Postfix  command  or  daemon
+              The  process  name  of  a Postfix command or daemon
               process.
 
        <b><a href="postconf.5.html#queue_directory">queue_directory</a> (see 'postconf -d' output)</b>
-              The  location of the Postfix top-level queue direc-
+              The location of the Postfix top-level queue  direc-
               tory.
 
        <b><a href="postconf.5.html#syslog_facility">syslog_facility</a> (mail)</b>
               The syslog facility of Postfix logging.
 
        <b><a href="postconf.5.html#syslog_name">syslog_name</a> (see 'postconf -d' output)</b>
-              The mail system  name  that  is  prepended  to  the
-              process  name  in  syslog  records, so that "smtpd"
+              The  mail  system  name  that  is  prepended to the
+              process name in syslog  records,  so  that  "smtpd"
               becomes, for example, "postfix/smtpd".
 
 <b>FILES</b>
@@ -190,7 +202,7 @@ MASTER(8)                                                            MASTER(8)
        syslogd(8), system logging
 
 <b>LICENSE</b>
-       The  Secure  Mailer  license must be distributed with this
+       The Secure Mailer license must be  distributed  with  this
        software.
 
 <b>AUTHOR(S)</b>
index a07120b6edcf6a99e091984c9ee15870cc12f17e..783d5b45d0352cc52b857bb58650ebf8b531c503 100644 (file)
@@ -17,7 +17,7 @@ POSTCONF(1)                                                        POSTCONF(1)
 
        <b>postconf</b> [<b>-ev</b>] [<b>-c</b> <i>config</i><b>_</b><i>dir</i>] [<i>parameter=value ...</i>]
 
-       <b>postconf</b> [<b>-#v</b>] [<b>-c</b> <i>config</i><b>_</b><i>dir</i>] [<i>parameter ...</i>]
+       <b>postconf</b> [<b>-#vX</b>] [<b>-c</b> <i>config</i><b>_</b><i>dir</i>] [<i>parameter ...</i>]
 
        <b>Managing <a href="master.5.html">master.cf</a>:</b>
 
@@ -312,6 +312,16 @@ POSTCONF(1)                                                        POSTCONF(1)
               tiple <b>-v</b> options  make  the  software  increasingly
               verbose.
 
+       <b>-X</b>     Edit the <a href="postconf.5.html"><b>main.cf</b></a> configuration file, and remove the
+              parameters given on the <a href="postconf.1.html"><b>postconf</b>(1)</a>  command  line.
+              The file is copied to a temporary file then renamed
+              into place.  Specify a list of parameter names, not
+              <i>name</i>=<i>value</i>  pairs.  There is no <a href="postconf.1.html"><b>postconf</b>(1)</a> command
+              to perform the reverse operation.
+
+              This feature is available  with  Postfix  2.10  and
+              later.
+
        <b>-#</b>     Edit  the  <a href="postconf.5.html"><b>main.cf</b></a>  configuration file, and comment
               out the parameters given on the <a href="postconf.1.html"><b>postconf</b>(1)</a> command
               line,  so  that  those  parameters  revert to their
index 9717c9cf26879403bf1a8d2655e79d24c6257be9..7f52555b15c311385d1b9756cbc69cef3d9a6c14 100644 (file)
@@ -17,7 +17,7 @@ Postfix configuration utility
 \fBpostconf\fR [\fB-ev\fR] [\fB-c \fIconfig_dir\fR]
 [\fIparameter=value ...\fR]
 
-\fBpostconf\fR [\fB-#v\fR] [\fB-c \fIconfig_dir\fR]
+\fBpostconf\fR [\fB-#vX\fR] [\fB-c \fIconfig_dir\fR]
 [\fIparameter ...\fR]
 
 \fBManaging master.cf:\fR
@@ -273,6 +273,16 @@ This feature is available with Postfix 2.3 and later.
 .IP \fB-v\fR
 Enable verbose logging for debugging purposes. Multiple \fB-v\fR
 options make the software increasingly verbose.
+.IP \fB-X\fR
+Edit the \fBmain.cf\fR configuration file, and remove
+the parameters given on the \fBpostconf\fR(1) command line.
+The file is copied to a temporary file then renamed into
+place.
+Specify a list of parameter names, not \fIname\fR=\fIvalue\fR
+pairs.  There is no \fBpostconf\fR(1) command to perform
+the reverse operation.
+
+This feature is available with Postfix 2.10 and later.
 .IP \fB-#\fR
 Edit the \fBmain.cf\fR configuration file, and comment out
 the parameters given on the \fBpostconf\fR(1) command line,
index 0953cce38924c1f3e6eb3f672c46f55419b58e42..45bdbde12dccadeb64ae6cc9678630710d5e03ef 100644 (file)
@@ -8,7 +8,7 @@ Postfix master process
 .SH "SYNOPSIS"
 .na
 .nf
-\fBmaster\fR [\fB-Ddtv\fR] [\fB-c \fIconfig_dir\fR] [\fB-e \fIexit_time\fR]
+\fBmaster\fR [\fB-Ddtvw\fR] [\fB-c \fIconfig_dir\fR] [\fB-e \fIexit_time\fR]
 .SH DESCRIPTION
 .ad
 .fi
@@ -51,6 +51,14 @@ that the \fBmaster\fR(8) daemon is not running.
 Enable verbose logging for debugging purposes. This option
 is passed on to child processes. Multiple \fB-v\fR options
 make the software increasingly verbose.
+.IP \fB-w\fR
+Wait in a dummy foreground process, while the real master
+daemon initializes in a background process.  The dummy
+foreground process returns a zero exit status only if the
+master daemon initialization is successful, and if it
+completes in a reasonable amount of time.
+.sp
+This feature is available in Postfix 2.10 and later.
 .PP
 Signals:
 .IP \fBSIGHUP\fR
@@ -71,7 +79,9 @@ processes to finish what they are doing.
 .SH DIAGNOSTICS
 .ad
 .fi
-Problems are reported to \fBsyslogd\fR(8).
+Problems are reported to \fBsyslogd\fR(8). The exit status
+is non-zero in case of problems, including problems while
+initializing as a master daemon process in the background.
 .SH "ENVIRONMENT"
 .na
 .nf
index 2ac9de75bdb51f5195bee210c92d223791a82040..c0f057eb9728cb9f5e9a0dd4e21af8ffce9bfc4e 100644 (file)
@@ -20,7 +20,7 @@
   * Patches change both the patchlevel and the release date. Snapshots have no
   * patchlevel; they change the release date only.
   */
-#define MAIL_RELEASE_DATE      "20120305"
+#define MAIL_RELEASE_DATE      "20120308"
 #define MAIL_VERSION_NUMBER    "2.10"
 
 #ifdef SNAPSHOT
index f1a59f61506adfa058aca34e50297a6719f7c4df..2305da34648f7938d0483552ea47fee70729e462 100644 (file)
@@ -2,10 +2,12 @@ SHELL = /bin/sh
 SRCS   = master.c master_conf.c master_ent.c master_sig.c master_avail.c \
        master_spawn.c master_service.c master_status.c master_listen.c \
        master_proto.c single_server.c multi_server.c master_vars.c \
-       master_wakeup.c master_flow.c master_watch.c mail_flow.c
+       master_wakeup.c master_flow.c master_watch.c mail_flow.c \
+       master_monitor.c
 OBJS   = master.o master_conf.o master_ent.o master_sig.o master_avail.o \
        master_spawn.o master_service.o master_status.o master_listen.o \
-       master_vars.o master_wakeup.o master_watch.o master_flow.o
+       master_vars.o master_wakeup.o master_watch.o master_flow.o \
+       master_monitor.o
 LIB_OBJ        = single_server.o multi_server.o trigger_server.o master_proto.o \
        mail_flow.o event_server.o
 HDRS   = mail_server.h master_proto.h mail_flow.h
@@ -207,6 +209,11 @@ master_listen.o: ../../include/vbuf.h
 master_listen.o: ../../include/vstring.h
 master_listen.o: master.h
 master_listen.o: master_listen.c
+master_monitor.o: ../../include/iostuff.h
+master_monitor.o: ../../include/msg.h
+master_monitor.o: ../../include/sys_defs.h
+master_monitor.o: master.h
+master_monitor.o: master_monitor.c
 master_proto.o: ../../include/msg.h
 master_proto.o: ../../include/sys_defs.h
 master_proto.o: master_proto.c
index 532eb789e438ecde42628cdb08d7f697d28d6710..be9e6d5b3b446616d21162cad68733dc9791109d 100644 (file)
@@ -4,7 +4,7 @@
 /* SUMMARY
 /*     Postfix master process
 /* SYNOPSIS
-/*     \fBmaster\fR [\fB-Ddtv\fR] [\fB-c \fIconfig_dir\fR] [\fB-e \fIexit_time\fR]
+/*     \fBmaster\fR [\fB-Ddtvw\fR] [\fB-c \fIconfig_dir\fR] [\fB-e \fIexit_time\fR]
 /* DESCRIPTION
 /*     The \fBmaster\fR(8) daemon is the resident process that runs Postfix
 /*     daemons on demand: daemons to send or receive messages via the
 /*     Enable verbose logging for debugging purposes. This option
 /*     is passed on to child processes. Multiple \fB-v\fR options
 /*     make the software increasingly verbose.
+/* .IP \fB-w\fR
+/*     Wait in a dummy foreground process, while the real master
+/*     daemon initializes in a background process.  The dummy
+/*     foreground process returns a zero exit status only if the
+/*     master daemon initialization is successful, and if it
+/*     completes in a reasonable amount of time.
+/* .sp
+/*     This feature is available in Postfix 2.10 and later.
 /* .PP
 /*     Signals:
 /* .IP \fBSIGHUP\fR
@@ -63,7 +71,9 @@
 /*     terminate only the master ("\fBpostfix stop\fR") and allow running
 /*     processes to finish what they are doing.
 /* DIAGNOSTICS
-/*     Problems are reported to \fBsyslogd\fR(8).
+/*     Problems are reported to \fBsyslogd\fR(8). The exit status
+/*     is non-zero in case of problems, including problems while
+/*     initializing as a master daemon process in the background.
 /* ENVIRONMENT
 /* .ad
 /* .fi
@@ -221,7 +231,7 @@ static void master_exit_event(int unused_event, char *unused_context)
 
 static NORETURN usage(const char *me)
 {
-    msg_fatal("usage: %s [-c config_dir] [-D (debug)] [-d (don't detach from terminal)] [-e exit_time] [-t (test)] [-v]", me);
+    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);
 }
 
 MAIL_VERSION_STAMP_DECLARE;
@@ -243,6 +253,8 @@ int     main(int argc, char **argv)
     VSTRING *why;
     WATCHDOG *watchdog;
     ARGV   *import_env;
+    int     wait_flag = 0;
+    int     monitor_fd = -1;
 
     /*
      * Fingerprint executables and core dumps.
@@ -311,7 +323,7 @@ int     main(int argc, char **argv)
     /*
      * Process JCL.
      */
-    while ((ch = GETOPT(argc, argv, "c:Dde:tv")) > 0) {
+    while ((ch = GETOPT(argc, argv, "c:Dde:tvw")) > 0) {
        switch (ch) {
        case 'c':
            if (setenv(CONF_ENV_PATH, optarg, 1) < 0)
@@ -332,6 +344,9 @@ int     main(int argc, char **argv)
        case 'v':
            msg_verbose++;
            break;
+       case 'w':
+           wait_flag = 1;
+           break;
        default:
            usage(argv[0]);
            /* NOTREACHED */
@@ -344,6 +359,17 @@ int     main(int argc, char **argv)
     if (argc > optind)
        usage(argv[0]);
 
+    /*
+     * Run a foreground monitor process that returns an exit status of 0 when
+     * the child background process reports successful initialization as a
+     * daemon process. We use a generous limit in case main/master.cf specify
+     * symbolic hosts/ports and the naming service is slow.
+     */
+#define MASTER_INIT_TIMEOUT    100             /* keep this limit generous */
+
+    if (wait_flag)
+       monitor_fd = master_monitor(MASTER_INIT_TIMEOUT);
+
     /*
      * If started from a terminal, get rid of any tty association. This also
      * means that all errors and warnings must go to the syslog daemon.
@@ -470,6 +496,14 @@ int     main(int argc, char **argv)
     msg_info("daemon started -- version %s, configuration %s",
             var_mail_version, var_config_dir);
 
+    /*
+     * Report successful initialization to the foreground monitor process.
+     */
+    if (monitor_fd >= 0) {
+       write(monitor_fd, "", 1);
+       (void) close(monitor_fd);
+    }
+
     /*
      * Process events. The event handler will execute the read/write/timer
      * action routines. Whenever something has happened, see if we received
index 954dac4f7b4f422166f87a41b67c9f438213c11f..baf5b143a52c86953881094daa609bcb6e69e726 100644 (file)
@@ -219,6 +219,11 @@ typedef struct {
 extern void master_str_watch(const MASTER_STR_WATCH *);
 extern void master_int_watch(MASTER_INT_WATCH *);
 
+ /*
+  * master_monitor.c
+  */
+extern int master_monitor(int);
+
 /* DIAGNOSTICS
 /* BUGS
 /* SEE ALSO
diff --git a/postfix/src/master/master_monitor.c b/postfix/src/master/master_monitor.c
new file mode 100644 (file)
index 0000000..4119ea9
--- /dev/null
@@ -0,0 +1,100 @@
+/*++
+/* NAME
+/*     master_monitor 3
+/* SUMMARY
+/*     Postfix master - start-up monitoring
+/* SYNOPSIS
+/*     #include "master.h"
+/*
+/*     int     master_monitor(time_limit)
+/*     int     time_limit;
+/* DESCRIPTION
+/*     master_monitor() forks off a background child process, and
+/*     returns in the child. The result value is the file descriptor
+/*     on which the child process must write one byte after it
+/*     completes successful initialization as a daemon process.
+/*
+/*     The foreground process waits for the child's completion for
+/*     a limited amount of time. It terminates with exit status 0
+/*     in case of success, non-zero otherwise.
+/* DIAGNOSTICS
+/*     Fatal errors: system call failure.
+/* BUGS
+/* SEE ALSO
+/* LICENSE
+/* .ad
+/* .fi
+/*     The Secure Mailer license must be distributed with this software.
+/* AUTHOR(S)
+/*     Wietse Venema
+/*     IBM T.J. Watson Research
+/*     P.O. Box 704
+/*     Yorktown Heights, NY 10598, USA
+/*--*/
+
+/* System library. */
+
+#include <sys_defs.h>
+#include <signal.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+/* Utility library. */
+
+#include <msg.h>
+#include <iostuff.h>
+
+/* Application-specific. */
+
+#include <master.h>
+
+/* master_monitor - fork off a foreground monitor process */
+
+int     master_monitor(int time_limit)
+{
+    pid_t   pid;
+    int     pipes[2];
+    char    buf[1];
+
+    /*
+     * Sanity check.
+     */
+    if (time_limit <= 0)
+       msg_panic("master_monitor: bad time limit: %d", time_limit);
+
+    /*
+     * Set up the plumbing for child-to-parent communication.
+     */
+    if (pipe(pipes) < 0)
+       msg_fatal("pipe: %m");
+    close_on_exec(pipes[0], CLOSE_ON_EXEC);
+    close_on_exec(pipes[1], CLOSE_ON_EXEC);
+
+    /*
+     * Fork the child, and wait for it to report successful initialization.
+     */
+    switch (pid = fork()) {
+    case -1:
+       /* Error. */
+       msg_fatal("fork: %m");
+    case 0:
+       /* Child. Initialize as daemon in the background. */
+       close(pipes[0]);
+       return (pipes[1]);
+    default:
+       /* Parent. Monitor the child in the foreground. */
+       close(pipes[1]);
+       switch (timed_read(pipes[0], buf, 1, time_limit, (char *) 0)) {
+       default:
+           /* The child process still runs, but something is wrong. */
+           (void) kill(pid, SIGKILL);
+           /* FALLTHROUGH */
+       case 0:
+           /* The child process exited prematurely. */
+           msg_fatal("daemon initialization failure");
+       case 1:
+           /* The child process initialized successfully. */
+           exit(0);
+       }
+    }
+}
index becede83455c0300a1a12f41d9cd422881bf787c..e9f0b340198a9e145968b9e94d5f0c38c102e6d8 100644 (file)
@@ -13,7 +13,7 @@
 /*     \fBpostconf\fR [\fB-ev\fR] [\fB-c \fIconfig_dir\fR]
 /*     [\fIparameter=value ...\fR]
 /*
-/*     \fBpostconf\fR [\fB-#v\fR] [\fB-c \fIconfig_dir\fR]
+/*     \fBpostconf\fR [\fB-#vX\fR] [\fB-c \fIconfig_dir\fR]
 /*     [\fIparameter ...\fR]
 /*
 /*     \fBManaging master.cf:\fR
 /* .IP \fB-v\fR
 /*     Enable verbose logging for debugging purposes. Multiple \fB-v\fR
 /*     options make the software increasingly verbose.
+/* .IP \fB-X\fR
+/*     Edit the \fBmain.cf\fR configuration file, and remove
+/*     the parameters given on the \fBpostconf\fR(1) command line.
+/*     The file is copied to a temporary file then renamed into
+/*     place.
+/*     Specify a list of parameter names, not \fIname\fR=\fIvalue\fR
+/*     pairs.  There is no \fBpostconf\fR(1) command to perform
+/*     the reverse operation.
+/*
+/*     This feature is available with Postfix 2.10 and later.
 /* .IP \fB-#\fR
 /*     Edit the \fBmain.cf\fR configuration file, and comment out
 /*     the parameters given on the \fBpostconf\fR(1) command line,
@@ -412,7 +422,7 @@ int     main(int argc, char **argv)
     /*
      * Parse JCL.
      */
-    while ((ch = GETOPT(argc, argv, "aAbc:C:deEf#hlmMntv")) > 0) {
+    while ((ch = GETOPT(argc, argv, "aAbc:C:deEf#hlmMntvX")) > 0) {
        switch (ch) {
        case 'a':
            cmd_mode |= SHOW_SASL_SERV;
@@ -432,7 +442,7 @@ int     main(int argc, char **argv)
            break;
        case 'C':
            param_class = name_mask_opt("-C option", param_class_table,
-                                   optarg, NAME_MASK_ANY_CASE | NAME_MASK_FATAL);
+                             optarg, NAME_MASK_ANY_CASE | NAME_MASK_FATAL);
            break;
        case 'd':
            cmd_mode |= SHOW_DEFS;
@@ -480,24 +490,29 @@ int     main(int argc, char **argv)
            ext_argv = argv_alloc(2);
            argv_add(ext_argv, "bounce", "-SVndump_templates", (char *) 0);
            break;
+       case 'X':
+           /* This is irreversible, therefore require two-finger action. */
+           cmd_mode = EDIT_EXCL;
+           break;
        case 'v':
            msg_verbose++;
            break;
        default:
-           msg_fatal("usage: %s [-a (server SASL types)] [-A (client SASL types)] [-b (bounce templates)] [-c config_dir] [-C param_class] [-d (defaults)] [-e (edit)] [-f (fold lines)] [-# (comment-out)] [-h (no names)] [-l (lock types)] [-m (map types)] [-M (master.cf)] [-n (non-defaults)] [-v] [name...]", argv[0]);
+           msg_fatal("usage: %s [-a (server SASL types)] [-A (client SASL types)] [-b (bounce templates)] [-c config_dir] [-C param_class] [-d (defaults)] [-e (edit)] [-f (fold lines)] [-# (comment-out)] [-h (no names)] [-l (lock types)] [-m (map types)] [-M (master.cf)] [-n (non-defaults)] [-v] [-X (exclude)] [name...]", argv[0]);
        }
     }
 
     /*
      * Sanity check.
      */
-    junk = (cmd_mode & (SHOW_DEFS | SHOW_NONDEF | SHOW_MAPS | SHOW_LOCKS | EDIT_MAIN | SHOW_SASL_SERV | SHOW_SASL_CLNT | COMMENT_OUT | SHOW_MASTER));
+    junk = (cmd_mode & (SHOW_DEFS | SHOW_NONDEF | SHOW_MAPS | SHOW_LOCKS | EDIT_MAIN | SHOW_SASL_SERV | SHOW_SASL_CLNT | COMMENT_OUT | SHOW_MASTER | EDIT_EXCL));
     if (junk != 0 && ((junk != SHOW_DEFS && junk != SHOW_NONDEF
             && junk != SHOW_MAPS && junk != SHOW_LOCKS && junk != EDIT_MAIN
                       && junk != SHOW_SASL_SERV && junk != SHOW_SASL_CLNT
-                      && junk != COMMENT_OUT && junk != SHOW_MASTER)
+                      && junk != COMMENT_OUT && junk != SHOW_MASTER
+                      && junk != EDIT_EXCL)
                      || ext_argv != 0))
-       msg_fatal("specify one of -a, -A, -b, -d, -e, -#, -l, -m, -M and -n");
+       msg_fatal("specify one of -a, -A, -b, -d, -e, -#, -l, -m, -M, -n, and -X");
 
     /*
      * Display bounce template information and exit.
@@ -555,7 +570,7 @@ int     main(int argc, char **argv)
     /*
      * Edit main.cf.
      */
-    else if (cmd_mode & (EDIT_MAIN | COMMENT_OUT)) {
+    else if (cmd_mode & (EDIT_MAIN | COMMENT_OUT | EDIT_EXCL)) {
        edit_parameters(cmd_mode, argc - optind, argv + optind);
     } else if (cmd_mode == DEF_MODE
               && argv[optind] && strchr(argv[optind], '=')) {
index 8a3bb8ad9f0241fc2eb6c57553b9300142c1c5da..f197d122369bbb978d56fd1856d822ca4ce28279 100644 (file)
@@ -30,6 +30,7 @@
 #define COMMENT_OUT    (1<<9)          /* #-out selected main.cf entries */
 #define SHOW_MASTER    (1<<10)         /* show master.cf entries */
 #define FOLD_LINE      (1<<11)         /* fold long *.cf entries */
+#define EDIT_EXCL      (1<<12)         /* exclude main.cf entries */
 
 #define DEF_MODE       SHOW_NAME       /* default mode */
 
@@ -165,7 +166,7 @@ extern void register_user_parameters(void);
   * postconf_dbms.c
   */
 extern void register_dbms_parameters(const char *,
-                                const char *(*) (const char *, int, char *),
+                               const char *(*) (const char *, int, char *),
                                             PC_MASTER_ENT *);
 
  /*
index 660e7e9c3dac83ece00a0d7d039130d5cd99618b..fcfe76338d2c1a3e0d2d80b6634562fb85753e8d 100644 (file)
@@ -88,19 +88,19 @@ void    edit_parameters(int mode, int argc, char **argv)
     table = htable_create(argc);
     while ((cp = *argv++) != 0) {
        if (strchr(cp, '\n') != 0)
-           msg_fatal("-e or -# accepts no multi-line input");
+           msg_fatal("-e, -X, or -# accepts no multi-line input");
        while (ISSPACE(*cp))
            cp++;
        if (*cp == '#')
-           msg_fatal("-e or -# accepts no comment input");
+           msg_fatal("-e, -X, or -# accepts no comment input");
        if (mode & EDIT_MAIN) {
            if ((err = split_nameval(cp, &edit_key, &edit_val)) != 0)
                msg_fatal("%s: \"%s\"", err, cp);
-       } else if (mode & COMMENT_OUT) {
+       } else if (mode & (COMMENT_OUT | EDIT_EXCL)) {
            if (*cp == 0)
-               msg_fatal("-# requires non-blank parameter names");
+               msg_fatal("-X or -# requires non-blank parameter names");
            if (strchr(cp, '=') != 0)
-               msg_fatal("-# requires parameter names only");
+               msg_fatal("-X or -# requires parameter names only");
            edit_key = mystrdup(cp);
            trimblanks(edit_key, 0);
            edit_val = 0;
@@ -164,8 +164,6 @@ void    edit_parameters(int mode, int argc, char **argv)
                    vstream_fprintf(dst, "%s = %s\n", STR(key), cvalue->value);
                else if (mode & COMMENT_OUT)
                    vstream_fprintf(dst, "#%s", cp);
-               else
-                   msg_panic("edit_parameters: unknown mode %d", mode);
            } else {
                vstream_fputs(STR(buf), dst);
            }