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

Re: [libvirt] [PATCH 1/2] LXC: hostdev: introduce lxcContainerSetupHostdevCapsMakePath



On Tue, Jul 09, 2013 at 11:20:35AM +0800, Gao feng wrote:
> This helper function is used to create parent directroy for
> the hostdev which will be added to the container. if the
> parent directory of this hostdev doesn't exist, the mknod of
> the hostdev will fail.
> 
> Signed-off-by: Gao feng <gaofeng cn fujitsu com>
> ---
>  src/lxc/lxc_container.c | 17 +++++++++++++++++
>  src/lxc/lxc_container.h |  2 ++
>  2 files changed, 19 insertions(+)
> 
> diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
> index c8420db..b954107 100644
> --- a/src/lxc/lxc_container.c
> +++ b/src/lxc/lxc_container.c
> @@ -1544,6 +1544,23 @@ cleanup:
>  }
>  
>  
> +int lxcContainerSetupHostdevCapsMakePath(char *dev)
> +{
> +    int ret = 0;
> +    char *dir = NULL;
> +
> +    if ((dir = strrchr(dev, '/'))) {
> +        *dir = '\0';

Modifying arguments that are passed into a function is bad
practice, so I'm changing this to strdup the arg thus:


+int lxcContainerSetupHostdevCapsMakePath(const char *dev)
+{
+    int ret = -1;
+    char *dir, *tmp;
+
+    if (VIR_STRDUP(dir, dev) < 0)
+        return -1;
+
+    if ((tmp = strrchr(dir, '/'))) {
+        *tmp = '\0';
+        if (virFileMakePath(dir) < 0) {
+            virReportSystemError(errno,
+                                 _("Failed to create directory for '%s' dev '%s'"),
+                                 dir, dev);
+            goto cleanup;
+        }
+    }
+
+    ret = 0;
+
+cleanup:
+    VIR_FREE(dir);
+    return ret;
+}


Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|


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