diff --git a/src/shared/hostname-setup.c b/src/shared/hostname-setup.c index 4abf662002..efd3681747 100644 --- a/src/shared/hostname-setup.c +++ b/src/shared/hostname-setup.c @@ -3,7 +3,6 @@ #include #include #include -#include #include #include @@ -26,7 +25,6 @@ #include "proc-cmdline.h" #include "process-util.h" #include "siphash24.h" -#include "stat-util.h" #include "stdio-util.h" #include "string-table.h" #include "string-util.h" @@ -399,7 +397,6 @@ static int pick_word_linear_scan(const char *words, size_t size, size_t offset, int hostname_pick_word(sd_id128_t mid, size_t pos, char **ret) { static const sd_id128_t word_key = SD_ID128_MAKE(2d,9f,1c,7a,4b,8e,43,11,9a,6d,5f,02,c8,77,e3,14); _cleanup_fclose_ FILE *f = NULL; - struct stat st; int r; assert(pos >= 1); @@ -413,15 +410,10 @@ int hostname_pick_word(sd_id128_t mid, size_t pos, char **ret) { if (r < 0) return r; - if (fstat(fileno(f), &st) < 0) - return -errno; - r = stat_verify_regular(&st); - if (r < 0) - return r; - _cleanup_free_ char *words = NULL; size_t size; - r = read_full_stream(f, &words, &size); + r = read_full_stream_full(f, /* filename= */ NULL, /* offset= */ UINT64_MAX, /* size= */ SIZE_MAX, + READ_FULL_FILE_VERIFY_REGULAR, &words, &size); if (r < 0) return r; if (size == 0) diff --git a/src/test/meson.build b/src/test/meson.build index ebdd46788a..81ff491b50 100644 --- a/src/test/meson.build +++ b/src/test/meson.build @@ -400,7 +400,7 @@ executables += [ 'timeout' : 180, }, test_template + { - 'sources': files('test-hostname-pick-word.c'), + 'sources' : files('test-hostname-pick-word.c'), 'type' : 'manual', }, test_template + { diff --git a/src/test/test-hostname-pick-word.c b/src/test/test-hostname-pick-word.c index 3021c6e6ef..5093c0267d 100644 --- a/src/test/test-hostname-pick-word.c +++ b/src/test/test-hostname-pick-word.c @@ -12,20 +12,20 @@ static int run(int argc, char **argv) { int r; - log_parse_environment(); + log_setup(); unsigned c = 100, pos = 1; if (argc > 1) { - r = safe_atou(argv[1], &pos); + r = safe_atou_bounded(argv[1], /* min= */ 1, /* max= */ UINT_MAX, &pos); if (r < 0) - return log_error_errno(r, "Cannot parse uint %s: %m", argv[1]); + return log_error_errno(r, "Cannot parse uint '%s': %m", argv[1]); } if (argc > 2) { - r = safe_atou(argv[2], &c); + r = safe_atou_bounded(argv[2], /* min= */ 1, /* max= */ UINT_MAX, &c); if (r < 0) - return log_error_errno(r, "Cannot parse uint %s: %m", argv[2]); + return log_error_errno(r, "Cannot parse uint '%s': %m", argv[2]); } sd_id128_t mid = SD_ID128_ARRAY(aa,bb,cc,ee,33,21,42,31,89,ba,a4,91,33,22,11,00);