Superseded patch?

2019-06-10 Thread Michael Greenberg
Hi all,

I just noticed that an old patch of mine is marked as 'superseded' in
patchwork . Was this a
conscious decision not to fix the POSIX noncompliance here, an accident,
or something else? Should I resubmit the patch?

Cheers,
Michael


[PATCH] Bug in times builtin

2019-06-10 Thread Michael Greenberg
Hi all,

The `times` builtin in dash fails to compute the seconds part
properly. To see the bug, I ran the following script:

```sh
delay() {
case "$#" in
( 0 ) secs=1 ;;
( 1 ) secs=$(($1+0)) ;;
( * ) exit 2 ;;
esac

start=$(date "+%s")
while now=$(date "+%s") ;
  [ $((now - start)) -lt "$secs" ]
do
:
done
}

times
delay $((5 * 60))
times
```

The script implements a 5min sleep. An unpatched dash produces the
following output:

```
0m0.00s 0m0.00s
0m0.00s 0m0.00s
0m8.33s 0m26.69s
1m97.67s 1m107.15s
```

With the patch, the seconds are computed correctly (NB that this is a
different run so times vary slightly):

```
0m0.00s 0m0.00s
0m0.00s 0m0.00s
0m8.26s 0m27.05s
1m38.13s 1m45.96s
```

If folks are opposed to including math.h for some reason, I'm sure the
computation could be done another way.

Cheers,
Michael

Signed-off-by: Michael Greenberg 
diff --git a/src/bltin/times.c b/src/bltin/times.c
index 8eabc1f..7e66f90 100644
--- a/src/bltin/times.c
+++ b/src/bltin/times.c
@@ -3,6 +3,7 @@
  * This file contains code for the times builtin.
  */
 
+#include 
 #include 
 #include 
 #ifdef USE_GLIBC_STDIO
@@ -19,12 +20,12 @@ int timescmd() {
times();
printf("%dm%fs %dm%fs\n%dm%fs %dm%fs\n",
   (int) (buf.tms_utime / clk_tck / 60),
-  ((double) buf.tms_utime) / clk_tck,
+  fmod(((double) buf.tms_utime) / clk_tck, 60),
   (int) (buf.tms_stime / clk_tck / 60),
-  ((double) buf.tms_stime) / clk_tck,
+  fmod(((double) buf.tms_stime) / clk_tck, 60),
   (int) (buf.tms_cutime / clk_tck / 60),
-  ((double) buf.tms_cutime) / clk_tck,
+  fmod(((double) buf.tms_cutime) / clk_tck, 60),
   (int) (buf.tms_cstime / clk_tck / 60),
-  ((double) buf.tms_cstime) / clk_tck);
+  fmod(((double) buf.tms_cstime) / clk_tck, 60));
return 0;
 }