Date: Sun, 18 Dec 2011 17:15:56 -0800 From: mdf@FreeBSD.org To: =?ISO-8859-1?Q?Fernando_Apestegu=EDa?= <fernando.apesteguia@gmail.com> Cc: FreeBSD Hackers <freebsd-hackers@freebsd.org> Subject: Re: sysctl variable question Message-ID: <CAMBSHm-o3TjnvJ6bHP81Q9tGT5oGScsQ2mZD_ncUn3z_j=KZRQ@mail.gmail.com> In-Reply-To: <CAGwOe2YSvWAnux016EYCGkjFtmjpbD9caCP7GKd0Wq5tcb7RJw@mail.gmail.com> References: <CAGwOe2bxBLHFcMzVygcaQjLrHsxFuccs9CHZoP30PC%2BDoORCdQ@mail.gmail.com> <4EEE5763.6010509@freebsd.org> <CAGwOe2YSvWAnux016EYCGkjFtmjpbD9caCP7GKd0Wq5tcb7RJw@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
2011/12/18 Fernando Apestegu=EDa <fernando.apesteguia@gmail.com>: > El 18/12/2011 22:12, "Julian Elischer" <julian@freebsd.org> escribi=F3: >> >> On 12/18/11 12:18 PM, Fernando Apestegu=EDa wrote: >>> >>> Hi all, >>> >>> I'm writing a small module just for fun. I would like to have two > variables: >>> >>> - "pid" of type unsigned int and RW so the user can set a pid >>> - "process_name" as a string RD that will display the process name >>> associated to that pid (or a message if the pid doesn't exist anymore) >> >> >> this is dangerous as there are some places in the kernel where processes >> are referenced by pid, so changing it may break kernel assumptions. > > Sorry, i think i didn't explain it clearly. The "pid" variable is static = in > my module and it is used just to tell the module which information it > should show in the other variable. Many sysctl handlers look for a req->newptr and leave early if it's NULL. If it's non-NULL then you can use SYSCTL_IN to fetch the data. Note that a caller of sysctl(3) API can specify both old pointer and new pointer, which is why most handlers always do a SYSCTL_OUT on the current value. Cheers, matthew >>> My problem is with the handler functions. For "process_name", as it is >>> read only, I wrote a simple handler that works fine. However, I want >>> to write another one for "pid" so I can sanitize the input (avoiding >>> pids< =A00 and so). As I understand, the handler I specify with >>> SYSCTL_OID will be called for both reads and writes. But, how can I >>> tell what kind of operation is it, so I know if I have to use >>> SYSCTL_OUT or SYSCTL_IN? I tried to have a look at sysctl_handle_int >>> but I don't fully understand what is going on with the arg1 parameter. >>> What is it for? >>> >>> Thanks in advance. >>> _______________________________________________ >>> freebsd-hackers@freebsd.org mailing list >>> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers >>> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.o= rg > " >>> >> > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org= "
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAMBSHm-o3TjnvJ6bHP81Q9tGT5oGScsQ2mZD_ncUn3z_j=KZRQ>