aboutsummaryrefslogtreecommitdiff
path: root/linux-user
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2019-03-13 13:53:22 -0700
committerRichard Henderson <richard.henderson@linaro.org>2019-05-22 12:38:54 -0400
commita573e9bac6f28cfaa93629b0ebaaa20594365b1d (patch)
treedb5cdc2155fd3513854bba5d49d3925b331438bf /linux-user
parent5ebdd774949d68e2526000b0655636d056595be9 (diff)
linux-user: Call qcrypto_init if not using -seed
When not using -seed, we will use the crypto subsystem for random numbers. Reviewed-by: Laurent Vivier <lvivier@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'linux-user')
-rw-r--r--linux-user/main.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/linux-user/main.c b/linux-user/main.c
index 7e704845c0..66c909a1a6 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -39,6 +39,7 @@
#include "trace/control.h"
#include "target_elf.h"
#include "cpu_loop-common.h"
+#include "crypto/init.h"
char *exec_path;
@@ -688,17 +689,26 @@ int main(int argc, char **argv, char **envp)
if (seed_optarg == NULL) {
seed_optarg = getenv("QEMU_RAND_SEED");
}
- if (seed_optarg != NULL) {
- unsigned long long seed;
+ {
+ Error *err = NULL;
+ if (seed_optarg != NULL) {
+ unsigned long long seed;
+
+ /* This will go away with the last user of rand(). */
+ if (parse_uint_full(seed_optarg, &seed, 0) != 0) {
+ fprintf(stderr, "Invalid seed number: %s\n", seed_optarg);
+ exit(EXIT_FAILURE);
+ }
+ srand(seed);
- /* This will go away with the last user of rand(). */
- if (parse_uint_full(seed_optarg, &seed, 0) != 0) {
- fprintf(stderr, "Invalid seed number: %s\n", seed_optarg);
- exit(EXIT_FAILURE);
+ qemu_guest_random_seed_main(seed_optarg, &err);
+ } else {
+ qcrypto_init(&err);
+ }
+ if (err) {
+ error_reportf_err(err, "cannot initialize crypto: ");
+ exit(1);
}
- srand(seed);
-
- qemu_guest_random_seed_main(seed_optarg, &error_fatal);
}
target_environ = envlist_to_environ(envlist, NULL);