[git commit] seedrng: code shrink
Denys Vlasenko
vda.linux at googlemail.com
Sat Apr 30 23:58:57 UTC 2022
commit: https://git.busybox.net/busybox/commit/?id=fb4546c7af3d1d2f11fb7851b56104f5580f328f
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master
function old new delta
seedrng_main 994 982 -12
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
util-linux/seedrng.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/util-linux/seedrng.c b/util-linux/seedrng.c
index c07bf84f7..3074e9a58 100644
--- a/util-linux/seedrng.c
+++ b/util-linux/seedrng.c
@@ -164,25 +164,27 @@ int seedrng_main(int argc UNUSED_PARAM, char *argv[])
{
const char *seed_dir;
int fd, dfd;
+ int i;
+ unsigned opts;
uint8_t new_seed[MAX_SEED_LEN];
size_t new_seed_len;
- bool new_seed_creditable, skip_credit;
+ bool new_seed_creditable;
struct timespec timestamp;
sha256_ctx_t hash;
enum {
- OPT_d = (1 << 0),
- OPT_n = (1 << 1)
+ OPT_n = (1 << 0), /* must be 1 */
+ OPT_d = (1 << 1),
};
#if ENABLE_LONG_OPTS
static const char longopts[] ALIGN1 =
- "seed-dir\0" Required_argument "d"
"skip-credit\0" No_argument "n"
+ "seed-dir\0" Required_argument "d"
;
#endif
seed_dir = DEFAULT_SEED_DIR;
- skip_credit = getopt32long(argv, "d:n", longopts, &seed_dir) & OPT_n;
+ opts = getopt32long(argv, "nd:", longopts, &seed_dir);
umask(0077);
if (getuid() != 0)
bb_simple_error_msg_and_die(bb_msg_you_must_be_root);
@@ -209,10 +211,10 @@ int seedrng_main(int argc UNUSED_PARAM, char *argv[])
clock_gettime(CLOCK_BOOTTIME, ×tamp);
sha256_hash(&hash, ×tamp, sizeof(timestamp));
- for (int i = 1; i < 3; ++i) {
- seed_from_file_if_exists(i == 1 ? NON_CREDITABLE_SEED_NAME : CREDITABLE_SEED_NAME,
+ for (i = 0; i <= 1; i++) {
+ seed_from_file_if_exists(i == 0 ? NON_CREDITABLE_SEED_NAME : CREDITABLE_SEED_NAME,
dfd,
- /* credit? */ i == 1 ? false : !skip_credit,
+ /* credit? */ (opts ^ OPT_n) & i, /* 0, then 1 unless -n */
&hash);
}
More information about the busybox-cvs
mailing list