Skip to content

Commit 2623995

Browse files
committed
conf: Return an error if zlog_init is called with a non-regular file
Currently, calling zlog_init with a non-regular file (e.g., a directory) didn’t return an error. The logger would have been configured the same as with an empty file. The file is now checked to ensure it is regular, and an error is returned if it is not. Fixes #278.
1 parent ee835a1 commit 2623995

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

src/conf.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@
3737
#include "rotater.h"
3838
#include "zc_defs.h"
3939

40-
#ifdef _WIN32
41-
#define STATS_FILE stat
42-
#else
43-
#define STATS_FILE lstat
44-
#endif
45-
4640
/*******************************************************************************/
4741
#define ZLOG_CONF_DEFAULT_FORMAT "default = \"%D %V [%p:%F:%L] %m%n\""
4842
#define ZLOG_CONF_DEFAULT_RULE "*.* >stdout"
@@ -471,11 +465,17 @@ static int zlog_conf_build_with_file(zlog_conf_t * a_conf)
471465
int section = 0;
472466
/* [global:1] [levels:2] [formats:3] [rules:4] */
473467

474-
if (STATS_FILE(a_conf->file, &a_stat)) {
468+
if (stat(a_conf->file, &a_stat)) {
475469
zc_error("lstat conf file[%s] fail, errno[%d]", a_conf->file,
476470
errno);
477471
return -1;
478472
}
473+
474+
if (!S_ISREG(a_stat.st_mode)) {
475+
zc_error("conf file[%s] is not a regular file", a_conf->file);
476+
return -1;
477+
}
478+
479479
localtime_r(&(a_stat.st_mtime), &local_time);
480480
strftime(a_conf->mtime, sizeof(a_conf->mtime), "%Y-%m-%d %H:%M:%S", &local_time);
481481

0 commit comments

Comments
 (0)