summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Crispin <blogic@openwrt.org>2013-07-09 11:49:55 +0200
committerJohn Crispin <blogic@openwrt.org>2013-07-09 14:50:28 +0200
commit8e1c60874f0ec195340b52953311e1521c3a063e (patch)
tree29263296e152138699039733150011be95bb26e1
parent5bf4764d977d35c2075fc183bd75ef5b28a03cb4 (diff)
downloadunitd-8e1c60874f0ec195340b52953311e1521c3a063e.tar
unitd-8e1c60874f0ec195340b52953311e1521c3a063e.zip
fix up the loging over network
Signed-off-by: John Crispin <blogic@openwrt.org>
-rw-r--r--logread.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/logread.c b/logread.c
index fc1d0ce..ba12f44 100644
--- a/logread.c
+++ b/logread.c
@@ -58,11 +58,11 @@ static struct uloop_timeout retry;
static struct uloop_fd sender;
static const char *log_file, *log_ip, *log_port, *pid_file;
static int log_type = LOG_STDOUT;
-static int log_size;
+static int log_size, log_udp;
static void log_handle_reconnect(struct uloop_timeout *timeout)
{
- sender.fd = usock(USOCK_TCP | USOCK_NUMERIC, log_ip, log_port);
+ sender.fd = usock((log_udp) ? (USOCK_UDP) : (USOCK_TCP), log_ip, log_port);
if (sender.fd < 0) {
fprintf(stderr, "failed to connect: %s\n", strerror(errno));
uloop_timeout_set(&retry, 1000);
@@ -128,14 +128,18 @@ static int log_notify(struct ubus_context *ctx, struct ubus_object *obj,
p = blobmsg_get_u32(tb[LOG_PRIO]);
c[strlen(c) - 1] = '\0';
str = blobmsg_format_json(msg, true);
- snprintf(buf, sizeof(buf), "%s %s.%s%s %s\n",
- c, facilitynames[LOG_FAC(p)].c_name, prioritynames[LOG_PRI(p)].c_name,
- (blobmsg_get_u32(tb[LOG_SOURCE])) ? ("") : (" kernel:"),
- method);
- if (log_type == LOG_NET)
+ if (log_type == LOG_NET) {
+ snprintf(buf, sizeof(buf), "%s%s\n",
+ (blobmsg_get_u32(tb[LOG_SOURCE])) ? ("") : ("kernel: "),
+ method);
send(sender.fd, buf, strlen(buf), 0);
- else
+ } else {
+ snprintf(buf, sizeof(buf), "%s %s.%s%s %s\n",
+ c, facilitynames[LOG_FAC(p)].c_name, prioritynames[LOG_PRI(p)].c_name,
+ (blobmsg_get_u32(tb[LOG_SOURCE])) ? ("") : (" kernel:"),
+ method);
write(sender.fd, buf, strlen(buf));
+ }
free(str);
if (log_type == LOG_FILE)
@@ -251,6 +255,7 @@ static int usage(const char *prog)
" -S <bytes> Log size\n"
" -p <file> PID file\n"
" -f Follow log messages\n"
+ " -u Use UDP as the protocol\n"
"\n", prog);
return 1;
}
@@ -263,8 +268,11 @@ int main(int argc, char **argv)
int ch, ret, subscribe = 0, lines = 0;
static struct blob_buf b;
- while ((ch = getopt(argc, argv, "fcs:l:r:F:p:S:")) != -1) {
+ while ((ch = getopt(argc, argv, "ufcs:l:r:F:p:S:")) != -1) {
switch (ch) {
+ case 'u':
+ log_udp = 1;
+ break;
case 's':
ubus_socket = optarg;
break;