From owner-freebsd-current@FreeBSD.ORG Tue Apr 29 15:12:57 2008 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 466FE1065680 for ; Tue, 29 Apr 2008 15:12:57 +0000 (UTC) (envelope-from bms@FreeBSD.org) Received: from out4.smtp.messagingengine.com (out4.smtp.messagingengine.com [66.111.4.28]) by mx1.freebsd.org (Postfix) with ESMTP id 0198C8FC18 for ; Tue, 29 Apr 2008 15:12:56 +0000 (UTC) (envelope-from bms@FreeBSD.org) Received: from compute2.internal (compute2.internal [10.202.2.42]) by out1.messagingengine.com (Postfix) with ESMTP id 6AA3E104B9F for ; Tue, 29 Apr 2008 11:12:56 -0400 (EDT) Received: from heartbeat1.messagingengine.com ([10.202.2.160]) by compute2.internal (MEProxy); Tue, 29 Apr 2008 11:12:56 -0400 X-Sasl-enc: Cm5OWmzkPm9OzQExXSkEwc+czJ+sXdqXRz/ao73Uds7P 1209481975 Received: from empiric.lon.incunabulum.net (82-35-112-254.cable.ubr07.dals.blueyonder.co.uk [82.35.112.254]) by mail.messagingengine.com (Postfix) with ESMTPSA id D3917CA6C for ; Tue, 29 Apr 2008 11:12:55 -0400 (EDT) Message-ID: <48173AF6.5090609@FreeBSD.org> Date: Tue, 29 Apr 2008 16:12:54 +0100 From: "Bruce M. Simpson" User-Agent: Thunderbird 2.0.0.12 (X11/20080423) MIME-Version: 1.0 To: FreeBSD Current References: <48167B72.1000207@incunabulum.net> In-Reply-To: <48167B72.1000207@incunabulum.net> X-Enigmail-Version: 0.95.6 Content-Type: multipart/mixed; boundary="------------050309060208090502030102" Subject: Re: [PATCH] cu/tip leaves tty in exclusive mode X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Apr 2008 15:12:57 -0000 This is a multi-part message in MIME format. --------------050309060208090502030102 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Bruce M Simpson wrote: > Hi, > > I think I saw a bug. I have an app which creates ptys on its own. I > connect to them manually with cu -l. > > It appears that cu doesn't clean up after itself... this is a quick fix Here's another way of fixing it. Perhaps this should go in tools for now? Only the superuser can clear the TS_XCLUDE bit according to kern/tty.c. There doesn't seem to be any way of resetting the TIONXCL flag on a tty without rebooting -- there's no sysctl or anything else, stty doesn't know about it, and it does not have a TERMIOS flag. cheers BMS --------------050309060208090502030102 Content-Type: text/plain; name="tionxcl.c" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="tionxcl.c" #include #include #include #include #include #include #include #define DEVPATHNAME "/dev" int main(int argc, char *argv[]) { char *progname; char *ttyname; int fd; int dofree; dofree = 0; progname = basename(argv[0]); if (argc != 2) errx(EX_USAGE, "usage: %s \n", progname); if (geteuid() != 0) errx(EX_NOPERM, "Sorry\n"); if (argv[1][0] == '/') { ttyname = argv[1]; } else { size_t len, maxpath, result; len = strlen(argv[1]) + sizeof(DEVPATHNAME) + 1; maxpath = pathconf(DEVPATHNAME, _PC_PATH_MAX); if (len > maxpath) { warnc(ENAMETOOLONG, ttyname); exit(EX_DATAERR); } ttyname = malloc(len); if (ttyname == NULL) { warnc(ENOMEM, "malloc"); exit(EX_OSERR); } dofree = 1; result = snprintf(ttyname, len, "%s/%s", DEVPATHNAME, argv[1]); if (result >= len) warnc(ENOMEM, "snprintf"); } fd = open(ttyname, O_RDWR); if (fd == -1) { warnc(errno, "open %s", ttyname); if (dofree) free(ttyname); exit(EX_OSERR); } if (0 != ioctl(fd, TIOCNXCL, 0)) warnc(errno, "ioctl TIOCNXCL %s", ttyname); if (dofree) free(ttyname); exit(0); } --------------050309060208090502030102--