Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 3 Feb 1998 13:05:48 -0800 (PST)
From:      archie@whistle.com
To:        FreeBSD-gnats-submit@FreeBSD.ORG
Subject:   kern/5636: line discipline is not unloaded when device closes
Message-ID:  <199802032105.NAA19000@bubba.whistle.com>

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


>Number:         5636
>Category:       kern
>Synopsis:       line discipline is not unloaded when device closes
>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:   Tue Feb  3 13:20:01 PST 1998
>Last-Modified:
>Originator:     Archie Cobbs
>Organization:
Whistle Communications, Inc.
>Release:        FreeBSD 2.2.5-STABLE i386
>Environment:

	FreeBSD 2.2.5

>Description:

	I have written a line discipline module. I have a test program
	that shows it successfully loads using ioctl(fd, TIOCSETD, &ldisc).

	The "open" method gets called upon installation, and if the
	line discipline is changed back to TTYDISC, the "close" method
	gets called.

	The problem is that if the device is closed after installing the
	new line discipline, but before reinstalling TTYDISC, the "close"
	method does NOT get called. This can cause memory leaks, dangling
	pointers, etc.

>From /sys/sys/conf.h:

	/*
	 * Line discipline switch table
	 */
	struct linesw {
		l_open_t        *l_open;	<-- open method
		l_close_t       *l_close;	<-- close method
		l_read_t        *l_read;
		l_write_t       *l_write;
		l_ioctl_t       *l_ioctl;
		l_rint_t        *l_rint;
		l_start_t       *l_start;
		l_modem_t       *l_modem;
	};

>How-To-Repeat:

	1. Register your own line discipline as #7

	2. Install it with a program containing these lines:

	  ldisc = 7;
	  if ((fd = open(file, O_RDWR, 0)) < 0) {
	    err(1, "%s", file);
	  }
	  if (ioctl(fd, TIOCSETD, &ldisc) < 0) {
	    err(1, "ioctl(TIOCSETD)"); 
	  }
	  sleep(10000);

	3. Hit control-C during the sleep() statement

	4. Notice that the "close" method of your line discipline
	   never gets called.

>Fix:

	Kernel should insure that when a tty device is closed, the
	"close" method of the corresponding line discipline is called.

>Audit-Trail:
>Unformatted:



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