Skip to content

Commit

Permalink
Fix rasperry pi hwGetentropy() (#856)
Browse files Browse the repository at this point in the history
  • Loading branch information
d00616 authored and marceloaqno committed May 23, 2017
1 parent 97ed21e commit aeceb0b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions hal/architecture/MyHwLinuxGeneric.cpp
Expand Up @@ -20,7 +20,6 @@
#include "MyHwLinuxGeneric.h"

#include <errno.h>
#include <linux/random.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
Expand All @@ -31,6 +30,7 @@
#include "log.h"

static SoftEeprom eeprom = SoftEeprom(MY_LINUX_CONFIG_FILE, 1024); // ATMega328 has 1024 bytes
static FILE *randomFp;

bool hwInit(void)
{
Expand All @@ -43,6 +43,10 @@ bool hwInit(void)
}
#endif
#endif
if (!(randomFp = fopen("/dev/urandom", "r"))) {
logError("Cannot open '/dev/urandom'.\n");
exit(2);
}
return true;
}

Expand Down Expand Up @@ -75,8 +79,7 @@ void hwRandomNumberInit()

ssize_t hwGetentropy(void *__buffer, size_t __length)
{
// getrandom syscall
return syscall(SYS_getrandom, __buffer, __length, GRND_NONBLOCK);
return(fread(__buffer, 1, __length, randomFp));
}

unsigned long hwMillis()
Expand Down

1 comment on commit aeceb0b

@micropet
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hallo,

Code compiled on an RPI but does not run:

May 23 23:03:45 pi143 systemd[1]: Started MySensors Gateway daemon.
May 23 23:03:45 pi143 systemd[1]: mysgw.service: main process exited, code=killed, status=11/SEGV
May 23 23:03:45 pi143 systemd[1]: Unit mysgw.service entered failed state.

Please sign in to comment.