On Sat, Apr 26, 2025 at 12:31:58PM +0200, Willy Tarreau wrote:
> Hi Thomas,
> 
> On Wed, Apr 23, 2025 at 05:01:35PM +0200, Thomas Weißschuh wrote:
> > --- /dev/null
> > +++ b/tools/include/nolibc/sys/random.h
> > @@ -0,0 +1,32 @@
> > +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
> > +/*
> > + * random definitions for NOLIBC
> > + * Copyright (C) 2025 Thomas Weißschuh <thomas.weisssc...@linutronix.de>
> > + */
> > +
> 
> Note: don't forget to add your nolibc include here from the other series.

Ack. This series was sent before I got the idea about moving "#include 
nolibc.h".
I'll fix it up for v2.

> > +#ifndef _NOLIBC_SYS_RANDOM_H
> > +#define _NOLIBC_SYS_RANDOM_H
> > +
> > +#include "../arch.h"
> > +#include "../sys.h"
> (...)
> 
> > diff --git a/tools/testing/selftests/nolibc/nolibc-test.c 
> > b/tools/testing/selftests/nolibc/nolibc-test.c
> > index 
> > abe0ae794208762f6d91ad81e902fbf77253a1c1..95d08e9ccf5b3be924548100e9621cd47f39e8c2
> >  100644
> > --- a/tools/testing/selftests/nolibc/nolibc-test.c
> > +++ b/tools/testing/selftests/nolibc/nolibc-test.c
> (...)
> > +int test_getrandom(void)
> > +{
> > +   uint64_t rng = 0;
> > +   ssize_t ret;
> > +
> > +   ret = getrandom(&rng, sizeof(rng), 0);
> > +   if (ret != sizeof(rng))
> > +           return ret;
> > +
> > +   if (!rng) {
> > +           errno = EINVAL;
> > +           return -1;
> > +   }
> > +
> > +   return 0;
> > +}
> > +
> 
> Just a thought about this one: in a not-so-distant past, getrandom()
> could hang forever when lacking entropy (classical problem when booting
> a headless machine having no RNG), and since a recent kernel it turned
> to "only" multiple seconds. I'm not seeing any easy solution to this,
> but we need to keep an eye on this one, and in case of bad reports,
> maybe have this test as an opt-in or something like this. Anyway the
> best way to know is to have it right now and wait for reports to
> arrive.

What about using GRND_NONBLOCK and mark the test as skipped if no entropy is
available?

Reply via email to