- added new scriptcontext with devser

This commit is contained in:
zolliker
2008-05-14 14:23:16 +00:00
parent bbb0b971a9
commit 3967dc8844
28 changed files with 1307 additions and 1363 deletions

View File

@ -76,7 +76,7 @@ time_t LoggerGetLastLife(char *dirarg) {
}
fclose(fil);
} else {
printf("can not read %s\n", path);
/* printf("can not read %s\n", path); */
}
return t;
}
@ -108,16 +108,17 @@ char *LoggerGetDir(void) {
return dir;
}
/*--------------------------------------------------------------------------*/
int LoggerVarPath(char *dir, char *path, int pathLen, char *name) {
int LoggerVarPath(char *dir, char *path, int pathLen, char *name, struct tm *t) {
int l;
l = strlen(dir);
if (l + strlen(name) + 2 >= pathLen) {
if (l + strlen(name) + 8 >= pathLen) {
path[0]='\0';
return 0;
}
strcpy(path, dir);
path[l] = '/'; l++;
strftime(path + l, pathLen - l, "/%Y/", t);
l += 6;
for (;*name != '\0'; name++, l++) {
path[l] = tolower(*name);
}
@ -140,7 +141,7 @@ int LoggerWrite0(Logger *log, time_t now, int period, char *value) {
}
lasttm = *localtime(&log->last);
tm = *localtime(&now);
l = LoggerVarPath(dir, path, sizeof path, log->name);
l = LoggerVarPath(dir, path, sizeof path, log->name, &tm);
strftime(path + l, sizeof path - l, "%m-%d.log", &tm);
strftime(stim, sizeof stim, "#%Y-%m-%d %H:%M:%S", &tm);
@ -226,7 +227,7 @@ int LoggerWrite(Logger *log, time_t now, int period, char *value) {
yday = tm->tm_yday;
/* -- debug logging if dir/debug exists */
l = LoggerVarPath(dir, path, sizeof path, "debug");
l = LoggerVarPath(dir, path, sizeof path, "debug", tm);
strftime(path + l, sizeof path - l, "%m-%d.log", tm);
fil=fopen(path, "a");
if (fil) {
@ -279,25 +280,53 @@ void LoggerKill(Logger *log) {
}
}
/*--------------------------------------------------------------------------*/
Logger *LoggerMake(char *name, int period, int exact) {
Logger *log;
char path[256];
static int LoggerMakeDir(char *path) {
static char buffer[4096];
struct stat st;
int i;
time_t t;
LoggerGetDir();
if (dir == NULL) return NULL;
LoggerVarPath(dir, path, sizeof path, name);
int i, lpath, l;
char *slash;
i = stat(path, &st);
if (i >= 0) {
if (((st.st_mode >> 12) & 15) != 4) { /* exists, but is no directory */
return NULL;
return 0;
}
} else {
i = mkdir(path, S_IRWXU+S_IRGRP+S_IXGRP+S_IROTH+S_IXOTH);
if (i < 0) return NULL; /* mkdir failed */
return 1;
}
i = mkdir(path, S_IRWXU+S_IRGRP+S_IXGRP+S_IROTH+S_IXOTH);
if (i < 0) {
if (errno != ENOENT) return 0; /* mkdir failed */
snprintf(buffer, sizeof buffer, "%s", path);
lpath = strlen(buffer);
do {
slash = strrchr(buffer, '/');
if (!slash) return 0;
*slash='\0';
i = mkdir(buffer, S_IRWXU+S_IRGRP+S_IXGRP+S_IROTH+S_IXOTH);
} while (i < 0 && errno == ENOENT);
l = strlen(buffer);
while (l<lpath) {
buffer[l] = '/';
i = mkdir(buffer, S_IRWXU+S_IRGRP+S_IXGRP+S_IROTH+S_IXOTH);
if (i< 0) return 0;
l = strlen(buffer);
}
}
return 1;
}
/*--------------------------------------------------------------------------*/
Logger *LoggerMake(char *name, int period, int exact) {
Logger *log;
char path[256];
time_t t;
struct tm tm;
LoggerGetDir();
if (dir == NULL) return NULL;
time(&t);
tm = *localtime(&t);
LoggerVarPath(dir, path, sizeof path, name, &tm);
if (LoggerMakeDir(path) == 0) return NULL;
log = LoggerFind(name); /* look if logger already exists */
if (log == NULL) {
log = calloc(1, sizeof *log);