DragonFly BSD
DragonFly submit List (threaded) for 2003-11
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: kern.file weirdness


From: YONETANI Tomokazu <qhwt@xxxxxxxxxxxxx>
Date: Mon, 24 Nov 2003 17:08:49 +0900

On Sun, Nov 23, 2003 at 11:56:30PM -0800, Matthew Dillon wrote:
> 
> :FreeBSD-current's version of sockstat has a block of code
> :which looks like this:
> :
> :static void
> :getfiles(void)
> :{
> :	size_t len;
> :
> :	if ((xfiles = malloc(len = sizeof *xfiles)) == NULL)
> :		err(1, "malloc()");
> :	while (sysctlbyname("kern.file", xfiles, &len, 0, 0) == -1) {
> :		if (errno != ENOMEM)
> :			err(1, "sysctlbyname()");
> :		len *= 2;
> :		if ((xfiles = realloc(xfiles, len)) == NULL)
> :			err(1, "realloc()");
> :	}
> :	if (len > 0 && xfiles->xf_size != sizeof *xfiles)
> :		errx(1, "struct xfile size mismatch");
> :	nxfiles = len / sizeof *xfiles;
> :}
> :
> :i.e., you must resize the buffer until sysctlbyname() fails with
> :ENOMEM.
> :
> :Cheers.
> 
>     I think you meant 'resize the buffer until sysctlbyname()
>     stops failing with ENOMEM'.

*Blush* Yes, that was what I meant say. Thanks for the correction.



[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]