[libvirt] [sandbox PATCH 09/10] Common-init: Building symlink from disks.cfg

Daniel P. Berrange berrange at redhat.com
Thu Jun 25 16:25:30 UTC 2015


On Thu, Jun 25, 2015 at 01:27:29PM +0200, Eren Yagdiran wrote:
> Similar to the existing mounts.cfg, the mapping between the device and the tag is
> passed by a new disks.cfg file. Common-init reads disks.cfg and maps the tags
> to corresponding devices
> ---
>  libvirt-sandbox/libvirt-sandbox-init-common.c | 51 +++++++++++++++++++++++++--
>  1 file changed, 49 insertions(+), 2 deletions(-)
> 
> diff --git a/libvirt-sandbox/libvirt-sandbox-init-common.c b/libvirt-sandbox/libvirt-sandbox-init-common.c
> index 68f96ba..f8b2ea5 100644
> --- a/libvirt-sandbox/libvirt-sandbox-init-common.c
> +++ b/libvirt-sandbox/libvirt-sandbox-init-common.c
> @@ -46,6 +46,7 @@
>  #include <grp.h>
>  
>  #include "libvirt-sandbox-rpcpacket.h"
> +#include "libvirt-sandbox-init-util.h"
>  
>  static gboolean debug = FALSE;
>  static gboolean verbose = FALSE;
> @@ -60,6 +61,51 @@ static void sig_child(int sig ATTR_UNUSED)
>          abort();
>  }
>  
> +static gboolean setup_disk_tags(void) {
> +    FILE *fp;
> +    gboolean ret = FALSE;
> +    static char line[1024];
> +    if (debug)
> +        fprintf(stderr, "libvirt-sandbox-init-common: %s: populate /dev/disk/by-tag/\n",
> +			__func__);
> +    fp = fopen(SANDBOXCONFIGDIR "/disks.cfg", "r");
> +    if (fp == NULL) {
> +        fprintf(stderr, "libvirt-sandbox-init-common: %s: cannot open " SANDBOXCONFIGDIR "/disks.cfg: %s\n",
> +                __func__, strerror(errno));
> +
> +        goto cleanup;
> +    }
> +    gvir_sandbox_init_util_mkdir("/dev/disk/by-tag", 0755, debug == TRUE ? 1 : 0);
> +    while (fgets(line, sizeof line, fp)) {
> +        char path[1024];
> +        char *tag = line;
> +        char *device = strchr(tag, '\t');
> +        *device = '\0';
> +        device++;
> +        char *tmp = strchr(device, '\n');
> +        *tmp = '\0';
> +
> +        if (sprintf(path, "/dev/disk/by-tag/%s", tag) < 0) {

It is preferrable to use  g_strdup_printf() from glib instead of
sprintf into a fixed buffer with no overflow checks.


Regards,
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 :|




More information about the libvir-list mailing list