Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/config.c
| /*- | /*- | |||||||||
| * SPDX-License-Identifier: BSD-2-Clause | * SPDX-License-Identifier: BSD-2-Clause | |||||||||
| * | * | |||||||||
| * Copyright (c) 2021 John H. Baldwin <jhb@FreeBSD.org> | * Copyright (c) 2021 John H. Baldwin <jhb@FreeBSD.org> | |||||||||
| * Copyright 2026 Hans Rosenfeld | ||||||||||
| * | * | |||||||||
| * Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | |||||||||
| * modification, are permitted provided that the following conditions | * modification, are permitted provided that the following conditions | |||||||||
| * are met: | * are met: | |||||||||
| * 1. Redistributions of source code must retain the above copyright | * 1. Redistributions of source code must retain the above copyright | |||||||||
| * notice, this list of conditions and the following disclaimer. | * notice, this list of conditions and the following disclaimer. | |||||||||
| * 2. Redistributions in binary form must reproduce the above copyright | * 2. Redistributions in binary form must reproduce the above copyright | |||||||||
| * notice, this list of conditions and the following disclaimer in the | * notice, this list of conditions and the following disclaimer in the | |||||||||
| ▲ Show 20 Lines • Show All 416 Lines • ▼ Show 20 Lines | ||||||||||
| void | void | |||||||||
| set_config_bool_node(nvlist_t *parent, const char *name, bool value) | set_config_bool_node(nvlist_t *parent, const char *name, bool value) | |||||||||
| { | { | |||||||||
| set_config_value_node(parent, name, value ? "true" : "false"); | set_config_value_node(parent, name, value ? "true" : "false"); | |||||||||
| } | } | |||||||||
| static void | int | |||||||||
| dump_tree(const char *prefix, const nvlist_t *nvl) | walk_config_nodes(const char *prefix, const nvlist_t *parent, void *arg, | |||||||||
| int (*cb)(const char *, const nvlist_t *, const char *, int, void *)) | ||||||||||
corvink: Same here, I prefer adding names to the parameter but feel free to ignore my comment. | ||||||||||
| { | { | |||||||||
| void *cookie = NULL; | ||||||||||
| const char *name; | const char *name; | |||||||||
| void *cookie; | ||||||||||
| int type; | int type; | |||||||||
| cookie = NULL; | while ((name = nvlist_next(parent, &type, &cookie)) != NULL) { | |||||||||
| while ((name = nvlist_next(nvl, &type, &cookie)) != NULL) { | int ret; | |||||||||
| ret = cb(prefix, parent, name, type, arg); | ||||||||||
| if (ret != 0) | ||||||||||
| return (ret); | ||||||||||
| } | ||||||||||
| return (0); | ||||||||||
| } | ||||||||||
| static int | ||||||||||
| dump_node_cb(const char *prefix, const nvlist_t *parent, const char *name, | ||||||||||
| int type, void *arg) | ||||||||||
| { | ||||||||||
| if (type == NV_TYPE_NVLIST) { | if (type == NV_TYPE_NVLIST) { | |||||||||
| char *new_prefix; | char *new_prefix; | |||||||||
| int ret; | ||||||||||
| asprintf(&new_prefix, "%s%s.", prefix, name); | asprintf(&new_prefix, "%s%s.", prefix, name); | |||||||||
| dump_tree(new_prefix, nvlist_get_nvlist(nvl, name)); | ret = walk_config_nodes(new_prefix, | |||||||||
| nvlist_get_nvlist(parent, name), arg, dump_node_cb); | ||||||||||
| free(new_prefix); | free(new_prefix); | |||||||||
| } else { | return (ret); | |||||||||
| } | ||||||||||
| assert(type == NV_TYPE_STRING); | assert(type == NV_TYPE_STRING); | |||||||||
| printf("%s%s=%s\n", prefix, name, | printf("%s%s=%s\n", prefix, name, nvlist_get_string(parent, name)); | |||||||||
| nvlist_get_string(nvl, name)); | return (0); | |||||||||
| } | } | |||||||||
| } | ||||||||||
| } | ||||||||||
| void | void | |||||||||
| dump_config(void) | dump_config(void) | |||||||||
| { | { | |||||||||
| dump_tree("", config_root); | (void)walk_config_nodes("", config_root, NULL, dump_node_cb); | |||||||||
Done Inline Actions
markj: | ||||||||||
| } | } | |||||||||
Same here, I prefer adding names to the parameter but feel free to ignore my comment.