Rev 12474 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 12474 | Rev 15509 | ||
---|---|---|---|
Line 16... | Line 16... | ||
16 | */ |
16 | */ |
17 | 17 | ||
18 | /* Daily housekeeping jobs. */ |
18 | /* Daily housekeeping jobs. */ |
19 | 19 | ||
20 | #include "wimslogd.h" |
20 | #include "wimslogd.h" |
- | 21 | int stringtodays(char * dat) |
|
- | 22 | { |
|
- | 23 | static int len[13] = {0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; |
|
- | 24 | int y = 1000*(dat[0]-'0')+100*(dat[1]-'0')+10*(dat[2]-'0')+(dat[3]-'0'); |
|
- | 25 | int m = 10*(dat[4]-'0')+(dat[5]-'0'); |
|
- | 26 | int d = 10*(dat[6]-'0')+(dat[7]-'0'); |
|
- | 27 | if (m < 3) {y--; d += 365;} |
|
- | 28 | return d + len[m] + 365*y + y/4 - y/100 + y/400; |
|
- | 29 | } |
|
- | 30 | void purgefile(char *fname) |
|
- | 31 | { |
|
- | 32 | char buf[8]; |
|
- | 33 | FILE *f = fopen(fname,"r"); |
|
- | 34 | fread (buf,1,8,f); |
|
- | 35 | fclose(f); |
|
- | 36 | int d1 = stringtodays(buf); |
|
- | 37 | int d2 = stringtodays(nowstr); |
|
- | 38 | if (d2-d1 > 2) |
|
- | 39 | unlink(fname); |
|
- | 40 | } |
|
21 | 41 | ||
22 | void housekeep(void) |
42 | void housekeep(void) |
23 | { |
43 | { |
- | 44 | struct stat st; |
|
24 | char fname[1024]; |
45 | char fname[1024], pathname[1024]; |
25 | FILE *keeplog; |
46 | FILE *keeplog; |
- | 47 | static char* lognames[]={ |
|
- | 48 | "access.log","referer.log","session.log","post.log","mail.log", |
|
- | 49 | "user_error.log","internal_error.log","refuse.log" |
|
26 | 50 | }; |
|
- | 51 | int i,j,cntlogs=sizeof(lognames)/sizeof(char*); |
|
27 | if(strncmp(keepdate,nowstr,8)==0) return; |
52 | if(strncmp(keepdate,nowstr,8)==0) return; |
28 | snprintf(fname,sizeof(fname),"%s/keepdate",tmpd); |
53 | snprintf(fname,sizeof(fname),"%s/keepdate",tmpd); |
29 | keeplog=fopen(fname,"r"); |
54 | keeplog=fopen(fname,"r"); |
30 | if(keeplog==NULL) goto dokeep; |
55 | if(keeplog==NULL) goto dokeep; |
31 | (void)fread(keepdate,8,1,keeplog); keepdate[8]=0; fclose(keeplog); |
56 | (void)fread(keepdate,8,1,keeplog); keepdate[8]=0; fclose(keeplog); |
32 | if(strncmp(keepdate,nowstr,8)==0) return; |
57 | if(strncmp(keepdate,nowstr,8)==0) return; |
33 | dokeep: |
58 | dokeep: |
34 | keeplog=fopen(fname,"w"); |
59 | keeplog=fopen(fname,"w"); |
35 | if(keeplog!=NULL) { |
60 | if(keeplog!=NULL) { |
36 | fwrite(nowstr,8,1,keeplog);fclose(keeplog); |
61 | fwrite(nowstr,8,1,keeplog);fclose(keeplog); |
37 | } |
62 | } |
- | 63 | /* delete files older than LOG_DELETE days */ |
|
- | 64 | for (j=0; j < cntlogs; ++j) |
|
- | 65 | { |
|
- | 66 | snprintf(pathname,sizeof(pathname),"%s/%s",logd,lognames[j]); |
|
- | 67 | for(i=OLD_LOG_FILES-1;i>0;i--) { |
|
- | 68 | snprintf(fname,sizeof(fname),"%s.old%d",pathname,i); |
|
- | 69 | if(stat(fname,&st)==0) purgefile(fname); |
|
- | 70 | } |
|
- | 71 | if(stat(pathname,&st)==0) purgefile(pathname); |
|
- | 72 | } |
|
- | 73 | ||
38 | call_ssh(0,"bin/housekeep.daily &>%s/housekeep.log",tmpd); |
74 | call_ssh(0,"bin/housekeep.daily &>%s/housekeep.log",tmpd); |
39 | } |
75 | } |
40 | 76 | ||
41 | /* module update */ |
77 | /* module update */ |
42 | void modupdate(void) |
78 | void modupdate(void) |