You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "Ralf S. Engelschall" <rs...@engelschall.com> on 1998/05/12 14:27:10 UTC

[PATCH] (for 1.3.1-dev) Option -t to run syntax config syntax check only

[for 1.3.1-dev]

Option to run syntax test for config files only
===============================================

I wondered for a long time why Apache don't provide a way to check the syntax
in configuration files. This is often needed in scripts which update the files
or do a hard kill/restart of a server to make sure it doesn't fall down
because of a syntax error. Every good program provides a command line option
which forces the program to parse its configuration stuff but exits
immediately after this step (e.g. perl -c).

The above patch adds a -t option which can be used like this

$ httpd -t -f /path/to/you/httpd.conf
Syntax OK
$ _

Greetings,
                                       Ralf S. Engelschall
                                       rse@engelschall.com
                                       www.engelschall.com

Index: src/main/http_main.c
===================================================================
RCS file: /e/apache/REPOS/apache-1.3/src/main/http_main.c,v
retrieving revision 1.351
diff -u -r1.351 http_main.c
--- http_main.c	1998/05/11 20:08:08	1.351
+++ http_main.c	1998/05/12 10:20:24
@@ -876,7 +876,7 @@
     fprintf(stderr, "Usage: %s [-d directory] [-f file]\n", bin);
 #endif
     fprintf(stderr, "       %s [-C \"directive\"] [-c \"directive\"]\n", pad);
-    fprintf(stderr, "       %s [-v] [-V] [-h] [-l] [-S]\n", pad);
+    fprintf(stderr, "       %s [-v] [-V] [-h] [-l] [-S] [-t]\n", pad);
     fprintf(stderr, "Options:\n");
 #ifdef SHARED_CORE
     fprintf(stderr, "  -L directory     : specify an alternate location for shared object files\n");
@@ -890,6 +890,7 @@
     fprintf(stderr, "  -h               : list available configuration directives\n");
     fprintf(stderr, "  -l               : list compiled-in modules\n");
     fprintf(stderr, "  -S               : show parsed settings (currently only vhost settings)\n");
+    fprintf(stderr, "  -t               : run syntax test for configuration files only\n");
     exit(1);
 }
 
@@ -4190,6 +4191,7 @@
 int REALMAIN(int argc, char *argv[])
 {
     int c;
+    int configtestonly = 0;
 
 #ifdef SOCKS
     SOCKSinit(argv[0]);
@@ -4206,7 +4208,7 @@
     ap_setup_prelinked_modules();
 
     while ((c = getopt(argc, argv,
-				    "C:c:Xd:f:vVhlL:S"
+				    "C:c:Xd:f:vVhlL:St"
 #ifdef DEBUG_SIGSTOP
 				    "Z:"
 #endif
@@ -4262,6 +4264,9 @@
 	case 'S':
 	    ap_dump_settings = 1;
 	    break;
+	case 't':
+	    configtestonly = 1;
+	    break;
 	case '?':
 	    usage(argv[0]);
 	}
@@ -4270,6 +4275,11 @@
     ap_suexec_enabled = init_suexec();
     server_conf = ap_read_config(pconf, ptrans, ap_server_confname);
 
+    if (configtestonly) {
+        fprintf(stderr, "Syntax OK\n");
+        exit(0);
+    }
+
     child_timeouts = !ap_standalone || one_process;
 
     if (ap_standalone) {
@@ -5335,6 +5345,7 @@
     char *cp;
     int run_as_service = 1;
     int install = 0;
+    int configtestonly = 0;
     
     common_init();
 
@@ -5359,7 +5370,7 @@
 
     ap_setup_prelinked_modules();
 
-    while ((c = getopt(argc, argv, "C:c:Xd:f:vVhlZ:iusS")) != -1) {
+    while ((c = getopt(argc, argv, "C:c:Xd:f:vVhlZ:iusSt")) != -1) {
         char **new;
 	switch (c) {
 	case 'c':
@@ -5417,6 +5428,9 @@
 	case 'X':
 	    ++one_process;	/* Weird debugging mode. */
 	    break;
+	case 't':
+	    configtestonly = 1;
+	    break;
 	case '?':
 	    usage(argv[0]);
 	}
@@ -5427,6 +5441,12 @@
     }
 
     server_conf = ap_read_config(pconf, ptrans, ap_server_confname);
+
+    if (configtestonly) {
+        fprintf(stderr, "Syntax OK\n");
+        exit(0);
+    }
+
     if (!child) {
 	ap_log_pid(pconf, ap_pid_fname);
     }
Index: src/support/httpd.8
===================================================================
RCS file: /e/apache/REPOS/apache-1.3/src/support/httpd.8,v
retrieving revision 1.9
diff -u -r1.9 httpd.8
--- httpd.8	1998/05/12 11:14:31	1.9
+++ httpd.8	1998/05/12 12:21:05
@@ -149,6 +149,11 @@
 Show the settings as parsed from the config file (currently only shows the
 virtualhost settings).
 .TP
+.B \-t
+Run syntax checks for configuration files only. The program immediately exits
+after these checks with either a return code of 0 (Syntax OK) or return code
+not equal to 0 (Syntax Error).
+.TP
 .B \-X
 Run in single-process mode, for internal debugging purposes only; the daemon
 does not detach from the terminal or fork any children. Do NOT use this mode