From owner-freebsd-current@FreeBSD.ORG Fri Mar 27 03:22:11 2015 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id DB925A52 for ; Fri, 27 Mar 2015 03:22:11 +0000 (UTC) Received: from sasl.smtp.pobox.com (pb-smtp1.int.icgroup.com [208.72.237.35]) by mx1.freebsd.org (Postfix) with ESMTP id A8ED28EB for ; Fri, 27 Mar 2015 03:22:11 +0000 (UTC) Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id E042C44A28 for ; Thu, 26 Mar 2015 23:20:20 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=message-id :date:from:mime-version:to:subject:content-type; s=sasl; bh=15ZA dsSSRjr8/yMdQFTR+rSirTg=; b=kMq/QiM0cb5hjh9KM9qVdCKlTyzCpf1onrbS Xp1KQwtcDDQIq5FaoZg4HKBXu9zt1r6r2MXVFmqQqczKAXExDWt8QfC26EuzJLtV w+X34qVRB1toitfeZIxDHbQv2wFyASJyNMaJn0nwOwSWrzQBb0ADSYeRjEGVYNQK SacRcj0= Received: from pb-smtp1.int.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id D7B5244A27 for ; Thu, 26 Mar 2015 23:20:20 -0400 (EDT) Received: from [192.168.1.103] (unknown [73.164.7.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id 582DA44A26 for ; Thu, 26 Mar 2015 23:20:18 -0400 (EDT) Message-ID: <5514CC6D.3020607@badgerio.us> Date: Thu, 26 Mar 2015 22:20:13 -0500 From: Eric Badger User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: freebsd-current@freebsd.org Subject: Early use of log() does not end up in kernel msg buffer Content-Type: multipart/mixed; boundary="------------000906090006050703080907" X-Pobox-Relay-ID: 3239FA2C-D430-11E4-A3E0-11859F42C9D4-46178211!pb-smtp1.pobox.com X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Mar 2015 03:22:11 -0000 This is a multi-part message in MIME format. --------------000906090006050703080907 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Using log(9) when no process is reading the log results in the message going only to the console (contrast with printf(9), which goes to the console and to the kernel message buffer in this case). I believe it is truer to the semantics of logging for messages to *always* go to the message buffer (where they can eventually be collected and in fact put into a logfile). I therefore propose the attached patch, which sends log(9) to the message buffer always, and to the console only if no one has yet opened the log. It may be more complete to log to the console only if the log level is greater than some (user defined) value, but this seems like that might be more than necessary for this case. Thoughts? Eric --------------000906090006050703080907 Content-Type: text/x-patch; name="log.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="log.diff" diff --git share/man/man9/printf.9 share/man/man9/printf.9 index 84ac822..505ea9b 100644 --- share/man/man9/printf.9 +++ share/man/man9/printf.9 @@ -67,7 +67,8 @@ The .Fn log function sends the message to the kernel logging facility, using the log level as indicated by -.Fa pri . +.Fa pri , +and to the console if no process is yet reading the log. .Pp Each of these related functions use the .Fa fmt diff --git sys/kern/subr_prf.c sys/kern/subr_prf.c index 7e6fd09..6509522 100644 --- sys/kern/subr_prf.c +++ sys/kern/subr_prf.c @@ -295,7 +295,7 @@ log(int level, const char *fmt, ...) va_list ap; va_start(ap, fmt); - (void)_vprintf(level, log_open ? TOLOG : TOCONS, fmt, ap); + (void)_vprintf(level, log_open ? TOLOG : TOCONS | TOLOG, fmt, ap); va_end(ap); msgbuftrigger = 1; --------------000906090006050703080907--