impl-core: handle getrandom errors

Handle getrandom errors and fall back to rand() if all fails.

See #583
This commit is contained in:
Wim Taymans 2021-01-22 16:37:37 +01:00
parent f464d8c596
commit 8f5231bd45

View file

@ -405,7 +405,15 @@ struct pw_impl_core *pw_context_create_core(struct pw_context *context,
this->info.user_name = pw_get_user_name();
this->info.host_name = pw_get_host_name();
this->info.version = pw_get_library_version();
getrandom(&this->info.cookie, sizeof(this->info.cookie), 0);
while (getrandom(&this->info.cookie, sizeof(this->info.cookie), 0) !=
sizeof(this->info.cookie)) {
if (errno == EINTR)
continue;
pw_log_warn(NAME" %p: cookie getrandom failed: %m", this);
this->info.cookie = rand();
break;
}
this->info.name = name;
spa_hook_list_init(&this->listener_list);