Skip to content

Commit

Permalink
broker: avoid truncation of log messages during shutdown
Browse files Browse the repository at this point in the history
Problem: In the broker shutdown code, log messages may be
truncated because the log forwarding code uses a static buffer of
FLUX_MAX_LOGBUF.

Since a maximum size of the final log message is known, use a
variable length array for the buffer in forward_logbuf() instead
of FLUX_MAX_LOGBUF to avoid any truncation.
  • Loading branch information
grondo committed Jan 14, 2025
1 parent 684d91b commit 8bcc918
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/broker/shutdown.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <flux/core.h>

#include "src/common/libutil/stdlog.h"
#include "src/common/libutil/errno_safe.h"

#include "shutdown.h"
#include "state_machine.h"
Expand Down Expand Up @@ -66,30 +67,27 @@ static int forward_logbuf (flux_t *h,
struct stdlog_header hdr;
const char *txt;
size_t txtlen;
char buf[FLUX_MAX_LOGBUF];
int len = strlen (stdlog);
char *buf;
int loglevel;
int rc;

if (flux_msg_unpack (request, "{s:i}", "loglevel", &loglevel) < 0)
loglevel = LOG_ERR;

if (stdlog_decode (stdlog,
strlen (stdlog),
&hdr,
NULL,
NULL,
&txt,
&txtlen) < 0
if (stdlog_decode (stdlog, len, &hdr, NULL, NULL, &txt, &txtlen) < 0
|| STDLOG_SEVERITY (hdr.pri) > loglevel
|| snprintf (buf,
sizeof (buf),
|| asprintf (&buf,
"%s.%s[%lu]: %.*s\n",
hdr.appname,
stdlog_severity_to_string (STDLOG_SEVERITY (hdr.pri)),
strtoul (hdr.hostname, NULL, 10),
(int)txtlen,
txt) >= sizeof (buf))
txt) < 0)
return 0;
return flux_respond_pack (h, request, "{s:s}", "log", buf);
rc = flux_respond_pack (h, request, "{s:s}", "log", buf);
ERRNO_SAFE_WRAP (free, buf);
return rc;
}

static void dmesg_continuation (flux_future_t *f, void *arg)
Expand Down

0 comments on commit 8bcc918

Please sign in to comment.