[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] xenstore: New function xs_path_is_subpath



# HG changeset patch
# User Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
# Date 1326473651 0
# Node ID 19a0a2e26137f3f1d436f84a55c24d473eef21fd
# Parent  5eba2a0c61a25beb162aea984a37589d481cf09d
xenstore: New function xs_path_is_subpath

This utility function compares two paths, textually and reports
whether one is a subpath (a child path) of the other.

Signed-off-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Acked-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
Committed-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
---


diff -r 5eba2a0c61a2 -r 19a0a2e26137 tools/xenstore/xs.c
--- a/tools/xenstore/xs.c       Fri Jan 13 16:54:11 2012 +0000
+++ b/tools/xenstore/xs.c       Fri Jan 13 16:54:11 2012 +0000
@@ -950,6 +950,23 @@
        return xs_single(h, XBT_NULL, XS_GET_DOMAIN_PATH, domid_str, NULL);
 }
 
+bool xs_path_is_subpath(const char *parent, const char *child)
+{
+        size_t childlen = strlen(child);
+        size_t parentlen = strlen(parent);
+
+       if (childlen < parentlen)
+               return false;
+
+       if (memcmp(child, parent, parentlen))
+               return false;
+
+       if (childlen > parentlen && child[parentlen] != '/')
+               return false;
+
+       return true;
+}
+
 bool xs_is_domain_introduced(struct xs_handle *h, unsigned int domid)
 {
        char *domain = single_with_domid(h, XS_IS_DOMAIN_INTRODUCED, domid);
diff -r 5eba2a0c61a2 -r 19a0a2e26137 tools/xenstore/xs.h
--- a/tools/xenstore/xs.h       Fri Jan 13 16:54:11 2012 +0000
+++ b/tools/xenstore/xs.h       Fri Jan 13 16:54:11 2012 +0000
@@ -207,6 +207,13 @@
  */
 char *xs_get_domain_path(struct xs_handle *h, unsigned int domid);
 
+/* Returns true if child is either equal to parent, or a node underneath
+ * parent; or false otherwise.  Done by string comparison, so relative and
+ * absolute pathnames never in a parent/child relationship by this
+ * definition.  Cannot fail.
+ */
+bool xs_path_is_subpath(const char *parent, const char *child);
+
 /* Return whether the domain specified has been introduced to xenstored.
  */
 bool xs_is_domain_introduced(struct xs_handle *h, unsigned int domid);

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.