Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.busybox.net/busybox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2022-05-01 02:58:57 +0300
committerDenys Vlasenko <vda.linux@googlemail.com>2022-05-01 02:58:57 +0300
commitfb4546c7af3d1d2f11fb7851b56104f5580f328f (patch)
tree7e8491e1354f00dee8bb3a19b153d2adfa66d295 /util-linux
parentd5bd2e57a7be6c34393c52aa5e7ac2a8937da8d3 (diff)
seedrng: code shrink
function old new delta seedrng_main 994 982 -12 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux')
-rw-r--r--util-linux/seedrng.c18
1 files 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, &timestamp);
sha256_hash(&hash, &timestamp, 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);
}