-
Notifications
You must be signed in to change notification settings - Fork 1.9k
plugins: exec: exit fluent-bit after oneshot and propagate exit code #7207
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Feature tests for various platform and compiler capabilities, | ||
| # system headers, etc. | ||
|
|
||
| include(CheckIncludeFile) | ||
| CHECK_INCLUDE_FILE("sys/wait.h" FLB_HAVE_SYS_WAIT_H) | ||
| if (FLB_HAVE_SYS_WAIT_H) | ||
| FLB_DEFINITION(FLB_HAVE_SYS_WAIT_H) | ||
| endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | ||
|
|
||
| /* Fluent Bit | ||
| * ========== | ||
| * Copyright (C) 2015-2022 The Fluent Bit Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| #ifndef FLB_IN_EXEC_WIN32_COMPAT_H | ||
| #define FLB_IN_EXEC_WIN32_COMPAT_H | ||
|
|
||
| #include <stdio.h> | ||
| #include <fluent-bit/flb_info.h> | ||
|
|
||
| /* | ||
| * Work around lack of sys/wait.h and POSIX exit status macros from waitpid() | ||
| * in win32's _popen() and _pclose() implementation, since fluent-bit uses | ||
| * these in the in_exec plugin. | ||
| * | ||
| * On POSIX-like OSes this'll just use the standard macros with a name alias. | ||
| * | ||
| * On windows, where the concept of a signal exit does not exist, it defines | ||
| * dummy macros to indicate that the process exited normally and extract the | ||
| * exit code. | ||
| * | ||
| * These macros are for use with flb_pclose() only. Do not use them with | ||
| * other APIs that may differ in return value semantics. | ||
| */ | ||
| #ifdef FLB_HAVE_SYS_WAIT_H | ||
| #include <sys/wait.h> | ||
| #define FLB_WIFEXITED(status) WIFEXITED((status)) | ||
| #define FLB_WEXITSTATUS(status) WEXITSTATUS((status)) | ||
| #define FLB_WIFSIGNALED(status) WIFSIGNALED((status)) | ||
| #define FLB_WTERMSIG(status) WTERMSIG((status)) | ||
| #else | ||
| #define FLB_WIFEXITED(status) (1) | ||
| #define FLB_WEXITSTATUS(status) ((status) & 0x00ff) | ||
| #define FLB_WIFSIGNALED(status) (0) | ||
| #define FLB_WTERMSIG(status) (-1) | ||
| #endif | ||
|
|
||
| /* | ||
| * Because Windows has to do everything differently, call _popen() and | ||
| * _pclose() instead of the POSIX popen() and pclose() functions. | ||
| * | ||
| * flb_pclose() has different return value semantics on Windows vs non-windows | ||
| * targets because it propagates the pclose() or _pclose() return value | ||
| * directly. You MUST use the FLB_WIFEXITED(), FLB_WEXITSTATUS(), | ||
| * FLB_WIFSIGNALED() and FLB_WTERMSIG() macros to consume the return value, | ||
| * rather than the underlying POSIX macros or manual bit-shifts. | ||
| */ | ||
| #if !defined(FLB_SYSTEM_WINDOWS) | ||
| static inline FILE* flb_popen(const char *command, const char *type) { | ||
| return popen(command, type); | ||
| } | ||
| static inline int flb_pclose(FILE *stream) { | ||
| return pclose(stream); | ||
| } | ||
| #define FLB_PCLOSE pclose | ||
| #else | ||
| static inline FILE* flb_popen(const char *command, const char *type) { | ||
| return _popen(command, type); | ||
| } | ||
| /* | ||
| * flb_pclose() has the same return value on Windows as win32 _pclose(), rather | ||
| * than posix pclose(). The process exit code is not bit-shifted to the high | ||
| * byte. | ||
| * | ||
| * The MSVC docs for _pclose() at | ||
| * https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/pclose?view=msvc-170 | ||
| * are misleading; they say that "The format of the return value is the same as | ||
| * for _cwait, except the low-order and high-order bytes are swapped." But | ||
| * _cwait isn't documented as having any meaningful return on success, the | ||
| * process exit code is meant to be in its "termstat" out parameter per | ||
| * https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/cwait?view=msvc-170 | ||
| * The return code of _pclose() actually appears to be the process exit code | ||
| * without the bit-shift that waitpid() applies. | ||
| */ | ||
| static inline int flb_pclose(FILE *stream) { | ||
| return _pclose(stream); | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* FLB_IN_EXEC_WIN32_COMPAT_H */ | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.