Section 20.1. Getting Started

   


20.1. Getting Started

Here is a list of some of the things that you can do with VCs. Some are specific to an individual VC (usually, the currently active VC); some apply to all VCs in use:

  • Find the current VC

  • Initiate a VC switch

  • Refuse or allow a switch to or from a VC

  • Disable VC switching completely

  • Find an unused VC

  • Allocate and deallocate VCs dynamically in the kernel

  • Make simple sounds

In all cases, the same preparation is needed. You will use ioctl() commands on /dev/tty so you need to start out by including the header files that define the ioctl() arguments:

 #include <signal.h> #include <sys/ioctl.h> #include <sys/vt.h> #include <sys/kd.h> #include <sys/param.h> 


Then open /dev/tty:

 if ((fd = open("/dev/tty", O_RDWR)) < 0) {     perror("myapp: could not open /dev/tty");     exit (1); } 


If you find that you cannot open /dev/tty, you probably have a permission problem: /dev/tty should be readable and writable by everyone.

Note that in addition to ioctl.h, there are two main header files that define the ioctl() calls that manipulate VCs. vt.h defines calls that start with VT and control the virtual terminal, or screen, part of the virtual consoles. kd.h defines calls that start with KD and that control the keyboard and fonts. You can ignore most of the contents of kd.h because the functionality it covers is so nicely encapsulated in utility programs, but it is useful for making the console beep at controlled frequencies.

Those two main header files also define structures that are used with the ioctl()s.

You use the vt_mode structure to find and change the current VC:

 struct vt_mode {     char mode;     char waitv;     short relsig;     short acqsig;     short frsig; }; 


  • mode is either VT_AUTO, which tells the kernel to switch VCs automatically when keys are pressed or when a program sends a request to the kernel to change VCs, or VT_PROCESS, which tells the kernel to ask before switching.

  • waitv is unused, but should be set to one for SVR4 compatibility.

  • relsig names a signal that the kernel should raise to request that the process release the VC.

  • acqsig names a signal that the kernel should raise to alert the process that it has acquired the VC.

  • frsig is unused and should be set to zero for SVR4 compatibility.

 struct vt_stat {     unsigned short v_active;     unsigned short v_signal;     unsigned short v_state; }; 


  • v_active holds the number of the currently active VC.

  • v_signal is not implemented.

  • v_state holds a bitmask telling which of the first 16 VCs are currently open (Linux supports up to 63). There is rarely any reason to consult this bitmask under Linux; you should probably ignore it because it is not sufficiently large to contain complete information, and because in most cases you need to know only the number of some open VC, which you can get with VT_OPENQRY (see page 507).


       
    top
     


    Linux Application Development
    Linux Application Development (paperback) (2nd Edition)
    ISBN: 0321563220
    EAN: 2147483647
    Year: 2003
    Pages: 168

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net