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
Merged

Openbsd support (#562) #615

merged 34 commits into from Nov 12, 2015

Conversation

landryb
Copy link
Contributor

@landryb 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 and others added 30 commits December 26, 2014 21:18
- 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
Copy link

benoitc commented May 14, 2015

+1

@giampaolo
Copy link
Owner

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 mentioned this pull request Nov 6, 2015
@giampaolo
Copy link
Owner

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
@landryb
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
@giampaolo
Copy link
Owner

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
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
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
Copy link
Owner

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
Copy link
Owner

@landryb can you please comment about this?

// TODO: why?

@landryb
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
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
Development

Successfully merging this pull request may close these issues.

None yet

3 participants