Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 21 Jul 2007 03:49:44 GMT
From:      Andrew Turner <andrew@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 123833 for review
Message-ID:  <200707210349.l6L3niEe084285@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=123833

Change 123833 by andrew@andrew_hermies on 2007/07/21 03:49:03

	When a the communications thread is closed also kill the update thread
	Listen to more signals

Affected files ...

.. //depot/projects/soc2007/andrew-update/backend/facund-be.c#15 edit

Differences ...

==== //depot/projects/soc2007/andrew-update/backend/facund-be.c#15 (text+ko) ====

@@ -76,6 +76,7 @@
 static struct facund_response *facund_call_restart_services(const char *,
     struct facund_object *);
 
+static int	facund_signals[] = { SIGHUP, SIGINT, SIGTERM };
 static void	facund_signal_handler(int, siginfo_t *, void *);
 
 /*
@@ -152,6 +153,12 @@
 	/* Add a signal event to check if there was a signal sent */
 	EV_SET(&event, SIGINT, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL);
 	kevent(kq, &event, 1, NULL, 0, NULL);
+	for (pos = 0; pos < sizeof(facund_signals) / sizeof(facund_signals[0]);
+	    pos++) {
+		EV_SET(&event, facund_signals[pos], EVFILT_SIGNAL, EV_ADD,
+		    0, 0, NULL);
+		kevent(kq, &event, 1, NULL, 0, NULL);
+	}
 
 	use_kqueue = 1;
 	found_updates = 0;
@@ -557,6 +564,7 @@
 	struct facund_conn *conn;
 	const char *config_file;
 	char *basedirs_string, **base_dirs;
+	unsigned int pos;
 	int config_fd;
 	properties config_data;
 	char ch;
@@ -580,10 +588,13 @@
 
 	basedirs_string = NULL;
 
-	sa.sa_sigaction = facund_signal_handler;
-	sigemptyset(&sa.sa_mask);
-	sa.sa_flags = SA_SIGINFO;
-	sigaction(SIGINT, &sa, NULL);
+	for (pos = 0; pos < sizeof(facund_signals) / sizeof(facund_signals[0]);
+	    pos++) {
+		sa.sa_sigaction = facund_signal_handler;
+		sigemptyset(&sa.sa_mask);
+		sa.sa_flags = SA_SIGINFO;
+		sigaction(facund_signals[pos], &sa, NULL);
+	}
 
 	/* Read in the config file */
 	config_fd = open(config_file, O_RDONLY);
@@ -632,6 +643,11 @@
 
 	/* Wait for the threads to quit */
 	pthread_join(comms_thread, NULL);
+	/*
+	 * As the communications thread has quit we should
+	 * also kill the update thread so we can exit
+	 */
+	pthread_kill(update_thread, SIGINT);
 	pthread_join(update_thread, NULL);
 
 	if (conn != NULL)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200707210349.l6L3niEe084285>