void conn_init (unsigned nentries) { arla_warnx (ADEBCONN, "initconncache"); connhtab = hashtabnew (CONNCACHESIZE, conncmp, connhash); if (connhtab == NULL) arla_errx (1, ADEBERROR, "conn_init: hashtabnew failed"); connfreelist = listnew (); if (connfreelist == NULL) arla_errx (1, ADEBERROR, "conn_init: listnew failed"); connprobelist = listnew (); if (connprobelist == NULL) arla_errx (1, ADEBERROR, "conn_init: listnew failed"); nconnections = 0; if (LWP_CreateProcess (pinger, PINGER_STACKSIZE, 1, NULL, "pinger", &pinger_pid)) arla_errx (1, ADEBERROR, "conn: cannot create pinger thread"); create_new_connections (nentries); }
static void arla_start (char *device_file, const char *cache_dir) { struct kernel_args kernel_args; PROCESS kernelpid; signal (SIGINT, sigint); signal (SIGTERM, sigint); signal (SIGHUP, sighup); umask (S_IRWXG|S_IRWXO); /* 077 */ #if defined(HAVE_SYS_PRCTL_H) && defined(PR_SET_DUMPABLE) prctl(PR_SET_DUMPABLE, 1); #endif nnpfs_message_init (); kernel_opendevice (device_file); kernel_args.num_workers = num_workers; if (LWP_CreateProcess (kernel_interface, KERNEL_STACKSIZE, 1, (char *)&kernel_args, "Kernel-interface", &kernelpid)) arla_errx (1, ADEBERROR, "Cannot create kernel-interface process"); write_pid_file ("arlad"); if (chroot (cache_dir) < 0) arla_err (1, ADEBERROR, errno, "chroot %s", cache_dir); if (chdir("/") < 0) arla_err (1, ADEBERROR, errno, "chdir /"); if (fork_flag) kill(getppid(), SIGUSR1); if (pw) { if (setgroups(1, &pw->pw_gid) == -1 || setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) == -1 || setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) == -1) arla_err (1, ADEBERROR, errno, "revoke"); } LWP_WaitProcess ((char *)arla_start); abort (); }
static void create_new_connections (unsigned n) { unsigned i; ConnCacheEntry *entries; entries = (ConnCacheEntry*)calloc (n, sizeof (ConnCacheEntry)); if (entries == NULL) arla_errx (1, ADEBERROR, "conncache: calloc failed"); for (i = 0; i < n; ++i) { entries[i].connection = NULL; entries[i].refcount = 0; entries[i].parent = NULL; entries[i].probe_le = NULL; listaddhead (connfreelist, &entries[i]); } nconnections += n; }
static ConnCacheEntry * new_connection (int32_t cell, uint32_t host, uint16_t port, uint16_t service, nnpfs_pag_t cred, int securityindex, int (*probe)(struct rx_connection *), struct rx_securityClass *securityobject) { ConnCacheEntry *e; assert (probe != NULL); e = get_free_connection (); e->cell = cell; e->host = host; e->port = port; e->service = service; e->flags.alivep = TRUE; e->flags.old = FALSE; e->refcount = 0; e->cred = cred; e->securityindex = securityindex; e->probe = probe; e->connection = rx_NewConnection (host, htons (port), service, securityobject, securityindex); if (e->connection == NULL) arla_errx (1, ADEBERROR, "rx_NewConnection failed"); return e; }
static ConnCacheEntry * get_free_connection (void) { ConnCacheEntry *e; e = (ConnCacheEntry *)listdelhead (connfreelist); if (e != NULL) return e; hashtabforeach (connhtab, clear_conn, NULL); e = (ConnCacheEntry *)listdelhead (connfreelist); if (e != NULL) return e; create_new_connections (CONNFREELISTINC); e = (ConnCacheEntry *)listdelhead (connfreelist); if (e != NULL) return e; arla_errx (1, ADEBERROR, "conncache: there was no way of getting a connection"); }