From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH v3 09/10] core: Make use of mainloop_run_with_signal
Date: Fri, 30 Nov 2018 12:20:12 +0200 [thread overview]
Message-ID: <20181130102013.29023-9-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20181130102013.29023-1-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This don't require setting up signalfd.
---
src/main.c | 64 +++---------------------------------------------------
1 file changed, 3 insertions(+), 61 deletions(-)
diff --git a/src/main.c b/src/main.c
index 7ab1349cc..67eb6ac59 100644
--- a/src/main.c
+++ b/src/main.c
@@ -497,24 +497,11 @@ static gboolean quit_eventloop(gpointer user_data)
return FALSE;
}
-static gboolean signal_handler(GIOChannel *channel, GIOCondition cond,
- gpointer user_data)
+static void signal_callback(int signum, void *user_data)
{
static bool terminated = false;
- struct signalfd_siginfo si;
- ssize_t result;
- int fd;
- if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP))
- return FALSE;
-
- fd = g_io_channel_unix_get_fd(channel);
-
- result = read(fd, &si, sizeof(si));
- if (result != sizeof(si))
- return FALSE;
-
- switch (si.ssi_signo) {
+ switch (signum) {
case SIGINT:
case SIGTERM:
if (!terminated) {
@@ -532,46 +519,6 @@ static gboolean signal_handler(GIOChannel *channel, GIOCondition cond,
__btd_toggle_debug();
break;
}
-
- return TRUE;
-}
-
-static guint setup_signalfd(void)
-{
- GIOChannel *channel;
- guint source;
- sigset_t mask;
- int fd;
-
- sigemptyset(&mask);
- sigaddset(&mask, SIGINT);
- sigaddset(&mask, SIGTERM);
- sigaddset(&mask, SIGUSR2);
-
- if (sigprocmask(SIG_BLOCK, &mask, NULL) < 0) {
- perror("Failed to set signal mask");
- return 0;
- }
-
- fd = signalfd(-1, &mask, 0);
- if (fd < 0) {
- perror("Failed to create signal descriptor");
- return 0;
- }
-
- channel = g_io_channel_unix_new(fd);
-
- g_io_channel_set_close_on_unref(channel, TRUE);
- g_io_channel_set_encoding(channel, NULL, NULL);
- g_io_channel_set_buffered(channel, FALSE);
-
- source = g_io_add_watch(channel,
- G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
- signal_handler, NULL);
-
- g_io_channel_unref(channel);
-
- return source;
}
static char *option_debug = NULL;
@@ -682,7 +629,6 @@ int main(int argc, char *argv[])
uint16_t sdp_mtu = 0;
uint32_t sdp_flags = 0;
int gdbus_flags = 0;
- guint signal;
init_defaults();
@@ -711,8 +657,6 @@ int main(int argc, char *argv[])
mainloop_init();
- signal = setup_signalfd();
-
__btd_log_init(option_debug, option_detach);
g_log_set_handler("GLib", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL |
@@ -781,12 +725,10 @@ int main(int argc, char *argv[])
mainloop_sd_notify("STATUS=Running");
mainloop_sd_notify("READY=1");
- mainloop_run();
+ mainloop_run_with_signal(signal_callback, NULL);
mainloop_sd_notify("STATUS=Quitting");
- g_source_remove(signal);
-
plugin_cleanup();
btd_profile_cleanup();
--
2.17.2
next prev parent reply other threads:[~2018-11-30 10:20 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-30 10:20 [PATCH v3 01/10] share/mainloop: Add handling of NOTIFY_SOCKET Luiz Augusto von Dentz
2018-11-30 10:20 ` [PATCH v3 02/10] share/mainloop: Add watchdog support Luiz Augusto von Dentz
2018-11-30 10:20 ` [PATCH v3 03/10] tool/btmon-logger: Use mainloop_notify instead of sd_notify Luiz Augusto von Dentz
2018-11-30 10:20 ` [PATCH v3 04/10] core: Use mainloop_sd_notify " Luiz Augusto von Dentz
2018-11-30 10:20 ` [PATCH v3 05/10] core: Remove old code related to sd_notify Luiz Augusto von Dentz
2018-11-30 10:20 ` [PATCH v3 06/10] shared/timeout-glib: Check 0 id when removing timeout Luiz Augusto von Dentz
2018-11-30 10:20 ` [PATCH v3 07/10] shared/mainloop: Add mainloop_run_with_signal Luiz Augusto von Dentz
2018-11-30 10:20 ` [PATCH v3 08/10] shared/mainloop: Remove mainloop_set_signal Luiz Augusto von Dentz
2018-11-30 10:20 ` Luiz Augusto von Dentz [this message]
2018-11-30 10:20 ` [PATCH v3 10/10] shared/tester: Make use of mainloop_run_with_signal Luiz Augusto von Dentz
2018-12-05 12:09 ` [PATCH v3 01/10] share/mainloop: Add handling of NOTIFY_SOCKET Luiz Augusto von Dentz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181130102013.29023-9-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).