index ca1c50de3866318efefe06f399539d65a762f35d..c3bd2b845abce37362a9003a5ee42a9fd344a80f 100644 (file)
--- a/src/tools/sysdbd/main.c
+++ b/src/tools/sysdbd/main.c
return NULL;
} /* backend_handler */
+static int
+main_loop(void)
+{
+ pthread_t backend_thread;
+ size_t i;
+
+ plugin_main_loop.do_loop = 1;
+ frontend_main_loop.do_loop = 1;
+
+ memset(&backend_thread, 0, sizeof(backend_thread));
+ if (pthread_create(&backend_thread, /* attr = */ NULL,
+ backend_handler, /* arg = */ NULL)) {
+ char buf[1024];
+ sdb_log(SDB_LOG_ERR, "Failed to create backend handler thread: %s",
+ sdb_strerror(errno, buf, sizeof(buf)));
+
+ plugin_main_loop.do_loop = 0;
+ return 1;
+ }
+
+ sdb_fe_socket_t *sock = sdb_fe_sock_create();
+ for (i = 0; i < listen_addresses_num; ++i)
+ if (sdb_fe_sock_add_listener(sock, listen_addresses[i]))
+ break;
+
+ /* break on error */
+ if (i >= listen_addresses_num)
+ sdb_fe_sock_listen_and_serve(sock, &frontend_main_loop);
+
+ sdb_log(SDB_LOG_INFO, "Waiting for backend thread to terminate");
+ plugin_main_loop.do_loop = 0;
+ /* send a signal to interrupt the sleep call
+ * and make the thread shut down faster */
+ pthread_kill(backend_thread, SIGINT);
+ pthread_join(backend_thread, NULL);
+ sdb_fe_sock_destroy(sock);
+
+ return 0;
+} /* main_loop */
+
int
main(int argc, char **argv)
{
char *config_filename = NULL;
_Bool do_daemonize = 1;
- pthread_t backend_thread;
-
struct sigaction sa_intterm;
int status;
sdb_plugin_init_all();
plugin_main_loop.default_interval = SECS_TO_SDB_TIME(60);
- memset(&backend_thread, 0, sizeof(backend_thread));
- if (pthread_create(&backend_thread, /* attr = */ NULL,
- backend_handler, /* arg = */ NULL)) {
- char buf[1024];
- sdb_log(SDB_LOG_ERR, "Failed to create backend handler thread: %s",
- sdb_strerror(errno, buf, sizeof(buf)));
+ /* ignore, we see this, for example, if a client disconnects without
+ * closing the connection cleanly */
+ signal(SIGPIPE, SIG_IGN);
- plugin_main_loop.do_loop = 0;
- }
- else {
- size_t i;
-
- sdb_fe_socket_t *sock = sdb_fe_sock_create();
- for (i = 0; i < listen_addresses_num; ++i)
- if (sdb_fe_sock_add_listener(sock, listen_addresses[i]))
- break;
-
- sdb_connection_enable_logging();
-
- /* break on error */
- if (i >= listen_addresses_num)
- sdb_fe_sock_listen_and_serve(sock, &frontend_main_loop);
-
- sdb_log(SDB_LOG_INFO, "Waiting for backend thread to terminate");
- plugin_main_loop.do_loop = 0;
- pthread_kill(backend_thread, SIGINT);
- pthread_join(backend_thread, NULL);
- sdb_fe_sock_destroy(sock);
- }
+ sdb_connection_enable_logging();
+ status = main_loop();
sdb_log(SDB_LOG_INFO, "Shutting down SysDB daemon "SDB_VERSION_STRING
SDB_VERSION_EXTRA" (pid %i)", (int)getpid());
- return 0;
+ return status;
} /* main */
/* vim: set tw=78 sw=4 ts=4 noexpandtab : */