| 1 |
--- inn-1.7.2.orig/config/files.list |
| 2 |
+++ inn-1.7.2/config/files.list |
| 3 |
@@ -107,4 +107,5 @@ |
| 4 |
../syslog/syslog.c |
| 5 |
../syslog/syslog.conf |
| 6 |
../syslog/syslogd.c |
| 7 |
+../actived/Makefile |
| 8 |
;; Do not run subst on its own manpage! ../doc/subst.1 |
| 9 |
--- inn-1.7.2.orig/include/paths.h |
| 10 |
+++ inn-1.7.2/include/paths.h |
| 11 |
@@ -210,3 +217,13 @@ |
| 12 |
|
| 13 |
/* =()<#define _PATH_PERL_FILTER_NNRPD "@<_PATH_PERL_FILTER_NNRPD>@">()= */ |
| 14 |
#define _PATH_PERL_FILTER_NNRPD "/usr/news/bin/control/filter_nnrpd.pl" |
| 15 |
+ |
| 16 |
+/* |
| 17 |
+** 18. actived configuration |
| 18 |
+*/ |
| 19 |
+ |
| 20 |
+/* =()<#define _PATH_ACTIVED "@<_PATH_ACTIVED>@">()= */ |
| 21 |
+#define _PATH_ACTIVED "/usr/lib/news/bin/actived" |
| 22 |
+/* =()<#define _PATH_ACTIVEDPID "@<_PATH_ACTIVEDPID>@">()= */ |
| 23 |
+#define _PATH_ACTIVEDPID "/var/run/innd/actived.pid" |
| 24 |
+ |
| 25 |
--- inn-1.7.2.orig/nnrpd/Makefile |
| 26 |
+++ inn-1.7.2/nnrpd/Makefile |
| 27 |
@@ -37,13 +37,15 @@ |
| 28 |
LIBNEWS = ../libinn.a |
| 29 |
LINTLIB = ../llib-linn.ln |
| 30 |
|
| 31 |
+CFLAGS+= -DOVERSCREAM |
| 32 |
+ |
| 33 |
SOURCES = \ |
| 34 |
article.c group.c commands.c misc.c newnews.c nnrpd.c \ |
| 35 |
- perl.c post.c loadave.c |
| 36 |
+ perl.c post.c loadave.c udp.c |
| 37 |
|
| 38 |
OBJECTS = \ |
| 39 |
article.o group.o commands.o misc.o newnews.o nnrpd.o \ |
| 40 |
- perl.o post.o loadave.o |
| 41 |
+ perl.o post.o loadave.o udp.o |
| 42 |
|
| 43 |
ALL = nnrpd |
| 44 |
|
| 45 |
--- inn-1.7.2.orig/nnrpd/group.c |
| 46 |
+++ inn-1.7.2/nnrpd/group.c |
| 47 |
@@ -8,6 +8,15 @@ |
| 48 |
#include "clibrary.h" |
| 49 |
#include "nnrpd.h" |
| 50 |
#include "mydir.h" |
| 51 |
+#include "../actived/protocol.h" |
| 52 |
+#include <sys/time.h> |
| 53 |
+#include <unistd.h> |
| 54 |
+ |
| 55 |
+BOOL XGetGroupList(); |
| 56 |
+int write_udp(int s, char *buf, int len); |
| 57 |
+int read_udp(int s, char *buf, int len); |
| 58 |
+int create_udp_socket(int port); |
| 59 |
+int connect_udp_socket(int s, char *address, int port); |
| 60 |
|
| 61 |
|
| 62 |
/* |
| 63 |
@@ -30,13 +33,34 @@ |
| 64 |
STATIC GROUPENTRY *GRPentries; |
| 65 |
STATIC int GRPbuckets; |
| 66 |
STATIC int GRPsize; |
| 67 |
+STATIC int GRPactived = -1; |
| 68 |
+int GRPuselocalhash = 1; /*actived is disabled by default*/ |
| 69 |
+STATIC int NRequestID; |
| 70 |
+ |
| 71 |
+ |
| 72 |
+void |
| 73 |
+NNewRequestID() |
| 74 |
+{ |
| 75 |
+ static int pid = -1; |
| 76 |
+ static int count = 123456789; |
| 77 |
+ struct timeval tv; |
| 78 |
+ |
| 79 |
+ if (pid < 0) { |
| 80 |
+ pid = getpid(); |
| 81 |
+ } |
| 82 |
+ gettimeofday(&tv, NULL); |
| 83 |
+ count += pid; |
| 84 |
+ NRequestID = tv.tv_sec ^ tv.tv_usec ^ pid ^ count; |
| 85 |
+} |
| 86 |
+ |
| 87 |
+ |
| 88 |
|
| 89 |
|
| 90 |
/* |
| 91 |
** See if a given newsgroup exists. |
| 92 |
*/ |
| 93 |
GROUPENTRY * |
| 94 |
-GRPfind(group) |
| 95 |
+XGRPfind(group) |
| 96 |
register char *group; |
| 97 |
{ |
| 98 |
register char *p; |
| 99 |
@@ -56,8 +80,129 @@ |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
+ |
| 104 |
+GROUPENTRY * |
| 105 |
+NGRPfind(group) |
| 106 |
+ register char *group; |
| 107 |
+{ |
| 108 |
+ int now = time(NULL); |
| 109 |
+ int expireat = now + ACTIVED_TIMEOUT; |
| 110 |
+ int last = now - 2; |
| 111 |
+ static struct wireprotocol buffer; |
| 112 |
+ fd_set fdset; |
| 113 |
+ struct timeval timeout; |
| 114 |
+ static GROUPENTRY data; |
| 115 |
+ |
| 116 |
+ /* Okay. Let's ask the server for the data. */ |
| 117 |
+ NNewRequestID(); |
| 118 |
+ while (now < expireat) { |
| 119 |
+ now = time(NULL); |
| 120 |
+ if (last < now - 1) { |
| 121 |
+ last = now; |
| 122 |
+ buffer.RequestID = NRequestID; |
| 123 |
+ buffer.RequestType = REQ_FIND; |
| 124 |
+ strncpy(buffer.Name, group, sizeof(buffer.Name) - 1); |
| 125 |
+ buffer.Name[sizeof(buffer.Name) - 1] = '\0'; |
| 126 |
+ |
| 127 |
+ if (write_udp(GRPactived, (char *)&buffer, sizeof(buffer)) != sizeof(buffer)) { |
| 128 |
+ syslog(L_ERROR, "%s actived socket couldnt be written FIND %m", |
| 129 |
+ ClientHost); |
| 130 |
+ sleep(1); |
| 131 |
+ continue; |
| 132 |
+ } |
| 133 |
+ } |
| 134 |
+ FD_ZERO(&fdset); |
| 135 |
+ FD_SET(GRPactived, &fdset); |
| 136 |
+ timeout.tv_sec = 1; |
| 137 |
+ timeout.tv_usec = 0; |
| 138 |
+ if (select(GRPactived + 1, &fdset, NULL, NULL, &timeout) < 0) { |
| 139 |
+ syslog(L_ERROR, "%s actived socket failed select %m", |
| 140 |
+ ClientHost); |
| 141 |
+ sleep(1); |
| 142 |
+ continue; |
| 143 |
+ } |
| 144 |
+ if (FD_ISSET(GRPactived, &fdset)) { |
| 145 |
+ if (read_udp(GRPactived, (char *)&buffer, sizeof(buffer)) != sizeof(buffer)) { |
| 146 |
+ syslog(L_ERROR, "%s actived socket couldnt be read FINDRESP %m", |
| 147 |
+ ClientHost); |
| 148 |
+ sleep(1); |
| 149 |
+ continue; |
| 150 |
+ } |
| 151 |
+ if (buffer.RequestID != NRequestID) { |
| 152 |
+ syslog(L_ERROR, "%s actived socket returned a different request-ID %d/%d", |
| 153 |
+ ClientHost, buffer.RequestID, NRequestID); |
| 154 |
+ sleep(1); |
| 155 |
+ continue; |
| 156 |
+ } |
| 157 |
+ if (buffer.RequestType != REQ_FINDRESP) { |
| 158 |
+ syslog(L_ERROR, "%s actived socket returned a non-FINDRESP %d", |
| 159 |
+ ClientHost, buffer.RequestType); |
| 160 |
+ sleep(1); |
| 161 |
+ continue; |
| 162 |
+ } |
| 163 |
+ |
| 164 |
+ /* Was the request successful? Did we find the group? */ |
| 165 |
+ if (! buffer.Success) { |
| 166 |
+ return(NULL); |
| 167 |
+ } |
| 168 |
+ |
| 169 |
+ /* Looks good! Copy all the data to the static "data" struct */ |
| 170 |
+ if (! buffer.NameNull) { |
| 171 |
+ data.Name = buffer.Name; |
| 172 |
+ } else { |
| 173 |
+ data.Name = NULL; |
| 174 |
+ } |
| 175 |
+ data.High = buffer.High; |
| 176 |
+ data.Low = buffer.Low; |
| 177 |
+ data.Flag = buffer.Flag; |
| 178 |
+ if (! buffer.AliasNull) { |
| 179 |
+ data.Alias = buffer.Alias; |
| 180 |
+ } else { |
| 181 |
+ data.Alias = NULL; |
| 182 |
+ } |
| 183 |
+ return(&data); |
| 184 |
+ } |
| 185 |
+ } |
| 186 |
+ |
| 187 |
+ /* Something is very wrong. Fall back to local access and whine like |
| 188 |
+ hell. GRPuselocalhash is explicitly checked by GRPfind, and will |
| 189 |
+ handle initializing the database for us. */ |
| 190 |
+ |
| 191 |
+ syslog(L_ERROR, "%s NOT using actived", ClientHost); |
| 192 |
+ GRPuselocalhash++; |
| 193 |
+ return(NULL); |
| 194 |
+} |
| 195 |
+ |
| 196 |
+ |
| 197 |
+GROUPENTRY * |
| 198 |
+GRPfind(group) |
| 199 |
+ register char *group; |
| 200 |
+{ |
| 201 |
+ GROUPENTRY *rval; |
| 202 |
+ |
| 203 |
+ /* |
| 204 |
+ * If we are not flagged to use local hash, call NGRPfind. |
| 205 |
+ * That could potentially fail (server no answer, etc) in which |
| 206 |
+ * case we fall back to standard INN and scream bloody murder. |
| 207 |
+ * NGRPfind will toggle GRPuselocalhash to TRUE if it has problems. |
| 208 |
+ */ |
| 209 |
+ |
| 210 |
+ if (! GRPuselocalhash) { |
| 211 |
+ rval = NGRPfind(group); |
| 212 |
+ if (! GRPuselocalhash) { |
| 213 |
+ return(rval); |
| 214 |
+ } |
| 215 |
+ |
| 216 |
+ /* Ow! We are falling back to local access since NGRPfind failed! */ |
| 217 |
+ XGetGroupList(); |
| 218 |
+ } |
| 219 |
+ |
| 220 |
+ return(XGRPfind(group)); |
| 221 |
+} |
| 222 |
+ |
| 223 |
+ |
| 224 |
STATIC void |
| 225 |
-GRPhash() |
| 226 |
+XGRPhash() |
| 227 |
{ |
| 228 |
register char *p; |
| 229 |
register int i; |
| 230 |
@@ -100,7 +245,7 @@ |
| 231 |
** newsgroups read in. Return TRUE if okay, FALSE on error. |
| 232 |
*/ |
| 233 |
BOOL |
| 234 |
-GetGroupList() |
| 235 |
+XGetGroupList() |
| 236 |
{ |
| 237 |
static char *active; |
| 238 |
register char *p; |
| 239 |
@@ -166,10 +311,112 @@ |
| 240 |
} |
| 241 |
|
| 242 |
GRPsize = i; |
| 243 |
- GRPhash(); |
| 244 |
+ XGRPhash(); |
| 245 |
return TRUE; |
| 246 |
} |
| 247 |
|
| 248 |
+BOOL |
| 249 |
+NGetGroupList() |
| 250 |
+{ |
| 251 |
+ int now = time(NULL); |
| 252 |
+ int expireat = now + ACTIVED_TIMEOUT; |
| 253 |
+ int last = now - 2; |
| 254 |
+ int s; |
| 255 |
+ struct wireprotocol buffer; |
| 256 |
+ fd_set fdset; |
| 257 |
+ struct timeval timeout; |
| 258 |
+ |
| 259 |
+ if (GRPactived < 0) { |
| 260 |
+ if ((s = create_udp_socket(0)) < 0) { |
| 261 |
+ syslog(L_ERROR, "%s actived socket couldnt be created %m", |
| 262 |
+ ClientHost); |
| 263 |
+ return(FALSE); |
| 264 |
+ } |
| 265 |
+ if (connect_udp_socket(s, "localhost", 1119) < 0) { |
| 266 |
+ syslog(L_ERROR, "%s actived socket couldnt be connected %m", |
| 267 |
+ ClientHost); |
| 268 |
+ return(FALSE); |
| 269 |
+ } |
| 270 |
+ if (fcntl(s, F_SETFL, O_NDELAY) < 0) { |
| 271 |
+ syslog(L_ERROR, "%s actived socket couldnt be fcntl O_NDELAY %m", |
| 272 |
+ ClientHost); |
| 273 |
+ return(FALSE); |
| 274 |
+ } |
| 275 |
+ GRPactived = s; |
| 276 |
+ } |
| 277 |
+ |
| 278 |
+ /* Okay. Let's ask the server if it's there. */ |
| 279 |
+ NNewRequestID(); |
| 280 |
+ while (now < expireat) { |
| 281 |
+ now = time(NULL); |
| 282 |
+ if (last < now - 1) { |
| 283 |
+ last = now; |
| 284 |
+ buffer.RequestID = NRequestID; |
| 285 |
+ buffer.RequestType = REQ_AYT; |
| 286 |
+ |
| 287 |
+ if (write_udp(GRPactived, (char *)&buffer, sizeof(buffer)) != sizeof(buffer)) { |
| 288 |
+ syslog(L_ERROR, "%s actived socket couldnt be written AYT %m", |
| 289 |
+ ClientHost); |
| 290 |
+ sleep(1); |
| 291 |
+ continue; |
| 292 |
+ } |
| 293 |
+ } |
| 294 |
+ FD_ZERO(&fdset); |
| 295 |
+ FD_SET(GRPactived, &fdset); |
| 296 |
+ timeout.tv_sec = 1; |
| 297 |
+ timeout.tv_usec = 0; |
| 298 |
+ if (select(GRPactived + 1, &fdset, NULL, NULL, &timeout) < 0) { |
| 299 |
+ syslog(L_ERROR, "%s actived socket failed select %m", |
| 300 |
+ ClientHost); |
| 301 |
+ sleep(1); |
| 302 |
+ return(FALSE); |
| 303 |
+ } |
| 304 |
+ if (FD_ISSET(GRPactived, &fdset)) { |
| 305 |
+ if (read_udp(GRPactived, (char *)&buffer, sizeof(buffer)) != sizeof(buffer)) { |
| 306 |
+ syslog(L_ERROR, "%s actived socket couldnt be read AYTACK %m", |
| 307 |
+ ClientHost); |
| 308 |
+ sleep(1); |
| 309 |
+ continue; |
| 310 |
+ } |
| 311 |
+ if (buffer.RequestID != NRequestID) { |
| 312 |
+ syslog(L_ERROR, "%s actived socket returned a different request-ID %d/%d", |
| 313 |
+ ClientHost, buffer.RequestID, NRequestID); |
| 314 |
+ sleep(1); |
| 315 |
+ continue; |
| 316 |
+ } |
| 317 |
+ if (buffer.RequestType != REQ_AYTACK) { |
| 318 |
+ syslog(L_ERROR, "%s actived socket returned a non-AYTACK %d", |
| 319 |
+ ClientHost, buffer.RequestType); |
| 320 |
+ sleep(1); |
| 321 |
+ continue; |
| 322 |
+ } |
| 323 |
+ /* Looks good! */ |
| 324 |
+ return(TRUE); |
| 325 |
+ } |
| 326 |
+ } |
| 327 |
+ return(FALSE); |
| 328 |
+} |
| 329 |
+ |
| 330 |
+BOOL |
| 331 |
+GetGroupList() |
| 332 |
+{ |
| 333 |
+ /* |
| 334 |
+ * If we are not flagged to use local hash, call NGetGroupList. |
| 335 |
+ * That could potentially fail (server no answer, etc) in which |
| 336 |
+ * case we fall back to standard INN and scream bloody murder. |
| 337 |
+ */ |
| 338 |
+ if (! GRPuselocalhash) { |
| 339 |
+ if (NGetGroupList() == FALSE) { |
| 340 |
+ syslog(L_ERROR, "%s NOT using actived", ClientHost); |
| 341 |
+ GRPuselocalhash++; |
| 342 |
+ return(XGetGroupList()); |
| 343 |
+ } |
| 344 |
+ return(TRUE); |
| 345 |
+ } else { |
| 346 |
+ return(XGetGroupList()); |
| 347 |
+ } |
| 348 |
+} |
| 349 |
+ |
| 350 |
|
| 351 |
/* |
| 352 |
** Sorting predicate to put newsgroup names into numeric order. |
| 353 |
--- inn-1.7.2.orig/nnrpd/nnrpd.c |
| 354 |
+++ inn-1.7.2/nnrpd/nnrpd.c |
| 355 |
@@ -636,6 +637,14 @@ |
| 356 |
ExitWithStats(0); |
| 357 |
} |
| 358 |
|
| 359 |
+ { |
| 360 |
+ char *UseActived; |
| 361 |
+ extern int GRPuselocalhash; |
| 362 |
+ if ((UseActived = GetConfigValue(_CONF_USEACTIVED)) != NULL) |
| 363 |
+ if (EQ(UseActived, "true") || EQ(UseActived, "yes")) |
| 364 |
+ GRPuselocalhash = 0; |
| 365 |
+ } |
| 366 |
+ |
| 367 |
ARTreadschema(); |
| 368 |
if (!GetGroupList()) { |
| 369 |
/* This shouldn't really happen. */ |
| 370 |
--- inn-1.7.2.orig/nnrpd/udp.c |
| 371 |
+++ inn-1.7.2/nnrpd/udp.c |
| 372 |
@@ -0,0 +1,162 @@ |
| 373 |
+#include <stdio.h> |
| 374 |
+#include <sys/types.h> |
| 375 |
+#include "clibrary.h" |
| 376 |
+#include <errno.h> |
| 377 |
+#include <sys/socket.h> |
| 378 |
+#include <netinet/in.h> |
| 379 |
+#include <arpa/inet.h> |
| 380 |
+#include <ctype.h> |
| 381 |
+#include <netdb.h> |
| 382 |
+#include "logging.h" |
| 383 |
+ |
| 384 |
+#ifdef NEED_BZERO_ETC |
| 385 |
+#include <fcntl.h> |
| 386 |
+void |
| 387 |
+bzero(b, length) |
| 388 |
+ char *b; |
| 389 |
+ int length; |
| 390 |
+{ |
| 391 |
+ while (--length >= 0) |
| 392 |
+ *b++ = '\0'; |
| 393 |
+} |
| 394 |
+void |
| 395 |
+bcopy(b1, b2, length) |
| 396 |
+ char *b1; |
| 397 |
+ char *b2; |
| 398 |
+ int length; |
| 399 |
+{ |
| 400 |
+ while (--length >= 0) |
| 401 |
+ *b2++ = *b1++; |
| 402 |
+} |
| 403 |
+#endif |
| 404 |
+ |
| 405 |
+int create_udp_socket(int port) |
| 406 |
+{ |
| 407 |
+ int s; |
| 408 |
+ struct sockaddr_in sin; |
| 409 |
+ |
| 410 |
+ sin.sin_port = htons(port); |
| 411 |
+ sin.sin_family = AF_INET; |
| 412 |
+ sin.sin_addr.s_addr = INADDR_ANY; |
| 413 |
+ |
| 414 |
+ if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { |
| 415 |
+ syslog(L_ERROR, "create_udp_socket: socket: %m"); |
| 416 |
+ return(-1); |
| 417 |
+ } |
| 418 |
+ if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { |
| 419 |
+ syslog(L_ERROR, "create_udp_socket: bind: %m"); |
| 420 |
+ return(-1); |
| 421 |
+ } |
| 422 |
+ return(s); |
| 423 |
+} |
| 424 |
+ |
| 425 |
+ |
| 426 |
+ |
| 427 |
+ |
| 428 |
+ |
| 429 |
+int make_udp_sockaddr(struct sockaddr_in *addr, char *ascii) |
| 430 |
+{ |
| 431 |
+ struct hostent *host; |
| 432 |
+ int dots = 0; |
| 433 |
+ int numeric = 0; |
| 434 |
+ char *str, *colon, *lastdot, *ptr; |
| 435 |
+ |
| 436 |
+ if (! (str = malloc(strlen(ascii) + 1))) { |
| 437 |
+ syslog(L_ERROR, "make_udp_sockaddr: malloc: %m"); |
| 438 |
+ return(-1); |
| 439 |
+ } |
| 440 |
+ strcpy(str, ascii); |
| 441 |
+ colon = strrchr(str, ':'); |
| 442 |
+ lastdot = strrchr(str, '.'); |
| 443 |
+ |
| 444 |
+ addr->sin_family = AF_INET; |
| 445 |
+ |
| 446 |
+ /* Count the number of dots in the address. */ |
| 447 |
+ for (ptr = str; *ptr; ptr++) { |
| 448 |
+ if (*ptr == '.') { |
| 449 |
+ dots++; |
| 450 |
+ } |
| 451 |
+ } |
| 452 |
+ |
| 453 |
+ /* Check if it seems to be numeric. */ |
| 454 |
+ numeric = isdigit(*str); |
| 455 |
+ |
| 456 |
+ /* If numeric and four dots, we have a.b.c.d.6000 */ |
| 457 |
+ if (numeric && dots == 4) { |
| 458 |
+ *lastdot = '\0'; |
| 459 |
+ addr->sin_port = htons(atoi(lastdot + 1)); |
| 460 |
+ } |
| 461 |
+ /* If nonnumeric, check if the last part is a port */ |
| 462 |
+ if (! numeric && lastdot && isdigit(*(lastdot + 1))) { |
| 463 |
+ *lastdot = '\0'; |
| 464 |
+ addr->sin_port = htons(atoi(lastdot + 1)); |
| 465 |
+ } |
| 466 |
+ /* Now do we have a numeric address */ |
| 467 |
+ if (numeric) { |
| 468 |
+ addr->sin_addr.s_addr = inet_addr(str); |
| 469 |
+ free(str); |
| 470 |
+ return(0); |
| 471 |
+ } |
| 472 |
+ /* Or a name */ |
| 473 |
+ if (! (host = gethostbyname(str))) { |
| 474 |
+ free(str); |
| 475 |
+ syslog(L_ERROR, "make_udp_sockaddr: gethostbyname: %m"); |
| 476 |
+ return(-1); |
| 477 |
+ } |
| 478 |
+ bcopy(host->h_addr_list[0], (char *)&addr->sin_addr.s_addr, sizeof(addr->sin_addr.s_addr)); |
| 479 |
+ free(str); |
| 480 |
+ return(0); |
| 481 |
+} |
| 482 |
+ |
| 483 |
+ |
| 484 |
+ |
| 485 |
+ |
| 486 |
+ |
| 487 |
+int connect_udp_socket(int s, char *address, int port) |
| 488 |
+{ |
| 489 |
+ struct sockaddr_in sin; |
| 490 |
+ |
| 491 |
+ bzero(&sin, sizeof(sin)); |
| 492 |
+ sin.sin_port = htons(port); |
| 493 |
+ sin.sin_family = AF_INET; |
| 494 |
+ sin.sin_addr.s_addr = INADDR_ANY; |
| 495 |
+ |
| 496 |
+ if (make_udp_sockaddr(&sin, address) < 0) { |
| 497 |
+ return(-1); |
| 498 |
+ } |
| 499 |
+ if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { |
| 500 |
+ syslog(L_ERROR, "connect_udp_socket: connect: %m"); |
| 501 |
+ return(-1); |
| 502 |
+ } |
| 503 |
+ return(0); |
| 504 |
+} |
| 505 |
+ |
| 506 |
+ |
| 507 |
+ |
| 508 |
+ |
| 509 |
+ |
| 510 |
+int write_udp(int s, char *buf, int len) |
| 511 |
+{ |
| 512 |
+ int rval; |
| 513 |
+ |
| 514 |
+ if ((rval = send(s, buf, len, 0x0)) < 0) { |
| 515 |
+ syslog(L_ERROR, "write_udp: send: %m"); |
| 516 |
+ return(-1); |
| 517 |
+ } |
| 518 |
+ return(rval); |
| 519 |
+} |
| 520 |
+ |
| 521 |
+ |
| 522 |
+ |
| 523 |
+ |
| 524 |
+ |
| 525 |
+int read_udp(int s, char *buf, int len) |
| 526 |
+{ |
| 527 |
+ int rval; |
| 528 |
+ |
| 529 |
+ if ((rval = recv(s, buf, len, 0x0)) < 0) { |
| 530 |
+ syslog(L_ERROR, "read_udp: recv: %m"); |
| 531 |
+ return(-1); |
| 532 |
+ } |
| 533 |
+ return(rval); |
| 534 |
+} |
| 535 |
--- inn-1.7.2.orig/Makefile |
| 536 |
+++ inn-1.7.2/Makefile |
| 537 |
@@ -17,7 +17,7 @@ |
| 538 |
RCSCOFLAGS = -u |
| 539 |
|
| 540 |
## The first two directories must be config and lib. |
| 541 |
-PROGS = config lib frontends innd nnrpd backends expire doc |
| 542 |
+PROGS = config lib frontends innd nnrpd actived backends expire doc |
| 543 |
DIRS = $(PROGS) site |
| 544 |
|
| 545 |
## We invoke an extra process and set this to be what to make. |
| 546 |
--- inn-1.7.2.orig/actived/Makefile |
| 547 |
+++ inn-1.7.2/actived/Makefile |
| 548 |
@@ -0,0 +1,97 @@ |
| 549 |
+## $Revision: 1.16 $ |
| 550 |
+SHELL = /bin/sh |
| 551 |
+MAKE = make |
| 552 |
+DESTDIR = |
| 553 |
+D = $(DESTDIR) |
| 554 |
+## =()<P = @<P>@>()= |
| 555 |
+P = |
| 556 |
+ |
| 557 |
+## =()<CC = @<CC>@>()= |
| 558 |
+CC = gcc |
| 559 |
+## =()<DEFS = @<DEFS>@>()= |
| 560 |
+DEFS = -I../include |
| 561 |
+## =()<CFLAGS = @<CFLAGS>@>()= |
| 562 |
+CFLAGS = $(DEFS) -g |
| 563 |
+## =()<LDFLAGS = @<LDFLAGS>@>()= |
| 564 |
+LDFLAGS = |
| 565 |
+## =()<LINTFLAGS = @<LINTFLAGS>@>()= |
| 566 |
+LINTFLAGS = -b -h -z $(DEFS) |
| 567 |
+## =()<LINTFILTER = @<LINTFILTER>@>()= |
| 568 |
+LINTFILTER = | sed -n -f ../sedf.sun |
| 569 |
+## =()<CTAGS = @<CTAGS>@>()= |
| 570 |
+CTAGS = ctags -t -w |
| 571 |
+## =()<PROF = @<PROF>@>()= |
| 572 |
+PROF = -pg |
| 573 |
+ |
| 574 |
+## =()<ACTIVED = @<_PATH_ACTIVED>@>()= |
| 575 |
+ACTIVED = /usr/lib/news/bin/actived |
| 576 |
+## =()<OWNER = -O @<NEWSUSER>@ -G @<NEWSGROUP>@>()= |
| 577 |
+OWNER = -O news -G news |
| 578 |
+ |
| 579 |
+## =()<LIBS = @<LIBS>@>()= |
| 580 |
+LIBS = -lutil |
| 581 |
+LIBNEWS = ../libinn.a |
| 582 |
+LINTLIB = ../llib-linn.ln |
| 583 |
+ |
| 584 |
+SOURCES = \ |
| 585 |
+ actived.c group.c udp.c activedstats.c |
| 586 |
+ |
| 587 |
+OBJECTS = \ |
| 588 |
+ actived.o group.o udp.o activedstats.o |
| 589 |
+ |
| 590 |
+ALL = actived |
| 591 |
+ |
| 592 |
+all: $(ALL) |
| 593 |
+ |
| 594 |
+install: $D$(ACTIVED) |
| 595 |
+ |
| 596 |
+## Low-level install actions. |
| 597 |
+$D$(ACTIVED): actived |
| 598 |
+ $(SHELL) ../installit.sh $(OWNER) -m 0555 -b .OLD $? $@ |
| 599 |
+ |
| 600 |
+clobber clean: |
| 601 |
+ rm -f *.o $(ALL) |
| 602 |
+ rm -f actived activedp profiled |
| 603 |
+ rm -f all install lint |
| 604 |
+ |
| 605 |
+tags ctags: $(SOURCES) |
| 606 |
+ $(CTAGS) $(SOURCES) ../lib/*.c actived.h ../include/*.h |
| 607 |
+ |
| 608 |
+actived: $(P) $(OBJECTS) $(LIBNEWS) |
| 609 |
+ @rm -f $@ |
| 610 |
+ $(CC) $(LDFLAGS) -o $@ $(OBJECTS) $(LIBNEWS) $(LIBS) |
| 611 |
+ |
| 612 |
+lint: $(ALL) |
| 613 |
+ @rm -f lint |
| 614 |
+ lint $(LINTFLAGS) $(SOURCES) $(LINTLIB) $(LINTFILTER) >lint |
| 615 |
+ |
| 616 |
+../include/dbz.h: |
| 617 |
+ (cd ../lib ; $(MAKE) ../include/dbz.h) |
| 618 |
+$(LIBNEWS) $(LINTLIB): |
| 619 |
+ (cd ../lib ; $(MAKE) install ) |
| 620 |
+ |
| 621 |
+## Profiling. The rules are a bit brute-force, but good enough. |
| 622 |
+profiled: activedp |
| 623 |
+ date >$@ |
| 624 |
+ |
| 625 |
+activedp: $(SOURCES) |
| 626 |
+ rm -f $(OBJECTS) |
| 627 |
+ $(MAKE) actived CFLAGS="$(CFLAGS) $(PROF)" LIBNEWS=../libinn_p.a |
| 628 |
+ mv actived activedp |
| 629 |
+ rm -f $(OBJECTS) |
| 630 |
+ |
| 631 |
+ccenter: $(SOURCES) |
| 632 |
+ #load $(CFLAGS) $(SOURCES) $(LIBNEWS) |
| 633 |
+ |
| 634 |
+## Dependencies. Default list, below, is probably good enough. |
| 635 |
+depend: Makefile $(SOURCES) |
| 636 |
+ makedepend $(DEFS) $(SOURCES) |
| 637 |
+ |
| 638 |
+# DO NOT DELETE THIS LINE -- make depend depends on it. |
| 639 |
+$(OBJECTS): actived.h \ |
| 640 |
+ ../include/clibrary.h ../include/configdata.h \ |
| 641 |
+ ../include/libinn.h ../include/logging.h \ |
| 642 |
+ ../include/macros.h ../include/nntp.h \ |
| 643 |
+ ../include/paths.h ../include/qio.h |
| 644 |
+group.o: ../include/mydir.h |
| 645 |
+misc.o: ../include/dbz.h |
| 646 |
--- inn-1.7.2.orig/actived/actived.c |
| 647 |
+++ inn-1.7.2/actived/actived.c |
| 648 |
@@ -0,0 +1,193 @@ |
| 649 |
+/* $Revision: 1.18 $ |
| 650 |
+** |
| 651 |
+** Active file server for readers (NNRP) for InterNetNews. |
| 652 |
+*/ |
| 653 |
+ |
| 654 |
+#define UPDATE_INTERVAL 30 |
| 655 |
+#define MAINLINE |
| 656 |
+#include <stdio.h> |
| 657 |
+#include <time.h> |
| 658 |
+#include "actived.h" |
| 659 |
+#include "protocol.h" |
| 660 |
+#include "configdata.h" |
| 661 |
+#include "paths.h" |
| 662 |
+ |
| 663 |
+BOOL GetGroupList(); |
| 664 |
+int create_udp_socket(int port); |
| 665 |
+int loads(int reader_count, int startup_count); |
| 666 |
+ |
| 667 |
+ |
| 668 |
+char ACTIVE[] = _PATH_ACTIVE; |
| 669 |
+char PID[] = _PATH_ACTIVEDPID; |
| 670 |
+char INNDDIR[] = _PATH_INNDDIR; |
| 671 |
+STATIC UID_T NewsUID; |
| 672 |
+STATIC GID_T NewsGID; |
| 673 |
+struct stat Sb; |
| 674 |
+ |
| 675 |
+int |
| 676 |
+handle(s) |
| 677 |
+ int s; |
| 678 |
+{ |
| 679 |
+ GROUPENTRY *ptr; |
| 680 |
+ struct sockaddr saddr; |
| 681 |
+ struct sockaddr_in *sin = (struct sockaddr_in *)&saddr; |
| 682 |
+ int saddrsiz = sizeof(saddr); |
| 683 |
+ struct wireprotocol buffer; |
| 684 |
+ int len = sizeof(buffer); |
| 685 |
+ int rval; |
| 686 |
+ |
| 687 |
+ if ((rval = recvfrom(s, (char *)&buffer, len, 0, &saddr, &saddrsiz)) < 0) { |
| 688 |
+ syslog(L_ERROR, "cant recvfrom %m"); |
| 689 |
+ return(-1); |
| 690 |
+ } |
| 691 |
+ |
| 692 |
+ if (rval != sizeof(buffer)) { |
| 693 |
+ syslog(L_ERROR, "message size wrong"); |
| 694 |
+ return(-1); |
| 695 |
+ } |
| 696 |
+ |
| 697 |
+ /* XXX If not 127.0.0.1, then reject and return */ |
| 698 |
+ |
| 699 |
+ |
| 700 |
+ switch (buffer.RequestType) { |
| 701 |
+ case REQ_AYT: |
| 702 |
+ buffer.RequestType = REQ_AYTACK; |
| 703 |
+ if (sendto(s, (char *)&buffer, len, 0, &saddr, saddrsiz) < 0) { |
| 704 |
+ syslog(L_ERROR, "cant sendto %m"); |
| 705 |
+ return(-1); |
| 706 |
+ } |
| 707 |
+ return(0); |
| 708 |
+ case REQ_FIND: |
| 709 |
+ buffer.RequestType = REQ_FINDRESP; |
| 710 |
+ |
| 711 |
+ buffer.Name[sizeof(buffer.Name) - 1] = '\0'; |
| 712 |
+ if (! (ptr = GRPfind(buffer.Name))) { |
| 713 |
+ buffer.Success = 0; |
| 714 |
+ } else { |
| 715 |
+ buffer.Success = 1; |
| 716 |
+ if (ptr->Name) { |
| 717 |
+ buffer.NameNull = 0; |
| 718 |
+ strncpy(buffer.Name, ptr->Name, sizeof(buffer.Name) - 1); |
| 719 |
+ buffer.Name[sizeof(buffer.Name) - 1] = '\0'; |
| 720 |
+ } else { |
| 721 |
+ buffer.NameNull = 1; |
| 722 |
+ } |
| 723 |
+ buffer.High = ptr->High; |
| 724 |
+ buffer.Low = ptr->Low; |
| 725 |
+ buffer.Flag = ptr->Flag; |
| 726 |
+ if (ptr->Alias) { |
| 727 |
+ buffer.AliasNull = 0; |
| 728 |
+ strncpy(buffer.Alias, ptr->Alias, sizeof(buffer.Alias) - 1); |
| 729 |
+ buffer.Alias[sizeof(buffer.Alias) - 1] = '\0'; |
| 730 |
+ } else { |
| 731 |
+ buffer.AliasNull = 1; |
| 732 |
+ } |
| 733 |
+ } |
| 734 |
+ if (sendto(s, (char *)&buffer, len, 0, &saddr, saddrsiz) < 0) { |
| 735 |
+ syslog(L_ERROR, "cant sendto %m"); |
| 736 |
+ return(-1); |
| 737 |
+ } |
| 738 |
+ return(0); |
| 739 |
+ } |
| 740 |
+ syslog(L_ERROR, "unknown requesttype %d", buffer.RequestType); |
| 741 |
+ return(-1); |
| 742 |
+} |
| 743 |
+ |
| 744 |
+ |
| 745 |
+ |
| 746 |
+ |
| 747 |
+ |
| 748 |
+/* ARGSUSED0 */ |
| 749 |
+int |
| 750 |
+main(argc, argv) |
| 751 |
+ int argc; |
| 752 |
+ char *argv[]; |
| 753 |
+{ |
| 754 |
+ int s, i; |
| 755 |
+ time_t last_active_update = time(NULL), now; |
| 756 |
+ fd_set fdset; |
| 757 |
+ struct timeval tv; |
| 758 |
+ FILE *F; |
| 759 |
+ PID_T pid; |
| 760 |
+ static char WHEN[] = "Pid file"; |
| 761 |
+ char LogName[] = "ACTIVED"; |
| 762 |
+ if (stat(INNDDIR, &Sb) < 0 || !S_ISDIR(Sb.st_mode)) { |
| 763 |
+ syslog(L_FATAL, "inndstart cant stat %s %m", INNDDIR); |
| 764 |
+ exit(1); |
| 765 |
+ } |
| 766 |
+ NewsUID = Sb.st_uid; |
| 767 |
+ NewsGID = Sb.st_gid; |
| 768 |
+ |
| 769 |
+ openlog("actived", L_OPENLOG_FLAGS | LOG_PID, LOG_INN_PROG); |
| 770 |
+ |
| 771 |
+ if ((s = create_udp_socket(1119)) < 0) { |
| 772 |
+ syslog(L_ERROR, "cant createudpsocket %m"); |
| 773 |
+ exit(1); |
| 774 |
+ } |
| 775 |
+ if (fcntl(s, F_SETFL, O_NONBLOCK) < 0) { |
| 776 |
+ syslog(L_ERROR, "cant fcntl O_NDELAY socket %m"); |
| 777 |
+ exit(1); |
| 778 |
+ } |
| 779 |
+ if (!GetGroupList()) { |
| 780 |
+ /* This shouldn't really happen. */ |
| 781 |
+ syslog(L_ERROR, "cant getgrouplist %m"); |
| 782 |
+ exit(1); |
| 783 |
+ } |
| 784 |
+ i = fork(); |
| 785 |
+ if (i < 0) |
| 786 |
+ syslog(L_ERROR, "daemon: cannot fork"); |
| 787 |
+ if (i != 0) |
| 788 |
+ exit(0); |
| 789 |
+ |
| 790 |
+ /* Change our UID and GID */ |
| 791 |
+ if (setgid(NewsGID) == -1) |
| 792 |
+ syslog(L_ERROR, "actived cant setgid: %m"); |
| 793 |
+ if (setuid(NewsUID) == -1) |
| 794 |
+ syslog(L_ERROR, "actived cant setuid: %m"); |
| 795 |
+ |
| 796 |
+ /* Record our PID. */ |
| 797 |
+ pid = getpid(); |
| 798 |
+ if ((F = fopen(PID, "w")) == NULL) { |
| 799 |
+ i = errno; |
| 800 |
+ syslog(L_ERROR, "%s cant fopen %s %m", LogName, PID); |
| 801 |
+ } |
| 802 |
+ else { |
| 803 |
+ if (fprintf(F, "%ld\n", (long)pid) == EOF || ferror(F)) { |
| 804 |
+ i = errno; |
| 805 |
+ syslog(L_ERROR, "%s cant fprintf %s %m", LogName, PID); |
| 806 |
+ } |
| 807 |
+ if (fclose(F) == EOF) { |
| 808 |
+ i = errno; |
| 809 |
+ syslog(L_ERROR, "%s cant fclose %s %m", LogName, PID); |
| 810 |
+ } |
| 811 |
+ if (chmod(PID, 0664) < 0) { |
| 812 |
+ i = errno; |
| 813 |
+ syslog(L_ERROR, "%s cant chmod %s %m", LogName, PID); |
| 814 |
+ } |
| 815 |
+ } |
| 816 |
+ |
| 817 |
+ for (;;) { |
| 818 |
+ FD_ZERO(&fdset); |
| 819 |
+ FD_SET(s, &fdset); |
| 820 |
+ tv.tv_sec = 0; |
| 821 |
+ tv.tv_usec = 300000; |
| 822 |
+ if (select(s + 1, &fdset, NULL, NULL, &tv) < 0) { |
| 823 |
+ syslog(L_ERROR, "cant select %m"); |
| 824 |
+ exit(1); |
| 825 |
+ } |
| 826 |
+ now = time(NULL); |
| 827 |
+ if (now > last_active_update + UPDATE_INTERVAL) { |
| 828 |
+ last_active_update = now; |
| 829 |
+ if (!GetGroupList()) { |
| 830 |
+ /* This shouldn't really happen. */ |
| 831 |
+ syslog(L_ERROR, "cant getgrouplist %m"); |
| 832 |
+ exit(1); |
| 833 |
+ } |
| 834 |
+ } |
| 835 |
+ if (FD_ISSET(s, &fdset)) { |
| 836 |
+ handle(s); |
| 837 |
+ loads(0, 1); |
| 838 |
+ } |
| 839 |
+ } |
| 840 |
+ /* NOTREACHED */ |
| 841 |
+} |
| 842 |
--- inn-1.7.2.orig/actived/actived.h |
| 843 |
+++ inn-1.7.2/actived/actived.h |
| 844 |
@@ -0,0 +1,51 @@ |
| 845 |
+/* $Revision: 1.15 $ |
| 846 |
+** |
| 847 |
+*/ |
| 848 |
+#include "configdata.h" |
| 849 |
+#include <stdio.h> |
| 850 |
+#include <sys/types.h> |
| 851 |
+#include <sys/stat.h> |
| 852 |
+#include <errno.h> |
| 853 |
+#include <ctype.h> |
| 854 |
+#include <sys/file.h> |
| 855 |
+#if defined(VAR_VARARGS) |
| 856 |
+#include <varargs.h> |
| 857 |
+#endif /* defined(VAR_VARARGS) */ |
| 858 |
+#if defined(VAR_STDARGS) |
| 859 |
+#include <stdarg.h> |
| 860 |
+#endif /* defined(VAR_STDARGS) */ |
| 861 |
+#include <syslog.h> |
| 862 |
+#include <fcntl.h> |
| 863 |
+#include <sys/socket.h> |
| 864 |
+#include <netinet/in.h> |
| 865 |
+#include <sys/time.h> |
| 866 |
+#include <unistd.h> |
| 867 |
+#include "paths.h" |
| 868 |
+#include "nntp.h" |
| 869 |
+#include "logging.h" |
| 870 |
+#include "clibrary.h" |
| 871 |
+#include "libinn.h" |
| 872 |
+#include "qio.h" |
| 873 |
+#include "macros.h" |
| 874 |
+ |
| 875 |
+ |
| 876 |
+/* |
| 877 |
+** A group entry. |
| 878 |
+*/ |
| 879 |
+typedef struct _GROUPENTRY { |
| 880 |
+ char *Name; |
| 881 |
+ ARTNUM High; |
| 882 |
+ ARTNUM Low; |
| 883 |
+ char Flag; |
| 884 |
+ char *Alias; |
| 885 |
+} GROUPENTRY; |
| 886 |
+ |
| 887 |
+ |
| 888 |
+#if defined(MAINLINE) |
| 889 |
+#define EXTERN /* NULL */ |
| 890 |
+#else |
| 891 |
+#define EXTERN extern |
| 892 |
+#endif /* defined(MAINLINE) */ |
| 893 |
+ |
| 894 |
+extern char ACTIVE[]; |
| 895 |
+extern GROUPENTRY *GRPfind(); |
| 896 |
--- inn-1.7.2.orig/actived/activedstats.c |
| 897 |
+++ inn-1.7.2/actived/activedstats.c |
| 898 |
@@ -0,0 +1,150 @@ |
| 899 |
+/* |
| 900 |
+ * Copyright (c) 1996 |
| 901 |
+ * Joe Greco. All rights reserved. |
| 902 |
+ * |
| 903 |
+ * Redistribution and use in source and binary forms, with or without |
| 904 |
+ * modification, are permitted provided that the following conditions |
| 905 |
+ * are met: |
| 906 |
+ * 1. Redistributions of source code must retain the above copyright |
| 907 |
+ * notice, this list of conditions and the following disclaimer. |
| 908 |
+ * 2. Redistributions in binary form must reproduce the above copyright |
| 909 |
+ * notice, this list of conditions and the following disclaimer in the |
| 910 |
+ * documentation and/or other materials provided with the distribution. |
| 911 |
+ * 3. All advertising materials mentioning features or use of this software |
| 912 |
+ * must display the following acknowledgement: |
| 913 |
+ * This product includes software developed by Joe Greco. |
| 914 |
+ * 4. Neither the name of the author nor the names of any co-contributors |
| 915 |
+ * may be used to endorse or promote products derived from this software |
| 916 |
+ * without specific prior written permission. |
| 917 |
+ * |
| 918 |
+ * THIS SOFTWARE IS PROVIDED BY JOE GRECO AND CONTRIBUTORS ``AS IS'' AND |
| 919 |
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 920 |
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 921 |
+ * ARE DISCLAIMED. IN NO EVENT SHALL JOE GRECO OR CONTRIBUTORS BE LIABLE |
| 922 |
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 923 |
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 924 |
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 925 |
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 926 |
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 927 |
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 928 |
+ * SUCH DAMAGE. |
| 929 |
+ * |
| 930 |
+ */ |
| 931 |
+ |
| 932 |
+ |
| 933 |
+#include <stdio.h> |
| 934 |
+#include <sys/types.h> |
| 935 |
+#include <sys/time.h> |
| 936 |
+ |
| 937 |
+int dumploads(); |
| 938 |
+int fprintloads(FILE *fp); |
| 939 |
+ |
| 940 |
+ |
| 941 |
+/* This breaks past 1024; see comments in sys/param.h - soln: make 64 bits */ |
| 942 |
+ |
| 943 |
+#define FSHIFT 11 /* bits to right of fixed binary point */ |
| 944 |
+#define FSCALE (1<<FSHIFT) |
| 945 |
+ |
| 946 |
+/* Load average structure. */ |
| 947 |
+struct loadavg { |
| 948 |
+ u_long ldavg[3]; |
| 949 |
+ long fscale; |
| 950 |
+}; |
| 951 |
+ |
| 952 |
+struct loadavg avgreaders = { {0, 0, 0}, FSCALE}; |
| 953 |
+struct loadavg avgstartups = { {0, 0, 0}, FSCALE}; |
| 954 |
+ |
| 955 |
+/* |
| 956 |
+ * Constants for averages over 1, 5, and 15 minutes |
| 957 |
+ * when sampling at 5 second intervals. |
| 958 |
+ */ |
| 959 |
+static u_long cexp[3] = { |
| 960 |
+ 0.9200444146293232 * FSCALE, /* exp(-1/12) */ |
| 961 |
+ 0.9834714538216174 * FSCALE, /* exp(-1/60) */ |
| 962 |
+ 0.9944598480048967 * FSCALE, /* exp(-1/180) */ |
| 963 |
+}; |
| 964 |
+ |
| 965 |
+ |
| 966 |
+/* |
| 967 |
+ * Compute a tenex style load average of a quantity on |
| 968 |
+ * 1, 5 and 15 minute intervals. |
| 969 |
+ */ |
| 970 |
+static void |
| 971 |
+loadav(struct loadavg *avg, int nrun) |
| 972 |
+{ |
| 973 |
+ register int i; |
| 974 |
+ register struct proc *p; |
| 975 |
+ |
| 976 |
+ for (i = 0; i < 3; i++) |
| 977 |
+ avg->ldavg[i] = (cexp[i] * avg->ldavg[i] + |
| 978 |
+ nrun * FSCALE * (FSCALE - cexp[i])) >> FSHIFT; |
| 979 |
+} |
| 980 |
+ |
| 981 |
+/* |
| 982 |
+ * Call this every half a second or so - every five seconds, it will |
| 983 |
+ * calculate loads. |
| 984 |
+ * |
| 985 |
+ * Originally designed for readers. We don't care for actived and |
| 986 |
+ * instead we call with loads(0, 1) for requests, and loads (0, 0) |
| 987 |
+ * for periodic calls. |
| 988 |
+ * |
| 989 |
+ * Formerly: |
| 990 |
+ * When a reader connects: loads(+1, 1) |
| 991 |
+ * disconn's: loads(-1, 0) |
| 992 |
+ */ |
| 993 |
+ |
| 994 |
+int |
| 995 |
+loads(int reader_count, int startup_count) |
| 996 |
+{ |
| 997 |
+ static int readers = 0; |
| 998 |
+ static int startups = 0; |
| 999 |
+ struct timeval tv; |
| 1000 |
+ static int tv_next = 0; |
| 1001 |
+ |
| 1002 |
+ readers += reader_count; |
| 1003 |
+ startups += startup_count; |
| 1004 |
+ |
| 1005 |
+ gettimeofday(&tv, NULL); |
| 1006 |
+ |
| 1007 |
+ if (! tv_next) { |
| 1008 |
+ tv_next = tv.tv_sec + 5; |
| 1009 |
+ } |
| 1010 |
+ if (tv.tv_sec >= tv_next) { |
| 1011 |
+ tv_next += 5; |
| 1012 |
+ loadav(&avgreaders, readers); |
| 1013 |
+ loadav(&avgstartups, startups); |
| 1014 |
+ startups = 0; |
| 1015 |
+ dumploads(); |
| 1016 |
+ } |
| 1017 |
+ return(0); |
| 1018 |
+} |
| 1019 |
+ |
| 1020 |
+int dumploads() |
| 1021 |
+{ |
| 1022 |
+ FILE *fp; |
| 1023 |
+ |
| 1024 |
+ if (! (fp = fopen("/var/log/news/activedloads", "w"))) { |
| 1025 |
+ return(-1); |
| 1026 |
+ } |
| 1027 |
+ fprintloads(fp); |
| 1028 |
+ fclose(fp); |
| 1029 |
+ return(0); |
| 1030 |
+} |
| 1031 |
+ |
| 1032 |
+int |
| 1033 |
+fprintloads(FILE *fp) |
| 1034 |
+{ |
| 1035 |
+ double avenrun[3]; |
| 1036 |
+ int i; |
| 1037 |
+ |
| 1038 |
+ for (i = 0; i < 3; i++) { |
| 1039 |
+ avenrun[i] = (double) avgstartups.ldavg[i] / avgstartups.fscale; |
| 1040 |
+ } |
| 1041 |
+ fprintf(fp, "Average ACTIVED Loads: "); |
| 1042 |
+ for (i = 0; i < (sizeof(avenrun) / sizeof(avenrun[0])); i++) { |
| 1043 |
+ if (i > 0) |
| 1044 |
+ fprintf(fp, ","); |
| 1045 |
+ fprintf(fp, " %6.2f", avenrun[i]); |
| 1046 |
+ } |
| 1047 |
+ fprintf(fp, "\n"); |
| 1048 |
+} |
| 1049 |
--- inn-1.7.2.orig/actived/group.c |
| 1050 |
+++ inn-1.7.2/actived/group.c |
| 1051 |
@@ -0,0 +1,166 @@ |
| 1052 |
+/* $Revision: 1.13 $ |
| 1053 |
+** |
| 1054 |
+** Newsgroups and the active file. |
| 1055 |
+*/ |
| 1056 |
+#include "actived.h" |
| 1057 |
+ |
| 1058 |
+ |
| 1059 |
+/* |
| 1060 |
+** Newsgroup hashing stuff. See comments in innd/ng.c. |
| 1061 |
+*/ |
| 1062 |
+ |
| 1063 |
+#define GRP_HASH(Name, p, j) \ |
| 1064 |
+ for (p = Name, j = 0; *p; ) j = (j << 5) + j + *p++ |
| 1065 |
+#define GRP_SIZE 65536 |
| 1066 |
+#define GRP_BUCKET(j) &GRPtable[j & (GRP_SIZE - 1)] |
| 1067 |
+ |
| 1068 |
+typedef struct _GRPHASH { |
| 1069 |
+ int Size; |
| 1070 |
+ int Used; |
| 1071 |
+ GROUPENTRY **Groups; |
| 1072 |
+} GRPHASH; |
| 1073 |
+ |
| 1074 |
+ |
| 1075 |
+STATIC GRPHASH GRPtable[GRP_SIZE]; |
| 1076 |
+STATIC GROUPENTRY *GRPentries; |
| 1077 |
+STATIC int GRPbuckets; |
| 1078 |
+STATIC int GRPsize; |
| 1079 |
+ |
| 1080 |
+ |
| 1081 |
+/* |
| 1082 |
+** See if a given newsgroup exists. |
| 1083 |
+*/ |
| 1084 |
+GROUPENTRY * |
| 1085 |
+GRPfind(group) |
| 1086 |
+ register char *group; |
| 1087 |
+{ |
| 1088 |
+ register char *p; |
| 1089 |
+ register unsigned int j; |
| 1090 |
+ register int i; |
| 1091 |
+ register GROUPENTRY **gpp; |
| 1092 |
+ GRPHASH *htp; |
| 1093 |
+ char c; |
| 1094 |
+ |
| 1095 |
+ /* SUPPRESS 6 *//* Over/underflow from plus expression */ |
| 1096 |
+ GRP_HASH(group, p, j); |
| 1097 |
+ htp = GRP_BUCKET(j); |
| 1098 |
+ for (c = *group, gpp = htp->Groups, i = htp->Used; --i >= 0; gpp++) |
| 1099 |
+ if (c == gpp[0]->Name[0] && EQ(group, gpp[0]->Name)) |
| 1100 |
+ return gpp[0]; |
| 1101 |
+ return NULL; |
| 1102 |
+} |
| 1103 |
+ |
| 1104 |
+ |
| 1105 |
+STATIC void |
| 1106 |
+GRPhash() |
| 1107 |
+{ |
| 1108 |
+ register char *p; |
| 1109 |
+ register int i; |
| 1110 |
+ register GROUPENTRY *gp; |
| 1111 |
+ register unsigned int j; |
| 1112 |
+ register GRPHASH *htp; |
| 1113 |
+ |
| 1114 |
+ /* Set up the default hash buckets. */ |
| 1115 |
+ GRPbuckets = GRPsize / GRP_SIZE; |
| 1116 |
+ if (GRPbuckets == 0) |
| 1117 |
+ GRPbuckets = 1; |
| 1118 |
+ if (GRPtable[0].Groups) |
| 1119 |
+ for (i = GRP_SIZE, htp = GRPtable; --i >= 0; htp++) |
| 1120 |
+ htp->Used = 0; |
| 1121 |
+ else |
| 1122 |
+ for (i = GRP_SIZE, htp = GRPtable; --i >= 0; htp++) { |
| 1123 |
+ htp->Size = GRPbuckets; |
| 1124 |
+ htp->Groups = NEW(GROUPENTRY*, htp->Size); |
| 1125 |
+ htp->Used = 0; |
| 1126 |
+ } |
| 1127 |
+ |
| 1128 |
+ /* Now put all groups into the hash table. */ |
| 1129 |
+ for (i = GRPsize, gp = GRPentries; --i >= 0; gp++) { |
| 1130 |
+ /* SUPPRESS 6 *//* Over/underflow from plus expression */ |
| 1131 |
+ GRP_HASH(gp->Name, p, j); |
| 1132 |
+ htp = GRP_BUCKET(j); |
| 1133 |
+ if (htp->Used >= htp->Size) { |
| 1134 |
+ htp->Size += GRPbuckets; |
| 1135 |
+ RENEW(htp->Groups, GROUPENTRY*, htp->Size); |
| 1136 |
+ } |
| 1137 |
+ htp->Groups[htp->Used++] = gp; |
| 1138 |
+ } |
| 1139 |
+ |
| 1140 |
+ /* Note that we don't sort the buckets. */ |
| 1141 |
+} |
| 1142 |
+ |
| 1143 |
+ |
| 1144 |
+/* |
| 1145 |
+** Read the active file into memory, sort it, and set the number of |
| 1146 |
+** newsgroups read in. Return TRUE if okay, FALSE on error. |
| 1147 |
+*/ |
| 1148 |
+BOOL |
| 1149 |
+GetGroupList() |
| 1150 |
+{ |
| 1151 |
+ static char *active; |
| 1152 |
+ register char *p; |
| 1153 |
+ register char *q; |
| 1154 |
+ register GROUPENTRY *gp; |
| 1155 |
+ register int i; |
| 1156 |
+ |
| 1157 |
+ /* If re-scanning, free previous groups. */ |
| 1158 |
+ if (active != NULL) { |
| 1159 |
+ DISPOSE(active); |
| 1160 |
+ DISPOSE(GRPentries); |
| 1161 |
+ } |
| 1162 |
+ |
| 1163 |
+ /* Get the new file. */ |
| 1164 |
+ active = ReadInFile(ACTIVE, (struct stat *)NULL); |
| 1165 |
+ if (active == NULL) { |
| 1166 |
+ syslog(L_ERROR, "cant read %s %m", ACTIVE); |
| 1167 |
+ return FALSE; |
| 1168 |
+ } |
| 1169 |
+ |
| 1170 |
+ /* Count lines. */ |
| 1171 |
+ for (p = active, i = 0; (p = strchr(p, '\n')) != NULL; p++, i++) |
| 1172 |
+ continue; |
| 1173 |
+ |
| 1174 |
+ /* Fill in the group array. */ |
| 1175 |
+ GRPentries = NEW(GROUPENTRY, i); |
| 1176 |
+ for (i = 0, gp = GRPentries, p = active; *p; i++, gp++, p = q + 1) { |
| 1177 |
+ gp->Name = p; |
| 1178 |
+ if ((p = strchr(p, ' ')) == NULL) { |
| 1179 |
+ syslog(L_ERROR, "internal no_space1 \"%.20s...\"", |
| 1180 |
+ gp->Name); |
| 1181 |
+ return FALSE; |
| 1182 |
+ } |
| 1183 |
+ *p++ = '\0'; |
| 1184 |
+ |
| 1185 |
+ /* Get the high mark. */ |
| 1186 |
+ if ((q = strchr(p, ' ')) == NULL) { |
| 1187 |
+ syslog(L_ERROR, "internal no_space2 \"%.20s...\"", |
| 1188 |
+ gp->Name); |
| 1189 |
+ return FALSE; |
| 1190 |
+ } |
| 1191 |
+ *q++ = '\0'; |
| 1192 |
+ gp->High = atol(p); |
| 1193 |
+ |
| 1194 |
+ /* Get the low mark. */ |
| 1195 |
+ if ((p = strchr(q, ' ')) == NULL) { |
| 1196 |
+ syslog(L_ERROR, "internal no_space3 \"%.20s...\"", |
| 1197 |
+ gp->Name); |
| 1198 |
+ return FALSE; |
| 1199 |
+ } |
| 1200 |
+ *p++ = '\0'; |
| 1201 |
+ gp->Low = atol(q); |
| 1202 |
+ |
| 1203 |
+ /* Kill the newline. */ |
| 1204 |
+ if ((q = strchr(p, '\n')) == NULL) { |
| 1205 |
+ syslog(L_ERROR, "internal newline \"%.20s...\"", |
| 1206 |
+ gp->Name); |
| 1207 |
+ return FALSE; |
| 1208 |
+ } |
| 1209 |
+ *q = '\0'; |
| 1210 |
+ gp->Flag = *p; |
| 1211 |
+ gp->Alias = gp->Flag == NF_FLAG_ALIAS ? p + 1 : NULL; |
| 1212 |
+ } |
| 1213 |
+ |
| 1214 |
+ GRPsize = i; |
| 1215 |
+ GRPhash(); |
| 1216 |
+ return TRUE; |
| 1217 |
+} |
| 1218 |
--- inn-1.7.2.orig/actived/protocol.h |
| 1219 |
+++ inn-1.7.2/actived/protocol.h |
| 1220 |
@@ -0,0 +1,19 @@ |
| 1221 |
+#define ACTIVED_TIMEOUT 10 |
| 1222 |
+ |
| 1223 |
+#define REQ_AYT 1 |
| 1224 |
+#define REQ_AYTACK 2 |
| 1225 |
+#define REQ_FIND 3 |
| 1226 |
+#define REQ_FINDRESP 4 |
| 1227 |
+ |
| 1228 |
+struct wireprotocol { |
| 1229 |
+ int RequestType; |
| 1230 |
+ int RequestID; |
| 1231 |
+ int Success; |
| 1232 |
+ int NameNull; |
| 1233 |
+ char Name[1024]; |
| 1234 |
+ ARTNUM High; |
| 1235 |
+ ARTNUM Low; |
| 1236 |
+ char Flag; |
| 1237 |
+ int AliasNull; |
| 1238 |
+ char Alias[1024]; |
| 1239 |
+}; |
| 1240 |
--- inn-1.7.2.orig/actived/query.c |
| 1241 |
+++ inn-1.7.2/actived/query.c |
| 1242 |
@@ -0,0 +1,48 @@ |
| 1243 |
+#include <stdio.h> |
| 1244 |
+#include "actived.h" |
| 1245 |
+#include "protocol.h" |
| 1246 |
+ |
| 1247 |
+ |
| 1248 |
+int main(argc, argv) |
| 1249 |
+int argc; |
| 1250 |
+char *argv[]; |
| 1251 |
+{ |
| 1252 |
+ int s, i; |
| 1253 |
+ int start = time(NULL) - 1; |
| 1254 |
+ struct wireprotocol buffer; |
| 1255 |
+ |
| 1256 |
+ if ((s = create_udp_socket(0)) < 0) { |
| 1257 |
+ fprintf(stderr, "couldnt create socket\n"); |
| 1258 |
+ exit(1); |
| 1259 |
+ } |
| 1260 |
+ if (connect_udp_socket(s, "localhost", 1119) < 0) { |
| 1261 |
+ fprintf(stderr, "couldnt connect socket\n"); |
| 1262 |
+ exit(1); |
| 1263 |
+ } |
| 1264 |
+ i = 0; |
| 1265 |
+ buffer.RequestType = REQ_FIND; |
| 1266 |
+ buffer.RequestID = getpid(); |
| 1267 |
+ sprintf(buffer.Name, argv[1]); |
| 1268 |
+ |
| 1269 |
+ fprintf(stderr, "asking question: request-id %d, group \"%s\"\n\n", buffer.RequestID, buffer.Name); |
| 1270 |
+ |
| 1271 |
+ if (write_udp(s, (char *)&buffer, sizeof(buffer)) < 0) { |
| 1272 |
+ fprintf(stderr, "couldnt write packet\n"); |
| 1273 |
+ exit(1); |
| 1274 |
+ } |
| 1275 |
+ if (read_udp(s, (char *)&buffer, sizeof(buffer)) != sizeof(buffer)) { |
| 1276 |
+ fprintf(stderr, "couldnt read packet\n"); |
| 1277 |
+ exit(1); |
| 1278 |
+ } |
| 1279 |
+ fprintf(stderr, "request-id ok? %s (%d)\n", buffer.RequestID == getpid() ? "yes" : "no", buffer.RequestID); |
| 1280 |
+ fprintf(stderr, "response type correct? %s (%d)\n", buffer.RequestType == REQ_FINDRESP ? "yes" : "no", buffer.RequestType); |
| 1281 |
+ fprintf(stderr, "success? %s\n", buffer.Success ? "yes" : "no"); |
| 1282 |
+ fprintf(stderr, "name? %s\n", buffer.NameNull ? "<NULL>" : buffer.Name); |
| 1283 |
+ fprintf(stderr, "alias? %s\n", buffer.AliasNull ? "<NULL>" : buffer.Alias); |
| 1284 |
+ fprintf(stderr, "range? %d-%d\n", buffer.Low, buffer.High); |
| 1285 |
+ fprintf(stderr, "flag? %c\n", buffer.Flag); |
| 1286 |
+} |
| 1287 |
+ |
| 1288 |
+ |
| 1289 |
+ |
| 1290 |
+ |
| 1291 |
--- inn-1.7.2.orig/actived/test.c |
| 1292 |
+++ inn-1.7.2/actived/test.c |
| 1293 |
@@ -0,0 +1,43 @@ |
| 1294 |
+#include <stdio.h> |
| 1295 |
+#include "actived.h" |
| 1296 |
+#include "protocol.h" |
| 1297 |
+ |
| 1298 |
+ |
| 1299 |
+int main(argc, argv) |
| 1300 |
+int argc; |
| 1301 |
+char *argv[]; |
| 1302 |
+{ |
| 1303 |
+ int s, i; |
| 1304 |
+ int start = time(NULL) - 1; |
| 1305 |
+ struct wireprotocol buffer; |
| 1306 |
+ |
| 1307 |
+ if ((s = create_udp_socket(0)) < 0) { |
| 1308 |
+ fprintf(stderr, "couldnt create socket\n"); |
| 1309 |
+ exit(1); |
| 1310 |
+ } |
| 1311 |
+ if (connect_udp_socket(s, "localhost", 1119) < 0) { |
| 1312 |
+ fprintf(stderr, "couldnt connect socket\n"); |
| 1313 |
+ exit(1); |
| 1314 |
+ } |
| 1315 |
+ i = 0; |
| 1316 |
+ fprintf(stderr, "%08d", 0); |
| 1317 |
+ for (;;) { |
| 1318 |
+ buffer.RequestType = REQ_FIND; |
| 1319 |
+ sprintf(buffer.Name, "alt.sex"); |
| 1320 |
+ if (write_udp(s, (char *)&buffer, sizeof(buffer)) < 0) { |
| 1321 |
+ fprintf(stderr, "couldnt write packet\n"); |
| 1322 |
+ exit(1); |
| 1323 |
+ } |
| 1324 |
+ if (read_udp(s, (char *)&buffer, sizeof(buffer)) != sizeof(buffer)) { |
| 1325 |
+ fprintf(stderr, "couldnt read packet\n"); |
| 1326 |
+ exit(1); |
| 1327 |
+ } |
| 1328 |
+ if (! (++i % 100)) { |
| 1329 |
+ fprintf(stderr, "\r%08d %5.2f", i, (float)i / (time(NULL) - start)); |
| 1330 |
+ } |
| 1331 |
+ } |
| 1332 |
+} |
| 1333 |
+ |
| 1334 |
+ |
| 1335 |
+ |
| 1336 |
+ |
| 1337 |
--- inn-1.7.2.orig/actived/udp.c |
| 1338 |
+++ inn-1.7.2/actived/udp.c |
| 1339 |
@@ -0,0 +1,162 @@ |
| 1340 |
+#include <stdio.h> |
| 1341 |
+#include <sys/types.h> |
| 1342 |
+#include "clibrary.h" |
| 1343 |
+#include <errno.h> |
| 1344 |
+#include <sys/socket.h> |
| 1345 |
+#include <netinet/in.h> |
| 1346 |
+#include <arpa/inet.h> |
| 1347 |
+#include <ctype.h> |
| 1348 |
+#include <netdb.h> |
| 1349 |
+#include "logging.h" |
| 1350 |
+ |
| 1351 |
+#ifdef NEED_BZERO_ETC |
| 1352 |
+#include <fcntl.h> |
| 1353 |
+void |
| 1354 |
+bzero(b, length) |
| 1355 |
+ char *b; |
| 1356 |
+ int length; |
| 1357 |
+{ |
| 1358 |
+ while (--length >= 0) |
| 1359 |
+ *b++ = '\0'; |
| 1360 |
+} |
| 1361 |
+void |
| 1362 |
+bcopy(b1, b2, length) |
| 1363 |
+ char *b1; |
| 1364 |
+ char *b2; |
| 1365 |
+ int length; |
| 1366 |
+{ |
| 1367 |
+ while (--length >= 0) |
| 1368 |
+ *b2++ = *b1++; |
| 1369 |
+} |
| 1370 |
+#endif |
| 1371 |
+ |
| 1372 |
+int create_udp_socket(int port) |
| 1373 |
+{ |
| 1374 |
+ int s; |
| 1375 |
+ struct sockaddr_in sin; |
| 1376 |
+ |
| 1377 |
+ sin.sin_port = htons(port); |
| 1378 |
+ sin.sin_family = AF_INET; |
| 1379 |
+ sin.sin_addr.s_addr = INADDR_ANY; |
| 1380 |
+ |
| 1381 |
+ if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { |
| 1382 |
+ syslog(L_ERROR, "create_udp_socket: socket: %m"); |
| 1383 |
+ return(-1); |
| 1384 |
+ } |
| 1385 |
+ if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { |
| 1386 |
+ syslog(L_ERROR, "create_udp_socket: bind: %m"); |
| 1387 |
+ return(-1); |
| 1388 |
+ } |
| 1389 |
+ return(s); |
| 1390 |
+} |
| 1391 |
+ |
| 1392 |
+ |
| 1393 |
+ |
| 1394 |
+ |
| 1395 |
+ |
| 1396 |
+int make_udp_sockaddr(struct sockaddr_in *addr, char *ascii) |
| 1397 |
+{ |
| 1398 |
+ struct hostent *host; |
| 1399 |
+ int dots = 0; |
| 1400 |
+ int numeric = 0; |
| 1401 |
+ char *str, *colon, *lastdot, *ptr; |
| 1402 |
+ |
| 1403 |
+ if (! (str = malloc(strlen(ascii) + 1))) { |
| 1404 |
+ syslog(L_ERROR, "make_udp_sockaddr: malloc: %m"); |
| 1405 |
+ return(-1); |
| 1406 |
+ } |
| 1407 |
+ strcpy(str, ascii); |
| 1408 |
+ colon = strrchr(str, ':'); |
| 1409 |
+ lastdot = strrchr(str, '.'); |
| 1410 |
+ |
| 1411 |
+ addr->sin_family = AF_INET; |
| 1412 |
+ |
| 1413 |
+ /* Count the number of dots in the address. */ |
| 1414 |
+ for (ptr = str; *ptr; ptr++) { |
| 1415 |
+ if (*ptr == '.') { |
| 1416 |
+ dots++; |
| 1417 |
+ } |
| 1418 |
+ } |
| 1419 |
+ |
| 1420 |
+ /* Check if it seems to be numeric. */ |
| 1421 |
+ numeric = isdigit(*str); |
| 1422 |
+ |
| 1423 |
+ /* If numeric and four dots, we have a.b.c.d.6000 */ |
| 1424 |
+ if (numeric && dots == 4) { |
| 1425 |
+ *lastdot = '\0'; |
| 1426 |
+ addr->sin_port = htons(atoi(lastdot + 1)); |
| 1427 |
+ } |
| 1428 |
+ /* If nonnumeric, check if the last part is a port */ |
| 1429 |
+ if (! numeric && lastdot && isdigit(*(lastdot + 1))) { |
| 1430 |
+ *lastdot = '\0'; |
| 1431 |
+ addr->sin_port = htons(atoi(lastdot + 1)); |
| 1432 |
+ } |
| 1433 |
+ /* Now do we have a numeric address */ |
| 1434 |
+ if (numeric) { |
| 1435 |
+ addr->sin_addr.s_addr = inet_addr(str); |
| 1436 |
+ free(str); |
| 1437 |
+ return(0); |
| 1438 |
+ } |
| 1439 |
+ /* Or a name */ |
| 1440 |
+ if (! (host = gethostbyname(str))) { |
| 1441 |
+ free(str); |
| 1442 |
+ syslog(L_ERROR, "make_udp_sockaddr: gethostbyname: %m"); |
| 1443 |
+ return(-1); |
| 1444 |
+ } |
| 1445 |
+ bcopy(host->h_addr_list[0], (char *)&addr->sin_addr.s_addr, sizeof(addr->sin_addr.s_addr)); |
| 1446 |
+ free(str); |
| 1447 |
+ return(0); |
| 1448 |
+} |
| 1449 |
+ |
| 1450 |
+ |
| 1451 |
+ |
| 1452 |
+ |
| 1453 |
+ |
| 1454 |
+int connect_udp_socket(int s, char *address, int port) |
| 1455 |
+{ |
| 1456 |
+ struct sockaddr_in sin; |
| 1457 |
+ |
| 1458 |
+ bzero(&sin, sizeof(sin)); |
| 1459 |
+ sin.sin_port = htons(port); |
| 1460 |
+ sin.sin_family = AF_INET; |
| 1461 |
+ sin.sin_addr.s_addr = INADDR_ANY; |
| 1462 |
+ |
| 1463 |
+ if (make_udp_sockaddr(&sin, address) < 0) { |
| 1464 |
+ return(-1); |
| 1465 |
+ } |
| 1466 |
+ if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { |
| 1467 |
+ syslog(L_ERROR, "connect_udp_socket: connect: %m"); |
| 1468 |
+ return(-1); |
| 1469 |
+ } |
| 1470 |
+ return(0); |
| 1471 |
+} |
| 1472 |
+ |
| 1473 |
+ |
| 1474 |
+ |
| 1475 |
+ |
| 1476 |
+ |
| 1477 |
+int write_udp(int s, char *buf, int len) |
| 1478 |
+{ |
| 1479 |
+ int rval; |
| 1480 |
+ |
| 1481 |
+ if ((rval = send(s, buf, len, 0x0)) < 0) { |
| 1482 |
+ syslog(L_ERROR, "write_udp: send: %m"); |
| 1483 |
+ return(-1); |
| 1484 |
+ } |
| 1485 |
+ return(rval); |
| 1486 |
+} |
| 1487 |
+ |
| 1488 |
+ |
| 1489 |
+ |
| 1490 |
+ |
| 1491 |
+ |
| 1492 |
+int read_udp(int s, char *buf, int len) |
| 1493 |
+{ |
| 1494 |
+ int rval; |
| 1495 |
+ |
| 1496 |
+ if ((rval = recv(s, buf, len, 0x0)) < 0) { |
| 1497 |
+ syslog(L_ERROR, "read_udp: recv: %m"); |
| 1498 |
+ return(-1); |
| 1499 |
+ } |
| 1500 |
+ return(rval); |
| 1501 |
+} |
| 1502 |
--- inn-1.7.2.orig/actived/README.actived |
| 1503 |
+++ inn-1.7.2/actived/README.actived |
| 1504 |
@@ -0,0 +1,46 @@ |
| 1505 |
+This is nnrpd-actived. |
| 1506 |
+ |
| 1507 |
+I found that one of the huge bottlenecks in an nnrp-oriented INN system |
| 1508 |
+is creating new sessions. I spent some time and tracked down one of the |
| 1509 |
+big time-consumers... hashing the active file. Even with sharedactive, |
| 1510 |
+each client would hash the contents into a local hash table, and with a |
| 1511 |
+very large active file, this took an appreciable amount of time. |
| 1512 |
+ |
| 1513 |
+My CPU's could do it a few times a second, but during peak periods, I |
| 1514 |
+see 5+ new connections per second, which essentially floods the CPU. |
| 1515 |
+ |
| 1516 |
+One fix would have been to have the nnrpd that updated the shared memory |
| 1517 |
+space also update a shared hash table. I didn't like that since I still |
| 1518 |
+think the sharedactive thing is uccchy. It used to occasionally snag |
| 1519 |
+a semaphore and hang a few hundred nnrpd's in limbo. Sharing the active |
| 1520 |
+file via mmap had drawbacks as well. |
| 1521 |
+ |
| 1522 |
+I finally decided to go a different route. I created an "active file |
| 1523 |
+server". This server reads and rehashes the active file once every 30 |
| 1524 |
+seconds, and will answer UDP requests about the contents of the file. |
| 1525 |
+ |
| 1526 |
+This is able to handle thousands of transactions per second, even though |
| 1527 |
+I rarely even see hundreds in production use. I can start up a hundred |
| 1528 |
+nnrp sessions a second without response time suffering noticeably. |
| 1529 |
+ |
| 1530 |
+The system is designed to fall back to standard active file accesses in |
| 1531 |
+the case actived falls over, which it hasn't in several months of |
| 1532 |
+production use. Hopefully my code is correct. I would strongly advise |
| 1533 |
+anyone who runs it to periodically check to see if actived has died, and |
| 1534 |
+restart it. Just because I've had luck with it,... ;-) |
| 1535 |
+ |
| 1536 |
+To install: patch your nnrpd with the enclosed "group.c.patch". |
| 1537 |
+Build the contents of this directory, install and run "actived", you |
| 1538 |
+can compile "query" and ask it a few questions (i.e. "query alt.sex"), |
| 1539 |
+and then install your new nnrpd if all looks good. |
| 1540 |
+ |
| 1541 |
+JG970605 |
| 1542 |
+ |
| 1543 |
+-- |
| 1544 |
+ |
| 1545 |
+I've made several changes to Joe's code (with Joe's assistance--thanks) to |
| 1546 |
+make actived a bit more portable. I've successfully compiled this version on |
| 1547 |
+Solaris 2.4, Solaris 2.5.1, SunOS 4.1.4, Linux 2.0.30, and OpenBSD 2.1, so |
| 1548 |
+I suspect it'll compile on just about anything now. |
| 1549 |
+ |
| 1550 |
+-Andrew Smith <[email protected]> 970625 |