"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/doveadm/doveadm-log.c" between
dovecot-2.3.16.tar.gz and dovecot-2.3.17.tar.gz

About: Dovecot is an IMAP and POP3 server, written with security primarily in mind.

doveadm-log.c  (dovecot-2.3.16):doveadm-log.c  (dovecot-2.3.17)
skipping to change at line 27 skipping to change at line 27
#include <fcntl.h> #include <fcntl.h>
#include <dirent.h> #include <dirent.h>
#include <signal.h> #include <signal.h>
#include <sys/stat.h> #include <sys/stat.h>
#define LAST_LOG_TYPE LOG_TYPE_PANIC #define LAST_LOG_TYPE LOG_TYPE_PANIC
#define TEST_LOG_MSG_PREFIX "This is Dovecot's " #define TEST_LOG_MSG_PREFIX "This is Dovecot's "
#define LOG_ERRORS_FNAME "log-errors" #define LOG_ERRORS_FNAME "log-errors"
#define LOG_TIMESTAMP_FORMAT "%b %d %H:%M:%S" #define LOG_TIMESTAMP_FORMAT "%b %d %H:%M:%S"
extern struct doveadm_cmd doveadm_cmd_log[];
static void ATTR_NULL(2) static void ATTR_NULL(2)
cmd_log_test(int argc ATTR_UNUSED, char *argv[] ATTR_UNUSED) cmd_log_test(struct doveadm_cmd_context *cctx ATTR_UNUSED)
{ {
struct failure_context ctx; struct failure_context ctx;
unsigned int i; unsigned int i;
master_service->log_initialized = FALSE; master_service->log_initialized = FALSE;
master_service->flags |= MASTER_SERVICE_FLAG_DONT_LOG_TO_STDERR; master_service->flags |= MASTER_SERVICE_FLAG_DONT_LOG_TO_STDERR;
master_service_init_log(master_service); master_service_init_log(master_service);
i_zero(&ctx); i_zero(&ctx);
for (i = 0; i < LAST_LOG_TYPE; i++) { for (i = 0; i < LAST_LOG_TYPE; i++) {
skipping to change at line 52 skipping to change at line 50
/* add timestamp so that syslog won't just write /* add timestamp so that syslog won't just write
"repeated message" text */ "repeated message" text */
ctx.type = i; ctx.type = i;
i_log_type(&ctx, TEST_LOG_MSG_PREFIX"%s log (%u)", i_log_type(&ctx, TEST_LOG_MSG_PREFIX"%s log (%u)",
t_str_lcase(t_strcut(prefix, ':')), t_str_lcase(t_strcut(prefix, ':')),
(unsigned int)ioloop_time); (unsigned int)ioloop_time);
} }
} }
static void cmd_log_reopen(int argc ATTR_UNUSED, char *argv[] ATTR_UNUSED) static void cmd_log_reopen(struct doveadm_cmd_context *cctx ATTR_UNUSED)
{ {
doveadm_master_send_signal(SIGUSR1); doveadm_master_send_signal(SIGUSR1);
} }
struct log_find_file { struct log_find_file {
const char *path; const char *path;
uoff_t size; uoff_t size;
/* 1 << enum log_type */ /* 1 << enum log_type */
unsigned int mask; unsigned int mask;
skipping to change at line 195 skipping to change at line 193
if (stat(file->path, &st) < 0 || if (stat(file->path, &st) < 0 ||
(uoff_t)st.st_size <= file->size) (uoff_t)st.st_size <= file->size)
continue; continue;
cmd_log_find_syslog_file_messages(file); cmd_log_find_syslog_file_messages(file);
} }
hash_table_iterate_deinit(&iter); hash_table_iterate_deinit(&iter);
} }
static void static void
cmd_log_find_syslog(struct log_find_context *ctx, int argc, char *argv[]) cmd_log_find_syslog(struct log_find_context *ctx,
struct doveadm_cmd_context *cctx)
{ {
const char *log_dir; const char *log_dir;
struct stat st; struct stat st;
if (argc > 1) if (doveadm_cmd_param_str(cctx, "log-dir", &log_dir))
log_dir = argv[1]; ;
else if (stat("/var/log", &st) == 0 && S_ISDIR(st.st_mode)) else if (stat("/var/log", &st) == 0 && S_ISDIR(st.st_mode))
log_dir = "/var/log"; log_dir = "/var/log";
else if (stat("/var/adm", &st) == 0 && S_ISDIR(st.st_mode)) else if (stat("/var/adm", &st) == 0 && S_ISDIR(st.st_mode))
log_dir = "/var/adm"; log_dir = "/var/adm";
else else
return; return;
printf("Looking for log files from %s\n", log_dir); printf("Looking for log files from %s\n", log_dir);
cmd_log_find_syslog_files(ctx, log_dir); cmd_log_find_syslog_files(ctx, log_dir);
cmd_log_test(0, NULL); cmd_log_test(cctx);
/* give syslog some time to write the messages to files */ /* give syslog some time to write the messages to files */
sleep(1); sleep(1);
cmd_log_find_syslog_messages(ctx); cmd_log_find_syslog_messages(ctx);
} }
static void cmd_log_find(int argc, char *argv[]) static void cmd_log_find(struct doveadm_cmd_context *cctx)
{ {
const struct master_service_settings *set; const struct master_service_settings *set;
const char *log_file_path; const char *log_file_path;
struct log_find_context ctx; struct log_find_context ctx;
unsigned int i; unsigned int i;
i_zero(&ctx); i_zero(&ctx);
ctx.pool = pool_alloconly_create("log file", 1024*32); ctx.pool = pool_alloconly_create("log file", 1024*32);
hash_table_create(&ctx.files, ctx.pool, 0, str_hash, strcmp); hash_table_create(&ctx.files, ctx.pool, 0, str_hash, strcmp);
skipping to change at line 259 skipping to change at line 258
log_file_path = set->debug_log_path; log_file_path = set->debug_log_path;
if (*log_file_path != '\0') if (*log_file_path != '\0')
cmd_log_find_add(&ctx, log_file_path, LOG_TYPE_DEBUG); 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->log_path, "syslog") == 0 ||
strcmp(set->info_log_path, "syslog") == 0 || strcmp(set->info_log_path, "syslog") == 0 ||
strcmp(set->debug_log_path, "syslog") == 0) { strcmp(set->debug_log_path, "syslog") == 0) {
/* at least some logs were logged via syslog */ /* at least some logs were logged via syslog */
cmd_log_find_syslog(&ctx, argc, argv); cmd_log_find_syslog(&ctx, cctx);
} }
/* print them */ /* print them */
for (i = 0; i < LAST_LOG_TYPE; i++) { for (i = 0; i < LAST_LOG_TYPE; i++) {
struct hash_iterate_context *iter; struct hash_iterate_context *iter;
char *key; char *key;
struct log_find_file *file; struct log_find_file *file;
bool found = FALSE; bool found = FALSE;
iter = hash_table_iterate_init(ctx.files); iter = hash_table_iterate_init(ctx.files);
skipping to change at line 328 skipping to change at line 327
t = 0; t = 0;
} }
if (t >= min_timestamp) { if (t >= min_timestamp) {
doveadm_print(t_strflocaltime(LOG_TIMESTAMP_FORMAT, t)); doveadm_print(t_strflocaltime(LOG_TIMESTAMP_FORMAT, t));
doveadm_print(t_cmd_log_error_trim(args[2])); doveadm_print(t_cmd_log_error_trim(args[2]));
doveadm_print(t_cmd_log_error_trim(type_prefix)); doveadm_print(t_cmd_log_error_trim(type_prefix));
doveadm_print(args[3]); doveadm_print(args[3]);
} }
} }
static void cmd_log_errors(int argc, char *argv[]) static void cmd_log_errors(struct doveadm_cmd_context *cctx)
{ {
struct istream *input; struct istream *input;
const char *path, *line, *const *args; const char *path, *line, *const *args;
time_t min_timestamp = 0; time_t min_timestamp = 0;
int c, fd; int64_t since_int64;
int fd;
while ((c = getopt(argc, argv, "s:")) > 0) { if (doveadm_cmd_param_int64(cctx, "since", &since_int64))
switch (c) { min_timestamp = since_int64;
case 's':
if (str_to_time(optarg, &min_timestamp) < 0)
i_fatal("Invalid timestamp: %s", optarg);
break;
default:
help(&doveadm_cmd_log[3]);
}
}
argv += optind - 1;
if (argv[1] != NULL)
help(&doveadm_cmd_log[3]);
path = t_strconcat(doveadm_settings->base_dir, path = t_strconcat(doveadm_settings->base_dir,
"/"LOG_ERRORS_FNAME, NULL); "/"LOG_ERRORS_FNAME, NULL);
fd = net_connect_unix(path); fd = net_connect_unix(path);
if (fd == -1) if (fd == -1)
i_fatal("net_connect_unix(%s) failed: %m", path); i_fatal("net_connect_unix(%s) failed: %m", path);
net_set_nonblock(fd, FALSE); net_set_nonblock(fd, FALSE);
input = i_stream_create_fd_autoclose(&fd, SIZE_MAX); input = i_stream_create_fd_autoclose(&fd, SIZE_MAX);
skipping to change at line 378 skipping to change at line 367
if (str_array_length(args) == 4) if (str_array_length(args) == 4)
cmd_log_error_write(args, min_timestamp); cmd_log_error_write(args, min_timestamp);
else { else {
i_error("Invalid input from log: %s", line); i_error("Invalid input from log: %s", line);
doveadm_exit_code = EX_PROTOCOL; doveadm_exit_code = EX_PROTOCOL;
} }
} T_END; } T_END;
i_stream_destroy(&input); i_stream_destroy(&input);
} }
struct doveadm_cmd doveadm_cmd_log[] = { struct doveadm_cmd_ver2 doveadm_cmd_log[] = {
{ cmd_log_test, "log test", "" }, {
{ cmd_log_reopen, "log reopen", "" }, .name = "log test",
{ cmd_log_find, "log find", "[<dir>]" }, .cmd = cmd_log_test,
}; .usage = "",
DOVEADM_CMD_PARAMS_START
struct doveadm_cmd_ver2 doveadm_cmd_log_errors_ver2 = { DOVEADM_CMD_PARAMS_END
},
{
.name = "log reopen",
.cmd = cmd_log_reopen,
.usage = "",
DOVEADM_CMD_PARAMS_START
DOVEADM_CMD_PARAMS_END
},
{
.name = "log find",
.cmd = cmd_log_find,
.usage = "[<dir>]",
DOVEADM_CMD_PARAMS_START
DOVEADM_CMD_PARAM('\0', "log-dir", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
DOVEADM_CMD_PARAMS_END
},
{
.name = "log errors", .name = "log errors",
.usage = "[-s <min_timestamp>]", .usage = "[-s <min_timestamp>]",
.old_cmd = cmd_log_errors, .cmd = cmd_log_errors,
DOVEADM_CMD_PARAMS_START DOVEADM_CMD_PARAMS_START
DOVEADM_CMD_PARAM('s', "since", CMD_PARAM_STR, 0) DOVEADM_CMD_PARAM('s', "since", CMD_PARAM_INT64, 0)
DOVEADM_CMD_PARAMS_END DOVEADM_CMD_PARAMS_END
}
}; };
void doveadm_register_log_commands(void) void doveadm_register_log_commands(void)
{ {
unsigned int i; unsigned int i;
doveadm_cmd_register_ver2(&doveadm_cmd_log_errors_ver2);
for (i = 0; i < N_ELEMENTS(doveadm_cmd_log); i++) for (i = 0; i < N_ELEMENTS(doveadm_cmd_log); i++)
doveadm_register_cmd(&doveadm_cmd_log[i]); doveadm_cmd_register_ver2(&doveadm_cmd_log[i]);
} }
 End of changes. 17 change blocks. 
37 lines changed or deleted 42 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)