From owner-freebsd-x11@FreeBSD.ORG Sat Mar 31 18:36:20 2012 Return-Path: Delivered-To: freebsd-x11@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 936311065673; Sat, 31 Mar 2012 18:36:20 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id 248C18FC18; Sat, 31 Mar 2012 18:36:18 +0000 (UTC) Received: from skuns.kiev.zoral.com.ua (localhost [127.0.0.1]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id q2VIaDav053536; Sat, 31 Mar 2012 21:36:13 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5) with ESMTP id q2VIaDT9043108; Sat, 31 Mar 2012 21:36:13 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5/Submit) id q2VIaDRU043107; Sat, 31 Mar 2012 21:36:13 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Sat, 31 Mar 2012 21:36:13 +0300 From: Konstantin Belousov To: Nicholas Wilson Message-ID: <20120331183613.GO2358@deviant.kiev.zoral.com.ua> References: <4F76D0E9.7060006@FreeBSD.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="PMKcwNXkopx7sVjc" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.0 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: "freebsd-x11@freebsd.org" , Andriy Gapon Subject: Re: Working out which VT an X process is on X-BeenThere: freebsd-x11@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: X11 on FreeBSD -- maintaining and support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 31 Mar 2012 18:36:20 -0000 --PMKcwNXkopx7sVjc Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Mar 31, 2012 at 07:17:38PM +0100, Nicholas Wilson wrote: > On Mar 31, 2012 10:39 AM, "Andriy Gapon" wrote: > > > > on 31/03/2012 04:10 Nicholas Wilson said the following: > > > Hello, > > > > > > I'm working at the moment on porting a VNC product to FreeBSD, and ha= ve > run > > > into a little problem which I hope I can get some help on. In brief: I > > > can't find a way of determining which virtual terminal is in use by a > given > > > X process. > > > > > > On linux, when X opens a handle to the tty it's going to run on, it > > > acquires it as a controlling terminal. So, if there are two X process= es, > > > and we see that tty7 and tty8 are in use, it's obvious from ps which > > > process is which, and hence by inspecting the processes' environments= we > > > can quickly establish which display number goes with which VT. (On the > > > other UNIX platforms we support, like AIX, we don't need to worry abo= ut > VTs > > > at all.) > > > > Not sure if there is a better way, but > > fstat -p ${X_SERVER_PID} | fgrep tty > > should give what you want. > > You need to have enough privileges to get information about the X proce= ss. > > > > -- > > Andriy Gapon >=20 > Oh! That makes it look so obvious. I'd been fixated on the fact that we > can't rely on proc on BSD, so fuser wouldn't work like does on linux. Of > couse there must be a sysctl-based equivalent for getting the X process's > fds! I'm sure I can work it out now. The sysctl you are looking for is kern.proc.filedesc. See lib/libutil/kinfo_getfile.c for sample use, or just use kinfo_getfile() as is. On the other hand, there may be more ttys opened then just VT which is used for framebuffer, and even more then VT + ctty. --PMKcwNXkopx7sVjc Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (FreeBSD) iEYEARECAAYFAk93Tp0ACgkQC3+MBN1Mb4iHbQCg9OAVSfyjHR1RGy+1RMEbE099 O+MAn21BFglD4VQffPHn6zx67bIfckML =7T2V -----END PGP SIGNATURE----- --PMKcwNXkopx7sVjc--