-
Notifications
You must be signed in to change notification settings - Fork 1.8k
lib: Recreate the event loop after daemonizing on BSD platforms. #11171
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
Open
yuichiro-naito
wants to merge
7
commits into
fluent:master
Choose a base branch
from
yuichiro-naito:fix/stop_daemon
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
03625d7
lib: Re-create the event loop after daemonizing on BSD platforms.
21f3c59
event_loop: Introduce 'flb_event_loop.c'.
yuichiro-naito 5ce38c3
event_loop: add NULL check for config member in 'flb_ctx_t'.
yuichiro-naito 9581c8d
event_loop: refactor an error message.
yuichiro-naito 53a212c
event_loop: Clean up 'config->ch_evl' in an error case.
yuichiro-naito e375369
event_loop: Use 'mk_event_closesocket()' instead of 'close()'.
yuichiro-naito 1bb6d3b
event_loop: Leave file descriptor handling to the monkey library.
yuichiro-naito 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
Some comments aren't visible on the classic Files Changed page.
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
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 |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ set(src | |
| flb_api.c | ||
| flb_csv.c | ||
| flb_lib.c | ||
| flb_event_loop.c | ||
| flb_log.c | ||
| flb_env.c | ||
| flb_file.c | ||
|
|
||
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,102 @@ | ||
| /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | ||
|
|
||
| /* Fluent Bit | ||
| * ========== | ||
| * Copyright (C) 2015-2025 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. | ||
| */ | ||
|
|
||
| #include <fluent-bit/flb_lib.h> | ||
| #include <fluent-bit/flb_mem.h> | ||
|
|
||
| #include <unistd.h> | ||
|
|
||
| int flb_event_loop_create(flb_ctx_t *ctx) | ||
| { | ||
| int ret; | ||
| struct flb_config *config; | ||
|
|
||
| if (ctx == NULL || ctx->config == NULL) | ||
| return FLB_LIB_ERROR; | ||
|
|
||
| config = ctx->config; | ||
|
|
||
| /* Create the event loop to receive notifications */ | ||
| ctx->event_loop = mk_event_loop_create(256); | ||
| if (!ctx->event_loop) | ||
| return FLB_LIB_ERROR; | ||
|
|
||
| config->ch_evl = ctx->event_loop; | ||
|
|
||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /* Prepare the notification channels */ | ||
| ctx->event_channel = flb_calloc(1, sizeof(struct mk_event)); | ||
| if (!ctx->event_channel) { | ||
| perror("calloc"); | ||
| goto error_1; | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| MK_EVENT_ZERO(ctx->event_channel); | ||
|
|
||
| ret = mk_event_channel_create(config->ch_evl, | ||
| &config->ch_notif[0], | ||
| &config->ch_notif[1], | ||
| ctx->event_channel); | ||
| if (ret != 0) { | ||
| flb_error("[lib] could not create notification channels"); | ||
| goto error_2; | ||
| } | ||
|
|
||
| return 0; | ||
|
|
||
| error_2: | ||
| flb_free(ctx->event_channel); | ||
| ctx->event_channel = NULL; | ||
| error_1: | ||
| mk_event_loop_destroy(ctx->event_loop); | ||
| ctx->event_loop = NULL; | ||
| return FLB_LIB_ERROR; | ||
| } | ||
|
|
||
| int flb_event_loop_destroy(flb_ctx_t *ctx) | ||
| { | ||
| int ret; | ||
| struct flb_config *config; | ||
|
|
||
| if (ctx == NULL || ctx->config == NULL) | ||
| return 0; | ||
|
|
||
| config = ctx->config; | ||
| if (ctx->event_channel != NULL) { | ||
| ret = mk_event_channel_destroy(config->ch_evl, | ||
| config->ch_notif[0], | ||
| config->ch_notif[1], | ||
| ctx->event_channel); | ||
| if (ret != 0) { | ||
| /* make sure to close file descriptors */ | ||
| close(config->ch_notif[0]); | ||
| close(config->ch_notif[1]); | ||
cosmo0920 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| flb_free(ctx->event_channel); | ||
| ctx->event_channel = NULL; | ||
| } | ||
|
|
||
| if (ctx->event_loop != NULL) { | ||
| mk_event_loop_destroy(ctx->event_loop); | ||
| ctx->event_loop = NULL; | ||
| config->ch_evl = NULL; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
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
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.