mirror of
https://github.com/troglobit/finit.git
synced 2026-11-27 20:48:24 +00:00
tty_exist(): Simplify, no need to call access() and then open()
Found by Coverity Scan, classified as security issue but was just unnecessary overhead. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
11dd877484
commit
5c3a07e8e6
1 file changed
+4
-10
@@ -345,24 +345,18 @@ tty_node_t *tty_find_by_pid(pid_t pid)
|
|||||||
|
|
||||||
static int tty_exist(char *dev)
|
static int tty_exist(char *dev)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd, result;
|
||||||
struct termios c;
|
struct termios c;
|
||||||
|
|
||||||
if (access(dev, F_OK))
|
fd = open(dev, O_RDWR);
|
||||||
return 1;
|
|
||||||
|
|
||||||
fd = open(dev, O_RDONLY);
|
|
||||||
if (-1 == fd)
|
if (-1 == fd)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
/* XXX: Add check for errno == EIO? */
|
/* XXX: Add check for errno == EIO? */
|
||||||
if (tcgetattr(fd, &c)) {
|
result = tcgetattr(fd, &c);
|
||||||
close(fd);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
return 0;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tty_start(finit_tty_t *tty)
|
void tty_start(finit_tty_t *tty)
|
||||||
|
|||||||
Reference in new issue
Block a user