NetBSD Problem Report #41230

From mmondor@pulsar-zone.net  Thu Apr 16 15:13:08 2009
Return-Path: <mmondor@pulsar-zone.net>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by www.NetBSD.org (Postfix) with ESMTP id 3AA5D63C1FA
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 16 Apr 2009 15:13:08 +0000 (UTC)
Message-Id: <200904161513.n3GFD4S0019169@ginseng.xisop>
Date: Thu, 16 Apr 2009 11:13:04 -0400 (EDT)
From: mmondor@pulsar-zone.net
Reply-To: mmondor@pulsar-zone.net
To: gnats-bugs@gnats.NetBSD.org
Subject: -current: sh(1) endlessly looping in interactive mode
X-Send-Pr-Version: 3.95

>Number:         41230
>Category:       bin
>Synopsis:       -current: sh(1) endlessly looping in interactive mode
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Apr 16 15:15:00 +0000 2009
>Closed-Date:    Tue Jun 02 12:45:50 +0000 2009
>Last-Modified:  Tue Jun 02 12:50:02 +0000 2009
>Originator:     Matthew Mondor
>Release:        NetBSD 5.99.10
>Organization:
>Environment:
System: NetBSD sat.xisop 5.99.10 NetBSD 5.99.10 (GENERIC_MM) #0: Wed Apr 15 17:31:57 EDT 2009  root@sat.xisop:/usr/obj/sys/arch/i386/compile/GENERIC_MM i386
Architecture: i386
Machine: i386
>Description:

On -current, /bin/sh becomes stuck in an endless loop when started
as an interactive login shell with the following configuration:


~/.profile
==========

if [ -x /usr/bin/tset ]; then
       eval `tset -sQrm 'unknown:?unknown'`
fi

export ENV=$HOME/.shrc


~/.shrc
=======

. /etc/profile

hup(){ (read pid; kill -HUP $pid) </var/run/$1.pid; }
ll(){ ls -l ${1+"$@"}; }

# Only do this if called in interactive mode
case "$-" in *i*)
	set -o emacs
	if [ $SHELL = '/bin/sh' ]; then
		set -o tabcomplete
	fi
	alias exit='clear; exit'

	prompt()
	{
		if [ $(/usr/bin/id -u) -eq 0 ]; then
			echo '#'
		else
			echo '$'
		fi
	}

	export PS1=" --- ($(/usr/bin/tty | /usr/bin/sed 's/\/dev\///')) $USER@$(/bin/hostname) $(prompt) "

	alias mv='mv -i'
	alias rm='rm -i'
	alias cp='cp -i'

	;;
esac

umask 022


Details
=======

An example prompts generated above would be:
 --- (pts/4) mmondor@sat.xisop $
 --- (pts/1) mmondor@sat.xisop #

After building /bin/sh and libedit+libreadline with debug symbols, it
was possible to attach gdb to the sh(1) process stuck in the endless
loop:

 --- (pts/6) root@sat.xisop # gdb /bin/sh 5454
