Skip to content

Commit

Permalink
Use g_unix_signal_add instead of sigaction
Browse files Browse the repository at this point in the history
Change-Id: I2ed6fbde5ba6db989ae80e89a9f929df36db4a80
  • Loading branch information
isak-jakobsson committed Nov 12, 2024
1 parent 12d3e45 commit 2d1f770
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/acap_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

#include <getopt.h>
#include <glib-unix.h>
#include <glib.h>
#include <grpcpp/grpcpp.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -53,28 +54,21 @@ static GMainLoop* loop = NULL;
*
* @param signal_num Signal number.
*/
static void handle_signals(__attribute__((unused)) int signal_num) {
switch (signal_num) {
static gboolean handle_signals(gpointer signal_num) {
switch (GPOINTER_TO_INT(signal_num)) {
case SIGINT:
case SIGTERM:
case SIGQUIT:
g_main_loop_quit(loop);
}
return G_SOURCE_REMOVE;
}

/**
* @brief Initialize signals
*/
static void init_signals(void) {
struct sigaction sa;

sa.sa_flags = 0;

sigemptyset(&sa.sa_mask);
sa.sa_handler = handle_signals;
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGQUIT, &sa, NULL);
g_unix_signal_add(SIGINT, handle_signals, gpointer(SIGINT));
g_unix_signal_add(SIGTERM, handle_signals, gpointer(SIGTERM));
}

// Initialize acap-runtime and start gRPC service
Expand Down

0 comments on commit 2d1f770

Please sign in to comment.