#include "common.h"
#include <errno.h>
-#include <pthread.h>
#include <stdlib.h>
#include "log.h"
exit(error);
}
}
+
+int
+close_thread(pthread_t thread, char const *what)
+{
+ int error;
+
+ error = pthread_cancel(thread);
+ if (error && error != ESRCH) {
+ pr_crit("pthread_cancel() threw %d on the '%s' thread.",
+ error, what);
+ return error;
+ }
+
+ error = pthread_join(thread, NULL);
+ if (error)
+ pr_crit("pthread_join() threw %d on the '%s' thread.",
+ error, what);
+
+ return error;
+}
+
#ifndef SRC_RTR_COMMON_H_
#define SRC_RTR_COMMON_H_
+#include <pthread.h>
#include <semaphore.h>
/* "I think that this is not supposed to be implemented." */
void rwlock_write_lock(pthread_rwlock_t *);
void rwlock_unlock(pthread_rwlock_t *);
+/** Also boilerplate. */
+int close_thread(pthread_t thread, char const *what);
+
#endif /* SRC_RTR_COMMON_H_ */
return error;
}
-/* Wait for threads to end gracefully */
+/* Terminates client threads as gracefully as I know how to. */
static void
wait_threads(void)
{
while (!SLIST_EMPTY(&threads)) {
ptr = SLIST_FIRST(&threads);
SLIST_REMOVE_HEAD(&threads, next);
- /* TODO interrupt then join? Is this legal? */
- pthread_kill(ptr->tid, SIGINT);
- pthread_join(ptr->tid, NULL);
- free(ptr);
+ /*
+ * If the close fails, the thread might still be using the
+ * thread_param variables, so leak instead.
+ */
+ if (close_thread(ptr->tid, "Client") == 0)
+ free(ptr);
}
}
#include "updates_daemon.h"
#include <errno.h>
-#include <pthread.h>
#include <stdbool.h>
#include <unistd.h>
+#include "common.h"
#include "config.h"
-#include "log.h" /* TODO delete me probably */
+#include "log.h"
#include "notify.h"
#include "object/tal.h"
#include "rtr/db/vrps.h"
void
updates_daemon_destroy(void)
{
- pthread_cancel(thread);
- pthread_join(thread, NULL);
+ /* Not much to do with the error code. */
+ close_thread(thread, "Validation");
}