summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-05-17 22:27:20 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-05-17 22:27:20 +0800
commita2668d9b5d10e98447fb8e5110240d1757bc1ebe (patch)
tree229e70ff747e9483cf2a51e00558189bc8d30bc9
parent68466d47bc2f2d879b3afcc312165f84dc2dec18 (diff)
downloadpttbbs-a2668d9b5d10e98447fb8e5110240d1757bc1ebe.tar
pttbbs-a2668d9b5d10e98447fb8e5110240d1757bc1ebe.tar.gz
pttbbs-a2668d9b5d10e98447fb8e5110240d1757bc1ebe.tar.bz2
pttbbs-a2668d9b5d10e98447fb8e5110240d1757bc1ebe.tar.lz
pttbbs-a2668d9b5d10e98447fb8e5110240d1757bc1ebe.tar.xz
pttbbs-a2668d9b5d10e98447fb8e5110240d1757bc1ebe.tar.zst
pttbbs-a2668d9b5d10e98447fb8e5110240d1757bc1ebe.zip
getopt()
timeout git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@181 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--util/shmctl.c40
1 files changed, 28 insertions, 12 deletions
diff --git a/util/shmctl.c b/util/shmctl.c
index 738926b9..17b9dc42 100644
--- a/util/shmctl.c
+++ b/util/shmctl.c
@@ -53,11 +53,21 @@ void purge_utmp(userinfo_t *uentp)
int utmpfix(int argc, char **argv)
{
int i, fast = 0;
- time_t now;
- char *clean, buf[1024];
+ time_t now, timeout = -1;
+ char *clean, buf[1024], ch;
- if( argc >= 1 && strcmp(argv[0], "-n") == 0 )
- fast = 1;
+ while( (ch = getopt(argc, argv, "nt:")) != -1 )
+ switch( ch ){
+ case 'n':
+ fast = 1;
+ break;
+ case 't':
+ timeout = atoi(optarg);
+ break;
+ default:
+ printf("usage:\tshmctl\tutmpfix[-n] [-t timeout]\n");
+ return 1;
+ }
time(&now);
for( i = 0 ; i < 5 ; ++i )
@@ -74,21 +84,27 @@ int utmpfix(int argc, char **argv)
clean = NULL;
if( !isalpha(utmpshm->uinfo[i].userid[0]) )
clean = "userid error";
+ else if( kill(utmpshm->uinfo[i].pid, 0) < 0 ){
+ clean = "process error";
+ purge_utmp(&utmpshm->uinfo[i]);
+ }
else if( !fast ){
#ifdef DOTIMEOUT
- if( now - utmpshm->uinfo[i].lastact > IDLE_TIMEOUT ){
+ if( now - utmpshm->uinfo[i].lastact >
+ (timeout == -1 ? IDLE_TIMEOUT : timeout) ){
sprintf(buf, "timeout(%s",
ctime(&utmpshm->uinfo[i].lastact));
buf[strlen(buf) - 1] = 0;
strcat(buf, ")");
+ clean = buf;
kill(utmpshm->uinfo[i].pid, SIGHUP);
purge_utmp(&utmpshm->uinfo[i]);
}
else
#endif
- if( searchuser(utmpshm->uinfo[i].userid) == 0 ){
- clean = "user not exist";
- }
+ if( searchuser(utmpshm->uinfo[i].userid) == 0 ){
+ clean = "user not exist";
+ }
}
if( clean ){
@@ -264,15 +280,15 @@ int showglobe(int argc, char **argv)
int setglobe(int argc, char **argv)
{
int where;
- if( argc != 2 )
+ if( argc != 3 )
return 1;
- where = atoi(argv[0]);
+ where = atoi(argv[1]);
if( !(0 <= where && where <= 9) ){
puts("only GLOBE[0] ~ GLOBE[9]");
return 1;
}
printf("GLOBE[%d] = %d -> ", where, ptt->GLOBE[where]);
- printf("%d\n", ptt->GLOBE[where] = atoi(argv[1]));
+ printf("%d\n", ptt->GLOBE[where] = atoi(argv[2]));
return 0;
}
@@ -309,7 +325,7 @@ int main(int argc, char **argv)
resolve_fcache();
for( i = 0 ; cmd[i].func != NULL ; ++i )
if( strcmp(cmd[i].cmd, argv[1]) == 0 ){
- return cmd[i].func(argc - 2, &argv[2]);
+ return cmd[i].func(argc - 1, &argv[1]);
}
}
if( argc == 1 || cmd[i].func == NULL ){