]> TLD Linux GIT Repositories - rc-scripts.git/blob - src/consoletype.c
- from PLD
[rc-scripts.git] / src / consoletype.c
1 /*
2  * Copyright (c) 1999-2003 Red Hat, Inc. All rights reserved.
3  *
4  * This software may be freely redistributed under the terms of the GNU
5  * public license.
6  *
7  * You should have received a copy of the GNU General Public License
8  * along with this program; if not, write to the Free Software
9  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
10  *
11  */
12
13 #include <fcntl.h>
14 #include <stdio.h>
15 #include <string.h>
16 #include <unistd.h>
17 #include <sys/ioctl.h>
18 #include <sys/stat.h>
19 #include <sys/sysmacros.h>
20
21 int main(int argc, char **argv)
22 {
23     unsigned char twelve = 12;
24     char *type;
25     int maj, min, ret = 0, fg = -1;
26     struct stat sb;
27         
28     fstat(0, &sb);
29     maj = major(sb.st_rdev);
30     min = minor(sb.st_rdev);
31     if (maj != 3 && (maj < 136 || maj > 143)) {
32         if ((fg = ioctl (0, TIOCLINUX, &twelve)) < 0) {
33             type = "serial";
34             ret = 1;
35         } else {
36 #ifdef __powerpc__
37             int fd;
38             char buf[65536];
39             
40             fd = open("/proc/tty/drivers",O_RDONLY);
41             read(fd, buf, 65535);
42             if (strstr(buf,"vioconsole           /dev/tty")) {
43                     type = "vio";
44                     ret = 3;
45             } else {
46                     type = "vt";
47                     ret = 0;
48             }
49 #else
50             type = "vt";
51             ret = 0;
52 #endif
53         }
54     } else {
55         type = "pty";
56         ret = 2;
57     }
58     if (argc > 1 && !strcmp(argv[1],"fg")) {
59             if (fg < 0 || fg != (min-1))
60                     return 1;
61             return 0;
62     } else {
63             printf("%s\n",type);
64             return ret;
65     }
66