summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--util/.cvsignore3
-rw-r--r--util/Makefile8
-rw-r--r--util/mdclean.c81
3 files changed, 87 insertions, 5 deletions
diff --git a/util/.cvsignore b/util/.cvsignore
index 73de8aac..982f6b1b 100644
--- a/util/.cvsignore
+++ b/util/.cvsignore
@@ -40,4 +40,5 @@ toplazyBM
jungo
bbsctl
mandex
-shmctl \ No newline at end of file
+shmctl
+mdclean
diff --git a/util/Makefile b/util/Makefile
index d1dd93e1..c0616b7b 100644
--- a/util/Makefile
+++ b/util/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.10 2002/04/14 14:08:56 in2 Exp $
+# $Id: Makefile,v 1.11 2002/04/15 20:07:08 in2 Exp $
BBSHOME?=$(HOME)
OSTYPE?=linux
@@ -30,7 +30,7 @@ CPROGS= bbsmail BM_money post account birth deluserfile expire mandex\
poststat showboard antispam countalldice webgrep bbsrf\
initbbs outmail xchatd userlist tunepasswd buildir reaper shmsweep\
merge_passwd merge_board inndBM buildAnnounce rmuid \
- toplazyBM jungo toplazyBBM shmctl killdeadbbs
+ toplazyBM jungo toplazyBBM shmctl mdclean
PROGS= $(CPROGS) BM_money.sh backpasswd.sh mailog.sh opendice.sh\
openticket.sh stock.sh topsong.sh weather.sh stock.perl weather.perl\
@@ -156,8 +156,8 @@ bbsctl: bbsctl.c
shmctl: shmctl.c $(OBJS)
$(CC) $(CFLAGS) -o $@ $@.c $(OBJS)
-killdeadbbs: killdeadbbs.c
- $(CC) $(CFLAGS) -lkvm -o $@ $@.c
+mdclean: mdclean.c
+ $(CC) $(CFLAGS) -o $@ $@.c
install: $(PROGS)
install -d $(BBSHOME)/bin/
diff --git a/util/mdclean.c b/util/mdclean.c
new file mode 100644
index 00000000..f8f58728
--- /dev/null
+++ b/util/mdclean.c
@@ -0,0 +1,81 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "config.h"
+#include <sys/types.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <err.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/param.h>
+#include <sys/mount.h>
+
+#define MAXDSs 1048576
+#define LEAVE 10
+#define CLEAN 10
+typedef struct {
+ time_t atime;
+ char name[60];
+} DS;
+
+DS ds[MAXDSs];
+int nDSs;
+
+int compar(const void *a, const void *b)
+{
+ return ((DS *)a)->atime - ((DS *)b)->atime;
+}
+
+int main(int argc, char **argv)
+{
+ DIR *dirp;
+ struct dirent *dp;
+ struct stat sb;
+ struct statfs sf;
+ char *fn;
+ time_t now;
+ if( chdir(BBSHOME "/cache") < 0 )
+ err(1, "chdir");
+
+ if( (dirp = opendir(".")) == NULL )
+ err(1, "opendir");
+
+ statfs(".", &sf);
+ if( sf.f_bfree * 100 / sf.f_blocks > LEAVE )
+ return 0;
+
+ now = time(NULL);
+ while( (dp = readdir(dirp)) != NULL ){
+ fn = dp->d_name;
+ if( fn[0] != 'e' && fn[0] != 'b' )
+ continue;
+ if( stat(fn, &sb) < 0 )
+ continue;
+ if( sb.st_atime < now - 1800 ){
+ printf("atime: %s\n", fn);
+ unlink(fn);
+ }
+ else if( sb.st_mtime < now - 7200 ){
+ printf("mtime: %s\n", fn);
+ unlink(fn);
+ }
+ else{
+ if( nDSs != MAXDSs ){
+ strcpy(ds[nDSs].name, fn);
+ ds[nDSs].atime = sb.st_atime;
+ ++nDSs;
+ }
+ }
+ }
+
+ statfs(".", &sf);
+ if( sf.f_bfree * 100 / sf.f_blocks <= LEAVE ){
+ qsort(ds, nDSs, sizeof(DS), compar);
+ nDSs = nDSs * CLEAN / 100;
+ while( nDSs-- ){
+ printf("%s\n", ds[nDSs].name);
+ unlink(ds[nDSs].name);
+ }
+ }
+ return 0;
+}