-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[Win32 Signals] Add term and ctrl-c signal handlers #13954
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
35 commits
Select commit
Hold shift + click to select a range
c9939d9
unix builds
ab8b2e2
fix format 1
2819000
format vol2
3774592
Win32 changes + tests
f55a385
add tests
f5ae7e0
fix format
c5f267f
fix pyformat
4159136
fix typo
709cbac
working through build errors
3158e46
fix with runfiles
2a16309
use the same if conditions everywhere
e9fde7f
fix format + deps
598b933
PR comments and robust testing
8cce5c9
format changes
44d4602
order includes
4d900be
fix include order vol 2
a191b0c
remove extra empty line
a201731
switch format to use absl duration
c484a75
fix linux CI
3d71e04
fix linux signal name typo
b050126
fix windows crash
c7186df
fix build deps
e6cc642
try fixing clang-tidy
a295a16
fix build break
e9bb5f2
fix build tools format
d92345b
Merge remote-tracking branch 'upstream/master' into processManagement
67aaa42
attempt to fix clang_tidy
6cc663b
fix typo
c378f5f
Change from map to array
7550099
Spelling
30bbdfa
fix pr comments by greg
a28a4f0
fix spelling mistake
85e19e3
Merge remote-tracking branch 'upstream/master' into processManagement
63e7ced
fix allocation + add panic
1f1e211
remove double signal entry
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
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
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
5 changes: 2 additions & 3 deletions
5
source/common/event/signal_impl.cc → source/common/event/posix/signal_impl.cc
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,44 @@ | ||
| #include "common/api/os_sys_calls_impl.h" | ||
| #include "common/event/dispatcher_impl.h" | ||
| #include "common/event/signal_impl.h" | ||
|
|
||
| #include "event2/event.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Event { | ||
|
|
||
| SignalEventImpl::SignalEventImpl(DispatcherImpl& dispatcher, signal_t signal_num, SignalCb cb) | ||
| : cb_(cb) { | ||
|
|
||
| if (signal_num > eventBridgeHandlersSingleton::get().size()) { | ||
| PANIC("Attempting to create SignalEventImpl with a signal id that exceeds the number of " | ||
| "supported signals."); | ||
| } | ||
|
|
||
| if (eventBridgeHandlersSingleton::get()[signal_num]) { | ||
| return; | ||
| } | ||
| os_fd_t socks[2]; | ||
| Api::SysCallIntResult result = | ||
| Api::OsSysCallsSingleton::get().socketpair(AF_INET, SOCK_STREAM, IPPROTO_TCP, socks); | ||
| ASSERT(result.rc_ == 0); | ||
|
|
||
| read_handle_ = std::make_unique<Network::IoSocketHandleImpl>(socks[0], false, AF_INET); | ||
| result = read_handle_->setBlocking(false); | ||
| ASSERT(result.rc_ == 0); | ||
| auto write_handle = std::make_shared<Network::IoSocketHandleImpl>(socks[1], false, AF_INET); | ||
| result = write_handle->setBlocking(false); | ||
| ASSERT(result.rc_ == 0); | ||
davinci26 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| read_handle_->initializeFileEvent( | ||
| dispatcher, | ||
| [this](uint32_t events) -> void { | ||
| ASSERT(events == Event::FileReadyType::Read); | ||
| cb_(); | ||
| }, | ||
| Event::FileTriggerType::Level, Event::FileReadyType::Read); | ||
| eventBridgeHandlersSingleton::get()[signal_num] = write_handle; | ||
| } | ||
|
|
||
| } // namespace Event | ||
| } // namespace Envoy | ||
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,35 @@ | ||
| #pragma once | ||
|
|
||
| #include "envoy/event/signal.h" | ||
| #include "envoy/network/io_handle.h" | ||
|
|
||
| #include "common/event/dispatcher_impl.h" | ||
| #include "common/event/event_impl_base.h" | ||
| #include "common/network/io_socket_handle_impl.h" | ||
| #include "common/singleton/threadsafe_singleton.h" | ||
|
|
||
| #include "absl/container/flat_hash_map.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Event { | ||
|
|
||
| /** | ||
| * libevent implementation of Event::SignalEvent. | ||
| */ | ||
| class SignalEventImpl : public SignalEvent { | ||
| public: | ||
| SignalEventImpl(DispatcherImpl& dispatcher, signal_t signal_num, SignalCb cb); | ||
|
|
||
| private: | ||
| SignalCb cb_; | ||
| Network::IoHandlePtr read_handle_; | ||
| }; | ||
|
|
||
| // Windows ConsoleControlHandler does not allow for a context. As a result the thread | ||
| // spawned to handle the console events communicates with the main program with this socketpair. | ||
| // Here we have a map from signal types to IoHandle. When we write to this handle we trigger an | ||
| // event that notifies Envoy to act on the signal. | ||
| using eventBridgeHandlersSingleton = | ||
| ThreadSafeSingleton<std::array<std::shared_ptr<Network::IoHandle>, ENVOY_WIN32_SIGNAL_COUNT>>; | ||
| } // namespace Event | ||
| } // namespace Envoy |
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
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
Oops, something went wrong.
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.