summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-03-23 21:19:40 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-03-23 21:19:40 +0800
commit08ead020dbe84be8507459fcd06dc4541ed3bae2 (patch)
tree90f67bae1c4f835f69f8e10a0a5c4fa5c77e4c9e
parent43e01c2ef41c038be688be9eb6ee2e8e0bf6de24 (diff)
downloadpttbbs-08ead020dbe84be8507459fcd06dc4541ed3bae2.tar
pttbbs-08ead020dbe84be8507459fcd06dc4541ed3bae2.tar.gz
pttbbs-08ead020dbe84be8507459fcd06dc4541ed3bae2.tar.bz2
pttbbs-08ead020dbe84be8507459fcd06dc4541ed3bae2.tar.lz
pttbbs-08ead020dbe84be8507459fcd06dc4541ed3bae2.tar.xz
pttbbs-08ead020dbe84be8507459fcd06dc4541ed3bae2.tar.zst
pttbbs-08ead020dbe84be8507459fcd06dc4541ed3bae2.zip
add shmctl
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@59 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--util/Makefile7
-rw-r--r--util/shmctl.c75
2 files changed, 80 insertions, 2 deletions
diff --git a/util/Makefile b/util/Makefile
index 6f204648..2b7aa690 100644
--- a/util/Makefile
+++ b/util/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.4 2002/03/09 17:44:30 in2 Exp $
+# $Id: Makefile,v 1.5 2002/03/23 13:19:40 in2 Exp $
BBSHOME?=$(HOME)
OSTYPE=linux
@@ -30,7 +30,7 @@ CPROGS= bbsmail BM_money post account birth deluserfile expire mandex\
poststat showboard antispam countalldice webgrep bbsrf\
initbbs outmail xchatd userlist tunepasswd buildir reaper shmsweep\
merge_passwd merge_board inndBM buildAnnounce rmuid \
- toplazyBM jungo toplazyBBM
+ toplazyBM jungo toplazyBBM shmctl
PROGS= $(CPROGS) BM_money.sh backpasswd.sh mailog.sh opendice.sh\
openticket.sh stock.sh topsong.sh weather.sh stock.perl weather.perl\
@@ -152,6 +152,9 @@ merge_board : merge_board.c
bbsctl: bbsctl.c
$(CC) $(CFLAGS) -o $@ $@.c
+shmctl: shmctl.c
+ $(CC) $(CFLAGS) -o $@ $@.c $(OBJS)
+
install: $(PROGS)
install -d $(BBSHOME)/bin/
install -c -m 755 $(PROGS) $(BBSHOME)/bin/
diff --git a/util/shmctl.c b/util/shmctl.c
new file mode 100644
index 00000000..77b9c99b
--- /dev/null
+++ b/util/shmctl.c
@@ -0,0 +1,75 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include "config.h"
+#include "pttstruct.h"
+#include "util.h"
+
+extern struct utmpfile_t *utmpshm;
+
+int fixutmp(int argc, char **argv)
+{
+ int i;
+ char buf[1024], *clean;
+ struct stat st;
+ if( utmpshm->busystate ){
+ puts("utmpshm is busy");
+ return 0;
+ }
+ utmpshm->busystate = 1;
+ for( i = 0 ; i < USHM_SIZE ; ++i )
+ if( utmpshm->uinfo[i].pid ){
+ clean = NULL;
+ if( !isalpha(utmpshm->uinfo[i].userid[0]) )
+ clean = "userid error";
+ else{
+ sprintf(buf, "/proc/%d", utmpshm->uinfo[i].pid);
+ if( stat(buf, &st) < 0 )
+ clean = "process not exist";
+ }
+
+ if( clean ){
+ printf("clean %06d(%s), userid: %s\n",
+ i, clean, utmpshm->uinfo[i].userid);
+ memset(&utmpshm->uinfo[i], 0, sizeof(userinfo_t));
+ }
+ }
+ utmpshm->busystate = 0;
+ return 0;
+}
+
+struct {
+ int (*func)(int, char **);
+ char *cmd, *descript;
+} cmd[] =
+ { {fixutmp, "fixutmp", "clear dead userlist entry"},
+ {NULL, NULL, NULL} };
+
+int main(int argc, char **argv)
+{
+ int i = 0;
+
+ if( argc >= 2 ){
+ resolve_utmp();
+ resolve_boards();
+ //resolve_garbage();
+ resolve_fcache();
+ for( i = 0 ; cmd[i].func != NULL ; ++i )
+ if( strcmp(cmd[i].cmd, argv[1]) == 0 ){
+ cmd[i].func(argc - 2, &argv[2]);
+ break;
+ }
+ }
+ if( argc == 1 || cmd[i].func == NULL ){
+ /* usage */
+ printf("usage: bbsctl [command] [options]\n");
+ printf("commands:\n");
+ for( i = 0 ; cmd[i].func != NULL ; ++i )
+ printf("\t%-15s%s\n", cmd[i].cmd, cmd[i].descript);
+ }
+ return 0;
+}