Subject: Re: Programmatic way of changing virtual terminals?
To: Brian de Alwis <netbsd-users@netbsd.org, bsd@cs.ubc.ca>
From: Tero Kivinen <kivinen@ssh.fi>
List: netbsd-users
Date: 01/23/2002 03:07:07
bsd@cs.ubc.ca (Brian de Alwis) writes:
> So my question: I was wondering if there was a way to do this VT-switching
> programmatically. It would be trivial to then incorporate this into
> the APM scripts. I'm using wscons; wsconsctl doesn't seem to have
> the ability to do this though. Is there any way of doing this?
I have been using attached currentscreen/switchtoscreen programs to
fix similar problem. My /etc/apm/script looks like this (the reason I
wait until the currentscreen really returns 1 is that my machine used
to crash immediately if I tried to suspend while X was displayed):
----------------------------------------------------------------------
...
SCREENNO=/var/run/apm-screenno
...
switch_to_vt0() {
/usr/sbin/switchtoscreen 1
while [ `/usr/sbin/currentscreen` != 1 ]
do
sleep 1
done
}
switch_to_back() {
/usr/sbin/switchtoscreen `cat $SCREENNO`
rm -f $SCREENNO
}
store_current_screen() {
if [ ! -f $SCREENNO ]; then
/usr/sbin/currentscreen > $SCREENNO
fi
}
...
case $0 in
*suspend)
...
store_current_screen
switch_to_vt0
...
;;
*standby)
...
store_current_screen
switch_to_vt0
...
;;
*resume)
...
switch_to_back
...
;;
...
----------------------------------------------------------------------
currentscreen.c:
----------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <dev/wscons/wsdisplay_usl_io.h>
int main(int argc, char **argv)
{
int f, data;
char *file;
if (argc == 1)
file = "/dev/ttyEcfg";
else
file = argv[1];
f = open(file, O_RDWR, 0000);
if (f < 0)
{
perror("File open failed");
exit(1);
}
if (ioctl(f, VT_GETACTIVE, &data) < 0)
{
perror("Ioctl failed");
exit(2);
}
printf("%d\n", data);
close(f);
exit(0);
}
----------------------------------------------------------------------
switchtoscreen.c:
----------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <dev/wscons/wsdisplay_usl_io.h>
int main(int argc, char **argv)
{
int f, data;
char *file;
if (argc == 1)
data = 1;
else
data = atoi(argv[1]);
if (argc <= 2)
file = "/dev/ttyEcfg";
else
file = argv[2];
if (data == 0)
exit(3);
f = open(file, O_RDWR, 0000);
if (f < 0)
{
perror("File open failed");
exit(1);
}
if (ioctl(f, VT_ACTIVATE, data) < 0)
{
perror("Ioctl failed");
exit(2);
}
close(f);
exit(0);
}
--
kivinen@ssh.fi
SSH Communications Security http://www.ssh.fi/
SSH IPSEC Toolkit http://www.ssh.fi/ipsec/