forked from github/server
fix log_rotate warnings (#529)
* ignore file-not-found errors when trying to rotate logs. I suspect this is faster and safer than testing existence. * block rename warnings, part deux
This commit is contained in:
parent
8f9bfe85b6
commit
03a8b7383c
|
@ -93,7 +93,7 @@ cp_convert(const char *format, char *buffer, size_t length, int codepage)
|
||||||
void log_rotate(const char *filename, int maxindex)
|
void log_rotate(const char *filename, int maxindex)
|
||||||
{
|
{
|
||||||
char buffer[2][MAX_PATH];
|
char buffer[2][MAX_PATH];
|
||||||
int dst = 1;
|
int err, dst = 1;
|
||||||
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);
|
||||||
|
@ -101,16 +101,17 @@ void log_rotate(const char *filename, int maxindex)
|
||||||
remove(buffer[dst]);
|
remove(buffer[dst]);
|
||||||
|
|
||||||
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]);
|
err = rename(buffer[src], buffer[dst]);
|
||||||
if (err != 0) {
|
if ((err != 0) && (err != ENOENT)) {
|
||||||
fprintf(stderr, "log rotate %s: %s", buffer[dst], strerror(errno));
|
fprintf(stderr, "log rotate %s: %d %s", buffer[dst], errno, strerror(errno));
|
||||||
}
|
}
|
||||||
dst = src;
|
dst = src;
|
||||||
}
|
}
|
||||||
if (rename(filename, buffer[dst]) != 0) {
|
err = rename(filename, buffer[dst]);
|
||||||
fprintf(stderr, "log rotate %s: %s", buffer[dst], strerror(errno));
|
if ((err != 0) && (err != ENOENT)) {
|
||||||
|
fprintf(stderr, "log rotate %s: %d %s", buffer[dst], errno, strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue