ulog: avoid accidental /dev/kmsg creation

Race is possible in ulog_kmsg(): if no /dev/kmsg exists
(e.g. while /dev gets re-mounted) regular file created instead.
>From this point system goes without kernel logger:
special character file can't be created anymore, all clients keep
overwriting single message in regular file.

To avoid this we open file in "r+" mode which doesn't create
file if it's not found.

Signed-off-by: Sergiy Kibrik <sakib@meta.ua>
Cc: John Crispin <blogic@openwrt.org>
This commit is contained in:
Sergiy Kibrik 2015-08-18 09:28:39 +03:00 committed by John Crispin
parent d66a89f010
commit 136a519626

2
ulog.c
View file

@ -90,7 +90,7 @@ static void ulog_kmsg(int priority, const char *fmt, va_list ap)
{
FILE *kmsg;
if ((kmsg = fopen("/dev/kmsg", "w")) != NULL) {
if ((kmsg = fopen("/dev/kmsg", "r+")) != NULL) {
fprintf(kmsg, "<%u>", priority);
if (_ulog_ident)