forked from github/server
22583 Time of check time of use
avoid use of access()
This commit is contained in:
parent
5f99288af1
commit
40651d57cd
1 changed files with 18 additions and 16 deletions
|
@ -77,24 +77,26 @@ 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)
|
||||||
{
|
{
|
||||||
if (_access(filename, 4) == 0) {
|
|
||||||
char buffer[2][MAX_PATH];
|
char buffer[2][MAX_PATH];
|
||||||
int dst = 1;
|
int 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);
|
||||||
|
#ifdef HAVE_UNISTD_H
|
||||||
|
/* make sure we don't overwrite an existing file (hard links) */
|
||||||
|
unlink(buffer[dst]);
|
||||||
|
#endif
|
||||||
while (maxindex > 0) {
|
while (maxindex > 0) {
|
||||||
int err, src = 1 - dst;
|
int err, 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) {
|
||||||
log_error("log rotate %s: %s", buffer[dst], strerror(errno));
|
log_debug("log rotate %s: %s", buffer[dst], strerror(errno));
|
||||||
}
|
}
|
||||||
dst = src;
|
dst = src;
|
||||||
}
|
}
|
||||||
if (rename(filename, buffer[dst]) != 0) {
|
if (rename(filename, buffer[dst]) != 0) {
|
||||||
log_error("log rotate %s: %s", buffer[dst], strerror(errno));
|
log_debug("log rotate %s: %s", buffer[dst], strerror(errno));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue