Usenet comp.os.linux.announce (1993-2013)
 help / color / mirror / Atom feed
* SOURCE: cyclevc - a small tool to auto-cycle through VCs
@ 1996-04-13  4:00 Mathias Koerber
  0 siblings, 0 replies; only message in thread
From: Mathias Koerber @ 1996-04-13  4:00 UTC (permalink / raw)


-----BEGIN PGP SIGNED MESSAGE-----

[ Moderator's note: This is _NOT_ an invitation for source code for
  more small programs.  Please, it is better to send them to an FTP
  site so that they are archived better and can be more easily found.
  --liw ]

This is a small utility i wrote to automatically cycle through
a defined list of VCs, each running some program (usually a monitor
or so). Enjoy ...

/*
 * cyclevc
 *
 * this small utility lets you cycle the screen through a number of VCs
 * presumably running some displayprograms...
 *
 * usage:	cyclevc <sleep> <vc> <vc> ...
 *
 *	secs:	number of seconds to display each VC
 *	vc:	number of a VC
 *
 * cyclevc allows you to switch VCs by "hand". If it detects a VC which
 * is not on its list of "switched" VCs, it will not switch out of that
 * VC. But it will check again <sleep> seconds later. If by then one of
 * the switched VCs is on the screen, switching will resume at that position
 * in the list..
 * This will allow you to run a number of monitoring programs in their own
 * VCs, and still let you flip to another VC for maintenance, without 
 * cyclevc pulling that VC from under your fingers :-)
 *
 * If you start the monitors from /etc/rc.d/rc.local you might start this
 *	right after them...
 *
 *	Example: On my production servers I start (from inittab)
 * 		top 		in /dev/tty7 and 
 *		procinfo 	in /dev/tty6
 *	in /etc/rc.d/rc.local I say:
 *		nohup /usr/local/bin/cyclevc 15 6 7 2>/dev/null &
 *
 * Written and tested on kernels in the 1.3.6x and 1.3.7x range...
 *
 * Wishlist:
 *	proper options/cmdline processing
 *	a list of VCs which shall not be switched away from
 *	a mode to find all active VCs automatically and add them to the list
 *	a way to suspend/resume switching, even if another program is displayed
 *		on the current console(is this possible?)
 *	a status screen, which allows control of cyclevc, maybe just one or
 *		two lines a la splitvt. Thus the real program would run on top, and
 *		one could control the switching from the status line below..
 *	a guarantee that the ioctl won't change :-)
 *
 * This program is free. Use it but don't abuse it. Enjoy
 * There is no guarantee/warrantee/whatever  for this, none whatsoever. 
 * Use at your own risk..
 *
 * 1996 Mathias Koerber <mathias@singnet.com.sg>
 */

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/vt.h>
#include <errno.h>
#include <getopt.h>

int main(argc, argv)
	int	argc;
	char	*argv[];
{
	int		fd;
	int		cc;
	struct vt_stat	state;
	int		*vc,*array;
	int		numvc;
	int		i, j;
	int		sleeptime;	

	if (argc < 3) {
		fprintf(stderr,"usage: cyclevc <sleep> <vc> <vc> ...\n");
		exit(2);
		}

	sleeptime = atoi(argv[1]);
	numvc = argc - 2;

	array = (int *)malloc(numvc*(sizeof(int)));
	for (i = 0; i < numvc; i++) {
		array[i] = atoi(argv[i+2]);
		}
	
	if ((fd = open("/dev/console",O_RDWR|O_NOCTTY)) == -1) {
		fprintf(stderr,"could not open /dev/console. %d %s\n",errno,sys_errlist[errno]);
		exit(1);
		}

	i = 0;

	/* loop now */
	while (1) {
		
		/* first lets find out which VC we're on */
		if ((cc = ioctl(fd,VT_GETSTATE,&state)) == -1) {
			fprintf(stderr,"could not get VT state... %d %s\n",errno,sys_errlist[errno]);
			exit(1);
			}

		/* check whether we are in one of the switched VCs */
		for (j = 0; j < numvc; j++) {
			if (state.v_active == array[j]) {
				i = j+1; /* yes, make that the current one and break out */
				break;
				}
			}
		/* if we're not on a switched VC, j == numvc ! */

		if (i == numvc) i = 0; /* wrap around if last in list reached */
			
		/* now switch to next console in list if we were in a switched vc (j < numvc) */
		if ((j < numvc) && 
		    ((cc = ioctl(fd,VT_ACTIVATE,array[i])) == -1)) {
			fprintf(stderr,"could not activate VC %d... %d %s\n",array[i],errno,sys_errlist[errno]);
			exit(1);
			}

		sleep(sleeptime);
		i++;
	}


}






-----BEGIN PGP SIGNATURE-----
Version: 2.6.2i

iQCVAwUBMW94y4QRll5MupLRAQEmrQQAmhzzCYiVq0AYRlexij0sRTg9Nw4uVr+4
uk6debvO0spZy1Ij4dmtO7eXvwp7HTWFBJgsemoD8NK5rYJF9gpHJX+DNGLbsAFS
c1ABl0J+vrIGubvhuFK10OzUMQfMAs0wThWeqExWXuAv1T2+wWPwpL2nMlCbwto4
/JWwl/+RTDA=
=8gQA
-----END PGP SIGNATURE-----

-- 
This article has been digitally signed by the moderator, using PGP.
Finger wirzeniu@kruuna.helsinki.fi for PGP key needed for validating signature.
Send submissions for comp.os.linux.announce to: linux-announce@news.ornl.gov
PLEASE remember a short description of the software and the LOCATION.



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1996-04-13  4:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-04-13  4:00 SOURCE: cyclevc - a small tool to auto-cycle through VCs Mathias Koerber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox