]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Log paths now support "syslog" string.
authorTimo Sirainen <tss@iki.fi>
Wed, 16 Jun 2010 16:38:15 +0000 (17:38 +0100)
committerTimo Sirainen <tss@iki.fi>
Wed, 16 Jun 2010 16:38:15 +0000 (17:38 +0100)
--HG--
branch : HEAD

src/doveadm/doveadm-log.c
src/lib-master/master-service-settings.c
src/lib-master/master-service.c

index 42e202ebd3a6fbe4d57f20ccf0865097a9c803b2..82c61fe3bdec64d1ab4711581c72b568be083580 100644 (file)
@@ -218,23 +218,30 @@ static void cmd_log_find(int argc, char *argv[])
        /* first get the paths that we know are used */
        set = master_service_settings_get(master_service);
        log_file_path = set->log_path;
-       if (*log_file_path != '\0') {
+       if (*log_file_path != '\0' && strcmp(log_file_path, "syslog") != 0) {
                cmd_log_find_add(&ctx, log_file_path, LOG_TYPE_WARNING);
                cmd_log_find_add(&ctx, log_file_path, LOG_TYPE_ERROR);
                cmd_log_find_add(&ctx, log_file_path, LOG_TYPE_FATAL);
        }
 
-       if (*set->info_log_path != '\0')
-               log_file_path = set->info_log_path;
-       if (*log_file_path != '\0')
-               cmd_log_find_add(&ctx, log_file_path, LOG_TYPE_INFO);
+       if (strcmp(set->info_log_path, "syslog") != 0) {
+               if (*set->info_log_path != '\0')
+                       log_file_path = set->info_log_path;
+               if (*log_file_path != '\0')
+                       cmd_log_find_add(&ctx, log_file_path, LOG_TYPE_INFO);
+       }
 
-       if (*set->debug_log_path != '\0')
-               log_file_path = set->debug_log_path;
-       if (*log_file_path != '\0')
-               cmd_log_find_add(&ctx, log_file_path, LOG_TYPE_DEBUG);
+       if (strcmp(set->debug_log_path, "syslog") != 0) {
+               if (*set->debug_log_path != '\0')
+                       log_file_path = set->debug_log_path;
+               if (*log_file_path != '\0')
+                       cmd_log_find_add(&ctx, log_file_path, LOG_TYPE_DEBUG);
+       }
 
-       if (*set->log_path == '\0') {
+       if (*set->log_path == '\0' ||
+           strcmp(set->log_path, "syslog") == 0 ||
+           strcmp(set->info_log_path, "syslog") == 0 ||
+           strcmp(set->debug_log_path, "syslog") == 0) {
                /* at least some logs were logged via syslog */
                cmd_log_find_syslog(&ctx, argc, argv);
        }
index 0f527d4ad8bbf9879c2938eab7fe9ba50d809996..ac1ab8c9229162667a3b5f3df0748403157c4628 100644 (file)
@@ -27,6 +27,9 @@
 #define DEF(type, name) \
        { type, #name, offsetof(struct master_service_settings, name), NULL }
 
+static bool
+master_service_settings_check(void *_set, pool_t pool, const char **error_r);
+
 static const struct setting_define master_service_setting_defines[] = {
        DEF(SET_STR, log_path),
        DEF(SET_STR, info_log_path),
@@ -41,7 +44,7 @@ static const struct setting_define master_service_setting_defines[] = {
 };
 
 static const struct master_service_settings master_service_default_settings = {
-       .log_path = "",
+       .log_path = "syslog",
        .info_log_path = "",
        .debug_log_path = "",
        .log_timestamp = DEFAULT_FAILURE_STAMP_FORMAT,
@@ -59,9 +62,25 @@ const struct setting_parser_info master_service_setting_parser_info = {
        .type_offset = (size_t)-1,
        .struct_size = sizeof(struct master_service_settings),
 
-       .parent_offset = (size_t)-1
+       .parent_offset = (size_t)-1,
+       .check_func = master_service_settings_check
 };
 
+/* <settings checks> */
+static bool
+master_service_settings_check(void *_set, pool_t pool ATTR_UNUSED,
+                             const char **error_r ATTR_UNUSED)
+{
+       struct master_service_settings *set = _set;
+
+       if (*set->log_path == '\0') {
+               /* default to syslog logging */
+               set->log_path = "syslog";
+       }
+       return TRUE;
+}
+/* </settings checks> */
+
 static void ATTR_NORETURN
 master_service_exec_config(struct master_service *service,
                           const struct master_service_settings_input *input)
index d23580a53f551368059412199a8e52358f263eb7..e5f8bfc4996f164e2c19f44d0f97e664346572bc 100644 (file)
@@ -214,8 +214,16 @@ void master_service_init_log(struct master_service *service,
                return;
        }
 
-       if (*service->set->log_path == '\0') {
-               /* log to syslog */
+       if (strcmp(service->set->log_path, "syslog") != 0) {
+               /* error logging goes to file or stderr */
+               path = home_expand(service->set->log_path);
+               i_set_failure_file(path, prefix);
+       }
+
+       if (strcmp(service->set->log_path, "syslog") == 0 ||
+           strcmp(service->set->info_log_path, "syslog") == 0 ||
+           strcmp(service->set->debug_log_path, "syslog") == 0) {
+               /* something gets logged to syslog */
                int facility;
 
                if (!syslog_facility_find(service->set->syslog_facility,
@@ -223,19 +231,27 @@ void master_service_init_log(struct master_service *service,
                        facility = LOG_MAIL;
                i_set_failure_syslog("dovecot", LOG_NDELAY, facility);
                i_set_failure_prefix(prefix);
-       } else {
-               /* log to file or stderr */
-               path = home_expand(service->set->log_path);
-               i_set_failure_file(path, prefix);
+
+               if (strcmp(service->set->log_path, "syslog") != 0) {
+                       /* set error handlers back to file */
+                       i_set_fatal_handler(NULL);
+                       i_set_error_handler(NULL);
+               }
        }
 
-       path = home_expand(service->set->info_log_path);
-       if (*path != '\0')
-               i_set_info_file(path);
+       if (*service->set->info_log_path != '\0' &&
+           strcmp(service->set->info_log_path, "syslog") != 0) {
+               path = home_expand(service->set->info_log_path);
+               if (*path != '\0')
+                       i_set_info_file(path);
+       }
 
-       path = home_expand(service->set->debug_log_path);
-       if (*path != '\0')
-               i_set_debug_file(path);
+       if (*service->set->debug_log_path != '\0' &&
+           strcmp(service->set->debug_log_path, "syslog") != 0) {
+               path = home_expand(service->set->debug_log_path);
+               if (*path != '\0')
+                       i_set_debug_file(path);
+       }
        i_set_failure_timestamp_format(service->set->log_timestamp);
 }