Esempio n. 1
0
static dnsmasqHostsfile *
hostsfileNew(const char *name,
             const char *config_dir)
{
    int err;
    dnsmasqHostsfile *hostsfile;

    if (VIR_ALLOC(hostsfile) < 0) {
        virReportOOMError();
        return NULL;
    }

    hostsfile->hosts = NULL;
    hostsfile->nhosts = 0;

    if (virAsprintf(&hostsfile->path, "%s/%s.%s", config_dir, name,
                    DNSMASQ_HOSTSFILE_SUFFIX) < 0) {
        virReportOOMError();
        goto error;
    }

    if ((err = virFileMakePath(config_dir))) {
        virReportSystemError(err, _("cannot create config directory '%s'"),
                             config_dir);
        goto error;
    }

    return hostsfile;

 error:
    hostsfileFree(hostsfile);
    return NULL;
}
Esempio n. 2
0
static dnsmasqHostsfile *
hostsfileNew(const char *name,
             const char *config_dir)
{
    dnsmasqHostsfile *hostsfile;
    virBuffer buf = VIR_BUFFER_INITIALIZER;

    if (VIR_ALLOC(hostsfile) < 0)
        return NULL;

    hostsfile->hosts = NULL;
    hostsfile->nhosts = 0;

    virBufferAsprintf(&buf, "%s", config_dir);
    virBufferEscapeString(&buf, "/%s", name);
    virBufferAsprintf(&buf, ".%s", DNSMASQ_HOSTSFILE_SUFFIX);

    if (virBufferCheckError(&buf) < 0)
                goto error;

    if (!(hostsfile->path = virBufferContentAndReset(&buf)))
        goto error;
    return hostsfile;

 error:
    virBufferFreeAndReset(&buf);
    hostsfileFree(hostsfile);
    return NULL;
}
Esempio n. 3
0
static dnsmasqHostsfile *
hostsfileNew(const char *name,
             const char *config_dir)
{
    dnsmasqHostsfile *hostsfile;

    if (VIR_ALLOC(hostsfile) < 0) {
        virReportOOMError();
        return NULL;
    }

    hostsfile->hosts = NULL;
    hostsfile->nhosts = 0;

    if (virAsprintf(&hostsfile->path, "%s/%s.%s", config_dir, name,
                    DNSMASQ_HOSTSFILE_SUFFIX) < 0) {
        virReportOOMError();
        goto error;
    }

    return hostsfile;

 error:
    hostsfileFree(hostsfile);
    return NULL;
}
Esempio n. 4
0
/**
 * dnsmasqContextFree:
 * @ctx: pointer to the dnsmasq context
 *
 * Free the resources associated with an dnsmasq context
 */
void
dnsmasqContextFree(dnsmasqContext *ctx)
{
    if (!ctx)
        return;

    if (ctx->hostsfile)
        hostsfileFree(ctx->hostsfile);

    VIR_FREE(ctx);
}
Esempio n. 5
0
/**
 * dnsmasqContextFree:
 * @ctx: pointer to the dnsmasq context
 *
 * Free the resources associated with a dnsmasq context
 */
void
dnsmasqContextFree(dnsmasqContext *ctx)
{
    if (!ctx)
        return;

    VIR_FREE(ctx->config_dir);

    if (ctx->hostsfile)
        hostsfileFree(ctx->hostsfile);
    if (ctx->addnhostsfile)
        addnhostsFree(ctx->addnhostsfile);

    VIR_FREE(ctx);
}