aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/zgenhostid
diff options
context:
space:
mode:
authorнаб <[email protected]>2021-05-16 14:26:42 +0200
committerBrian Behlendorf <[email protected]>2021-05-20 08:55:31 -0700
commit359b6cca0f858808790023c5c5a562dcd92cbf43 (patch)
tree3d776c9fd21af4e48642b9ceeec0fbbbc8068124 /cmd/zgenhostid
parent6fc3099248f04591d7d7bf05078482f794b38eaa (diff)
zgenhostid: use argument path directly
Reviewed-by: John Kennedy <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes #12042
Diffstat (limited to 'cmd/zgenhostid')
-rw-r--r--cmd/zgenhostid/zgenhostid.c16
1 files changed, 3 insertions, 13 deletions
diff --git a/cmd/zgenhostid/zgenhostid.c b/cmd/zgenhostid/zgenhostid.c
index 5a9bdad7c..4a4ca80e0 100644
--- a/cmd/zgenhostid/zgenhostid.c
+++ b/cmd/zgenhostid/zgenhostid.c
@@ -36,8 +36,6 @@
#include <time.h>
#include <unistd.h>
-static void usage(void);
-
static void
usage(void)
{
@@ -60,12 +58,11 @@ int
main(int argc, char **argv)
{
/* default file path, can be optionally set by user */
- char path[PATH_MAX] = "/etc/hostid";
+ const char *path = "/etc/hostid";
/* holds converted user input or lrand48() generated value */
unsigned long input_i = 0;
int opt;
- int pathlen;
int force_fwrite = 0;
while ((opt = getopt_long(argc, argv, "fo:h?", 0, 0)) != -1) {
switch (opt) {
@@ -73,14 +70,7 @@ main(int argc, char **argv)
force_fwrite = 1;
break;
case 'o':
- pathlen = snprintf(path, sizeof (path), "%s", optarg);
- if (pathlen >= sizeof (path)) {
- fprintf(stderr, "%s\n", strerror(EOVERFLOW));
- exit(EXIT_FAILURE);
- } else if (pathlen < 1) {
- fprintf(stderr, "%s\n", strerror(EINVAL));
- exit(EXIT_FAILURE);
- }
+ path = optarg;
break;
case 'h':
case '?':
@@ -118,7 +108,7 @@ main(int argc, char **argv)
if (force_fwrite == 0 && stat(path, &fstat) == 0 &&
S_ISREG(fstat.st_mode)) {
fprintf(stderr, "%s: %s\n", path, strerror(EEXIST));
- exit(EXIT_FAILURE);
+ exit(EXIT_FAILURE);
}
/*