static int wait_random_seeded(void)
{
    static int seeded = OPENSSL_RAND_SEED_DEVRANDOM_SHM_ID < 0;
    static const int kernel_version[] = { DEVRANDOM_SAFE_KERNEL };
    int kernel[2];
    int shm_id, fd, r;
    char c, *p;
    struct utsname un;
    fd_set fds;

    if (!seeded) {
        /* See if anthing has created the global seeded indication */
        if ((shm_id = shmget(OPENSSL_RAND_SEED_DEVRANDOM_SHM_ID, 1, 0)) == -1) {
            /*
             * Check the kernel's version and fail if it is too recent.
             *
             * Linux kernels from 4.8 onwards do not guarantee that
             * /dev/urandom is properly seeded when /dev/random becomes
             * readable.  However, such kernels support the getentropy(2)
             * system call and this should always succeed which renders
             * this alternative but essentially identical source moot.
             */
            if (uname(&un) == 0) {
                kernel[0] = atoi(un.release);
                p = strchr(un.release, '.');
                kernel[1] = p == NULL ? 0 : atoi(p + 1);
                if (kernel[0] > kernel_version[0]
                    || (kernel[0] == kernel_version[0]
                        && kernel[1] >= kernel_version[1])) {
                    return 0;
                }
            }
            /* Open /dev/random and wait for it to be readable */
            if ((fd = open(DEVRANDOM_WAIT, O_RDONLY)) != -1) {
                if (DEVRANDM_WAIT_USE_SELECT && fd < FD_SETSIZE) {
                    FD_ZERO(&fds);
                    FD_SET(fd, &fds);
                    while ((r = select(fd + 1, &fds, NULL, NULL, NULL)) < 0
                           && errno == EINTR);
                } else {
                    while ((r = read(fd, &c, 1)) < 0 && errno == EINTR);
                }
                close(fd);
                if (r == 1) {
                    seeded = 1;
                    /* Craete the shared memory indicator */
                    shm_id = shmget(OPENSSL_RAND_SEED_DEVRANDOM_SHM_ID, 1,
                                    IPC_CREAT | S_IRUSR | S_IRGRP | S_IROTH);
                }
            }
        }
        if (shm_id != -1) {
            seeded = 1;
            /*
             * Map the shared memory to prevent its premature destruction.
             * If this call fails, it isn't a big problem.
             */
            shm_addr = shmat(shm_id, NULL, SHM_RDONLY);
#    ifndef FIPS_MODE
            /* TODO 3.0: The FIPS provider doesn't have OPENSSL_atexit */
            if (shm_addr != (void *)-1)
                OPENSSL_atexit(&cleanup_shm);
#    endif
        }
    }
    return seeded;
}