Re: How to have more than 15 pflog interfaces?

2012-04-11 Thread Siju George
On Thu, Apr 12, 2012 at 3:44 AM, Henning Brauer
 wrote:
>
>
> diffs are for current of course but should work for 5.1 as well -
> dunno what you are trying.
>

Ok thanks :-)
I am running 5.0

--Siju



Re: How to have more than 15 pflog interfaces?

2012-04-11 Thread patrick keshishian
On Wed, Apr 11, 2012 at 3:14 PM, Henning Brauer
 wrote:
> * patrick keshishian  [2012-04-11 14:55]:
>> On Wed, Apr 11, 2012 at 12:20:30PM +0200, Henning Brauer wrote:
>> don't you need two different index vars for this next
>> section?
>
> no, why?

I put the caveat that I am not familiar with the code (and its use).
So apologies if I'm making grave assumptions on the use case (more
below).

>> > +   for (i = 0; i < n; i++)
>> > +   if (i < npflogifs)
>> > +   p[i] = pflogifs[i];
>> > +   else
>> > +   p[i] = NULL;
>
> i think that is pretty clear: each slot in the newly allocated p gets
> the same value as it had in the old pflogifs, once we're at the end of
> pflogifs we set the remaining slots to NULL. unused slots were NULL
> before so just inheriting the NULL is safe.

Unless pflog_clone_destroy() takes out one in the middle of the list.
I probably assumed too much.

>> something like the following with caveats that a) it is
>> 5am-ish for me and b) i did not try compiling it:
>>
>>   for (i = 0, j = 0; i < n; i++, j++) {
>>   for (; j < npflogifs && NULL == pflogifs[j]; j++)
>>   ;
>>   if (j == npflogifs)
>>   break;
>>   p[i] = pflogifs[j];
>>   }
>>   for (; i < n; i++)
>>   p[i] = NULL;
>
> i gave up following this after a bit.

The loop is like yours, but looks out for an NULL-ed out pflogifs
entry (from pflog_clone_destroy()?). If one is detected, adjust index
into pflogifs accordingly.

Now, if it is the case that pflog_clone_destroy() won't ever take out
an entry in the middle of pflogifs, then ignore my comments.

>> > +
>> > +   if(pflogifs)
>>  ^^ nit
>
> fixed
>
>> > s = splnet();
>> > pflogifs[pflogif->sc_unit] = NULL;
>> > LIST_REMOVE(pflogif, sc_list);
>> > +
>> > +   for (i = npflogifs; i > 0 && pflogifs[i - 1] != NULL; i--)
>> > +   ; /* nothing */
>> > +   if (i < npflogifs)
>> > +   pflogifs_resize(i); /* error harmless here */
>>
>> So, if the last pflogifs entry is NULL don't resize
>> down? Not really questioning the logic, but want to
>> make sure I understand that's what is meant, cause
>> there is an easier check for that than the for()-loop.
>> Caveats: a) 5am-ish, b) not familiar with code.
>
> walk the array backwards until we find the first non-empty slot, then
> shrink it to that.

OK. So the _destroy() code will always take out entries from the end
of the pflogifs array.

Sorry for the noise.
--patrick


> --
> Henning Brauer, h...@bsws.de, henn...@openbsd.org
> BS Web Services, http://bsws.de, Full-Service ISP
> Secure Hosting, Mail and DNS Services. Dedicated Servers, Root to Fully
Managed
> Henning Brauer Consulting, http://henningbrauer.com/



Re: How to have more than 15 pflog interfaces?

2012-04-11 Thread Henning Brauer
* patrick keshishian  [2012-04-11 14:55]:
> On Wed, Apr 11, 2012 at 12:20:30PM +0200, Henning Brauer wrote:
> don't you need two different index vars for this next
> section?

no, why?

> > +   for (i = 0; i < n; i++)
> > +   if (i < npflogifs)
> > +   p[i] = pflogifs[i];
> > +   else
> > +   p[i] = NULL;

i think that is pretty clear: each slot in the newly allocated p gets
the same value as it had in the old pflogifs, once we're at the end of
pflogifs we set the remaining slots to NULL. unused slots were NULL
before so just inheriting the NULL is safe.

> something like the following with caveats that a) it is
> 5am-ish for me and b) i did not try compiling it:
> 
>   for (i = 0, j = 0; i < n; i++, j++) {
>   for (; j < npflogifs && NULL == pflogifs[j]; j++)
>   ;
>   if (j == npflogifs)
>   break;
>   p[i] = pflogifs[j];
>   }
>   for (; i < n; i++)
>   p[i] = NULL;

i gave up following this after a bit.

> > +
> > +   if(pflogifs)
>  ^^ nit

fixed

> > s = splnet();
> > pflogifs[pflogif->sc_unit] = NULL;
> > LIST_REMOVE(pflogif, sc_list);
> > +
> > +   for (i = npflogifs; i > 0 && pflogifs[i - 1] != NULL; i--)
> > +   ; /* nothing */
> > +   if (i < npflogifs)
> > +   pflogifs_resize(i); /* error harmless here */
> 
> So, if the last pflogifs entry is NULL don't resize
> down? Not really questioning the logic, but want to
> make sure I understand that's what is meant, cause
> there is an easier check for that than the for()-loop.
> Caveats: a) 5am-ish, b) not familiar with code.

walk the array backwards until we find the first non-empty slot, then
shrink it to that.

-- 
Henning Brauer, h...@bsws.de, henn...@openbsd.org
BS Web Services, http://bsws.de, Full-Service ISP
Secure Hosting, Mail and DNS Services. Dedicated Servers, Root to Fully Managed
Henning Brauer Consulting, http://henningbrauer.com/



Re: How to have more than 15 pflog interfaces?

