aboutsummaryrefslogtreecommitdiff
path: root/qom
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2018-05-30 18:16:04 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2018-06-01 14:15:10 +0200
commite40077fd2ccbf4ffa8d07f186110fac240a45bf9 (patch)
treed00d212e796d570a999407b3504d8a24c2904be7 /qom
parent24ed11723230e43f44e9a1aef72e7c71714288d1 (diff)
qom: support orphan objects in object_get_canonical_path
Mostly a rewrite, in order to keep the loop simple. Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'qom')
-rw-r--r--qom/object.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/qom/object.c b/qom/object.c
index 0fc972030e..cb7a8cd589 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1669,25 +1669,29 @@ gchar *object_get_canonical_path(Object *obj)
Object *root = object_get_root();
char *newpath, *path = NULL;
- while (obj != root) {
+ if (obj == root) {
+ return g_strdup("/");
+ }
+
+ do {
char *component = object_get_canonical_path_component(obj);
- if (path) {
- newpath = g_strdup_printf("%s/%s", component, path);
- g_free(component);
+ if (!component) {
+ /* A canonical path must be complete, so discard what was
+ * collected so far.
+ */
g_free(path);
- path = newpath;
- } else {
- path = component;
+ return NULL;
}
+ newpath = g_strdup_printf("/%s%s", component, path ? path : "");
+ g_free(path);
+ g_free(component);
+ path = newpath;
obj = obj->parent;
- }
-
- newpath = g_strdup_printf("/%s", path ? path : "");
- g_free(path);
+ } while (obj != root);
- return newpath;
+ return path;
}
Object *object_resolve_path_component(Object *parent, const gchar *part)