[libvirt] [PATCH] Use XDG Base Directories instead of storing in home directory
William Jon McCann
william.jon.mccann at gmail.com
Wed May 2 15:33:26 UTC 2012
On Wed, May 2, 2012 at 11:30 AM, Daniel P. Berrange <berrange at redhat.com> wrote:
> 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.
Ha, oops, one gets used to using glib :)
I'll update.
Thanks,
Jon
More information about the libvir-list
mailing list