static void virLogHandlerLogFileFree(virLogHandlerLogFilePtr file) { if (!file) return; VIR_FORCE_CLOSE(file->pipefd); virRotatingFileWriterFree(file->file); if (file->watch != -1) virEventRemoveHandle(file->watch); VIR_FREE(file); }
/** * virRotatingFileWriterNew * @path: the base path for files * @maxlen: the maximum number of bytes to write before rollover * @maxbackup: number of backup files to keep when rolling over * @trunc: whether to truncate the current files when opening * @mode: the file mode to use for creating new files * * Create a new object for writing data to a file with * automatic rollover. If @maxbackup is zero, no backup * files will be created. The primary file will just get * truncated and reopened. * * The files will never exceed @maxlen bytes in size, * but may be rolled over before they reach this size * in order to avoid splitting lines */ virRotatingFileWriterPtr virRotatingFileWriterNew(const char *path, off_t maxlen, size_t maxbackup, bool trunc, mode_t mode) { virRotatingFileWriterPtr file; if (VIR_ALLOC(file) < 0) goto error; if (VIR_STRDUP(file->basepath, path) < 0) goto error; if (maxbackup > VIR_MAX_MAX_BACKUP) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Max backup %zu must be less than or equal to %d"), maxbackup, VIR_MAX_MAX_BACKUP); goto error; } file->mode = mode; file->maxbackup = maxbackup; file->maxlen = maxlen; if (trunc && virRotatingFileWriterDelete(file) < 0) goto error; if (!(file->entry = virRotatingFileWriterEntryNew(file->basepath, mode))) goto error; return file; error: virRotatingFileWriterFree(file); return NULL; }