Skip to content
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

Openbsd support (#562) #615

Merged
merged 34 commits into from Nov 12, 2015

Conversation

@landryb
Copy link
Contributor

landryb commented Apr 5, 2015

Isnt perfect yet, but would be nice to merge early so that the work isnt lost. Basic functionality needed by end users work...

landryb added 30 commits Dec 26, 2014
- switch mem/swap to VM_UVMEXP & swapctl
- #if 0 out cpu_count_phys
- use KERN_CPTIME in cpu_times
- provide an empty disk_io_counters implem, needed by tests
- disable proc_connections for now
…that info.

At best you get an inode or the filesystem the process is running within..
No way to distinguish between read and write times, so assume half spent in both..
@benoitc

This comment has been minimized.

Copy link

benoitc commented May 14, 2015

+1

@giampaolo

This comment has been minimized.

Copy link
Owner

giampaolo commented Nov 6, 2015

I took a look back at this and updated the code here:
https://github.com/giampaolo/psutil/tree/landryb-openbsd
What's missing:

  • Process.open_files()'s path is an empty string; kif->f_mntonname refers to the mountpoint (useless), kif->unp_path is always empty. lsof somehow manages to do it.
  • Process.memory_maps() is not implemented (see code sample here: https://github.com/Bluerise/OpenBSD-src/blob/master/usr.sbin/procmap/procmap.c).
  • Process.cmdline() does not return the actual cmdline; we get things such as ['pflogd: [running] -s 160 -i pflog0 -f /var/log/pflog'], ['sshd: user@notty'] and ['smtpd: scheduler'].
  • Process.num_ctx_switches()'s involuntary field is always 0; I suppose this means it is just not supported on OpenBSD so it's OK to skip this test.
  • user@openbsd~/psutil$ python -c "import psutil; print psutil.Process(0).exe()"
    python: Invalid argument

DONE:

  • Process.threads() returns EINVAL. (fixed in 67da39e)
  • Process.memory_info().vms (aka kp.p_vm_map_size) is always 0. "ps" manages to show VMS somehow; as a last resort we might parse ps output (fixed in eeac17f).
  • Process.cwd() is not implemented; couldn't find any way to determine this. lsof somehow manages to get this. (fixed in 0410205).
  • Process.num_threads() is not implemented. (fixed in 2ce156b)
  • Process.connetions() and net_connections()'s status is always None. (fixed in 5808a06)
  • Process.connetions() and net_connections()'s addr is always None for IPv6 sockets. (fixed in de97900)
@giampaolo giampaolo referenced this pull request Nov 6, 2015
@giampaolo

This comment has been minimized.

Copy link
Owner

giampaolo commented Nov 8, 2015

Process.cwd() implemented in 0410205

giampaolo added a commit that referenced this pull request Nov 8, 2015
giampaolo added a commit that referenced this pull request Nov 8, 2015
giampaolo added a commit that referenced this pull request Nov 8, 2015
giampaolo added a commit that referenced this pull request Nov 8, 2015
giampaolo added a commit that referenced this pull request Nov 8, 2015
@landryb

This comment has been minimized.

Copy link
Contributor Author

landryb commented Nov 9, 2015

Thanks for picking up this, i admit it feel out of the radar since i had no time for it...

giampaolo added a commit that referenced this pull request Nov 9, 2015
giampaolo added a commit that referenced this pull request Nov 10, 2015
@giampaolo giampaolo merged commit 7edb559 into giampaolo:master Nov 12, 2015
1 check failed
1 check failed
continuous-integration/travis-ci/pr The Travis CI build failed
Details
@giampaolo

This comment has been minimized.

Copy link
Owner

giampaolo commented Nov 12, 2015

OK, I merged everything in here #709 and b4625ab.
Last remaining issues are:

  • Process.memory_maps() is not supported
  • Process.open_files() return empty paths (also FreeBSD has this problem)
  • Process.exe() is not fully implemented and currently relies on cmdline()
@landryb

This comment has been minimized.

Copy link
Contributor Author

landryb commented Nov 12, 2015

as i already said several times, open_files() will never get implemented, the kernel won't provide such an API.

@landryb

This comment has been minimized.

Copy link
Contributor Author

landryb commented Nov 12, 2015

But yay for seeing this merged \o/

giampaolo added a commit that referenced this pull request Nov 12, 2015
@giampaolo

This comment has been minimized.

Copy link
Owner

giampaolo commented Nov 12, 2015

as i already said several times, open_files() will never get implemented, the kernel won't provide such an API.

Do you know if this is a kernel bug? We have the same problem on FreeBSD which does provide the necessary API but the path sometimes is empty. Also OpenBSD should provide it (kif->unp_path) and it's empty. Any internet reference which explains any of this is welcome.

@giampaolo

This comment has been minimized.

Copy link
Owner

giampaolo commented Nov 12, 2015

@landryb can you please comment about this?

// TODO: why?

@landryb

This comment has been minimized.

Copy link
Contributor Author

landryb commented Nov 13, 2015

Do you know if this is a kernel bug? We have the same problem on FreeBSD which does provide the necessary API but the path sometimes is empty. Also OpenBSD should provide it (kif->unp_path) and it's empty. Any internet reference which explains any of this is welcome.

This is not a bug, it's on purpose for 'privacy reasons'. As for kif->unp_path, it's not filled much, see http://bxr.su/search?q=unp_path&project=OpenBSD

The only information you can get is the inode (see http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man1/fstat.1 from which you can list open inodes for a process), from which you could theoretically do lookups in the filesystem but this is cumbersome.

$fstat -p 21801   
USER     CMD          PID   FD MOUNT        INUM MODE       R/W    SZ|DV
landry   xfce4-session 21801 text /         1147672 -r-xr-xr-x   r   189368
landry   xfce4-session 21801   wd /home    29491840 drwxr-xr-x   r     7680
landry   xfce4-session 21801    0 /         1716753 crw-rw-rw-  rw     null
landry   xfce4-session 21801    1 /home    29496358 -rw-r--r--   w   407233
landry   xfce4-session 21801    2 /home    29496358 -rw-r--r--   w   407233
landry   xfce4-session 21801    3 /          572089 -rw-r--r--   w     2643
landry   xfce4-session 21801    4* unix stream 0x0
landry   xfce4-session 21801    5 pipe 0x0 state: 
landry   xfce4-session 21801    6 pipe 0x0 state: 
landry   xfce4-session 21801    7* unix stream 0x0
landry   xfce4-session 21801    8* unix stream 0x0
landry   xfce4-session 21801    9 /home    29492111 -rw-r--r--   w    11834
landry   xfce4-session 21801   10 pipe 0x0 state: 
landry   xfce4-session 21801   11 pipe 0x0 state: 
landry   xfce4-session 21801   12* unix stream 0x0
landry   xfce4-session 21801   13* unix stream 0x0
landry   xfce4-session 21801   14* unix stream 0x0
landry   xfce4-session 21801   15* unix stream 0x0
landry   xfce4-session 21801   16* unix stream 0x0
landry   xfce4-session 21801   17* unix stream 0x0

@landryb can you please comment about this?

// TODO: why?

struct diskstats doesnt provide a breakdown between read and write time i think, see
http://bxr.su/OpenBSD/sys/sys/disk.h#62

@landryb

This comment has been minimized.

Copy link
Contributor Author

landryb commented Nov 13, 2015

As for the open files, the OS providing this information have to keep a cache of fd/inode/path around, and update it if the file is moved/hardlinked/etc - OpenBSD just doesnt do this.

zachriggle added a commit to zachriggle/pwntools that referenced this pull request Dec 19, 2016
OpenBSD was the edge case we cared about, it is supported for over a year (giampaolo/psutil#615)
zachriggle added a commit to Gallopsled/pwntools that referenced this pull request Dec 20, 2016
* Remove support for installation without psutil.

OpenBSD was the edge case we cared about, it is supported for over a year (giampaolo/psutil#615)

* Bump psutil version to when they introduced OpenBSD support
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.