[lkml]   [2005]   [Jan]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    Subjectshort read from /dev/urandom
    The /dev/urandom device is advertised as always returning the requested 
    number of bytes. Yet, it fails to do this under some situations.
    Compile this

    int main (void)
    alarm (100);
    char buf[32];
    int fd = open ("/dev/urandom", 0);
    while (1)
    if (read (fd, buf, sizeof buf) != sizeof (buf))
    abort ();


    gcc -o r r.c -g -O2 -pg

    Note the -pg at the end to enable profiling. Running this code fails
    for me after less than a second.

    The relevant code in the kernel is this

    while (nbytes) {
    * Check if we need to break out or reschedule....
    if ((flags & EXTRACT_ENTROPY_USER) && need_resched()) {
    if (signal_pending(current)) {
    if (ret == 0)
    ret = -ERESTARTSYS;

    Here the loop is left prematurely if a signal is pending.

    One solution is to redefine the /dev/urandom interface. The problem is
    that this will cause program to fail. I know since I found this while
    debugging such a program.

    ➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
    [unhandled content-type:application/pgp-signature]
     \ /
      Last update: 2005-03-22 14:09    [W:0.022 / U:1.664 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site