85 lines
2.3 KiB
Diff
85 lines
2.3 KiB
Diff
From: Marcel Holtmann <marcel@holtmann.org>
|
|
Date: Mon, 3 Dec 2018 19:48:08 +0100
|
|
Subject: [PATCH] tools: Use l_main_run_with_signal instead of open coding it
|
|
|
|
---
|
|
tools/btpclient.c | 14 +++-----------
|
|
1 file changed, 3 insertions(+), 11 deletions(-)
|
|
|
|
diff --git a/tools/btpclient.c b/tools/btpclient.c
|
|
index b217df58f..3f958e65c 100644
|
|
--- a/tools/btpclient.c
|
|
+++ b/tools/btpclient.c
|
|
@@ -27,10 +27,11 @@
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
#include <assert.h>
|
|
#include <getopt.h>
|
|
+#include <signal.h>
|
|
|
|
#include <ell/ell.h>
|
|
|
|
#include "lib/bluetooth.h"
|
|
#include "src/shared/btp.h"
|
|
@@ -2825,12 +2826,11 @@ static void register_core_service(void)
|
|
|
|
btp_register(btp, BTP_CORE_SERVICE, BTP_OP_CORE_UNREGISTER,
|
|
btp_core_unregister, NULL, NULL);
|
|
}
|
|
|
|
-static void signal_handler(struct l_signal *signal, uint32_t signo,
|
|
- void *user_data)
|
|
+static void signal_handler(uint32_t signo, void *user_data)
|
|
{
|
|
switch (signo) {
|
|
case SIGINT:
|
|
case SIGTERM:
|
|
l_info("Terminating");
|
|
@@ -3154,12 +3154,10 @@ static const struct option options[] = {
|
|
};
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
struct l_dbus_client *client;
|
|
- struct l_signal *signal;
|
|
- sigset_t mask;
|
|
int opt;
|
|
|
|
l_log_set_stderr();
|
|
|
|
while ((opt = getopt_long(argc, argv, "+hs:vq", options, NULL)) != -1) {
|
|
@@ -3192,15 +3190,10 @@ int main(int argc, char *argv[])
|
|
return EXIT_FAILURE;
|
|
|
|
|
|
adapters = l_queue_new();
|
|
|
|
- sigemptyset(&mask);
|
|
- sigaddset(&mask, SIGINT);
|
|
- sigaddset(&mask, SIGTERM);
|
|
- signal = l_signal_create(&mask, signal_handler, NULL, NULL);
|
|
-
|
|
dbus = l_dbus_new_default(L_DBUS_SYSTEM_BUS);
|
|
l_dbus_set_ready_handler(dbus, ready_callback, NULL, NULL);
|
|
client = l_dbus_client_new(dbus, "org.bluez", "/org/bluez");
|
|
|
|
l_dbus_client_set_connect_handler(client, client_connected, NULL, NULL);
|
|
@@ -3210,15 +3203,14 @@ int main(int argc, char *argv[])
|
|
l_dbus_client_set_proxy_handlers(client, proxy_added, proxy_removed,
|
|
property_changed, NULL, NULL);
|
|
|
|
l_dbus_client_set_ready_handler(client, client_ready, NULL, NULL);
|
|
|
|
- l_main_run();
|
|
+ l_main_run_with_signal(signal_handler, NULL);
|
|
|
|
l_dbus_client_destroy(client);
|
|
l_dbus_destroy(dbus);
|
|
- l_signal_remove(signal);
|
|
btp_cleanup(btp);
|
|
|
|
l_queue_destroy(adapters, (l_queue_destroy_func_t)btp_adapter_free);
|
|
|
|
l_free(socket_path);
|