Change autounmountd(8) to use time_t for duration instead of double

Summary:
autounmountd(8) uses doubles to handle mount time durations.  However,
it must convert to integer types, time_t in particular, to do anything
meaningful.  Additionally, even though it's a floating-point value in
seconds, the sub-seconds component is never used, so it's unnecessary.

Switching type to time_t fixes an assertion on powerpc64, which checks
that a sleep value that's not -1.0 is greater than 0.  On powerpc64, it
happens that the value of -1.0 gets loaded as a float (perhaps a bug in
gcc), but gets compared to a double.  This compares as false, so follows
through the 'sleep != -1.0' path, and fails the assert.  Since the
sub-second component isn't used in the double, just drop it and deal
with whole-integer seconds.

Reviewed by:	trasz
Differential Revision: https://reviews.freebsd.org/D21109
This commit is contained in:
Justin Hibbits 2019-08-08 03:16:32 +00:00
parent 7d0658ad55
commit ca05fff090
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=350737

View File

@ -179,12 +179,12 @@ unmount_by_fsid(const fsid_t fsid, const char *mountpoint)
return (error);
}
static double
expire_automounted(double expiration_time)
static time_t
expire_automounted(time_t expiration_time)
{
struct automounted_fs *af, *tmpaf;
time_t now;
double mounted_for, mounted_max = -1.0;
time_t mounted_for, mounted_max = -1;
int error;
now = time(NULL);
@ -196,9 +196,9 @@ expire_automounted(double expiration_time)
if (mounted_for < expiration_time) {
log_debugx("skipping %s (FSID:%d:%d), mounted "
"for %.0f seconds", af->af_mountpoint,
"for %ld seconds", af->af_mountpoint,
af->af_fsid.val[0], af->af_fsid.val[1],
mounted_for);
(long)mounted_for);
if (mounted_for > mounted_max)
mounted_max = mounted_for;
@ -207,9 +207,9 @@ expire_automounted(double expiration_time)
}
log_debugx("filesystem mounted on %s (FSID:%d:%d), "
"was mounted for %.0f seconds; unmounting",
"was mounted for %ld seconds; unmounting",
af->af_mountpoint, af->af_fsid.val[0], af->af_fsid.val[1],
mounted_for);
(long)mounted_for);
error = unmount_by_fsid(af->af_fsid, af->af_mountpoint);
if (error != 0) {
if (mounted_for > mounted_max)
@ -229,18 +229,19 @@ usage_autounmountd(void)
}
static void
do_wait(int kq, double sleep_time)
do_wait(int kq, time_t sleep_time)
{
struct timespec timeout;
struct kevent unused;
int nevents;
if (sleep_time != -1.0) {
assert(sleep_time > 0.0);
if (sleep_time != -1) {
assert(sleep_time > 0);
timeout.tv_sec = sleep_time;
timeout.tv_nsec = 0;
log_debugx("waiting for filesystem event for %.0f seconds", sleep_time);
log_debugx("waiting for filesystem event for %ld seconds",
(long)sleep_time);
nevents = kevent(kq, NULL, 0, &unused, 1, &timeout);
} else {
log_debugx("waiting for filesystem event");
@ -254,7 +255,7 @@ do_wait(int kq, double sleep_time)
if (nevents == 0) {
log_debugx("timeout reached");
assert(sleep_time > 0.0);
assert(sleep_time > 0);
} else {
log_debugx("got filesystem event");
}
@ -268,7 +269,7 @@ main_autounmountd(int argc, char **argv)
pid_t otherpid;
const char *pidfile_path = AUTOUNMOUNTD_PIDFILE;
int ch, debug = 0, error, kq;
double expiration_time = 600, retry_time = 600, mounted_max, sleep_time;
time_t expiration_time = 600, retry_time = 600, mounted_max, sleep_time;
bool dont_daemonize = false;
while ((ch = getopt(argc, argv, "dr:t:v")) != -1) {
@ -336,17 +337,17 @@ main_autounmountd(int argc, char **argv)
for (;;) {
refresh_automounted();
mounted_max = expire_automounted(expiration_time);
if (mounted_max == -1.0) {
if (mounted_max == -1) {
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);
log_debugx("some filesystems expire in %ld seconds",
(long)sleep_time);
} else {
sleep_time = retry_time;
log_debugx("some expired filesystems remain mounted, "
"will retry in %.0f seconds", sleep_time);
"will retry in %ld seconds", (long)sleep_time);
}
do_wait(kq, sleep_time);