[Bug 260174] libprocstat's i386 procstat_getfiles() fails on amd64

From: <bugzilla-noreply_at_freebsd.org>
Date: Thu, 02 Dec 2021 16:46:03 UTC

            Bug ID: 260174
           Summary: libprocstat's i386 procstat_getfiles() fails on amd64
           Product: Base System
           Version: 13.0-RELEASE
          Hardware: amd64
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: bin
          Assignee: bugs@FreeBSD.org
          Reporter: damjan.jov@gmail.com

An i386 binary calling procstat_getfiles() on amd64 always gets NULL returned
and errno==0, even though libutil's kinfo_getfile() works. The same code built
as an amd64 binary works with both.

I don't like procstat_getfiles() anyway, and won't be using it, at almost 1
millisecond per call it's ridiculously slow, and its linked list is less useful
and costlier to build than kinfo_getfile()'s array. Just thought it would be
good to document this issue for others that run into it.

cc -m32 file.c -o proctest -lprocstat

#include <sys/types.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/sysctl.h>
#include <sys/socket.h>
#include <sys/user.h>
#include <libprocstat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
    struct procstat *procstat = NULL;
    unsigned int count;
    struct kinfo_proc *kp = NULL;
    struct filestat_list *files = NULL;
    struct filestat *fs = NULL;
    char *ret = NULL;

    procstat = procstat_open_sysctl();
    if (!procstat) {
        fprintf(stderr, "couldn't open procstat\n");
        goto end;
    printf("opened procstat\n");
    kp = procstat_getprocs( procstat, KERN_PROC_PID, getpid(), &count );
    if (!kp || count != 1) {
        fprintf(stderr, "getprocs failed\n");
        goto end;

    printf("got proc, now looking up files...\n");
    files = procstat_getfiles( procstat, kp, 0 );
    if (!files) {
        fprintf(stderr, "getfiles failed, errno %d\n", errno);
        goto end;
    STAILQ_FOREACH( fs, files, next )
        printf("%d -> %s\n", fs->fs_fd, fs->fs_path);

    return 0;

You are receiving this mail because:
You are the assignee for the bug.