Example #1
0
int
tapdisk_logfile_open(td_logfile_t *log,
                     const char *dir, const char *ident, const char *ext,
                     size_t bufsz)
{
    int err;

    memset(log, 0, sizeof(*log));

    tapdisk_logfile_name(log->path, sizeof(log->path), dir, ident, ext);

    log->file = fopen(log->path, "w");
    if (!log->file) {
        err = -errno;
        goto fail;
    }

    err = tapdisk_logfile_init_buffer(log, bufsz);
    if (err)
        goto fail;

    return 0;

fail:
    tapdisk_logfile_unlink(log);
    tapdisk_logfile_close(log);
    return err;
}
Example #2
0
/**
 * Closes the log file.
 *
 * @param keep if set to true the log file is never removed. NB if an error has
 * occurred or a USR1 has been received the log is always kept, independently
 * of whether @keep is set to false.
 */
static void
tlog_logfile_close(bool keep)
{
	td_logfile_t *logfile = &tapdisk_log.logfile;

	if (tapdisk_log.precious || tapdisk_log.errors)
		keep = true;

	tlog_info("closing log, %lu errors", tapdisk_log.errors);

	tapdisk_logfile_close(logfile);

	if (!keep)
		tapdisk_logfile_unlink(logfile);
}