From owner-p4-projects@FreeBSD.ORG Wed May 30 07:23:49 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 05AD516A46C; Wed, 30 May 2007 07:23:49 +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 B685116A41F for ; Wed, 30 May 2007 07:23:48 +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 A62DF13C469 for ; Wed, 30 May 2007 07:23:48 +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 l4U7NmSV037264 for ; Wed, 30 May 2007 07:23:48 GMT (envelope-from andrew@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.8/8.13.8/Submit) id l4U7Nmko037258 for perforce@freebsd.org; Wed, 30 May 2007 07:23:48 GMT (envelope-from andrew@freebsd.org) Date: Wed, 30 May 2007 07:23:48 GMT Message-Id: <200705300723.l4U7Nmko037258@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 120598 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, 30 May 2007 07:23:49 -0000 http://perforce.freebsd.org/chv.cgi?CH=120598 Change 120598 by andrew@andrew_hermies on 2007/05/30 07:22:48 Document what the look_for_updates function is ment to do and how it does it Use default_check_period rather than a magic number Push the selection of base dirs out of look_for_updates to let me read it from a config file later Affected files ... .. //depot/projects/soc2007/andrew-update/backend/facund-be.c#2 edit Differences ... ==== //depot/projects/soc2007/andrew-update/backend/facund-be.c#2 (text+ko) ==== @@ -71,16 +71,27 @@ return 0; } +/* + * Loops looking for updates. + * There are two ways, the first is to use kqueue to wait + * for an EVFILT_VNODE event on the database directory with + * a timeout to allow for the directory to have changed + * between the time we last checked for updates and the + * call to kqueue. The second is to sleep for a set time + * period. The only advantage the kqueue method has over + * sleeping is we may see the update sooner this way. + */ void * -look_for_updates(void *data __unused) +look_for_updates(void *data) { - const char *base_dirs[] = { "/", NULL }; char db_dir[PATH_MAX]; struct timespec timeout; int *dir_fd, kq, use_kqueue, found_updates; struct kevent *events, changes; size_t pos, dir_count; + char **base_dirs; + base_dirs = data; for (dir_count = 0; base_dirs[dir_count] != NULL; dir_count++) continue; @@ -110,7 +121,7 @@ found_updates = 0; /* XXX This timeout will be bigger in a live system */ - timeout.tv_sec = 10; + timeout.tv_sec = default_check_period; timeout.tv_nsec = 0; kq = kqueue(); if (kq == -1) @@ -140,7 +151,7 @@ use_kqueue = 1; } } else { - sleep(10); + sleep(default_check_period); } } return NULL; @@ -149,7 +160,8 @@ int main(int argc __unused, char *argv[] __unused) { - look_for_updates(NULL); + const char *base_dirs[] = { "/", NULL }; + look_for_updates(base_dirs); return 0; }