Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 Jan 2013 16:48:50 -0500
From:      John Baldwin <jhb@freebsd.org>
To:        Mikolaj Golub <trociny@freebsd.org>
Cc:        Stanislav Sedov <stas@freebsd.org>, freebsd-hackers@freebsd.org, Robert Watson <rwatson@freebsd.org>
Subject:   Re: libprocstat(3): retrieve process command line args and environment
Message-ID:  <201301221648.50747.jhb@freebsd.org>
In-Reply-To: <20130122211743.GA4490@gmail.com>
References:  <20130119151253.GB88025@gmail.com> <201301221201.06290.jhb@freebsd.org> <20130122211743.GA4490@gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tuesday, January 22, 2013 4:17:43 pm Mikolaj Golub wrote:
> On Tue, Jan 22, 2013 at 12:01:06PM -0500, John Baldwin wrote:
> 
> > How is this different from kvm_getargv()?  It seems to be a direct copy.
> 
> libprocstat(3) is a frontend for sysctl(3) and kvm(3) interfaces, so
> it is good to extend it to cover "getarg/env" functionality.
> 
> Yes the functions look similar to kvm_getargv() but I couldn't
> implement them just as wrappers around kvm_getargv(): I would like to
> have libprocstat functions thread safe, while kvm_getargv() uses
> static variables for its internal buffers.
> 
> It looks like I could fix kvm_getargv() to use fields of kvm structure
> instead of static variables to store pointers to the buffers, and then
> use it in libprocstat(3). Do you think it is worth doing?
> 
> BTW, struct __kvm already contains some pointers, which looks like are
> unused currently:
> 
>   char    **argv;         /* (dynamic) storage for argv pointers */
>   int     argc;           /* length of above (not actual # present) */
>   char    *argbuf;        /* (dynamic) temporary storage */
> 
> But if I even had kvm_getargv() to behave as I wanted, there is still
> an issue with using it in libprocstat(): to get kvm structure you need
> to initialize procstat using procstat_open_kvm(). It is supposed to
> call procstat_open_kvm() when you want to read from kernel memory,
> while kvm_getargv() uses sysctl. So from a user point of you it would
> be a litle confusing if she had to call procstat_open_kvm() to get
> runtime args and env. If she wanted e.g. to get both runtime args and
> file info (via sysctl) she would have to do procstat_open_kvm() for
> args and procstat_open_sysctl() for files.

Well, you could make procstat open a kvm handle in both cases (open a "live" 
handle in the procstat_open_sysctl() case).  It just seems rather silly to be 
duplicating code in the two interfaces.  More a question for Robert: does 
libprocstat intentionally duplicate the code in libkvm for other things as 
well in the live case?  (Like fetching the list of processes?)

-- 
John Baldwin



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201301221648.50747.jhb>