1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
/*
* fsarchiver: Filesystem Archiver
*
* Copyright (C) 2008-2012 Francois Dupoux. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License v2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* Homepage: http://www.fsarchiver.org
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <limits.h>
#include <time.h>
#include "fsarchiver.h"
#include "logfile.h"
#include "common.h"
#include "error.h"
int g_logfile=-1;
int logfile_open()
{
char logpath[PATH_MAX];
char timestamp[1024];
char *logdir="/var/log";
format_time(timestamp, sizeof(timestamp), time(NULL));
snprintf(logpath, sizeof(logpath), "%s/fsarchiver_%s_%ld.log", logdir, timestamp, (long)getpid());
mkdir_recursive(logdir);
g_logfile=open64(logpath, O_RDWR|O_CREAT|O_TRUNC|O_LARGEFILE, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
if (g_logfile>=0)
{ msgprintf(MSG_VERB1, "Creating logfile in %s\n", logpath);
msgprintf(MSG_VERB1, "Running fsarchiver version=[%s], fileformat=[%s]\n", FSA_VERSION, FSA_FILEFORMAT);
return FSAERR_SUCCESS;
}
else
{ sysprintf("Cannot create logfile in %s\n", logpath);
return FSAERR_UNKNOWN;
}
}
int logfile_close()
{
close(g_logfile);
return FSAERR_SUCCESS;
}
int logfile_write(char *str, int len)
{
if (g_logfile>=0)
return write(g_logfile, str, len);
else
return FSAERR_UNKNOWN;
}
|