summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-04-16 04:07:51 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-04-16 04:07:51 +0800
commitc0bdb92ced5b2911d800fb3920e252a50e25dc9d (patch)
treea1528e1e553154a2fe0cb0147bc040c89c0a8920
parentd10177be1eb9a86b468387498fe81e979e1638cb (diff)
downloadpttbbs-c0bdb92ced5b2911d800fb3920e252a50e25dc9d.tar
pttbbs-c0bdb92ced5b2911d800fb3920e252a50e25dc9d.tar.gz
pttbbs-c0bdb92ced5b2911d800fb3920e252a50e25dc9d.tar.bz2
pttbbs-c0bdb92ced5b2911d800fb3920e252a50e25dc9d.tar.lz
pttbbs-c0bdb92ced5b2911d800fb3920e252a50e25dc9d.tar.xz
pttbbs-c0bdb92ced5b2911d800fb3920e252a50e25dc9d.tar.zst
pttbbs-c0bdb92ced5b2911d800fb3920e252a50e25dc9d.zip
mdclean
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@113 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-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;
+}