[libvirt] [PATCH] Use XDG Base Directories instead of storing in home directory

Daniel P. Berrange berrange at redhat.com
Wed May 2 15:30:27 UTC 2012


On Tue, May 01, 2012 at 09:50:31AM -0400, William Jon McCann wrote:
> +static int migrateProfile(void)
> +{
> +    char *old_base = NULL;
> +    char *updated = NULL;
> +    char *home = NULL;
> +    char *xdg_dir = NULL;
> +    char *config_dir = NULL;
> +    int ret = -1;
> +    mode_t old_umask;
> +
> +    if (!(home = virGetUserDirectory(geteuid())))
> +        goto cleanup;
> +
> +    if (virAsprintf(&old_base, "%s/.libvirt", home) < 0) {
> +        goto cleanup;
> +    }
> +
> +    /* if the new directory is there or the old one is not: do nothing */
> +    if (!(config_dir = virGetUserConfigDirectory(geteuid())))
> +        goto cleanup;
> +
> +    if (!virFileIsDir(old_base) || virFileExists(config_dir)) {
> +        goto cleanup;
> +    }
> +
> +    /* test if we already attempted to migrate first */
> +    if (virAsprintf(&updated, "%s/DEPRECATED-DIRECTORY", old_base) < 0) {
> +        goto cleanup;
> +    }
> +    if (virFileExists(updated)) {
> +        goto cleanup;
> +    }
> +
> +    xdg_dir = strdup(getenv("XDG_CONFIG_HOME"));

Opps, segv-tastic - you can't pass a NULL string to strdup().

Bugs aside, I think this patch gets my vote.

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