| 1 | /* |
|---|
| 2 | * Copyright (c) 1999-2003 Red Hat, Inc. All rights reserved. |
|---|
| 3 | * |
|---|
| 4 | * This program is free software; you can redistribute it and/or modify |
|---|
| 5 | * it under the terms of the GNU General Public License, version 2, |
|---|
| 6 | * as published by the Free Software Foundation. |
|---|
| 7 | * |
|---|
| 8 | * This program is distributed in the hope that it will be useful, |
|---|
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | * GNU General Public License for more details. |
|---|
| 12 | * |
|---|
| 13 | * You should have received a copy of the GNU General Public License |
|---|
| 14 | * along with this program; if not, write to the Free Software |
|---|
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|---|
| 16 | * |
|---|
| 17 | */ |
|---|
| 18 | |
|---|
| 19 | #include <fcntl.h> |
|---|
| 20 | #include <stdio.h> |
|---|
| 21 | #include <string.h> |
|---|
| 22 | #include <unistd.h> |
|---|
| 23 | #include <sys/ioctl.h> |
|---|
| 24 | #include <sys/stat.h> |
|---|
| 25 | #include <sys/sysmacros.h> |
|---|
| 26 | |
|---|
| 27 | int main(int argc, char **argv) |
|---|
| 28 | { |
|---|
| 29 | unsigned char twelve = 12; |
|---|
| 30 | char *type; |
|---|
| 31 | int maj, min, ret = 0, fg = -1; |
|---|
| 32 | struct stat sb; |
|---|
| 33 | |
|---|
| 34 | fstat(0, &sb); |
|---|
| 35 | maj = major(sb.st_rdev); |
|---|
| 36 | min = minor(sb.st_rdev); |
|---|
| 37 | if (maj != 3 && (maj < 136 || maj > 143)) { |
|---|
| 38 | if ((fg = ioctl (0, TIOCLINUX, &twelve)) < 0) { |
|---|
| 39 | type = "serial"; |
|---|
| 40 | ret = 1; |
|---|
| 41 | } else { |
|---|
| 42 | #ifdef __powerpc__ |
|---|
| 43 | int fd; |
|---|
| 44 | char buf[65536]; |
|---|
| 45 | |
|---|
| 46 | fd = open("/proc/tty/drivers",O_RDONLY); |
|---|
| 47 | read(fd, buf, 65535); |
|---|
| 48 | if (strstr(buf,"vioconsole /dev/tty")) { |
|---|
| 49 | type = "vio"; |
|---|
| 50 | ret = 3; |
|---|
| 51 | } else { |
|---|
| 52 | type = "vt"; |
|---|
| 53 | ret = 0; |
|---|
| 54 | } |
|---|
| 55 | #else |
|---|
| 56 | type = "vt"; |
|---|
| 57 | ret = 0; |
|---|
| 58 | #endif |
|---|
| 59 | } |
|---|
| 60 | } else { |
|---|
| 61 | type = "pty"; |
|---|
| 62 | ret = 2; |
|---|
| 63 | } |
|---|
| 64 | if (argc > 1 && !strcmp(argv[1],"fg")) { |
|---|
| 65 | if (fg < 0 || fg != (min-1)) |
|---|
| 66 | return 1; |
|---|
| 67 | return 0; |
|---|
| 68 | } else { |
|---|
| 69 | printf("%s\n",type); |
|---|
| 70 | return ret; |
|---|
| 71 | } |
|---|
| 72 | } |
|---|