resetting manifest requested domain to floor
[platform/upstream/expect.git] / exp_console.c
1 /* exp_console.c - grab console.  This stuff is in a separate file to
2 avoid unpleasantness of AIX (3.2.4) .h files which provide no way to
3 reference TIOCCONS and include both sys/ioctl.h and sys/sys/stropts.h
4 without getting some sort of warning from the compiler.  The problem
5 is that both define _IO but only ioctl.h checks to see if it is
6 defined first.  This would suggest that it is sufficient to include
7 ioctl.h after stropts.h.  Unfortunately, ioctl.h, having seen that _IO
8 is defined, then fails to define other important things (like _IOW).
9
10 Written by: Don Libes, NIST, 2/6/90
11
12 Design and implementation of this program was paid for by U.S. tax
13 dollars.  Therefore it is public domain.  However, the author and NIST
14 would appreciate credit if this program or parts of it are used.
15 */
16
17 #include "expect_cf.h"
18 #include <stdio.h>
19 #include <sys/types.h>
20 #include <sys/ioctl.h>
21
22 /* Solaris needs this for console redir */
23 #ifdef HAVE_STRREDIR_H
24 #include <sys/strredir.h>
25 # ifdef SRIOCSREDIR
26 #  undef TIOCCONS
27 # endif
28 #endif
29
30 #ifdef HAVE_SYS_FCNTL_H
31 #include <sys/fcntl.h>
32 #endif
33
34 #include "tcl.h"
35 #include "exp_rename.h"
36 #include "exp_prog.h"
37 #include "exp_command.h"
38 #include "exp_log.h"
39
40 static void
41 exp_console_manipulation_failed(s)
42 char *s;
43 {
44     expErrorLog("expect: spawn: cannot %s console, check permissions of /dev/console\n",s);
45     exit(-1);
46 }
47
48 void
49 exp_console_set()
50 {
51 #ifdef SRIOCSREDIR
52         int fd;
53
54         if ((fd = open("/dev/console", O_RDONLY)) == -1) {
55                 exp_console_manipulation_failed("open");
56         }
57         if (ioctl(fd, SRIOCSREDIR, 0) == -1) {
58                 exp_console_manipulation_failed("redirect");
59         }
60         close(fd);
61 #endif
62
63 #ifdef TIOCCONS
64         int on = 1;
65
66         if (ioctl(0,TIOCCONS,(char *)&on) == -1) {
67                 exp_console_manipulation_failed("redirect");
68         }
69 #endif /*TIOCCONS*/
70 }