Atoptool / atop

System and process monitor for Linux
GNU General Public License v2.0
792 stars 109 forks source link

changes needed for 64-bit time_t #306

Closed Zugschlus closed 2 months ago

Zugschlus commented 2 months ago

Hi,

Debian is currently migrating to a 64-bit time_t even on 32bit systems. This doesn't work with atop. The following patch is suggested:

+Index: atop-2.10.0/parseable.c
+===================================================================
+--- atop-2.10.0.orig/parseable.c
++++ atop-2.10.0/parseable.c
+@@ -214,10 +214,10 @@
+                       convdate(curtime, datestr);
+                       convtime(curtime, timestr);
+
+-                      snprintf(header, sizeof header, "%s %s %ld %s %s %d",
++                      snprintf(header, sizeof header, "%s %s %lld %s %s %d",
+                               labeldef[i].label,
+                               utsname.nodename,
+-                              curtime,
++                              (long long)curtime,
+                               datestr, timestr, numsecs);
+
+                       /*

I am not very well versed in C, but this looks to me like it will fail on systems that still have a 32-bit time_t, so this patch might not be suitable to take upstream. Would you want to handle this upstream, or should I apply the patch in Debian nevertheless for the time being?

Usages of atop -P cpu and atop -P DSK on 32 bit arches such as armhf with Debian unstable seem to be affected by this issue, I can readily reproduce it.

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1069859

Greetings Marc

Atoptool commented 2 months ago

In my opinion the suggested patch can be considered as a generic solution. The type cast (long long) takes care that the variable will be converted in case of a 32-bit value or might be ignored in case of a 64-bit value.