summaryrefslogtreecommitdiff
path: root/meta-ibs/meta-cp2-5422/recipes-phosphor/network/phosphor-snmp/0002-main-Add-UNIX-signals-handler.patch
blob: 9ff1e358972901419393ac31578e3fd036399557 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
From 81daf0a592fdcb0df22476621e3202e9932a867e Mon Sep 17 00:00:00 2001
From: "Andrey V.Kosteltsev" <AKosteltsev@IBS.RU>
Date: Sun, 17 Jul 2022 12:55:01 +0300
Subject: [PATCH 2/3] main: Add UNIX signals handler

This commit adds a handler for SIGTERM and SIGINT signals that is the normal service stop.

Signed-off-by: Andrey V.Kosteltsev <AKosteltsev@IBS.RU>
---
 meson.build              |  4 ++++
 snmp_main.cpp            | 15 +++++++++++++++
 subprojects/stdplus.wrap |  6 ++++++
 3 files changed, 25 insertions(+)
 create mode 100644 subprojects/stdplus.wrap

diff --git a/meson.build b/meson.build
index 8a82752..4ed6094 100644
--- a/meson.build
+++ b/meson.build
@@ -18,6 +18,7 @@ conf_data.set('CLASS_VERSION', 1)
 
 sdbusplus_dep = dependency('sdbusplus')
 sdeventplus_dep = dependency('sdeventplus')
+stdplus_dep = dependency('stdplus')
 phosphor_dbus_interfaces_dep = dependency('phosphor-dbus-interfaces')
 phosphor_logging_dep = dependency('phosphor-logging')
 libsystemd_dep = dependency('libsystemd')
@@ -32,6 +33,7 @@ deps = [
     phosphor_logging_dep,
     sdbusplus_dep,
     sdeventplus_dep,
+    stdplus_dep,
 ]
 
 sources = [
@@ -58,6 +60,7 @@ executable(
 libsnmp_deps = [
     sdbusplus_dep,
     sdeventplus_dep,
+    stdplus_dep,
     phosphor_logging_dep,
     phosphor_dbus_interfaces_dep,
     netsnmp_dep,
@@ -91,6 +94,7 @@ import('pkgconfig').generate(
     requires: [
       sdbusplus_dep,
       sdeventplus_dep,
+      stdplus_dep,
     ],
     description: 'Phosphor snmp utilities',
 )
diff --git a/snmp_main.cpp b/snmp_main.cpp
index ab3c4b6..df5850b 100644
--- a/snmp_main.cpp
+++ b/snmp_main.cpp
@@ -5,10 +5,18 @@
 #include <phosphor-logging/lg2.hpp>
 #include <sdbusplus/bus.hpp>
 #include <sdeventplus/event.hpp>
+#include <sdeventplus/source/signal.hpp>
 #include <sdbusplus/server/manager.hpp>
+#include <stdplus/signal.hpp>
 
 #include <memory>
 
+static void cleanExit(sdeventplus::source::Signal& source,
+                      const struct signalfd_siginfo*)
+{
+    source.get_event().exit(EXIT_SUCCESS);
+}
+
 int main(int /*argc*/, char** /*argv[]*/)
 {
     auto bus = sdbusplus::bus::new_default();
@@ -27,5 +35,12 @@ int main(int /*argc*/, char** /*argv[]*/)
 
     manager->restoreClients();
 
+    // Clean exit by unix signal
+    stdplus::signal::block(SIGTERM);
+    stdplus::signal::block(SIGINT);
+
+    sdeventplus::source::Signal sigTerm(event, SIGTERM, cleanExit);
+    sdeventplus::source::Signal sigInt(event, SIGINT, cleanExit);
+
     return event.loop();
 }
diff --git a/subprojects/stdplus.wrap b/subprojects/stdplus.wrap
new file mode 100644
index 0000000..2f8a5f4
--- /dev/null
+++ b/subprojects/stdplus.wrap
@@ -0,0 +1,6 @@
+[wrap-git]
+url = https://github.com/openbmc/stdplus.git
+revision = HEAD
+
+[provide]
+stdplus = stdplus_dep
-- 
2.35.1