Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 17 Mar 2013 11:19:32 +0200
From:      Mikolaj Golub <trociny@FreeBSD.org>
To:        Konstantin Belousov <kostikbel@gmail.com>
Cc:        Stanislav Sedov <stas@freebsd.org>, Attilio Rao <attilio@freebsd.org>, "Robert N. M. Watson" <rwatson@freebsd.org>, freebsd-hackers@freebsd.org
Subject:   Re: libprocstat(3): retrieve process command line args and environment
Message-ID:  <20130317091930.GA2833@gmail.com>
In-Reply-To: <20130317063033.GL3794@kib.kiev.ua>
References:  <20130119151253.GB88025@gmail.com> <201301251531.43540.jhb@freebsd.org> <20130212215054.GA9839@gmail.com> <201302200904.15324.jhb@freebsd.org> <20130220195801.GA8679@gmail.com> <20130316180915.GA91146@gmail.com> <20130316191605.GJ3794@kib.kiev.ua> <20130316223339.GA3534@gmail.com> <20130317063033.GL3794@kib.kiev.ua>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Mar 17, 2013 at 08:30:33AM +0200, Konstantin Belousov wrote:
> On Sun, Mar 17, 2013 at 12:35:20AM +0200, Mikolaj Golub wrote:
> > A KPI that would be natural for my case: 
> > 
> >   /* start a section that is going to be aligned to sizeof(Elf_Size),
> >      using byte '0' for padding */
> >   sbuf_padded_start(sb, sizeof(Elf_Size), 0);
> >   /* write something to sbuf */
> >   sbuf_bcat(sb, data, len);
> >   /* align the sbuf section */
> >   sbuf_pad(sb);
> > 
> > This might look a little awkward and would add some overhead for the normal
> > case though...
> This looks fine, in fact. You might want to call it sbuf_start_section()
> and sbuf_end_section() ?

Ok, will try this way. Thanks.

...

> All you need is to reset req->oldidx. This could be done outside the
> sbuf interface, in the top level function implementing the sysctl ?

I am afraid at this level I don't know a value to reset req->oldidx
to. Reseting it to 0 I think is not a good solution?

> What you propose in the follow-up message should work too, I do not
> have any preference.

Ok. Thanks.

> > > Indents after the else clauses in kern_proc_out() are wrong.
> > 
> > Do you mean indents after '#ifdef COMPAT_FREEBSD32' block? I did it
> > that way so if COMPAT_FREEBSD32 sections were removed from the code
> > the indentation would be correct. I saw this practice through the code
> > and used it myself before.
> The sections are not going to be removed. IMHO code should be formatted
> as if the preprocessor directive lines are not present. Could you point
> out an example of existing code consistent with your indentation ?

In kern/kern_proc.c my code (get_proc_vector, sysctl_kern_proc_auxv)
has such indentation. There were no objection when I introduced it, so
I thought it was a right way. But surely I didn't invented such
indentation myself. I don't recall if I used some particular examples
as a reference then, but here are several examples of such indentation
found by quick grep:

net/bpf.c-#ifdef BPF_JITTER
net/bpf.c-              bf = bpf_jitter_enable != 0 ? d->bd_bfilter : NULL;
net/bpf.c-              if (bf != NULL)
net/bpf.c-                      slen = (*(bf->func))(pkt, pktlen, pktlen);
net/bpf.c-              else
net/bpf.c:#endif
net/bpf.c-              slen = bpf_filter(d->bd_rfilter, pkt, pktlen, pktlen);

kern/kern_conf.c-#if 0
kern/kern_conf.c-       if (dev->si_usecount == 0 &&
kern/kern_conf.c-           (dev->si_flags & SI_CHEAPCLONE) && (dev->si_flags & SI_NAMED))
kern/kern_conf.c-               ;
kern/kern_conf.c-       else 
kern/kern_conf.c:#endif
kern/kern_conf.c-       if (dev->si_devsw == NULL && dev->si_refcount == 0) {

kern/kern_jail.c-       if (SV_PROC_FLAG(td->td_proc, SV_ILP32)) {
kern/kern_jail.c-               uint32_t hid32 = pr->pr_hostid;
kern/kern_jail.c-
kern/kern_jail.c-               error = vfs_setopt(opts, "host.hostid", &hid32, sizeof(hid32));
kern/kern_jail.c-       } else
kern/kern_jail.c:#endif
kern/kern_jail.c-       error = vfs_setopt(opts, "host.hostid", &pr->pr_hostid,

netinet6/raw_ip6.c-             /* Do not inject data into pcb. */
netinet6/raw_ip6.c-             INP_RUNLOCK(last);
netinet6/raw_ip6.c-     } else
netinet6/raw_ip6.c:#endif /* IPSEC */
netinet6/raw_ip6.c-     if (last != NULL) {
netinet6/raw_ip6.c-             if (last->inp_flags & INP_CONTROLOPTS ||

On the other hand there are many examples where indentation is used in
the way you prefer. I don't have any strong opinion about this so I
will do in the way you suggest.

-- 
Mikolaj Golub



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