Skip to content
This repository was archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Add signal handler to aktualizr daemon
Browse files Browse the repository at this point in the history
Interrupts the main loop cleanly when a signal is caught

Signed-off-by: Laurent Bonnans <laurent.bonnans@here.com>
  • Loading branch information
lbonn committed Sep 23, 2019
1 parent 1a0fea1 commit c1c1c68
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/libaktualizr/primary/aktualizr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <sodium.h>

#include "primary/events.h"
#include "utilities/sig_handler.h"
#include "utilities/timer.h"

using std::make_shared;
Expand Down Expand Up @@ -83,8 +84,24 @@ bool Aktualizr::UptaneCycle() {
std::future<void> Aktualizr::RunForever() {
std::future<void> future = std::async(std::launch::async, [&]() {
SendDeviceData().get();
while (UptaneCycle()) {
std::this_thread::sleep_for(std::chrono::seconds(config_.uptane.polling_sec));

bool exiting = false;
std::mutex exit_m;
std::condition_variable exit_cv;
SigHandler::get().start([&exit_m, &exit_cv, &exiting]() {
{
std::lock_guard<std::mutex> g(exit_m);
exiting = true;
}
exit_cv.notify_one();
});

std::unique_lock<std::mutex> l(exit_m);
while (true) {
UptaneCycle();
if (exit_cv.wait_for(l, std::chrono::seconds(config_.uptane.polling_sec), [&exiting] { return exiting; })) {
break;
}
}
uptane_client_->completeInstall();
});
Expand Down

0 comments on commit c1c1c68

Please sign in to comment.