dhcp-done: send status to notify netboot service
This enables the daemon for sending boot status so that netboot service
can take actions accordingly.
Tested with nc and verified that the data byte is present.
Change-Id: I570bbd7c05028b6c007ff9d5a00a8589da73a8ff
Signed-off-by: Yuxiao Zhang <yuxiaozhang@google.com>
diff --git a/subprojects/dhcp-done/dhcp-done.cpp b/subprojects/dhcp-done/dhcp-done.cpp
index dae06db..e4fcbc0 100644
--- a/subprojects/dhcp-done/dhcp-done.cpp
+++ b/subprojects/dhcp-done/dhcp-done.cpp
@@ -19,9 +19,16 @@
#include <stdplus/fd/create.hpp>
#include <stdplus/fd/ops.hpp>
+using namespace std::string_view_literals;
+
// A privileged port that is reserved for querying BMC DHCP completion.
// This is well known by the clients querying the status.
constexpr uint16_t kListenPort = 23;
+enum : uint8_t
+{
+ DONE = 0,
+ POWERCYCLE = 1,
+};
stdplus::ManagedFd createListener()
{
@@ -37,8 +44,30 @@
return sock;
}
-int main()
+int main(int argc, char* argv[])
{
+ if (argc != 2)
+ {
+ fmt::print(stderr, "Invalid parameter count\n");
+ return 1;
+ }
+
+ std::vector<uint8_t> data;
+
+ if (argv[1] == "POWERCYCLE"sv)
+ {
+ data.push_back(POWERCYCLE);
+ }
+ else if (argv[1] == "DONE"sv)
+ {
+ data.push_back(DONE);
+ }
+ else
+ {
+ fmt::print(stderr, "Invalid parameter\n");
+ return 1;
+ }
+
try
{
auto listener = createListener();
@@ -46,8 +75,11 @@
sdeventplus::source::IO do_accept(
event, listener.get(), EPOLLIN | EPOLLET,
[&](sdeventplus::source::IO&, int, uint32_t) {
- while (stdplus::fd::accept(listener))
- ;
+ while (auto fd = stdplus::fd::accept(listener))
+ {
+ stdplus::fd::sendExact(*fd, data,
+ stdplus::fd::SendFlags(0));
+ }
});
return event.loop();
}
diff --git a/subprojects/dhcp-done/dhcp-done.service.in b/subprojects/dhcp-done/dhcp-done@.service.in
similarity index 69%
rename from subprojects/dhcp-done/dhcp-done.service.in
rename to subprojects/dhcp-done/dhcp-done@.service.in
index 9fa5e24..ece864b 100644
--- a/subprojects/dhcp-done/dhcp-done.service.in
+++ b/subprojects/dhcp-done/dhcp-done@.service.in
@@ -3,4 +3,4 @@
[Service]
Restart=on-failure
-ExecStart=@@BIN@ dhcp-done
+ExecStart=@@BIN@ dhcp-done %I
diff --git a/subprojects/dhcp-done/meson.build b/subprojects/dhcp-done/meson.build
index a72690b..8f0272f 100644
--- a/subprojects/dhcp-done/meson.build
+++ b/subprojects/dhcp-done/meson.build
@@ -44,7 +44,7 @@
configure_file(
configuration: {'BIN': libexecdir / 'dhcp-done'},
- input: 'dhcp-done.service.in',
- output: 'dhcp-done.service',
+ input: 'dhcp-done@.service.in',
+ output: 'dhcp-done@.service',
install_mode: 'rw-r--r--',
install_dir: systemunitdir)