]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
* Fix logging when process is starting
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 26 Feb 2009 15:51:31 +0000 (18:51 +0300)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 26 Feb 2009 15:51:31 +0000 (18:51 +0300)
* Add -t option for config testing
* Try to search default config in install prefix not in current directory

config.h.in
rspamd.conf.sample
src/cfg_file.h
src/cfg_utils.c
src/main.c
src/main.h
src/util.c

index 23d08ee363bd9578f8653904dea5f5f0e9631351..23aabf6668d7fe187ad5c019e7d3095bd25b7c83 100644 (file)
 #include <gmime/gmime.h>
 #endif
 
+#define CMAKE_PREFIX "${CMAKE_INSTALL_PREFIX}"
+
 /* Forwarded declaration */
 struct module_ctx;
 struct config_file;
index 0c6ba3189d68a4b574848f9cf08b21b3765ee6e3..41b44ccdda988cb74cb866071324a93753604145 100644 (file)
@@ -41,7 +41,7 @@ logging {
        # log_facility = "LOG_MAIL";
        
        # Log file is used with log type "file"
-       # log_file = /var/log/rspamd.log
+       # log_file = "/var/log/rspamd.log"
 };
 
 # Limit for statfile pool size
index 7bacb8aa9f4326944b8bec27541df5c4c2d096c8..78ad6e93aff080d727b2e221184b5d67f159e3f5 100644 (file)
@@ -153,7 +153,8 @@ struct config_file {
        int controller_enabled;                                                 /**< whether controller is enabled                                              */
        char *control_password;                                                 /**< controller password                                                                */
 
-       int no_fork;                                                                    /**< if 1 do not call daemon()                                                  */
+       gboolean no_fork;                                                               /**< if 1 do not call daemon()                                                  */
+       gboolean config_test;                                                   /**< if TRUE do only config file test                                   */
        unsigned int workers_number;                                    /**< number of workers                                                                  */
 
        enum rspamd_log_type log_type;                                  /**< log type                                                                                   */
index 2785e18d9cf8a4a008f9f0a2a705fb47e46e8d4f..e90fe11cb68e827e948ef4ad77e719841fb32c47 100644 (file)
@@ -681,7 +681,7 @@ parse_err (const char *fmt, ...)
        r += vsnprintf (logbuf + r, sizeof (logbuf) - r, fmt, aq);
 
        va_end (aq);
-       g_error ("%s", logbuf);
+       g_critical ("%s", logbuf);
 }
 
 void
index 6a170726a15167e9982aa95c9a8385cdad07ba92..9c2da60b7af1547291e75704671bc8a3275ac0d6 100644 (file)
@@ -265,9 +265,16 @@ main (int argc, char **argv, char **env)
 
        rspamd->cfg->cfg_name = memory_pool_strdup (rspamd->cfg->cfg_pool, FIXED_CONFIG_FILE);
        read_cmd_line (argc, argv, rspamd->cfg);
+
+       if (cfg->config_test) {
+               cfg->log_level = G_LOG_LEVEL_DEBUG;
+       }
+       else {
+               cfg->log_level = G_LOG_LEVEL_CRITICAL;
+       }
        
        /* First set logger to console logger */
-       cfg->log_fd = 2;
+       cfg->log_fd = STDERR_FILENO;
        g_log_set_default_handler (file_log_function, cfg);
 
        #ifndef HAVE_SETPROCTITLE
@@ -287,6 +294,11 @@ main (int argc, char **argv, char **env)
        }
 
        fclose (f);
+
+       if (cfg->config_test) {
+               fprintf (stderr, "syntax OK\n");
+               return EXIT_SUCCESS;
+       }
        
        config_logger (rspamd, TRUE);
 
index fab8a9040dda532a5b16952b0e616bba594806e9..8661346f186b72d92e7fbf657718124a63074a57 100644 (file)
@@ -17,7 +17,7 @@
 #include "buffer.h"
 
 /* Default values */
-#define FIXED_CONFIG_FILE "./rspamd.conf"
+#define FIXED_CONFIG_FILE CMAKE_PREFIX "/etc/rspamd.conf"
 /* Time in seconds to exit for old worker */
 #define SOFT_SHUTDOWN_TIME 60
 /* Default metric name */
index cffa5e06b17e685ebc9d5e51903966aa2c82c27a..a7aea229cb3a8aece40b744085ab7ee0f781ef73 100644 (file)
@@ -118,7 +118,7 @@ void
 read_cmd_line (int argc, char **argv, struct config_file *cfg)
 {
        int ch;
-       while ((ch = getopt(argc, argv, "hfc:")) != -1) {
+       while ((ch = getopt(argc, argv, "thfc:")) != -1) {
         switch (ch) {
             case 'f':
                 cfg->no_fork = 1;
@@ -128,13 +128,17 @@ read_cmd_line (int argc, char **argv, struct config_file *cfg)
                     cfg->cfg_name = memory_pool_strdup (cfg->cfg_pool, optarg);
                 }
                 break;
+                       case 't':
+                               cfg->config_test = 1;
+                               break;
             case 'h':
             case '?':
             default:
                 /* Show help message and exit */
                 printf ("Rspamd version " RVERSION "\n"
-                        "Usage: rspamd [-h] [-n] [-f] [-c config_file]\n"
+                        "Usage: rspamd [-t] [-h] [-n] [-f] [-c config_file]\n"
                         "-h:        This help message\n"
+                                               "-t:        Do config test and exit\n"
                         "-f:        Do not daemonize main process\n"
                         "-c:        Specify config file (./rspamd.conf is used by default)\n");
                 exit (0);