On Thu, Mar 22, 2012 at 04:34:16PM +0800, Osier Yang wrote: > On 2012年03月21日 01:33, Daniel P. Berrange wrote: > >+int virAuthGetConfigFilePath(virConnectPtr conn, > >+ char **path) > >+{ > >+ int ret = -1; > >+ size_t i; > >+ const char *authenv = getenv("LIBVIRT_AUTH_FILE"); > >+ char *userdir = NULL; > >+ > >+ *path = NULL; > >+ > >+ VIR_DEBUG("Determining auth config file path"); > >+ > >+ if (authenv) { > >+ VIR_DEBUG("Using path from env '%s'", authenv); > >+ if (!(*path = strdup(authenv))) > >+ goto no_memory; > >+ return 0; > >+ } > >+ > >+ for (i = 0 ; i< conn->uri->paramsCount ; i++) { > >+ if (STREQ_NULLABLE(conn->uri->params[i].name, "authfile")&& > >+ conn->uri->params[i].value) { > >+ VIR_DEBUG("Using path from URI '%s'", > >+ conn->uri->params[i].value); > >+ if (!(*path = strdup(conn->uri->params[i].value))) > >+ goto no_memory; > >+ return 0; > >+ } > >+ } > >+ > >+ if (!(userdir = virGetUserDirectory(geteuid()))) > >+ goto cleanup; > >+ > >+ if (virAsprintf(path, "%s/.libvirt/auth.conf", userdir)< 0) > >+ goto no_memory; > >+ > >+ VIR_DEBUG("Checking for readability of '%s'", *path); > >+ if (access(*path, R_OK) == 0) > >+ goto done; > >+ > >+ VIR_FREE(*path); > >+ > >+ if (!(*path = strdup(SYSCONFDIR "/libvirt/auth.conf"))) > >+ goto no_memory; > >+ > >+ VIR_DEBUG("Checking for readability of '%s'", *path); > >+ if (access(*path, R_OK) == 0) > >+ goto done; > >+ > >+ VIR_FREE(*path); > > *path will be NULL if the last choice of authfile (e.g. > /etc/libvirt/auth.conf) is not readable, while the function > will return 0. Yes, that is correct behaviour. We only return '-1' upon some fatal error. We return 0 if we successfully found a path, or if no path exists. This is why we return the path in a out parameter, instead of using the return value. 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 :| -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list