[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to determine the VT of a running X session?



> > Apparently VT_GETSTATE doesn't work when you're under X (returns EINVAL)...
> 
> I hadn't tried it outside of X and there it does work as a non-root
> user.  but in X I get:
> 
> dberg@ubuntu:~$ fgconsole
> Couldnt get a file descriptor referring to the console
> dberg@ubuntu:~$ sudo fgconsole
> 9
> dberg@ubuntu:~$ sudo -u dberg fgconsole
> Couldnt get a file descriptor referring to the console
> dberg@ubuntu:~$
> 
> On both my ubuntu and debian box.
> 
> Perhaps its just environment, but why would it work for a non-root
> outside X, for root using either su or sudo in X, but not a non-root
> in X wether sudo is used or not?

Ah, now I understand.

When running an application (or shell) directly on the console, the
fd you call the ioctl() on afterwards can be obtained via "/dev/tty"
(which is an alias for "the controlling terminal of the current process,
if any") - and this, of course, can be opened without restrictions.

For applications under X, the controlling teminal typically is something
like /dev/pts/X, which doesn't accept VT ioctl()s... so the only
remaining possibility is to open /dev/console itself - but that
has ownership/permission 0:0 0620.


Regards,

Jan

-- 
Jan C. Nordholz
<jckn At gmx net>

Attachment: signature.asc
Description: Digital signature


Reply to: