Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177792749
D61833.1795295761.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
D61833.1795295761.diff
View Options
diff --git a/sbin/zfsbootcfg/zfsbootcfg.c b/sbin/zfsbootcfg/zfsbootcfg.c
--- a/sbin/zfsbootcfg/zfsbootcfg.c
+++ b/sbin/zfsbootcfg/zfsbootcfg.c
@@ -1,6 +1,10 @@
/*-
* Copyright (c) 2016 Andriy Gapon <avg@FreeBSD.org>
* All rights reserved.
+ * Copyright (c) 2026 The FreeBSD Foundation
+ *
+ * Portions of this software were developed by Klara, Inc. under sponsorship
+ * from the FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -24,14 +28,15 @@
*/
#include <sys/types.h>
+#include <err.h>
#include <errno.h>
-#include <limits.h>
#include <inttypes.h>
+#include <kenv.h>
+#include <limits.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
-#include <stdbool.h>
#include <string.h>
-#include <kenv.h>
#include <unistd.h>
#include <libzfsbootenv.h>
@@ -175,6 +180,18 @@
return (rv);
}
+static void
+usage(void)
+{
+ fprintf(stderr, "%s\n%s\n%s\n%s\n",
+ "usage: zfsbootcfg [-z pool] [options]",
+ " zfsbootcfg [-z pool] [-n name] -k key [-t type] -v value "
+ "[-p]",
+ " zfsbootcfg [-z pool] [-n name] -d key [-p]",
+ " zfsbootcfg [-z pool] [-n name] -p");
+ exit(1);
+}
+
/*
* Usage: zfsbootcfg [-z pool] [-d key] [-k key -t type -v value] [-p]
* zfsbootcfg [-z pool] -n nvlist [-d key] [-k key -t type -v value] [-p]
@@ -220,6 +237,8 @@
case 'z':
name = optarg;
break;
+ default:
+ usage();
}
}
@@ -229,16 +248,17 @@
if (argc == 1)
value = argv[0];
- if (argc > 1) {
- fprintf(stderr, "usage: zfsbootcfg <boot.config(5) options>\n");
- return (1);
- }
+ if (argc > 1)
+ usage();
+
+ /* Setting a key needs something to set it to. */
+ if (key != NULL && !delete && value == NULL)
+ usage();
if (name == NULL) {
rv = kenv(KENV_GET, "vfs.root.mountfrom", buf, sizeof(buf));
if (rv <= 0) {
- perror("can't get vfs.root.mountfrom");
- return (1);
+ err(1, "can't get vfs.root.mountfrom");
}
if (strncmp(buf, "zfs:", 4) == 0) {
@@ -247,8 +267,7 @@
*name = '\0';
name = buf + 4;
} else {
- perror("not a zfs root");
- return (1);
+ err(1, "not a zfs root");
}
}
@@ -267,7 +286,7 @@
if (rv == 0)
printf("zfs bootenv is successfully written\n");
else
- printf("error: %d\n", rv);
+ warnx("error: %d\n", rv);
} else if (!print) {
char *ptr;
@@ -281,5 +300,5 @@
rv = lzbe_bootenv_print(name, nvlist, stdout);
}
- return (rv);
+ exit(rv != 0);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 21, 9:16 PM (23 h, 36 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41895616
Default Alt Text
D61833.1795295761.diff (2 KB)
Attached To
Mode
D61833: zfsbootcfg: don't crash on bad or incomplete options
Attached
Detach File
Event Timeline