Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 30 May 2007 07:23:48 GMT
From:      Andrew Turner <andrew@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 120598 for review
Message-ID:  <200705300723.l4U7Nmko037258@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
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;
 }
 



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