asterisk: add logger patch
[feed/telephony.git] / net / asterisk / patches / 190-logger-workaround-woefully-small-BUFSIZ-in-MUSL.patch
1 From 140c19c2067a5e2dcedfbb4dfa08c57758b822cb Mon Sep 17 00:00:00 2001
2 From: Philip Prindeville <philipp@redfish-solutions.com>
3 Date: Mon, 21 Feb 2022 18:05:49 -0700
4 Subject: [PATCH] logger: workaround woefully small BUFSIZ in MUSL
5
6 MUSL defines BUFSIZ as 1024 which is not reasonable for log messages.
7
8 More broadly, BUFSIZ is the amount of buffering stdio.h does, which
9 is arbitrary and largely orthogonal to what logging should accept
10 as the maximum message size.
11
12 ASTERISK-29928
13
14 Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
15 Change-Id: Iaa49fbbab029c64ae3d95e4b18270e0442cce170
16 ---
17 main/logger.c | 15 ++++++++++-----
18 1 file changed, 10 insertions(+), 5 deletions(-)
19
20 --- a/main/logger.c
21 +++ b/main/logger.c
22 @@ -97,6 +97,11 @@ static int logger_queue_limit = 1000;
23 static int logger_messages_discarded;
24 static unsigned int high_water_alert;
25
26 +/* On some platforms, like those with MUSL as the runtime, BUFSIZ is
27 + * unreasonably small (1024). Use a larger value in those environments.
28 + */
29 +#define LOGMSG_SIZE MAX(BUFSIZ, 8192)
30 +
31 static enum rotatestrategy {
32 NONE = 0, /* Do not rotate log files at all, instead rely on external mechanisms */
33 SEQUENTIAL = 1 << 0, /* Original method - create a new file, in order */
34 @@ -1665,7 +1670,7 @@ static struct sigaction handle_SIGXFSZ =
35 static void logger_print_normal(struct logmsg *logmsg)
36 {
37 struct logchannel *chan = NULL;
38 - char buf[BUFSIZ];
39 + char buf[LOGMSG_SIZE];
40 int level = 0;
41
42 AST_RWLIST_RDLOCK(&logchannels);
43 @@ -1698,13 +1703,13 @@ static void logger_print_normal(struct l
44
45 /* Don't use LOG_MAKEPRI because it's broken in glibc<2.17 */
46 syslog_level = chan->facility | syslog_level; /* LOG_MAKEPRI(chan->facility, syslog_level); */
47 - if (!chan->formatter.format_log(chan, logmsg, buf, BUFSIZ)) {
48 + if (!chan->formatter.format_log(chan, logmsg, buf, sizeof(buf))) {
49 syslog(syslog_level, "%s", buf);
50 }
51 }
52 break;
53 case LOGTYPE_CONSOLE:
54 - if (!chan->formatter.format_log(chan, logmsg, buf, BUFSIZ)) {
55 + if (!chan->formatter.format_log(chan, logmsg, buf, sizeof(buf))) {
56 ast_console_puts_mutable_full(buf, logmsg->level, logmsg->sublevel);
57 }
58 break;
59 @@ -1716,7 +1721,7 @@ static void logger_print_normal(struct l
60 continue;
61 }
62
63 - if (chan->formatter.format_log(chan, logmsg, buf, BUFSIZ)) {
64 + if (chan->formatter.format_log(chan, logmsg, buf, sizeof(buf))) {
65 continue;
66 }
67
68 @@ -1780,7 +1785,7 @@ static struct logmsg * __attribute__((fo
69 }
70
71 /* Build string */
72 - res = ast_str_set_va(&buf, BUFSIZ, fmt, ap);
73 + res = ast_str_set_va(&buf, LOGMSG_SIZE, fmt, ap);
74
75 /* If the build failed, then abort and free this structure */
76 if (res == AST_DYNSTR_BUILD_FAILED) {