Example #1
0
static int
lxcNetworkParseDataEntry(const char *name,
                         virConfValuePtr value,
                         lxcNetworkParseData *parseData)
{
    const char *suffix = STRSKIP(name, "lxc.network.");

    return lxcNetworkParseDataSuffix(suffix, value, parseData);
}
Example #2
0
char *
canonicalize_file_name(const char *path)
{
    if (getenv("LIBVIRT_MTAB")) {
        const char *p;
        char *ret;

        if ((p = STRSKIP(path, "/some/symlink")))
            ignore_value(virAsprintfQuiet(&ret, "/gluster%s", p));
        else
            ignore_value(VIR_STRDUP_QUIET(ret, path));

        return ret;
    }

    return real_canonicalize_file_name(path);
}
Example #3
0
static int
dnsmasqCapsSetFromBuffer(dnsmasqCapsPtr caps, const char *buf)
{
    const char *p;

    caps->noRefresh = true;

    p = STRSKIP(buf, DNSMASQ_VERSION_STR);
    if (!p)
       goto fail;
    virSkipSpaces(&p);
    if (virParseVersionString(p, &caps->version, true) < 0)
        goto fail;

    if (strstr(buf, "--bind-dynamic"))
        dnsmasqCapsSet(caps, DNSMASQ_CAPS_BIND_DYNAMIC);

    /* if this string is a part of the --version output, dnsmasq
     * has been patched to use SO_BINDTODEVICE when listening,
     * so that it will only accept requests that arrived on the
     * listening interface(s)
     */
    if (strstr(buf, "--bind-interfaces with SO_BINDTODEVICE"))
        dnsmasqCapsSet(caps, DNSMASQ_CAPS_BINDTODEVICE);

    if (strstr(buf, "--ra-param"))
        dnsmasqCapsSet(caps, DNSMASQ_CAPS_RA_PARAM);

    VIR_INFO("dnsmasq version is %d.%d, --bind-dynamic is %spresent, "
             "SO_BINDTODEVICE is %sin use, --ra-param is %spresent",
             (int)caps->version / 1000000,
             (int)(caps->version % 1000000) / 1000,
             dnsmasqCapsGet(caps, DNSMASQ_CAPS_BIND_DYNAMIC) ? "" : "NOT ",
             dnsmasqCapsGet(caps, DNSMASQ_CAPS_BINDTODEVICE) ? "" : "NOT ",
             dnsmasqCapsGet(caps, DNSMASQ_CAPS_RA_PARAM) ? "" : "NOT ");
    return 0;

 fail:
    p = strchrnul(buf, '\n');
    virReportError(VIR_ERR_INTERNAL_ERROR,
                   _("cannot parse %s version number in '%.*s'"),
                   caps->binaryPath, (int) (p - buf), buf);
    return -1;

}
Example #4
0
int
vmwareParseVersionStr(int type, const char *verbuf, unsigned long *version)
{
    const char *pattern;
    const char *tmp;

    switch (type) {
        case VMWARE_DRIVER_PLAYER:
            pattern = "VMware Player ";
            break;
        case VMWARE_DRIVER_WORKSTATION:
            pattern = "VMware Workstation ";
            break;
        case VMWARE_DRIVER_FUSION:
            pattern = "\nVMware Fusion Information:\nVMware Fusion ";
            break;
        default:
            virReportError(VIR_ERR_INTERNAL_ERROR,
                           _("Invalid driver type: %d"), type);
            return -1;
    }

    if ((tmp = strstr(verbuf, pattern)) == NULL) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("cannot find version pattern \"%s\""), pattern);
        return -1;
    }

    if ((tmp = STRSKIP(tmp, pattern)) == NULL) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("failed to parse %sversion"), pattern);
        return -1;
    }

    if (virParseVersionString(tmp, version, false) < 0) {
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                       _("version parsing error"));
        return -1;
    }

    return 0;
}
Example #5
0
/*
 * value will be freed before a new value is assigned to it, the caller is
 * responsible for freeing it afterwards.
 *
 * Returns <0 on error, 0 if not found, 1 if found.
 */
