summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-04-14 22:08:56 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-04-14 22:08:56 +0800
commit5894f7afe1f35469e766a3c3fd6f6b0ee806a31a (patch)
tree4d534c39e130d6c83f6dfaec1be3a1322749f288
parent3520f2dfe75daa8b73eb43a66688da275a492725 (diff)
downloadpttbbs-5894f7afe1f35469e766a3c3fd6f6b0ee806a31a.tar
pttbbs-5894f7afe1f35469e766a3c3fd6f6b0ee806a31a.tar.gz
pttbbs-5894f7afe1f35469e766a3c3fd6f6b0ee806a31a.tar.bz2
pttbbs-5894f7afe1f35469e766a3c3fd6f6b0ee806a31a.tar.lz
pttbbs-5894f7afe1f35469e766a3c3fd6f6b0ee806a31a.tar.xz
pttbbs-5894f7afe1f35469e766a3c3fd6f6b0ee806a31a.tar.zst
pttbbs-5894f7afe1f35469e766a3c3fd6f6b0ee806a31a.zip
kvm's killdeadbbs
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@102 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--util/Makefile7
-rw-r--r--util/killdeadbbs.c56
2 files changed, 61 insertions, 2 deletions
diff --git a/util/Makefile b/util/Makefile
index 443ac6eb..d1dd93e1 100644
--- a/util/Makefile
+++ b/util/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.9 2002/04/05 14:36:44 in2 Exp $
+# $Id: Makefile,v 1.10 2002/04/14 14:08:56 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 shmctl
+ toplazyBM jungo toplazyBBM shmctl killdeadbbs
PROGS= $(CPROGS) BM_money.sh backpasswd.sh mailog.sh opendice.sh\
openticket.sh stock.sh topsong.sh weather.sh stock.perl weather.perl\
@@ -156,6 +156,9 @@ bbsctl: bbsctl.c
shmctl: shmctl.c $(OBJS)
$(CC) $(CFLAGS) -o $@ $@.c $(OBJS)
+killdeadbbs: killdeadbbs.c
+ $(CC) $(CFLAGS) -lkvm -o $@ $@.c
+
install: $(PROGS)
install -d $(BBSHOME)/bin/
install -c -m 755 $(PROGS) $(BBSHOME)/bin/
diff --git a/util/killdeadbbs.c b/util/killdeadbbs.c
new file mode 100644
index 00000000..0c83fe29
--- /dev/null
+++ b/util/killdeadbbs.c
@@ -0,0 +1,56 @@
+#ifndef FreeBSD
+int main(int argc, char **argv)
+{
+ puts("this program is only for FreeBSD");
+}
+#else
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <signal.h>
+#include <kvm.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/user.h>
+#include "config.h" // for BBSUID
+
+int main(int argc, char **argv)
+{
+ kvm_t *kd;
+ struct kinfo_proc *kp;
+ char errbuf[_POSIX2_LINE_MAX];
+ int nentries, i, npids;
+ pid_t pids[8192];
+ kd = kvm_openfiles("/dev/null", "/dev/null", NULL, O_RDONLY, errbuf);
+ if( kd == NULL )
+ errx(1, "%s", errbuf);
+
+ if ((kp = kvm_getprocs(kd, KERN_PROC_UID, BBSUID, &nentries)) == 0 ||
+ nentries < 0)
+ errx(1, "%s", kvm_geterr(kd));
+
+ for( npids = 0, i = nentries ; --i >= 0 ; ++kp ){
+ if( strncmp(kp->ki_comm, "mbbsd", 5) == 0 ){
+ if( kp->ki_runtime > (60 * 1000000) ){ // 60 secs
+ kill(kp->ki_pid, 1);
+ pids[npids++] = kp->ki_pid;
+ printf("%d\n", kp->ki_pid);
+ }
+ }
+ }
+
+ if( npids != 0 ){
+ sleep(2);
+ while( --npids >= 0 )
+ kill(pids[npids], 9);
+ }
+
+ kvm_close(kd);
+ return 0;
+}
+
+#endif