-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement psutil_proc_exe for NetBSD #1534
base: master
Are you sure you want to change the base?
Conversation
Mmm... on a second thought I am not sure I understand why this change is necessary. Isn't pure-python |
|
Uh? No, Linux is not involved. This is (Net)BSD specific code which is not shared with the Linux implementation. |
/proc on NetBSD is kept for Linux compat only. |
All native applications shall use sysctl, mounting /proc shall be restricted to running emulated linux binaries only. In practice this is sometimes violated, but that is abnormal state. |
And regarding pid 0, it has to be removed from the list of processes on NetBSD. If some operation for it works, it's rather accident. |
Are you saying /proc on NetBSD is broken, deprecated or something? I'm merely trying to understand the rationale here as there are 2 other functions using it.
Nope, PID 0 is a legitimate PID. The kernel itself returns it and so does |
It's not a native interface. It's a compat layer for Linux binaries as NetBSD can run native Linux programs as is. The same applies to FreeBSD. OpenBSD doesn't support compat and deleted /proc completely. I don't want to go into historical notes as it was.. a replacement for ptrace(2) back in the days. That property is long gone. In short it shall not be used in modern NetBSD software. We can tell that it is formally deprecated, as adding there !Linux interfaces need special core approval. Depending on /proc mounted on NetBSD is at most a compat fallback. It's not needed to be mounted for native programs (and it shall be unmounted). |
I question this. The lowest meaningful PID that can be a parent for other processes is pid1 (/sbin/init). You cannot reparent anything to pid0 (possibly an exception is pid1). Usability of pid0 as process is probably restricted to programs like ps(1) or top(1) to a little bit introspect into the kernel... but I don't know the original rationale. |
I intend to switch psutil to native interfaces for all calls that are applicable for NetBSD. |
After some discussions, I think we should add missing interfaces for pid0 to return somewhat fake values for queries that in general make no sense for kernel anyway.. this is better than erroring. |
I see no error. Running as limited user:
On other platforms certain methods will fail with |
After some more research there is no way to determine exe name for pid0. Probably better than returning some /nonexistent, return an error from the kernel and handle this in a userland program. |
pthread does not make sense for kernel. It is also not that clear for userland as not every threaded program uses POSIX threads, e.g. golang reinvents them. On NetBSD there are native threads (LWP) and they can be wrapped with libpthread to compose POSIX C-style threads. |
What error are you getting? ...as for threads, regardless from PID 0 there are some failing tests (see |
The kernel can be loaded from other source than filesystem (e.g. passed with |
OK but what python exception are you seeing if you query PID 0? |
As I said |
It turns out this approach was already tried and in fact there is even a commented code doing what you did in here (but I forgot): psutil/psutil/arch/netbsd/specific.c Line 153 in 6bb5a30
Your patch differs in that it does not dynamically determine the size via sysctl.
|
Did you run tests? Do you get the same failure reported in #557 (comment)? |
I will update my code tonight. |
Keep fallback for versions <8.0 without KERN_PROC_PATHNAME.
I don't know how to run tests. I'm just checking new functions manually.
|
Ping? |
Please refresh me on this. What's wrong with doing
...but AFAIK /proc is always available on NetBSD. Also, we rely on /proc also for other things (/proc/stat and /proc/meminfo). |
The official interface for prompting this data is sysctl(3). /proc is a legacy interface from BSD4.4 and it happened to have some compat use with Linux, but it is deprecated for BSD software. Ideally we would remove it completely (some other BSDs already did it). It is available only if we mount it, it's not enabled by default. |
|
The only valid use case of |
Kamil Rytarowski writes:
[...]
It is available only if we mount it, it's not enabled by default.
[...]
That's not correct: sysinst(8) always adds an entry in fstab and enable
it by default (i.e. I would expect it enabled by default on most
installations).
|
Interesting. I missed it, but the statement about preference on sysctl stands. |
There was also a core@ statement in NetBSD on deprecation of /proc at some point. |
I googled for "netbsd procfs deprecation" and similar but nothing relevant came up. I found different references of procfs on NetBSD but nothing that suggests a deprecation. AFAICT /proc on NetBSD currently looks alive and supported. |
I don't know about a public one, but as I worked on ptrace(2) there was a statement from a core member that any extra work with /proc (that is not for compat for linux executables) needs approval. Today new APIs and interfaces are not implemented in /proc. |
I actually removed some /proc functionality already too. |
Generally speaking the BSDs have been trying to move away from procfs for a long time already. And even so if it's kind of supported, meaning that it can be mounted, one should not rely on its presence. In many systems it just won't be mounted by default. For example FreeBSD doesn't even mount it by default, OpenBSD doesn't , DragonFly BSD still mounts it but does not recommend it (and in fact doesn't even use it during their binary package build). sysctl is a much more robust interface to extract information and operate some system parameters, it should be used whenever possible in the BSDs. HTH |
@krytarowski psutil/psutil/arch/freebsd/specific.c Line 232 in 994c429
If you want, you can move that into _psutil_bsd.c so that it's used by NetBSD and FreeBSD (I think it won't work on OpenBSD, but I may be wrong).
Once you do that let's see the test output though, because there is a comment saying psutil/psutil/arch/netbsd/specific.c Line 155 in 994c429
|
Both BSDs use different arguments. I am not motivated to pretend that BSDs are similar as they are not.
/proc and sysctl use the same functionality in the kernel. In general this feature was improved internally to be more reliable over few years. There were issues with long filenames or hardsymlink confusion in a path etc. |
They look the same to me. :-\ |
Keep fallback for versions <8.0 without KERN_PROC_PATHNAME.