#include <sys/types.h>
#include <pwd.h>
#include <stdio.h>
#include <unistd.h>
#include <syslog.h>
#include <linux/types.h>
#include <libubox/uloop.h>
#include <libubox/blobmsg.h>
#include <libubox/list.h>
#include <libubox/ustream.h>
#include <libubox/utils.h>
#include <libubus.h>
Go to the source code of this file.
|
static | LIST_HEAD (clients) |
|
static void | client_close (struct ustream *s) |
|
static void | client_notify_state (struct ustream *s) |
|
static void | client_notify_write (struct ustream *s, int bytes) |
|
static void | log_fill_msg (struct blob_buf *b, struct log_head *l) |
|
static int | read_log (struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) |
|
static int | write_log (struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) |
|
void | ubus_notify_log (struct log_head *l) |
|
static void | ubus_connect_handler (struct ubus_context *ctx) |
|
int | main (int argc, char **argv) |
|
◆ anonymous enum
Enumerator |
---|
READ_LINES | |
READ_STREAM | |
READ_ONESHOT | |
__READ_MAX | |
Definition at line 38 of file logd.c.
◆ client_close()
static void client_close |
( |
struct ustream * |
s | ) |
|
|
static |
◆ client_notify_state()
static void client_notify_state |
( |
struct ustream * |
s | ) |
|
|
static |
Definition at line 72 of file logd.c.
static void client_close(struct ustream *s)
◆ client_notify_write()
static void client_notify_write |
( |
struct ustream * |
s, |
|
|
int |
bytes |
|
) |
| |
|
static |
Definition at line 77 of file logd.c.
79 if (ustream_pending_data(s,
true))
◆ LIST_HEAD()
static LIST_HEAD |
( |
clients |
| ) |
|
|
static |
◆ log_fill_msg()
static void log_fill_msg |
( |
struct blob_buf * |
b, |
|
|
struct log_head * |
l |
|
) |
| |
|
static |
Definition at line 86 of file logd.c.
88 blobmsg_add_string(
b,
"msg", l->
data);
89 blobmsg_add_u32(
b,
"id", l->
id);
90 blobmsg_add_u32(
b,
"priority", l->
priority);
91 blobmsg_add_u32(
b,
"source", l->
source);
92 blobmsg_add_u64(
b,
"time", (((__u64) l->
ts.tv_sec) * 1000) + (l->
ts.tv_nsec / 1000000));
◆ main()
int main |
( |
int |
argc, |
|
|
char ** |
argv |
|
) |
| |
Definition at line 245 of file logd.c.
248 struct passwd *p = NULL;
250 signal(SIGPIPE, SIG_IGN);
251 while ((ch = getopt(argc, argv,
"S:")) != -1) {
265 ubus_auto_connect(&
conn);
267 p = getpwnam(
"logd");
269 if (setgid(p->pw_gid) < 0) {
270 fprintf(stderr,
"setgid() failed: %s\n", strerror(errno));
274 if (setuid(p->pw_uid) < 0) {
275 fprintf(stderr,
"setuid() failed: %s\n", strerror(errno));
280 udebug_ubus_free(&
udebug);
283 ubus_auto_shutdown(&
conn);
static void ubus_connect_handler(struct ubus_context *ctx)
static struct udebug_ubus udebug
static struct ubus_auto_conn conn
void log_init(int _log_size)
void log_udebug_config(struct udebug_ubus *ctx, struct blob_attr *data, bool enabled)
◆ read_log()
static int read_log |
( |
struct ubus_context * |
ctx, |
|
|
struct ubus_object * |
obj, |
|
|
struct ubus_request_data * |
req, |
|
|
const char * |
method, |
|
|
struct blob_attr * |
msg |
|
) |
| |
|
static |
Definition at line 96 of file logd.c.
107 bool oneshot =
false;
125 if (pipe(fds) == -1) {
126 fprintf(stderr,
"logd: failed to create pipe: %m\n");
130 ubus_request_set_fd(
ctx, req, fds[0]);
131 cl = calloc(1,
sizeof(*cl));
134 ustream_fd_init(&cl->
s, cl->
fd);
135 list_add(&cl->
list, &clients);
137 blob_buf_init(&
b, 0);
140 ret = ustream_write(&cl->
s.stream, (
void *)
b.head, blob_len(
b.head) +
sizeof(
struct blob_attr),
false);
150 blob_buf_init(&
b, 0);
151 c = blobmsg_open_array(&
b,
"log");
153 e = blobmsg_open_table(&
b, NULL);
155 blobmsg_close_table(&
b, e);
158 blobmsg_close_array(&
b, c);
159 ubus_send_reply(
ctx, req,
b.head);
static void client_notify_state(struct ustream *s)
static void client_notify_write(struct ustream *s, int bytes)
static const struct blobmsg_policy read_policy[__READ_MAX]
static void log_fill_msg(struct blob_buf *b, struct log_head *l)
static struct ubus_context * ctx
struct log_head * log_list(int count, struct log_head *h)
◆ ubus_connect_handler()
static void ubus_connect_handler |
( |
struct ubus_context * |
ctx | ) |
|
|
static |
Definition at line 232 of file logd.c.
238 fprintf(stderr,
"Failed to add object: %s\n", ubus_strerror(ret));
241 fprintf(stderr,
"log: connected to ubus\n");
static struct ubus_object log_object
◆ ubus_notify_log()
void ubus_notify_log |
( |
struct log_head * |
l | ) |
|
Definition at line 208 of file logd.c.
212 if (list_empty(&clients) && !
log_object.has_subscribers)
215 blob_buf_init(&
b, 0);
216 blobmsg_add_string(&
b,
"msg", l->
data);
217 blobmsg_add_u32(&
b,
"id", l->
id);
218 blobmsg_add_u32(&
b,
"priority", l->
priority);
219 blobmsg_add_u32(&
b,
"source", l->
source);
220 blobmsg_add_u64(&
b,
"time", (((__u64) l->
ts.tv_sec) * 1000) + (l->
ts.tv_nsec / 1000000));
225 list_for_each_entry(c, &clients,
list)
226 ustream_write(&c->
s.stream, (
void *)
b.head, blob_len(
b.head) +
sizeof(
struct blob_attr),
false);
◆ write_log()
static int write_log |
( |
struct ubus_context * |
ctx, |
|
|
struct ubus_object * |
obj, |
|
|
struct ubus_request_data * |
req, |
|
|
const char * |
method, |
|
|
struct blob_attr * |
msg |
|
) |
| |
|
static |
Definition at line 166 of file logd.c.
170 struct blob_attr *tb;
176 blobmsg_parse(&
write_policy, 1, &tb, blob_data(msg), blob_len(msg));
178 event = blobmsg_get_string(tb);
179 len = strlen(event) + 1;
static const struct blobmsg_policy write_policy
void log_add(char *buf, int size, int source)
◆ conn
struct ubus_auto_conn conn |
|
static |
◆ debug
◆ log_methods
const struct ubus_method log_methods[] |
|
static |
Initial value:= {
}
static int write_log(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg)
static int read_log(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg)
Definition at line 166 of file logd.c.
◆ log_object
struct ubus_object log_object |
|
static |
Initial value:= {
.name = "log",
}
static struct ubus_object_type log_object_type
static const struct ubus_method log_methods[]
Definition at line 166 of file logd.c.
◆ log_object_type
struct ubus_object_type log_object_type |
|
static |
Initial value:
Definition at line 166 of file logd.c.
◆ read_policy
const struct blobmsg_policy read_policy[__READ_MAX] |
|
static |
Initial value:= {
[
READ_LINES] = { .name =
"lines", .type = BLOBMSG_TYPE_INT32 },
[
READ_STREAM] = { .name =
"stream", .type = BLOBMSG_TYPE_BOOL },
[
READ_ONESHOT] = { .name =
"oneshot", .type = BLOBMSG_TYPE_BOOL },
}
Definition at line 36 of file logd.c.
◆ udebug
struct udebug_ubus udebug |
|
static |
◆ write_policy
const struct blobmsg_policy write_policy |
|
static |
Initial value:=
{ .name = "event", .type = BLOBMSG_TYPE_STRING }
Definition at line 36 of file logd.c.