Skip to content

Commit 805efcc

Browse files
committed
Abort also on SIGTERM
1 parent be694c8 commit 805efcc

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/main.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,12 @@ int main(int argc, const char* argv[]) noexcept {
218218
#else
219219
// Linux ctrl-c handler
220220

221-
sigint_function = [&](int /*s*/) {
222-
zit::logger()->warn("CTRL-C pressed. Stopping torrent(s)...");
221+
sigint_function = [&](int s) {
222+
if (s == SIGINT) {
223+
zit::logger()->warn("CTRL-C pressed. Stopping torrent(s)...");
224+
} else if (s == SIGTERM) {
225+
zit::logger()->warn("SIGTERM received. Stopping torrent(s)...");
226+
}
223227
for (const auto& torrent : torrents) {
224228
torrent->stop();
225229
}
@@ -232,11 +236,11 @@ int main(int argc, const char* argv[]) noexcept {
232236
};
233237

234238
// NOLINTBEGIN(cppcoreguidelines-pro-type-union-access,misc-include-cleaner)
235-
struct sigaction sigIntHandler {};
239+
struct sigaction sigIntHandler{};
236240
sigIntHandler.sa_handler = sigint_handler;
237241
sigemptyset(&sigIntHandler.sa_mask);
238242
sigIntHandler.sa_flags = 0;
239-
sigaction(SIGINT, &sigIntHandler, nullptr);
243+
sigaction(SIGINT | SIGTERM, &sigIntHandler, nullptr);
240244
// NOLINTEND(cppcoreguidelines-pro-type-union-access,misc-include-cleaner)
241245
#endif // !WIN32
242246

tests/process_linux.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ bool Process::wait_for_exit(chrono::milliseconds timeout) {
102102

103103
void Process::terminate() {
104104
if (m_pid) {
105+
logger()->debug("Sending SIGTERM to {}", m_name);
105106
kill(m_pid, SIGTERM);
106107
if (!wait_for_exit(5s)) {
107108
logger()->info("{} still not dead, sending SIGKILL", m_name);

0 commit comments

Comments
 (0)