aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277>2003-09-01 08:53:32 +0000
committerbug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277>2003-09-01 08:53:32 +0000
commit253ff43f62644ee79597eed14b49dcf291f198a1 (patch)
tree0b6c4e7e592bb6f150be66ec072002d2e85fd4dc
parent64c7e422387452d3f3597ced29c936a4f49beead (diff)
downloadbusybox-w32-253ff43f62644ee79597eed14b49dcf291f198a1.tar.gz
busybox-w32-253ff43f62644ee79597eed14b49dcf291f198a1.tar.bz2
busybox-w32-253ff43f62644ee79597eed14b49dcf291f198a1.zip
Fix compile error and reducing size for libbb/get_console.c to previous size.
Vodz last_patch106 git-svn-id: svn://busybox.net/trunk/busybox@7345 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--libbb/get_console.c72
-rw-r--r--shell/ash.c4
2 files changed, 29 insertions, 47 deletions
diff --git a/libbb/get_console.c b/libbb/get_console.c
index 9eb4190a9..0dc24cb78 100644
--- a/libbb/get_console.c
+++ b/libbb/get_console.c
@@ -2,8 +2,8 @@
2/* 2/*
3 * Utility routines. 3 * Utility routines.
4 * 4 *
5 * Copyright (C) many different people. 5 * Copyright (C) many different people. If you wrote this, please
6 * If you wrote this, please acknowledge your work. 6 * acknowledge your work.
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
@@ -29,27 +29,15 @@
29 29
30 30
31 31
32
33
34/* From <linux/kd.h> */ 32/* From <linux/kd.h> */
35static const int KDGKBTYPE = 0x4B33; /* get keyboard type */ 33static const int KDGKBTYPE = 0x4B33; /* get keyboard type */
36static const int KB_84 = 0x01;
37static const int KB_101 = 0x02; /* this is what we always answer */
38 34
39static int is_a_console(int fd)
40{
41 char arg;
42 35
43 arg = 0; 36static int open_a_console(const char *fnam)
44 return (ioctl(fd, KDGKBTYPE, &arg) == 0
45 && ((arg == KB_101) || (arg == KB_84)));
46}
47
48static int open_a_console(char *fnam)
49{ 37{
50 int fd; 38 int fd;
51 39
52 /* try read-only */ 40 /* try read-write */
53 fd = open(fnam, O_RDWR); 41 fd = open(fnam, O_RDWR);
54 42
55 /* if failed, try read-only */ 43 /* if failed, try read-only */
@@ -60,17 +48,6 @@ static int open_a_console(char *fnam)
60 if (fd < 0 && errno == EACCES) 48 if (fd < 0 && errno == EACCES)
61 fd = open(fnam, O_WRONLY); 49 fd = open(fnam, O_WRONLY);
62 50
63 /* if failed, fail */
64 if (fd < 0)
65 return -1;
66
67 /* if not a console, fail */
68 if (!is_a_console(fd)) {
69 close(fd);
70 return -1;
71 }
72
73 /* success */
74 return fd; 51 return fd;
75} 52}
76 53
@@ -78,32 +55,37 @@ static int open_a_console(char *fnam)
78 * Get an fd for use with kbd/console ioctls. 55 * Get an fd for use with kbd/console ioctls.
79 * We try several things because opening /dev/console will fail 56 * We try several things because opening /dev/console will fail
80 * if someone else used X (which does a chown on /dev/console). 57 * if someone else used X (which does a chown on /dev/console).
81 *
82 * if tty_name is non-NULL, try this one instead.
83 */ 58 */
84 59
85int get_console_fd(void) 60int get_console_fd(void)
86{ 61{
87 int fd; 62 int fd;
88 63
89 fd = open_a_console(CURRENT_TTY); 64 static const char * const choise_console_names[] = {
90 if (fd >= 0) 65 CONSOLE_DEV, CURRENT_VC, CURRENT_TTY
91 return fd; 66 };
92 67
93 fd = open_a_console(CURRENT_VC); 68 for (fd = 2; fd >= 0; fd--) {
94 if (fd >= 0) 69 int fd4name;
95 return fd; 70 int choise_fd;
96 71 char arg;
97 fd = open_a_console(CONSOLE_DEV); 72
98 if (fd >= 0) 73 fd4name = open_a_console(choise_console_names[fd]);
99 return fd; 74 chk_std:
100 75 choise_fd = fd4name >= 0 ? fd4name : fd;
101 for (fd = 0; fd < 3; fd++) 76
102 if (is_a_console(fd)) 77 arg = 0;
103 return fd; 78 if (ioctl(choise_fd, KDGKBTYPE, &arg) == 0)
79 return choise_fd;
80 if(fd4name >= 0) {
81 close(fd4name);
82 fd4name = -1;
83 goto chk_std;
84 }
85 }
104 86
105 bb_error_msg("Couldn't get a file descriptor referring to the console"); 87 bb_error_msg("Couldn't get a file descriptor referring to the console");
106 return -1; /* total failure */ 88 return fd; /* total failure */
107} 89}
108 90
109 91
diff --git a/shell/ash.c b/shell/ash.c
index ec33a106c..521d65ab6 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -5628,7 +5628,7 @@ expmeta(char *enddir, char *name)
5628 char *start; 5628 char *start;
5629 char *endname; 5629 char *endname;
5630 int metaflag; 5630 int metaflag;
5631 struct stat64 statb; 5631 struct stat statb;
5632 DIR *dirp; 5632 DIR *dirp;
5633 struct dirent *dp; 5633 struct dirent *dp;
5634 int atend; 5634 int atend;
@@ -5671,7 +5671,7 @@ out:
5671 p++; 5671 p++;
5672 *enddir++ = *p; 5672 *enddir++ = *p;
5673 } while (*p++); 5673 } while (*p++);
5674 if (metaflag == 0 || lstat64(expdir, &statb) >= 0) 5674 if (metaflag == 0 || lstat(expdir, &statb) >= 0)
5675 addfname(expdir); 5675 addfname(expdir);
5676 return; 5676 return;
5677 } 5677 }