From owner-freebsd-questions@FreeBSD.ORG Mon Mar 14 15:03:36 2011 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 44F0B1065670 for ; Mon, 14 Mar 2011 15:03:36 +0000 (UTC) (envelope-from smithi@nimnet.asn.au) Received: from sola.nimnet.asn.au (paqi.nimnet.asn.au [115.70.110.159]) by mx1.freebsd.org (Postfix) with ESMTP id 970F08FC12 for ; Mon, 14 Mar 2011 15:03:35 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by sola.nimnet.asn.au (8.14.2/8.14.2) with ESMTP id p2EF3Waj019339; Tue, 15 Mar 2011 02:03:33 +1100 (EST) (envelope-from smithi@nimnet.asn.au) Date: Tue, 15 Mar 2011 02:03:32 +1100 (EST) From: Ian Smith To: perryh@pluto.rain.com In-Reply-To: <20110314120040.18EF61065838@hub.freebsd.org> Message-ID: <20110315001045.G36648@sola.nimnet.asn.au> References: <20110314120040.18EF61065838@hub.freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Cc: freebsd-questions@freebsd.org Subject: Re: logging to dmesg from userland X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Mar 2011 15:03:36 -0000 In freebsd-questions Digest, Vol 354, Issue 1, Message: 15 On Sun, 13 Mar 2011 19:08:20 -0700 perryh@pluto.rain.com wrote: > I am looking for a way to write into the kernel message buffer -- > the one that dmesg prints out -- from a userland program, to help > in relating kernel printf messages to the userland operations which > provoked them. (Yes, I am aware of the potential DoS implications: > the capability should be restricted to root, or at least to the > "operator" group. I expect to use it only in single-user mode.) Perry, interesting to see that unprivileged users can use logger to spam /var/log/messages (by default), on 5.5 and 7.4-PRE anyway. I've long assumed that I could do that just because I'm in wheel, but not so. > Is there a program, or a system call, which can do this? logger(1) > seemed a likely prospect, but either it doesn't have this capability > or I haven't found the formula. Had a bit of a play around earlier, and as an unprivileged user can do: %who am i subs ttyv6 Mar 14 18:06 %id -p uid subs groups subs %logger -p kern.notice hello from subs at kern.notice %logger -p kern.crit hello from subs at kern.crit logger(1) without -p writes to user.notice, which writes only to /var/log/messages (with standardish syslog.conf settings), but of the two above, only the latter one to kern.crit wound up in 'dmesg -a' sola# dmesg | grep subs sola# dmesg -a | grep subs Mar 15 00:07:35 sola subs: hello from subs at kern.crit Mar 15 00:07:35 sola subs: hello from subs at kern.crit but twice! Both appear in /var/log/messages, one of each, but only the latter also appeared - again twice - in /var/log/console.log .. not sure why twice, but syslog.conf can be tricky .. anyway, later trying other kern.levels: %logger -p kern.err hello from subs at kern.err %logger -p kern.alert hello from subs at kern.alert %logger -p kern.warning hello from subs at kern.warning All three go to messages, but just these two added to dmesg -a output: Mar 15 00:44:54 sola subs: hello from subs at kern.err Mar 15 00:45:37 sola subs: hello from subs at kern.alert Moreover on my 7.4 system I tested also with kern.emerg, which indeed sent the emerg message to all open consoles, including root's! Other kern. levels may work too, as may other facilities? and YMMV. Colour me very surprised not having to be root to do any of those, especially those that do write to the kernel message buffer .. cheers, Ian