aboutsummaryrefslogtreecommitdiffstats
path: root/src/consoletype.c
diff options
context:
space:
mode:
authorBill Nottingham <notting@redhat.com>2003-07-08 20:15:34 +0000
committerBill Nottingham <notting@redhat.com>2003-07-08 20:15:34 +0000
commit9c51f7ea621bd202c58a44a61772acf97c8a48c0 (patch)
treecb8b26db2c058275ad1d992e62037ae9662d132a /src/consoletype.c
parent5ee4ea5c44a5e916c08e8063d587b9ff11c98f04 (diff)
downloadinitscripts-9c51f7ea621bd202c58a44a61772acf97c8a48c0.tar
initscripts-9c51f7ea621bd202c58a44a61772acf97c8a48c0.tar.gz
initscripts-9c51f7ea621bd202c58a44a61772acf97c8a48c0.tar.bz2
initscripts-9c51f7ea621bd202c58a44a61772acf97c8a48c0.tar.xz
initscripts-9c51f7ea621bd202c58a44a61772acf97c8a48c0.zip
add a test to consoletype to test that we're the current foreground
console
Diffstat (limited to 'src/consoletype.c')
-rw-r--r--src/consoletype.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/consoletype.c b/src/consoletype.c
index 6bfda4bd..1ce98901 100644
--- a/src/consoletype.c
+++ b/src/consoletype.c
@@ -7,21 +7,31 @@
int main(int argc, char **argv)
{
unsigned char twelve = 12;
- int maj;
+ char *type;
+ int maj, min, ret = 0, fg = -1;
struct stat sb;
-
+
fstat(0, &sb);
maj = major(sb.st_rdev);
+ min = minor(sb.st_rdev);
if (maj != 3 && (maj < 136 || maj > 143)) {
- if (ioctl (0, TIOCLINUX, &twelve) < 0) {
- printf ("serial\n");
- return 1;
+ if ((fg = ioctl (0, TIOCLINUX, &twelve)) < 0) {
+ type = "serial";
+ ret = 1;
} else {
- printf ("vt\n");
- return 0;
+ type = "vt";
+ ret = 0;
}
} else {
- printf ("pty\n");
- return 2;
+ type = "pty";
+ ret = 2;
+ }
+ if (argc > 1 && !strcmp(argv[1],"fg")) {
+ if (fg < 0 || fg != (min-1))
+ return 1;
+ return 0;
+ } else {
+ printf("%s\n",type);
+ return ret;
}
}