connections.c 16.8 KB
Newer Older
Per Cederqvist's avatar
Per Cederqvist committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * connections.c
 *
 * Denna fil inneh}ller niv}n ovanf|r isc.
 *
 * Created by Willf|r 31/3-90. Mostly written by ceder.
 */

#include <errno.h>
#include <setjmp.h>
#include <sys/types.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <time.h>
#include <sys/time.h>

Per Cederqvist's avatar
Per Cederqvist committed
17
#include "s-string.h"
Per Cederqvist's avatar
Per Cederqvist committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31
#include <kom-types.h>
#include "lyskomd.h"
#include <config.h>
#include <debug.h>
#include "end-of-atomic.h"
#include "log.h"
#include <services.h>
#include "isc.h"
#include <kom-errno.h>
#include "com.h"
#include "connections.h"
#include "prot-a-parse.h"
#include "prot-a-output.h"
#include "prot-a.h"
32
#include <server/smalloc.h>
Per Cederqvist's avatar
Per Cederqvist committed
33 34 35 36 37 38 39 40 41 42 43
#include "prot-a-parse-arg.h"
#include "isc-parse.h"
#include "cache.h"
#include "send-async.h"
#include "mux.h"
#include "mux-parse.h"
#include "internal-connections.h"

ISCMCB         * kom_server_mcb    = NULL;
Connection     * active_connection = NULL;

44 45
volatile Bool	 go_and_die = FALSE;
volatile Bool	 do_sync_db = FALSE;
Per Cederqvist's avatar
Per Cederqvist committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59

jmp_buf 	 parse_env;


const Fnc_descriptor fnc_defs[]={
#include "fnc-def-init.incl"
};

u_long service_statistics[sizeof (fnc_defs) / sizeof (Fnc_descriptor)];

BUGDECL;



Per Cederqvist's avatar
Per Cederqvist committed
60
static void
Per Cederqvist's avatar
Per Cederqvist committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
logout_client(Connection *cp)
{
    Connection *real_active_connection;

    if ( active_connection != NULL )
    {
	log("BUGCHK: logout_client(%d): connection %d is active.\n",
	    cp->session_no, active_connection->session_no);
    }
    
    switch (cp->magic)
    {
    case CONN_MAGIC_ALLOC:
        break;

    case CONN_MAGIC_FREE:
	log("LOGOUT_CLIENT: Trying to free freed Connection - ignored!\n");
	return;

    default:
	restart_kom("LOGOUT_CLIENT: Bad magic number\n");
    }

    if ( cp->pers_no != 0 )
    {
	real_active_connection = active_connection; /* Shouldn't be needed +++ */
	active_connection = cp;
	logout();
	active_connection = real_active_connection;
    }

    switch(cp->protocol)
    {
    case 0:			/* Hasn't yet allocated any protocol. */
	break;
	
    case 'A':
	prot_a_destruct(cp);
	break;
	
    default:
	restart_kom("logout_client(): Bad protocol.\n");
    }

    mux_close(cp);		/* Close fd's. Clear mux and isc structures. */

    kill_client(cp);		/* Free the Connection */
}

Per Cederqvist's avatar
Per Cederqvist committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
/*
 * This function is part of the shutdown tidy-up sequence.
 */
void
logout_all_clients(void)
{
    Session_no sess = 0;
    Connection *conn;
    
    while ( (sess = traverse_connections (sess)) != 0)
    {
	conn = get_conn_by_number (sess);

	if ( conn == NULL )
	    restart_kom("logout_all_clients(): cant get session %d.\n",
			sess);
	else
	    logout_client (conn);
    }

    if ( traverse_connections (0) != 0)
	restart_kom("logout_all_clients(): traverse_connections(0) == %d.\n",
		    traverse_connections(0));
}

    
Per Cederqvist's avatar
Per Cederqvist committed
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671
    

    
/*
 * Call a function in services.c. A pointer to the result is returned.
 * The pointer points to static data which is overwritten on each call.
 */
static Success
call_function (Connection  * client,
	       Result_holder   * res)     /* This is a union. */
{
    Success	status=FAILURE;	/* OK if the call was successful. */

    if ( active_connection != NULL )
    {
	log("call_function(%d): active_connection = %d",
	    client->session_no, active_connection->session_no);
    }
    
    active_connection = client;

    service_statistics[client->function]++;

#include "call-switch.incl"

    active_connection = NULL;

    return status;
}


