Skip to content

Commit c66851c

Browse files
committed
pipe: add flb_pipe_error
On Windows, the `flb_pipe_r` and `flb_pipe_w` macros do not set errno on failure, meaning calling `flb_errno` in error scenarios is insufficient. This PR adds a new macro that will check the correct place, `WSAGetLastError`, and output a similar error message. On Linux this will still be `flb_errno`, meaning messages should work the same as they always did, but now on Windows we will get actual error messages. Signed-off-by: braydonk <[email protected]>
1 parent 8e8c9d6 commit c66851c

File tree

20 files changed

+72
-45
lines changed

20 files changed

+72
-45
lines changed

include/fluent-bit/flb_input.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ static FLB_INLINE void flb_input_return(struct flb_coro *coro) {
671671
val = FLB_BITS_U64_SET(FLB_ENGINE_IN_CORO, ins->id);
672672
n = flb_pipe_w(ins->ch_events[1], (void *) &val, sizeof(val));
673673
if (n == -1) {
674-
flb_errno();
674+
flb_pipe_error();
675675
}
676676

677677
flb_input_coro_prepare_destroy(input_coro);

include/fluent-bit/flb_log.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,18 @@ static inline int flb_log_suppress_check(int log_suppress_interval, const char *
232232
int flb_log_worker_init(struct flb_worker *worker);
233233
int flb_log_worker_destroy(struct flb_worker *worker);
234234
int flb_errno_print(int errnum, const char *file, int line);
235+
int flb_WSAGetLastError_print(int errnum, const char *file, int line);
235236

236237
#ifdef __FLB_FILENAME__
237238
#define flb_errno() flb_errno_print(errno, __FLB_FILENAME__, __LINE__)
239+
#ifdef WIN32
240+
#define flb_WSAGetLastError() flb_WSAGetLastError_print(WSAGetLastError(), __FLB_FILENAME__, __LINE__)
241+
#endif
238242
#else
239243
#define flb_errno() flb_errno_print(errno, __FILE__, __LINE__)
244+
#ifdef WIN32
245+
#define flb_WSAGetLastError() flb_WSAGetLastError_print(WSAGetLastError(), __FILE__, __LINE__)
246+
#endif
240247
#endif
241248

242249
#endif

include/fluent-bit/flb_output.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ static inline void flb_output_return(int ret, struct flb_coro *co) {
11991199
/* Notify the event loop about our return status */
12001200
n = flb_pipe_w(pipe_fd, (void *) &val, sizeof(val));
12011201
if (n == -1) {
1202-
flb_errno();
1202+
flb_pipe_error();
12031203
}
12041204

12051205
/*

include/fluent-bit/flb_pipe.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@
2828
#define flb_sockfd_t evutil_socket_t
2929
#define flb_pipe_w(fd, buf, len) send(fd, buf, len, 0)
3030
#define flb_pipe_r(fd, buf, len) recv(fd, buf, len, 0)
31+
#define flb_pipe_error() flb_WSAGetLastError()
3132
#define FLB_PIPE_WOULDBLOCK() (WSAGetLastError() == WSAEWOULDBLOCK)
3233
#else
3334
#define flb_pipefd_t int
3435
#define flb_sockfd_t int
3536
#define flb_pipe_w(fd, buf, len) write(fd, buf, len)
3637
#define flb_pipe_r(fd, buf, len) read(fd, buf, len)
38+
#define flb_pipe_error() flb_errno()
3739
#define FLB_PIPE_WOULDBLOCK() (errno == EAGAIN || errno == EWOULDBLOCK)
3840
#endif
3941

@@ -43,5 +45,6 @@ int flb_pipe_close(flb_pipefd_t fd);
4345
int flb_pipe_set_nonblocking(flb_pipefd_t fd);
4446
ssize_t flb_pipe_read_all(int fd, void *buf, size_t count);
4547
ssize_t flb_pipe_write_all(int fd, const void *buf, size_t count);
48+
void flb_pipe_log_last_error();
4649

4750
#endif

include/fluent-bit/flb_scheduler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ static FLB_INLINE void flb_sched_timer_cb_coro_return()
234234
val = FLB_BITS_U64_SET(FLB_SCHED_TIMER_CORO_RETURN, stc->id);
235235
n = flb_pipe_w(sched->ch_events[1], &val, sizeof(val));
236236
if (n == -1) {
237-
flb_errno();
237+
flb_pipe_error();
238238
}
239239

240240
flb_coro_yield(coro, FLB_TRUE);

plugins/in_exec/in_exec.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static int in_exec_collect(struct flb_input_instance *ins,
5454
if (ctx->oneshot == FLB_TRUE) {
5555
ret = flb_pipe_r(ctx->ch_manager[0], &val, sizeof(val));
5656
if (ret == -1) {
57-
flb_errno();
57+
flb_pipe_error();
5858
return -1;
5959
}
6060
}
@@ -256,7 +256,7 @@ static int in_exec_config_read(struct flb_exec *ctx,
256256
flb_plg_error(in, "unable to load configuration");
257257
return -1;
258258
}
259-
259+
260260
/* filepath setting */
261261
if (ctx->cmd == NULL) {
262262
flb_plg_error(in, "no input 'command' was given");
@@ -418,7 +418,7 @@ static int in_exec_prerun(struct flb_input_instance *ins,
418418
/* Kick the oneshot execution */
419419
ret = flb_pipe_w(ctx->ch_manager[1], &val, sizeof(val));
420420
if (ret == -1) {
421-
flb_errno();
421+
flb_pipe_error();
422422
return -1;
423423
}
424424
return 0;

plugins/in_exec_wasi/in_exec_wasi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static int in_exec_wasi_collect(struct flb_input_instance *ins,
6969
ret = flb_pipe_r(ctx->ch_manager[0], &val, sizeof(val));
7070
if (ret == -1) {
7171
fclose(stdoutp);
72-
flb_errno();
72+
flb_pipe_error();
7373
return -1;
7474
}
7575
}
@@ -404,7 +404,7 @@ static int in_exec_wasi_prerun(struct flb_input_instance *ins,
404404
/* Kick the oneshot execution */
405405
ret = flb_pipe_w(ctx->ch_manager[1], &val, sizeof(val));
406406
if (ret == -1) {
407-
flb_errno();
407+
flb_pipe_error();
408408
return -1;
409409
}
410410
return 0;

plugins/in_lib/in_lib.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ static int in_lib_collect(struct flb_input_instance *ins,
6969
flb_plg_trace(ctx->ins, "in_lib read() = %i", bytes);
7070
if (bytes == -1) {
7171
perror("read");
72+
flb_pipe_error();
7273
if (errno == -EPIPE) {
7374
return -1;
7475
}

plugins/in_tail/tail.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static inline int consume_byte(flb_pipefd_t fd)
5050
/* We need to consume the byte */
5151
ret = flb_pipe_r(fd, (char *) &val, sizeof(val));
5252
if (ret <= 0) {
53-
flb_errno();
53+
flb_pipe_error();
5454
return -1;
5555
}
5656

plugins/in_tail/tail_signal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static inline int tail_signal_manager(struct flb_tail_config *ctx)
4545
/* Insert a dummy event into the channel manager */
4646
n = flb_pipe_w(ctx->ch_manager[1], (const char *) &val, sizeof(val));
4747
if (n == -1) {
48-
flb_errno();
48+
flb_pipe_error();
4949
return -1;
5050
}
5151
else {
@@ -68,7 +68,7 @@ static inline int tail_signal_pending(struct flb_tail_config *ctx)
6868
* notification is already pending, it's safe to ignore.
6969
*/
7070
if (n == -1 && !FLB_PIPE_WOULDBLOCK()) {
71-
flb_errno();
71+
flb_pipe_error();
7272
return -1;
7373
}
7474

@@ -87,7 +87,7 @@ static inline int tail_consume_pending(struct flb_tail_config *ctx)
8787
do {
8888
ret = flb_pipe_r(ctx->ch_pending[0], (char *) &val, sizeof(val));
8989
if (ret <= 0 && !FLB_PIPE_WOULDBLOCK()) {
90-
flb_errno();
90+
flb_pipe_error();
9191
return -1;
9292
}
9393
} while (!FLB_PIPE_WOULDBLOCK());

0 commit comments

Comments
 (0)