GNU gdb 6.5
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386--netbsdelf"...
Attaching to program: /bin/sh, process 5454
Reading symbols from /lib/libedit.so.3...done.
Loaded symbols for /lib/libedit.so.3
Reading symbols from /lib/libtermcap.so.0...done.
Loaded symbols for /lib/libtermcap.so.0
Reading symbols from /lib/libc.so.12...done.
Loaded symbols for /lib/libc.so.12
Reading symbols from /libexec/ld.elf_so...done.
Loaded symbols for /libexec/ld.elf_so
0xbbbd6b5e in prompt_print (el=0xbb906800, op=0) at prompt.c:97
97              while (*p) {
(gdb) bt
#0  0xbbbd6b5e in prompt_print (el=0xbb906800, op=0) at prompt.c:97
#1  0xbbbd7d07 in re_refresh (el=0xbb906800) at refresh.c:220
#2  0xbbbd7317 in read_prepare (el=0xbb906800) at read.c:394
#3  0xbbbd74be in el_gets (el=0xbb906800, nread=0x8069670) at read.c:472
#4  0x08053798 in preadfd () at input.c:185
#5  0x0805397c in preadbuffer () at input.c:255
#6  0x0805a818 in xxreadtoken () at parser.c:816
#7  0x0805a64c in readtoken () at parser.c:736
#8  0x08059568 in parsecmd (interact=1) at parser.c:139
#9  0x0805737a in cmdloop (top=1) at main.c:250
#10 0x080572e7 in main (argc=1, argv=0xbfbfeeb8) at main.c:215
(gdb) info local
elp = (el_prompt_t *) 0xbb906a24
p = 0xbb904121 "p $ "
ignore = 1
(gdb) step
98                      if (elp->p_ignore == *p) {
(gdb) step
99                              ignore = !ignore;
(gdb) step
100                             continue;
(gdb) step
97              while (*p) {  
(gdb) step
98                      if (elp->p_ignore == *p) {
(gdb) step
99                              ignore = !ignore;
(gdb) step
100                             continue;
[...]
(gdb) print *elp
$2 = {p_func = 0x805c9c3 <getprompt>, p_pos = {h = 0, v = 0},
  p_ignore = 112 'p'}
(gdb)

Commenting out the "continue;" above indeed stopped the problem,
but obviously the prompt wasn't printed properly without it.
I've not had time to read more throughly the prompt related code,
but decided to file a PR now (and add it to my to-track list).

>How-To-Repeat:
>Fix:

>Release-Note:

>Audit-Trail:
From: Matthew Mondor <mmondor@pulsar-zone.net>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/41230: -current: sh(1) endlessly looping in interactive
 mode
Date: Thu, 16 Apr 2009 11:29:31 -0400

 --Sig_/BsVKxHNAQuOAJWKITByTmY7
 Content-Type: multipart/mixed; boundary="MP_/jxS+J7LC_S1yf1KeBPasFUw"

 --MP_/jxS+J7LC_S1yf1KeBPasFUw
 Content-Type: text/plain; charset=US-ASCII
 Content-Transfer-Encoding: quoted-printable
 Content-Disposition: inline


 The following diff appears to work for me:

 --=20
 Matt

 --MP_/jxS+J7LC_S1yf1KeBPasFUw
 Content-Type: text/plain; name=tmp.txt
 Content-Transfer-Encoding: quoted-printable
 Content-Disposition: attachment; filename=tmp.txt

 Index: prompt.c
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
 RCS file: /nfs/ginseng/home/data/cvsup/netbsd/src/lib/libedit/prompt.c,v
 retrieving revision 1.14
 diff -u -r1.14 prompt.c
 --- prompt.c	31 Mar 2009 17:38:27 -0000	1.14
 +++ prompt.c	16 Apr 2009 15:26:05 -0000
 @@ -94,6 +94,17 @@
  	else
  		elp =3D &el->el_rprompt;
  	p =3D (elp->p_func) (el);
 +	for (; *p !=3D '\0'; p++) {
 +		if (elp->p_ignore =3D=3D *p) {
 +			ignore =3D !ignore;
 +			continue;
 +		}
 +		if (ignore)
 +			term__putc(el, *p);
 +		else
 +			re_putc(el, *p, 1);
 +	}
 +	/*
  	while (*p) {
  		if (elp->p_ignore =3D=3D *p) {
  			ignore =3D !ignore;
 @@ -104,6 +115,7 @@
  		else
  			re_putc(el, *p++, 1);
  	}
 +	*/
 =20
  	elp->p_pos.v =3D el->el_refresh.r_cursor.v;
  	elp->p_pos.h =3D el->el_refresh.r_cursor.h;

 --MP_/jxS+J7LC_S1yf1KeBPasFUw--

 --Sig_/BsVKxHNAQuOAJWKITByTmY7
 Content-Type: application/pgp-signature; name=signature.asc
 Content-Disposition: attachment; filename=signature.asc

 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.9 (NetBSD)

 iQIcBAEBAgAGBQJJ507cAAoJEBALqbeH/laXKpYP/1c4EVDWoiGPzkm0B2e0XvkU
 /rKFcvbynCH6Sqd5L3rL1UOnDvW9r1gln0cDcZULLXv1WQFYOWIZsRS+ZnfHa/C6
 /O+8+uVDUza/3y/x+YaurTkFuOjRlI6Lh3cFnXbZYboTDunUbeAfSUcBCpcF7lqY
 fgfA4PyJlfsF+S3Zf9wmPypXU0/ZrkMBf2JebVRqhBWUTp4YbJP894DF5Ly/+4Ok
 VXI0SFpXP1wfRt3CZBRzXl2rjd2xRYBn+IGYFD2iDQLzyr1o62jxZ8LiabkT0yoh
 7w5YWIJtuKZcgdDgLB5VnejiR/vnAVIvcCrdmcSmaBbgKkAAB/2oqmnVcR8gDzOx
 RhdtkIFw1HUtJvTyGCGvqiOQ87lp8QhIPYsPwFDei+bvZVIRi6C3CanWtZAED+c0
 sDVetrzfDiEDh/NBVoyHyGLhKIkWi4WmEUHABujhIsGYkSqY7WCNG0fS4hPW6Vgh
 60vWkCsrMTkCsPr+Fe1EF98xJgkzIbf4f8riD+Adey9RexzfRoIm4QMU29PuIAzC
 GJsS35m7prTqMqdNc04qYF1vtOEDuY/qHtRbWtjI5Fjc8wPk1CJ7FmDsJRc8UQ1l
 BxUjVogVnydw7DsxHg/E02zaFSRdGDep4Y3eaxwpL6ZwzadWRCkym3T5ktnBSRUD
 GXpYMVXtYCssqwLNH2dx
 =zJ2T
 -----END PGP SIGNATURE-----

 --Sig_/BsVKxHNAQuOAJWKITByTmY7--

From: Matthew Mondor <mm_lists@pulsar-zone.net>
To: gnats-bugs@gnats.NetBSD.org
Cc: christos@netbsd.org
Subject: Re: bin/41230: -current: sh(1) endlessly looping in interactive
 mode
Date: Mon, 1 Jun 2009 22:35:21 -0400

 I can confirm the fix solves the problem, this PR can probably be closed.
 Thanks,
 -- 
 Matt

State-Changed-From-To: open->closed
State-Changed-By: christos@NetBSD.org
State-Changed-When: Tue, 02 Jun 2009 08:45:50 -0400
State-Changed-Why:
fixed verified by submitter


From: christos@zoulas.com (Christos Zoulas)
To: Matthew Mondor <mm_lists@pulsar-zone.net>, gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: Re: bin/41230: -current: sh(1) endlessly looping in interactive mode
Date: Tue, 2 Jun 2009 08:46:06 -0400

 On Jun 1, 10:35pm, mm_lists@pulsar-zone.net (Matthew Mondor) wrote:
 -- Subject: Re: bin/41230: -current: sh(1) endlessly looping in interactive m

 | I can confirm the fix solves the problem, this PR can probably be closed.
 | Thanks,

 Closed it, thanks!

 christos

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