pkgsrc-Users archive

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

Re: Failure to build go on some 32bit port-i386 machines



On Sun, May 05, 2024 at 08:01:15PM +0200, Matthias Petermann wrote:
> Hi,
> 
> On 05.05.24 18:00, Alexander Schreiber wrote:
> > Since what got me here was wanting to run node_exporter, I've got
> > two remaining open paths:
> >   - look at sysutils/netbsd_exporter and fix it (it currently reports
> >     negative numbers for filesystem size)
> 
> that's interesting... are you able to provide me a test case or some
> parameters for this?

Simply build and run on a 32bit machine. I tested my usual candidates
for this: port-i386, port-sparc, port-vax. I assume this was written
and tested on 64bit machines only.

Example output (snipped irrelevant parts):

netbsd_fs_size_bytes{device="wd0a",mountpoint="/"} -1958563840
netbsd_fs_used_bytes{device="wd0a",mountpoint="/"} -1555032064
netbsd_fs_free_bytes{device="wd0a",mountpoint="/"} -1808840704

df says:

/dev/wd0a       26G   2.6G    22G  10% /

> Which with partition / filesystem size and type you
> erperience this problems? I'm looking forward to fix this. Feel free to
> submit an issue against my mirror [1].

It's too trivial for that. You got bitten by the old "size of classic
C integer types depends on platform" trap. In this case, long is
8 bytes (64bit) on a 64bit machine (which is large enough here) and
4 bytes (32bit) on a 32bit machine (which will cheerfully overflow
here).

There are reasons int64_t, uint64_t, int32_t and friends are defined
these days. Of course with _that_, gcc rightfully complains about
the formatting args, because uint64_t is long long int on 32bit and
long int on 64bit machines. So I ended up using long long which is
64bit on both.

With that, it works correctly on both 32bit and 64bit machines. Tested
platforms: port-i386, port-amd64, port-vax, port-sparc, port-sparc64.

And for those who no longer _have_ 32bit machines, qemu works very well
(that's how I run my port-sparc machine on an arm64 host).


--------------- cut here for patch -----------------------
--- netbsd_exporter.h.orig      2024-05-09 18:58:29.961248161 +0200
+++ netbsd_exporter.h   2024-05-09 19:49:00.021634195 +0200
@@ -31,7 +31,7 @@
 int option_http_header = 1;
 int option_syslog = 1;
 
-void print_filesystem_metric(const char*, const char*, const char*, long );
+void print_filesystem_metric(const char*, const char*, const char*, long long unsigned int);
 
 void print_disk_io_metric(const char*, long long unsigned int, long long unsigned int );
 
--- netbsd_exporter.c.orig      2024-05-07 11:40:44.013487932 +0200
+++ netbsd_exporter.c   2024-05-09 19:49:15.832451252 +0200
@@ -53,8 +53,8 @@
 #include "netbsd_exporter.h"
 #include "version.h"
 
-void print_filesystem_metric(const char* metric, const char* device, const char* mountpoint, long value) {
-    printf("netbsd_fs_%s_bytes{device=\"%s\",mountpoint=\"%s\"} %ld\n", metric, device, mountpoint, value);
+void print_filesystem_metric(const char* metric, const char* device, const char* mountpoint, long long unsigned int value) {
+    printf("netbsd_fs_%s_bytes{device=\"%s\",mountpoint=\"%s\"} %llu\n", metric, device, mountpoint, value);
 }
 
 void print_disk_io_metric(const char* device, long long unsigned int rbytes, long long unsigned int wbytes) {
--------------- cut here for patch -----------------------

Kind regards,
            Alex.
-- 
"Opportunity is missed by most people because it is dressed in overalls and
 looks like work."                                      -- Thomas A. Edison


Home | Main Index | Thread Index | Old Index