Skip to content

Commit 2bdc5e9

Browse files
authored
Merge pull request #5253 from grondo/issue#5250
support utf-8 in broker logs
2 parents 1f13a17 + 1d6c715 commit 2bdc5e9

File tree

4 files changed

+44
-8
lines changed

4 files changed

+44
-8
lines changed

src/broker/broker.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#endif
1414
#include <assert.h>
1515
#include <libgen.h>
16+
#include <locale.h>
1617
#include <inttypes.h>
1718
#include <sys/prctl.h>
1819
#include <sys/resource.h>
@@ -204,6 +205,8 @@ int main (int argc, char *argv[])
204205
const char *method;
205206
flux_error_t error;
206207

208+
setlocale (LC_ALL, "");
209+
207210
memset (&ctx, 0, sizeof (ctx));
208211
log_init (argv[0]);
209212

src/common/libutil/stdlog.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,6 @@ int stdlog_vencodef (char *buf, int len, struct stdlog_header *hdr,
180180
rc += n;
181181
if (n > len - m)
182182
n = len - m;
183-
for (i = 0; i < n; i++)
184-
buf[m + i] &= 0x7f; // ensure only ascii chars are logged
185183
for (i = n - 1; i >= 0; i--) {
186184
if (buf[m + i] != '\r' && buf[m + i] != '\n')
187185
break;

src/common/libutil/test/stdlog.c

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,28 +127,57 @@ int main(int argc, char** argv)
127127
"stdlog_decode decoded procid") ;
128128
ok (streq (hdr.msgid, cln.msgid),
129129
"stdlog_decode decoded msgid") ;
130-
ok (sdlen == strlen (STDLOG_NILVALUE) && strncmp (sd, STDLOG_NILVALUE, sdlen) == 0,
130+
ok (sdlen == strlen (STDLOG_NILVALUE)
131+
&& strncmp (sd, STDLOG_NILVALUE, sdlen) == 0,
131132
"stdlog_decode decoded structured data");
132-
ok (msglen == strlen (STDLOG_NILVALUE) && strncmp (msg, STDLOG_NILVALUE, msglen) == 0,
133+
ok (msglen == strlen (STDLOG_NILVALUE)
134+
&& strncmp (msg, STDLOG_NILVALUE, msglen) == 0,
133135
"stdlog_decode decoded message");
134136

135137
/* Check that trailing \n or \r in message are dropped
136138
*/
137139
stdlog_init (&hdr);
138-
len = stdlog_encode (buf, sizeof (buf), &hdr,
140+
len = stdlog_encode (buf,
141+
sizeof (buf),
142+
&hdr,
139143
STDLOG_NILVALUE,
140144
"Hello whorl\n\r\n");
141145
ok (len >= 0,
142146
"stdlog_encode worked with message");
143147
diag ("%.*s", len, buf);
144148
n = stdlog_decode (buf, len, &hdr, &sd, &sdlen, &msg, &msglen);
145-
ok (n == 0 && strncmp (msg, "Hello whorl", msglen) == 0,
149+
ok (n == 0
150+
&& strncmp (msg, "Hello whorl", msglen) == 0,
146151
"trailing cr/lf chars were truncated");
147152

153+
/* Check that valid UTF-8 non-ascii characters are preserved
154+
*/
155+
const char data[] = "jobid ƒ6LEmNENaf9 😄 😹";
156+
len = stdlog_encode (buf,
157+
sizeof (buf),
158+
&hdr,
159+
STDLOG_NILVALUE,
160+
data);
161+
ok (len >= 0,
162+
"stdlog_encode worked with %s", data);
163+
n = stdlog_decode (buf, len, &hdr, &sd, &sdlen, &msg, &msglen);
164+
ok (n == 0,
165+
"stdlog_decode worked");
166+
is (data, msg,
167+
"non-ascii characters were preserved");
168+
148169
int i = 0;
149170
while (valid[i] != NULL) {
150-
n = stdlog_decode (valid[i], strlen (valid[i]), &hdr, &sd, &sdlen, &msg, &msglen);
151-
ok (n == 0 && msglen == strlen ("message") && strncmp (msg, "message", msglen) == 0,
171+
n = stdlog_decode (valid[i],
172+
strlen (valid[i]),
173+
&hdr,
174+
&sd,
175+
&sdlen,
176+
&msg,
177+
&msglen);
178+
ok (n == 0
179+
&& msglen == strlen ("message")
180+
&& strncmp (msg, "message", msglen) == 0,
152181
"successfully decoded %s", valid[i]);
153182
i++;
154183
}

t/t0009-dmesg.t

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ test_expect_success 'logged non-ascii characters handled ok' '
108108
/bin/echo -n -e "\xFF\xFE\x82\x00" | flux logger &&
109109
flux dmesg
110110
'
111+
test_expect_success 'logged non-ascii printable characters are unmodified' '
112+
flux logger ƒ Φ Ψ Ω Ö &&
113+
flux dmesg | tail -1 > dmesg.utf-8 &&
114+
test_debug "cat dmesg.utf-8" &&
115+
grep "ƒ Φ Ψ Ω Ö" dmesg.utf-8
116+
'
111117
test_expect_success 'dmesg request with empty payload fails with EPROTO(71)' '
112118
${RPC} log.dmesg 71 </dev/null
113119
'

0 commit comments

Comments
 (0)