From brian@Awfulhak.org  Wed May  2 10:19:08 2001
Return-Path: <brian@Awfulhak.org>
Received: from Awfulhak.org (awfulhak.demon.co.uk [194.222.196.252])
	by hub.freebsd.org (Postfix) with ESMTP
	id B2CD837B424; Wed,  2 May 2001 10:19:06 -0700 (PDT)
	(envelope-from brian@Awfulhak.org)
Received: from dev.lan.Awfulhak.org (root@dev.lan.Awfulhak.org [172.16.0.5])
	by Awfulhak.org (8.11.3/8.11.3) with ESMTP id f42HI3q01343;
	Wed, 2 May 2001 18:18:03 +0100 (BST)
	(envelope-from brian@lan.Awfulhak.org)
Received: (from brian@localhost)
	by dev.lan.Awfulhak.org (8.11.3/8.11.3) id f42HI3q64316;
	Wed, 2 May 2001 18:18:03 +0100 (BST)
	(envelope-from brian)
Message-Id: <200105021718.f42HI3q64316@dev.lan.Awfulhak.org>
Date: Wed, 2 May 2001 18:18:03 +0100 (BST)
From: Brian Somers <brian@Awfulhak.org>
Reply-To: brian@Awfulhak.org
To: FreeBSD-gnats-submit@FreeBSD.org
Cc: deischen@FreeBSD.org
Subject: libc_r breaks pppctl
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         27035
>Category:       bin
>Synopsis:       libc_r aborts pppctl(8)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    deischen
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed May 02 10:20:00 PDT 2001
>Closed-Date:    Fri May 4 13:37:55 PDT 2001
>Last-Modified:  Fri May 04 13:38:42 PDT 2001
>Originator:     Brian Somers
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
Awfulhak Ltd.
>Environment:
System: FreeBSD dev.lan.Awfulhak.org 5.0-CURRENT FreeBSD 5.0-CURRENT #0: Wed May 2 11:59:47 BST 2001 cvs@dev.lan.Awfulhak.org:/usr/obj/usr/src/sys/DEV i386


>Description:
	pppctl aborts with

	Fatal error '_waitq_remove: Not in queue' at line 317 in file /usr/src/lib/libc_r/uthread/uthread_priority_queue.c (errno = 35)

>How-To-Repeat:
	Start up two windows.

	Window 1:
		# ppp
		Working in interactive mode
		Using interface: tun0
		# ppp ON machine> set server /tmp/s ""

	Window 2:
		# pppctl /tmp/s
		# ppp ON machine> set log local command

	Window 1:
		# ppp ON machine> show who
		.......

	You may need to do the ``show who'' more than once - on one occasion
	here I needed to do it twice.

	Window 2 eventually shows:
		ppp ON machine> Command: /dev/tty: show who
		Fatal error '_waitq_remove: Not in queue' at line 317 in file /usr/src/lib/libc_r/uthread/uthread_priority_queue.c (errno = 35)
		Abort trap (core dumped)
		# 

>Fix:

	No idea, I know little about the pthreads implementation.  It's
	always possible to use telnet instead of pppctl though, so this
	problem can't really be described as critical...
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->deischen 
Responsible-Changed-By: brian 
Responsible-Changed-When: Wed May 2 10:22:06 PDT 2001 
Responsible-Changed-Why:  
I think Daniel looks after the pthreads stuff....? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=27035 

