vga_init3
Initialize svgalib library
Usage
#include <vga.h>
int vga_init(void);
Overview
It detects the chipset and gives up supervisor rights. This is the recommended first line of any program that uses svgalib. vga_setchipset(3) can be called before it to avoid detection.
Svgalib catches a bunch of signals that usually kill your program to restore textmode. If you catch signal's before calling vga_init() svgalib will restore textmode and prepare for shutdown and then call your handler routine. If you don't want this, catch the signal after calling vga_init and do not daisychain to svgalib's original handler.
WARNING! svgalib needs two signals for it's own purposes (that is managing console switches). To avoid problems it uses the otherwise unused signals SIGUSR1 and SIGUSR2. However, this means that you cannot use them in your program by any means. They are setup by vga_init() as everything else is.
Since version 1.2.11 vga_init() includes code to hunt for a free virtual console on its own in case you are not starting the program from one (but instead over a network or modem login, from within 'screen' or an 'xterm'). Provided there is a free console, this succeeds if you are root or if the svgalib calling user own the current console. This is to avoid people not using the console being able to fiddle with it. On graceful exit the program returns to the console from which it was started. Otherwise it remains in text mode at the VC which svgalib allocated to allow you to see any error messages. In any case, any I/O the svgalib makes in text mode (after calling vga_init) will also take place at this new console.
Alas, some games misuse their suid root priviledge and run as full root process. svgalib cannot detect this and allows Joe Blow User to open a new VC on the console. If this annoys you ROOT_VC_SHORTCUT in Makefile.cfg allows you to disable allocating a new VC for root (except when he owns the current console) when compiling svgalib. This is the default (disabling the allocation for root).
vga_init() returns a non-zero value in case of errors. As of this writing it will return -1 if it is unable to allocate a graphical console. Otherwise, 0 is returned.
Releases
Unchanged in 5 releases since Debian 3.1 (Sarge).