linux-c-log-rotation-scheme

linux-c-log-rotation-scheme

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

void logworker()
{
    ino_t inode = 0;
    FILE *logfile;

    logfile = fopen(logfilename, "a+");
    while(running)
    {
        struct stat mystat;

        if (stat(logfilename, &mystat)!=0 || mystat.st_ino != inode)
        {
            logfile = freopen(logfilename, "a+", logfile);
            inode = mystat.st_ino;
        }

        while (stuff_in_buffer)
        {
            fwrite(); /* etc */
        }
        fflush(logfile);

        /* sleep until something interesting happens */
    }
}

或者 renamefreopen

posted on 2024-05-29 16:58  明天有风吹  阅读(4)  评论(0编辑  收藏  举报

导航

+V atob('d2h5X251bGw=')

请备注:from博客园