From owner-freebsd-hackers@FreeBSD.ORG Mon Dec 19 01:15:57 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 37C11106564A for ; Mon, 19 Dec 2011 01:15:57 +0000 (UTC) (envelope-from mdf356@gmail.com) Received: from mail-pz0-f54.google.com (mail-pz0-f54.google.com [209.85.210.54]) by mx1.freebsd.org (Postfix) with ESMTP id 0631C8FC0C for ; Mon, 19 Dec 2011 01:15:56 +0000 (UTC) Received: by dakp5 with SMTP id p5so4873828dak.13 for ; Sun, 18 Dec 2011 17:15:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=f7BDuXu657zdbY1Tk7OMCXbtCW+mRT++URmGWsGMAhQ=; b=l9v32RGv7U7M8mNrC8WCrNfJQD7C7pagFU41VNLONhwpSFqdKMZHfHkRbEf4Da7CnK +3o2Jm9CSBngU177u6a3ugdZaKx6Mo3mmzi6PKvq98z2J+gvnT2ZgRy25CtaiQZfmR75 R5uZ26iM88LifAjPRQlGVGGH8TlPqjyGwc2O0= MIME-Version: 1.0 Received: by 10.68.191.70 with SMTP id gw6mr35230679pbc.85.1324257356477; Sun, 18 Dec 2011 17:15:56 -0800 (PST) Sender: mdf356@gmail.com Received: by 10.68.197.198 with HTTP; Sun, 18 Dec 2011 17:15:56 -0800 (PST) In-Reply-To: References: <4EEE5763.6010509@freebsd.org> Date: Sun, 18 Dec 2011 17:15:56 -0800 X-Google-Sender-Auth: Bd5ZlXUEpkAno-siSjyU4k5xVSE Message-ID: From: mdf@FreeBSD.org To: =?ISO-8859-1?Q?Fernando_Apestegu=EDa?= Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: FreeBSD Hackers Subject: Re: sysctl variable question X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Dec 2011 01:15:57 -0000 2011/12/18 Fernando Apestegu=EDa : > El 18/12/2011 22:12, "Julian Elischer" 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= "