Skip to content

Commit 9bf2bd2

Browse files
committed
refactor sdbd: replease random read path with getrandom
Signed-off-by: John Sanpe <[email protected]>
1 parent b67151b commit 9bf2bd2

File tree

1 file changed

+2
-23
lines changed

1 file changed

+2
-23
lines changed

sdbd.c

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <sys/eventfd.h>
2525
#include <sys/signalfd.h>
2626
#include <sys/stat.h>
27+
#include <sys/random.h>
2728
#include <sys/socket.h>
2829
#include <sys/types.h>
2930
#include <inttypes.h>
@@ -550,28 +551,6 @@ kexpectedpad_sha256_rsa2048[BFDEV_SHA256_DIGEST_SIZE] = {
550551
static int
551552
service_sync_write(struct sdbd_service *service, void *data, size_t length);
552553

553-
static ssize_t
554-
path_read(const char *path, char *buff, size_t size)
555-
{
556-
ssize_t length;
557-
int fd;
558-
559-
fd = open(path, O_RDONLY);
560-
if (bfdev_unlikely(fd < 0)) {
561-
bfdev_log_err("path read: failed to open file");
562-
return -BFDEV_EACCES;
563-
}
564-
565-
length = read(fd, buff, size);
566-
if (bfdev_unlikely(length <= 0)) {
567-
bfdev_log_err("path read: failed to open file");
568-
return -BFDEV_EFAULT;
569-
}
570-
571-
close(fd);
572-
return length;
573-
}
574-
575554
static int
576555
sdbd_read(int fd, void *data, size_t size)
577556
{
@@ -3374,7 +3353,7 @@ sdbd(void)
33743353
}
33753354
}
33763355

3377-
retval = path_read("/dev/random", (void *)&seed, sizeof(seed));
3356+
retval = getrandom(&seed, sizeof(seed), GRND_RANDOM);
33783357
if (retval != sizeof(seed)) {
33793358
bfdev_log_err("failed to read seed\n");
33803359
goto error;

0 commit comments

Comments
 (0)