Fix compile error and reducing size for libbb/get_console.c to previous size.
Vodz last_patch106
This commit is contained in:
parent
d9461f887e
commit
005f83adf5
@ -2,8 +2,8 @@
|
|||||||
/*
|
/*
|
||||||
* Utility routines.
|
* Utility routines.
|
||||||
*
|
*
|
||||||
* Copyright (C) many different people.
|
* Copyright (C) many different people. If you wrote this, please
|
||||||
* If you wrote this, please acknowledge your work.
|
* acknowledge your work.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -29,27 +29,15 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* From <linux/kd.h> */
|
/* From <linux/kd.h> */
|
||||||
static const int KDGKBTYPE = 0x4B33; /* get keyboard type */
|
static const int KDGKBTYPE = 0x4B33; /* get keyboard type */
|
||||||
static const int KB_84 = 0x01;
|
|
||||||
static const int KB_101 = 0x02; /* this is what we always answer */
|
|
||||||
|
|
||||||
static int is_a_console(int fd)
|
|
||||||
{
|
|
||||||
char arg;
|
|
||||||
|
|
||||||
arg = 0;
|
static int open_a_console(const char *fnam)
|
||||||
return (ioctl(fd, KDGKBTYPE, &arg) == 0
|
|
||||||
&& ((arg == KB_101) || (arg == KB_84)));
|
|
||||||
}
|
|
||||||
|
|
||||||
static int open_a_console(char *fnam)
|
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
/* try read-only */
|
/* try read-write */
|
||||||
fd = open(fnam, O_RDWR);
|
fd = open(fnam, O_RDWR);
|
||||||
|
|
||||||
/* if failed, try read-only */
|
/* if failed, try read-only */
|
||||||
@ -60,17 +48,6 @@ static int open_a_console(char *fnam)
|
|||||||
if (fd < 0 && errno == EACCES)
|
if (fd < 0 && errno == EACCES)
|
||||||
fd = open(fnam, O_WRONLY);
|
fd = open(fnam, O_WRONLY);
|
||||||
|
|
||||||
/* if failed, fail */
|
|
||||||
if (fd < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
/* if not a console, fail */
|
|
||||||
if (!is_a_console(fd)) {
|
|
||||||
close(fd);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* success */
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,32 +55,37 @@ static int open_a_console(char *fnam)
|
|||||||
* Get an fd for use with kbd/console ioctls.
|
* Get an fd for use with kbd/console ioctls.
|
||||||
* We try several things because opening /dev/console will fail
|
* We try several things because opening /dev/console will fail
|
||||||
* if someone else used X (which does a chown on /dev/console).
|
* if someone else used X (which does a chown on /dev/console).
|
||||||
*
|
|
||||||
* if tty_name is non-NULL, try this one instead.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int get_console_fd(void)
|
int get_console_fd(void)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
fd = open_a_console(CURRENT_TTY);
|
static const char * const choise_console_names[] = {
|
||||||
if (fd >= 0)
|
CONSOLE_DEV, CURRENT_VC, CURRENT_TTY
|
||||||
return fd;
|
};
|
||||||
|
|
||||||
fd = open_a_console(CURRENT_VC);
|
for (fd = 2; fd >= 0; fd--) {
|
||||||
if (fd >= 0)
|
int fd4name;
|
||||||
return fd;
|
int choise_fd;
|
||||||
|
char arg;
|
||||||
|
|
||||||
fd = open_a_console(CONSOLE_DEV);
|
fd4name = open_a_console(choise_console_names[fd]);
|
||||||
if (fd >= 0)
|
chk_std:
|
||||||
return fd;
|
choise_fd = fd4name >= 0 ? fd4name : fd;
|
||||||
|
|
||||||
for (fd = 0; fd < 3; fd++)
|
arg = 0;
|
||||||
if (is_a_console(fd))
|
if (ioctl(choise_fd, KDGKBTYPE, &arg) == 0)
|
||||||
return fd;
|
return choise_fd;
|
||||||
|
if(fd4name >= 0) {
|
||||||
|
close(fd4name);
|
||||||
|
fd4name = -1;
|
||||||
|
goto chk_std;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bb_error_msg("Couldn't get a file descriptor referring to the console");
|
bb_error_msg("Couldn't get a file descriptor referring to the console");
|
||||||
return -1; /* total failure */
|
return fd; /* total failure */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -5628,7 +5628,7 @@ expmeta(char *enddir, char *name)
|
|||||||
char *start;
|
char *start;
|
||||||
char *endname;
|
char *endname;
|
||||||
int metaflag;
|
int metaflag;
|
||||||
struct stat64 statb;
|
struct stat statb;
|
||||||
DIR *dirp;
|
DIR *dirp;
|
||||||
struct dirent *dp;
|
struct dirent *dp;
|
||||||
int atend;
|
int atend;
|
||||||
@ -5671,7 +5671,7 @@ out:
|
|||||||
p++;
|
p++;
|
||||||
*enddir++ = *p;
|
*enddir++ = *p;
|
||||||
} while (*p++);
|
} while (*p++);
|
||||||
if (metaflag == 0 || lstat64(expdir, &statb) >= 0)
|
if (metaflag == 0 || lstat(expdir, &statb) >= 0)
|
||||||
addfname(expdir);
|
addfname(expdir);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user