• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / mender / 1022753986

02 Oct 2023 10:37AM UTC coverage: 78.168% (-2.0%) from 80.127%
1022753986

push

gitlab-ci

oleorhagen
feat: Run the authentication loop once upon bootstrap

Ticket: MEN-6658
Changelog: None

Signed-off-by: Ole Petter <ole.orhagen@northern.tech>

32 of 32 new or added lines in 1 file covered. (100.0%)

6996 of 8950 relevant lines covered (78.17%)

10353.4 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.37
/common/events/platform/boost/events.cpp
1
// Copyright 2023 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14

15
#include <common/events.hpp>
16

17
#include <boost/asio.hpp>
18

19
#include <common/error.hpp>
20
#include <common/log.hpp>
21

22
namespace mender {
23
namespace common {
24
namespace events {
25

26
namespace asio = boost::asio;
27
namespace error = mender::common::error;
28
namespace log = mender::common::log;
29

30
void EventLoop::Run() {
955✔
31
        bool stopped = ctx_.stopped();
955✔
32
        if (stopped) {
954✔
33
                ctx_.restart();
180✔
34
        }
35
        ctx_.run();
954✔
36
        if (!stopped) {
955✔
37
                // For recursive invocations. If we were originally running, but we stopped and
38
                // exited this level, then keep the running state of the previous recursive level.
39
                ctx_.restart();
775✔
40
        }
41
}
955✔
42

43
void EventLoop::Stop() {
952✔
44
        ctx_.stop();
952✔
45
}
952✔
46

47
void EventLoop::Post(std::function<void()> func) {
8,582✔
48
        ctx_.post(func);
8,582✔
49
}
8,582✔
50

51
Timer::Timer(EventLoop &loop) :
2,402✔
52
        timer_(GetAsioIoContext(loop)),
53
        destroying_(make_shared<bool>(false)) {
2,402✔
54
}
2,402✔
55

56
void Timer::Cancel() {
2,405✔
57
        timer_.cancel();
2,405✔
58
}
2,405✔
59

60
SignalHandler::SignalHandler(EventLoop &loop) :
×
61
        signal_set_ {GetAsioIoContext(loop)} {};
×
62

63
void SignalHandler::Cancel() {
275✔
64
        signal_set_.cancel();
275✔
65
}
275✔
66

67
error::Error SignalHandler::RegisterHandler(const SignalSet &set, SignalHandlerFn handler_fn) {
275✔
68
        signal_set_.clear();
275✔
69
        for (auto sig_num : set) {
734✔
70
                boost::system::error_code ec;
459✔
71
                signal_set_.add(sig_num, ec);
459✔
72
                if (ec) {
459✔
73
                        return error::Error(
74
                                ec.default_error_condition(),
×
75
                                "Could not add signal " + std::to_string(sig_num) + " to signal set");
×
76
                }
77
        }
78

79
        class SignalHandlerFunctor {
80
        public:
81
                asio::signal_set &sig_set;
82
                SignalHandlerFn handler_fn;
83

84
                void operator()(const boost::system::error_code &ec, int signal_number) {
8✔
85
                        if (ec) {
8✔
86
                                if (ec == boost::asio::error::operation_aborted) {
4✔
87
                                        // All handlers are called with this error when the signal set
88
                                        // is cancelled.
89
                                        return;
4✔
90
                                }
91
                                log::Error("Failure in signal handler: " + ec.message());
×
92
                        } else {
93
                                handler_fn(signal_number);
4✔
94
                        }
95

96
                        // in either case, register ourselves again because
97
                        // asio::signal_set::async_wait() is a one-off thing
98
                        sig_set.async_wait(*this);
4✔
99
                }
100
        };
101

102
        SignalHandlerFunctor fctor {signal_set_, handler_fn};
550✔
103
        signal_set_.async_wait(fctor);
275✔
104

105
        // Unfortunately, asio::signal_set::async_wait() doesn't return anything so
106
        // we have no chance to propagate any error here (wonder what they do if
107
        // they get an error from sigaction() or whatever they use
108
        // internally). Other implementations may have better options, though.
109
        return error::NoError;
275✔
110
}
111

112
} // namespace events
113
} // namespace common
114
} // namespace mender
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc