summaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-10-25 16:58:11 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-10-25 16:58:11 +0800
commitb6ef6cf9ddb6699ad37200ee5e7560454e57dc93 (patch)
tree25d4b0bce82fee56fa5df7427ef952a1f8110881 /util
parent2d92502ae81eb947ec24509bed6bacedccecaaa0 (diff)
downloadpttbbs-b6ef6cf9ddb6699ad37200ee5e7560454e57dc93.tar
pttbbs-b6ef6cf9ddb6699ad37200ee5e7560454e57dc93.tar.gz
pttbbs-b6ef6cf9ddb6699ad37200ee5e7560454e57dc93.tar.bz2
pttbbs-b6ef6cf9ddb6699ad37200ee5e7560454e57dc93.tar.lz
pttbbs-b6ef6cf9ddb6699ad37200ee5e7560454e57dc93.tar.xz
pttbbs-b6ef6cf9ddb6699ad37200ee5e7560454e57dc93.tar.zst
pttbbs-b6ef6cf9ddb6699ad37200ee5e7560454e57dc93.zip
add daemon mode for utmpfix
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2279 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'util')
-rw-r--r--util/shmctl.c75
1 files changed, 48 insertions, 27 deletions
diff --git a/util/shmctl.c b/util/shmctl.c
index cf12ee1e..198d6e8f 100644
--- a/util/shmctl.c
+++ b/util/shmctl.c
@@ -55,24 +55,19 @@ int sfIDLE(const void *a, const void *b)
return ((IDLE_t *)b)->idle - ((IDLE_t *)a)->idle;
}
-#ifdef DIRECTMODE
-int utmpfix(time_t timeout, int lowerbound)
-#else
int utmpfix(int argc, char **argv)
-#endif
{
int i, fast = 0, nownum = SHM->UTMPnumber;
- int which, nactive = 0, dofork = 1;
+ int which, nactive = 0, dofork = 1, daemonsleep = 0;
time_t now;
char *clean, buf[1024];
IDLE_t idle[USHM_SIZE];
char changeflag = 0;
-#ifndef DIRECTMODE
time_t timeout = -1;
- int lowerbound = 100;
+ int lowerbound = 100, upperbound = 0;
char ch;
- while( (ch = getopt(argc, argv, "nt:l:F")) != -1 )
+ while( (ch = getopt(argc, argv, "nt:l:FD:u:")) != -1 )
switch( ch ){
case 'n':
fast = 1;
@@ -86,46 +81,65 @@ int utmpfix(int argc, char **argv)
case 'F':
dofork = 0;
break;
+ case 'D':
+ daemonsleep = atoi(optarg);
+ break;
+ case 'u':
+ upperbound = atoi(optarg);
+ break;
default:
- printf("usage:\tshmctl\tutmpfix [-n] [-t timeout] [-F]\n");
+ printf("usage:\tshmctl\tutmpfix [-n] [-t timeout] [-F] [-D sleep]\n");
return 1;
}
-#endif
- for( i = 0 ; i < 5 ; ++i )
- if( !SHM->UTMPbusystate )
+ if( daemonsleep )
+ switch( fork() ){
+ case -1:
+ perror("fork()");
+ return 0;
+ case 0:
break;
- else{
- puts("utmpshm is busy....");
- sleep(1);
+ default:
+ return 0;
}
- SHM->UTMPbusystate = 1;
- if( dofork ){
- int times, status;
+ if( daemonsleep || dofork ){
+ int times = 1000, status;
pid_t pid;
- printf("forking mode\n");
- for( times = 0 ; times < 100 ; ++times ){
- switch( (pid = fork()) ){
+ while( daemonsleep ? 1 : times-- )
+ switch( pid = fork() ){
case -1:
- perror("fork()");
sleep(1);
break;
case 0:
+ setproctitle("utmpfix");
goto DoUtmpfix;
- break;
default:
+ setproctitle(daemonsleep ? "utmpfixd(wait for %d)" :
+ "utmpfix(wait for %d)", (int)pid);
waitpid(pid, &status, 0);
- printf("status: %d\n", status);
- if( WIFEXITED(status) )
+ if( WIFEXITED(status) && !daemonsleep )
return 0;
- changeflag = 1;
+ if( !WIFEXITED(status) ){
+ /* last utmpfix fails, so SHM->UTMPbusystate is holded */
+ SHM->UTMPbusystate = 0;
+ }
}
- }
+ return 0; // never reach
}
DoUtmpfix:
+ for( i = 0 ; i < 5 ; ++i )
+ if( !SHM->UTMPbusystate )
+ break;
+ else{
+ puts("utmpshm is busy....");
+ sleep(1);
+ }
+ SHM->UTMPbusystate = 1;
+
printf("starting scaning... %s \n", (fast ? "(fast mode)" : ""));
+ nownum = SHM->UTMPnumber;
#ifdef OUTTA_TIMER
now = SHM->GV2.e.now;
#else
@@ -197,6 +211,13 @@ int utmpfix(int argc, char **argv)
SHM->UTMPbusystate = 0;
if( changeflag )
SHM->UTMPneedsort = 1;
+
+ if( daemonsleep ){
+ do{
+ sleep(daemonsleep);
+ } while( upperbound && SHM->UTMPnumber < upperbound );
+ goto DoUtmpfix; /* XXX: goto */
+ }
return 0;
}
/* end of utmpfix ---------------------------------------------------------- */