Ejemplo n.º 1
0
/* intialize the whole system */
int
bnode_Init(void)
{
    PROCESS junk;
    afs_int32 code;
    struct sigaction newaction;
    static int initDone = 0;

    if (initDone)
	return 0;
    initDone = 1;
    memset(&bnode_stats, 0, sizeof(bnode_stats));
    LWP_InitializeProcessSupport(1, &junk);	/* just in case */
    IOMGR_Initialize();
    code = LWP_CreateProcess(bproc, BNODE_LWP_STACKSIZE,
			     /* priority */ 1, (void *) /* parm */ 0,
			     "bnode-manager", &bproc_pid);
    if (code)
	return code;
    memset(&newaction, 0, sizeof(newaction));
    newaction.sa_handler = bnode_Int;
    code = sigaction(SIGCHLD, &newaction, NULL);
    if (code)
	return errno;
    code = sigaction(SIGQUIT, &newaction, NULL);
    if (code)
	return errno;
    code = sigaction(SIGTERM, &newaction, NULL);
    if (code)
	return errno;
    return code;
}
Ejemplo n.º 2
0
void
rxi_InitializeThreadSupport(void)
{
    PROCESS junk;

    LWP_InitializeProcessSupport(LWP_NORMAL_PRIORITY, &junk);
    IOMGR_Initialize();
    FD_ZERO(&rx_selectMask);
}
Ejemplo n.º 3
0
void InitRPC(int VmonPort) {
    long rc = 0;
    int RPC2_TimeOut = 30;
    int RPC2_Retries = 5;

    /* Initialize LWP. */
    PROCESS lwpid;

    if ((rc = LWP_Init(LWP_VERSION, LWP_NORMAL_PRIORITY, &lwpid)) != LWP_SUCCESS)
	Die("InitRPC: LWP_Init failed (%d)\n", rc);

    if ((rc = IOMGR_Initialize()) != LWP_SUCCESS)
	Die("InitRPC: IOMGR Init failed (%d)\n", rc);

    RPC2_PortalIdent portal1;
    portal1.Tag = RPC2_PORTALBYINETNUMBER;
    portal1.Value.InetPortNumber = htons(VmonPort);
    RPC2_PortalIdent *portallist[1];
    portallist[0] = &portal1;
    struct timeval tv;
    tv.tv_sec = RPC2_TimeOut;
    tv.tv_usec = 0;
    rc = RPC2_Init(RPC2_VERSION, 0, portallist, 1, RPC2_Retries,&tv);
    if (rc <= RPC2_ELIMIT)
	Die("InitRPC: RPC2_Init failed (%d)", rc);
    if (rc != RPC2_SUCCESS) {
	LogMsg(0,LogLevel,LogFile, "InitRPC: RPC2_Init warning (%d)", rc);
	rc = 0;
    }

    /* set debug level in lwp */
    if (LogLevel >= 1010)
	lwp_debug = 1;

    /* Export the mond service. */
    RPC2_SubsysIdent server;
    server.Tag = RPC2_SUBSYSBYID;
    server.Value.SubsysId = MondSubsysId;
    if ((rc = RPC2_Export(&server)) != RPC2_SUCCESS)
	Die("InitRPC: RPC2_Export failed (%d)", rc);
    /* get our portal number */
    if (rpc2_LocalPortal.Tag != RPC2_PORTALBYINETNUMBER)
	Die("No portal number.  Tag value (%d)\n",rpc2_LocalPortal.Tag);
    LogMsg(0,LogLevel,LogFile,
	   "My portnum is %d",ntohs(rpc2_LocalPortal.Value.InetPortNumber));
}
Ejemplo n.º 4
0
void
_ko_resolve_init(void)
{
    char *errmem;
    int ret;

    IOMGR_Initialize();

    if (LWP_CreateProcess(ares_worker_thread, AFS_LWP_MINSTACKSIZE, 0, 0, 
			  "ares resolver daemon", &ares_pid))
	errx(1, "Couldn't initialize resolver, helper thread didn't start");

    /* XXX use ARES_FLAG_NOSEARCH */
    ret = ares_init(&achannel);
    if (ret != ARES_SUCCESS)
	errx(1, "Couldn't initialize resolver: %s", 
	     ares_strerror(ret, &errmem));
}
Ejemplo n.º 5
0
int main(int argc, char **argv)
{
    struct timeval t1, t2;
    PROCESS pid, otherpid;
    long i, count, x;
    static char c[] = "OtherProcess";

    count = argc > 1 ? atoi(argv[1]) : 10000;

    cont_sw_threshold.tv_sec    = 0;
    cont_sw_threshold.tv_usec   = 10000;
    last_context_switch.tv_sec  = 0;
    last_context_switch.tv_usec = 0;

    assert(LWP_Init(LWP_VERSION, 0, &pid) == LWP_SUCCESS);
    assert(LWP_CreateProcess(OtherProcess, 16384, 0, (char *)pid, c,
                             &otherpid) == LWP_SUCCESS);
    assert(IOMGR_Initialize() == LWP_SUCCESS);
    gettimeofday(&t1, NULL);

    for (i = 0; i < count; i++) {
#if 0
        LWP_DispatchProcess();
#else
        LWP_QSignal(otherpid);
        LWP_QWait();
#endif
    }

    gettimeofday(&t2, NULL);

    if (count) {
        x = (t2.tv_sec - t1.tv_sec) * 1000000 + (t2.tv_usec - t1.tv_usec);
        printf("%ld milliseconds for %ld Yields (%f usec per Yield)\n",
               x / 1000, count, (float)(x / count));
    }

    LWP_TerminateProcessSupport();
    exit(EXIT_SUCCESS);
}
Ejemplo n.º 6
0
void
main(int ac, char **av)
{
    int delay = 0;
    int iters = 0;
    int inter = 0;
    int line = 0;
    int i;
    PROCESS dotpid;
    int rc;

    for (i = 1; i < ac; i++) {
	if (!strcmp("-delay", av[i])) {
	    if (++i >= ac) {
		printf("Missing delay time for -delay option.\n");
	    }
	    delay = atoi(av[i]);
	    if (delay < 0) {
		printf("Delay must be at least 0 seconds.\n");
		Usage();
	    }
	} else if (!strcmp("-iters", av[i])) {
	    if (++i >= ac) {
		printf("Missing iteration count for -iters option.\n");
	    }
	    iters = atoi(av[i]);
	    if (iters < 0) {
		printf("Number of iterations must be at least 0.\n");
		Usage();
	    }
	} else if (!strcmp("-nobuf", av[i])) {
	    rc = setvbuf(stdin, NULL, _IONBF, 0);
	    if (rc < 0) {
		perror("Setting -nobuf for stdin");
	    }
	} else if (!strcmp("-inter", av[i])) {
	    inter = 1;
	} else if (!strcmp("-line", av[i])) {
	    line = 1;
	} else
	    Usage();
    }

    IOMGR_Initialize();

    LWP_CreateProcess(DotWriter, 32000, LWP_NORMAL_PRIORITY, (char *)0,
		      "DotWriter", &dotpid);

    if (inter) {
	interTest();
	exit(1);
    }
    if (line) {
	lineTest();
	exit(1);
    }
    if (delay == 0) {
	delay = -1;		/* Means wait indefinitely. */
    }
    for (; iters >= 0; iters--) {
	waitingForAnswer = 1;
	LWP_NoYieldSignal(&waitingForAnswer);
	rc = LWP_WaitForKeystroke(delay);
	waitingForAnswer = 0;
	if (rc) {
	    printf("\n'%c'\n", getchar());
	    printf("Flushing remaining input.\n");
	    while (LWP_WaitForKeystroke(0)) {
		printf("'%c'\n", getchar());
	    }
	} else {
	    printf("\nNo data available on this iteration.\n");
	}
    }


}
Ejemplo n.º 7
0
afs_int32
init_krb_udp(void)
#endif
{
    struct sockaddr_in taddr;
    static PROCESS slPid;	/* socket listener pid */
    static PROCESS checkPid;	/* fiveminute check */
    afs_int32 code;
    char *krb4name;		/* kerberos version4 service */

#if MAIN
    PROCESS junk;
#endif
    struct servent *sp;
    static int inited = 0;
    afs_int32 kerb_port;

    if (inited)
	return -1;
    inited = 1;

    memset(&taddr, 0, sizeof(taddr));
    krb4name = "kerberos4";
    sp = getservbyname(krb4name, "udp");
    taddr.sin_family = AF_INET;	/* added for NCR port */
#ifdef STRUCT_SOCKADDR_HAS_SA_LEN
    taddr.sin_len = sizeof(struct sockaddr_in);
#endif
    if (!sp) {
	/* if kerberos-4 is not available, try "kerberos-iv" */
	krb4name = "kerberos-iv";
	sp = getservbyname(krb4name, "udp");
    }
    if (!sp) {
	/* if kerberos-iv is not available, try "kerberos" */
	krb4name = "kerberos";
	sp = getservbyname(krb4name, "udp");
    }
    if (!sp) {
	fprintf(stderr,
		"kerberos/udp is unknown; check /etc/services.  Using port=%d as default\n",
		KRB_PORT);
	taddr.sin_port = htons(KRB_PORT);
    } else {
	/* copy the port number */
	fprintf(stderr, "%s/udp port=%hu\n", krb4name,
		(unsigned short)sp->s_port);
	taddr.sin_port = sp->s_port;
    }
    kerb_port = taddr.sin_port;
    sock_kerb = socket(AF_INET, SOCK_DGRAM, 0);
    code = bind(sock_kerb, (struct sockaddr *)&taddr, sizeof(taddr));
    if (code < 0) {
	perror("calling bind");
	sock_kerb = -1;
    }

    sp = getservbyname("kerberos5", "udp");
    if (!sp) {
	fprintf(stderr,
		"kerberos5/udp is unknown; check /etc/services.  Using port=%d as default\n",
		KRB5_PORT);
	taddr.sin_port = htons(KRB5_PORT);
    } else {
	/* copy the port number */
	fprintf(stderr, "kerberos5/udp port=%hu\n",
		(unsigned short)sp->s_port);
	taddr.sin_port = sp->s_port;
    }
    if (taddr.sin_port != kerb_port) {	/* a different port */
	sock_kerb5 = socket(AF_INET, SOCK_DGRAM, 0);
	code = bind(sock_kerb5, (struct sockaddr *)&taddr, sizeof(taddr));
	if (code < 0) {
	    perror("calling bind");
	    sock_kerb5 = -1;
	}
    }

    /* Bail out if we can't bind with any port */
    if ((sock_kerb < 0) && (sock_kerb5 < 0))
	return -1;

#if MAIN
    /* this has already been done */
    LWP_InitializeProcessSupport(LWP_NORMAL_PRIORITY, &junk);
    IOMGR_Initialize();
#endif
    LWP_CreateProcess(SocketListener, /*stacksize */ 16000,
		      LWP_NORMAL_PRIORITY, (void *)0, "Socket Listener",
		      &slPid);

    /* just to close the log every five minutes */

    LWP_CreateProcess(FiveMinuteCheckLWP, 24 * 1024, LWP_MAX_PRIORITY - 2,
		      (void *)&fiveminutes, "FiveMinuteChecks", &checkPid);

#if MAIN
    initialize_ka_error_table();
    initialize_rxk_error_table();
    while (1)			/* don't just stand there, run it */
	IOMGR_Sleep(60);
#else
    return 0;
#endif

}
Ejemplo n.º 8
0
main(int ac, char **av)
{
    int i;
    int on = 1;
    short port = -1;		/* host order. */
    int setFD = 0;
    struct sockaddr_in saddr;
    int acceptFD;
    clientHandle_t *clientHandle;
    int code;
    int addr_len;
    PROCESS pid;
    fd_set *rfds, *wfds, *efds;
    int sockFD;

    program = av[0];

    if (ac < 2)
	Usage();

/*    lwp_debug = 1; */

    signal(SIGIO, sigIO);


    for (i = 1; i < ac; i++) {
	if (!strcmp("-fd", av[i])) {
	    if (++i >= ac) {
		printf("Missing number for -fd option.\n");
		Usage();
	    }
	    setFD = atoi(av[i]);
	    if (setFD <= 2) {
		printf("%d: file descriptor must be at least 3.\n", setFD);
		Usage();
	    }
	} else {
	    if (port == -1) {
		port = atoi(av[i]);
		if (port <= 0) {
		    printf("%s: port must be at least 1\n", av[i]);
		    Usage();
		}
	    } else {
		printf("%s: Unknown argument.\n", av[i]);
	    }
	}
    }

    if (port == -1) {
	printf("Missing port.\n");
	Usage();
    }

    if (!setFD) {
	setFD = 31;
	printf("Using default socket of %d.\n", setFD);
    }

    OpenFDs(setFD);

    IOMGR_Initialize();

    /* Setup server processes */
    for (i = 0; i < MAX_THREADS; i++) {
	if (LWP_CreateProcess
	    (handleRequest, 32768, LWP_NORMAL_PRIORITY,
	     (char *)&clientHandles[i], "HandleRequestThread", &pid) < 0) {
	    printf("%s: Failed to start all LWP's\n", program);
	    exit(1);
	}
	clientHandles[i].ch_pid = pid;
    }


    sockFD = socket(AF_INET, SOCK_STREAM, 0);
    if (sockFD < 0) {
	perror("socket");
	exit(1);
    }
    Log("Using socket at file descriptor %d.\n", sockFD);

    if (setsockopt(sockFD, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on))
	< 0) {
	perror("setsockopt: ");
	exit(1);
    }

    memset((void *)&saddr, 0, sizeof(saddr));

    saddr.sin_family = AF_INET;
    saddr.sin_port = ntohs(port);
    saddr.sin_addr.s_addr = htonl(INADDR_ANY);

    if (bind(sockFD, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
	perror("bind: ");
	exit(1);
    }


    rfds = IOMGR_AllocFDSet();
    wfds = IOMGR_AllocFDSet();
    efds = IOMGR_AllocFDSet();
    if (!rfds || !wfds || !efds) {
	printf("main: Could not alloc fd_set's.\n");
	exit(1);
    }

    listen(sockFD, 100);


    while (1) {
	FD_ZERO(rfds);
	FD_ZERO(wfds);
	FD_ZERO(efds);
	FD_SET(sockFD, rfds);
	FD_SET(sockFD, efds);

	Log("Main - going to select.\n");
	code =
	    IOMGR_Select(sockFD + 1, rfds, wfds, efds, (struct timeval *)0);
	switch (code) {
	case 0:		/* Timer, can't happen here. */
	case -1:
	case -2:
	    Log("Oops! select returns %d!\n", code);
	    abort();
	default:
	    if (FD_ISSET(sockFD, efds)) {
		recvOOB(sockFD);
		assertNullFDSet(sockFD, rfds);
		assertNullFDSet(-1, wfds);
		assertNullFDSet(sockFD, efds);
	    }
	    if (FD_ISSET(sockFD, rfds)) {
		while (nThreads > MAX_THREADS) {
		    IOMGR_Sleep(1);
		}

		clientHandle = getClientHandle();

		addr_len = sizeof(clientHandle->ch_addr);
		clientHandle->ch_fd = accept(sockFD, (struct sockaddr *)
					     &clientHandle->ch_addr,
					     &addr_len);
		if (clientHandle->ch_fd < 0) {
		    perror("accept: ");
		    exit(1);
		}

		Log("Main - signalling LWP 0x%x\n", &clientHandle->ch_state);
		LWP_NoYieldSignal(&clientHandle->ch_state);
		assertNullFDSet(sockFD, rfds);
		assertNullFDSet(-1, wfds);
		assertNullFDSet(-1, efds);
		break;
	    }
	    Die(1, "(main) No data to read.\n");
	}
    }
}
Ejemplo n.º 9
0
int main(int argc, char **argv)
{
    PROCESS pid;
    char *progname = strdup(argv[0]);

    if (progname == NULL)
	progname = "foo";

    if (argc <= 1 ) 
	usage(progname);
    
    printf("starting LWP support\n");
    if (LWP_InitializeProcessSupport(LWP_NORMAL_PRIORITY, &pid))
	errx(1, "LWP_InitializeProcessSupport()");

    printf("starting IOMGR support\n");
    if (IOMGR_Initialize())
	errx(1, "IOMGR_Initialize()");

    while (argv[1]) {
	if (strcasecmp("pc", argv[1]) == 0) {
	    startPCtest();
	} else if (strcasecmp("sleep", argv[1]) == 0) {
	    putMrSleeptoBed();
	} else if (strcasecmp("selectproducer", argv[1]) == 0) {
	    SelectProducer(NULL); 
	    exit(1); /* Special case */
	} else if (strcasecmp("selectconsumer", argv[1]) == 0) {
	    startSelectPC (progname);
	} else if (strcasecmp("cancel", argv[1]) == 0) {
	    yaEndlessLoop();	 
	} else if (strcasecmp("deadlock-write", argv[1]) == 0) {
	    deadlock_write();
	} else if (strcasecmp("deadlock-read", argv[1]) == 0) {
	    deadlock_read();
	} else if (strcasecmp("deadlock-read2", argv[1]) == 0) {
	    deadlock_read2();
	} else if (strcasecmp("overrun-stack", argv[1]) == 0) {
	    PROCESS tpid;
	    if (LWP_CreateProcess (overrun_stack, LWPTEST_STACKSIZE, 1,
				   NULL, "overunner", &tpid))
		errx (1, "Cannot create stack overrunner process");
	} else if (strcasecmp("underrun-stack", argv[1]) == 0) {
	    PROCESS tpid;
	    if (LWP_CreateProcess (underrun_stack, LWPTEST_STACKSIZE, 1,
				   NULL, "underrunner", &tpid))
		errx (1, "Cannot create stack underrunner process");
	} else if (strcasecmp("version", argv[1]) == 0) {
	    printf("Version: "
		   "$arla: testlwp.c,v 1.9 2002/06/01 17:47:49 lha Exp $\n");
	    exit (0);
	} else {
	    printf("unknown command %s\n", argv[1]);
	    exit (1);
	}

	argc--;
	argv++;
    }
    LWP_WaitProcess((char *) main);
    return 0;
}
Ejemplo n.º 10
0
main(int ac, char **av)
{
    int i;
    int on = 1;
    char *hostname = 0;
    struct hostent *hostent;
    int host;			/* net order. */
    short port = -1;		/* host order. */
    int setFD = 0;
    int sockFD;
    struct sockaddr_in saddr;
    int reqOOB = 0;
    int putOOB = 0;
    int delay = 5;
    int doEnd = 0;
    int doWrite = 0;
    int writeSize = 0;

    program = av[0];

    signal(SIGIO, sigIO);


    for (i = 1; i < ac; i++) {
	if (!strcmp("-fd", av[i])) {
	    if (++i >= ac) {
		printf("Missing number for -fd option.\n");
		Usage();
	    }
	    setFD = atoi(av[i]);
	    if (setFD <= 2) {
		printf("%s: %d: file descriptor must be at least 3.\n",
		       program, setFD);
		Usage();
	    }
	} else if (!strcmp("-end", av[i])) {
	    doEnd = 1;
	} else if (!strcmp("-delay", av[i])) {
	    if (++i >= ac) {
		printf("%s: Missing time for -delay option.\n", program);
		Usage();
	    }
	    delay = atoi(av[i]);
	    if (delay < 0) {
		printf("%s: %s: delay must be at least 0 seconds.\n", program,
		       av[i]);
		Usage();
	    }
	} else if (!strcmp("-write", av[i])) {
	    doWrite = 1;
	    if (++i >= ac) {
		printf("%s: Missing size for -write option.\n", program);
		Usage();
	    }
	    writeSize = atoi(av[i]);
	    if (writeSize < 1) {
		printf("%s: %s: Write size must be at least 1 byte.\n",
		       program, av[i]);
		Usage();
	    }
	} else if (!strcmp("-oob", av[i])) {
	    reqOOB = 1;
	} else if (!strcmp("-soob", av[i])) {
	    putOOB = 1;
	} else {
	    if (!hostname) {
		hostname = av[i];
	    } else if (port == -1) {
		port = atoi(av[i]);
		if (port <= 0) {
		    printf("%s: %s: port must be at least 1\n", program,
			   av[i]);
		    Usage();
		}
	    } else {
		printf("%s: %s: Unknown argument.\n", program, av[i]);
	    }
	}
    }

    if (!hostname) {
	printf("%s: Missing hostname and port.\n", program);
	Usage();
    }
    if (port == -1) {
	printf("%s: Missing port.\n", program);
	Usage();
    }

    if (writeSize == 0 && doEnd == 0 && putOOB == 0) {
	printf("%s: Missing action.\n", program);
	Usage();
    }

    if (!setFD) {
	setFD = 31;
	printf("%s: Using default socket of %d.\n", program, setFD);
    }

    if (!(hostent = gethostbyname(hostname))) {
	printf("%s: Failed to find host entry for %s.\n", program, hostname);
	exit(1);
    }

    memcpy((void *)&host, (const void *)hostent->h_addr, sizeof(host));

    OpenFDs(setFD);

    /* Connect to server. */
    sockFD = socket(AF_INET, SOCK_STREAM, 0);
    if (sockFD < 0) {
	Die(0, "socket");
    }
    printf("%s: Using socket at file descriptor %d.\n", program, sockFD);

    memset((void *)&saddr, 0, sizeof(saddr));
    saddr.sin_family = AF_INET;
    saddr.sin_addr.s_addr = host;	/* already in network byte order. */
    saddr.sin_port = htons(port);

    if (connect(sockFD, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
	assert(0);
    }


    if (doEnd) {
	sendEnd(sockFD);
    } else if (putOOB) {
	Log("Will send OOB in 2 seconds.\n");
	sleep(2);
	sendOOB(sockFD);
	Log("Sent OOB, sleeping for 5 seconds.\n");
	sleep(5);
	Log("Sent OOB, exiting.\n");
    } else {
	IOMGR_Initialize();
	sendTest(sockFD, delay, reqOOB, writeSize);
    }
    close(sockFD);
}
Ejemplo n.º 11
0
long RPC2_Init(const char *VId,		/* magic version string */
	       RPC2_Options *Options,
	       RPC2_PortIdent *Port,	/* array of portal ids */
	       long RetryCount,	   /* max number of retries before breaking conn*/
	       struct timeval *KAInterval	/* for keeping long RPC requests alive  */
	       )
{
    char *c;
    long i;
    PROCESS ctpid;
    struct RPC2_addrinfo *rpc2_localaddrs;
    long rc1 = RPC2_NOCONNECTION, rc2, rc;
    short port = 0;
    int verbose;
    char *env;

    rpc2_logfile = stderr;
    rpc2_tracefile = stderr;

    rpc2_Enter();
    say(1, RPC2_DebugLevel, "RPC2_Init()\n");
    say(999, RPC2_DebugLevel, "Runtime system version: \"%s\"\n", RPC2_VERSION);

    if (strcmp(VId, RPC2_VERSION) != 0)
    {
	say(-1, RPC2_DebugLevel, "RPC2_Init(): Wrong RPC2 version\n");
	rpc2_Quit (RPC2_WRONGVERSION);
    }

    /* rpc2_InitConn returns 0 if we're already initialized */
    if (rpc2_InitConn() == 0) rpc2_Quit(RPC2_SUCCESS);

    if (Options && (Options->Flags & RPC2_OPTION_IPV6))
	rpc2_ipv6ready = 1;

    env = getenv("RPC2SEC_KEYSIZE");
    if (env)
	RPC2_Preferred_Keysize = atoi(env);
    if (RPC2_Preferred_Keysize > 64)
	RPC2_Preferred_Keysize /= 8;

    /* Do we accept only secure connections, default is yes. This can be
     * disabled by setting the RPC2SEC_ONLY to 0, false, no, (nada, forgetit) */
    env = getenv("RPC2SEC_ONLY");
    RPC2_secure_only = !env || (env && memchr("0fFnN", *env, 5) == NULL);

    verbose = (Options && (Options->Flags & RPC2_OPTION_VERBOSE_INIT));
    secure_init(verbose);

    rpc2_InitMgrp();
    rpc2_InitHost();

    rpc2_localaddrs = rpc2_resolve(&rpc2_bindhost, Port);

    if (!rpc2_localaddrs) {
	say(-1, RPC2_DebugLevel, "RPC2_Init(): Couldn't get addrinfo for localhost!\n");
	rpc2_Quit(RPC2_FAIL);
    }

#ifdef PF_INET6
    rc1 = rpc2_CreateIPSocket(PF_INET6, &rpc2_v6RequestSocket,
			      rpc2_localaddrs, &port);
#endif
    rc2 = rpc2_CreateIPSocket(PF_INET, &rpc2_v4RequestSocket,
			      rpc2_localaddrs, &port);

    RPC2_freeaddrinfo(rpc2_localaddrs);

    /* rc should probably be the most 'positive' result of the two */
    rc = (rc1 > rc2) ? rc1 : rc2;
    if (rc < RPC2_ELIMIT) {
	say(-1, RPC2_DebugLevel, "RPC2_Init(): Couldn't create socket\n");
	rpc2_Quit(rc);
    }

    rpc2_LocalPort.Tag = RPC2_PORTBYINETNUMBER;
    rpc2_LocalPort.Value.InetPortNumber = port;

    if (Port)
	*Port = rpc2_LocalPort;

    /* Initialize retry parameters */
    if (rpc2_InitRetry(RetryCount, KAInterval) != 0) {
	say(-1, RPC2_DebugLevel,"RPC2_Init(): Failed to init retryintervals\n");
	rpc2_Quit(RPC2_FAIL);
    }

    IOMGR_Initialize();
    TM_Init(&rpc2_TimerQueue);

    /* Register rpc2 packet handler with rpc2_SocketListener before
     * initializing the sideeffects */
    SL_RegisterHandler(RPC2_PROTOVERSION, rpc2_HandlePacket);
    
    /* Call side effect initialization routines */
    for (i = 0; i < SE_DefCount; i++)
	if (SE_DefSpecs[i].SE_Init != NULL)
	    if ((*SE_DefSpecs[i].SE_Init)() < RPC2_ELIMIT) {
		say(-1, RPC2_DebugLevel, "RPC2_Init(): Failed to init SE\n");
		rpc2_Quit(RPC2_SEFAIL2);
	    }

    c = "SocketListener";
    LWP_CreateProcess(rpc2_SocketListener, 32768, LWP_NORMAL_PRIORITY, NULL,
		      c, &rpc2_SocketListenerPID);

    c = "ClockTick";
    LWP_CreateProcess(rpc2_ClockTick, 16384, LWP_NORMAL_PRIORITY, NULL, c, &ctpid);

    LUA_init();

    if (rc != RPC2_SUCCESS)
	say(-1, RPC2_DebugLevel, "RPC2_Init(): Exiting with error\n");

    rpc2_Quit(rc);
}