summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwens <wens@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2006-08-21 23:58:46 +0800
committerwens <wens@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2006-08-21 23:58:46 +0800
commitc708a61a17ff8ba114ca95bb3a3d36b71538a825 (patch)
tree9c4095a4b307412c5be1b91a0235c8aa1bf41ca3
parent8455f22f975f00c901cf8b30ac7f739a230edc1b (diff)
downloadpttbbs-c708a61a17ff8ba114ca95bb3a3d36b71538a825.tar
pttbbs-c708a61a17ff8ba114ca95bb3a3d36b71538a825.tar.gz
pttbbs-c708a61a17ff8ba114ca95bb3a3d36b71538a825.tar.bz2
pttbbs-c708a61a17ff8ba114ca95bb3a3d36b71538a825.tar.lz
pttbbs-c708a61a17ff8ba114ca95bb3a3d36b71538a825.tar.xz
pttbbs-c708a61a17ff8ba114ca95bb3a3d36b71538a825.tar.zst
pttbbs-c708a61a17ff8ba114ca95bb3a3d36b71538a825.zip
site-wide broadcast
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3399 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--util/Makefile2
-rw-r--r--util/broadcast.c73
2 files changed, 74 insertions, 1 deletions
diff --git a/util/Makefile b/util/Makefile
index 63f3552f..b2bff5ce 100644
--- a/util/Makefile
+++ b/util/Makefile
@@ -20,7 +20,7 @@ MBBSD_OBJS= \
CPROG_WITH_UTIL= \
boardlist BM_money post poststat \
jungo account birth deluserfile \
- expire mandex horoscope \
+ expire mandex horoscope broadcast \
openvice parse_news openticket topusr \
yearsold toplazyBM toplazyBBM writemoney \
reaper buildAnnounce inndBM mailangel \
diff --git a/util/broadcast.c b/util/broadcast.c
new file mode 100644
index 00000000..13dab086
--- /dev/null
+++ b/util/broadcast.c
@@ -0,0 +1,73 @@
+/* $Id$ */
+#include "bbs.h"
+#include <getopt.h>
+
+extern SHM_t *SHM;
+
+int main(int argc, char *argv[])
+{
+ int sleep_time = 5;
+ int num_per_loop = 500;
+
+ int i, j;
+ userinfo_t *uentp;
+ msgque_t msg;
+ time_t now;
+ int *sorted, UTMPnumber; // SHM snapshot
+
+ while ((i = getopt(argc, argv, "t:n:")) != -1)
+ switch (i) {
+ case 't':
+ sleep_time = atoi(optarg);
+ break;
+ case 'n':
+ num_per_loop = atoi(optarg);
+ break;
+ }
+
+ if (optind == argc || strlen(argv[optind]) == 0) {
+ fprintf(stderr, "no message to broadcast\n\n");
+ return 1;
+ }
+
+ printf("broadcast \"%s\" ? [y/N]\n", argv[optind]);
+ if (tolower(getchar()) != 'y')
+ return 0;
+
+ attach_SHM();
+ sorted = (int *)malloc(sizeof(int) * USHM_SIZE);
+ memcpy(sorted, SHM->sorted[SHM->currsorted][0], sizeof(int) * USHM_SIZE);
+ UTMPnumber = SHM->UTMPnumber;
+
+ msg.pid = currpid;
+ strlcpy(msg.userid, "¨t²Î¼s¼½", sizeof(msg.userid));
+ snprintf(msg.last_call_in, sizeof(msg.last_call_in), "[¼s¼½]%s", argv[optind]);
+
+ now = time(NULL);
+
+ for (i = 0, j = 1; i < UTMPnumber; ++i, ++j) {
+ if (j == num_per_loop) {
+ fprintf(stderr, "%5d/%5d\n", i + 1, UTMPnumber);
+ j = 1;
+ now = time(NULL);
+ sleep(sleep_time);
+ }
+
+ // XXX why use sorted list?
+ // can we just scan uinfo with proper checking?
+ uentp = &SHM->uinfo[sorted[i]];
+ if (uentp->pid && kill(uentp->pid, 0) != -1){
+ int write_pos = uentp->msgcount;
+ if (write_pos < (MAX_MSGS - 1)){
+ uentp->msgcount = write_pos + 1;
+ memcpy(&uentp->msgs[write_pos], &msg, sizeof(msg));
+#ifdef NOKILLWATERBALL
+ uentp->wbtime = (time4_t)now;
+#else
+ kill(uentp->pid, SIGUSR2);
+#endif
+ }
+ }
+ }
+ return 0;
+}