int
openvzReadConfigParam(const char *conf_file, const char *param, char **value)
{
    char *line = NULL;
    size_t line_size = 0;
    FILE *fp;
    int err = 0;
    char *sf, *token, *saveptr = NULL;

    fp = fopen(conf_file, "r");
    if (fp == NULL)
        return -1;

    VIR_FREE(*value);
    while (1) {
        if (getline(&line, &line_size, fp) < 0) {
            err = !feof(fp);
            break;
        }

        if (!(sf = STRSKIP(line, param)))
            continue;

        if (*sf++ != '=')
            continue;

        saveptr = NULL;
        if ((token = strtok_r(sf, "\"\t\n", &saveptr)) != NULL) {
            VIR_FREE(*value);
            if (VIR_STRDUP(*value, token) < 0) {
                err = 1;
                break;
            }
            /* keep going - last entry wins */
        }
    }
    VIR_FREE(line);
    VIR_FORCE_FCLOSE(fp);

    return err ? -1 : *value ? 1 : 0;
}
Example #6
0
int
vmwareExtractVersion(struct vmware_driver *driver)
{
    unsigned long version = 0;
    char *tmp;
    int ret = -1;
    virCommandPtr cmd;
    char * outbuf = NULL;
    const char * bin = (driver->type == TYPE_PLAYER) ? "vmplayer" : "vmware";
    const char * pattern = (driver->type == TYPE_PLAYER) ?
                "VMware Player " : "VMware Workstation ";

    cmd = virCommandNewArgList(bin, "-v", NULL);
    virCommandSetOutputBuffer(cmd, &outbuf);

    if (virCommandRun(cmd, NULL) < 0)
        goto cleanup;

    if ((tmp = STRSKIP(outbuf, pattern)) == NULL) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("failed to parse %s version"), bin);
        goto cleanup;
    }

    if (virParseVersionString(tmp, &version, false) < 0) {
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                       _("version parsing error"));
        goto cleanup;
    }

    driver->version = version;
    ret = 0;

cleanup:
    virCommandFree(cmd);
    VIR_FREE(outbuf);
    return ret;
}
Example #7
0
static int
openvzExtractVersionInfo(const char *cmdstr, int *retversion)
{
    int ret = -1;
    unsigned long version;
    char *help = NULL;
    char *tmp;
    virCommandPtr cmd = virCommandNewArgList(cmdstr, "--help", NULL);

    if (retversion)
        *retversion = 0;

    virCommandAddEnvString(cmd, "LC_ALL=C");
    virCommandSetOutputBuffer(cmd, &help);

    if (virCommandRun(cmd, NULL) < 0)
        goto cleanup;

    tmp = help;

    /* expected format: vzctl version <major>.<minor>.<micro> */
    if ((tmp = STRSKIP(tmp, "vzctl version ")) == NULL)
        goto cleanup;

    if (virParseVersionString(tmp, &version, true) < 0)
        goto cleanup;

    if (retversion)
        *retversion = version;

    ret = 0;

cleanup:
    virCommandFree(cmd);
    VIR_FREE(help);

    return ret;
}
Example #8
0
/**
 * Create a full filename with path to the lock file based on
 * name/path of corresponding device
 *
 * @dev path of the character device
 *
 * Returns a modified name that the caller has to free, or NULL
 * on error.
 */
