NetBSD Problem Report #41651

From ws@solfrank.net  Tue Jun 30 10:46:38 2009
Return-Path: <ws@solfrank.net>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by www.NetBSD.org (Postfix) with ESMTP id A9BD663B976
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 30 Jun 2009 10:46:38 +0000 (UTC)
Message-Id: <20090630104624.BB5341676E@ws.solfrank.net>
Date: Tue, 30 Jun 2009 12:46:24 +0200 (MEST)
From: ws@solfrank.net
Reply-To: ws@solfrank.net
To: gnats-bugs@gnats.NetBSD.org
Subject: cups doesn't print any more
X-Send-Pr-Version: 3.95

>Number:         41651
>Category:       kern
>Synopsis:       cups doesn't print any more
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    ad
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jun 30 10:50:00 +0000 2009
>Closed-Date:    Tue Jun 30 20:36:04 +0000 2009
>Last-Modified:  Tue Jun 30 20:36:04 +0000 2009
>Originator:     Wolfgang Solfrank
>Release:        NetBSD 5.99.14
>Organization:

>Environment:


System: NetBSD ws.solfrank.net 5.99.14 NetBSD 5.99.14 (ws) #1: Mon Jun 29 22:14:42 MEST 2009 ws@ws.solfrank.net:/src/obj/sys/arch/amd64/compile/ws amd64
Architecture: x86_64
Machine: amd64
>Description:
	cups doesn't print any longer with a current kernel.
>How-To-Repeat:
	Install cups from pkgsrc and try to print some file.
	Nothing will show up on the printer.
	If logging is enabled in /etc/syslog.conf (lpr.info),
	you'll notice a message like

	PID ... (/usr/pkg/libexec/cups/filter/pstops) stopped with status 1!

	It turns out to be a problem with kqueue used in cupsd.

	The problem can be reproduced with the following test program:

	#include <stdio.h>
	#include <errno.h>
	#include <fcntl.h>
	#include <stdlib.h>
	#include <string.h>
	#include <unistd.h>

	#include <sys/event.h>
	#include <sys/time.h>

	int
	main(int argc, char **argv)
	{
	    int k, ret;
	    char *err;

	    printf("kqueue -> %d\n", k = kqueue());
	    open("/dev/null", 0);
	    switch (fork()) {
	    case 0:
		ret = close(k);
		err = strerror(errno);
		printf("close -> %d", ret);
		printf(" (%s)\n", err);
		printf("dup-> %d\n", open("/dev/null", 0));
		exit(0);
	    default:
		wait(NULL);
		return 0;
	    }
	}

	The program will produce the followint output:

	kqueue -> 3
	close -> -1 (Bad file descriptor)
	dup-> 5

	As you can see, while the kqueue file descriptor is closed on
	the fork as documented, the subsequent dup doesn't pick up
	its file descriptor.  With cups this results in the filter
	not being started as expected, as it gets no stdin.
Fix:
	The problem is that the fd_freefile optimization, which tracks
	the lowest available file descriptor, isn't correctly maintained
	when the kqueue descriptor isn't copied from the parent to the
	child.

	The following diff fixes this:

	===================================================================
	RCS file: /cvsroot/src/sys/kern/kern_descrip.c,v
	retrieving revision 1.197
	diff -u -r1.197 kern_descrip.c
	--- kern_descrip.c      8 Jun 2009 00:19:56 -0000       1.197
	+++ kern_descrip.c      30 Jun 2009 10:40:53 -0000
	@@ -1423,6 +1423,8 @@
			}
			if (__predict_false(fp->f_type == DTYPE_KQUEUE)) {
				/* kqueue descriptors cannot be copied. */
	+                       if (i < newfdp->fd_freefile)
	+                               newfdp->fd_freefile = i;
				continue;
			}
			/* It's active: add a reference to the file. */

>Fix:

Unknown
>Release-Note:

>Audit-Trail:

State-Changed-From-To: open->closed
State-Changed-By: martin@NetBSD.org
State-Changed-When: Tue, 30 Jun 2009 11:03:15 +0000
State-Changed-Why:
See kern/41593


Responsible-Changed-From-To: kern-bug-people->ad
Responsible-Changed-By: martin@NetBSD.org
Responsible-Changed-When: Tue, 30 Jun 2009 19:11:11 +0000
Responsible-Changed-Why:
Superceeds 41593, so over to it's maintainer


State-Changed-From-To: closed->open
State-Changed-By: martin@NetBSD.org
State-Changed-When: Tue, 30 Jun 2009 19:11:11 +0000
State-Changed-Why:
swapping prs


From: Martin Husemann <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/41651 CVS commit: src/sys/kern
Date: Tue, 30 Jun 2009 20:32:49 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Tue Jun 30 20:32:49 UTC 2009

 Modified Files:
 	src/sys/kern: kern_descrip.c

 Log Message:
 Update fd_freefile when kqueue descriptors are not copied from
 parent to child. From Wolfgang Solfrank in PR kern/41651.
 Approved by Andrew Doran.


 To generate a diff of this commit:
 cvs rdiff -u -r1.197 -r1.198 src/sys/kern/kern_descrip.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: martin@NetBSD.org
State-Changed-When: Tue, 30 Jun 2009 20:36:04 +0000
State-Changed-Why:
Commited, thanks!


>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.