2012-04-11 Thread Henning Brauer
* Siju George  [2012-04-11 14:25]:
> On Wed, Apr 11, 2012 at 3:50 PM, Henning Brauer  wrote:
> >
> > please try this & report back
> >
> 
> Thanks Henning but I need some help :-(
> 
> I got the following errors and I have attached the .rej files

diffs are for current of course but should work for 5.1 as well -
dunno what you are trying.

-- 
Henning Brauer, h...@bsws.de, henn...@openbsd.org
BS Web Services, http://bsws.de, Full-Service ISP
Secure Hosting, Mail and DNS Services. Dedicated Servers, Root to Fully Managed
Henning Brauer Consulting, http://henningbrauer.com/



top(1) cannot show minus process lines

2012-04-11 Thread Mark Lumsden
Currently if you resize an xterm that top(1) is running in to too few lines
for any processes to be shown and then type 'n' to show X process lines, top
will display a message saying:

 This terminal can only display -Y processes.
 
Obviously a negative number is not quite correct. This diff makes top display:

 This terminal can only display 0 processes.

Perhaps the grammar is not great...but...

ok?

-lum

Index: display.c
===
RCS file: /cvs/src/usr.bin/top/display.c,v
retrieving revision 1.41
diff -u -p -r1.41 display.c
--- display.c   16 Dec 2011 14:50:24 -  1.41
+++ display.c   11 Apr 2012 18:26:44 -
@@ -147,6 +147,9 @@ display_resize(void)
if (display_width >= MAX_COLS)
display_width = MAX_COLS - 1;
 
+   if (display_lines < 0)
+   display_lines = 0;
+
/* return number of lines available */
/* for dumb terminals, pretend like we can show any amount */
return (smart_terminal ? display_lines : Largest);
@@ -196,9 +199,6 @@ display_init(struct statics * statics)
cpustate_total_length += i + 8;
}
}
-
-   if (display_lines < 0)
-   display_lines = 0;
 
/* return number of lines available */
return (display_lines);



move accounting flags from the proc to the process

2012-04-11 Thread Mike Belopuhov
This moves the accounting flag to struct process where it belongs.
The main rationale is that accounting flags are being collected on
the program exit.  Ok?

Index: kern/kern_acct.c
===
RCS file: /cvs/src/sys/kern/kern_acct.c,v
retrieving revision 1.24
diff -u -p -r1.24 kern_acct.c
--- kern/kern_acct.c23 Mar 2012 15:51:26 -  1.24
+++ kern/kern_acct.c11 Apr 2012 17:04:34 -
@@ -224,7 +224,7 @@ acct_process(struct proc *p)
acct.ac_tty = NODEV;
 
/* (8) The boolean flags that tell how the process terminated, etc. */
-   acct.ac_flag = p->p_acflag;
+   acct.ac_flag = pr->ps_acflag;
 