static void
parse_packet(Connection *client)
{
    if ( client->protocol == '\0' ) /* Not known yet. */
    {
	client->protocol = parse_char(client);
	switch(client->protocol)
	{
	case 'A':
	    prot_a_init(client);
	    break;

	default:
	    client->protocol = '\0';
	    mux_printf(client,
		    "%%%%LysKOM unsupported protocol.\n");
	    mux_flush(client);
	    BUG(("%%%%Unsupported protocol.\n"));
	    longjmp(parse_env, ISC_LOGOUT);
	}
    }

    switch(client->protocol)
    {
    case 'A':
	prot_a_parse_packet(client);
	break;

    default:
	restart_kom("parse_packet(): Bad protocol.\n");
	break;
    }
}

/*
 * Free all parsed areas which are no longer needed. Re-initialize all
 * parse_pos fields so that the parse will expect a new function.
 *
 * This function is called
 *	when a parse error occurs
 *	when a parse is complete and the function has executed.
 */
static void
free_parsed(Connection *client)
{
    s_clear(&client->c_string0);
    s_clear(&client->c_string1);
    client->string0 = EMPTY_STRING; /* So that no one frees it. */
    sfree( client->c_misc_info_p);
    client->c_misc_info_p = NULL;
    sfree( client->c_local_text_no_p);
    client->c_local_text_no_p = NULL;
    client->parse_pos = 0;
    client->fnc_parse_pos = 0;
    client->array_parse_pos = 0;
    client->struct_parse_pos = 0;
    client->string_parse_pos = 0;
}

/*
 * Send a reply to a call.
 */
static void
reply(Connection *client,
      Success	      status,
      Result_holder  *result)
{
    switch(client->protocol)
    {
    case 'A':
	prot_a_reply(client, status, result);
	break;

    default:
	restart_kom("reply(): Bad protocol.\n");
	break;
    }
}


/*
 * Try to parse enough data from client->unparsed to call a function.
 * If more data is needed set client->more_to_parse to FALSE.
 */
static void
parse_unparsed(Connection *client)
{
    String        tmp_str = EMPTY_STRING;
    Success       status;
    Result_holder result;
        
    switch ( setjmp(parse_env) )
    {
    case 0 :
	/* Parse message. If message is complete call function and reply. */
	parse_packet(client);
	client->last_request = time(NULL);
	status = call_function(client, &result);
	reply(client, status, &result);
	free_parsed(client);
	end_of_atomic(FALSE);
	break;

    case ISC_PROTOCOL_ERR:
	s_clear(&client->string0);
	free_parsed(client);
	mux_printf(client, "%% LysKOM protocol error.\n");
	mux_flush(client);
	BUG(("%%%% Protocol error.\n"));
	s_clear(&client->unparsed);
	client->first_to_parse = 0;
	client->more_to_parse = FALSE;
	end_of_atomic(FALSE);
	break;

    case ISC_MSG_INCOMPLETE:
	client->more_to_parse = FALSE;
	break;

    case ISC_LOGOUT:
	client->kill_me = TRUE;
	break;
    }
    
    /* Delete the parsed part of 'unparsed' */
    
    if ( s_substr(&tmp_str, client->unparsed,
		  client->first_to_parse, END_OF_STRING) != OK )
	restart_kom("parse_unparsed: s_substr\n");

    s_clear(&client->unparsed);
    client->unparsed = tmp_str;
    client->first_to_parse = 0;
}


/*
 * There is a message in the event. Parse it.
 */
static void
parse_message(Connection *cp, String tmp_str)
{
    VBUGSTR(tmp_str);

    cp->more_to_parse = TRUE;
    
    if ( s_strcat(&cp->unparsed, tmp_str) != OK )
	restart_kom("parse_message(): s_strcat\n");

    tmp_str = EMPTY_STRING;
    
    /* Parse this packet, but leave the last token if it isn't complete. */

    parse_unparsed(cp);

    return;
}

