<p>Philip Prindeville has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/18105">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">logger: workaround woefully small BUFSIZ in MUSL<br><br>MUSL defines BUFSIZ as 1024 which is not reasonable for log messages.<br><br>More broadly, BUFSIZ is the amount of buffering stdio.h does, which<br>is arbitrary and largely orthogonal to what logging should accept<br>as the maximum message size.<br><br>ASTERISK-29928<br><br>Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com><br>Change-Id: Iaa49fbbab029c64ae3d95e4b18270e0442cce170<br>---<br>M main/logger.c<br>1 file changed, 14 insertions(+), 5 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/05/18105/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/logger.c b/main/logger.c</span><br><span>index e9f8f96..ad30afa 100644</span><br><span>--- a/main/logger.c</span><br><span>+++ b/main/logger.c</span><br><span>@@ -97,6 +97,15 @@</span><br><span> static int logger_messages_discarded;</span><br><span> static unsigned int high_water_alert;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/* On some platforms, like those with MUSL as the runtime, BUFSIZ is</span><br><span style="color: hsl(120, 100%, 40%);">+ * unreasonably small (1024). Use a larger value in those environments.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+#if BUFSIZ >= 4096</span><br><span style="color: hsl(120, 100%, 40%);">+#define LOGMSG_SIZE                BUFSIZ</span><br><span style="color: hsl(120, 100%, 40%);">+#else</span><br><span style="color: hsl(120, 100%, 40%);">+#define LOGMSG_SIZE              8192</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static enum rotatestrategy {</span><br><span>       NONE = 0,                /* Do not rotate log files at all, instead rely on external mechanisms */</span><br><span>   SEQUENTIAL = 1 << 0,     /* Original method - create a new file, in order */</span><br><span>@@ -1665,7 +1674,7 @@</span><br><span> static void logger_print_normal(struct logmsg *logmsg)</span><br><span> {</span><br><span>    struct logchannel *chan = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- char buf[BUFSIZ];</span><br><span style="color: hsl(120, 100%, 40%);">+     char buf[LOGMSG_SIZE];</span><br><span>       int level = 0;</span><br><span> </span><br><span>   AST_RWLIST_RDLOCK(&logchannels);</span><br><span>@@ -1698,13 +1707,13 @@</span><br><span> </span><br><span>                                   /* Don't use LOG_MAKEPRI because it's broken in glibc<2.17 */</span><br><span>                                     syslog_level = chan->facility | syslog_level; /* LOG_MAKEPRI(chan->facility, syslog_level); */</span><br><span style="color: hsl(0, 100%, 40%);">-                                    if (!chan->formatter.format_log(chan, logmsg, buf, BUFSIZ)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                                      if (!chan->formatter.format_log(chan, logmsg, buf, sizeof(buf))) {</span><br><span>                                                syslog(syslog_level, "%s", buf);</span><br><span>                                   }</span><br><span>                            }</span><br><span>                            break;</span><br><span>                       case LOGTYPE_CONSOLE:</span><br><span style="color: hsl(0, 100%, 40%);">-                           if (!chan->formatter.format_log(chan, logmsg, buf, BUFSIZ)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                              if (!chan->formatter.format_log(chan, logmsg, buf, sizeof(buf))) {</span><br><span>                                        ast_console_puts_mutable_full(buf, logmsg->level, logmsg->sublevel);</span><br><span>                           }</span><br><span>                            break;</span><br><span>@@ -1716,7 +1725,7 @@</span><br><span>                                               continue;</span><br><span>                                    }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-                                   if (chan->formatter.format_log(chan, logmsg, buf, BUFSIZ)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                                       if (chan->formatter.format_log(chan, logmsg, buf, sizeof(buf))) {</span><br><span>                                                 continue;</span><br><span>                                    }</span><br><span> </span><br><span>@@ -1780,7 +1789,7 @@</span><br><span>        }</span><br><span> </span><br><span>        /* Build string */</span><br><span style="color: hsl(0, 100%, 40%);">-      res = ast_str_set_va(&buf, BUFSIZ, fmt, ap);</span><br><span style="color: hsl(120, 100%, 40%);">+      res = ast_str_set_va(&buf, LOGMSG_SIZE, fmt, ap);</span><br><span> </span><br><span>    /* If the build failed, then abort and free this structure */</span><br><span>        if (res == AST_DYNSTR_BUILD_FAILED) {</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/18105">change 18105</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/18105"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: Iaa49fbbab029c64ae3d95e4b18270e0442cce170 </div>
<div style="display:none"> Gerrit-Change-Number: 18105 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Philip Prindeville <philipp@redfish-solutions.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>