From e167949db200b1e210b0ef8d3b70fd0a47aa3330 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 19 May 2021 11:05:58 -0400 Subject: [PATCH] Fix comments and improve randomness Since the granularity on time could cause a boot to select the same 'random' entry, use better seed for rand() --- misc/urlmount.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/misc/urlmount.c b/misc/urlmount.c index 80293dbf..174d1d85 100644 --- a/misc/urlmount.c +++ b/misc/urlmount.c @@ -1,3 +1,4 @@ +/* # vim: tabstop=4 shiftwidth=4 softtabstop=4 # Copyright 2021 Lenovo @@ -13,6 +14,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +*/ #define FUSE_USE_VERSION 26 #include @@ -166,8 +168,16 @@ static const struct fuse_operations http_ops = { int main(int argc, char* argv[]) { char *tmp; double fsize; - int i, j; - srand(time(NULL)); + unsigned int i; + int j; + j = open("/dev/urandom", O_RDONLY); + if (j <= 0 || read(j, (char*)&i, 4) < 0) { + i = time(NULL); + } + if (j > 0) { + close(j); + } + srand(i); j = 0; memset(urls, 0, 32*sizeof(char*)); urlidx = 0;