coverity CID 141509 Unchecked return value from library

Conflicts:
	src/util/log.c
This commit is contained in:
Enno Rehling 2016-08-09 18:28:15 +02:00 committed by Enno Rehling
parent 43c2c74d75
commit 3e47f02fc2

View file

@ -102,21 +102,29 @@ void log_rotate(const char *filename, int maxindex)
assert(strlen(filename) < sizeof(buffer[0]) - 4); assert(strlen(filename) < sizeof(buffer[0]) - 4);
sprintf(buffer[dst], "%s.%d", filename, maxindex); sprintf(buffer[dst], "%s.%d", filename, maxindex);
#ifdef HAVE_UNISTD_H if (remove(buffer[dst]) != 0) {
/* make sure we don't overwrite an existing file (hard links) */ if (errno != ENOENT) {
unlink(buffer[dst]); fprintf(stderr, "log rotate %s: %d %s", buffer[dst], errno, strerror(errno));
#endif }
errno = 0;
}
while (maxindex > 0) { while (maxindex > 0) {
int err, src = 1 - dst; int src = 1 - dst;
sprintf(buffer[src], "%s.%d", filename, --maxindex); sprintf(buffer[src], "%s.%d", filename, --maxindex);
err = rename(buffer[src], buffer[dst]); if (rename(buffer[src], buffer[dst]) != 0) {
if (err != 0) { if (errno != ENOENT) {
log_debug("log rotate %s: %s", buffer[dst], strerror(errno)); fprintf(stderr, "log rotate %s: %d %s", buffer[dst], errno, strerror(errno));
}
errno = 0;
} }
dst = src; dst = src;
} }
if (rename(filename, buffer[dst]) != 0) { if (rename(filename, buffer[dst]) != 0) {
log_debug("log rotate %s: %s", buffer[dst], strerror(errno)); if (errno != ENOENT) {
fprintf(stderr, "log rotate %s: %d %s", buffer[dst], errno, strerror(errno));
}
errno = 0;
} }
} }