summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott Murray <scott.murray@konsulko.com>2023-06-20 13:10:23 -0400
committerScott Murray <scott.murray@konsulko.com>2023-06-20 13:12:45 -0400
commitc32fe42f40d0af8b31b6113a3140f52b83be7769 (patch)
treeabeefb1405161486bd37ccf8846be866411eac5e
parent7a3e870a8349d43a4838604db2c28140c2f76c9f (diff)
To avoid races with client applications, add a call to sd_notify after the gRPC service should be available, so that a Type=notify systemd unit can be used to start applaunchd. As well, fix up some naming and comments around what the call to the gRPC server object's Wait method is for. Bug-AGL: SPEC-4843 Signed-off-by: Scott Murray <scott.murray@konsulko.com> Change-Id: I069d3caa4e3cddb0041e2f94ecb568499104dcf2
-rw-r--r--src/main-grpc.cc11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/main-grpc.cc b/src/main-grpc.cc
index d94e4aa..0347aba 100644
--- a/src/main-grpc.cc
+++ b/src/main-grpc.cc
@@ -7,6 +7,7 @@
#include <chrono>
#include <glib.h>
#include <glib-unix.h>
+#include <systemd/sd-daemon.h>
#include "systemd_manager.h"
#include "AppLauncherImpl.h"
@@ -27,9 +28,9 @@ static gboolean quit_cb(gpointer user_data)
return G_SOURCE_REMOVE;
}
-void RunGrpcServer(std::shared_ptr<Server> &server)
+void WaitGrpcServer(std::shared_ptr<Server> &server)
{
- // Start server and wait for shutdown
+ // Wait for shutdown
server->Wait();
}
@@ -58,12 +59,14 @@ int main(int argc, char *argv[])
exit(1);
}
std::cout << "Server listening on " << server_address << std::endl;
+ sd_notify(0, "READY=1");
g_unix_signal_add(SIGTERM, quit_cb, (gpointer) &server);
g_unix_signal_add(SIGINT, quit_cb, (gpointer) &server);
- // Start gRPC API server on its own thread
- std::thread grpc_thread(RunGrpcServer, std::ref(server));
+ // Wait on gRPC API server in another thread to keep that
+ // separate from the glib loop.
+ std::thread grpc_thread(WaitGrpcServer, std::ref(server));
g_main_loop_run(main_loop);