From 8b2e2b6fbe1ad9360d624bd0f4f95a19f00cc629 Mon Sep 17 00:00:00 2001 From: in2 Date: Tue, 19 Oct 2004 13:34:45 +0000 Subject: 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 --- util/shmctl.c | 35 +++++++++++++++++++++++++++++++---- 1 file 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; -- cgit v1.2.3