diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2022-04-30 15:45:53 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2022-04-30 15:45:53 +0200 |
commit | d49da38aa38a3d9a28447fc725b3d43a3fabc7b4 (patch) | |
tree | 84f91aa65154111d90c72ee7b24da870133e78ad | |
parent | 2cbfd01c150420199a9cb74f5de72d7279e6cd11 (diff) | |
download | busybox-w32-d49da38aa38a3d9a28447fc725b3d43a3fabc7b4.tar.gz busybox-w32-d49da38aa38a3d9a28447fc725b3d43a3fabc7b4.tar.bz2 busybox-w32-d49da38aa38a3d9a28447fc725b3d43a3fabc7b4.zip |
seedrng: use more xfuncs where appropriate
function old new delta
.rodata 104929 104898 -31
seedrng_main 1050 1011 -39
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | util-linux/seedrng.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/util-linux/seedrng.c b/util-linux/seedrng.c index 023ed8688..978860bbd 100644 --- a/util-linux/seedrng.c +++ b/util-linux/seedrng.c | |||
@@ -143,7 +143,8 @@ static void seed_from_file_if_exists(const char *filename, bool credit, sha256_c | |||
143 | if (seed_len != 0) { | 143 | if (seed_len != 0) { |
144 | sha256_hash(hash, &seed_len, sizeof(seed_len)); | 144 | sha256_hash(hash, &seed_len, sizeof(seed_len)); |
145 | sha256_hash(hash, seed, seed_len); | 145 | sha256_hash(hash, seed, seed_len); |
146 | printf("Seeding %u bits %s crediting\n", (unsigned)seed_len * 8, credit ? "and" : "without"); | 146 | printf("Seeding %u bits %s crediting\n", |
147 | (unsigned)seed_len * 8, credit ? "and" : "without"); | ||
147 | seed_rng(seed, seed_len, credit); | 148 | seed_rng(seed, seed_len, credit); |
148 | } | 149 | } |
149 | } | 150 | } |
@@ -152,7 +153,7 @@ int seedrng_main(int argc, char *argv[]) MAIN_EXTERNALLY_VISIBLE; | |||
152 | int seedrng_main(int argc UNUSED_PARAM, char *argv[]) | 153 | int seedrng_main(int argc UNUSED_PARAM, char *argv[]) |
153 | { | 154 | { |
154 | const char *seed_dir; | 155 | const char *seed_dir; |
155 | int fd, dfd, program_ret = 0; | 156 | int fd, dfd; |
156 | uint8_t new_seed[MAX_SEED_LEN]; | 157 | uint8_t new_seed[MAX_SEED_LEN]; |
157 | size_t new_seed_len; | 158 | size_t new_seed_len; |
158 | bool new_seed_creditable, skip_credit = false; | 159 | bool new_seed_creditable, skip_credit = false; |
@@ -178,8 +179,8 @@ int seedrng_main(int argc UNUSED_PARAM, char *argv[]) | |||
178 | 179 | ||
179 | if (mkdir(seed_dir, 0700) < 0 && errno != EEXIST) | 180 | if (mkdir(seed_dir, 0700) < 0 && errno != EEXIST) |
180 | bb_perror_msg_and_die("can't %s seed directory", "create"); | 181 | bb_perror_msg_and_die("can't %s seed directory", "create"); |
181 | dfd = open(seed_dir, O_DIRECTORY | O_RDONLY); | 182 | dfd = xopen(seed_dir, O_DIRECTORY | O_RDONLY); |
182 | if (dfd < 0 || flock(dfd, LOCK_EX) < 0) | 183 | if (flock(dfd, LOCK_EX) < 0) |
183 | bb_perror_msg_and_die("can't %s seed directory", "lock"); | 184 | bb_perror_msg_and_die("can't %s seed directory", "lock"); |
184 | xfchdir(dfd); | 185 | xfchdir(dfd); |
185 | 186 | ||
@@ -204,14 +205,13 @@ int seedrng_main(int argc UNUSED_PARAM, char *argv[]) | |||
204 | 205 | ||
205 | printf("Saving %u bits of %screditable seed for next boot\n", | 206 | printf("Saving %u bits of %screditable seed for next boot\n", |
206 | (unsigned)new_seed_len * 8, new_seed_creditable ? "" : "non-"); | 207 | (unsigned)new_seed_len * 8, new_seed_creditable ? "" : "non-"); |
207 | fd = open(NON_CREDITABLE_SEED_NAME, O_WRONLY | O_CREAT | O_TRUNC, 0400); | 208 | fd = xopen3(NON_CREDITABLE_SEED_NAME, O_WRONLY | O_CREAT | O_TRUNC, 0400); |
208 | if (fd < 0 || full_write(fd, new_seed, new_seed_len) != (ssize_t)new_seed_len || fsync(fd) < 0) { | 209 | xwrite(fd, new_seed, new_seed_len); |
210 | if (fsync(fd) < 0) { | ||
209 | bb_perror_msg("can't%s seed", " write"); | 211 | bb_perror_msg("can't%s seed", " write"); |
210 | return program_ret | (1 << 4); | 212 | return (1 << 4); |
211 | } | 213 | } |
212 | if (new_seed_creditable && rename(NON_CREDITABLE_SEED_NAME, CREDITABLE_SEED_NAME) < 0) { | 214 | if (new_seed_creditable) |
213 | bb_simple_perror_msg("can't make new seed creditable"); | 215 | xrename(NON_CREDITABLE_SEED_NAME, CREDITABLE_SEED_NAME); |
214 | return program_ret | (1 << 5); | 216 | return EXIT_SUCCESS; |
215 | } | ||
216 | return program_ret; | ||
217 | } | 217 | } |