diff options
author | Douglas Gilbert <dgilbert@interlog.com> | 2021-03-28 00:58:36 +0000 |
---|---|---|
committer | Douglas Gilbert <dgilbert@interlog.com> | 2021-03-28 00:58:36 +0000 |
commit | 9ccb556a21f1aa2c8d08052622aa4471b7acd6a3 (patch) | |
tree | 47fbc1779312c01ed306b1685e3f4494abc0ee44 /src | |
parent | 865ab8e10f0e1dfadc31bd27e51d4fdac1075293 (diff) | |
download | sg3_utils-9ccb556a21f1aa2c8d08052622aa4471b7acd6a3.tar.gz |
sg_dd: setup conditional auto rule for getrandom()
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@883 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'src')
-rw-r--r-- | src/sg_dd.c | 23 | ||||
-rw-r--r-- | src/sg_inq.c | 4 | ||||
-rw-r--r-- | src/sg_vpd.c | 4 |
3 files changed, 21 insertions, 10 deletions
diff --git a/src/sg_dd.c b/src/sg_dd.c index 7d9b0edf..be90b7a0 100644 --- a/src/sg_dd.c +++ b/src/sg_dd.c @@ -42,6 +42,7 @@ #include <signal.h> #include <ctype.h> #include <errno.h> +#include <time.h> #include <limits.h> #define __STDC_FORMAT_MACROS 1 #include <inttypes.h> @@ -50,7 +51,6 @@ #include <sys/time.h> #include <sys/file.h> #include <sys/sysmacros.h> -#include <sys/random.h> /* for getrandom() system call */ #ifndef major #include <sys/types.h> #endif @@ -60,6 +60,9 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif +#ifdef HAVE_GETRANDOM +#include <sys/random.h> /* for getrandom() system call */ +#endif #include "sg_lib.h" #include "sg_cmds_basic.h" #include "sg_cmds_extra.h" @@ -67,7 +70,7 @@ #include "sg_unaligned.h" #include "sg_pr2serr.h" -static const char * version_str = "6.24 20210321"; +static const char * version_str = "6.25 20210326"; #define ME "sg_dd: " @@ -2104,13 +2107,21 @@ main(int argc, char * argv[]) ccp = "<0xff bytes>"; cc2p = "ff"; } else if (iflag.random) { - ssize_t ssz; ccp = "<random>"; cc2p = "random"; - ssz = getrandom(&seed, sizeof(seed), GRND_NONBLOCK); - if (ssz < (ssize_t)sizeof(seed)) - pr2serr("getrandom() failed, ret=%d\n", (int)ssz); +#ifdef HAVE_GETRANDOM + { + ssize_t ssz = getrandom(&seed, sizeof(seed), GRND_NONBLOCK); + + if (ssz < (ssize_t)sizeof(seed)) { + pr2serr("getrandom() failed, ret=%d\n", (int)ssz); + seed = (long)time(NULL); + } + } +#else + seed = (long)time(NULL); /* use seconds since epoch as proxy */ +#endif if (verbose > 1) pr2serr("seed=%ld\n", seed); srand48_r(seed, &drand); diff --git a/src/sg_inq.c b/src/sg_inq.c index 546d2a65..60fcfa39 100644 --- a/src/sg_inq.c +++ b/src/sg_inq.c @@ -1,5 +1,5 @@ /* A utility program originally written for the Linux OS SCSI subsystem. - * Copyright (C) 2000-2020 D. Gilbert + * Copyright (C) 2000-2021 D. Gilbert * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) @@ -51,7 +51,7 @@ #include "sg_pt_nvme.h" #endif -static const char * version_str = "2.08 20201114"; /* spc6r02 + 20-0114r2 */ +static const char * version_str = "2.09 20210226"; /* spc6r05 */ /* INQUIRY notes: * It is recommended that the initial allocation length given to a diff --git a/src/sg_vpd.c b/src/sg_vpd.c index 69919dec..2d699c30 100644 --- a/src/sg_vpd.c +++ b/src/sg_vpd.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2020 Douglas Gilbert. + * Copyright (c) 2006-2021 Douglas Gilbert. * All rights reserved. * Use of this source code is governed by a BSD-style * license that can be found in the BSD_LICENSE file. @@ -40,7 +40,7 @@ */ -static const char * version_str = "1.61 20201114"; /* spc6r02 + sbc4r22 */ +static const char * version_str = "1.62 20210326"; /* spc6r05 + sbc4r22 */ /* standard VPD pages, in ascending page number order */ #define VPD_SUPPORTED_VPDS 0x0 |