Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 9 Jul 2014 21:06:31 +1000 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Bruce Evans <brde@optusnet.com.au>
Cc:        arch@freebsd.org, Bryan Drewery <bdrewery@freebsd.org>
Subject:   Re: sys/proc.h inclusion of sys/time.h
Message-ID:  <20140709205126.V1201@besplex.bde.org>
In-Reply-To: <20140709201148.W1201@besplex.bde.org>
References:  <53BC4F49.7000903@FreeBSD.org> <20140709201148.W1201@besplex.bde.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 9 Jul 2014, Bruce Evans wrote:

> On Tue, 8 Jul 2014, Bryan Drewery wrote:
>
>> In r34924 sys/proc.h was changed to only include sys/time.h if not building 
>> in kernel.
> ...
>> struct proc {
>> ..
>> struct itimerval p_realtimer;   /* (c) Alarm timer. */
>> 
>> This manifests when (hackishly) including sys/proc.h with _KERNEL defined:
>> 
>>> In file included from 
>>> /root/svn/base/usr.sbin/tcpdump/tcpdump/../../../contrib/tcpdump/print-pflog.c:37:
>>> /usr/include/sys/proc.h:524:19: error: field has incomplete type 'struct 
>>> itimerval'
>>>         struct itimerval p_realtimer;   /* (c) Alarm timer. */
>> 
>> (Why am I doing this? I need PID_MAX and NO_PID for a tcpdump change I am 
>> testing that is intended for upstreaming. Perhaps I can use kern.pid_max in 
>> __FreeBSD__ and other hacks on other platforms, I have not yet decided on 
>> this.)
>
> Ah, you were chummy with the implementation, but not chummy enough to
> know all the details of the kernel environment that must be duplicated
> to use the hack of defining _KERNEL.  It seems to be necessary to include
> sys/param.h and define _KERNEL before that.  There may be collateral
> pollution and further chumminess to avoid problems with it.

PS: in some old cleanups, proc.h caused similar problems but I was
able to avoid them by not including it at all.  It is less needed for
abuse outside the kernel than most kernel headers.

% diff -u2 ./kvm.c~ ./kvm.c
% --- ./kvm.c~	Wed Jun  9 06:13:50 2004
% +++ ./kvm.c	Wed Jun  9 06:13:51 2004
% @@ -46,10 +46,10 @@
% 
%  #include <sys/param.h>
% -#include <sys/user.h>
% -#include <sys/proc.h>

These cleanups are mainly to combine with ones for sys/user.h.  Here I
mainly just wanted to sort it. but sys/proc.h dependend on the sys/time.h
pollution in it.

% +#include <sys/errno.h>
%  #include <sys/ioctl.h>
% +#include <sys/linker.h>
%  #include <sys/stat.h>
%  #include <sys/sysctl.h>
% -#include <sys/linker.h>
% +#include <sys/user.h>
% 
%  #include <vm/vm.h>
% diff -u2 ./kvm_file.c~ ./kvm_file.c
% --- ./kvm_file.c~	Fri Aug  1 21:47:20 2003
% +++ ./kvm_file.c	Fri Aug  1 21:47:53 2003
% @@ -48,23 +48,14 @@
%   */
% 
% -#include <sys/param.h>
% -#include <sys/user.h>
% -#include <sys/proc.h>
% +#include <sys/types.h>
%  #define _KERNEL
%  #include <sys/file.h>
%  #undef _KERNEL

sys/param.h turns out to be mustly unnecessary here.  Defining _KERNEL
before including it was not needed partly because including it at all
is not needed, except possibly for other things that are not needed.

% -#include <sys/stat.h>
% -#include <sys/ioctl.h>
% -#include <nlist.h>
% -#include <kvm.h>
% -
% -#include <vm/vm.h>
% -#include <vm/vm_param.h>
% -
%  #include <sys/sysctl.h>
% 
% +#include <kvm.h>
%  #include <limits.h>
% -#include <ndbm.h>
% -#include <paths.h>
% +#include <nlist.h>
% +#include <stddef.h>
% 
%  #include "kvm_private.h"
% diff -u2 ./kvm_i386.c~ ./kvm_i386.c
% --- ./kvm_i386.c~	Thu Oct 11 20:18:31 2001
% +++ ./kvm_i386.c	Sun Sep  8 01:05:29 2002
% @@ -52,5 +52,4 @@
%  #include <sys/param.h>
%  #include <sys/user.h>
% -#include <sys/proc.h>
%  #include <sys/stat.h>
%  #include <stdlib.h>
% @@ -60,4 +59,5 @@
% 
%  #include <vm/vm.h>
% +#include <vm/pmap.h>
%  #include <vm/vm_param.h>
%

PS2: grepping for PID_MAX shows that ps used to use BSD_PID_MAX (defined
as 99999.  That was supposed to be a copy of the kernel PID_MAX, perhaps
to avoid the namespace problem.  It now uses kern.pid_max with a
fallback to 99999.

Bruce



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