如何避免 stat 和 rename for LOGFILE 之间的竞争条件的 TOCTOU(time-of-check, time-of-use) 竞争条件?
需要在其大小值超过最大大小后移动日志文件。
result = stat(LOGFILE, & data);
if (result != 0) {
// stat failed
// file probably does not exist
} else if (data.st_size > MAX_LOGSIZE) {
unlink(PREV_LOGFILE);
(void) rename(LOGFILE, PREV_LOGFILE);
}