FreeBSD port

20 views
Skip to first unread message

dawe

unread,
Jan 14, 2010, 10:18:32 AM1/14/10
to PSI - Python System Information
Hi all,
I need to install a python package which uses PSI on a FreeBSD server.
Unfortunately I see that PSI is not implemented on FreeBSD (8).
So far so good.
I just want to know if a FreeBSD port will be released soon (i.e. in
the next month), otherwise I'll start writing the code.

Thanks

d

Floris Bruynooghe

unread,
Jan 14, 2010, 3:11:20 PM1/14/10
to psi-d...@googlegroups.com
Hello

I'm actively working on a Windows port currently, but the going is
slow so FreeBSD is certainly not going to be released in the next
month (I'm pretty certain Windows won't be either).

I'm happy to help you if you start writing the code for it tough.

Almost a year ago I actually started with a FreeBSD port (7.1) as a
small experiment. Most stuff seemed fairly easy IIRC so it shouldn't
be too hard. Attached are the diffs/files I have of that, I doubt
they can be cleanly applied to the current trunk but might give
pointers or a starting point (or just be plain embarrasing since
you're probably a lot more familiar with FreeBSD then me).


Regards
Floris


--
Debian GNU/Linux -- The Power of Freedom
www.debian.org | www.gnu.org | www.kernel.org

arch.diff
freebsd_process.c

Davide Cittaro

unread,
Jan 15, 2010, 3:40:28 AM1/15/10
to psi-d...@googlegroups.com
Hi Floris,

On Jan 14, 2010, at 9:11 PM, Floris Bruynooghe wrote:

Almost a year ago I actually started with a FreeBSD port (7.1) as a
small experiment.  Most stuff seemed fairly easy IIRC so it shouldn't
be too hard.  Attached are the diffs/files I have of that, I doubt
they can be cleanly applied to the current trunk but might give
pointers or a starting point (or just be plain embarrasing since
you're probably a lot more familiar with FreeBSD then me).


Ahah! I won't be so sure! I'm not a system programmer, I only have to deal with FreeBSD because here is the standard OS on servers :-)
BTW, I've looked at your code and I agree that kinfo_proc is an interesting struct. Yesterday, before your answer, I've started and had something woking just filling the psi_process struct with data directly from kinfo_proc struct. I still have to figure how to get proci->exe and args as the procfs filesystem is not mounted by default and I don't want to use it at all. Nevertheless there's this in kinfo_proc:

struct kinfo_proc {
[…]
struct pargs *ki_args; /* address of command arguments */
struct proc *ki_paddr; /* address of proc */
struct user *ki_addr; /* kernel virtual addr of u-area */
struct vnode *ki_tracep; /* pointer to trace file */
struct vnode *ki_textvp; /* pointer to executable file */
struct filedesc *ki_fd; /* pointer to open file info */
struct vmspace *ki_vmspace; /* pointer to kernel vmspace struct */
[…]

which could be exploited to fill the PSI process object.

Just an additional question: suppose I'm able to write everything, how can I test everything needed is working properly? Will setup.py test be enough?

python setup.py test --all
running test
running build
running build_py
running build_ext
compiling helper apps for tests
Traceback (most recent call last):
  File "setup.py", line 536, in <module>
    cmdclass = COMMANDS)
  File "/usr/local/lib/python2.6/distutils/core.py", line 152, in setup
    dist.run_commands()
  File "/usr/local/lib/python2.6/distutils/dist.py", line 975, in run_commands
    self.run_command(cmd)
  File "/usr/local/lib/python2.6/distutils/dist.py", line 995, in run_command
    cmd_obj.run()
  File "setup.py", line 342, in run
    self.compile_ctests()
  File "setup.py", line 389, in compile_ctests
    sys.exit('Unkown compiler: %s' % cc.compiler)
NameError: global name 'cc' is not defined

d

--

Floris Bruynooghe

unread,
Jan 15, 2010, 3:11:57 PM1/15/10
to psi-d...@googlegroups.com
Hello Davide

On Fri, Jan 15, 2010 at 09:40:28AM +0100, Davide Cittaro wrote:
> BTW, I've looked at your code and I agree that kinfo_proc is an
> interesting struct. Yesterday, before your answer, I've started and
> had something woking just filling the psi_process struct with data
> directly from kinfo_proc struct. I still have to figure how to get
> proci->exe and args as the procfs filesystem is not mounted by
> default and I don't want to use it at all. Nevertheless there's this
> in kinfo_proc:

> struct kinfo_proc {
> […]
> struct pargs *ki_args; /* address of command arguments */
> struct proc *ki_paddr; /* address of proc */
> struct user *ki_addr; /* kernel virtual addr of u-area */
> struct vnode *ki_tracep; /* pointer to trace file */
> struct vnode *ki_textvp; /* pointer to executable file */
> struct filedesc *ki_fd; /* pointer to open file info */
> struct vmspace *ki_vmspace; /* pointer to kernel vmspace struct */
> […]
>
> which could be exploited to fill the PSI process object.

Sounds like you should be able to use this ki_args to read the
arguments, but only if you have permission to read the process memory.
Maybe the best solution is to try /proc first as that's always
readable (is it?) and fall back to this method if it's not mounted,
but with the gotcha that you need to be able to read the process
memory (the solaris code does something similar, only there /proc
contains a chopped version of the args).

As for .exe, again going by the name, ki_textvp should contain this
info.

> Just an additional question: suppose I'm able to write everything,
> how can I test everything needed is working properly? Will setup.py
> test be enough?

If it's not we'll have to adapt it! It actually very likely will need
adapting since it uses "ps" to check the correctness of process
information and the ways to invoke "ps" tends to be different on OSs.

> python setup.py test --all
> running test
> running build
> running build_py
> running build_ext
> compiling helper apps for tests
> Traceback (most recent call last):
> File "setup.py", line 536, in <module>
> cmdclass = COMMANDS)
> File "/usr/local/lib/python2.6/distutils/core.py", line 152, in setup
> dist.run_commands()
> File "/usr/local/lib/python2.6/distutils/dist.py", line 975, in run_commands
> self.run_command(cmd)
> File "/usr/local/lib/python2.6/distutils/dist.py", line 995, in run_command
> cmd_obj.run()
> File "setup.py", line 342, in run
> self.compile_ctests()
> File "setup.py", line 389, in compile_ctests
> sys.exit('Unkown compiler: %s' % cc.compiler)
> NameError: global name 'cc' is not defined

That's a bug in setup.py! But I also think this is from a fairly old
version, could you use the latest version from bitbucket
(http://bitbucket.org/chrismiles/psi) before we try to find out if
this needs adapting for FreeBSD?

Davide Cittaro

unread,
Jan 15, 2010, 3:16:09 PM1/15/10
to psi-d...@googlegroups.com
Hi

On Jan 15, 2010, at 9:11 PM, Floris Bruynooghe wrote:

Sounds like you should be able to use this ki_args to read the
arguments, but only if you have permission to read the process memory.
Maybe the best solution is to try /proc first as that's always
readable (is it?) and fall back to this method if it's not mounted,
but with the gotcha that you need to be able to read the process
memory (the solaris code does something similar, only there /proc
contains a chopped version of the args).

As for .exe, again going by the name, ki_textvp should contain this
info.


Actually it seems I can go with some kvm functions to get those. Hopefully I'll have a working version within the end of january. Today I've got working arch module and most of process module (still not args, cwd, exe...), process table not implemented yet...



That's a bug in setup.py!  But I also think this is from a fairly old
version, could you use the latest version from bitbucket
(http://bitbucket.org/chrismiles/psi) before we try to find out if
this needs adapting for FreeBSD?


I'll try to update next week (or correct 'cc' entry in setuptools...).
d
Reply all
Reply to author
Forward
0 new messages