From c32fe42f40d0af8b31b6113a3140f52b83be7769 Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Tue, 20 Jun 2023 13:10:23 -0400 Subject: Add sd_notify call 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 Change-Id: I069d3caa4e3cddb0041e2f94ecb568499104dcf2 --- src/main-grpc.cc | 11 +++++++---- 1 file 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 #include #include +#include #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) +void WaitGrpcServer(std::shared_ptr &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); -- cgit 1.2.3-korg