summaryrefslogtreecommitdiffstats
path: root/util/shmctl.c
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2005-01-31 23:08:48 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2005-01-31 23:08:48 +0800
commitefa25c523ed5683485feac2d58745c5f38405581 (patch)
treea5b91bc2d17c499bc332d608b5f08838a47a5cb9 /util/shmctl.c
parentfa5d585ed80c29aaa228431c61379b2ca0573d62 (diff)
downloadpttbbs-efa25c523ed5683485feac2d58745c5f38405581.tar
pttbbs-efa25c523ed5683485feac2d58745c5f38405581.tar.gz
pttbbs-efa25c523ed5683485feac2d58745c5f38405581.tar.bz2
pttbbs-efa25c523ed5683485feac2d58745c5f38405581.tar.lz
pttbbs-efa25c523ed5683485feac2d58745c5f38405581.tar.xz
pttbbs-efa25c523ed5683485feac2d58745c5f38405581.tar.zst
pttbbs-efa25c523ed5683485feac2d58745c5f38405581.zip
in utmpfix, send SIGKILL if the processes are not response to SIGHUP.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2450 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'util/shmctl.c')
-rw-r--r--util/shmctl.c44
1 files changed, 35 insertions, 9 deletions
diff --git a/util/shmctl.c b/util/shmctl.c
index bbf0239e..17938461 100644
--- a/util/shmctl.c
+++ b/util/shmctl.c
@@ -67,6 +67,17 @@ int utmpfix(int argc, char **argv)
int lowerbound = 100, upperbound = 0;
char ch;
+ int killtop = 0;
+ struct {
+ pid_t pid;
+ int where;
+ } killlist[USHM_SIZE];
+ #define addkilllist(a, b) \
+ do { \
+ killlist[killtop].where = a; \
+ killlist[killtop++].pid = b; \
+ } while( 0 )
+
while( (ch = getopt(argc, argv, "nt:l:FD:u:")) != -1 )
switch( ch ){
case 'n':
@@ -160,17 +171,17 @@ int utmpfix(int argc, char **argv)
if( !isalpha(SHM->uinfo[which].userid[0]) ){
clean = "userid error";
if( SHM->uinfo[which].pid > 0 )
- kill(SHM->uinfo[which].pid, SIGHUP);
+ addkilllist(which, SHM->uinfo[which].pid);
}
else if( memchr(SHM->uinfo[which].userid, '\0', IDLEN + 1) == NULL ){
clean = "userid without z";
if( SHM->uinfo[which].pid > 0 )
- kill(SHM->uinfo[which].pid, SIGHUP);
+ addkilllist(which, SHM->uinfo[which].pid);
}
else if( SHM->uinfo[which].friendtotal > MAX_FRIEND ){
clean = "too many friend";
if( SHM->uinfo[which].pid > 0 )
- kill(SHM->uinfo[which].pid, SIGHUP);
+ addkilllist(which, SHM->uinfo[which].pid);
}
else if( kill(SHM->uinfo[which].pid, 0) < 0 ){
clean = "process error";
@@ -179,18 +190,22 @@ int utmpfix(int argc, char **argv)
else if( searchuser(SHM->uinfo[which].userid) == 0 ){
clean = "user not exist";
if( SHM->uinfo[which].pid > 0 )
- kill(SHM->uinfo[which].pid, SIGHUP);
+ addkilllist(which, SHM->uinfo[which].pid);
}
#ifdef DOTIMEOUT
else if( !fast ){
if( nownum > lowerbound &&
idle[i].idle >
(timeout == -1 ? IDLE_TIMEOUT : timeout) ){
- sprintf(buf, "timeout(%s)",
+ sprintf(buf, "timeout(%s",
ctime4(&SHM->uinfo[which].lastact));
+ buf[strlen(buf) - 1] = 0;
+ strcat(buf, ")");
clean = buf;
if( SHM->uinfo[which].pid > 0 )
- kill(SHM->uinfo[which].pid, SIGHUP);
+ addkilllist(which, SHM->uinfo[which].pid);
+ else
+ purge_utmp(&SHM->uinfo[which]);
printf("%s\n", buf);
--nownum;
continue;
@@ -206,6 +221,18 @@ int utmpfix(int argc, char **argv)
changeflag = 1;
}
}
+ for( i = 0 ; i < killtop ; ++i ){
+ printf("sending SIGHUP to %d\n", (int)killlist[i].pid);
+ kill(killlist[i].pid, SIGHUP);
+ }
+ sleep(3);
+ for( i = 0 ; i < killtop ; ++i )
+ if( SHM->uinfo[killlist[i].where].pid == killlist[i].pid &&
+ kill(killlist[i].pid, 0) == 0 ){ // still alive
+ printf("sending SIGKILL to %d\n", (int)killlist[i].pid);
+ kill(killlist[i].pid, SIGKILL);
+ purge_utmp(&SHM->uinfo[killlist[i].where]);
+ }
SHM->UTMPbusystate = 0;
if( changeflag )
SHM->UTMPneedsort = 1;
@@ -449,13 +476,12 @@ int utmpsortd(int argc, char **argv)
}
/* end of utmpsortd -------------------------------------------------------- */
-char *CTIMEx(char *buf, time_t t)
+char *CTIMEx(char *buf, time4_t t)
{
- strcpy(buf, ctime(&t));
+ strcpy(buf, ctime4(&t));
buf[strlen(buf) - 1] = 0;
return buf;
}
-
int utmpstatus(int argc, char **argv)
{
time_t now;