Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/autofs autofs: Change autounmountd(8) to use time_t...



details:   https://anonhg.NetBSD.org/src/rev/25a00def1ebe
branches:  trunk
changeset: 461269:25a00def1ebe
user:      tkusumi <tkusumi%NetBSD.org@localhost>
date:      Thu Nov 21 16:45:05 2019 +0000

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

The commit log from FreeBSD.
--
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.
--

Taken-from: FreeBSD and DragonFlyBSD

diffstat:

 usr.sbin/autofs/autounmountd.c |  47 ++++++++++++++++++++---------------------
 1 files changed, 23 insertions(+), 24 deletions(-)

diffs (133 lines):

diff -r d7383a4a3249 -r 25a00def1ebe usr.sbin/autofs/autounmountd.c
--- a/usr.sbin/autofs/autounmountd.c    Thu Nov 21 15:24:17 2019 +0000
+++ b/usr.sbin/autofs/autounmountd.c    Thu Nov 21 16:45:05 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: autounmountd.c,v 1.1 2018/01/09 03:31:15 christos Exp $        */
+/*     $NetBSD: autounmountd.c,v 1.2 2019/11/21 16:45:05 tkusumi Exp $ */
 
 /*-
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  *
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: autounmountd.c,v 1.1 2018/01/09 03:31:15 christos Exp $");
+__RCSID("$NetBSD: autounmountd.c,v 1.2 2019/11/21 16:45:05 tkusumi Exp $");
 
 #include <sys/types.h>
 #include <sys/mount.h>
@@ -175,12 +175,12 @@
        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);
@@ -188,14 +188,14 @@
        log_debugx("expiring automounted filesystems");
 
        TAILQ_FOREACH_SAFE(af, &automounted, af_next, tmpaf) {
-               mounted_for = difftime(now, af->af_mount_time);
+               mounted_for = (time_t)difftime(now, af->af_mount_time);
 
                if (mounted_for < expiration_time) {
                        log_debugx("skipping %s (FSID:%d:%d), mounted "
-                           "for %.0f seconds", af->af_mountpoint,
+                           "for %jd seconds", af->af_mountpoint,
                            af->af_fsid.__fsid_val[0],
                            af->af_fsid.__fsid_val[1],
-                           mounted_for);
+                           (intmax_t)mounted_for);
 
                        if (mounted_for > mounted_max)
                                mounted_max = mounted_for;
@@ -204,9 +204,9 @@
                }
 
                log_debugx("filesystem mounted on %s (FSID:%d:%d), "
-                   "was mounted for %.0f seconds; unmounting",
+                   "was mounted for %jd seconds; unmounting",
                    af->af_mountpoint, af->af_fsid.__fsid_val[0],
-                   af->af_fsid.__fsid_val[1], mounted_for);
+                   af->af_fsid.__fsid_val[1], (intmax_t)mounted_for);
                error = do_unmount(af->af_fsid, af->af_mountpoint);
                if (error != 0) {
                        if (mounted_for > mounted_max)
@@ -227,19 +227,19 @@
 }
 
 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 = (int)sleep_time;
                timeout.tv_nsec = 0;
 
-               log_debugx("waiting for filesystem event for %.0f seconds",
-                   sleep_time);
+               log_debugx("waiting for filesystem event for %jd seconds",
+                   (intmax_t)sleep_time);
                nevents = kevent(kq, NULL, 0, &unused, 1, &timeout);
        } else {
                log_debugx("waiting for filesystem event");
@@ -253,7 +253,7 @@
 
        if (nevents == 0) {
                log_debugx("timeout reached");
-               assert(sleep_time > 0.0);
+               assert(sleep_time > 0);
        } else {
                log_debugx("got filesystem event");
        }
@@ -264,7 +264,7 @@
 {
        struct kevent event;
        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) {
@@ -333,19 +333,18 @@
        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 = 
-                           (double)difftime((time_t)expiration_time,
-                           (time_t)mounted_max);
-                       log_debugx("some filesystems expire in %.0f seconds",
-                           sleep_time);
+                       sleep_time =
+                           (time_t)difftime(expiration_time, mounted_max);
+                       log_debugx("some filesystems expire in %jd seconds",
+                           (intmax_t)sleep_time);
                } else {
                        sleep_time = retry_time;
                        log_debugx("some expired filesystems remain mounted, "
-                           "will retry in %.0f seconds", sleep_time);
+                           "will retry in %jd seconds", (intmax_t)sleep_time);
                }
 
                do_wait(kq, sleep_time);



Home | Main Index | Thread Index | Old Index