[libvirt] [RFC 4/4] add automatic cleanup support in src/util/virauth.c
Erik Skultety
eskultet at redhat.com
Thu May 31 13:05:41 UTC 2018
On Wed, May 30, 2018 at 02:30:07AM +0530, Sukrit Bhatnagar wrote:
> Define a new cleanup function for virAuthConfigPtr in
> src/util/virauthconfig.h.
> Modifiy code to use cleanup macros where required.
s/fiy/fy
>
> Signed-off-by: Sukrit Bhatnagar <skrtbhtngr at gmail.com>
> ---
> src/util/virauth.c | 66 ++++++++++++++++++------------------------------
> src/util/virauthconfig.h | 3 +++
> 2 files changed, 27 insertions(+), 42 deletions(-)
>
> diff --git a/src/util/virauth.c b/src/util/virauth.c
> index adb093e..aa7593c 100644
> --- a/src/util/virauth.c
> +++ b/src/util/virauth.c
> @@ -26,7 +26,6 @@
>
> #include "virauth.h"
> #include "virutil.h"
> -#include "viralloc.h"
> #include "virlog.h"
> #include "datatypes.h"
> #include "virerror.h"
> @@ -42,10 +41,9 @@ int
> virAuthGetConfigFilePathURI(virURIPtr uri,
> char **path)
> {
> - int ret = -1;
> size_t i;
> const char *authenv = virGetEnvBlockSUID("LIBVIRT_AUTH_FILE");
> - char *userdir = NULL;
> + VIR_AUTOFREE(char *) userdir = NULL;
>
> *path = NULL;
>
> @@ -54,7 +52,7 @@ virAuthGetConfigFilePathURI(virURIPtr uri,
> if (authenv) {
> VIR_DEBUG("Using path from env '%s'", authenv);
> if (VIR_STRDUP(*path, authenv) < 0)
> - goto cleanup;
> + return -1;
> return 0;
> }
>
> @@ -64,41 +62,38 @@ virAuthGetConfigFilePathURI(virURIPtr uri,
> uri->params[i].value) {
> VIR_DEBUG("Using path from URI '%s'", uri->params[i].value);
> if (VIR_STRDUP(*path, uri->params[i].value) < 0)
> - goto cleanup;
> + return -1;
> return 0;
> }
> }
> }
>
> if (!(userdir = virGetUserConfigDirectory()))
> - goto cleanup;
> + return -1;
>
> if (virAsprintf(path, "%s/auth.conf", userdir) < 0)
> - goto cleanup;
> + return -1;
>
> VIR_DEBUG("Checking for readability of '%s'", *path);
> - if (access(*path, R_OK) == 0)
> - goto done;
> + if (access(*path, R_OK) == 0) {
> + VIR_DEBUG("Using auth file '%s'", NULLSTR(*path));
> + return 0;
> + }
>
> VIR_FREE(*path);
>
> if (VIR_STRDUP(*path, SYSCONFDIR "/libvirt/auth.conf") < 0)
> - goto cleanup;
> + return -1;
>
> VIR_DEBUG("Checking for readability of '%s'", *path);
> - if (access(*path, R_OK) == 0)
> - goto done;
> + if (access(*path, R_OK) == 0) {
> + VIR_DEBUG("Using auth file '%s'", NULLSTR(*path));
> + return 0;
> + }
>
> VIR_FREE(*path);
>
> - done:
> - ret = 0;
> -
> - VIR_DEBUG("Using auth file '%s'", NULLSTR(*path));
> - cleanup:
> - VIR_FREE(userdir);
> -
> - return ret;
> + return 0;
> }
>
>
> @@ -117,8 +112,7 @@ virAuthGetCredential(const char *servicename,
> const char *path,
> char **value)
> {
> - int ret = -1;
> - virAuthConfigPtr config = NULL;
> + VIR_AUTOPTR(virAuthConfigPtr) config = NULL;
As I said in patch 1, changes related to VIR_AUTOPTR should be a separate patch
series, IOW the patches shouldn't combine changing both VIR_AUTOFREE and
VIR_AUTOPTR.
Otherwise, the changes look good, looking forward to more files. As we
discussed privately, having a series addressing src/util then e.g. src/conf as
separate patch series which can be merged gradually is IMHO better than trying
to make all the VIR_FREE changes everywhere, then sending a massive series
consisting of tens of patches and then doing the same for VIR_AUTOPTR.
Erik
More information about the libvir-list
mailing list