[OpenWrt-Devel] [PATCH] ubox: make remote logging send \0 or \n on tcp connections as a trailer

Etienne Champetier champetier.etienne at gmail.com
Wed Apr 1 18:23:41 EDT 2015


Hi

I've just tested the patch and it need some fixing,
see my comments/fixes inline.

I will not be able to tests other patches until ~1 week,
but you can test simply using netcat (nc -l 5140) and watching with tcpdump
-i any port 5140 -vvvX

Your code is cleaner but it's 2 syscalls instead of 1 each time

Thanks for your work,
Etienne

2015-03-30 6:48 GMT+02:00 John Crispin <blogic at openwrt.org>:

> Signed-off-by: John Crispin <blogic at openwrt.org>
> ---
>  log/logread.c |   22 +++++++++++++++++++---
>  1 file changed, 19 insertions(+), 3 deletions(-)
>
> diff --git a/log/logread.c b/log/logread.c
> index 06dda62..cb601be 100644
> --- a/log/logread.c
> +++ b/log/logread.c
> @@ -59,7 +59,7 @@ static struct uloop_timeout retry;
>  static struct uloop_fd sender;
>  static const char *log_file, *log_ip, *log_port, *log_prefix, *pid_file,
> *hostname;
>  static int log_type = LOG_STDOUT;
> -static int log_size, log_udp, log_follow = 0;
> +static int log_size, log_udp, log_follow, log_newline;
>
>  static const char* getcodetext(int value, CODE *codetable) {
>         CODE *i;
> @@ -93,6 +93,18 @@ static void log_handle_fd(struct uloop_fd *u, unsigned
> int events)
>         }
>  }
>
> +static int send_tcp(int sock, char *buf)
> +{
>

you are not using "sock"


> +       int err = send(sender.fd, buf, strlen(buf), MSG_MORE);
> +       if (err)
>
should be "if (err < 0)"


> +               return err;
> +
> +       if (log_newline)
> +               return send(sender.fd, "\n", 1, 0);
> +
> +       return send(sender.fd, "\0", 1, 0);
>

\n should be the default, many receiver do not support \0 i think


> +}
> +
>  static int log_notify(struct blob_attr *msg)
>  {
>         struct blob_attr *tb[__LOG_MAX];
> @@ -152,7 +164,7 @@ static int log_notify(struct blob_attr *msg)
>                 if (log_udp)
>                         err = write(sender.fd, buf, strlen(buf));
>                 else
> -                       err = send(sender.fd, buf, strlen(buf), 0);
> +                       err = send_tcp(sender.fd, buf);
>
>                 if (err < 0) {
>                         syslog(LOG_INFO, "failed to send log data to %s:%s
> via %s\n",
> @@ -190,6 +202,7 @@ static int usage(const char *prog)
>                 "    -P <prefix>        Prefix custom text to streamed
> messages\n"
>                 "    -f                 Follow log messages\n"
>                 "    -u                 Use UDP as the protocol\n"
> +               "    -n                 Use newline when remote logging\n"
>

-0 Use null byte instead of newline when remote logging ?


>                 "\n", prog);
>         return 1;
>  }
> @@ -234,7 +247,7 @@ int main(int argc, char **argv)
>
>         signal(SIGPIPE, SIG_IGN);
>
> -       while ((ch = getopt(argc, argv, "ufcs:l:r:F:p:S:P:h:")) != -1) {
> +       while ((ch = getopt(argc, argv, "ufcs:l:r:F:p:S:P:h:n")) != -1) {
>                 switch (ch) {
>                 case 'u':
>                         log_udp = 1;
> @@ -270,6 +283,9 @@ int main(int argc, char **argv)
>                 case 'h':
>                         hostname = optarg;
>                         break;
> +               case 'n':
> +                       log_newline = 1;
> +                       break;
>                 default:
>                         return usage(*argv);
>                 }
> --
> 1.7.10.4
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/openwrt-devel/attachments/20150402/023d3bc6/attachment.htm>
-------------- next part --------------
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list