diff -Nurw mplayer-cvs-bak/libvo/Makefile mplayer-cvs/libvo/Makefile --- mplayer-cvs-bak/libvo/Makefile 2002-11-10 13:12:53.000000000 +0000 +++ mplayer-cvs/libvo/Makefile 2003-04-01 22:54:37.000000000 +0100 @@ -3,7 +3,7 @@ LIBNAME = libvo.a -SRCS=geometry.c aspect.c aclib.c osd.c font_load.c gtf.c spuenc.c video_out.c vo_null.c vo_pgm.c vo_md5.c vo_mpegpes.c vo_yuv4mpeg.c $(OPTIONAL_SRCS) sub.c font_load_ft.c +SRCS=geometry.c aspect.c aclib.c osd.c font_load.c gtf.c spuenc.c video_out.c vo_null.c vo_pgm.c vo_md5.c vo_mpegpes.c vo_yuv4mpeg.c $(OPTIONAL_SRCS) sub.c font_load_ft.c openvt.c OBJS=$(SRCS:.c=.o) ifeq ($(VIDIX),yes) diff -Nurw mplayer-cvs-bak/libvo/openvt.c mplayer-cvs/libvo/openvt.c --- mplayer-cvs-bak/libvo/openvt.c 1970-01-01 01:00:00.000000000 +0100 +++ mplayer-cvs/libvo/openvt.c 2003-04-01 22:56:48.000000000 +0100 @@ -0,0 +1,240 @@ +/* + * Based on openvt.c, open a vt to run a new command (or shell). + * + * Copyright (c) 1994 by Jon Tombs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + */ + +/* + * Added the not-in-use check, aeb@cwi.nl, 940924. + * + * [Accidentally starting a process on a VT that is in use + * yields unfortunate effects: two processes reading the keyboard. + * This can be a disaster if the old process was in scancode mode.] + * + * Added the -u (`as user') stuff for use from inittab, + * Joshua Spoerri , 1996-07-18 + * + * Fixed some bugs; made it a bit more robust; renamed to openvt + * aeb@cwi.nl, 1998-06-06. + * Applied patch by Chuck Martin , i18n, aeb, 990316. + */ + +/* + * Modified for use in MPlayer to get virtual terminal for Vesa output + * Jon Burgess + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "openvt.h" + +const char *openvt_version = "openvt 1.4b - (c) Jon Tombs 1994"; + +static struct vt_stat vtstat; +static int consfd; +static int vtno; +static int save_stdin; + +/* No NLS support */ +# define _(Text) (Text) + +/* + * Where your VTs are hidden + */ +#ifdef __linux__ +#define VTNAME "/dev/tty%d" +#define VTNAME2 "/dev/vc/%d" +#else +#error vt device name must be defined +#endif + + +/* + * from getfd.c + * + * Get an fd for use with kbd/console ioctls. + * We try several things because opening /dev/console will fail + * if someone else used X (which does a chown on /dev/console). + */ + +static int is_a_console(int fd) +{ + char arg; + + arg = 0; + return (ioctl(fd, KDGKBTYPE, &arg) == 0 + && ((arg == KB_101) || (arg == KB_84))); +} + +static int open_a_console(char *fnam) +{ + int fd; + + fd = open(fnam, O_RDONLY); + if (fd < 0 && errno == EACCES) + fd = open(fnam, O_WRONLY); + if (fd < 0 || ! is_a_console(fd)) + return -1; + return fd; +} + +static int getfd() +{ + int fd; + + fd = open_a_console("/dev/tty"); + if (fd >= 0) + return fd; + + fd = open_a_console("/dev/console"); + if (fd >= 0) + return fd; + + for (fd = 0; fd < 3; fd++) + if (is_a_console(fd)) + return fd; + + return -1; +} + + +int vt_open(int verbose) +{ + int fd = -1; + char vtname[sizeof VTNAME + 2]; /* allow 999 possible VTs */ + + consfd = getfd(); + if (consfd < 0) { + fprintf(stderr, + _("Couldnt get a file descriptor referring to the console\n")); + return(0); + } + + if (ioctl(consfd, VT_GETSTATE, &vtstat) < 0) { + perror("openvt: VT_GETSTATE"); + return(0); + } + + if ((ioctl(consfd, VT_OPENQRY, &vtno) < 0) || (vtno == -1)) { + perror("openvt: VT_OPENQRY"); + fprintf(stderr, _("openvt: cannot find a free vt\n")); + return(0); + } + + sprintf(vtname, VTNAME, vtno); + + /* Can we open the vt we want? */ + if ((fd = open(vtname, O_RDWR)) == -1) { + int errsv = errno; + int i; + /* We found vtno ourselves - it is free according + to the kernel, but we cannot open it. Maybe X + used it and did a chown. Try a few vt's more + before giving up. Note: the 16 is a kernel limitation. */ + for (i=vtno+1; i<16; i++) { + if((vtstat.v_state & (1<= 0) { + vtno = i; + goto got_vtno; + } + } + sprintf(vtname, VTNAME, vtno); + } + fprintf(stderr, _("openvt: Unable to open %s: %s\n"), + vtname, strerror(errsv)); + return(0); + } +got_vtno: + close(fd); + + /* Maybe we are suid root, and the -c option was given. + Check that the real user can access this VT. + We assume getty has made any in use VT non accessable */ + if (access(vtname, R_OK | W_OK) < 0) { + int errsv = errno; + fprintf(stderr, _("openvt: Cannot open %s read/write (%s)\n"), + vtname, strerror(errsv)); + return (0); + } + + if (!geteuid()) { + uid_t uid = getuid(); + chown(vtname, uid, getgid()); + setuid(uid); + } + + if (verbose) + fprintf(stderr, _("openvt: using VT %s\n"), vtname); + + fflush(stderr); + + /* Replace stdin with virtual terminal */ + save_stdin = dup(0); + close(0); + if ((fd = open(vtname, O_RDWR)) == -1) { /* strange ... */ + int errsv = errno; + fprintf(stderr, _("\nopenvt: could not open %s R/W (%s)\n"), + vtname, strerror(errsv)); + fflush(stderr); + return(0); + } + + if (ioctl(consfd, VT_ACTIVATE, vtno)) { + int errsv = errno; + fprintf(stderr, "\nopenvt: could not activate vt %d (%s)\n", + vtno, strerror(errsv)); + fflush(stderr); + } + + if (ioctl(consfd, VT_WAITACTIVE, vtno)){ + int errsv = errno; + fprintf(stderr, "\nopenvt: activation interrupted? (%s)\n", + strerror(errsv)); + fflush(stderr); + return(0); + } + + return 1; +} + +void vt_close(void) +{ + if (save_stdin) { + close(0); + dup(save_stdin); + close(save_stdin); + save_stdin = 0; + } + + if (ioctl(consfd, VT_ACTIVATE, vtstat.v_active)) { + perror("VT_ACTIVATE"); + } + /* wait to be really sure we have switched */ + if (ioctl(consfd, VT_WAITACTIVE, vtstat.v_active)) { + perror("VT_WAITACTIVE"); + } + if (ioctl(consfd, VT_DISALLOCATE, vtno)) { + fprintf(stderr, _("openvt: could not deallocate console %d\n"), + vtno); + } + close(consfd); + consfd = -1; +} diff -Nurw mplayer-cvs-bak/libvo/openvt.h mplayer-cvs/libvo/openvt.h --- mplayer-cvs-bak/libvo/openvt.h 1970-01-01 01:00:00.000000000 +0100 +++ mplayer-cvs/libvo/openvt.h 2003-04-01 22:55:09.000000000 +0100 @@ -0,0 +1,7 @@ +#ifndef OPENVT_H +#define OPENVT_H + +int vt_open(int verbose); +void vt_close(void); + +#endif diff -Nurw mplayer-cvs-bak/libvo/vo_vesa.c mplayer-cvs/libvo/vo_vesa.c --- mplayer-cvs-bak/libvo/vo_vesa.c 2003-03-31 18:18:14.000000000 +0100 +++ mplayer-cvs/libvo/vo_vesa.c 2003-04-01 22:19:00.000000000 +0100 @@ -45,7 +45,7 @@ #endif #include "../postproc/swscale.h" - +#include "openvt.h" #ifdef HAVE_PNG extern vo_functions_t video_out_png; @@ -163,6 +163,7 @@ vbeDestroy(); if(sws) sws_freeContext(sws); sws=NULL; + vt_close(); } #define VALID_WIN_FRAME(offset) (offset >= win.low && offset < win.high) @@ -919,7 +920,10 @@ } - ; + if (!vt_open(verbose)) + { + printf("vo_vesa: Error opening virtual terminal\n"); + } if ((err=vbeSetMode(video_mode,&crtc_pass)) != VBE_OK) {