openvt utility build with src/getfd.c.
authorAlexey Gladkov <legion@altlinux.org>
Sat, 10 Feb 2007 16:31:36 +0000 (19:31 +0300)
committerAlexey Gladkov <legion@altlinux.org>
Sat, 10 Feb 2007 16:31:36 +0000 (19:31 +0300)
Signed-off-by: Alexey Gladkov <legion@altlinux.org>
openvt/Makefile
openvt/getfd.c [deleted file]
openvt/openvt.c
openvt/openvt.h
po/POTFILES.in

index 1eec2c7..3180c47 100644 (file)
@@ -1,11 +1,11 @@
 
 CC=gcc
 RPM_OPT_FLAGS=-O2 -Wall -ansi
-CFLAGS=$(RPM_OPT_FLAGS)
+CFLAGS=$(RPM_OPT_FLAGS) -I../src
 LDFLAGS=$(CFLAGS) -s 
 
 SRC=openvt.c
-OBJ=openvt.o getfd.o
+OBJ=openvt.o ../src/getfd.o
 PROG=openvt
 PROGS=$(PROG)
 MAN=openvt.1
diff --git a/openvt/getfd.c b/openvt/getfd.c
deleted file mode 100644 (file)
index 9dbe15c..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-#include <stdio.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <linux/kd.h>
-#include <sys/ioctl.h>
-
-/*
- * getfd.c
- *
- * Get an fd for use with kbd/console ioctls.
- * We try several things because opening /dev/console will fail
- * if someone else used X (which does a chown on /dev/console).
- */
-
-static int
-is_a_console(int fd) {
-    char arg;
-
-    arg = 0;
-    return (ioctl(fd, KDGKBTYPE, &arg) == 0
-           && ((arg == KB_101) || (arg == KB_84)));
-}
-
-static int
-open_a_console(char *fnam) {
-    int fd;
-
-    fd = open(fnam, O_RDONLY);
-    if (fd < 0 && errno == EACCES)
-      fd = open(fnam, O_WRONLY);
-    if (fd < 0 || ! is_a_console(fd))
-      return -1;
-    return fd;
-}
-
-int getfd() {
-    int fd;
-
-    fd = open_a_console("/dev/tty");
-    if (fd >= 0)
-      return fd;
-
-    fd = open_a_console("/dev/console");
-    if (fd >= 0)
-      return fd;
-
-    for (fd = 0; fd < 3; fd++)
-      if (is_a_console(fd))
-       return fd;
-
-    return -1;
-}
index 92d904d..f7753f4 100644 (file)
@@ -104,7 +104,7 @@ main(int argc, char *argv[])
       }
    }
 
-   consfd = getfd();
+   consfd = getfd(NULL);
    if (consfd < 0) {
       fprintf(stderr,
              _("Couldnt get a file descriptor referring to the console\n"));
index 54baeb5..166703c 100644 (file)
 #include <sys/types.h>
 #include <sys/wait.h>
 
+#include "getfd.h"
+
 #ifndef NAME_MAX
 #define NAME_MAX 255
 #endif
 
 void usage(int);
 char *authenticate_user(int);
-int getfd(void);
 
 /*
  * There must be a universal way to find these!
index 6cd5cf7..314d553 100644 (file)
@@ -2,7 +2,6 @@ contrib/codepage.c
 contrib/splitfont.c
 contrib/sti.c
 contrib/vcstime.c
-openvt/getfd.c
 openvt/openvt.c
 po/cat-id-tbl.c
 src/chvt.c