aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile4
-rw-r--r--src/consoletype.128
-rw-r--r--src/consoletype.c27
3 files changed, 58 insertions, 1 deletions
diff --git a/src/Makefile b/src/Makefile
index b312a08b..e21aa10e 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,7 +1,7 @@
CFLAGS+=-Wall -D_GNU_SOURCE -g
PROGS=usernetctl doexec netreport testd usleep ipcalc initlog minilogd \
- getkey ppp-watch
+ getkey ppp-watch consoletype
PPPWATCH_OBJS=ppp-watch.o shvar.o
INITLOG_OBJS=initlog.o process.o
USLEEP_OBJS=usleep.o
@@ -22,12 +22,14 @@ install:
install -s -m 755 minilogd $(ROOT)/sbin/minilogd
install -s -m 755 getkey $(ROOT)/sbin/getkey
install -s -m 755 ppp-watch $(ROOT)/sbin/ppp-watch
+ install -s -m 755 consoletype $(ROOT)/sbin/consoletype
install -m 644 initlog.1 $(ROOT)/usr/man/man1
install -m 644 doexec.1 $(ROOT)/usr/man/man1
install -m 644 netreport.1 $(ROOT)/usr/man/man1
install -m 644 usleep.1 $(ROOT)/usr/man/man1
install -m 644 usernetctl.1 $(ROOT)/usr/man/man1
install -m 644 ipcalc.1 $(ROOT)/usr/man/man1
+ install -m 644 consoletype.1 $(ROOT)/usr/man/man1
install -m 644 initlog.conf $(ROOT)/etc
# this daemon and initscript are useful for testing the up/down/status stuff
diff --git a/src/consoletype.1 b/src/consoletype.1
new file mode 100644
index 00000000..b14b03b0
--- /dev/null
+++ b/src/consoletype.1
@@ -0,0 +1,28 @@
+.TH CONSOLETYPE 1 "Red Hat Software" "RHS" \" -*- nroff -*-
+.SH NAME
+.B consoletype
+\- print type of the console connected to standard input
+.SH SYNOPSIS
+.B consoletype
+.SH DESCRIPTION
+.B consoletype
+prints the type of console connected to standard input. It prints
+.I vt
+if console is a virtual terminal (/dev/tty* or /dev/console device if not on
+a serial console),
+.I serial
+if standard input is a serial console (/dev/console or /dev/ttyS*) and
+.I pty
+if standard input is a pseudo terminal.
+.SH RETURN VALUE
+.B consoletype
+returns
+.TP
+.I 0
+if on virtual terminal
+.TP
+.I 1
+if on serial console
+.TP
+.I 2
+if on a pseudo terminal.
diff --git a/src/consoletype.c b/src/consoletype.c
new file mode 100644
index 00000000..6bfda4bd
--- /dev/null
+++ b/src/consoletype.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/sysmacros.h>
+
+int main(int argc, char **argv)
+{
+ unsigned char twelve = 12;
+ int maj;
+ struct stat sb;
+
+ fstat(0, &sb);
+ maj = major(sb.st_rdev);
+ if (maj != 3 && (maj < 136 || maj > 143)) {
+ if (ioctl (0, TIOCLINUX, &twelve) < 0) {
+ printf ("serial\n");
+ return 1;
+ } else {
+ printf ("vt\n");
+ return 0;
+ }
+ } else {
+ printf ("pty\n");
+ return 2;
+ }
+}