diff options
author | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-10-19 21:34:45 +0800 |
---|---|---|
committer | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-10-19 21:34:45 +0800 |
commit | 8b2e2b6fbe1ad9360d624bd0f4f95a19f00cc629 (patch) | |
tree | a27ea790c50288de644871a30a04190d4a13fc6c /util/shmctl.c | |
parent | a5a5d25fc0ccd1bb220601f92ce3b5e3a3f81f4a (diff) | |
download | pttbbs-8b2e2b6fbe1ad9360d624bd0f4f95a19f00cc629.tar pttbbs-8b2e2b6fbe1ad9360d624bd0f4f95a19f00cc629.tar.gz pttbbs-8b2e2b6fbe1ad9360d624bd0f4f95a19f00cc629.tar.bz2 pttbbs-8b2e2b6fbe1ad9360d624bd0f4f95a19f00cc629.tar.lz pttbbs-8b2e2b6fbe1ad9360d624bd0f4f95a19f00cc629.tar.xz pttbbs-8b2e2b6fbe1ad9360d624bd0f4f95a19f00cc629.tar.zst pttbbs-8b2e2b6fbe1ad9360d624bd0f4f95a19f00cc629.zip |
shmctl should NOT fail in utmpfix, but when something wrong
in SHM, this would happen and utmp is still dirty. so now
shmctl will fork(2) before real utmpfix, and if it fails,
utmpfix will start again automatically.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2265 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'util/shmctl.c')
-rw-r--r-- | util/shmctl.c | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/util/shmctl.c b/util/shmctl.c index deebf459..f3067fc2 100644 --- a/util/shmctl.c +++ b/util/shmctl.c @@ -55,13 +55,13 @@ int sfIDLE(const void *a, const void *b) int utmpfix(int argc, char **argv) { int i, fast = 0, lowerbound = 100, nownum = SHM->UTMPnumber; - int which, nactive = 0; + int which, nactive = 0, dofork = 1; time_t now, timeout = -1; char *clean, buf[1024], ch; IDLE_t idle[USHM_SIZE]; char changeflag = 0; - while( (ch = getopt(argc, argv, "nt:l:")) != -1 ) + while( (ch = getopt(argc, argv, "nt:l:F")) != -1 ) switch( ch ){ case 'n': fast = 1; @@ -72,8 +72,11 @@ int utmpfix(int argc, char **argv) case 'l': lowerbound = atoi(optarg); break; + case 'F': + dofork = 0; + break; default: - printf("usage:\tshmctl\tutmpfix [-n] [-t timeout]\n"); + printf("usage:\tshmctl\tutmpfix [-n] [-t timeout] [-F]\n"); return 1; } @@ -84,8 +87,32 @@ int utmpfix(int argc, char **argv) puts("utmpshm is busy...."); sleep(1); } - SHM->UTMPbusystate = 1; + + if( dofork ){ + int times, status; + pid_t pid; + printf("forking mode\n"); + for( times = 0 ; times < 100 ; ++times ){ + switch( (pid = fork()) ){ + case -1: + perror("fork()"); + sleep(1); + break; + case 0: + goto DoUtmpfix; + break; + default: + waitpid(pid, &status, 0); + printf("status: %d\n", status); + if( WIFEXITED(status) ) + return 0; + changeflag = 1; + } + } + } + + DoUtmpfix: printf("starting scaning... %s \n", (fast ? "(fast mode)" : "")); #ifdef OUTTA_TIMER now = SHM->GV2.e.now; |