-
- uloop_run();
- ubus_free(ctx);
- uloop_done();
-}
-
-enum {
- READ_LINE,
- __READ_MAX
-};
-
-
-
-static const struct blobmsg_policy read_policy[] = {
- [READ_LINE] = { .name = "lines", .type = BLOBMSG_TYPE_ARRAY },
-};
-
-static void read_cb(struct ubus_request *req, int type, struct blob_attr *msg)
-{
- struct blob_attr *cur;
- struct blob_attr *_tb[__READ_MAX];
- time_t t;
- int rem;
-
- if (!msg)
- return;
-
- blobmsg_parse(read_policy, ARRAY_SIZE(read_policy), _tb, blob_data(msg), blob_len(msg));
- if (!_tb[READ_LINE])
- return;
- blobmsg_for_each_attr(cur, _tb[READ_LINE], rem) {
- struct blob_attr *tb[__LOG_MAX];
- uint32_t p;
- char *c;
-
- if (blobmsg_type(cur) != BLOBMSG_TYPE_TABLE)
- continue;
-
- blobmsg_parse(log_policy, ARRAY_SIZE(log_policy), tb, blobmsg_data(cur), blobmsg_data_len(cur));
- if (!tb[LOG_MSG] || !tb[LOG_ID] || !tb[LOG_PRIO] || !tb[LOG_SOURCE] || !tb[LOG_TIME])
- continue;
-
- t = blobmsg_get_u64(tb[LOG_TIME]);
- p = blobmsg_get_u32(tb[LOG_PRIO]);
- c = ctime(&t);
- c[strlen(c) - 1] = '\0';
-
- printf("%s %s.%s%s %s\n",
- c, getcodetext(LOG_FAC(p) << 3, facilitynames), getcodetext(LOG_PRI(p), prioritynames),
- (blobmsg_get_u32(tb[LOG_SOURCE])) ? ("") : (" kernel:"),
- blobmsg_get_string(tb[LOG_MSG]));
- }
-}
-
-static int usage(const char *prog)
-{
- fprintf(stderr, "Usage: %s [options]\n"
- "Options:\n"
- " -s <path> Path to ubus socket\n"
- " -l <count> Got only the last 'count' messages\n"
- " -r <server> <port> Stream message to a server\n"
- " -F <file> Log file\n"
- " -S <bytes> Log size\n"
- " -p <file> PID file\n"
- " -h <hostname> Add hostname to the message\n"
- " -P <prefix> Prefix custom text to streamed messages\n"
- " -f Follow log messages\n"
- " -u Use UDP as the protocol\n"
- "\n", prog);
- return 1;