<div dir="ltr"><div><div>Hi<br><br>I've just tested the patch and it need some fixing,<br>see my comments/fixes inline.<br><br>I will not be able to tests other patches until ~1 week,<br>but you can test simply using netcat (nc -l 5140) and watching with tcpdump -i any port 5140 -vvvX<br></div><div><br>Your code is cleaner but it's 2 syscalls instead of 1 each time<br><br></div>Thanks for your work,<br></div>Etienne<br><div><div><div><div class="gmail_extra"><br><div class="gmail_quote">2015-03-30 6:48 GMT+02:00 John Crispin <span dir="ltr"><<a href="mailto:blogic@openwrt.org" target="_blank">blogic@openwrt.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Signed-off-by: John Crispin <<a href="mailto:blogic@openwrt.org">blogic@openwrt.org</a>><br>
---<br>
log/logread.c | 22 +++++++++++++++++++---<br>
1 file changed, 19 insertions(+), 3 deletions(-)<br>
<br>
diff --git a/log/logread.c b/log/logread.c<br>
index 06dda62..cb601be 100644<br>
--- a/log/logread.c<br>
+++ b/log/logread.c<br>
@@ -59,7 +59,7 @@ static struct uloop_timeout retry;<br>
static struct uloop_fd sender;<br>
static const char *log_file, *log_ip, *log_port, *log_prefix, *pid_file, *hostname;<br>
static int log_type = LOG_STDOUT;<br>
-static int log_size, log_udp, log_follow = 0;<br>
+static int log_size, log_udp, log_follow, log_newline;<br>
<br>
static const char* getcodetext(int value, CODE *codetable) {<br>
CODE *i;<br>
@@ -93,6 +93,18 @@ static void log_handle_fd(struct uloop_fd *u, unsigned int events)<br>
}<br>
}<br>
<br>
+static int send_tcp(int sock, char *buf)<br>
+{<br></blockquote><div><br></div><div>you are not using "sock"<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ int err = send(sender.fd, buf, strlen(buf), MSG_MORE);<br>
+ if (err)<br></blockquote><div>should be "if (err < 0)"<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ return err;<br>
+<br>
+ if (log_newline)<br>
+ return send(sender.fd, "\n", 1, 0);<br>
+<br>
+ return send(sender.fd, "\0", 1, 0);<br></blockquote><div><br></div><div>\n should be the default, many receiver do not support \0 i think<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+}<br>
+<br>
static int log_notify(struct blob_attr *msg)<br>
{<br>
struct blob_attr *tb[__LOG_MAX];<br>
@@ -152,7 +164,7 @@ static int log_notify(struct blob_attr *msg)<br>
if (log_udp)<br>
err = write(sender.fd, buf, strlen(buf));<br>
else<br>
- err = send(sender.fd, buf, strlen(buf), 0);<br>
+ err = send_tcp(sender.fd, buf);<br>
<br>
if (err < 0) {<br>
syslog(LOG_INFO, "failed to send log data to %s:%s via %s\n",<br>
@@ -190,6 +202,7 @@ static int usage(const char *prog)<br>
" -P <prefix> Prefix custom text to streamed messages\n"<br>
" -f Follow log messages\n"<br>
" -u Use UDP as the protocol\n"<br>
+ " -n Use newline when remote logging\n"<br></blockquote><div><br></div><div>-0 Use null byte instead of newline when remote logging ?<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
"\n", prog);<br>
return 1;<br>
}<br>
@@ -234,7 +247,7 @@ int main(int argc, char **argv)<br>
<br>
signal(SIGPIPE, SIG_IGN);<br>
<br>
- while ((ch = getopt(argc, argv, "ufcs:l:r:F:p:S:P:h:")) != -1) {<br>
+ while ((ch = getopt(argc, argv, "ufcs:l:r:F:p:S:P:h:n")) != -1) {<br>
switch (ch) {<br>
case 'u':<br>
log_udp = 1;<br>
@@ -270,6 +283,9 @@ int main(int argc, char **argv)<br>
case 'h':<br>
hostname = optarg;<br>
break;<br>
+ case 'n':<br>
+ log_newline = 1;<br>
+ break;<br>
default:<br>
return usage(*argv);<br>
}<br>
<span class=""><font color="#888888">--<br>
1.7.10.4<br>
<br>
</font></span></blockquote></div><br></div></div></div></div></div>