Skip to content

Commit 73d2660

Browse files
committed
Fix messages to stdout/stderr getting truncated
The maximum zlog message length is 1024 including timestamp et cetera. With very long messages over 1024 characters, these get wrapped into multiple chunks correctly, but then the "WARNING: child blah said into blah" gets added and the zlog call truncates the messages using "..." at the end, resulting in a couple dozen bytes getting lost. This change calculates the length at which wrapping needs to occur correctly.
1 parent 4d8db15 commit 73d2660

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

sapi/fpm/fpm/fpm_stdio.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg)
119119
int is_last_message = 0;
120120
int in_buf = 0;
121121
int res;
122+
char fmt_buf[max_buf_size];
123+
int fmt_len = 0;
122124

123125
if (!arg) {
124126
return;
@@ -130,10 +132,15 @@ static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg)
130132
} else {
131133
event = &child->ev_stderr;
132134
}
135+
136+
/* calculate how long the "child 123 said into ..." prefix is so we can subtract its length from max_buf_size */
137+
fmt_len = snprintf(fmt_buf, max_buf_size, "[pool %s] child %d said into %s: \"%%s\"%%s", child->wp->config->name, (int) child->pid, is_stdout ? "stdout" : "stderr");
138+
/* subtract two characters each for the two "%s", then add character counts for "WARNING: " added by zlog and "[11-Feb-2015 15:58:20] " added by zlog; we're ignoring the potential extra length in log_level=DEBUG */
139+
fmt_len = fmt_len - 2 - 2 + 9 + 23;
133140

134141
while (fifo_in || fifo_out) {
135142
if (fifo_in) {
136-
res = read(fd, buf + in_buf, max_buf_size - 1 - in_buf);
143+
res = read(fd, buf + in_buf, max_buf_size - fmt_len - 1 - in_buf);
137144
if (res <= 0) { /* no data */
138145
fifo_in = 0;
139146
if (res < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
@@ -171,7 +178,7 @@ static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg)
171178
/* FIXME: there might be binary data */
172179

173180
/* we should print if no more space in the buffer */
174-
if (in_buf == max_buf_size - 1) {
181+
if (in_buf == max_buf_size - fmt_len - 1) {
175182
should_print = 1;
176183
}
177184

@@ -187,8 +194,7 @@ static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg)
187194
*nl = '\0';
188195
}
189196

190-
zlog(ZLOG_WARNING, "[pool %s] child %d said into %s: \"%s\"%s", child->wp->config->name,
191-
(int) child->pid, is_stdout ? "stdout" : "stderr", buf, is_last_message ? ", pipe is closed" : "");
197+
zlog(ZLOG_WARNING, fmt_buf, buf, is_last_message ? ", pipe is closed" : "");
192198

193199
if (nl) {
194200
int out_buf = 1 + nl - buf;

0 commit comments

Comments
 (0)