summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2005-10-28 15:18:53 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2005-10-28 15:18:53 +0800
commit9ad29a4d9bfb725a12cc7869004b78e0837b5ce9 (patch)
tree82a9a474b3cacaa9ca8f5f30b2aaca6d48613724
parentdc1acd98048b748ec801dc86187ff5362d546de1 (diff)
downloadpttbbs-9ad29a4d9bfb725a12cc7869004b78e0837b5ce9.tar
pttbbs-9ad29a4d9bfb725a12cc7869004b78e0837b5ce9.tar.gz
pttbbs-9ad29a4d9bfb725a12cc7869004b78e0837b5ce9.tar.bz2
pttbbs-9ad29a4d9bfb725a12cc7869004b78e0837b5ce9.tar.lz
pttbbs-9ad29a4d9bfb725a12cc7869004b78e0837b5ce9.tar.xz
pttbbs-9ad29a4d9bfb725a12cc7869004b78e0837b5ce9.tar.zst
pttbbs-9ad29a4d9bfb725a12cc7869004b78e0837b5ce9.zip
add fixbcache
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3235 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--util/shmctl.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/util/shmctl.c b/util/shmctl.c
index 1a5fd525..0699d601 100644
--- a/util/shmctl.c
+++ b/util/shmctl.c
@@ -958,6 +958,62 @@ int torb(int argc, char **argv)
return 0;
}
+int fixbcache(int argc, char **argv)
+{
+ void lockbcache(void)
+ {
+ int i;
+ for( i = 0 ; i < 10 && SHM->Bbusystate ; ++i ){
+ printf("SHM->Bbusystate is currently locked (value: %d). "
+ "please wait... ", SHM->Bbusystate);
+ sleep(1);
+ }
+ if( i == 10 )
+ puts("steal bcache lock\n");
+ SHM->Bbusystate = 1;
+ }
+ void unlockbcache(void)
+ {
+ SHM->Bbusystate = 0;
+ }
+ int n, fd, bid, changed = 0;
+ boardheader_t bh;
+
+ if( (fd = open(fn_board, O_RDONLY)) < 0 ){
+ perror("open .BRD");
+ return 1;
+ }
+
+ for( bid = 0 ;
+ (bid < MAX_BOARD && read(fd, &bh, sizeof(bh)) == sizeof(bh)) ;
+ ++bid ){
+ if( strcmp(bh.brdname, bcache[bid].brdname) != 0 ){
+ char fn[PATHLEN];
+ printf("bid: %d, brdname not match(.BRD: %s, bcache: %s). "
+ "fix it!\n",
+ bid + 1, bh.brdname, bcache[bid].brdname);
+ changed = 1;
+ lockbcache();
+ bcache[bid] = bh;
+ unlockbcache();
+
+ sprintf(fn, "boards/%c/%s/.DIR.bottom",
+ bh.brdname[0],
+ bh.brdname);
+ n = get_num_records(fn, sizeof(fileheader_t));
+ if( n > 5 )
+ n = 5;
+ SHM->n_bottom[bid] = n;
+ }
+ }
+ close(fd);
+ if( changed ){
+ puts("re-sort bcache");
+ sort_bcache();
+ }
+ return 0;
+}
+
int rlfcache(int argc, char **argv)
{
reload_fcache();
@@ -1082,6 +1138,7 @@ struct {
{dummy, "\b\b\b\bBuild cache/fix tool:", ""},
{torb, "reloadbcache", "reload bcache"},
+ {fixbcache, "fixbcache", "fix bcache"},
{rlfcache, "reloadfcache", "reload fcache"},
{bBMC, "bBMC", "build BM cache"},
{utmpfix, "utmpfix", "clear dead userlist entry & kick idle user"},