Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 6 Jun 2007 06:48:32 GMT
From:      Andrew Turner <andrew@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 121038 for review
Message-ID:  <200706060648.l566mWm8086181@repoman.freebsd.org>

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

Change 121038 by andrew@andrew_hermies on 2007/06/06 06:47:47

	Use the new library to communicate with the front-end over a unix socket.

Affected files ...

.. //depot/projects/soc2007/andrew-update/backend/Makefile#5 edit
.. //depot/projects/soc2007/andrew-update/backend/facund-be.c#6 edit

Differences ...

==== //depot/projects/soc2007/andrew-update/backend/Makefile#5 (text+ko) ====

@@ -1,7 +1,7 @@
 PROG=	facund-be
 
-CFLAGS+=-pthread
-LDADD+=	-lutil -lmd
+CFLAGS+=-pthread -I${.CURDIR}/../lib
+LDADD+=	-lbsdxml -lutil -lmd ${.OBJDIR}/../lib/libfacund.a
 
 MAN=
 

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

@@ -35,6 +35,7 @@
 #include <sys/time.h>
 
 #include <assert.h>
+#include <bsdxml.h>
 #include <err.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -46,6 +47,8 @@
 #include <string.h>
 #include <unistd.h>
 
+#include <facund_connection.h>
+
 /* Check if there are updates every 30min  */
 static const time_t default_check_period = 30 * 60;
 
@@ -55,6 +58,7 @@
 static int	  has_update(const char *);
 static void	 *look_for_updates(void *);
 static char	**get_base_dirs(char *);
+static void	 *do_communication(void *);
 
 /*
  * Looks for updates on the system with a root of basedir
@@ -225,10 +229,42 @@
 	return ret;
 }
 
+static void *
+do_communication(void *data)
+{
+	struct facund_conn *conn = (struct facund_conn *)data;
+
+	signal(SIGPIPE, SIG_DFL);
+
+	while(1) {
+		int ret = 0;
+		if(facund_server_start(conn) == -1) {
+			fprintf(stderr,
+			    "ERROR: Couldn't start the connection\n");
+			break;
+		}
+
+		while(ret == 0) {
+			ret = facund_server_get_request(conn);
+			if (ret == -1) {
+				fprintf(stderr,
+				    "ERROR: Couldn't read data from network\n");
+			}
+		}
+
+		facund_server_finish(conn);
+		if (ret == -1)
+			break;
+	}
+
+	return NULL;
+}
+
 int
 main(int argc __unused, char *argv[] __unused)
 {
-	pthread_t update_thread;
+	pthread_t update_thread, comms_thread;
+	struct facund_conn *conn;
 	const char *config_file;
 	char *basedirs_string, **base_dirs;
 	int config_fd;
@@ -282,11 +318,24 @@
 		    config_file);
 	}
 
+	/* Create the data connection */
+	conn = facund_connect_server("/tmp/facund");
+	if (conn == NULL) {
+		errx(1, "Could not open a socket: %s\n", strerror(errno));
+	}
+
 	pthread_create(&update_thread, NULL, look_for_updates, base_dirs);
+	pthread_create(&comms_thread, NULL, do_communication, conn);
+
+	pthread_join(comms_thread, NULL);
 	pthread_join(update_thread, NULL);
 
+	if (conn != NULL)
+		facund_cleanup(conn);
+
 	if (base_dirs != NULL)
 		free(base_dirs);
+
 	free(basedirs_string);
 	return 0;
 }



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