static char *virChrdevLockFilePath(const char *dev)
{
    char *path = NULL;
    char *sanitizedPath = NULL;
    char *devCopy;
    char *filename;
    char *p;

    if (!(devCopy = strdup(dev))) {
        virReportOOMError();
        goto cleanup;
    }

    /* skip the leading "/dev/" */
    filename = STRSKIP(devCopy, "/dev");
    if (!filename)
        filename = devCopy;

    /* substitute path forward slashes for underscores */
    p = filename;
    while (*p) {
        if (*p == '/')
            *p = '_';
        ++p;
    }

    if (virAsprintf(&path, "%s/LCK..%s", VIR_CHRDEV_LOCK_FILE_PATH, filename) < 0)
        goto cleanup;

    sanitizedPath = virFileSanitizePath(path);

cleanup:
    VIR_FREE(path);
    VIR_FREE(devCopy);

    return sanitizedPath;
}
Example #9
0
static int
lxcAddFstabLine(virDomainDefPtr def, lxcFstabPtr fstab)
{
    const char *src = NULL;
    char *dst = NULL;
    char **options = virStringSplit(fstab->options, ",", 0);
    bool readonly;
    int type = VIR_DOMAIN_FS_TYPE_MOUNT;
    unsigned long long usage = 0;
    int ret = -1;

    if (!options)
        return -1;

    if (fstab->dst[0] != '/') {
        if (virAsprintf(&dst, "/%s", fstab->dst) < 0)
            goto cleanup;
    } else {
        if (VIR_STRDUP(dst, fstab->dst) < 0)
            goto cleanup;
    }

    /* Check that we don't add basic mounts */
    if (lxcIsBasicMountLocation(dst)) {
        ret = 0;
        goto cleanup;
    }

    if (STREQ(fstab->type, "tmpfs")) {
        char *sizeStr = NULL;
        size_t i;
        type = VIR_DOMAIN_FS_TYPE_RAM;

        for (i = 0; options[i]; i++) {
            if ((sizeStr = STRSKIP(options[i], "size="))) {
                if (lxcConvertSize(sizeStr, &usage) < 0)
                    goto cleanup;
                break;
            }
        }
        if (!sizeStr) {
            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                           _("missing tmpfs size, set the size option"));
            goto cleanup;
        }
    } else {
        src = fstab->src;
    }

    /* Is it a block device that needs special favor? */
    if (STRPREFIX(fstab->src, "/dev/"))
        type = VIR_DOMAIN_FS_TYPE_BLOCK;

    /* Do we have ro in options? */
    readonly = virStringArrayHasString(options, "ro");

    if (lxcAddFSDef(def, type, src, dst, readonly, usage) < 0)
        goto cleanup;

    ret = 1;

 cleanup:
    VIR_FREE(dst);
    virStringFreeList(options);
    return ret;
}
Example #10
0
File: api.c Project: emonkak/cereja
static int
parse_item(lua_State* L, const char** p_format, va_list* p_va,
           int value_index, BOOL in_tablep, BOOL* p_optionalp)
{
	const char* format = *p_format;

L_RETRY:
	format = STRSKIP(format, WHITESPACES);
	switch (*format) {
	default:
		lua_pushfstring(L, "format item `%c(%d)' is not valid",
		                SANITIZE_CHAR(*format), *format);
		return FAILURE;
	case 'n': CONVERT_NUMBER(L, *p_va, value_index, lua_Number); break;
	case 'b': CONVERT_NUMBER(L, *p_va, value_index, char); break;
	case 'h': CONVERT_NUMBER(L, *p_va, value_index, short); break;
	case 'i': CONVERT_NUMBER(L, *p_va, value_index, int); break;
	case 'l': CONVERT_NUMBER(L, *p_va, value_index, long); break;
	case 'B': CONVERT_NUMBER(L, *p_va, value_index, unsigned char); break;
	case 'H': CONVERT_NUMBER(L, *p_va, value_index, unsigned short); break;
	case 'I': CONVERT_NUMBER(L, *p_va, value_index, unsigned int); break;
	case 'L': CONVERT_NUMBER(L, *p_va, value_index, unsigned long); break;
	case 's':
		CHECK_TYPE(L, value_index, LUA_TSTRING);
		/* FALLTHRU */
	case 'z': {
		const char** string;
		size_t* length = NULL;

		string = va_arg(*p_va, const char**);
		if (*(format+1) == '#') {
			length = va_arg(*p_va, size_t*);
			format++;
		}

		if (lua_isstring(L, value_index)) {
			*string = lua_tolstring(L, value_index, length);
		} else if (!lua_toboolean(L, value_index)) {  /*nil-or-false?*/
			*string = NULL;
			if (length != NULL)
				*length = 0;
		} else {
			lua_pushfstring(L,
			  "type mismatch (expected %s/nil/false, but got %s)",
			  lua_typename(L, LUA_TSTRING),
			  luaL_typename(L, value_index));
			return FAILURE;
		}
		} break;
	case 'Q': {
		BOOL* p_boolean;

		p_boolean = va_arg(*p_va, BOOL*);
		*p_boolean = lua_toboolean(L, value_index);
		} break;
	case 'u': /* FALLTHRU */
	case 'U': {
		void** userdata;

		CHECK_TYPE(L, value_index,
		           ((*format == 'U') ? LUA_TUSERDATA
		                             : LUA_TLIGHTUSERDATA));
		userdata = va_arg(*p_va, void**);
		*userdata = lua_touserdata(L, value_index);
		} break;
	case 'O': {
		int* index;

		if (in_tablep) {
			lua_pushstring(L,
			  "format item `O' is not available in `{...}");
			return FAILURE;
		}

		if (*(format+1) == '/') {
			int type;

			switch (*(format+2)) {
			default:
				lua_pushfstring(L,
				  "type `%c(%d)' for `O/<type>' is not valid",
				  SANITIZE_CHAR(*(format+2)), *(format+2));
				return FAILURE;
			case 'N': type = LUA_TNIL; break;
			case 'n': type = LUA_TNUMBER; break;
			case 's': type = LUA_TSTRING; break;
			case 'f': type = LUA_TFUNCTION; break;
			case 'Q': type = LUA_TBOOLEAN; break;
			case 'u': type = LUA_TLIGHTUSERDATA; break;
			case 'U': type = LUA_TUSERDATA; break;
			case 't': type = LUA_TTABLE; break;
			case 'T': type = LUA_TTHREAD; break;
			}
			CHECK_TYPE(L, value_index, type);
			format += 2;
		}

		index = va_arg(*p_va, int*);
		*index = value_index;
		} break;
	case '{':
		CHECK_TYPE(L, value_index, LUA_TTABLE);
		format++;
		if (parse_table(L, &format, p_va, value_index) != SUCCESS)
			return FAILURE;
		break;
	case '|':
		if (in_tablep) {
			lua_pushstring(L,
			  "optional argument `|' is not available in `{...}");
			return FAILURE;
		}
		*p_optionalp = TRUE;
		format++;
		goto L_RETRY;
	}