Rev 3836 | Rev 8185 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3836 | Rev 8155 | ||
---|---|---|---|
Line 13... | Line 13... | ||
13 | * You should have received a copy of the GNU General Public License |
13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program; if not, write to the Free Software |
14 | * along with this program; if not, write to the Free Software |
15 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
15 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
16 | */ |
16 | */ |
17 | 17 | ||
18 |
|
18 | /* This file contains a routine to do housekeeping: |
19 |
|
19 | * it erases obsolete session directories. |
20 | |
20 | * Regular checkup every 10 minutes or so. |
- | 21 | */ |
|
21 | 22 | ||
22 |
|
23 | /* internal */ |
23 | void _cleaning(char *di,int hardcheck) |
24 | void _cleaning(char *di,int hardcheck) |
24 | { |
25 | { |
25 | DIR *sdir_base; |
26 | DIR *sdir_base; |
26 | struct dirent *ses; |
27 | struct dirent *ses; |
27 | struct stat session_stat; |
28 | struct stat session_stat; |
Line 41... | Line 42... | ||
41 | if(remove(session_name)<0) { |
42 | if(remove(session_name)<0) { |
42 | error("wimslogd cleaning(): unable to chase squatter file."); |
43 | error("wimslogd cleaning(): unable to chase squatter file."); |
43 | return; |
44 | return; |
44 | } |
45 | } |
45 | } |
46 | } |
46 |
|
47 | /* remove idle session. */ |
47 | else { |
48 | else { |
48 | struct stat fst; |
49 | struct stat fst; |
49 | char fbuf[4096],cbuf[MAX_LINELEN+1]; |
50 | char fbuf[4096],cbuf[MAX_LINELEN+1]; |
50 | char *pp; |
51 | char *pp; |
51 | if(session_stat.st_mtime<nowtime-idle_time || |
52 | if(session_stat.st_mtime<nowtime-idle_time || |
Line 114... | Line 115... | ||
114 | } |
115 | } |
115 | } |
116 | } |
116 | closedir(sdir_base); |
117 | closedir(sdir_base); |
117 | } |
118 | } |
118 | 119 | ||
119 |
|
120 | /* Clean obsolete session directories. */ |
120 | void cleaning(int withmain) |
121 | void cleaning(int withmain) |
121 | { |
122 | { |
122 | struct stat lastclean_stat; |
123 | struct stat lastclean_stat; |
123 | pid_t pid; |
124 | pid_t pid; |
124 | char lastclean_name[MAX_FNAME+1]; |
125 | char lastclean_name[MAX_FNAME+1]; |
125 | FILE *lastclean; |
126 | FILE *lastclean; |
126 |
|
127 | /* Active only if idle_time>0 */ |
127 | if(idle_time<=0) return; |
128 | if(idle_time<=0) return; |
128 |
|
129 | /* when is last clean? */ |
129 | if(lastcleantime>nowtime-300) return; |
130 | if(lastcleantime>nowtime-300) return; |
130 | mystrncpy(lastclean_name,"tmp/log/lastclean",sizeof(lastclean_name)); |
131 | mystrncpy(lastclean_name,"tmp/log/lastclean",sizeof(lastclean_name)); |
131 | if(stat(lastclean_name,&lastclean_stat)==0 && |
132 | if(stat(lastclean_name,&lastclean_stat)==0 && |
132 | lastclean_stat.st_mtime>nowtime-300 && |
133 | lastclean_stat.st_mtime>nowtime-300 && |
133 | lastclean_stat.st_mtime<nowtime+100) return; |
134 | lastclean_stat.st_mtime<nowtime+100) return; |
Line 136... | Line 137... | ||
136 | close(commsock); |
137 | close(commsock); |
137 | if(withmain) _cleaning(sesd,1); |
138 | if(withmain) _cleaning(sesd,1); |
138 | _cleaning("s2",2); |
139 | _cleaning("s2",2); |
139 | _cleaning("tmp/sessions",0); |
140 | _cleaning("tmp/sessions",0); |
140 | _cleaning("chroot/tmp/sessions",0); |
141 | _cleaning("chroot/tmp/sessions",0); |
141 |
|
142 | /* touch lastclean file */ |
142 | lastclean=fopen(lastclean_name,"w"); fclose(lastclean); |
143 | lastclean=fopen(lastclean_name,"w"); fclose(lastclean); |
143 | lastcleantime=nowtime; |
144 | lastcleantime=nowtime; |
144 | snprintf(lastclean_name,sizeof(lastclean_name),"%s/trap.check",tmpd); |
145 | snprintf(lastclean_name,sizeof(lastclean_name),"%s/trap.check",tmpd); |
145 | if(stat(lastclean_name,&lastclean_stat)==0 && |
146 | if(stat(lastclean_name,&lastclean_stat)==0 && |
146 | (lastclean_stat.st_mtime<nowtime-3600 || |
147 | (lastclean_stat.st_mtime<nowtime-3600 || |