Page MenuHomeFreeBSD

D60125.1794937299.diff
No OneTemporary

Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None

D60125.1794937299.diff

diff --git a/usr.sbin/bhyve/bhyve.8 b/usr.sbin/bhyve/bhyve.8
--- a/usr.sbin/bhyve/bhyve.8
+++ b/usr.sbin/bhyve/bhyve.8
@@ -244,11 +244,19 @@
directive.
.Pp
Other than that, each line of the config file is expected to consist of a
-config variable name, an equals sign
-.Pq Sq = ,
-and a value.
-No spaces are permitted between the variable name, equals sign, or
+config variable name, an assignment operator, and a value.
+No spaces are permitted between the variable name, assignment operator, or
value.
+Valid assignment operators are:
+.Bl -tag -width 5n
+.It Sq =
+Assigns a value to a variable.
+If the variable already has a value it will be overwritten by the newly
+assigned value.
+.It Sq +=
+Assigns a value to a variable if it has no value, or appends it to the existing
+value separated by a comma.
+.El
.Pp
See
.Xr bhyve_config 5
diff --git a/usr.sbin/bhyve/bhyve_config.5 b/usr.sbin/bhyve/bhyve_config.5
--- a/usr.sbin/bhyve/bhyve_config.5
+++ b/usr.sbin/bhyve/bhyve_config.5
@@ -52,6 +52,24 @@
The path to the configuration file to be included may be absolute, or relative
to the directory of the configuration file currently being processed.
.Pp
+The values assigned to nodes are represented internally as strings and include
+all whitespace, quotation marks, and other special characters specified between
+the assignment operator and the next newline.
+.Pp
+Assignment takes one of the following forms:
+.Bl -column "Operator" "config.node+=value" "Description"
+.It Sy Operator Ta Sy Example Ta Sy Description
+.It Vt = Ta Va config.node Ns Vt = Ns Va value Ta
+The value is assigned to the specified node.
+If the node already has a value assigned, the new value overwrites the existing
+value.
+.It Vt += Ta Va config.node Ns Vt += Ns Va value Ta
+The value is assigned to the specified node.
+If the node already has a value assigned, the new value is appended to the
+existing value separated by a comma, allowing the incremental construction of
+comma-separated lists.
+.El
+.Pp
The remainder of this manual describes the configuration variables understood by
.Xr bhyve 8 .
If additional variables are defined,
diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c
--- a/usr.sbin/bhyve/bhyverun.c
+++ b/usr.sbin/bhyve/bhyverun.c
@@ -846,16 +846,26 @@
bool
bhyve_parse_config_option(const char *option)
{
+ bool append = false;
const char *value;
char *path;
value = strchr(option, '=');
- if (value == NULL || value[1] == '\0')
+ if (value == NULL || value[1] == '\0' || value == option)
return (false);
- path = strndup(option, value - option);
+
+ if (value[-1] == '+')
+ append = true;
+
+ path = strndup(option, value - option - (append ? 1 : 0));
if (path == NULL)
err(4, "Failed to allocate memory");
- set_config_value(path, value + 1);
+
+ if (append)
+ append_config_value(path, value + 1);
+ else
+ set_config_value(path, value + 1);
+
free(path);
return (true);
}
diff --git a/usr.sbin/bhyve/config.h b/usr.sbin/bhyve/config.h
--- a/usr.sbin/bhyve/config.h
+++ b/usr.sbin/bhyve/config.h
@@ -3,6 +3,7 @@
*
* Copyright (c) 2021 John H. Baldwin <jhb@FreeBSD.org>
* Copyright 2026 Hans Rosenfeld
+ * Copyright (c) 2026 The FreeBSD Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -124,6 +125,13 @@
void set_config_value_if_unset(const char *const path,
const char *const value);
+/*
+ * Similar to set_config_value but appends value to the existing value,
+ * separated by a comma.
+ */
+void append_config_value(const char *const path,
+ const char *const value);
+
/* Convenience wrappers for boolean variables. */
bool get_config_bool(const char *path);
bool get_config_bool_node(const nvlist_t *parent, const char *name);
diff --git a/usr.sbin/bhyve/config.c b/usr.sbin/bhyve/config.c
--- a/usr.sbin/bhyve/config.c
+++ b/usr.sbin/bhyve/config.c
@@ -233,6 +233,24 @@
return (NULL);
}
+void
+append_config_value(const char *path, const char *value)
+{
+ const char *old_value = get_raw_config_value(path);
+ char *new_value;
+
+ if (old_value == NULL)
+ new_value = strdup(value);
+ else
+ (void) asprintf(&new_value, "%s,%s", old_value, value);
+
+ if (new_value == NULL)
+ err(4, "Failed to allocate memory");
+
+ set_config_value(path, new_value);
+ free(new_value);
+}
+
static char *
_expand_config_value(const char *value, int depth)
{

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 17, 5:41 PM (23 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41803956
Default Alt Text
D60125.1794937299.diff (4 KB)

Event Timeline