Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 9 Aug 2002 22:07:56 +0400 (MSD)
From:      "Artem 'Zazoobr' Ignatjev" <timon@memphis.mephi.ru>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   bin/41486: watch(8) trapping with `fatal: malloc failed' reason when observed tty is closed then reopened 
Message-ID:  <200208091807.g79I7u846534@memphis.mephi.ru>

next in thread | raw e-mail | index | archive | help

>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:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Aug 09 11:10:01 PDT 2002
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200208091807.g79I7u846534>