#include "expect_cf.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#ifdef HAVE_STRREDIR_H
#include <sys/strredir.h>
# ifdef SRIOCSREDIR
# undef TIOCCONS
# endif
#endif
#ifdef HAVE_SYS_FCNTL_H
#include <sys/fcntl.h>
#endif
#include "tcl.h"
#include "exp_rename.h"
#include "exp_prog.h"
#include "exp_log.h"
static void
exp_console_manipulation_failed(s)
char *s;
{
exp_errorlog("expect: spawn: cannot %s console, check permissions of /dev/console\n",s);
exit(-1);
}
void
exp_console_set()
{
#ifdef SRIOCSREDIR
int fd;
if ((fd = open("/dev/console", O_RDONLY)) == -1) {
exp_console_manipulation_failed("open");
}
if (ioctl(fd, SRIOCSREDIR, 0) == -1) {
exp_console_manipulation_failed("redirect");
}
close(fd);
#endif
#ifdef TIOCCONS
int on = 1;
if (ioctl(0,TIOCCONS,(char *)&on) == -1) {
exp_console_manipulation_failed("redirect");
}
#endif
}