NetBSD-Bugs archive

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

bin/60248: pluralization bug: shutdown(8) warning says "1 minutes" if time left > 60 seconds



>Number:         60248
>Category:       bin
>Synopsis:       pluralization bug: shutdown(8) warning says "1 minutes" if time left > 60 seconds
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon May 11 19:50:00 +0000 2026
>Originator:     Ilia Javan
>Release:        10.1
>Organization:
None
>Environment:
NetBSD  10.1 NetBSD 10.1 (GENERIC) #0: Mon Dec 16 13:08:11 UTC 2024  mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/amd64/compile/GENERIC amd64
>Description:
Calling shutdown(8) with a scheduled time will warn the user how many minutes remain until shutdown, rounding down the number of seconds. However, it incorrectly uses the plural form "minutes" if the time left is less than two minutes but greater than exactly 60 seconds.

For example, if 3 minutes + 50 seconds remain, then the system warns that "3 minutes" remain:

# date
Mon May 11 14:39:09 EDT 2026
# shutdown 43
Shutdown at Mon May 11 14:43:00 2026.
shutdown: [pid 3471]
#
*** System shutdown message from ilia@ ***
System going down in 3 minutes

If exactly 60 seconds remain, the correct singular form "1 minute" is used:

# date; shutdown 53
Mon May 11 14:51:59 EDT 2026
Shutdown at Mon May 11 14:53:00 2026.
shutdown: [pid 751]
#
*** System shutdown message from ilia@ ***
System going down in 1 minute

However, if 1 minute and a nonzero number of seconds remain, the system incorrectly uses the plural form "1 minutes" because it does not account for the rounding down from, e.g. 90 seconds, to 1 minute:

# date; shutdown 08
Mon May 11 15:06:29 EDT 2026
Shutdown at Mon May 11 15:08:00 2026.
shutdown: [pid 3312]
#                                                          
*** System shutdown message from ilia@ ***                 
System going down in 1 minutes  

p.s. this is my first PR; please let me know if anything is incorrect, missing, or unnecessary. thank you.
>How-To-Repeat:
1. Run date to get the current time, e.g.,

$ date
Mon May 11 15:12:05 EDT 2026

2. Before the minute finishes, schedule shutdown at the current time plus two minutes, assuming that the current time is not exactly on second zero. This must be done as root, e.g,

# shutdown 14
Shutdown at Mon May 11 15:14:00 2026.
shutdown: [pid 3561]
#                                                          
*** System shutdown message from ilia@ ***                 
System going down in 1 minutes                             

I have verified my fix with the following testcases:
-exactly 60 seconds: prints "1 minute" (originally correct)
-90 seconds: prints "1 minute" (now fixed)
-120 seconds: prints "2 minutes" (originally correct)
>Fix:
--- sbin/shutdown/shutdown.c.orig       2026-05-11 10:38:54.316248625 -0400
+++ sbin/shutdown/shutdown.c    2026-05-11 15:42:20.258931444 -0400
@@ -324,7 +324,7 @@
                    ctime(&shuttime) + 11);
        else if (timeleft > 59)
                (void)fprintf(pf, "System going down in %ld minute%s\n\n",
-                   (long)timeleft / 60, (timeleft > 60) ? "s" : "");
+                   (long)timeleft / 60, (timeleft >= 120) ? "s" : "");
        else if (timeleft)
                (void)fprintf(pf, "System going down in 30 seconds\n\n");
        else




Home | Main Index | Thread Index | Old Index