From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KVQRF-0001i0-Uy for qemu-devel@nongnu.org; Tue, 19 Aug 2008 08:35:54 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KVQRE-0001gb-1W for qemu-devel@nongnu.org; Tue, 19 Aug 2008 08:35:52 -0400 Received: from [199.232.76.173] (port=55788 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KVQRD-0001gP-Ql for qemu-devel@nongnu.org; Tue, 19 Aug 2008 08:35:51 -0400 Received: from pf.freedaemonhosting.com ([66.210.104.252]:10624 helo=FreeDaemonHosting.com) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KVQRD-0007GE-3t for qemu-devel@nongnu.org; Tue, 19 Aug 2008 08:35:51 -0400 Date: Tue, 19 Aug 2008 07:35:45 -0500 From: "Todd T. Fries" Subject: Re: [Qemu-devel] pty/tty functions for BSD too Message-ID: <20080819123544.GA30399@fries.net> References: <20080818105912.GF4686@implementation.uk.xensource.com> <48A981F1.6070606@codemonkey.ws> <20080818142333.GQ4686@implementation.uk.xensource.com> <20080818162618.GA20089@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20080818162618.GA20089@redhat.com> Reply-To: todd@fries.net, qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" Cc: qemu-devel@nongnu.org >>From the OpenBSD man page... DESCRIPTION The openpty(), login_tty(), and forkpty() functions perform manipulations on ttys and pseudo-ttys. The openpty() function finds an available pseudo-tty and returns file de- scriptors for the master and slave in amaster and aslave. If name is non-null, the filename of the slave is returned in name (a string of at least 16 characters). If termp is non-null, the terminal parameters of the slave will be set to the values in termp. If winp is non-null, the window size of the slave will be set to the values in winp. The openpty() function works in the following way: first it attempts to allocate the pseudo-tty through the /dev/ptm device (see pty(4) for de- tails) and if that fails it searches for a free pseudo-tty by iterating through all existing pseudo-tty devices in /dev. When a free pseudo-tty is found, its ownership is changed to the UID of the caller, permissions are set to correct values, and all earlier uses of that device are re- voked (see revoke(2) for details). The first method can work for any us- er, the second method requires super-user privileges in most cases. In OpenBSD, it's a pretty safe bet that 16chars is overkill. The tty and/or pty name will never be longer than /dev/?ty??. Thanks, -- Todd Fries .. todd@fries.net _____________________________________________ | \ 1.636.410.0632 (voice) | Free Daemon Consulting, LLC \ 1.405.227.9094 (voice) | http://FreeDaemonConsulting.com \ 1.866.792.3418 (FAX) | "..in support of free software solutions." \ 250797 (FWD) | \ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 37E7 D3EB 74D0 8D66 A68D B866 0326 204E 3F42 004A http://todd.fries.net/pgp.txt Penned by Daniel P. Berrange on 20080818 17:26.18, we have: | On Mon, Aug 18, 2008 at 07:16:36PM +0300, Blue Swirl wrote: | > On 8/18/08, Samuel Thibault wrote: | > > Anthony Liguori, le Mon 18 Aug 2008 09:06:41 -0500, a ?crit : | > > | > > > Samuel Thibault wrote: | > > > >In Xen, pty/tty functions are enabled for BSD too, shouldn't we enable | > > > >them in upstream qemu too, as patched below? | > > > > | > > > | > > > And you're sure that these functions compile/work on NetBSD/OpenBSD? | > > | > > | > > The defines are explicit in Xen, so I guess somebody tested it. I | > > haven't myself. I wonder why there is no FreeBSD however. | > | > The patch does not work on OpenBSD, because while openpty() is | > available, ptsname() isn't. | > | > I tested the attached version on OpenBSD and Linux, pty name is | > printed correctly. | | Passing a non-NULL value to openpty()'s name parameter is not safe | | [quote openpty(1)] | BUGS | Nobody knows how much space should be reserved for name. So, call- | ing openpty() or forkpty() with non-NULL name may not be secure. | [/quote] | | If BSD has no other way to determine the PTY name, then at least it | should be conditionalized so that systems with ptsname() use it, only | falling back to using the 'name' arg to openpty() for OS lacking ptsname | | Regards, | Daniel | -- | |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| | |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| | |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| | |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :| |