static int get_manifest_channel_locked(struct NaClSrpcChannel **result) { int status; int manifest; int manifest_conn; if (manifest_channel_initialized) { *result = &manifest_channel; return 0; } *result = NULL; status = irt_nameservice_lookup("ManifestNameService", O_RDWR, &manifest); if (NACL_NAME_SERVICE_SUCCESS != status) { print_error("ManifestNameService lookup failed\n"); return EIO; } if (-1 == manifest) { print_error("Manifest descriptor is invalid\n"); return EIO; } manifest_conn = imc_connect(manifest); close(manifest); if (-1 == manifest_conn) { print_error("Can't connect to manifest service\n"); return EIO; } if (!NaClSrpcClientCtor(&manifest_channel, manifest_conn)) { print_error("Can't create manifest srpc channel\n"); return EIO; } *result = &manifest_channel; manifest_channel_initialized = 1; return 0; }
static int prepare_secure_random(void) { if (secure_random_fd == -1) { int fd; int status = irt_nameservice_lookup("SecureRandom", O_RDONLY, &fd); if (status != NACL_NAME_SERVICE_SUCCESS) { return EIO; } if (!__sync_bool_compare_and_swap(&secure_random_fd, -1, fd)) { /* * We raced with another thread. It already installed an fd. */ NACL_SYSCALL(close)(fd); } } return 0; }