[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [patch] system_process_attributes for OpenBSD
From: |
Omar Polo |
Subject: |
Re: [patch] system_process_attributes for OpenBSD |
Date: |
Sat, 02 Jan 2021 11:36:22 +0100 |
User-agent: |
mu4e 1.4.13; emacs 27.1 |
Timo Myyrä <timo.myyra@bittivirhe.fi> writes:
> Omar Polo <op@omarpolo.com> [2021-01-01, 23:29 +0100]:
>
>[snip]
>
> Hi Omar,
>
> Are you sure you need kvm? I'm under impression its frowned upon to
> access that from userland.
Thanks for sharing! I haven't followed closely the development of
OpenBSD, but at least on -CURRENT trying to get a struct kinfo_proc for
a specific pid via sysctl results in errors (both from sysctl(8) and
sysctl(3)):
$ sysctl kern.proc
sysctl: use ps to view kern.proc information
$ sysctl kern.proc 75056 # a valid pid
sysctl: use ps to view kern.proc information
sysctl: top level name 75056 in 75056 is invalid
$ cat <<EOF > pid.c
#include <sys/types.h>
#include <sys/sysctl.h>
#include <err.h>
#include <stdlib.h>
int
main(void)
{
pid_t pid = 75056; /* valid pid */
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid };
struct kinfo_proc proc;
size_t len = sizeof(proc);
if (sysctl(mib, 4, &proc, &len, NULL, 0) != 0 || len == 0)
err(1, "sysctl");
return 0;
}
EOF
$ cc pid.c -o pid && ./pid
pid: sysctl: Invalid argument
$ ps 75056
75056 ?? S 0:38.85 emacs --daemon (emacs-27.1)
This plus the fact that both top and ps in base uses kvm were the
rationale for my choice.
Regarding list_system_processes, I still have to check the differences,
but the current version on master is fundamentally equivalent to yours
(modulo a bunch of #ifdefs for freebsd and macos), so I guess it was
merged at some point? Here on emacs-27.1 (list-system-processes)
returns nil, but on emacs compiled from master it works correctly.