simple-init

A set of init binaries for linux
git clone git://depsterr.com/git/simple-init
Log | Files | Refs | README | LICENSE

commit 67a14bc30fd6746d589f6e619cc11006bab6b57f
parent 7f99c5d6b89b4edf6f3025b50dbb5b4cc52ae094
Author: depsterr <depsterr@protonmail.com>
Date:   Sun, 31 May 2020 13:06:42 +0200

added random seeding to util.c

Diffstat:
Minitscripts/util.c | 38++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+), 0 deletions(-)

diff --git a/initscripts/util.c b/initscripts/util.c @@ -1,4 +1,5 @@ #include <sys/types.h> +#include <sys/stat.h> #include <unistd.h> #include <stdlib.h> @@ -54,7 +55,44 @@ void mount(char* options, char* type, char* device, char* mountpoint) { } void save_random_seed() { + if (access("/var/init", F_OK) == -1) { + mkdir("/var/init", 0755); + } + + int fdesc = open("/dev/urandom", O_RDONLY); + char random_buffer[512]; + + if (fdesc < 0) + return; + else if (read(fdesc, random_buffer, sizeof(random_buffer) < 0) + return; + + + fdesc = open("/var/init/random-seed", O_CREAT|O_WRONLY); + + if (fdesc < 0) + return; + else + write(fdesc, random_buffer, sizeof(random_buffer)); } void load_random_seed() { + if (access("/var/init/random-seed", F_OK) == -1) { + return; + } + + int fdesc = open("/var/init/random-seed", O_RDONLY); + char random_buffer[512]; + + if (fdesc < 0) + return; + else if (read(fdesc, random_buffer, sizeof(random_buffer) < 0) + return; + + fdesc = open("/dev/urandom", O_WRONLY); + + if (fdesc < 0) + return; + else + write(fdesc, random_buffer, sizeof(random_buffer)); }