Blame exp_console.c

Packit a69f91
/* exp_console.c - grab console.  This stuff is in a separate file to
Packit a69f91
avoid unpleasantness of AIX (3.2.4) .h files which provide no way to
Packit a69f91
reference TIOCCONS and include both sys/ioctl.h and sys/sys/stropts.h
Packit a69f91
without getting some sort of warning from the compiler.  The problem
Packit a69f91
is that both define _IO but only ioctl.h checks to see if it is
Packit a69f91
defined first.  This would suggest that it is sufficient to include
Packit a69f91
ioctl.h after stropts.h.  Unfortunately, ioctl.h, having seen that _IO
Packit a69f91
is defined, then fails to define other important things (like _IOW).
Packit a69f91
Packit a69f91
Written by: Don Libes, NIST, 2/6/90
Packit a69f91
Packit a69f91
Design and implementation of this program was paid for by U.S. tax
Packit a69f91
dollars.  Therefore it is public domain.  However, the author and NIST
Packit a69f91
would appreciate credit if this program or parts of it are used.
Packit a69f91
*/
Packit a69f91
Packit a69f91
#include "expect_cf.h"
Packit a69f91
#include <stdio.h>
Packit a69f91
#include <sys/types.h>
Packit a69f91
#include <sys/ioctl.h>
Packit a69f91
Packit a69f91
/* Solaris needs this for console redir */
Packit a69f91
#ifdef HAVE_STRREDIR_H
Packit a69f91
#include <sys/strredir.h>
Packit a69f91
# ifdef SRIOCSREDIR
Packit a69f91
#  undef TIOCCONS
Packit a69f91
# endif
Packit a69f91
#endif
Packit a69f91
Packit a69f91
#ifdef HAVE_SYS_FCNTL_H
Packit a69f91
#include <sys/fcntl.h>
Packit a69f91
#endif
Packit a69f91
Packit a69f91
#include "tcl.h"
Packit a69f91
#include "exp_rename.h"
Packit a69f91
#include "exp_prog.h"
Packit a69f91
#include "exp_command.h"
Packit a69f91
#include "exp_log.h"
Packit a69f91
Packit a69f91
static void
Packit a69f91
exp_console_manipulation_failed(s)
Packit a69f91
char *s;
Packit a69f91
{
Packit a69f91
    expErrorLog("expect: spawn: cannot %s console, check permissions of /dev/console\n",s);
Packit a69f91
    exit(-1);
Packit a69f91
}
Packit a69f91
Packit a69f91
void
Packit a69f91
exp_console_set()
Packit a69f91
{
Packit a69f91
#ifdef SRIOCSREDIR
Packit a69f91
	int fd;
Packit a69f91
Packit a69f91
	if ((fd = open("/dev/console", O_RDONLY)) == -1) {
Packit a69f91
		exp_console_manipulation_failed("open");
Packit a69f91
	}
Packit a69f91
	if (ioctl(fd, SRIOCSREDIR, 0) == -1) {
Packit a69f91
		exp_console_manipulation_failed("redirect");
Packit a69f91
	}
Packit a69f91
	close(fd);
Packit a69f91
#endif
Packit a69f91
Packit a69f91
#ifdef TIOCCONS
Packit a69f91
	int on = 1;
Packit a69f91
Packit a69f91
	if (ioctl(0,TIOCCONS,(char *)&on) == -1) {
Packit a69f91
		exp_console_manipulation_failed("redirect");
Packit a69f91
	}
Packit a69f91
#endif /*TIOCCONS*/
Packit a69f91
}