util: don't log unlink() error if file is not accessible
Try stat() before calling unlink() to make sure the file is accessible. This fixes chronyc running under a non-root/chrony user printing an error message due to missing permissions on /var/run/chrony before trying to bind its socket.
This commit is contained in:
parent
994409a036
commit
1858104b5c
1 changed files with 8 additions and 2 deletions
10
util.c
10
util.c
|
@ -1218,13 +1218,19 @@ int
|
||||||
UTI_RemoveFile(const char *basedir, const char *name, const char *suffix)
|
UTI_RemoveFile(const char *basedir, const char *name, const char *suffix)
|
||||||
{
|
{
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
|
struct stat buf;
|
||||||
|
|
||||||
if (!join_path(basedir, name, suffix, path, sizeof (path), LOGS_ERR))
|
if (!join_path(basedir, name, suffix, path, sizeof (path), LOGS_ERR))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
/* Avoid logging an error message if the file is not accessible */
|
||||||
|
if (stat(path, &buf) < 0) {
|
||||||
|
DEBUG_LOG("Could not remove %s : %s", path, strerror(errno));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (unlink(path) < 0) {
|
if (unlink(path) < 0) {
|
||||||
LOG(errno != ENOENT ? LOGS_ERR : LOGS_DEBUG,
|
LOG(LOGS_ERR, "Could not remove %s : %s", path, strerror(errno));
|
||||||
"Could not remove %s : %s", path, strerror(errno));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue