check_logfiles: 3.7.5.1
[omd.git] / packages / rrdtool / patches / 0001-rrd_daemon_log_into_file.diff
blob3e9f53bf2fcd941f4134d7296d63e84e2097210b
1 --- a/src/rrd_daemon.c 2015-08-09 17:18:19.000000000 +0200
2 +++ b/src/rrd_daemon.c 2015-08-26 14:18:08.010681423 +0200
3 @@ -103,6 +103,7 @@
4 #include <libgen.h>
5 #include <grp.h>
6 #include <pwd.h>
7 +#include <wordexp.h>
9 #ifdef HAVE_LIBWRAP
10 #include <tcpd.h>
11 @@ -112,14 +113,46 @@
12 #include <glib.h>
13 /* }}} */
15 +#define LOGFILE_PATH "~/var/log/rrdcached.log"
16 +#define DATE_FORMAT "%Y-%m-%d %H:%M:%S "
17 +char g_logfile_path[512]; // Contains expanded path
18 +char g_date[32];
20 +void log_to_file(char* format, ...);
21 +void set_logfile_path(void);
23 #define RRDD_LOG(severity, ...) \
24 do { \
25 if (stay_foreground) { \
26 fprintf(stderr, __VA_ARGS__); \
27 fprintf(stderr, "\n"); } \
28 - syslog ((severity), __VA_ARGS__); \
29 + log_to_file(__VA_ARGS__); \
30 } while (0)
32 +void log_to_file(char* format, ...)
34 + va_list ap;
35 + va_start(ap, format);
37 + time_t now = time(NULL);
38 + FILE *logfile_fd = fopen(g_logfile_path, "a+");
39 + strftime(g_date, sizeof(g_date), DATE_FORMAT, gmtime(&now));
40 + fprintf(logfile_fd, g_date, NULL);
41 + vfprintf(logfile_fd, format, ap);
42 + va_end(ap);
44 + fprintf(logfile_fd, "\n");
45 + fflush(logfile_fd);
46 + fclose(logfile_fd);
49 +void set_logfile_path(void)
51 + wordexp_t exp_result;
52 + wordexp(LOGFILE_PATH, &exp_result, 0);
53 + strncpy(g_logfile_path, exp_result.we_wordv[0], sizeof(g_logfile_path));
56 #if defined(__FreeBSD__) || defined(__APPLE__)
57 #define RRD_LISTEN_BACKLOG -1
58 #else
59 @@ -4337,6 +4370,9 @@
61 int status;
63 + // Determine logfile path within user directory
64 + set_logfile_path();
66 status = read_options (argc, argv);
67 if (status != 0)