Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 9 Sep 1998 12:45:31 +0200 (CEST)
From:      Andrzej Bialecki <abial@nask.pl>
To:        freebsd-current@FreeBSD.ORG
Subject:   Adding sysctl, part II
Message-ID:  <Pine.BSF.4.02A.9809091233260.19836-200000@korin.warman.org.pl>

index | next in thread | raw e-mail

[-- Attachment #1 --]
Hi,

Well, I kind of figured out I probably need to use SYSCTL_PROC, and
applied the following patch to machdep.c:

Index: machdep.c
===================================================================
RCS file: /home/ncvs/src/sys/i386/i386/machdep.c,v
retrieving revision 1.307
diff -r1.307 machdep.c
213a214,222
> static int
> sysctl_hw_msgbuf SYSCTL_HANDLER_ARGS
> {
> 	return(sysctl_handle_opaque(oidp,msgbufp,MSGBUF_SIZE,req));
> }
> 
> SYSCTL_PROC(_machdep, OID_AUTO, msgbuf, CTLTYPE_STRUCT|CTLFLAG_RD,
> 	0, 0, sysctl_hw_msgbuf, "S,msgbuf","");
> 

and I wrote a simple program to get the info (attached).

BUT... it returns garbage instead of msbguf contents...

Also, there is yet another problem which I need to solve: with above
sysctl I get only the msgbufp contents, and I need to also know the value
of struct msgbuf in order to know where to start and stop reading.

Any suggestions are appreciated...

Andrzej Bialecki

--------------------   ++-------++  -------------------------------------
 <abial@nask.pl>       ||PicoBSD||   FreeBSD in your pocket? Go and see:
 Research & Academic   |+-------+|       "Small & Embedded FreeBSD"
 Network in Poland     | |TT~~~| |    http://www.freebsd.org/~picobsd/
--------------------   ~-+==---+-+  -------------------------------------

[-- Attachment #2 --]
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/msgbuf.h>
#include <sys/sysctl.h>

int
main(int argc, char *argv[])
{
	int i,len;
	char *mib="machdep.msgbuf";
	u_char *buf;

	i=sysctlbyname(mib,NULL,&len,NULL,NULL);
	if(i<0) {
		perror("sysctl");
		exit(-1);
	}
	fprintf(stderr,"len=%d\n",len);
	buf=(u_char *)calloc(1,len);
	sysctlbyname(mib,buf,&len,NULL,NULL);
	fprintf(stderr,"len=%d\n",len);
	write(1,buf,len);
}
help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.02A.9809091233260.19836-200000>