From owner-freebsd-hackers@FreeBSD.ORG Tue Jan 22 21:57:38 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 1B136C78; Tue, 22 Jan 2013 21:57:38 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (bigknife-pt.tunnel.tserv9.chi1.ipv6.he.net [IPv6:2001:470:1f10:75::2]) by mx1.freebsd.org (Postfix) with ESMTP id EC0678D7; Tue, 22 Jan 2013 21:57:37 +0000 (UTC) Received: from pakbsde14.localnet (unknown [38.105.238.108]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 4EF31B96E; Tue, 22 Jan 2013 16:57:37 -0500 (EST) From: John Baldwin To: Mikolaj Golub Subject: Re: libprocstat(3): retrieve process command line args and environment Date: Tue, 22 Jan 2013 16:48:50 -0500 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110714-p22; KDE/4.5.5; amd64; ; ) References: <20130119151253.GB88025@gmail.com> <201301221201.06290.jhb@freebsd.org> <20130122211743.GA4490@gmail.com> In-Reply-To: <20130122211743.GA4490@gmail.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201301221648.50747.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Tue, 22 Jan 2013 16:57:37 -0500 (EST) Cc: Stanislav Sedov , freebsd-hackers@freebsd.org, Robert Watson X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Jan 2013 21:57:38 -0000 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