static void
mux_handle_packet(Mux *mux)
{
    Mux_client *mcp = NULL;
    Connection *cp = NULL;

    switch(mux->parse.function)
    {
    case 0:			/* ping */
	isc_printf(mux->scb, "0\n");
	isc_flush(mux->scb);
	break;

    case 1:			/* login */

	mcp = mux_getclientbyid(mux, mux->parse.num);
	if (mcp)
	{			/* ERROR %d: Already logged in\n */
	    isc_printf(mux->scb, "4\n");
	    isc_flush(mux->scb);
	    return;
	}
    
	cp = new_client();
	cp->mux = mux;
	cp->hostname = mux->parse.string;
	mux->parse.string = EMPTY_STRING;
	
	mux_addclient(mux, mux->parse.num, cp);

    
	BUG(("\n[Client %d from %.*s via MUX %s",
	     cp->session_no,
	     cp->hostname.len,
	     cp->hostname.string,
	     mux->scb->info.tcp.hostname));
	BUG((" is connecting]\n"));

	break;
    
    case 2:			/* logout */
	mcp = mux_getclientbyid(mux, mux->parse.num);
	if (!mcp)
	{			/* ERROR %d: No such mux-session */
	    isc_printf(mux->scb, "4\n");
	    isc_flush(mux->scb);
	    return;
	}

	cp = mcp->conn;
    
	BUG(("\n[Client %d via MUX(%s)",
	     cp->session_no,
	     mux->scb->info.tcp.hostname));
	BUG((" is logging out by request]\n"));

#if 0
	logout_client(cp);
	end_of_atomic(FALSE);	/* ??? */
#else
	cp->kill_me = TRUE;
#endif
	break;

    case 3:			/* msg */
	mcp = mux_getclientbyid(mux, mux->parse.num);
	if (!mcp)
	{			/* ERROR %d: No such mux-session */
	    isc_printf(mux->scb, "4\n");
	    isc_flush(mux->scb);
	    return;
	}
    
	cp = mcp->conn;
    
	VBUG(("\n[Message client %d via MUX #%d]\n",
	      cp->session_no, mux->scb));

	parse_message(cp, mux->parse.string);
	break;

    default:
	
	VBUG(("\nMUX Protocol error from MUX #%d]\n",
	      mux->scb));

	isc_printf(mux->scb, "5\n");
	isc_flush(mux->scb);
	break;
	
    }
}
	
void
mux_logout(Mux *mp)
{
    int i;

    for (i = 0; i < mp->client_c; i++)
	if (mp->client_v[i].conn)
	{
	    BUG(("\n[Client %d via MUX(%s)",
		 mp->client_v[i].conn->session_no,
		 mp->scb->info.tcp.hostname));
	    BUG((" is logging out by MUX shutdown]\n"));
	    logout_client(mp->client_v[i].conn);
	    end_of_atomic(FALSE);
	}
	      
    isc_close(mp->scb);
    mux_destruct(mp);
}


static void
mux_parse_unparsed(Mux *mux)
{
    String        tmp_str;

    while ( mux->parse.more_to_parse )
    {
	switch ( setjmp(mux_parse_env) )
	{
	case 0 :
	    /* Parse message. Take apropriate action if message is complete. */
	    mux_parse_packet(mux);
	    mux_handle_packet(mux);
	    mux_free_parsed(mux);
	    break;

	case MUX_PROTOCOL_ERR:
	    s_clear(&mux->parse.string);
	    mux_free_parsed(mux);
	    isc_printf(mux->scb, "5\n");
	    isc_flush(mux->scb);
	    BUG(("%%%% Mux protocol error.\n"));
	    s_clear(&mux->parse.unparsed);
	    mux->parse.first_to_parse = 0;
	    mux->parse.more_to_parse = FALSE;
	    break;

	case MUX_MSG_INCOMPLETE:
	    mux->parse.more_to_parse = FALSE;
	    break;

	case MUX_LOGOUT:
	    mux_logout(mux);
	    return;
	}
    
	/* Delete the parsed part of 'unparsed' */

	tmp_str = EMPTY_STRING;

	if ( s_substr(&tmp_str, mux->parse.unparsed,
		      mux->parse.first_to_parse, END_OF_STRING) != OK )
	    restart_kom("mux_parse_unparsed: s_substr\n");

	s_clear(&mux->parse.unparsed);
	mux->parse.unparsed = tmp_str;
	mux->parse.first_to_parse = 0;
    }
}


