ttytype(): Fix race
The intention of the code is just to not report an error message when 'typefile' doesn't exist. If we call access(2) and then fopen(2), there's a race. It's not a huge problem, and the worst thing that can happen is reporting an error when the file has been removed after access(2). It's not a problem, but we can fix the race and at the same time clarify the intention of not warning about ENOENT and also remove one syscall. Seems like a win-win. Suggested-by: Christian Göttsche <cgzones@googlemail.com> Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
parent
bddcd9b095
commit
5da8388fc6
@ -34,12 +34,10 @@ void ttytype (const char *line)
|
|||||||
if (NULL == typefile) {
|
if (NULL == typefile) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (access (typefile, F_OK) != 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
fp = fopen (typefile, "r");
|
fp = fopen (typefile, "r");
|
||||||
if (NULL == fp) {
|
if (NULL == fp) {
|
||||||
|
if (errno != ENOENT)
|
||||||
perror (typefile);
|
perror (typefile);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user