From owner-p4-projects@FreeBSD.ORG Wed Jun 6 06:48:33 2007 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 1EC7B16A468; Wed, 6 Jun 2007 06:48:33 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id B8E2916A41F for ; Wed, 6 Jun 2007 06:48:32 +0000 (UTC) (envelope-from andrew@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id ABE4A13C455 for ; Wed, 6 Jun 2007 06:48:32 +0000 (UTC) (envelope-from andrew@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.8/8.13.8) with ESMTP id l566mWdv086190 for ; Wed, 6 Jun 2007 06:48:32 GMT (envelope-from andrew@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.8/8.13.8/Submit) id l566mWm8086181 for perforce@freebsd.org; Wed, 6 Jun 2007 06:48:32 GMT (envelope-from andrew@freebsd.org) Date: Wed, 6 Jun 2007 06:48:32 GMT Message-Id: <200706060648.l566mWm8086181@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to andrew@freebsd.org using -f From: Andrew Turner To: Perforce Change Reviews Cc: Subject: PERFORCE change 121038 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Jun 2007 06:48:33 -0000 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 #include +#include #include #include #include @@ -46,6 +47,8 @@ #include #include +#include + /* 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; }