Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix a segmentation fault issue in logging worker #2295

Merged
merged 3 commits into from
Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/flb_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,16 @@ static inline int log_read(flb_pipefd_t fd, struct flb_log *log)
* under the PIPE_BUF limit (4KB on Linux) and our messages are always 1KB,
* we can trust we will always get a full message on each read(2).
*/
bytes = flb_pipe_r(fd, &msg, sizeof(struct log_message));
bytes = flb_pipe_read_all(fd, &msg, sizeof(struct log_message));
if (bytes <= 0) {
perror("bytes");
return -1;
}
if (msg.size > sizeof(msg.msg)) {
fprintf(stderr, "[log] message too long: %zi > %zi",
msg.size, sizeof(msg.msg));
return -1;
}
log_push(&msg, log);

return bytes;
Expand Down Expand Up @@ -410,7 +415,7 @@ void flb_log_print(int type, const char *file, int line, const char *fmt, ...)

w = flb_worker_get();
if (w) {
int n = flb_pipe_w(w->log[1], &msg, sizeof(msg));
int n = flb_pipe_write_all(w->log[1], &msg, sizeof(msg));
if (n == -1) {
perror("write");
}
Expand Down
2 changes: 2 additions & 0 deletions src/flb_pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ ssize_t flb_pipe_read_all(int fd, void *buf, size_t count)
flb_time_msleep(50);
continue;
}
return -1;
}
else if (bytes == 0) {
/* Broken pipe ? */
Expand Down Expand Up @@ -160,6 +161,7 @@ ssize_t flb_pipe_write_all(int fd, const void *buf, size_t count)
flb_time_msleep(50);
continue;
}
return -1;
}
else if (bytes == 0) {
/* Broken pipe ? */
Expand Down