From timon@memphis.mephi.ru  Fri Aug  9 11:08:01 2002
Return-Path: <timon@memphis.mephi.ru>
Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 91F3A37B400
	for <FreeBSD-gnats-submit@freebsd.org>; Fri,  9 Aug 2002 11:08:01 -0700 (PDT)
Received: from memphis.mephi.ru (memphis.mephi.ru [194.67.67.234])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 9904A43E77
	for <FreeBSD-gnats-submit@freebsd.org>; Fri,  9 Aug 2002 11:07:59 -0700 (PDT)
	(envelope-from timon@memphis.mephi.ru)
Received: (from timon@localhost)
	by memphis.mephi.ru (8.11.6/8.11.6) id g79I7u846534;
	Fri, 9 Aug 2002 22:07:56 +0400 (MSD)
	(envelope-from timon)
Message-Id: <200208091807.g79I7u846534@memphis.mephi.ru>
Date: Fri, 9 Aug 2002 22:07:56 +0400 (MSD)
From: "Artem 'Zazoobr' Ignatjev" <timon@memphis.mephi.ru>
Reply-To: "Artem 'Zazoobr' Ignatjev" <timon@memphis.mephi.ru>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: watch(8) trapping with `fatal: malloc failed' reason when observed tty is closed then reopened 
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         41486
>Category:       bin
>Synopsis:       watch(8) trapping with `fatal: malloc failed' reason when observed tty is closed then reopened
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Aug 09 11:10:01 PDT 2002
>Closed-Date:    Thu Aug 22 11:54:45 PDT 2002
>Last-Modified:  Thu Aug 22 11:54:45 PDT 2002
>Originator:     Artem 'Zazoobr' Ignatjev
>Release:        FreeBSD 4.6.1-RELEASE-p7 i386
>Organization:
NetherWorld Ultima Online Shard
>Environment:
System: FreeBSD netherworld.ru 4.6.1-RELEASE-p7 FreeBSD 4.6.1-RELEASE-p7 #1: Fri Aug 2 16:55:42 MSD 2002 root@netherworld.ru:/usr/obj/usr/src/sys/NETHER i386
watch.c revision: 
  "$FreeBSD: src/usr.sbin/watch/watch.c,v 1.18.2.2 2002/03/11 01:26:42 dd Exp $";

	
>Description:
	watch(8) allows the user to examine all data coming through a specified tty using the snp(4) device. 
	When the observed tty is closed, and then reopened, watch dies with
`fatal: malloc failed' reason when reconnecting. I suppose that it happens because of missed `brake's in event-handling switch.
	
>How-To-Repeat:
---- proof.sh ----
#!/bin/sh                                                    
if [ `id -u` -ne 0 ] ; then                                  
    echo "I need root ;-)"                                   
    exit 1                                                   
fi                                                           
echo "#include <stdio.h>" >proof.c                           
echo 'int main(void) { printf("Hello, world\n"); }' >>proof.c
cc -o proof proof.c                                          
(while true; do ./proof >/dev/ttyv9 ; sleep 5 ; done ) &     
PID=$!                                                       
watch -c v9                                                  
echo "watch exit_code: $?"                                   
kill -9 $PID                                                 
---- EOF proof.sh ----
The output must be something like that:
Hello, world               
watch: fatal: malloc failed
watch exit_code: 69        
45910: Killed              
	
>Fix:

	

--- patch-watch.c begins here ---
--- usr.sbin/watch/watch.c.orig	Fri Aug  9 18:49:40 2002
+++ usr.sbin/watch/watch.c	Fri Aug  9 18:52:45 2002
@@ -415,6 +415,7 @@
 				set_dev(dev_name);
 			} else
 				cleanup(-1);
+			break;
 		case SNP_DETACH:
 		case SNP_TTYCLOSE:
 			if (opt_reconn_close)
@@ -424,6 +425,7 @@
 				set_dev(dev_name);
 			} else
 				cleanup(-1);
+			break;
 		default:
 			nread = (unsigned)idata;
 			if (nread < (b_size / 2) && (b_size / 2) > MIN_SIZE) {
--- patch-watch.c ends here ---


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: mikeh 
State-Changed-When: Thu Aug 22 11:53:45 PDT 2002 
State-Changed-Why:  
Duplicate of bin/41511. 

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