]>
Commit | Line | Data |
---|---|---|
00196ec7 AM |
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> | |
01eacb48 AM |
14 | #include <stdio.h> |
15 | #include <string.h> | |
00196ec7 | 16 | #include <unistd.h> |
01eacb48 AM |
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; | |
00196ec7 AM |
24 | char *type; |
25 | int maj, min, ret = 0, fg = -1; | |
01eacb48 | 26 | struct stat sb; |
00196ec7 | 27 | |
01eacb48 AM |
28 | fstat(0, &sb); |
29 | maj = major(sb.st_rdev); | |
00196ec7 | 30 | min = minor(sb.st_rdev); |
01eacb48 | 31 | if (maj != 3 && (maj < 136 || maj > 143)) { |
00196ec7 AM |
32 | if ((fg = ioctl (0, TIOCLINUX, &twelve)) < 0) { |
33 | type = "serial"; | |
34 | ret = 1; | |
01eacb48 | 35 | } else { |
00196ec7 AM |
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 | |
01eacb48 AM |
53 | } |
54 | } else { | |
00196ec7 AM |
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; | |
01eacb48 AM |
65 | } |
66 | } |