From 210baa258f2895475c94603b77e1cfbdd6f13ee6 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Tue, 17 Oct 2023 09:43:16 +0200 Subject: [PATCH] Exit cleanly on avahi error --- server/avahi_publisher.cpp | 7 ++++--- server/main.cpp | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/server/avahi_publisher.cpp b/server/avahi_publisher.cpp index 30d80e06..0f5b3d5a 100644 --- a/server/avahi_publisher.cpp +++ b/server/avahi_publisher.cpp @@ -23,9 +23,10 @@ void avahi_publisher::create_service(AvahiClient * client) entry_group = avahi_entry_group_new(client, avahi_entry_group_callback, nullptr); if (!entry_group) { - std::cerr << "Cannot create entry group, you may need to remove disable-user-service-publishing from your avahi daemon config: " - << avahi_strerror(avahi_client_errno(client)) << std::endl; - abort(); + throw std::runtime_error( + std::string( + "Cannot create entry group, you may need to remove disable-user-service-publishing from your avahi daemon config: ") + + avahi_strerror(avahi_client_errno(client))); } } avahi_entry_group_reset(entry_group); diff --git a/server/main.cpp b/server/main.cpp index 1afd471e..2ee37f02 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -194,6 +194,7 @@ int inner_main(int argc, char * argv[]) bool quit = false; while (!quit) { + try { avahi_publisher publisher(hostname().c_str(), "_wivrn._tcp", control_port); @@ -220,6 +221,11 @@ int inner_main(int argc, char * argv[]) if (sigint_received) break; } + catch (std::exception& e) + { + std::cerr << e.what() << std::endl; + return EXIT_FAILURE; + } pid_t client_pid = start_application();