From: Dan Eischen <eischen@vigrid.com>
To: freebsd-gnats-submit@FreeBSD.org, brian@Awfulhak.org
Cc:  
Subject: Re: bin/27035: libc_r aborts pppctl(8)
Date: Wed, 02 May 2001 23:22:59 -0400

 You want to try this fix?
 
 -- 
 Dan Eischen
 
 
 Index: uthread_kern.c
 ===================================================================
 RCS file: /opt/b/CVS/src/lib/libc_r/uthread/uthread_kern.c,v
 retrieving revision 1.37
 diff -u -r1.37 uthread_kern.c
 --- uthread_kern.c	2001/01/24 13:03:34	1.37
 +++ uthread_kern.c	2001/05/03 03:17:03
 @@ -206,12 +206,6 @@
  			PANIC("Unable to restore alternate signal stack");
  	}
  
 -	/* Are there pending signals for this thread? */
 -	if (curthread->check_pending != 0) {
 -		curthread->check_pending = 0;
 -		_thread_sig_check_pending(curthread);
 -	}
 -
  	/*
  	 * Enter a scheduling loop that finds the next thread that is
  	 * ready to run. This loop completes when there are no more threads
 @@ -335,6 +329,12 @@
  				PTHREAD_WORKQ_INSERT(curthread);
  				break;
  			}
 +		}
 +
 +		/* Are there pending signals for this thread? */
 +		if (curthread->check_pending != 0) {
 +			curthread->check_pending = 0;
 +			_thread_sig_check_pending(curthread);
  		}
  
  		/*

From: Brian Somers <brian@Awfulhak.org>
To: Dan Eischen <eischen@vigrid.com>
Cc: freebsd-gnats-submit@FreeBSD.org, brian@Awfulhak.org,
	brian@Awfulhak.org
Subject: Re: bin/27035: libc_r aborts pppctl(8) 
Date: Thu, 03 May 2001 11:11:50 +0100

 Hi,
 
 Yes, this gets it past the problem.  However, with the same setup, 
 typing ``quit'' at the original ppp command prompt makes pppctl drop 
 a core.  Also, once pppctl's Receive() thread has read data, it doesn't 
 seem to accept keyboard input any more.
 
 > You want to try this fix?
 > 
 > -- 
 > Dan Eischen
 > 
 > 
 > Index: uthread_kern.c
 > ===================================================================
 > RCS file: /opt/b/CVS/src/lib/libc_r/uthread/uthread_kern.c,v
 > retrieving revision 1.37
 > diff -u -r1.37 uthread_kern.c
 > --- uthread_kern.c	2001/01/24 13:03:34	1.37
 > +++ uthread_kern.c	2001/05/03 03:17:03
 > @@ -206,12 +206,6 @@
 >  			PANIC("Unable to restore alternate signal stack");
 >  	}
 >  
 > -	/* Are there pending signals for this thread? */
 > -	if (curthread->check_pending != 0) {
 > -		curthread->check_pending = 0;
 > -		_thread_sig_check_pending(curthread);
 > -	}
 > -
 >  	/*
 >  	 * Enter a scheduling loop that finds the next thread that is
 >  	 * ready to run. This loop completes when there are no more threads
 > @@ -335,6 +329,12 @@
 >  				PTHREAD_WORKQ_INSERT(curthread);
 >  				break;
 >  			}
 > +		}
 > +
 > +		/* Are there pending signals for this thread? */
 > +		if (curthread->check_pending != 0) {
 > +			curthread->check_pending = 0;
 > +			_thread_sig_check_pending(curthread);
 >  		}
 >  
 >  		/*
 > 
 
 -- 
 Brian <brian@Awfulhak.org>                        <brian@[uk.]FreeBSD.org>
       <http://www.Awfulhak.org>                   <brian@[uk.]OpenBSD.org>
 Don't _EVER_ lose your sense of humour !
 
 

From: Daniel Eischen <eischen@vigrid.com>
To: Brian Somers <brian@Awfulhak.org>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: bin/27035: libc_r aborts pppctl(8) 
Date: Thu, 3 May 2001 16:26:01 -0400 (EDT)

 On Thu, 3 May 2001, Brian Somers wrote:
 > Hi,
 > 
 > Yes, this gets it past the problem.  However, with the same setup, 
 > typing ``quit'' at the original ppp command prompt makes pppctl drop 
 > a core.  Also, once pppctl's Receive() thread has read data, it doesn't 
 > seem to accept keyboard input any more.
 
 Hmm, I tried a similar patch to 4.3-stable and can't reproduce this
 new problem.  If you can reproduce this under -stable also, let me know.
 I'll try -current later tonight.
 
 -- 
 Dan Eischen

From: Dan Eischen <eischen@vigrid.com>
To: freebsd-gnats-submit@FreeBSD.org, brian@Awfulhak.org
Cc:  
Subject: Re: bin/27035: libc_r aborts pppctl(8)
Date: Fri, 04 May 2001 10:45:14 -0400

 This patch seems to fix both the original problem and the followup
 problem.  Please try it and see if there are any other bogosities
 that you can find.
 
 Thanks!
 
 Index: uthread_kern.c
 ===================================================================
 RCS file: /opt/b/CVS/src/lib/libc_r/uthread/uthread_kern.c,v
 retrieving revision 1.37
 diff -u -r1.37 uthread_kern.c
 --- uthread_kern.c	2001/01/24 13:03:34	1.37
 +++ uthread_kern.c	2001/05/04 14:28:07
 @@ -206,12 +206,6 @@
  			PANIC("Unable to restore alternate signal stack");
  	}
  
 -	/* Are there pending signals for this thread? */
 -	if (curthread->check_pending != 0) {
 -		curthread->check_pending = 0;
 -		_thread_sig_check_pending(curthread);
 -	}
 -
  	/*
  	 * Enter a scheduling loop that finds the next thread that is
  	 * ready to run. This loop completes when there are no more threads
 @@ -334,6 +328,21 @@
  				/* Insert into the work queue: */
  				PTHREAD_WORKQ_INSERT(curthread);
  				break;
 +			}
 +
 +			/*
 +			 * Are there pending signals for this thread?
 +			 *
 +			 * This check has to be performed after the thread
 +			 * has been placed in the queue(s) appropriate for
 +			 * its state.  The process of adding pending signals
 +			 * can change a threads state, which in turn will
 +			 * attempt to add or remove the thread from any
 +			 * scheduling queue to which it belongs.
 +			 */
 +			if (curthread->check_pending != 0) {
 +				curthread->check_pending = 0;
 +				_thread_sig_check_pending(curthread);
  			}
  		}
  
 Index: uthread_sig.c
 ===================================================================
 RCS file: /opt/b/CVS/src/lib/libc_r/uthread/uthread_sig.c,v
 retrieving revision 1.35
 diff -u -r1.35 uthread_sig.c
 --- uthread_sig.c	2001/03/09 16:05:43	1.35
 +++ uthread_sig.c	2001/05/04 14:27:56
 @@ -575,6 +575,9 @@
  
  	restart = _thread_sigact[sig - 1].sa_flags & SA_RESTART;
  
 +	/* Make sure this signal isn't still in the pending set: */
 +	sigdelset(&pthread->sigpend, sig);
 +
  	/*
  	 * Process according to thread state:
  	 */

