NetBSD Problem Report #41003

From Wolfgang.Stukenbrock@nagler-company.com  Fri Mar 13 07:50:07 2009
Return-Path: <Wolfgang.Stukenbrock@nagler-company.com>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by www.NetBSD.org (Postfix) with ESMTP id 5322263BE42
	for <gnats-bugs@gnats.NetBSD.org>; Fri, 13 Mar 2009 07:50:07 +0000 (UTC)
Message-Id: <20090313074946.8432A4EA9F9@s012.nagler-company.com>
Date: Fri, 13 Mar 2009 08:49:46 +0100 (CET)
From: Wolfgang.Stukenbrock@nagler-company.com
Reply-To: Wolfgang.Stukenbrock@nagler-company.com
To: gnats-bugs@gnats.NetBSD.org
Subject: gated exits due to syslog to console when tracing is enabled
X-Send-Pr-Version: 3.95

>Number:         41003
>Category:       pkg
>Synopsis:       gated exits due to syslog to console when tracing is enabled
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Mar 13 07:55:00 +0000 2009
>Last-Modified:  Mon Mar 16 05:35:01 +0000 2009
>Originator:     Wolfgang Stukenbrock
>Release:        NetBSD 4.0
>Organization:
Dr. Nagler & Company GmbH

>Environment:


System: NetBSD s012 4.0 NetBSD 4.0 (NSW-S012) #1: Thu Sep 11 12:21:03 CEST 2008 root@s012:/usr/src/sys/arch/amd64/compile/NSW-S012 amd64
Architecture: x86_64
Machine: amd64
>Description:
	gated seems to analyse errno in an outer loop to see if something has failed
	in the procesing before. (I haven't search where it is in the source ...)
	When tracing is enabled some output will be send to a tracefile and to syslog().
	If syslog is routed to the console too, the syslog() call will open /dev/console
	and try to write to it. If the console is slow (e.g. a serial line), then the
	write() will fail with EAGAIN.
	You can see this if you start gated with ktruss - e.g. "ktruss gated -N -f /etc/gated.conf".
	The error writing to /dev/console is in general no problem - a message is lost on
	the console. This is OK for the syslog stuff itself.
	But the failed write has set errno to EAGAIN and the check for some errors in
	gated detect the EAGAIN, forcing gated to exit.
	This is a strage behaviour for a routing daemon and makes it impossible to trace
	configuration problems by using the trace feature of gated.
>How-To-Repeat:
	Enable tracing in gated and setup syslog to send the output to the console.
	gated will exit with "Resource temporary unavailable" after a very short time.
>Fix:
	A look into the code has shown, that the problem can be fixed by saving the variable
	errno prior calling some tracing routines and restore it after tracing is done.
	This avoid the exit by any error produced by the tracing stuff.
	The best place I've found for the patch is in trace.h
	There the macro trace_log_tf() is used to send out the information - either by
	calling syslog() directly or indirectly via trace_syslog().
	The flowing patch will save the errno prior calling one oth theese routines and
	restores the value after it.


--- src/trace.h.orig	2009-03-13 08:23:04.000000000 +0100
+++ src/trace.h	2009-03-13 08:24:02.000000000 +0100
@@ -351,12 +351,12 @@
 	if ((trp) && (trp)->tr_file->trf_FILE && !BIT_TEST((trp)->tr_control|(cf), TRC_LOGONLY)) { \
 	     trace_trace((trp), (trp)->tr_control|(cf)); \
 	} \
-	if (pri) { \
+	if (pri) { int x_err = errno; \
 	    if (trace_nosyslog) { \
 	    	trace_syslog((pri)); \
 	    } else { \
 		syslog((pri), trace_buffer); \
-	    } \
+	    } errno = x_err; \
 	} \
 	trace_clear(); \
     }

>Audit-Trail:
From: David Holland <dholland-pbugs@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: pkg/41003: gated exits due to syslog to console when tracing
	is enabled
Date: Mon, 16 Mar 2009 05:31:19 +0000

 On Fri, Mar 13, 2009 at 07:55:00AM +0000, Wolfgang.Stukenbrock@nagler-company.com wrote:
  > >Description:
  > 	gated seems to analyse errno in an outer loop to see if
  > 	something has failed in the procesing before. (I haven't
  > 	search where it is in the source ...)  When tracing is enabled
  > 	some output will be send to a tracefile and to syslog().  If
  > 	syslog is routed to the console too, the syslog() call will
  > 	open /dev/console and try to write to it. If the console is
  > 	slow (e.g. a serial line), then the write() will fail with
  > 	EAGAIN.  You can see this if you start gated with ktruss -
  > 	e.g. "ktruss gated -N -f /etc/gated.conf".  The error writing
  > 	to /dev/console is in general no problem - a message is lost
  > 	on the console. This is OK for the syslog stuff itself.  But
  > 	the failed write has set errno to EAGAIN and the check for
  > 	some errors in gated detect the EAGAIN, forcing gated to exit.
  > 	This is a strange behaviour for a routing daemon and makes it
  > 	impossible to trace configuration problems by using the trace
  > 	feature of gated.

 This code is broken; it should not be checking errno until/unless
 something has reported failure.

 although I'm not sure that's anything particularly unexpected with
 gated. :-/

 -- 
 David A. Holland
 dholland@netbsd.org

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.