static void
mux_parse_message(Mux *mp, String tmp_str)
{
    VBUGSTR(tmp_str);

    BUG(("mux_parse_message(): mp->parse.unparsed = { len = %d, "
	 "string = %p }\n", mp->parse.unparsed.len,
	 mp->parse.unparsed.string));
    
    if ( s_strcat(&mp->parse.unparsed, tmp_str) != OK )
	restart_kom("mux_parse_message(): s_strcat\n");

    tmp_str = EMPTY_STRING;
    
    /* Parse this packet, but leave the last token if it isn't complete. */

    mux_parse_unparsed(mp);

    return;
}

/*
 * parse data in client->unparsed and mux->unparsed if there
 * is data that has not yet been taken care of. Return TRUE
 * if there was no data to take care of.
 */
Bool
parse_forgotten()
{
    Bool flg = FALSE;			/* Was there anything? */
    Connection *ci;
    Session_no session_no = 0;

    if ( traverse_connections(0) == 0 )
	return TRUE;

    while ( ( session_no = traverse_connections( session_no ) ) != 0 )
    {
	ci = get_conn_by_number (session_no);

	if ( ci->more_to_parse )
	{
	    parse_unparsed(ci);
	    flg = TRUE;
	}
    }

    return !flg;
}


/* Return 1 if the named file exists, 0 otherwise */
static int
fexists(char *filename)
{
    extern int stat(char *filename, struct stat *bufp);
    struct stat buf;
    int code;
  
    code = !stat(filename, &buf);
    errno = 0;

    return code;
}


void
dump_statistics(void)
{
    static time_t last_dump = NO_TIME;
    int i;
    time_t now;
    FILE *fp;
    extern char statisticfile[1024]; /* Defined in ramkomd.c */

    if ( (fp = fopen(statisticfile, "a")) == NULL )
    {
	log(__FILE__ ": dump_statistics(): can't open file %s\n",
	    statisticfile);
	return;
    }

    time(&now);

    if (last_dump == NO_TIME)
    {
	fprintf(fp, "RESTART\n");
	last_dump = now;
    }
    
    fprintf(fp, "TIME: %s", ctime(&now));
    fprintf(fp, "SECONDS: %d\n", (int)difftime(now, last_dump));
    fprintf(fp, "STATISTICS:");
    for ( i = 0; i < sizeof(service_statistics) / sizeof(u_long); i++)
    {
	fprintf(fp, " %lu", service_statistics[i]);
	service_statistics[i]=0;
    }

    fprintf(fp, "\n");
    fclose(fp);

    last_dump = now;
}


/*
 * check_kill_flg must NEVER be called inside an atomic call!
 */
static void
check_kill_flg(void)
{
    Session_no  i = 0;
    Connection *conn;

    if ( active_connection != NULL )
    {
	restart_kom("check_kill_flg: active_connection == %d",
		    active_connection->session_no);
    }

    while ( (i = traverse_connections (i)) != 0 )
    {
	conn = get_conn_by_number(i);

	if ( conn->kill_me == TRUE )
	{
	    logout_client(conn);
	    end_of_atomic(FALSE);
	}
    }
}

static void
login_request(ISCECB  *event)
{
    Connection  * cp;

    if (isc_sessions(kom_server_mcb) >= MAX_NO_OF_CONNECTIONS)
    {
	BUG(("Connection attempt rejected.\n"));
	isc_printf(event->session, "%s", "%% No connections left.\n");
	isc_flush(event->session);
	isc_close(event->session);
	      
	async_rejected_connection();
	return;
    }

    /* Supress logins if /etc/nologin exists */
    if (fexists("/etc/nologin"))
    {
	isc_printf(event->session, "%s", "%% No logins allowed.\n");
	isc_flush(event->session);
	isc_close(event->session);
	return;
    }

    if (event->session->info.tcp.listen == listen_mux)
    {
	/* Multiplexer requesting connection */

	/*
	 ** Create, and setup the MUX for the MUX case
	 */
	event->session->udg = mux_create(MUX_TYPE_MUX, event->session);
	      
	BUG(("MUX #%d at %s connecting.\n",
	     event->session, event->session->info.tcp.hostname));
    }
    else
    {
	/* Client requesting connection */
	      
	/*
	 ** Create, and setup the MUX for the CLIENT case
	 */
	event->session->udg = mux_create(MUX_TYPE_CLIENT,
					 event->session);
	      
	cp = new_client();
	cp->mux = event->session->udg;
Per Cederqvist's avatar
Per Cederqvist committed
672
	s_crea_str(&cp->hostname, event->session->info.tcp.hostname);
Per Cederqvist's avatar
Per Cederqvist committed
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719
	      
	mux_addclient(event->session->udg, 0, cp);
	      
	BUG(("\n[Client %d from %s", cp->session_no,
	     event->session->info.tcp.hostname));
	BUG((" is connecting]\n"));
    }	      
}

