aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorÉrico Rolim <[email protected]>2020-11-10 11:22:27 -0300
committerBrian Behlendorf <[email protected]>2020-11-17 12:19:33 -0800
commitc4a5e3b90fc98890e58cd93c0eea1b27484648d1 (patch)
treeedff7ef159b0a1beb3d861797332d63dce6b75ac /cmd
parentd02fc15ba1739903afe273c4c1ce064954050652 (diff)
zgenhostid: accept hostid arguments equal to zero.
A common usage pattern for zgenhostid, including in the ZFS dracut module, is running it as: zgenhostid $(hostid) However, zgenhostid only accepted hostid arguments greater than 0, which meant that, when the output of hostid(1) was "00000000", zgenhostid would error out, even though 0 is a possible return value for the gethostid(3) function used by hostid(1): - On current musl libc, gethostid(3) is a stub that always returns 0. - On glibc, gethostid(3) will return 0 if /etc/hostid exists but is smaller than 4 bytes. In these cases, it makes more sense for zgenhostid to treat a value of 0 as other parts of the zfs codebase do, meaning that a hostid value couldn't be determined; therefore, it should attempt to generate a random value to write into /etc/hostid. The manpage and usage output have been updated to reflect this. Whitespace has also been fixed in the usage output. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Georgy Yakovlev <[email protected]> Reviewed-by: Andrew J. Hesford <[email protected]> Signed-off-by: Érico Rolim <[email protected]> Closes #11174 Closes #11189
Diffstat (limited to 'cmd')
-rw-r--r--cmd/zgenhostid/zgenhostid.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/cmd/zgenhostid/zgenhostid.c b/cmd/zgenhostid/zgenhostid.c
index 562262928..50fcf05e4 100644
--- a/cmd/zgenhostid/zgenhostid.c
+++ b/cmd/zgenhostid/zgenhostid.c
@@ -47,10 +47,10 @@ usage(void)
" -h\t\t print this usage and exit\n"
" -o <filename>\t write hostid to this file\n\n"
"If hostid file is not present, store a hostid in it.\n"
- "The optional value must be an 8-digit hex number between"
- "1 and 2^32-1.\n"
- "If no value is provided, a random one will"
- "be generated.\n"
+ "The optional value should be an 8-digit hex number between"
+ " 1 and 2^32-1.\n"
+ "If the value is 0 or no value is provided, a random one"
+ " will be generated.\n"
"The value must be unique among your systems.\n");
exit(EXIT_FAILURE);
/* NOTREACHED */
@@ -108,7 +108,7 @@ main(int argc, char **argv)
exit(EXIT_FAILURE);
}
- if (input_i < 0x1 || input_i > UINT32_MAX) {
+ if (input_i > UINT32_MAX) {
fprintf(stderr, "%s\n", strerror(ERANGE));
usage();
}