Several follow-ups for wildcard hostname (#43628)
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
#include <fcntl.h>
|
||||
#include <sched.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 + {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user