From c708a61a17ff8ba114ca95bb3a3d36b71538a825 Mon Sep 17 00:00:00 2001 From: wens Date: Mon, 21 Aug 2006 15:58:46 +0000 Subject: site-wide broadcast git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3399 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- util/Makefile | 2 +- util/broadcast.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 util/broadcast.c (limited to 'util') 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 + +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; +} -- cgit v1.2.3