psutil icon indicating copy to clipboard operation
psutil copied to clipboard

[Haiku] IFF bugs in Haiku OS R1/beta4

Open amstelchen opened this issue 1 year ago • 2 comments

Summary

  • OS: Haiku 1 hrev56578+87 Jul 14 2023 06:23: x86_64 x86_64 Haiku
  • Architecture: 64bit
  • Psutil version: psutil-5.6.7-1
  • Python version: Python 3.9.17 (main, Jun 11 2023, 12:39:17) ** also tested with Python 3.10.12 (main, Jun 11 2023, 12:18:53) [GCC 11.2.0] on haiku
  • Type: { installation, build, haikuports }

Description

Tried on preinstalled Python 3.9.17, as well as Python 3.10.12. With 3.9.17: haikuporter/haikuporter -v --debug --no-repository-update psutil output

This did of course not give any hints what was wrong, thus after applying the patch manually, using patch -p1 < psutil-5.6.7.patchset:

psutil/_psutil_posix.c: In function 'psutil_net_if_is_running':
psutil/_psutil_posix.c:665:26: error: 'IFF_RUNNING' undeclared (first use in this function)
  665 |     if ((ifr.ifr_flags & IFF_RUNNING) != 0)
      |                          ^~~~~~~~~~~
psutil/_psutil_posix.c:665:26: note: each undeclared identifier is reported only once for each function it appears in
error: command '/bin/gcc' failed with exit code 1

If I patch psutil/_psutil_posix.c:

    // if ((ifr.ifr_flags & IFF_RUNNING) != 0)
        return Py_BuildValue("O", Py_True);
    //else
    //    return Py_BuildValue("O", Py_False);

it apparently works, but throws some module error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/packages/python3.9-3.9.17-1/.self/non-packaged/lib/python3.9/site-packages/psutil-5.6.7-py3.9-haiku-1-x86_64.egg/psutil/__init__.py", line 180, in <module>
    from . import _pshaiku as _psplatform
  File "/packages/python3.9-3.9.17-1/.self/non-packaged/lib/python3.9/site-packages/psutil-5.6.7-py3.9-haiku-1-x86_64.egg/psutil/_pshaiku.py", line 22, in <module>
    from ._common import AccessDenied
ImportError: cannot import name 'AccessDenied' from 'psutil._common' (/packages/python3.9-3.9.17-1/.self/non-packaged/lib/python3.9/site-packages/psutil-5.6.7-py3.9-haiku-1-x86_64.egg/psutil/_common.py)

Looking at psutil/_common-py, AccessDenied is there:

class AccessDenied(Error):
    """Exception raised when permission to perform an action is denied."""
    __module__ = 'psutil'

Is this due to some change in output of network interfaces in beta4?

Other failed tests: Python 3.9.17 + psutil-5.9.5 Python 3.10.12 + psutil-5.6.7-1 Python 3.10.12 and latest psutil-5.9.5

amstelchen avatar Jul 15 '23 13:07 amstelchen

This port of psutil you're trying to use is based on a version released a year before Python 3.9. Wouldn't even try it...

When trying 5.9.5 did you apply proper patches for Haiku? Those 5.6.7 patches don't seem to cleanly apply for 5.9.5.

After applying those (with i.e. git apply -3 psutil-5.6.7.patchset and resolving conflicts) there are still changes to be made:

  • Changing set_testing to set_debug in _psutil_haiku.cpp
  • Adding check_pid_range to _psutil_haiku.cpp

And there are probably more... Adapt to the changes made to other _psutil_<platform>.c (and maybe _ps<platform>.py) files between 5.6.7-5.9.5.

Anyway, with those changes I could use psutil.pids(), psutil.Process(<pid>), psutil.virtual_memory() and psutil.boot_time() on Haiku, for example.

BTW, when testing psutil make sure your cwd is not the psutil source directory, or you'd get some weird import errors...

And... I'd suggest submitting required changes back to haikuports, because I doubt support for a niche OS such as this one would be upstreamed anytime soon.

ben9923 avatar Aug 05 '23 22:08 ben9923

Is IFF_RUNNING defined on Haiku? Can you paste the output of grep -r IFF_RUNNING /usr/include/?

giampaolo avatar Aug 07 '23 03:08 giampaolo

Have been able to build latest release with an updated patchset and a define for IFF_RUNNING, needed psutil to checkout vorta which seems to run fine (needed that to checkout borgbackup).

Begasus avatar Feb 27 '24 10:02 Begasus

@Begasus can you provide a PR or a diff?

giampaolo avatar Feb 27 '24 10:02 giampaolo

Sure, let me try to fork and create a PR for master branch.

EDIT: this still applies cleanly on the latest commit:

https://raw.githubusercontent.com/haikuports/haikuports/0db48f44988880f47275d3c5dc90ebadcd247753/dev-python/psutil/patches/psutil-5.9.8.patchset

Credit due to @mmuman

Begasus avatar Feb 27 '24 10:02 Begasus

Sorry, I didn't realize Haiku would be a brand new platform implementation (I erroneously thought it was a Linux variant requiring just a couple of tweaks). Adding support for Haiku was something I rejected some years back, see the reasoning given in https://github.com/giampaolo/psutil/pull/1690#issuecomment-748222016.

giampaolo avatar Feb 27 '24 11:02 giampaolo

OK, no problem, so far Haiku has come a long way and is even noticed globaly (hence KDE mentions Haiku in their list of supported OS's), you are right that you probably won't see any figures popping up on how many downloads this will list up (as we use our own package managment). Thanks for checking.

Begasus avatar Feb 27 '24 11:02 Begasus

Yeah. I think it makes more sense to make this work live, develop and mature in its own fork / repo. It would receive more maintenance than in here (e.g. in here it wouldn't have CI testing). If such a repo / fork exists we can link it in this ticket, so that users that look for it can find it.

giampaolo avatar Feb 27 '24 14:02 giampaolo

Thanks, for now this lives in: https://github.com/haikuports/haikuports/tree/master/dev-python/psutil Where the patches are collected/kept, if need be users can help out there or file an issue at our issue tracker at: https://github.com/haikuports/haikuports/issues

Begasus avatar Feb 27 '24 14:02 Begasus