/*
 * Now, just write the accounting information to the file.
Index: kern/kern_exec.c
===
RCS file: /cvs/src/sys/kern/kern_exec.c,v
retrieving revision 1.127
diff -u -p -r1.127 kern_exec.c
--- kern/kern_exec.c26 Mar 2012 04:19:55 -  1.127
+++ kern/kern_exec.c11 Apr 2012 17:04:34 -
@@ -475,7 +475,7 @@ sys_execve(struct proc *p, void *v, regi
bzero(p->p_comm, sizeof(p->p_comm));
len = min(nid.ni_cnd.cn_namelen, MAXCOMLEN);
bcopy(nid.ni_cnd.cn_nameptr, p->p_comm, len);
-   p->p_acflag &= ~AFORK;
+   pr->ps_acflag &= ~AFORK;
 
/* record proc's vnode, for use by procfs and others */
if (p->p_textvp)
Index: kern/kern_fork.c
===
RCS file: /cvs/src/sys/kern/kern_fork.c,v
retrieving revision 1.136
diff -u -p -r1.136 kern_fork.c
--- kern/kern_fork.c10 Apr 2012 15:50:52 -  1.136
+++ kern/kern_fork.c11 Apr 2012 17:04:35 -
@@ -501,7 +501,7 @@ fork1(struct proc *curp, int exitsig, in
 */
SCHED_LOCK(s);
getmicrotime(&pr->ps_start);
-   p->p_acflag = AFORK;
+   pr->ps_acflag = AFORK;
p->p_stat = SRUN;
p->p_cpu = sched_choosecpu_fork(curp, flags);
setrunqueue(p);
Index: kern/kern_sig.c
===
RCS file: /cvs/src/sys/kern/kern_sig.c,v
retrieving revision 1.138
diff -u -p -r1.138 kern_sig.c
--- kern/kern_sig.c 23 Mar 2012 15:51:26 -  1.138
+++ kern/kern_sig.c 11 Apr 2012 17:04:35 -
@@ -1345,7 +1345,7 @@ sigexit(struct proc *p, int signum)
/* Mark process as going away */
atomic_setbits_int(&p->p_flag, P_WEXIT);
 
-   p->p_acflag |= AXSIG;
+   p->p_p->ps_acflag |= AXSIG;
if (sigprop[signum] & SA_CORE) {
p->p_sisig = signum;
 
@@ -1444,7 +1444,7 @@ coredump(struct proc *p)
VATTR_NULL(&vattr);
vattr.va_size = 0;
VOP_SETATTR(vp, &vattr, cred, p);
-   p->p_acflag |= ACORE;
+   p->p_p->ps_acflag |= ACORE;
 
io.io_proc = p;
io.io_vp = vp;
Index: sys/proc.h
===
RCS file: /cvs/src/sys/sys/proc.h,v
retrieving revision 1.154
diff -u -p -r1.154 proc.h
--- sys/proc.h  10 Apr 2012 15:50:52 -  1.154
+++ sys/proc.h  11 Apr 2012 17:04:35 -
@@ -202,6 +202,8 @@ struct process {
u_int   pr_scale;   /* pc scaling */
} ps_prof;
 
+   u_short ps_acflag;  /* Accounting flags. */
+
 /* End area that is copied on creation. */
 #define ps_endcopy ps_refcnt
 
@@ -344,7 +346,6 @@ struct proc {
u_long  p_prof_ticks;   /* temp storage for profiling ticks util AST */
 
u_short p_xstat;/* Exit status for wait; also stop signal. */
-   u_short p_acflag;   /* Accounting flags. */
 };
 
 /* Status values. */
Index: sys/sysctl.h
===
RCS file: /cvs/src/sys/sys/sysctl.h,v
retrieving revision 1.122
diff -u -p -r1.122 sysctl.h
--- sys/sysctl.h10 Apr 2012 15:50:52 -  1.122
+++ sys/sysctl.h11 Apr 2012 17:04:35 -
@@ -519,7 +519,7 @@ do {
\
(kp)->p_nice = (pr)->ps_nice;   \
\
(kp)->p_xstat = (p)->p_xstat;   \
-   (kp)->p_acflag = (p)->p_acflag; \
+   (kp)->p_acflag = (pr)->ps_acflag;   
\
\
/* XXX depends on e_name being an array and not a pointer */\
copy_str((kp)->p_emul, (char *)(p)->p_emul +\



Re: correct suser flag usage

2012-04-11 Thread Philip Guenther
On Wed, 11 Apr 2012, Mike Belopuhov wrote:
> guenther@ has pointed out that sometimes suser is passed an incorrect 
> flags argument.  Currently, there's only one flag that's defined: 
> SUSER_NOACCT (0x1). Unfortunately it aligns too well with AFORK flag 
> used with p_acflag.  This diff cleans up the tree.  OK?

ok guenther@



Re: ps axH per-thread usage times

2012-04-11 Thread Paul Irofti
> From piro...@cvs.openbsd.org Wed Apr 11 08:36:38 2012
> Date: Wed, 11 Apr 2012 08:36:38 -0600 (MDT)
> From: Paul Irofti 
> To: guent...@gmail.com, piro...@cvs.openbsd.org
> Subject: Re: ps axH per-thread usage times
> Cc: tech@openbsd.org
>
> Updated the diff and included the ps(1) and top(1) bits.

Added pkill and documentation bits.


Index: sys/sys/sysctl.h
===
RCS file: /cvs/src/sys/sys/sysctl.h,v
retrieving revision 1.122
diff -u -p -r1.122 sysctl.h
--- sys/sys/sysctl.h10 Apr 2012 15:50:52 -  1.122
+++ sys/sys/sysctl.h11 Apr 2012 16:03:38 -
@@ -466,7 +466,7 @@ struct kinfo_proc {
 
 #define PTRTOINT64(_x) ((u_int64_t)(u_long)(_x))
 
-#define FILL_KPROC(kp, copy_str, p, pr, pc, uc, pg, paddr, praddr, sess, vm, 
lim, sa) \
+#define FILL_KPROC(kp, copy_str, p, pr, pc, uc, pg, paddr, praddr, sess, vm, 
lim, sa, isthread) \
 do {   \
memset((kp), 0, sizeof(*(kp))); \
\
@@ -498,15 +498,24 @@ do {  
\
(kp)->p_jobc = (pg)->pg_jobc;   \
\
(kp)->p_estcpu = (p)->p_estcpu; \
-   (kp)->p_rtime_sec = (pr)->ps_tu.tu_runtime.tv_sec;  \
-   (kp)->p_rtime_usec = (pr)->ps_tu.tu_runtime.tv_usec;\
+   if (isthread) { \
+   (kp)->p_rtime_sec = (p)->p_tu.tu_runtime.tv_sec;\
+   (kp)->p_rtime_usec = (p)->p_tu.tu_runtime.tv_usec;  \
+   (kp)->p_tid = (p)->p_pid + THREAD_PID_OFFSET;   \
+   (kp)->p_uticks = (p)->p_tu.tu_uticks;   \
+   (kp)->p_sticks = (p)->p_tu.tu_sticks;   \
+   (kp)->p_iticks = (p)->p_tu.tu_iticks;   \
+   } else {\
+   (kp)->p_rtime_sec = (pr)->ps_tu.tu_runtime.tv_sec;  \
+   (kp)->p_rtime_usec = (pr)->ps_tu.tu_runtime.tv_usec;\
+   (kp)->p_tid = -1;   \
+   (kp)->p_uticks = (pr)->ps_tu.tu_uticks; \
+   (kp)->p_sticks = (pr)->ps_tu.tu_sticks; \
+   (kp)->p_iticks = (pr)->ps_tu.tu_iticks; \
+   }   \
(kp)->p_cpticks = (p)->p_cpticks;   \
(kp)->p_pctcpu = (p)->p_pctcpu; \
\
-   (kp)->p_uticks = (p)->p_uticks; \
-   (kp)->p_sticks = (p)->p_sticks; \
-   (kp)->p_iticks = (p)->p_iticks; \
-   \
(kp)->p_tracep = PTRTOINT64((pr)->ps_tracevp);  \
(kp)->p_traceflag = (pr)->ps_traceflag; \
\
@@ -587,7 +596,6 @@ do {
\
}   \
\
(kp)->p_cpuid = KI_NOCPU;   \
-   (kp)->p_tid = (p)->p_pid + THREAD_PID_OFFSET;   \
(kp)->p_rtableid = (pr)->ps_rtableid;   \
 } while (0)
 
@@ -933,7 +941,7 @@ int sysctl_dopool(int *, u_int, char *, 
 void fill_file2(struct kinfo_file2 *, struct file *, struct filedesc *,
 int, struct vnode *, struct proc *, struct proc *);
 
-void fill_kproc(struct proc *, struct kinfo_proc *);
+void fill_kproc(struct proc *, struct kinfo_proc *, int);
 
 int kern_sysctl(int *, u_int, void *, size_t *, void *, size_t,
 struct proc *);
Index: sys/kern/kern_sysctl.c
===
RCS file: /cvs/src/sys/kern/kern_sysctl.c,v
retrieving revision 1.219
diff -u -p -r1.219 kern_sysctl.c
--- sys/kern/kern_sysctl.c  10 Apr 2012 15:50:52 -  1.219
+++ sys/kern/kern_sysctl.c  11 Apr 2012 16:03:38 -
@@ -1458,8 +1458,20 @@ again:
goto err;
}
 
+   if ((p->p_flag & P_THREAD) == 0) {
+   if (buflen >= elem_size && elem_count > 0) {
+   fill_kproc(p, kproc, 0);
+   error = copyout(kpr

correct suser flag usage

2012-04-11 Thread Mike Belopuhov
guenther@ has pointed out that sometimes suser is passed an incorrect
flags argument.  Currently, there's only one flag that's defined:
SUSER_NOACCT (0x1). Unfortunately it aligns too well with AFORK flag
used with p_acflag.   This diff cleans up the tree.  OK?


Index: dev/pci/if_san_obsd.c
===
RCS file: /cvs/src/sys/dev/pci/if_san_obsd.c,v
retrieving revision 1.12
diff -u -p -r1.12 if_san_obsd.c
--- dev/pci/if_san_obsd.c   13 May 2006 19:04:30 -  1.12
+++ dev/pci/if_san_obsd.c   11 Apr 2012 15:24:02 -
@@ -244,7 +244,7 @@ wanpipe_generic_ioctl(struct ifnet *ifp,
goto ioctl_out;
 
case SIOCSIFTIMESLOT:
-   if ((err = suser(p, p->p_acflag)) != 0)
+   if ((err = suser(p, 0)) != 0)
goto ioctl_out;
if (card->state != WAN_DISCONNECTED) {
log(LOG_INFO, "%s: Unable to change timeslot map!\n",
@@ -313,14 +313,14 @@ wanpipe_generic_ioctl(struct ifnet *ifp,
 
case IF_PROTO_CISCO:
case IF_PROTO_PPP:
-   if ((err = suser(p, p->p_acflag)) != 0)
+   if ((err = suser(p, 0)) != 0)
goto ioctl_out;
err = wp_lite_set_proto(ifp, (struct ifreq*)data);
break;
 
case IF_IFACE_T1:
case IF_IFACE_E1:
-   if ((err = suser(p, p->p_acflag)) != 0)
+   if ((err = suser(p, 0)) != 0)
goto ioctl_out;
err = wp_lite_set_te1_cfg(ifp, (struct ifreq*)data);
break;
Index: dev/pci/drm/drmP.h
===
RCS file: /cvs/src/sys/dev/pci/drm/drmP.h,v
retrieving revision 1.128
diff -u -p -r1.128 drmP.h
--- dev/pci/drm/drmP.h  2 Jun 2011 18:22:00 -   1.128
+++ dev/pci/drm/drmP.h  11 Apr 2012 15:24:02 -
@@ -99,7 +99,7 @@
 #endif
 
 /* DRM_SUSER returns true if the user is superuser */
-#define DRM_SUSER(p)   (suser(p, p->p_acflag) == 0)
+#define DRM_SUSER(p)   (suser(p, 0) == 0)
 #define DRM_MTRR_WCMDF_WRITECOMBINE
 
 #define PAGE_ALIGN(addr)   (((addr) + PAGE_MASK) & ~PAGE_MASK)
Index: net/if_pflow.c
===
RCS file: /cvs/src/sys/net/if_pflow.c,v
retrieving revision 1.19
diff -u -p -r1.19 if_pflow.c
--- net/if_pflow.c  2 Feb 2012 12:34:37 -   1.19
+++ net/if_pflow.c  11 Apr 2012 15:24:03 -
@@ -345,7 +345,7 @@ pflowioctl(struct ifnet *ifp, u_long cmd
break;
 
case SIOCSETPFLOW:
-   if ((error = suser(p, p->p_acflag)) != 0)
+   if ((error = suser(p, 0)) != 0)
return (error);
if ((error = copyin(ifr->ifr_data, &pflowr,
sizeof(pflowr
Index: net/if_pfsync.c
===
RCS file: /cvs/src/sys/net/if_pfsync.c,v
retrieving revision 1.183
diff -u -p -r1.183 if_pfsync.c
--- net/if_pfsync.c 7 Apr 2012 14:28:45 -   1.183
+++ net/if_pfsync.c 11 Apr 2012 15:24:03 -
@@ -1310,7 +1310,7 @@ pfsyncioctl(struct ifnet *ifp, u_long cm
return (copyout(&pfsyncr, ifr->ifr_data, sizeof(pfsyncr)));
 
case SIOCSETPFSYNC:
-   if ((error = suser(p, p->p_acflag)) != 0)
+   if ((error = suser(p, 0)) != 0)
return (error);
if ((error = copyin(ifr->ifr_data, &pfsyncr, sizeof(pfsyncr
return (error);
Index: net/if_pppoe.c
===
RCS file: /cvs/src/sys/net/if_pppoe.c,v
retrieving revision 1.34
diff -u -p -r1.34 if_pppoe.c
--- net/if_pppoe.c  19 Jan 2012 01:13:20 -  1.34
+++ net/if_pppoe.c  11 Apr 2012 15:24:03 -
@@ -920,8 +920,8 @@ pppoe_ioctl(struct ifnet *ifp, unsigned 
{
struct pppoediscparms *parms = (struct pppoediscparms *)data;
int len;
-   
-   if ((error = suser(p, p->p_acflag)) != 0)
+
+   if ((error = suser(p, 0)) != 0)
return (error);
if (parms->eth_ifname[0] != '\0') {
struct ifnet*eth_if;
Index: netinet/ip_carp.c
===
RCS file: /cvs/src/sys/netinet/ip_carp.c,v
retrieving revision 1.194
diff -u -p -r1.194 ip_carp.c
--- netinet/ip_carp.c   19 Nov 2011 13:54:53 -  1.194
+++ netinet/ip_carp.c   11 Apr 2012 15:24:03 -
@@ -2270,7 +2270,7 @@ carp_ioctl(struct ifnet *ifp, u_long cmd
 
case SIOCSVH:
vhe = LIST_FIRST(&sc->carp_vhosts);
-   if ((error = suser(p, p->p_acflag)) != 0)
+

Re: ps axH per-thread usage times

2012-04-11 Thread Paul Irofti
Updated the diff and included the ps(1) and top(1) bits.


Index: sys/kern/kern_sysctl.c
===
RCS file: /cvs/src/sys/kern/kern_sysctl.c,v
retrieving revision 1.219
diff -u -p -r1.219 kern_sysctl.c
--- sys/kern/kern_sysctl.c  10 Apr 2012 15:50:52 -  1.219
+++ sys/kern/kern_sysctl.c  11 Apr 2012 14:31:14 -
@@ -1458,8 +1458,20 @@ again:
goto err;
}
 
+   if ((p->p_flag & P_THREAD) == 0) {
+   if (buflen >= elem_size && elem_count > 0) {
+   fill_kproc(p, kproc, 0);
+   error = copyout(kproc, dp, elem_size);
+   if (error)
+   goto err;
+   dp += elem_size;
+   buflen -= elem_size;
+   elem_count--;
+   }
+   needed += elem_size;
+   }
if (buflen >= elem_size && elem_count > 0) {
-   fill_kproc(p, kproc);
+   fill_kproc(p, kproc, 1);
error = copyout(kproc, dp, elem_size);
if (error)
goto err;
@@ -1467,7 +1479,6 @@ again:
buflen -= elem_size;
elem_count--;
}
-   needed += elem_size;
}
if (doingzomb == 0) {
p = LIST_FIRST(&zombproc);
@@ -1494,7 +1505,7 @@ err:
  * Fill in a kproc structure for the specified process.
  */
 void
-fill_kproc(struct proc *p, struct kinfo_proc *ki)
+fill_kproc(struct proc *p, struct kinfo_proc *ki, int isthread)
 {
struct process *pr = p->p_p;
struct session *s = pr->ps_session;
@@ -1502,7 +1513,7 @@ fill_kproc(struct proc *p, struct kinfo_
struct timeval ut, st;
 
FILL_KPROC(ki, strlcpy, p, pr, p->p_cred, p->p_ucred, pr->ps_pgrp,
-   p, pr, s, p->p_vmspace, pr->ps_limit, p->p_sigacts);
+   p, pr, s, p->p_vmspace, pr->ps_limit, p->p_sigacts, isthread);
 
/* stuff that's too painful to generalize into the macros */
ki->p_pid = pr->ps_pid;
Index: sys/sys/sysctl.h
===
RCS file: /cvs/src/sys/sys/sysctl.h,v
retrieving revision 1.122
diff -u -p -r1.122 sysctl.h
--- sys/sys/sysctl.h10 Apr 2012 15:50:52 -  1.122
+++ sys/sys/sysctl.h11 Apr 2012 14:31:14 -
@@ -466,7 +466,7 @@ struct kinfo_proc {
 
 #define PTRTOINT64(_x) ((u_int64_t)(u_long)(_x))
 
-#define FILL_KPROC(kp, copy_str, p, pr, pc, uc, pg, paddr, praddr, sess, vm, 
lim, sa) \
+#define FILL_KPROC(kp, copy_str, p, pr, pc, uc, pg, paddr, praddr, sess, vm, 
lim, sa, isthread) \
 do {   \
memset((kp), 0, sizeof(*(kp))); \
\
@@ -498,15 +498,24 @@ do {  
\
(kp)->p_jobc = (pg)->pg_jobc;   \
\
(kp)->p_estcpu = (p)->p_estcpu; \
-   (kp)->p_rtime_sec = (pr)->ps_tu.tu_runtime.tv_sec;  \
-   (kp)->p_rtime_usec = (pr)->ps_tu.tu_runtime.tv_usec;\
+   if ((isthread)) {   \
+   (kp)->p_rtime_sec = (p)->p_tu.tu_runtime.tv_sec;\
+   (kp)->p_rtime_usec = (p)->p_tu.tu_runtime.tv_usec;  \
+   (kp)->p_tid = (p)->p_pid + THREAD_PID_OFFSET;   \
+   (kp)->p_uticks = (p)->p_tu.tu_uticks;   \
+   (kp)->p_sticks = (p)->p_tu.tu_sticks;   \
+   (kp)->p_iticks = (p)->p_tu.tu_iticks;   \
+   } else {\
+   (kp)->p_rtime_sec = (pr)->ps_tu.tu_runtime.tv_sec;  \
+   (kp)->p_rtime_usec = (pr)->ps_tu.tu_runtime.tv_usec;\
+   (kp)->p_tid = -1;   \
+   (kp)->p_uticks = (pr)->ps_tu.tu_uticks; \
+   (kp)->p_sticks = (pr)->ps_tu.tu_sticks; \
+   (kp)->p_iticks = (pr)->ps_tu.tu_iticks; \
+   }   \
(kp)->p_cpticks = (p)->p_cpticks;   \
(kp)->p_pctcpu = (p)->p_pctcpu; \
\
-   (kp)->p_uticks = (p)->p_uticks; \
-   (kp)->p

Re: ps axH per-thread usage times

2012-04-11 Thread Philip Guenther
On Wed, Apr 11, 2012 at 6:37 AM, Paul Irofti  wrote:
> This displayes usage times per thread.
>
> For the main thread it displays the total time (as it did in the past)
> and puts marks the TID as -1.

Chatting about this we've agreed that with the -H flag, ps (and top)
should only show the lines for the threads (and thus hide the TID=-1
line), while without the -H flag it should only show the process line
(and thus hide the TID=-1 lines, *including* the line for the main
thread).  That way, ps w/o -H behaves as expected with one line per
process, while with -H you get exactly one line per thread.

The only caveat is that the usage values for the process are not
*just* the roll-up of the values for the individual threads: if any
threads have exited, their accumulation will be in the process total,
but they'll no longer show in the -H output.  Overall, the output will
probably better match expectations, however.


Philip Guenther



ps axH per-thread usage times

2012-04-11 Thread Paul Irofti
This displayes usage times per thread.

For the main thread it displays the total time (as it did in the past)
and puts marks the TID as -1.

Okay? Should I expand the manpage bits for ps(1)? Currently it says:

.It Fl H
Also display information about kernel visible threads.

EXAMPLE

$ ps axH   
  PID TID TT  STAT   TIME COMMAND
[--snip--]
13449 1026043 p3  I+  0:00.03 firefox
13449 1029081 p3  I+  0:00.03 firefox
13449 1008267 p3  I+  0:00.02 firefox
13449 1021695 p3  I+  0:00.01 firefox
13449  -1 p3  S+  0:04.07 firefox
13449 1013449 p3  S+  0:03.70 firefox
13449 1029858 p3  I+  0:00.00 firefox
13449 1005221 p3  I+  0:00.00 firefox
13449 1022364 p3  I+  0:00.01 firefox
13449 1032468 p3  I+  0:00.03 firefox
13449 1010551 p3  I+  0:00.01 firefox
13449 1016943 p3  I+  0:00.02 firefox
13449 1022871 p3  I+  0:00.02 firefox
13449 1021688 p3  I+  0:00.00 firefox
13449 1028757 p3  I+  0:00.01 firefox
13449 1024286 p3  I+  0:00.01 firefox
13449 1005207 p3  I+  0:00.02 firefox
13449 1021471 p3  S+  0:00.02 firefox
13449 1006822 p3  I+  0:00.04 firefox
13449 1025675 p3  I+  0:00.01 firefox
[--snip--]



Index: sys/sysctl.h
===
RCS file: /cvs/src/sys/sys/sysctl.h,v
retrieving revision 1.122
diff -u -p -r1.122 sysctl.h
--- sys/sysctl.h10 Apr 2012 15:50:52 -  1.122
+++ sys/sysctl.h11 Apr 2012 13:29:04 -
@@ -466,7 +466,7 @@ struct kinfo_proc {
 
 #define PTRTOINT64(_x) ((u_int64_t)(u_long)(_x))
 
-#define FILL_KPROC(kp, copy_str, p, pr, pc, uc, pg, paddr, praddr, sess, vm, 
lim, sa) \
+#define FILL_KPROC(kp, copy_str, p, pr, pc, uc, pg, paddr, praddr, sess, vm, 
lim, sa, isthread) \
 do {   \
memset((kp), 0, sizeof(*(kp))); \
\
@@ -498,8 +498,15 @@ do {   
\
(kp)->p_jobc = (pg)->pg_jobc;   \
\
(kp)->p_estcpu = (p)->p_estcpu; \
-   (kp)->p_rtime_sec = (pr)->ps_tu.tu_runtime.tv_sec;  \
-   (kp)->p_rtime_usec = (pr)->ps_tu.tu_runtime.tv_usec;\
+   if ((isthread)) {   \
+   (kp)->p_rtime_sec = (p)->p_tu.tu_runtime.tv_sec;\
+   (kp)->p_rtime_usec = (p)->p_tu.tu_runtime.tv_usec;  \
+   (kp)->p_tid = (p)->p_pid + THREAD_PID_OFFSET;   \
+   } else {\
+   (kp)->p_rtime_sec = (pr)->ps_tu.tu_runtime.tv_sec;  \
+   (kp)->p_rtime_usec = (pr)->ps_tu.tu_runtime.tv_usec;\
+   (kp)->p_tid = -1;   \
+   }   \
(kp)->p_cpticks = (p)->p_cpticks;   \
(kp)->p_pctcpu = (p)->p_pctcpu; \
\
@@ -587,7 +594,6 @@ do {
\
}   \
\
(kp)->p_cpuid = KI_NOCPU;   \
-   (kp)->p_tid = (p)->p_pid + THREAD_PID_OFFSET;   \
(kp)->p_rtableid = (pr)->ps_rtableid;   \
 } while (0)
 
@@ -933,7 +939,7 @@ int sysctl_dopool(int *, u_int, char *, 
 void fill_file2(struct kinfo_file2 *, struct file *, struct filedesc *,
 int, struct vnode *, struct proc *, struct proc *);
 
-void fill_kproc(struct proc *, struct kinfo_proc *);
+void fill_kproc(struct proc *, struct kinfo_proc *, int);
 
 int kern_sysctl(int *, u_int, void *, size_t *, void *, size_t,
 struct proc *);
Index: kern/kern_sysctl.c
===
RCS file: /cvs/src/sys/kern/kern_sysctl.c,v
retrieving revision 1.219
diff -u -p -r1.219 kern_sysctl.c
--- kern/kern_sysctl.c  10 Apr 2012 15:50:52 -  1.219
+++ kern/kern_sysctl.c  11 Apr 2012 13:29:05 -
@@ -1458,8 +1458,20 @@ again:
goto err;
}
 
+   if ((p->p_flag & P_THREAD) == 0) {
+   if (buflen >= elem_size && elem_count > 0) {
+ 

Re: How to have more than 15 pflog interfaces?

2012-04-11 Thread patrick keshishian
On Wed, Apr 11, 2012 at 12:20:30PM +0200, Henning Brauer wrote:
> * Henning Brauer  [2012-04-11 11:26]:
> > * Siju George  [2012-04-10 08:16]:
> > > On Tue, Apr 10, 2012 at 11:40 AM, Andres Perera  wrote:
> > > > altering the max might have consequences i don't know about:
> > > I will stick with 15 :-)
> > 
> > actually, bumping it should be absolutely safe.
> > 
> > pretty dumb limit actually, we should just dynamically allocate the
> > pflogifs array.
> 
> please try this & report back
> 
> Index: if_pflog.c
> ===
> RCS file: /cvs/src/sys/net/if_pflog.c,v
> retrieving revision 1.49
> diff -u -p -r1.49 if_pflog.c
> --- if_pflog.c3 Feb 2012 01:57:50 -   1.49
> +++ if_pflog.c11 Apr 2012 10:19:56 -
> @@ -80,6 +80,7 @@
>  #endif
>  
>  void pflogattach(int);
> +int  pflogifs_resize(size_t);
>  int  pflogoutput(struct ifnet *, struct mbuf *, struct sockaddr *,
>  struct rtentry *);
>  int  pflogioctl(struct ifnet *, u_long, caddr_t);
> @@ -91,16 +92,14 @@ LIST_HEAD(, pflog_softc)  pflogif_list;
>  struct if_clone  pflog_cloner =
>  IF_CLONE_INITIALIZER("pflog", pflog_clone_create, pflog_clone_destroy);
>  
> -struct ifnet *pflogifs[PFLOGIFS_MAX];/* for fast access */
> -struct mbuf  *pflog_mhdr = NULL, *pflog_mptr = NULL;
> +intnpflogifs = 0;
> +struct ifnet **pflogifs = NULL;  /* for fast access */
> +struct mbuf   *pflog_mhdr = NULL, *pflog_mptr = NULL;
>  
>  void
>  pflogattach(int npflog)
>  {
> - int i;
>   LIST_INIT(&pflogif_list);
> - for (i = 0; i < PFLOGIFS_MAX; i++)
> - pflogifs[i] = NULL;
>   if (pflog_mhdr == NULL)
>   if ((pflog_mhdr = m_get(M_DONTWAIT, MT_HEADER)) == NULL)
>   panic("pflogattach: no mbuf");
> @@ -111,14 +110,41 @@ pflogattach(int npflog)
>  }
>  
>  int
> +pflogifs_resize(size_t n)
> +{
> + struct ifnet**p;
> + int   i;
> +
> + if (n > SIZE_MAX / sizeof(struct ifnet))
> + return (EINVAL);
> + if (n == 0)
> + p = NULL;
> + else
> + if ((p = malloc(n * sizeof(struct ifnet), M_DEVBUF,
> + M_NOWAIT|M_ZERO)) == NULL)
> + return (ENOMEM);

don't you need two different index vars for this next
section?

> + for (i = 0; i < n; i++)
> + if (i < npflogifs)
> + p[i] = pflogifs[i];
> + else
> + p[i] = NULL;

something like the following with caveats that a) it is
5am-ish for me and b) i did not try compiling it:

for (i = 0, j = 0; i < n; i++, j++) {
for (; j < npflogifs && NULL == pflogifs[j]; j++)
;
if (j == npflogifs)
break;
p[i] = pflogifs[j];
}
for (; i < n; i++)
p[i] = NULL;

> +
> + if(pflogifs)
 ^^ nit
> + free(pflogifs, M_DEVBUF);
> + pflogifs = p;
> + npflogifs = n;
> + return (0);
> +}
> +
> +int
>  pflog_clone_create(struct if_clone *ifc, int unit)
>  {
>   struct ifnet *ifp;
>   struct pflog_softc *pflogif;
>   int s;
>  
> - if (unit >= PFLOGIFS_MAX)
> - return (EINVAL);
> + if (unit + 1 > npflogifs && pflogifs_resize(unit + 1) != 0)
> + return (ENOMEM);
>  
>   if ((pflogif = malloc(sizeof(*pflogif),
>   M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL)
> @@ -154,11 +180,16 @@ int
>  pflog_clone_destroy(struct ifnet *ifp)
>  {
>   struct pflog_softc  *pflogif = ifp->if_softc;
> - int  s;
> + int  s, i;
>  
>   s = splnet();
>   pflogifs[pflogif->sc_unit] = NULL;
>   LIST_REMOVE(pflogif, sc_list);
> +
> + for (i = npflogifs; i > 0 && pflogifs[i - 1] != NULL; i--)
> + ; /* nothing */
> + if (i < npflogifs)
> + pflogifs_resize(i); /* error harmless here */

So, if the last pflogifs entry is NULL don't resize
down? Not really questioning the logic, but want to
make sure I understand that's what is meant, cause
there is an easier check for that than the for()-loop.
Caveats: a) 5am-ish, b) not familiar with code.

--patrick

>   splx(s);
>  
>   if_detach(ifp);
> @@ -225,7 +256,8 @@ pflog_packet(struct pf_pdesc *pd, u_int8
>   if (rm == NULL || pd == NULL || pd->kif == NULL || pd->m == NULL)
>   return (-1);
>  
> - if ((ifn = pflogifs[rm->logif]) == NULL || !ifn->if_bpf)
> + if (rm->logif >= npflogifs || (ifn = pflogifs[rm->logif]) == NULL ||
> + !ifn->if_bpf)
>   return (0);
>  
>   bzero(&hdr, sizeof(hdr));
> Index: pf_ioctl.c
> ===
> RCS file: /cvs/src/sys/net/pf_ioctl.c,v
> retrieving revision 1.250
> diff -u -p -r1.250 pf_ioctl.c
> --- pf_ioctl.c3 Apr 2012 15:

Re: How to have more than 15 pflog interfaces?

2012-04-11 Thread Siju George
On Wed, Apr 11, 2012 at 3:50 PM, Henning Brauer  wrote:
>
> please try this & report back
>

Thanks Henning but I need some help :-(

I got the following errors and I have attached the .rej files

=
# patch -p0 < patch.if_pflog
Hmm...  Looks like a unified diff to me...
The text leading up to this was:
--
|Index: if_pflog.c
|===
|RCS file: /cvs/src/sys/net/if_pflog.c,v
|retrieving revision 1.49
|diff -u -p -r1.49 if_pflog.c
|--- if_pflog.c  3 Feb 2012 01:57:50 -   1.49
|+++ if_pflog.c  11 Apr 2012 10:19:56 -
--
File to patch: sys/net/if_pflog.c
Patching file sys/net/if_pflog.c using Plan A...
Hunk #1 failed at 80.
Hunk #2 failed at 92.
Hunk #3 failed at 110.
Hunk #4 failed at 180.
Hunk #5 failed at 256.
5 out of 5 hunks failed--saving rejects to sys/net/if_pflog.c.rej
Hmm...  The next patch looks like a unified diff to me...
The text leading up to this was:
--
|Index: pf_ioctl.c
|===
|RCS file: /cvs/src/sys/net/pf_ioctl.c,v
|retrieving revision 1.250
|diff -u -p -r1.250 pf_ioctl.c
|--- pf_ioctl.c  3 Apr 2012 15:09:03 -   1.250
|+++ pf_ioctl.c  11 Apr 2012 10:19:57 -
--
File to patch: sys/net/pf_ioctl.c
Patching file sys/net/pf_ioctl.c using Plan A...
Hunk #1 failed at 2595.
1 out of 1 hunks failed--saving rejects to sys/net/pf_ioctl.c.rej
done
===

Thanks

Siju

[demime 1.01d removed an attachment of type application/octet-stream which had 
a name of if_pflog.c.rej]

[demime 1.01d removed an attachment of type application/octet-stream which had 
a name of pf_ioctl.c.rej]



Quel type de cible utilisez-vous ?

2012-04-11 Thread Stephane
Un moyen efficace : cibler juste !

Avec ` nos envois 100% ciblis,
vous atteignez directement votre coeur de cible !

Utilisez nos packs : "TOUT BUDGET"

Consultez nos offres

visualisez nos offres

Quel type de ciblage utiliser ?

Tous ces crithres sont disponibles avec nos packs :

- Secteur d'activiti / ptle
- Secteur giographique / Giomarketing
- Chiffre d'affaires
- Effectif
- Annie de criation de l'entreprise
- Fichiers de comportement
- Ciblage par ichantillon, ciblages test

logo

Un renseignement ?

I M A P L U S

(*) FORFAIT valable pendant 10 jours*

Allez sur notre site

[IMAGE]

[IMAGE]

[IMAGE]

[IMAGE]

[IMAGE]

Envoyez ce message ` un ami
Pour jtre retiri de nos listes c'est ici
serial : 518094782[IMAGE]



Re: How to have more than 15 pflog interfaces?

2012-04-11 Thread Henning Brauer
* Henning Brauer  [2012-04-11 11:26]:
> * Siju George  [2012-04-10 08:16]:
> > On Tue, Apr 10, 2012 at 11:40 AM, Andres Perera  wrote:
> > > altering the max might have consequences i don't know about:
> > I will stick with 15 :-)
> 
> actually, bumping it should be absolutely safe.
> 
> pretty dumb limit actually, we should just dynamically allocate the
> pflogifs array.

please try this & report back

Index: if_pflog.c
===
RCS file: /cvs/src/sys/net/if_pflog.c,v
retrieving revision 1.49
diff -u -p -r1.49 if_pflog.c
--- if_pflog.c  3 Feb 2012 01:57:50 -   1.49
+++ if_pflog.c  11 Apr 2012 10:19:56 -
@@ -80,6 +80,7 @@
 #endif
 
 void   pflogattach(int);
+intpflogifs_resize(size_t);
 intpflogoutput(struct ifnet *, struct mbuf *, struct sockaddr *,
   struct rtentry *);
 intpflogioctl(struct ifnet *, u_long, caddr_t);
@@ -91,16 +92,14 @@ LIST_HEAD(, pflog_softc)pflogif_list;
 struct if_clonepflog_cloner =
 IF_CLONE_INITIALIZER("pflog", pflog_clone_create, pflog_clone_destroy);
 
-struct ifnet   *pflogifs[PFLOGIFS_MAX];/* for fast access */
-struct mbuf*pflog_mhdr = NULL, *pflog_mptr = NULL;
+int  npflogifs = 0;
+struct ifnet   **pflogifs = NULL;  /* for fast access */
+struct mbuf *pflog_mhdr = NULL, *pflog_mptr = NULL;
 
 void
 pflogattach(int npflog)
 {
-   int i;
LIST_INIT(&pflogif_list);
-   for (i = 0; i < PFLOGIFS_MAX; i++)
-   pflogifs[i] = NULL;
if (pflog_mhdr == NULL)
if ((pflog_mhdr = m_get(M_DONTWAIT, MT_HEADER)) == NULL)
panic("pflogattach: no mbuf");
@@ -111,14 +110,41 @@ pflogattach(int npflog)
 }
 
 int
+pflogifs_resize(size_t n)
+{
+   struct ifnet**p;
+   int   i;
+
+   if (n > SIZE_MAX / sizeof(struct ifnet))
+   return (EINVAL);
+   if (n == 0)
+   p = NULL;
+   else
+   if ((p = malloc(n * sizeof(struct ifnet), M_DEVBUF,
+   M_NOWAIT|M_ZERO)) == NULL)
+   return (ENOMEM);
+   for (i = 0; i < n; i++)
+   if (i < npflogifs)
+   p[i] = pflogifs[i];
+   else
+   p[i] = NULL;
+
+   if(pflogifs)
+   free(pflogifs, M_DEVBUF);
+   pflogifs = p;
+   npflogifs = n;
+   return (0);
+}
+
+int
 pflog_clone_create(struct if_clone *ifc, int unit)
 {
struct ifnet *ifp;
struct pflog_softc *pflogif;
int s;
 
-   if (unit >= PFLOGIFS_MAX)
-   return (EINVAL);
+   if (unit + 1 > npflogifs && pflogifs_resize(unit + 1) != 0)
+   return (ENOMEM);
 
if ((pflogif = malloc(sizeof(*pflogif),
M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL)
@@ -154,11 +180,16 @@ int
 pflog_clone_destroy(struct ifnet *ifp)
 {
struct pflog_softc  *pflogif = ifp->if_softc;
-   int  s;
+   int  s, i;
 
s = splnet();
pflogifs[pflogif->sc_unit] = NULL;
LIST_REMOVE(pflogif, sc_list);
+
+   for (i = npflogifs; i > 0 && pflogifs[i - 1] != NULL; i--)
+   ; /* nothing */
+   if (i < npflogifs)
+   pflogifs_resize(i); /* error harmless here */
splx(s);
 
if_detach(ifp);
@@ -225,7 +256,8 @@ pflog_packet(struct pf_pdesc *pd, u_int8
if (rm == NULL || pd == NULL || pd->kif == NULL || pd->m == NULL)
return (-1);
 
-   if ((ifn = pflogifs[rm->logif]) == NULL || !ifn->if_bpf)
+   if (rm->logif >= npflogifs || (ifn = pflogifs[rm->logif]) == NULL ||
+   !ifn->if_bpf)
return (0);
 
bzero(&hdr, sizeof(hdr));
Index: pf_ioctl.c
===
RCS file: /cvs/src/sys/net/pf_ioctl.c,v
retrieving revision 1.250
diff -u -p -r1.250 pf_ioctl.c
--- pf_ioctl.c  3 Apr 2012 15:09:03 -   1.250
+++ pf_ioctl.c  11 Apr 2012 10:19:57 -
@@ -2595,8 +2595,6 @@ pf_rule_copyin(struct pf_rule *from, str
 #if NPFLOG > 0
if (!to->log)
to->logif = 0;
-   if (to->logif >= PFLOGIFS_MAX)
-   return (EINVAL);
 #endif
to->quick = from->quick;
to->ifnot = from->ifnot;

-- 
Henning Brauer, h...@bsws.de, henn...@openbsd.org
BS Web Services, http://bsws.de, Full-Service ISP
Secure Hosting, Mail and DNS Services. Dedicated Servers, Root to Fully Managed
Henning Brauer Consulting, http://henningbrauer.com/