From: Brian Somers <brian@Awfulhak.org>
To: Dan Eischen <eischen@vigrid.com>
Cc: freebsd-gnats-submit@FreeBSD.org, brian@Awfulhak.org,
	brian@Awfulhak.org
Subject: Re: bin/27035: libc_r aborts pppctl(8) 
Date: Fri, 04 May 2001 16:47:38 +0100

 Yes - this seems to make things work again.
 
 Thanks.
 
 > This patch seems to fix both the original problem and the followup
 > problem.  Please try it and see if there are any other bogosities
 > that you can find.
 > 
 > Thanks!
 > 
 > Index: uthread_kern.c
 > ===================================================================
 > RCS file: /opt/b/CVS/src/lib/libc_r/uthread/uthread_kern.c,v
 > retrieving revision 1.37
 > diff -u -r1.37 uthread_kern.c
 > --- uthread_kern.c	2001/01/24 13:03:34	1.37
 > +++ uthread_kern.c	2001/05/04 14:28:07
 > @@ -206,12 +206,6 @@
 >  			PANIC("Unable to restore alternate signal stack");
 >  	}
 >  
 > -	/* Are there pending signals for this thread? */
 > -	if (curthread->check_pending != 0) {
 > -		curthread->check_pending = 0;
 > -		_thread_sig_check_pending(curthread);
 > -	}
 > -
 >  	/*
 >  	 * Enter a scheduling loop that finds the next thread that is
 >  	 * ready to run. This loop completes when there are no more threads
 > @@ -334,6 +328,21 @@
 >  				/* Insert into the work queue: */
 >  				PTHREAD_WORKQ_INSERT(curthread);
 >  				break;
 > +			}
 > +
 > +			/*
 > +			 * Are there pending signals for this thread?
 > +			 *
 > +			 * This check has to be performed after the thread
 > +			 * has been placed in the queue(s) appropriate for
 > +			 * its state.  The process of adding pending signals
 > +			 * can change a threads state, which in turn will
 > +			 * attempt to add or remove the thread from any
 > +			 * scheduling queue to which it belongs.
 > +			 */
 > +			if (curthread->check_pending != 0) {
 > +				curthread->check_pending = 0;
 > +				_thread_sig_check_pending(curthread);
 >  			}
 >  		}
 >  
 > Index: uthread_sig.c
 > ===================================================================
 > RCS file: /opt/b/CVS/src/lib/libc_r/uthread/uthread_sig.c,v
 > retrieving revision 1.35
 > diff -u -r1.35 uthread_sig.c
 > --- uthread_sig.c	2001/03/09 16:05:43	1.35
 > +++ uthread_sig.c	2001/05/04 14:27:56
 > @@ -575,6 +575,9 @@
 >  
 >  	restart = _thread_sigact[sig - 1].sa_flags & SA_RESTART;
 >  
 > +	/* Make sure this signal isn't still in the pending set: */
 > +	sigdelset(&pthread->sigpend, sig);
 > +
 >  	/*
 >  	 * Process according to thread state:
 >  	 */
 > 
 
 -- 
 Brian <brian@Awfulhak.org>                        <brian@[uk.]FreeBSD.org>
       <http://www.Awfulhak.org>                   <brian@[uk.]OpenBSD.org>
 Don't _EVER_ lose your sense of humour !
 
 
State-Changed-From-To: open->closed 
State-Changed-By: deischen 
State-Changed-When: Fri May 4 13:37:55 PDT 2001 
State-Changed-Why:  
Fix just committed.  Thanks for the test cases Brian :-) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=27035 
>Unformatted:
