3 #include "log_storage.h"
16 #include <linux/limits.h>
17 #include <sys/epoll.h>
18 #include <sys/socket.h>
20 #include <sys/resource.h>
22 #include <sys/types.h>
26 #include <logconfig.h>
27 #include <ptrs_list.h>
28 #include <sd-daemon.h>
29 #include <backend_androidlogger.h>
30 #include <queued_entry_timestamp.h>
31 #include <dlogutil-internal.h>
33 #include "fd_entity.h"
34 #include "reader_common.h"
35 #include "reader_logger.h"
36 #include "reader_pipe.h"
38 #include "dlogutil_line.h"
39 #include "log_buffer.h"
46 /* supported main() return codes */
48 DLOG_EXIT_SUCCESS = 0,
53 /* Size in bytes of the pipe given to libdlog clients.
54 * The default size (1 page, usually 4 kiB) is fairly small
55 * which leads programs that log a lot to easily clog the
56 * pipe. On the other hand, the amount of memory allocated
57 * to pipes specifically can be limited and on most relevant
58 * targets seems to be set to 16ki pages (64 MiB raw memory)
59 * so pipes should not be too large so as not to waste it. */
60 #define PIPE_REQUESTED_SIZE (64 * 1024) // 16 pages at 4 kiB per page
62 /* Dumping readers should ideally get a larger pipe than clients
63 * so that it doesn't get easily clogged by the odd spammer.
64 * We can afford more generosity here because these are invoked
65 * quite rarely yet require handling priority, either because
66 * they are called by a developer manually or because a crashing
67 * program caused a system state dump. */
68 #define DUMPING_READER_PIPE_SIZE (4 * PIPE_REQUESTED_SIZE)
70 #define FILE_PATH_SIZE (256)
71 #define MAX_CONNECTION_Q 100
73 #define CONF_PREFIX "dlog_logger_conf_"
76 BUF_PARAM_TIME_MIN = 0,
77 BUF_PARAM_TIME_MAX = 3600,
78 BUF_PARAM_TIME_DEFAULT = 1,
82 BUF_PARAM_BYTES_MIN = 0,
83 BUF_PARAM_BYTES_MAX = 65536,
84 BUF_PARAM_BYTES_DEFAULT = 100
88 LOGGER_DEVICE_THROTTLING_DEFAULT = 100,
91 extern struct backend_data {
92 bool use_logger_by_default;
93 char logger_devices[LOG_ID_MAX][MAX_CONF_VAL_LEN];
94 int logger_device_throttling[LOG_ID_MAX];
95 struct reader_logger *logger_readers[LOG_ID_MAX];
99 /* Writers and readers can be a bit confusing in what they refer to.
100 * Something that does write() calls is usually actually a reader,
101 * and something that read()s is typically a writer. This is because
102 * the terminology is from the point of view of the primary log storage
103 * and not the daemon itself. Additionally, under the Android Logger
104 * the situation is even more complex because there's a hybrid structure
105 * that sits at both edges of the daemon at the same time and read()s,
106 * then immediately write()s data. Nevertheless it is classified as a
107 * reader because of its relationship with the primary log storage.
109 * Here's a picture for Pipe backend:
111 * ╔══════════════════════ daemon ════════════════════╗
112 * ┌─────────┐ ║ ┌────────┐ ┌─────────────────┐ ┌────────┐ ║ ┌─────────────────┐
113 * │ libdlog ├─╫─>│ struct ├───>│ primary storage ├───>│ struct ├─╫─>│ /var/log/dlog/x │
114 * │ client │ ║ │ writer │ │ char buffer[N]; │ │ reader │ ║ │ or dlogutil │
115 * └─────────┘ ║ └────────┘ └─────────────────┘ └────────┘ ║ └─────────────────┘
116 * ╚══════════════════════════════════════════════════╝
118 * And here's one for the Android Logger backend:
121 * ┌─────────┐ ┌─────────────────┐ ║ ┌────────┐ ║ ┌─────────────────┐
122 * │ libdlog ├─────────────────>│ primary storage ├─╫─>│ struct ├─╫─>│ /var/log/dlog/x │
123 * │ client │ │ /dev/log_x │ ║ │ reader │ ║ │ │
124 * └─────────┘ └─────────────────┘ ║ └────────┘ ║ └─────────────────┘
130 struct epoll_metadata epoll_common;
131 struct epoll_metadata epoll_socket;
133 int lazy_polling_total;
134 int lazy_polling_sleep;
136 list_head readers_logger;
137 struct log_buffer* buffers[LOG_ID_MAX];
138 struct buf_params buf_params;
141 struct qos_module qos;
144 struct logger_config_data {
145 struct buf_params buf_params;
146 list_head logfile_configs;
147 int lazy_polling_total;
148 int lazy_polling_sleep;
150 int is_buffer_enabled[LOG_ID_MAX];
151 struct buffer_config_data buffers[LOG_ID_MAX];
152 char *dynamic_config_dir;
154 int qos_max_throughput;
155 int qos_limit_duration;
157 int qos_threshold_reapply;
158 char *first_time_file_path;
161 void remove_reader_fd_entities(struct logger *server, struct reader *reader);
162 void reader_deinit_common(struct reader *reader);
163 void check_if_fd_limit_reached(struct logger *server, int err);
164 int service_writer_kmsg(struct logger* server, struct writer* wr, struct epoll_event* event);
165 int service_writer_socket(struct logger* server, struct writer* wr, struct epoll_event* event);
166 int service_writer_syslog(struct logger* server, struct writer* wr, struct epoll_event* event);
167 void logger_add_writer(struct logger* l, struct writer* wr);
168 int create_fifo_fds(struct logger *server, int fifo_id, int *write_fd, int *read_fd, bool dump);
169 int add_reader_pipe(struct logger *server, struct reader_pipe *reader);