本文整理汇总了C++中STRNEQ函数的典型用法代码示例。如果您正苦于以下问题:C++ STRNEQ函数的具体用法?C++ STRNEQ怎么用?C++ STRNEQ使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了STRNEQ函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: disk_create_qcow2
static int
disk_create_qcow2 (guestfs_h *g, const char *orig_filename, int64_t size,
const char *backingfile,
const struct guestfs_disk_create_argv *optargs)
{
CLEANUP_FREE char *filename = NULL;
const char *backingformat = NULL;
const char *preallocation = NULL;
const char *compat = NULL;
int clustersize = -1;
CLEANUP_FREE_STRINGSBUF DECLARE_STRINGSBUF (optionsv);
CLEANUP_CMD_CLOSE struct command *cmd = guestfs_int_new_command (g);
int r;
/* If the filename is something like "file:foo" then qemu-img will
* try to interpret that as "foo" in the file:/// protocol. To
* avoid that, if the path is relative prefix it with "./" since
* qemu-img won't try to interpret such a path.
*/
if (orig_filename[0] != '/')
filename = safe_asprintf (g, "./%s", orig_filename);
else
filename = safe_strdup (g, orig_filename);
if (optargs->bitmask & GUESTFS_DISK_CREATE_BACKINGFORMAT_BITMASK) {
backingformat = optargs->backingformat;
/* Conservative whitelist. This can be extended with other
* valid formats as required.
*/
if (STRNEQ (backingformat, "raw") &&
STRNEQ (backingformat, "qcow2") &&
STRNEQ (backingformat, "vmdk")) {
error (g, _("invalid value for backingformat parameter '%s'"),
backingformat);
return -1;
}
}
if (optargs->bitmask & GUESTFS_DISK_CREATE_PREALLOCATION_BITMASK) {
if (STREQ (optargs->preallocation, "off") ||
STREQ (optargs->preallocation, "sparse"))
preallocation = "off";
else if (STREQ (optargs->preallocation, "metadata"))
preallocation = "metadata";
else if (STREQ (optargs->preallocation, "full"))
/* Ugh: https://lists.gnu.org/archive/html/qemu-devel/2014-08/msg03863.html */
preallocation = "falloc";
else {
error (g, _("invalid value for preallocation parameter '%s'"),
preallocation);
return -1;
}
}
if (optargs->bitmask & GUESTFS_DISK_CREATE_COMPAT_BITMASK) {
compat = optargs->compat;
if (STRNEQ (compat, "0.10") && STRNEQ (compat, "1.1")) {
error (g, _("invalid value for compat parameter '%s'"), compat);
return -1;
}
}
if (optargs->bitmask & GUESTFS_DISK_CREATE_CLUSTERSIZE_BITMASK) {
clustersize = optargs->clustersize;
if (clustersize < 512 || clustersize > 2097152 ||
!is_power_of_2 ((unsigned) clustersize)) {
error (g, _("invalid value for clustersize parameter '%d'"),
clustersize);
return -1;
}
}
/* Assemble the qemu-img command line. */
guestfs_int_cmd_add_arg (cmd, "qemu-img");
guestfs_int_cmd_add_arg (cmd, "create");
guestfs_int_cmd_add_arg (cmd, "-f");
guestfs_int_cmd_add_arg (cmd, "qcow2");
/* -o parameter. */
if (backingfile) {
CLEANUP_FREE char *p = qemu_escape_param (g, backingfile);
guestfs_int_add_sprintf (g, &optionsv, "backing_file=%s", p);
}
if (backingformat)
guestfs_int_add_sprintf (g, &optionsv, "backing_fmt=%s", backingformat);
if (preallocation)
guestfs_int_add_sprintf (g, &optionsv, "preallocation=%s", preallocation);
if (compat)
guestfs_int_add_sprintf (g, &optionsv, "compat=%s", compat);
if (clustersize >= 0)
guestfs_int_add_sprintf (g, &optionsv, "cluster_size=%d", clustersize);
guestfs_int_end_stringsbuf (g, &optionsv);
if (optionsv.size > 1) {
CLEANUP_FREE char *options = guestfs_int_join_strings (",", optionsv.argv);
guestfs_int_cmd_add_arg (cmd, "-o");
guestfs_int_cmd_add_arg (cmd, options);
}
/* Complete the command line. */
guestfs_int_cmd_add_arg (cmd, filename);
if (size >= 0)
guestfs_int_cmd_add_arg_format (cmd, "%" PRIi64, size);
//.........这里部分代码省略.........
示例2: testCompareXMLToArgvFiles
static int testCompareXMLToArgvFiles(const char *xml,
const char *cmd,
unsigned long long extraFlags,
const char *migrateFrom) {
char argvData[MAX_FILE];
char *expectargv = &(argvData[0]);
char *actualargv = NULL;
const char **argv = NULL;
const char **qenv = NULL;
const char **tmp = NULL;
int ret = -1, len;
unsigned long long flags;
virDomainDefPtr vmdef = NULL;
virDomainChrDef monitor_chr;
virConnectPtr conn;
if (!(conn = virGetConnect()))
goto fail;
if (virtTestLoadFile(cmd, &expectargv, MAX_FILE) < 0)
goto fail;
if (!(vmdef = virDomainDefParseFile(driver.caps, xml,
VIR_DOMAIN_XML_INACTIVE)))
goto fail;
if (extraFlags & QEMUD_CMD_FLAG_DOMID)
vmdef->id = 6;
else
vmdef->id = -1;
memset(&monitor_chr, 0, sizeof(monitor_chr));
monitor_chr.type = VIR_DOMAIN_CHR_TYPE_UNIX;
monitor_chr.data.nix.path = (char *)"/tmp/test-monitor";
monitor_chr.data.nix.listen = 1;
if (!(monitor_chr.info.alias = strdup("monitor")))
goto fail;
flags = QEMUD_CMD_FLAG_VNC_COLON |
QEMUD_CMD_FLAG_NO_REBOOT |
extraFlags;
if (qemudCanonicalizeMachine(&driver, vmdef) < 0)
goto fail;
if (flags & QEMUD_CMD_FLAG_DEVICE) {
qemuDomainPCIAddressSetPtr pciaddrs;
if (!(pciaddrs = qemuDomainPCIAddressSetCreate(vmdef)))
goto fail;
if (qemuAssignDevicePCISlots(vmdef, pciaddrs) < 0)
goto fail;
qemuDomainPCIAddressSetFree(pciaddrs);
}
if (qemudBuildCommandLine(conn, &driver,
vmdef, &monitor_chr, 0, flags,
&argv, &qenv,
NULL, NULL, migrateFrom, NULL) < 0)
goto fail;
len = 1; /* for trailing newline */
tmp = qenv;
while (*tmp) {
len += strlen(*tmp) + 1;
tmp++;
}
tmp = argv;
while (*tmp) {
len += strlen(*tmp) + 1;
tmp++;
}
if ((actualargv = malloc(sizeof(*actualargv)*len)) == NULL)
goto fail;
actualargv[0] = '\0';
tmp = qenv;
while (*tmp) {
if (actualargv[0])
strcat(actualargv, " ");
strcat(actualargv, *tmp);
tmp++;
}
tmp = argv;
while (*tmp) {
if (actualargv[0])
strcat(actualargv, " ");
strcat(actualargv, *tmp);
tmp++;
}
strcat(actualargv, "\n");
if (STRNEQ(expectargv, actualargv)) {
virtTestDifference(stderr, expectargv, actualargv);
goto fail;
}
ret = 0;
//.........这里部分代码省略.........
示例3: complete_dest_paths_generator
//.........这里部分代码省略.........
\
if ( n > 0 && ! xalloc_oversized (nr_words + n, sizeof (struct word))) { \
struct word *w; \
w = realloc (words, sizeof (struct word) * (nr_words + n)); \
\
if (w == NULL) { \
free_words (words, nr_words); \
words = NULL; \
nr_words = 0; \
} else { \
words = w; \
for (i = 0; i < n; ++i) { \
words[nr_words].name = strs[i]; \
words[nr_words].is_dir = 0; \
nr_words++; \
} \
} \
} \
free (strs); \
} \
} while (0)
/* Is it a device? */
if (len < 5 || STREQLEN (text, "/dev/", 5)) {
/* Get a list of everything that can possibly begin with /dev/ */
strs = guestfs_list_devices (g);
APPEND_STRS_AND_FREE;
strs = guestfs_list_partitions (g);
APPEND_STRS_AND_FREE;
strs = guestfs_lvs (g);
APPEND_STRS_AND_FREE;
strs = guestfs_list_dm_devices (g);
APPEND_STRS_AND_FREE;
strs = guestfs_list_md_devices (g);
APPEND_STRS_AND_FREE;
}
if (len < 1 || text[0] == '/') {
/* If we've got a partial path already, we need to list everything
* in that directory, otherwise list everything in /
*/
char *p, *dir;
struct guestfs_dirent_list *dirents;
p = strrchr (text, '/');
dir = p && p > text ? strndup (text, p - text) : strdup ("/");
if (dir) {
dirents = guestfs_readdir (g, dir);
/* Prepend directory to names before adding them to the list
* of words.
*/
if (dirents) {
size_t i;
for (i = 0; i < dirents->len; ++i) {
int err;
if (STRNEQ (dirents->val[i].name, ".") &&
STRNEQ (dirents->val[i].name, "..")) {
if (STREQ (dir, "/"))
err = asprintf (&p, "/%s", dirents->val[i].name);
else
err = asprintf (&p, "%s/%s", dir, dirents->val[i].name);
if (err >= 0) {
if (!xalloc_oversized (nr_words+1, sizeof (struct word))) {
struct word *w;
w = realloc (words, sizeof (struct word) * (nr_words+1));
if (w == NULL) {
free_words (words, nr_words);
words = NULL;
nr_words = 0;
}
else {
words = w;
words[nr_words].name = p;
words[nr_words].is_dir = dirents->val[i].ftyp == 'd';
nr_words++;
}
}
}
}
}
guestfs_free_dirent_list (dirents);
}
}
}
/* else ... In theory we could complete other things here such as VG
* names. At the moment we don't do that.
*/
RESTORE_ERROR_CB
}
示例4: do_initrd_cat
//.........这里部分代码省略.........
rmdir (tmpdir);
return NULL;
}
r = system (cmd);
if (r == -1) {
reply_with_perror ("command failed: %s", cmd);
rmdir (tmpdir);
return NULL;
}
if (WEXITSTATUS (r) != 0) {
reply_with_perror ("command failed with return code %d",
WEXITSTATUS (r));
rmdir (tmpdir);
return NULL;
}
/* Construct the expected name of the extracted file. */
if (asprintf (&fullpath, "%s/%s", tmpdir, filename) == -1) {
reply_with_perror ("asprintf");
rmdir (tmpdir);
return NULL;
}
/* See if we got a file. */
fd = open (fullpath, O_RDONLY|O_CLOEXEC);
if (fd == -1) {
reply_with_perror ("open: %s:%s", path, filename);
rmdir (tmpdir);
return NULL;
}
/* From this point, we know the file exists, so we require full
* cleanup.
*/
if (fstat (fd, &statbuf) == -1) {
reply_with_perror ("fstat: %s:%s", path, filename);
goto cleanup;
}
/* The actual limit on messages is smaller than this. This
* check just limits the amount of memory we'll try and allocate
* here. If the message is larger than the real limit, that will
* be caught later when we try to serialize the message.
*/
if (statbuf.st_size >= GUESTFS_MESSAGE_MAX) {
reply_with_error ("%s:%s: file is too large for the protocol",
path, filename);
goto cleanup;
}
ret = malloc (statbuf.st_size);
if (ret == NULL) {
reply_with_perror ("malloc");
goto cleanup;
}
if (xread (fd, ret, statbuf.st_size) == -1) {
reply_with_perror ("read: %s:%s", path, filename);
free (ret);
ret = NULL;
goto cleanup;
}
if (close (fd) == -1) {
reply_with_perror ("close: %s:%s", path, filename);
free (ret);
ret = NULL;
goto cleanup;
}
fd = -1;
/* Mustn't touch *size_r until we are sure that we won't return any
* error (RHBZ#589039).
*/
*size_r = statbuf.st_size;
cleanup:
if (fd >= 0)
close (fd);
/* Remove the file. */
if (unlink (fullpath) == -1) {
fprintf (stderr, "unlink: %s: %m\n", fullpath);
/* non-fatal */
}
/* Remove the directories up to and including the temp directory. */
do {
char *p = strrchr (fullpath, '/');
if (!p) break;
*p = '\0';
if (rmdir (fullpath) == -1) {
fprintf (stderr, "rmdir: %s: %m\n", fullpath);
/* non-fatal */
}
} while (STRNEQ (fullpath, tmpdir));
return ret;
}
示例5: testCompareXMLToArgvFiles
//.........这里部分代码省略.........
if (!(emulator = strdup(vmdef->emulator + 1)))
goto fail;
free(vmdef->emulator);
vmdef->emulator = NULL;
if (virAsprintf(&vmdef->emulator, "%s/qemuxml2argvdata/%s",
abs_srcdir, emulator) < 0)
goto fail;
}
if (qemuCapsGet(extraFlags, QEMU_CAPS_DOMID))
vmdef->id = 6;
else
vmdef->id = -1;
memset(&monitor_chr, 0, sizeof(monitor_chr));
monitor_chr.type = VIR_DOMAIN_CHR_TYPE_UNIX;
monitor_chr.data.nix.path = (char *)"/tmp/test-monitor";
monitor_chr.data.nix.listen = true;
qemuCapsSetList(extraFlags,
QEMU_CAPS_VNC_COLON,
QEMU_CAPS_NO_REBOOT,
QEMU_CAPS_LAST);
if (qemudCanonicalizeMachine(&driver, vmdef) < 0)
goto fail;
if (qemuCapsGet(extraFlags, QEMU_CAPS_DEVICE)) {
qemuDomainPCIAddressSetPtr pciaddrs;
if (!(pciaddrs = qemuDomainPCIAddressSetCreate(vmdef)))
goto fail;
if (qemuAssignDevicePCISlots(vmdef, pciaddrs) < 0)
goto fail;
qemuDomainPCIAddressSetFree(pciaddrs);
}
free(virtTestLogContentAndReset());
virResetLastError();
/* We do not call qemuCapsExtractVersionInfo() before calling
* qemuBuildCommandLine(), so we should set QEMU_CAPS_PCI_MULTIBUS for
* x86_64 and i686 architectures here.
*/
if (STREQLEN(vmdef->os.arch, "x86_64", 6) ||
STREQLEN(vmdef->os.arch, "i686", 4)) {
qemuCapsSet(extraFlags, QEMU_CAPS_PCI_MULTIBUS);
}
if (qemuAssignDeviceAliases(vmdef, extraFlags) < 0)
goto fail;
if (!(cmd = qemuBuildCommandLine(conn, &driver,
vmdef, &monitor_chr, json, extraFlags,
migrateFrom, migrateFd, NULL,
VIR_NETDEV_VPORT_PROFILE_OP_NO_OP)))
goto fail;
if (!!virGetLastError() != expectError) {
if (virTestGetDebug() && (log = virtTestLogContentAndReset()))
fprintf(stderr, "\n%s", log);
goto fail;
}
if (expectError) {
/* need to suppress the errors */
virResetLastError();
}
if (!(actualargv = virCommandToString(cmd)))
goto fail;
if (emulator) {
/* Skip the abs_srcdir portion of replacement emulator. */
char *start_skip = strstr(actualargv, abs_srcdir);
char *end_skip = strstr(actualargv, emulator);
if (!start_skip || !end_skip)
goto fail;
memmove(start_skip, end_skip, strlen(end_skip) + 1);
}
if (STRNEQ(expectargv, actualargv)) {
virtTestDifference(stderr, expectargv, actualargv);
goto fail;
}
ret = 0;
fail:
free(log);
free(emulator);
free(expectargv);
free(actualargv);
virCommandFree(cmd);
virDomainDefFree(vmdef);
virUnrefConnect(conn);
return ret;
}
示例6: testJSONAddRemove
static int
testJSONAddRemove(const void *data)
{
const struct testInfo *info = data;
virJSONValuePtr json;
virJSONValuePtr name = NULL;
char *result = NULL;
int ret = -1;
json = virJSONValueFromString(info->doc);
if (!json) {
if (virTestGetVerbose())
fprintf(stderr, "Fail to parse %s\n", info->doc);
ret = -1;
goto cleanup;
}
switch (virJSONValueObjectRemoveKey(json, "name", &name)) {
case 1:
if (!info->pass) {
if (virTestGetVerbose())
fprintf(stderr, "should not remove from non-object %s\n",
info->doc);
goto cleanup;
}
break;
case -1:
if (!info->pass)
ret = 0;
else if (virTestGetVerbose())
fprintf(stderr, "Fail to recognize non-object %s\n", info->doc);
goto cleanup;
default:
if (virTestGetVerbose())
fprintf(stderr, "unexpected result when removing from %s\n",
info->doc);
goto cleanup;
}
if (STRNEQ_NULLABLE(virJSONValueGetString(name), "sample")) {
if (virTestGetVerbose())
fprintf(stderr, "unexpected value after removing name: %s\n",
NULLSTR(virJSONValueGetString(name)));
goto cleanup;
}
if (virJSONValueObjectRemoveKey(json, "name", NULL)) {
if (virTestGetVerbose())
fprintf(stderr, "%s",
"unexpected success when removing missing key\n");
goto cleanup;
}
if (virJSONValueObjectAppendString(json, "newname", "foo") < 0) {
if (virTestGetVerbose())
fprintf(stderr, "%s", "unexpected failure adding new key\n");
goto cleanup;
}
if (!(result = virJSONValueToString(json, false))) {
if (virTestGetVerbose())
fprintf(stderr, "%s", "failed to stringize result\n");
goto cleanup;
}
if (STRNEQ(info->expect, result)) {
if (virTestGetVerbose())
virtTestDifference(stderr, info->expect, result);
goto cleanup;
}
ret = 0;
cleanup:
virJSONValueFree(json);
virJSONValueFree(name);
VIR_FREE(result);
return ret;
}
示例7: parallelsLoadNetwork
static int
parallelsLoadNetwork(parallelsConnPtr privconn, virJSONValuePtr jobj)
{
int ret = -1;
virNetworkObjPtr net = NULL;
virNetworkDefPtr def;
const char *tmp;
/* MD5_DIGEST_SIZE = VIR_UUID_BUFLEN = 16 */
unsigned char md5[MD5_DIGEST_SIZE];
if (VIR_ALLOC(def) < 0)
goto cleanup;
if (!(tmp = virJSONValueObjectGetString(jobj, "Network ID"))) {
parallelsParseError();
goto cleanup;
}
if (VIR_STRDUP(def->name, tmp) < 0)
goto cleanup;
/* Network names are unique in Parallels Cloud Server, so we can make
* a UUID from it */
md5_buffer(tmp, strlen(tmp), md5);
memcpy(def->uuid, md5, VIR_UUID_BUFLEN);
def->uuid_specified = 1;
if (!(tmp = virJSONValueObjectGetString(jobj, "Type"))) {
parallelsParseError();
goto cleanup;
}
if (STREQ(tmp, PARALLELS_BRIDGED_NETWORK_TYPE)) {
def->forward.type = VIR_NETWORK_FORWARD_BRIDGE;
if (parallelsGetBridgedNetInfo(def, jobj) < 0) {
/* Only mandatory networks are required to be configured completely */
if (STRNEQ(def->name, PARALLELS_REQUIRED_BRIDGED_NETWORK))
ret = 0;
goto cleanup;
}
} else if (STREQ(tmp, PARALLELS_HOSTONLY_NETWORK_TYPE)) {
def->forward.type = VIR_NETWORK_FORWARD_NONE;
if (parallelsGetHostOnlyNetInfo(def, def->name) < 0) {
/* Only mandatory networks are required to be configured completely */
if (STRNEQ(def->name, PARALLELS_REQUIRED_HOSTONLY_NETWORK))
ret = 0;
goto cleanup;
}
} else {
parallelsParseError();
goto cleanup;
}
if (!(net = virNetworkAssignDef(privconn->networks, def, 0)))
goto cleanup;
def = NULL;
net->active = 1;
net->autostart = 1;
ret = 0;
cleanup:
virNetworkObjEndAPI(&net);
virNetworkDefFree(def);
return ret;
}
示例8: testCompareXMLToArgvFiles
//.........这里部分代码省略.........
if (virQEMUCapsGet(extraFlags, QEMU_CAPS_DOMID))
vmdef->id = 6;
else
vmdef->id = -1;
memset(&monitor_chr, 0, sizeof(monitor_chr));
monitor_chr.type = VIR_DOMAIN_CHR_TYPE_UNIX;
monitor_chr.data.nix.path = (char *)"/tmp/test-monitor";
monitor_chr.data.nix.listen = true;
virQEMUCapsSetList(extraFlags,
QEMU_CAPS_VNC_COLON,
QEMU_CAPS_NO_REBOOT,
QEMU_CAPS_NO_ACPI,
QEMU_CAPS_LAST);
if (STREQ(vmdef->os.machine, "pc") &&
STREQ(vmdef->emulator, "/usr/bin/qemu-system-x86_64")) {
VIR_FREE(vmdef->os.machine);
if (VIR_STRDUP(vmdef->os.machine, "pc-0.11") < 0)
goto out;
}
if (virQEMUCapsGet(extraFlags, QEMU_CAPS_DEVICE)) {
if (qemuDomainAssignAddresses(vmdef, extraFlags, NULL)) {
if (flags & FLAG_EXPECT_ERROR)
goto ok;
goto out;
}
}
log = virtTestLogContentAndReset();
VIR_FREE(log);
virResetLastError();
if (vmdef->os.arch == VIR_ARCH_X86_64 ||
vmdef->os.arch == VIR_ARCH_I686) {
virQEMUCapsSet(extraFlags, QEMU_CAPS_PCI_MULTIBUS);
}
if (qemuAssignDeviceAliases(vmdef, extraFlags) < 0)
goto out;
if (!(cmd = qemuBuildCommandLine(conn, &driver, vmdef, &monitor_chr,
(flags & FLAG_JSON), extraFlags,
migrateFrom, migrateFd, NULL,
VIR_NETDEV_VPORT_PROFILE_OP_NO_OP,
&testCallbacks))) {
if (flags & FLAG_EXPECT_FAILURE) {
ret = 0;
if (virTestGetDebug() > 1)
fprintf(stderr, "Got expected error: %s\n",
virGetLastErrorMessage());
virResetLastError();
}
goto out;
} else if (flags & FLAG_EXPECT_FAILURE) {
if (virTestGetDebug())
fprintf(stderr, "qemuBuildCommandLine should have failed\n");
goto out;
}
if (!!virGetLastError() != !!(flags & FLAG_EXPECT_ERROR)) {
if (virTestGetDebug() && (log = virtTestLogContentAndReset()))
fprintf(stderr, "\n%s", log);
goto out;
}
if (!(actualargv = virCommandToString(cmd)))
goto out;
len = virtTestLoadFile(cmdline, &expectargv);
if (len < 0)
goto out;
if (len && expectargv[len - 1] == '\n')
expectargv[len - 1] = '\0';
if (STRNEQ(expectargv, actualargv)) {
virtTestDifference(stderr, expectargv, actualargv);
goto out;
}
ok:
if (flags & FLAG_EXPECT_ERROR) {
/* need to suppress the errors */
virResetLastError();
}
ret = 0;
out:
VIR_FREE(log);
VIR_FREE(expectargv);
VIR_FREE(actualargv);
virCommandFree(cmd);
virDomainDefFree(vmdef);
virObjectUnref(conn);
return ret;
}
示例9: vmwareOpen
static virDrvOpenStatus
vmwareOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
int flags ATTRIBUTE_UNUSED)
{
struct vmware_driver *driver;
char * vmrun = NULL;
if (conn->uri == NULL) {
/* @TODO accept */
return VIR_DRV_OPEN_DECLINED;
} else {
if (conn->uri->scheme == NULL ||
(STRNEQ(conn->uri->scheme, "vmwareplayer") &&
STRNEQ(conn->uri->scheme, "vmwarews")))
return VIR_DRV_OPEN_DECLINED;
/* If server name is given, its for remote driver */
if (conn->uri->server != NULL)
return VIR_DRV_OPEN_DECLINED;
/* If path isn't /session, then they typoed, so tell them correct path */
if (conn->uri->path == NULL || STRNEQ(conn->uri->path, "/session")) {
vmwareError(VIR_ERR_INTERNAL_ERROR,
_("unexpected VMware URI path '%s', try vmwareplayer:///session or vmwarews:///session"),
NULLSTR(conn->uri->path));
return VIR_DRV_OPEN_ERROR;
}
}
/* We now know the URI is definitely for this driver, so beyond
* here, don't return DECLINED, always use ERROR */
vmrun = virFindFileInPath(VMRUN);
if (vmrun == NULL) {
vmwareError(VIR_ERR_INTERNAL_ERROR,
_("%s utility is missing"), VMRUN);
return VIR_DRV_OPEN_ERROR;
} else {
VIR_FREE(vmrun);
}
if (VIR_ALLOC(driver) < 0) {
virReportOOMError();
return VIR_DRV_OPEN_ERROR;
}
if (virMutexInit(&driver->lock) < 0)
goto cleanup;
driver->type = STRNEQ(conn->uri->scheme, "vmwareplayer") ?
TYPE_WORKSTATION : TYPE_PLAYER;
if (virDomainObjListInit(&driver->domains) < 0)
goto cleanup;
if (!(driver->caps = vmwareCapsInit()))
goto cleanup;
driver->caps->privateDataAllocFunc = vmwareDataAllocFunc;
driver->caps->privateDataFreeFunc = vmwareDataFreeFunc;
if (vmwareLoadDomains(driver) < 0)
goto cleanup;
if (vmwareExtractVersion(driver) < 0)
goto cleanup;
conn->privateData = driver;
return VIR_DRV_OPEN_SUCCESS;
cleanup:
vmwareFreeDriver(driver);
return VIR_DRV_OPEN_ERROR;
};
示例10: SELinuxGenSecurityLabel
static int
SELinuxGenSecurityLabel(virSecurityManagerPtr mgr ATTRIBUTE_UNUSED,
virDomainDefPtr def)
{
int rc = -1;
char *mcs = NULL;
char *scontext = NULL;
int c1 = 0;
int c2 = 0;
context_t ctx = NULL;
const char *range;
if ((def->seclabel.type == VIR_DOMAIN_SECLABEL_DYNAMIC) &&
!def->seclabel.baselabel &&
def->seclabel.model) {
virSecurityReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("security model already defined for VM"));
return rc;
}
if (def->seclabel.type == VIR_DOMAIN_SECLABEL_DYNAMIC &&
def->seclabel.label) {
virSecurityReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("security label already defined for VM"));
return rc;
}
if (def->seclabel.imagelabel) {
virSecurityReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("security image label already defined for VM"));
return rc;
}
if (def->seclabel.model &&
STRNEQ(def->seclabel.model, SECURITY_SELINUX_NAME)) {
virSecurityReportError(VIR_ERR_INTERNAL_ERROR,
_("security label model %s is not supported with selinux"),
def->seclabel.model);
return rc;
}
switch (def->seclabel.type) {
case VIR_DOMAIN_SECLABEL_STATIC:
if (!(ctx = context_new(def->seclabel.label)) ) {
virReportSystemError(errno,
_("unable to allocate socket security context '%s'"),
def->seclabel.label);
return rc;
}
range = context_range_get(ctx);
if (!range ||
!(mcs = strdup(range))) {
virReportOOMError();
goto cleanup;
}
break;
case VIR_DOMAIN_SECLABEL_DYNAMIC:
do {
c1 = virRandomBits(10);
c2 = virRandomBits(10);
if ( c1 == c2 ) {
if (virAsprintf(&mcs, "s0:c%d", c1) < 0) {
virReportOOMError();
goto cleanup;
}
} else {
if (c1 > c2) {
c1 ^= c2;
c2 ^= c1;
c1 ^= c2;
}
if (virAsprintf(&mcs, "s0:c%d,c%d", c1, c2) < 0) {
virReportOOMError();
goto cleanup;
}
}
} while (mcsAdd(mcs) == -1);
def->seclabel.label =
SELinuxGenNewContext(def->seclabel.baselabel ?
def->seclabel.baselabel :
default_domain_context, mcs);
if (! def->seclabel.label) {
virSecurityReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot generate selinux context for %s"), mcs);
goto cleanup;
}
break;
case VIR_DOMAIN_SECLABEL_NONE:
/* no op */
break;
default:
virSecurityReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected security label type '%s'"),
virDomainSeclabelTypeToString(def->seclabel.type));
//.........这里部分代码省略.........
示例11: testSELinuxCheckCon
static bool
testSELinuxCheckCon(context_t con,
const char *user,
const char *role,
const char *type,
int sensMin,
int sensMax ATTRIBUTE_UNUSED,
int catMin,
int catMax)
{
const char *range;
char *tmp;
int gotSens;
int gotCatOne;
int gotCatTwo;
if (STRNEQ(context_user_get(con), user)) {
fprintf(stderr, "Expect user %s got %s\n",
user, context_user_get(con));
return false;
}
if (STRNEQ(context_role_get(con), role)) {
fprintf(stderr, "Expect role %s got %s\n",
role, context_role_get(con));
return false;
}
if (STRNEQ(context_type_get(con), type)) {
fprintf(stderr, "Expect type %s got %s\n",
type, context_type_get(con));
return false;
}
range = context_range_get(con);
if (range[0] != 's') {
fprintf(stderr, "Malformed range %s, cannot find sensitivity\n",
range);
return false;
}
if (virStrToLong_i(range + 1, &tmp, 10, &gotSens) < 0 ||
!tmp) {
fprintf(stderr, "Malformed range %s, cannot parse sensitivity\n",
range + 1);
return false;
}
if (*tmp != ':') {
fprintf(stderr, "Malformed range %s, too many sensitivity values\n",
tmp);
return false;
}
tmp++;
if (*tmp != 'c') {
fprintf(stderr, "Malformed range %s, cannot find first category\n",
tmp);
return false;
}
tmp++;
if (virStrToLong_i(tmp, &tmp, 10, &gotCatOne) < 0) {
fprintf(stderr, "Malformed range %s, cannot parse category one\n",
tmp);
return false;
}
if (tmp && *tmp == ',')
tmp++;
if (tmp && *tmp == 'c') {
tmp++;
if (virStrToLong_i(tmp, &tmp, 10, &gotCatTwo) < 0) {
fprintf(stderr, "Malformed range %s, cannot parse category two\n",
tmp);
return false;
}
if (*tmp != '\0') {
fprintf(stderr, "Malformed range %s, junk after second category\n",
tmp);
return false;
}
if (gotCatOne == gotCatTwo) {
fprintf(stderr, "Saw category pair %d,%d where cats were equal\n",
gotCatOne, gotCatTwo);
return false;
}
} else {
gotCatTwo = gotCatOne;
}
if (gotSens != sensMin) {
fprintf(stderr, "Sensitivity %d is not equal to min %d\n",
gotSens, sensMin);
return false;
}
if (gotCatOne < catMin ||
gotCatOne > catMax) {
fprintf(stderr, "Category one %d is out of range %d-%d\n",
gotCatTwo, catMin, catMax);
return false;
}
if (gotCatTwo < catMin ||
gotCatTwo > catMax) {
fprintf(stderr, "Category two %d is out of range %d-%d\n",
gotCatTwo, catMin, catMax);
return false;
//.........这里部分代码省略.........
示例12: build_supermin_appliance
/* Build supermin appliance from supermin_path to $TMPDIR/.guestfs-$UID.
*
* Returns:
* 0 = built
* -1 = error (aborts launch)
*/
static int
build_supermin_appliance (guestfs_h *g,
const char *supermin_path,
uid_t uid,
char **kernel, char **initrd,
char **appliance)
{
CLEANUP_FREE char *tmpdir = guestfs_get_cachedir (g);
struct stat statbuf;
size_t len;
/* len must be longer than the length of any pathname we can
* generate in this function.
*/
len = strlen (tmpdir) + 128;
char cachedir[len];
snprintf (cachedir, len, "%s/.guestfs-%ju", tmpdir, (uintmax_t) uid);
char lockfile[len];
snprintf (lockfile, len, "%s/lock", cachedir);
char appliancedir[len];
snprintf (appliancedir, len, "%s/appliance.d", cachedir);
ignore_value (mkdir (cachedir, 0755));
ignore_value (chmod (cachedir, 0755)); /* RHBZ#921292 */
/* See if the cache directory exists and passes some simple checks
* to make sure it has not been tampered with.
*/
if (lstat (cachedir, &statbuf) == -1)
return 0;
if (statbuf.st_uid != uid) {
error (g, _("security: cached appliance %s is not owned by UID %ju"),
cachedir, (uintmax_t) uid);
return -1;
}
if (!S_ISDIR (statbuf.st_mode)) {
error (g, _("security: cached appliance %s is not a directory (mode %o)"),
cachedir, statbuf.st_mode);
return -1;
}
if ((statbuf.st_mode & 0022) != 0) {
error (g, _("security: cached appliance %s is writable by group or other (mode %o)"),
cachedir, statbuf.st_mode);
return -1;
}
(void) utimes (cachedir, NULL);
if (g->verbose)
guestfs_int_print_timestamped_message (g, "begin building supermin appliance");
/* Build the appliance if it needs to be built. */
if (g->verbose)
guestfs_int_print_timestamped_message (g, "run supermin");
if (run_supermin_build (g, lockfile, appliancedir, supermin_path) == -1)
return -1;
if (g->verbose)
guestfs_int_print_timestamped_message (g, "finished building supermin appliance");
/* Return the appliance filenames. */
*kernel = safe_malloc (g, len);
*initrd = safe_malloc (g, len);
*appliance = safe_malloc (g, len);
snprintf (*kernel, len, "%s/kernel", appliancedir);
snprintf (*initrd, len, "%s/initrd", appliancedir);
snprintf (*appliance, len, "%s/root", appliancedir);
/* Touch the files so they don't get deleted (as they are in /var/tmp). */
(void) utimes (*kernel, NULL);
(void) utimes (*initrd, NULL);
/* Checking backend != "uml" is a big hack. UML encodes the mtime
* of the original backing file (in this case, the appliance) in the
* COW file, and checks it when adding it to the VM. If there are
* multiple threads running and one touches the appliance here, it
* will disturb the mtime and UML will give an error.
*
* We can get rid of this hack as soon as UML fixes the
* ubdN=cow,original parsing bug, since we won't need to run
* uml_mkcow separately, so there is no possible race.
*
* XXX
*/
if (STRNEQ (g->backend, "uml"))
(void) utimes (*appliance, NULL);
return 0;
}
示例13: virQEMUDriverConfigLoadFile
//.........这里部分代码省略.........
}
VIR_FREE(cfg->hugetlbfs);
if (p->type == VIR_CONF_LIST) {
size_t len = 0;
virConfValuePtr pp = p->list;
/* Calc length and check items */
while (pp) {
if (pp->type != VIR_CONF_STRING) {
virReportError(VIR_ERR_CONF_SYNTAX, "%s",
_("hugetlbfs_mount must be a list of strings"));
goto cleanup;
}
len++;
pp = pp->next;
}
if (len && VIR_ALLOC_N(cfg->hugetlbfs, len) < 0)
goto cleanup;
cfg->nhugetlbfs = len;
pp = p->list;
len = 0;
while (pp) {
if (virQEMUDriverConfigHugeTLBFSInit(&cfg->hugetlbfs[len],
pp->str, !len) < 0)
goto cleanup;
len++;
pp = pp->next;
}
} else {
CHECK_TYPE("hugetlbfs_mount", VIR_CONF_STRING);
if (STRNEQ(p->str, "")) {
if (VIR_ALLOC_N(cfg->hugetlbfs, 1) < 0)
goto cleanup;
cfg->nhugetlbfs = 1;
if (virQEMUDriverConfigHugeTLBFSInit(&cfg->hugetlbfs[0],
p->str, true) < 0)
goto cleanup;
}
}
}
GET_VALUE_STR("bridge_helper", cfg->bridgeHelperName);
GET_VALUE_BOOL("mac_filter", cfg->macFilter);
GET_VALUE_BOOL("relaxed_acs_check", cfg->relaxedACS);
GET_VALUE_BOOL("clear_emulator_capabilities", cfg->clearEmulatorCapabilities);
GET_VALUE_BOOL("allow_disk_format_probing", cfg->allowDiskFormatProbing);
GET_VALUE_BOOL("set_process_name", cfg->setProcessName);
GET_VALUE_ULONG("max_processes", cfg->maxProcesses);
GET_VALUE_ULONG("max_files", cfg->maxFiles);
GET_VALUE_STR("lock_manager", cfg->lockManagerName);
GET_VALUE_ULONG("max_queued", cfg->maxQueuedJobs);
GET_VALUE_LONG("keepalive_interval", cfg->keepAliveInterval);
GET_VALUE_ULONG("keepalive_count", cfg->keepAliveCount);
GET_VALUE_LONG("seccomp_sandbox", cfg->seccompSandbox);
GET_VALUE_STR("migration_host", cfg->migrateHost);
virStringStripIPv6Brackets(cfg->migrateHost);
示例14: virNetDevVPortProfileMerge
//.........这里部分代码省略.........
"with mismatched managerids (%d and %d)"),
orig->managerID, mods->managerID);
return -1;
}
orig->managerID = mods->managerID;
orig->managerID_specified = true;
}
if (mods->typeID_specified &&
(otype == VIR_NETDEV_VPORT_PROFILE_8021QBG ||
otype == VIR_NETDEV_VPORT_PROFILE_NONE)) {
if (orig->typeID_specified &&
(orig->typeID != mods->typeID)) {
virReportError(VIR_ERR_XML_ERROR,
_("attempt to merge virtualports "
"with mismatched typeids (%d and %d)"),
orig->typeID, mods->typeID);
return -1;
}
orig->typeID = mods->typeID;
orig->typeID_specified = true;
}
if (mods->typeIDVersion_specified &&
(otype == VIR_NETDEV_VPORT_PROFILE_8021QBG ||
otype == VIR_NETDEV_VPORT_PROFILE_NONE)) {
if (orig->typeIDVersion_specified &&
(orig->typeIDVersion != mods->typeIDVersion)) {
virReportError(VIR_ERR_XML_ERROR,
_("attempt to merge virtualports with "
"mismatched typeidversions (%d and %d)"),
orig->typeIDVersion, mods->typeIDVersion);
return -1;
}
orig->typeIDVersion = mods->typeIDVersion;
orig->typeIDVersion_specified = true;
}
if (mods->instanceID_specified &&
(otype == VIR_NETDEV_VPORT_PROFILE_8021QBG ||
otype == VIR_NETDEV_VPORT_PROFILE_NONE)) {
if (orig->instanceID_specified &&
memcmp(orig->instanceID, mods->instanceID,
sizeof(orig->instanceID))) {
char origuuid[VIR_UUID_STRING_BUFLEN];
char modsuuid[VIR_UUID_STRING_BUFLEN];
virReportError(VIR_ERR_XML_ERROR,
_("attempt to merge virtualports with "
"mismatched instanceids ('%s' and '%s')"),
virUUIDFormat(orig->instanceID, origuuid),
virUUIDFormat(mods->instanceID, modsuuid));
return -1;
}
memcpy(orig->instanceID, mods->instanceID, sizeof(orig->instanceID));
orig->instanceID_specified = true;
}
if (mods->interfaceID_specified &&
(otype == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH ||
otype == VIR_NETDEV_VPORT_PROFILE_NONE)) {
if (orig->interfaceID_specified &&
memcmp(orig->interfaceID, mods->interfaceID,
sizeof(orig->interfaceID))) {
char origuuid[VIR_UUID_STRING_BUFLEN];
char modsuuid[VIR_UUID_STRING_BUFLEN];
virReportError(VIR_ERR_XML_ERROR,
_("attempt to merge virtualports with "
"mismatched interfaceids ('%s' and '%s')"),
virUUIDFormat(orig->interfaceID, origuuid),
virUUIDFormat(mods->interfaceID, modsuuid));
return -1;
}
memcpy(orig->interfaceID, mods->interfaceID, sizeof(orig->interfaceID));
orig->interfaceID_specified = true;
}
if (mods->profileID[0] &&
(otype == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH ||
otype == VIR_NETDEV_VPORT_PROFILE_8021QBH ||
otype == VIR_NETDEV_VPORT_PROFILE_NONE)) {
if (orig->profileID[0] &&
STRNEQ(orig->profileID, mods->profileID)) {
virReportError(VIR_ERR_XML_ERROR,
_("attempt to merge virtualports with "
"mismatched profileids ('%s' and '%s')"),
orig->profileID, mods->profileID);
return -1;
}
if (virStrcpyStatic(orig->profileID, mods->profileID) == NULL) {
/* this should never happen - it indicates mods->profileID
* isn't properly null terminated. */
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("corrupted profileid string"));
return -1;
}
}
return 0;
}
示例15: getSocketPath
static char *
getSocketPath(const char *name)
{
char *rundir = virGetUserRuntimeDirectory();
char *sock_path = NULL;
size_t i = 0;
virURIPtr uri = NULL;
if (name) {
if (!(uri = virURIParse(name)))
goto error;
if (STRNEQ(uri->scheme, "admin") ||
uri->server || uri->user || uri->fragment) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Invalid connection name '%s'"), name);
goto error;
}
for (i = 0; i < uri->paramsCount; i++) {
virURIParamPtr param = &uri->params[i];
if (STREQ(param->name, "socket")) {
VIR_FREE(sock_path);
if (VIR_STRDUP(sock_path, param->value) < 0)
goto error;
} else {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Unknown URI parameter '%s'"), param->name);
goto error;
}
}
}
if (!sock_path) {
if (!uri || !uri->path || STREQ(uri->path, "/system")) {
if (VIR_STRDUP(sock_path, LIBVIRTD_ADMIN_UNIX_SOCKET) < 0)
goto error;
} else if (STREQ_NULLABLE(uri->path, "/session")) {
if (!rundir)
goto error;
if (virAsprintf(&sock_path,
"%s%s", rundir, LIBVIRTD_ADMIN_SOCK_NAME) < 0)
goto error;
} else {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Invalid URI path '%s'"), uri->path);
goto error;
}
}
cleanup:
VIR_FREE(rundir);
virURIFree(uri);
return sock_path;
error:
VIR_FREE(sock_path);
goto cleanup;
}