static void
logout_request(ISCECB *event)
{
    Connection  * cp;
    
    if (event->session->udg->type == MUX_TYPE_MUX)
    {
	BUG(("\n[MUX #%d at %s", event->session,
	     event->session->info.tcp.hostname));
	BUG((" is logging out]\n"));

	/*
	 ** Logout any remaining clients
	 */
	mux_logout(event->session->udg);
    }
    else
    {
	cp = event->session->udg->client_v[0].conn;
	      
	BUG(("\n[Client %d from %s", cp->session_no,
	     event->session->info.tcp.hostname));
	BUG((" is logging out]\n"));
	      
	cp->kill_me = TRUE;
    }
}


static void
message_request(ISCECB *event)
{
    Connection *cp;
    String      tmp_str;

    if (event->session->udg->type == MUX_TYPE_MUX)
    {
	event->session->udg->parse.more_to_parse = TRUE;
720
	tmp_str.string = (unsigned char *)event->msg->buffer;
Per Cederqvist's avatar
Per Cederqvist committed
721 722 723 724 725 726 727 728 729 730 731
	tmp_str.len    = event->msg->length;
	mux_parse_message(event->session->udg, tmp_str);
    }
    else
    {
	cp = event->session->udg->client_v[0].conn;
	VBUG(("\n[Message from client %d]\n",
	      cp->session_no));
	/*
	 ** Pass the message on to the parser
	 */
732
	tmp_str.string = (unsigned char *)event->msg->buffer;
Per Cederqvist's avatar
Per Cederqvist committed
733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833
	tmp_str.len    = event->msg->length;
	parse_message(cp, tmp_str);
    }
}

static long
timevaldiff(struct timeval a,
	    struct timeval b)
{
    return 1000000 * (a.tv_sec - b.tv_sec) + a.tv_usec - b.tv_usec;
}

void
toploop(void)
{
    ISCECB      * event;
    Bool	pending_input = TRUE; /* Should be TRUE whenever there
				         is or might be pending input
					 from any client in the unparsed
					 buffer. */
    long	timeout = TIMEOUT;    /* In milliseconds. */
    struct timeval before, after;
    
    while ( !go_and_die )
    {
        if (do_sync_db)
	{
	    cache_sync();	/* A noop in diskomd. Actually
				   stops the server and dumps
				   everything in ramkomd. */
	    dump_statistics();
	    do_sync_db = 0;
	}

	gettimeofday(&before, NULL);
	event = isc_getnextevent(kom_server_mcb,
				 pending_input ? 0 : timeout );
	gettimeofday(&after, NULL);

	timeout -= timevaldiff(after, before) / 1000;

	if ( timeout < 0 )
	    timeout = 0;
	
	if ( event == NULL )
	    restart_kom("toploop(): Got NULL event - shouldn't happen...\n");

	switch ( event->event )
	{
	case ISC_EVENT_ERROR:
	    if (errno != EINTR)
	    {
		log("toploop: ISC_EVENT_ERROR (error = '%s'):\n   '%s'\n",
		    strerror(errno), event->msg ? event->msg->buffer
		    : "(unknown)");
	    }
	    break;
	    
	case ISC_EVENT_TIMEOUT:
	    BUG((">"));
#ifdef DEBUG
	    fflush(stdout);
#endif
	    if ( pending_input == FALSE )
		timeout = end_of_atomic(TRUE); /* Idle. Do some cleaning up. */
	    else
	    {
		if ( timeout == 0 )
		    end_of_atomic(FALSE);
		pending_input = !parse_forgotten();
	    }
	    
	    	    
	    break;
	    
	case ISC_EVENT_LOGIN:
	    pending_input = TRUE;
	    login_request(event);
	    break;

	case ISC_EVENT_LOGOUT:
	    pending_input = TRUE;
	    logout_request(event);
	    break;

 	case ISC_EVENT_MESSAGE:
	    pending_input = TRUE;
	    message_request(event);
	    break;

	default:
	    pending_input = TRUE;
	    log("ERROR: toploop(): Unknown ISC_EVENT\n");
	    break;
	}

        isc_dispose(event);

	check_kill_flg();
    }
}