[LEDE-DEV] [PATCH ubox] Fix logger starvation and Add feature log priority filtering

Hans Dedecker dedeckeh at gmail.com
Wed Jul 5 00:38:57 PDT 2017


On Tue, Jul 4, 2017 at 8:33 PM, Ron Brash <ron.brash at gmail.com> wrote:
> Hello all,
>
> We had an issue with a customer's recent deployment and needed to
> perform the following:
> * Add a syslog filtering functionality into the logger
> * Fix a condition where ubox's logd would continue running, but needed
> to be restarted after it stopped responding after several hours (or
> after a large number of logs were sent to it)
Hi,

Thank you for the patch but split the patch into two patches; one
patch adding syslog filtering functionality and the other patch fixing
the described error condition. Each patch must have a SoB which is
missing in this patch; see also
https://lede-project.org/submitting-patches for submitting patches

Hans
>
> The inline patch is following the signature.
>
> Ron Brash
> CTO  & Co-founder of Atlants Embedded Inc.
> www.atlantsembedded.com
> ------------------------------------------------------------------
>
> Cell +1 438 880 6441
> Email  ron.brash at gmail.com
> LinkedIn ca.linkedin.com/in/ronbrash/
>
>
>
> This communication is intended for the use of the recipient to which it is
> addressed, and may contain confidential, personal, and or privileged
> information. Please contact the sender immediately if you are not the
> intended recipient of this communication, and do not copy, distribute, or
> take action relying on it. Any communication received in error, or
> subsequent reply, should be deleted or destroyed.
>
>
> ------------------------------------------------------------------
>
>
> Fix for silent logging error:
> * There was a condition on a custom at91 board where the
> logreader/logd would starve
>
> Add functionality to add priority parsing into the log daemon
> * Previously had no way to do this with a customer's setup
> ---
>  log/logd.c    | 14 +++++++++++++-
>  log/logread.c | 27 +++++++++++++++++++++++----
>  2 files changed, 36 insertions(+), 5 deletions(-)
>
> diff --git a/log/logd.c b/log/logd.c
> index 07aee2b..a60cb8f 100644
> --- a/log/logd.c
> +++ b/log/logd.c
> @@ -27,6 +27,7 @@
>  #include "syslog.h"
>
>  int debug = 0;
> +int priority = 7;
>  static struct blob_buf b;
>  static struct ubus_auto_conn conn;
>  static LIST_HEAD(clients);
> @@ -182,6 +183,9 @@ ubus_notify_log(struct log_head *l)
>   if (list_empty(&clients))
>   return;
>
> + if((l->priority & 7) > priority) {
> + return; // skip if greater (logger level filtering)
> + }
>   blob_buf_init(&b, 0);
>   blobmsg_add_string(&b, "msg", l->data);
>   blobmsg_add_u32(&b, "id", l->id);
> @@ -214,13 +218,21 @@ main(int argc, char **argv)
>   int ch, log_size = 16;
>
>   signal(SIGPIPE, SIG_IGN);
> - while ((ch = getopt(argc, argv, "S:")) != -1) {
> + while ((ch = getopt(argc, argv, "P:S:")) != -1) {
>   switch (ch) {
>   case 'S':
>   log_size = atoi(optarg);
>   if (log_size < 1)
>   log_size = 16;
>   break;
> + case 'P':
> + priority = atoi(optarg);
> + if (priority < 0)
> + priority = 0;
> + else if(priority > 7) {
> + priority = 7; // bounds check
> + }
> + break;
>   }
>   }
>   log_size *= 1024;
> diff --git a/log/logread.c b/log/logread.c
> index edac1d9..2032819 100644
> --- a/log/logread.c
> +++ b/log/logread.c
> @@ -230,8 +230,10 @@ static void logread_fd_data_cb(struct ustream *s,
> int bytes)
>   break;
>
>   cur_len = blob_len(a) + sizeof(*a);
> - if (len < cur_len)
> + if (len < cur_len) {
> + ustream_consume(s, len);
>   break;
> + }
>
>   log_notify(a);
>   ustream_consume(s, cur_len);
> @@ -240,14 +242,28 @@ static void logread_fd_data_cb(struct ustream
> *s, int bytes)
>   uloop_end();
>  }
>
> +static void notify_fd_remove_cb();
> +
>  static void logread_fd_cb(struct ubus_request *req, int fd)
>  {
>   static struct ustream_fd test_fd;
> -
> + uloop_register_notify_fd_remove(fd, notify_fd_remove_cb);
>   test_fd.stream.notify_read = logread_fd_data_cb;
>   ustream_fd_init(&test_fd, fd);
>  }
>
> +struct ubus_context *context;
> +uint32_t ctx_id;
> +struct blob_buf * bb;
> +struct ubus_request request;
> +
> +static void notify_fd_remove_cb() {
> + ubus_lookup_id(context, "log", &ctx_id);
> + ubus_invoke_async(context, ctx_id, "read", bb->head, &request);
> + request.fd_cb = logread_fd_cb;
> + ubus_complete_request_async(context, &request);
> +}
> +
>  int main(int argc, char **argv)
>  {
>   static struct ubus_request req;
> @@ -361,11 +377,14 @@ int main(int argc, char **argv)
>   } else {
>   sender.fd = STDOUT_FILENO;
>   }
> -
> +
> + context = ctx;
> + bb = &b;
> +
>   ubus_invoke_async(ctx, id, "read", b.head, &req);
>   req.fd_cb = logread_fd_cb;
>   ubus_complete_request_async(ctx, &req);
> -
> +
>   uloop_run();
>   ubus_free(ctx);
>   uloop_done();
> --
>
> _______________________________________________
> Lede-dev mailing list
> Lede-dev at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/lede-dev



More information about the Lede-dev mailing list