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: Matthew Dillon <dillon@xxxxxxxxxxxxxxxxxxxx>
Date: Sun, 23 Nov 2003 23:56:30 -0800 (PST)

: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'.

					-Matt
					Matthew Dillon 
					<dillon@xxxxxxxxxxxxx>



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