#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <syslog.h>
#include <fcntl.h>
#include <errno.h>
#include <time.h>
#include "check_cron_process.h"
static char buffer[BUFFSIZE1] = {0};
static char datetime[BUFFSIZE2] = {0};
/* 获得当前系统时间 */
int get_curr_date(char *strtime, unsigned int ustrlen)
{
struct tm *pt = NULL;
time_t timer;
if (!strtime) {
return -1;
}
time(&timer);
strtime[0] = '\0';
pt = localtime(&timer);
if (!pt) {
return -1;
}
memset(strtime, 0, ustrlen);
sprintf(strtime, "%04d-%02d-%02d-%02d:%02d:%02d",
pt->tm_year + 1900, pt->tm_mon + 1, pt->tm_mday, pt->tm_hour, pt->tm_min, pt->tm_sec);
return 0;
}
/* 将信息写入日志文件 */
int writelog(const char *pLoginfo)
{
FILE *fp = NULL;
unsigned int ustrlen = 0;
if (pLoginfo == NULL) {
return -1;
}
ustrlen = strlen(pLoginfo);
if (ustrlen > 256) {
return -1;
}
if ((fp = fopen(LOGFILE, "a+")) == NULL) {
return -1;
}
memset(datetime, 0, BUFFSIZE2);
get_curr_date(datetime, BUFFSIZE2);