#include <linux/un.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <regex.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <syslog.h>
#include <errno.h>
#include <ctype.h>
#include <libubox/uloop.h>
#include <libubox/usock.h>
#include <libubox/ustream.h>
#include <libubox/utils.h>
Go to the source code of this file.
|
static struct log_head * | log_next (struct log_head *h, int size) |
|
static uint64_t | get_kernel_ts (const char *ts_sec, const char *ts_nsec) |
|
static void | log_add_udebug (int priority, char *buf, int size, int source) |
|
void | log_add (char *buf, int size, int source) |
|
static void | syslog_handle_fd (struct uloop_fd *fd, unsigned int events) |
|
static void | klog_cb (struct ustream *s, int bytes) |
|
static int | klog_open (void) |
|
static int | syslog_open (void) |
|
struct log_head * | log_list (int count, struct log_head *h) |
|
int | log_buffer_init (int size) |
|
void | log_udebug_config (struct udebug_ubus *ctx, struct blob_attr *data, bool enabled) |
|
void | log_init (int _log_size) |
|
◆ KLOG_DEFAULT_PROC
#define KLOG_DEFAULT_PROC "/proc/kmsg" |
◆ LOG_DEFAULT_SIZE
#define LOG_DEFAULT_SIZE (16 * 1024) |
◆ LOG_DEFAULT_SOCKET
#define LOG_DEFAULT_SOCKET "/dev/log" |
◆ PAD
#define PAD |
( |
|
x | ) |
(x % 4) ? (((x) - (x % 4)) + 4) : (x) |
◆ SYSLOG_PADDING
#define SYSLOG_PADDING 16 |
◆ get_kernel_ts()
static uint64_t get_kernel_ts |
( |
const char * |
ts_sec, |
|
|
const char * |
ts_nsec |
|
) |
| |
|
static |
Definition at line 96 of file syslog.c.
98 uint64_t ts = strtoull(ts_sec, NULL, 10) * UDEBUG_TS_SEC +
99 strtoull(ts_nsec, NULL, 10) / 1000;
100 struct timespec wall, mono;
102 if (clock_gettime(CLOCK_REALTIME, &wall) ||
103 clock_gettime(CLOCK_MONOTONIC, &mono))
106 ts += (wall.tv_sec - mono.tv_sec) * UDEBUG_TS_SEC;
107 ts += (wall.tv_nsec - mono.tv_nsec) / 1000;
◆ klog_cb()
static void klog_cb |
( |
struct ustream * |
s, |
|
|
int |
bytes |
|
) |
| |
|
static |
Definition at line 245 of file syslog.c.
247 struct ustream_buf *buf = s->r.head;
252 str = ustream_get_read_buf(s, NULL);
255 newline = strchr(buf->data,
'\n');
259 len = newline + 1 - str;
261 ustream_consume(s, len);
void log_add(char *buf, int size, int source)
◆ klog_open()
static int klog_open |
( |
void |
| ) |
|
|
static |
Definition at line 275 of file syslog.c.
284 fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
285 ustream_fd_init(&
klog, fd);
static struct ustream_fd klog
#define KLOG_DEFAULT_PROC
◆ log_add()
void log_add |
( |
char * |
buf, |
|
|
int |
size, |
|
|
int |
source |
|
) |
| |
Definition at line 147 of file syslog.c.
149 regmatch_t matches[3];
157 fprintf(stderr,
"%s", buf);
161 for (c = buf; *c; c++) {
167 while (isspace(*c)) {
175 ret = regexec(&
pat_prio, buf, 3, matches, 0);
177 priority = atoi(&buf[matches[1].rm_so]);
178 size -= matches[2].rm_so;
179 buf += matches[2].rm_so;
191 if ((
priority & LOG_FACMASK) == LOG_LOCAL7)
213 clock_gettime(CLOCK_REALTIME, &
newest->
ts);
void ubus_notify_log(struct log_head *l)
static struct log_head * oldest
static struct log_head * log
static struct log_head * log_next(struct log_head *h, int size)
static void log_add_udebug(int priority, char *buf, int size, int source)
static struct log_head * newest
◆ log_add_udebug()
static void log_add_udebug |
( |
int |
priority, |
|
|
char * |
buf, |
|
|
int |
size, |
|
|
int |
source |
|
) |
| |
|
static |
Definition at line 113 of file syslog.c.
115 regmatch_t matches[4];
116 struct udebug_buf *udb;
121 else if ((priority & LOG_FACMASK) == LOG_LOCAL7)
126 if (!udebug_buf_valid(udb))
131 ts =
get_kernel_ts(&buf[matches[1].rm_so], &buf[matches[2].rm_so]);
132 buf += matches[3].rm_so;
133 size -= matches[3].rm_so;
137 ts = udebug_timestamp();
139 udebug_entry_init_ts(udb, ts);
140 udebug_entry_printf(udb,
"<%d>", priority);
141 udebug_entry_append(udb, buf, size - 1);
142 udebug_entry_add(udb);
static struct udebug_buf udb_kernel udb_user udb_debug
static uint64_t get_kernel_ts(const char *ts_sec, const char *ts_nsec)
static regex_t pat_tstamp
◆ log_buffer_init()
int log_buffer_init |
( |
int |
size | ) |
|
Definition at line 328 of file syslog.c.
333 fprintf(stderr,
"Failed to initialize log buffer with size %d\n",
log_size);
343 while ((start < end) && l && l->
size) {
struct log_head * log_list(int count, struct log_head *h)
static struct log_head * log_end
◆ log_init()
void log_init |
( |
int |
_log_size | ) |
|
◆ log_list()
Definition at line 305 of file syslog.c.
307 unsigned int min = count;
◆ log_next()
◆ log_udebug_config()
void log_udebug_config |
( |
struct udebug_ubus * |
ctx, |
|
|
struct blob_attr * |
data, |
|
|
bool |
enabled |
|
) |
| |
Definition at line 362 of file syslog.c.
365 udebug_ubus_apply_config(&
ud,
rings, ARRAY_SIZE(
rings), data, enabled);
static struct udebug_ubus_ring rings[]
◆ syslog_handle_fd()
static void syslog_handle_fd |
( |
struct uloop_fd * |
fd, |
|
|
unsigned int |
events |
|
) |
| |
|
static |
◆ syslog_open()
static int syslog_open |
( |
void |
| ) |
|
|
static |
Definition at line 290 of file syslog.c.
293 syslog_fd.fd = usock(USOCK_UNIX | USOCK_UDP | USOCK_SERVER | USOCK_NONBLOCK,
log_dev, NULL);
295 fprintf(stderr,
"Failed to open %s\n",
log_dev);
299 uloop_fd_add(&
syslog_fd, ULOOP_READ | ULOOP_EDGE_TRIGGER);
static struct uloop_fd syslog_fd
◆ current_id
◆ klog
Initial value:= {
.stream.string_data = true,
}
static void klog_cb(struct ustream *s, int bytes)
Definition at line 245 of file syslog.c.
◆ log
◆ log_dev
char* log_dev = "/dev/log" |
|
static |
◆ log_end
◆ log_size
int log_size = (16 * 1024) |
|
static |
◆ meta_debug
const struct udebug_buf_meta meta_debug |
|
static |
Initial value:= {
.name = "debug",
.format = UDEBUG_FORMAT_STRING,
}
Definition at line 51 of file syslog.c.
◆ meta_kernel
const struct udebug_buf_meta meta_kernel |
|
static |
Initial value:= {
.name = "kernel",
.format = UDEBUG_FORMAT_STRING,
}
Definition at line 51 of file syslog.c.
◆ meta_user
const struct udebug_buf_meta meta_user |
|
static |
Initial value:= {
.name = "syslog",
.format = UDEBUG_FORMAT_STRING,
}
Definition at line 51 of file syslog.c.
◆ newest
◆ oldest
◆ pat_prio
◆ pat_tstamp
◆ rings
struct udebug_ubus_ring rings[] |
|
static |
Initial value:= {
{
.buf = &udb_kernel,
.default_entries = 1024,
.default_size = 65536,
},
{
.buf = &udb_user,
.default_entries = 1024,
.default_size = 65536,
},
{
.default_entries = 1024,
.default_size = 65536,
},
}
static const struct udebug_buf_meta meta_debug
static const struct udebug_buf_meta meta_kernel
static const struct udebug_buf_meta meta_user
Definition at line 51 of file syslog.c.
◆ syslog_fd
struct uloop_fd syslog_fd |
|
static |
Initial value:= {
}
static void syslog_handle_fd(struct uloop_fd *fd, unsigned int events)
Definition at line 245 of file syslog.c.
◆ ud
◆ udb_debug
struct udebug_buf udb_kernel udb_user udb_debug |
|
static |