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

Re: how to know the real device used by /dev/console ?



Eric Delaunay wrote:
>   is there a way (an ioctl or such) to get the real device connected to
> /dev/console ?  Especially, I need to know whether the console is connected to
> a serial one or not.

See attached code.

/* Prints the number of the current VC to stdout. Most of this code
 * was ripped from the open program, and this code is GPL'd
 *
 * Joey Hess, Fri Apr  4 14:58:50 EST 1997
 */

#include <sys/vt.h>
#include <fcntl.h>

main () {
	int fd = 0;
	struct vt_stat vt;
	
	if ((fd = open("/dev/console",O_WRONLY,0)) < 0) {
		perror("Failed to open /dev/console\n");
		return(2);
	}
	if (ioctl(fd, VT_GETSTATE, &vt) < 0) {
		perror("can't get VTstate\n");
		close(fd);
		return(4);
	}
	printf("%d\n",vt.v_active);
}

-- 
see shy jo


Reply to: