summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authortrasz <trasz@FreeBSD.org>2015-01-28 15:46:11 +0000
committertrasz <trasz@FreeBSD.org>2015-01-28 15:46:11 +0000
commitb7bb1dabe49776494d20ef55f89858d44829945d (patch)
tree805856343c0ecfe50504861e89788083e581cc56 /usr.sbin
parenta109e385975169f6a5ec55a2999f1f70a6b1457d (diff)
downloadFreeBSD-src-b7bb1dabe49776494d20ef55f89858d44829945d.zip
FreeBSD-src-b7bb1dabe49776494d20ef55f89858d44829945d.tar.gz
When there are no automounted filesystems, autounmountd(8) should wait
for filesystem event, instead of looping on a timeout. MFC after: 1 month Sponsored by: The FreeBSD Foundation
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/autofs/autounmountd.c36
1 files changed, 23 insertions, 13 deletions
diff --git a/usr.sbin/autofs/autounmountd.c b/usr.sbin/autofs/autounmountd.c
index 0f52b66..b85f3ca 100644
--- a/usr.sbin/autofs/autounmountd.c
+++ b/usr.sbin/autofs/autounmountd.c
@@ -182,7 +182,7 @@ expire_automounted(double expiration_time)
{
struct automounted_fs *af, *tmpaf;
time_t now;
- double mounted_for, mounted_max = 0;
+ double mounted_for, mounted_max = -1.0;
int error;
now = time(NULL);
@@ -231,21 +231,28 @@ do_wait(int kq, double sleep_time)
{
struct timespec timeout;
struct kevent unused;
- int error;
-
- assert(sleep_time > 0);
- timeout.tv_sec = sleep_time;
- timeout.tv_nsec = 0;
-
- log_debugx("waiting for filesystem event for %.0f seconds", sleep_time);
- error = kevent(kq, NULL, 0, &unused, 1, &timeout);
- if (error < 0)
+ int nevents;
+
+ if (sleep_time != -1.0) {
+ assert(sleep_time > 0.0);
+ timeout.tv_sec = sleep_time;
+ timeout.tv_nsec = 0;
+
+ log_debugx("waiting for filesystem event for %.0f seconds", sleep_time);
+ nevents = kevent(kq, NULL, 0, &unused, 1, &timeout);
+ } else {
+ log_debugx("waiting for filesystem event");
+ nevents = kevent(kq, NULL, 0, &unused, 1, NULL);
+ }
+ if (nevents < 0)
log_err(1, "kevent");
- if (error == 0)
+ if (nevents == 0) {
log_debugx("timeout reached");
- else
+ assert(sleep_time > 0.0);
+ } else {
log_debugx("got filesystem event");
+ }
}
int
@@ -324,7 +331,10 @@ main_autounmountd(int argc, char **argv)
for (;;) {
refresh_automounted();
mounted_max = expire_automounted(expiration_time);
- if (mounted_max < expiration_time) {
+ if (mounted_max == -1.0) {
+ sleep_time = mounted_max;
+ log_debugx("no filesystems to expire");
+ } else if (mounted_max < expiration_time) {
sleep_time = difftime(expiration_time, mounted_max);
log_debugx("some filesystems expire in %.0f seconds",
sleep_time);
OpenPOWER on IntegriCloud