mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-21 20:15:17 +00:00
Replace virStringSplit with g_strsplit
Our implementation was heavily inspired by the glib version so it's a drop-in replacement. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
51f8baee8d
commit
10157731f4
@ -806,7 +806,7 @@ virAppendBootloaderArgs(virCommandPtr cmd, virDomainDefPtr def)
|
||||
char **blargs;
|
||||
|
||||
/* XXX: Handle quoted? */
|
||||
blargs = virStringSplit(def->os.bootloaderArgs, " ", 0);
|
||||
blargs = g_strsplit(def->os.bootloaderArgs, " ", 0);
|
||||
virCommandAddArgSet(cmd, (const char * const *)blargs);
|
||||
g_strfreev(blargs);
|
||||
}
|
||||
|
@ -1305,7 +1305,7 @@ virStorageCheckCompat(const char *compat)
|
||||
if (!compat)
|
||||
return 0;
|
||||
|
||||
version = virStringSplit(compat, ".", 2);
|
||||
version = g_strsplit(compat, ".", 2);
|
||||
if (!version || !version[1] ||
|
||||
virStrToLong_ui(version[0], NULL, 10, &result) < 0 ||
|
||||
virStrToLong_ui(version[1], NULL, 10, &result) < 0) {
|
||||
|
@ -698,7 +698,7 @@ libxlMakeDomBuildInfo(virDomainDefPtr def,
|
||||
b_info->bootloader = g_strdup(def->os.bootloader);
|
||||
if (def->os.bootloaderArgs) {
|
||||
if (!(b_info->bootloader_args =
|
||||
virStringSplit(def->os.bootloaderArgs, " \t\n", 0)))
|
||||
g_strsplit(def->os.bootloaderArgs, " \t\n", 0)))
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
@ -714,7 +714,7 @@ libxlMakeDomBuildInfo(virDomainDefPtr def,
|
||||
}
|
||||
if (def->os.bootloaderArgs) {
|
||||
if (!(b_info->u.pv.bootloader_args =
|
||||
virStringSplit(def->os.bootloaderArgs, " \t\n", 0)))
|
||||
g_strsplit(def->os.bootloaderArgs, " \t\n", 0)))
|
||||
return -1;
|
||||
}
|
||||
b_info->u.pv.cmdline = g_strdup(def->os.cmdline);
|
||||
@ -1896,14 +1896,14 @@ libxlDriverGetDom0MaxmemConf(libxlDriverConfigPtr cfg,
|
||||
int ret = -1;
|
||||
|
||||
if (cfg->verInfo->commandline == NULL ||
|
||||
!(cmd_tokens = virStringSplit(cfg->verInfo->commandline, " ", 0)))
|
||||
!(cmd_tokens = g_strsplit(cfg->verInfo->commandline, " ", 0)))
|
||||
goto physmem;
|
||||
|
||||
for (i = 0; cmd_tokens[i] != NULL; i++) {
|
||||
if (!STRPREFIX(cmd_tokens[i], "dom0_mem="))
|
||||
continue;
|
||||
|
||||
if (!(mem_tokens = virStringSplit(cmd_tokens[i], ",", 0)))
|
||||
if (!(mem_tokens = g_strsplit(cmd_tokens[i], ",", 0)))
|
||||
break;
|
||||
for (j = 0; mem_tokens[j] != NULL; j++) {
|
||||
if (STRPREFIX(mem_tokens[j], "max:")) {
|
||||
|
@ -420,7 +420,7 @@ xenParsePCI(char *entry)
|
||||
return NULL;
|
||||
|
||||
str = nextstr;
|
||||
if (str && (options = virStringSplit(str, ",", 0))) {
|
||||
if (str && (options = g_strsplit(str, ",", 0))) {
|
||||
size_t i;
|
||||
|
||||
for (i = 0; options[i] != NULL; i++) {
|
||||
@ -1051,7 +1051,7 @@ xenParseVifBridge(virDomainNetDefPtr net, char *bridge)
|
||||
/* 'bridge' string contains a bridge name and one or more vlan trunks */
|
||||
size_t i;
|
||||
size_t nvlans = 0;
|
||||
char **vlanstr_list = virStringSplit(bridge, ":", 0);
|
||||
char **vlanstr_list = g_strsplit(bridge, ":", 0);
|
||||
|
||||
if (!vlanstr_list)
|
||||
return -1;
|
||||
@ -1258,7 +1258,7 @@ xenParseVif(char *entry, const char *vif_typename)
|
||||
goto cleanup;
|
||||
}
|
||||
if (ip[0]) {
|
||||
char **ip_list = virStringSplit(ip, " ", 0);
|
||||
char **ip_list = g_strsplit(ip, " ", 0);
|
||||
size_t i;
|
||||
|
||||
if (!ip_list)
|
||||
|
@ -268,7 +268,7 @@ xenParseXLCPUID(virConfPtr conf, virDomainDefPtr def)
|
||||
def->cpu->nfeatures_max = 0;
|
||||
}
|
||||
|
||||
cpuid_pairs = virStringSplit(cpuid_str, ",", 0);
|
||||
cpuid_pairs = g_strsplit(cpuid_str, ",", 0);
|
||||
if (!cpuid_pairs)
|
||||
goto cleanup;
|
||||
|
||||
@ -285,7 +285,7 @@ xenParseXLCPUID(virConfPtr conf, virDomainDefPtr def)
|
||||
}
|
||||
|
||||
for (i = 1; cpuid_pairs[i]; i++) {
|
||||
name_and_value = virStringSplit(cpuid_pairs[i], "=", 2);
|
||||
name_and_value = g_strsplit(cpuid_pairs[i], "=", 2);
|
||||
if (!name_and_value)
|
||||
goto cleanup;
|
||||
if (!name_and_value[0] || !name_and_value[1]) {
|
||||
|
@ -119,7 +119,7 @@ static char ** lxcStringSplit(const char *string)
|
||||
tmp[i] = ' ';
|
||||
}
|
||||
|
||||
if (!(parts = virStringSplit(tmp, " ", 0)))
|
||||
if (!(parts = g_strsplit(tmp, " ", 0)))
|
||||
goto error;
|
||||
|
||||
/* Append NULL element */
|
||||
@ -257,7 +257,7 @@ lxcAddFstabLine(virDomainDefPtr def, lxcFstabPtr fstab)
|
||||
{
|
||||
const char *src = NULL;
|
||||
g_autofree char *dst = NULL;
|
||||
char **options = virStringSplit(fstab->options, ",", 0);
|
||||
char **options = g_strsplit(fstab->options, ",", 0);
|
||||
bool readonly;
|
||||
int type = VIR_DOMAIN_FS_TYPE_MOUNT;
|
||||
unsigned long long usage = 0;
|
||||
@ -567,7 +567,7 @@ lxcNetworkParseDataIPs(const char *name,
|
||||
if (STREQ(name, "ipv6") || STREQ(name, "ipv6.address"))
|
||||
family = AF_INET6;
|
||||
|
||||
ipparts = virStringSplit(value->str, "/", 2);
|
||||
ipparts = g_strsplit(value->str, "/", 2);
|
||||
if (!ipparts || !ipparts[0] || !ipparts[1] ||
|
||||
virSocketAddrParse(&ip->address, ipparts[0], family) < 0 ||
|
||||
virStrToLong_ui(ipparts[1], NULL, 10, &ip->prefix) < 0) {
|
||||
@ -1103,7 +1103,7 @@ lxcSetCapDrop(virDomainDefPtr def, virConfPtr properties)
|
||||
size_t i;
|
||||
|
||||
if (virConfGetValueString(properties, "lxc.cap.drop", &value) > 0)
|
||||
toDrop = virStringSplit(value, " ", 0);
|
||||
toDrop = g_strsplit(value, " ", 0);
|
||||
|
||||
for (i = 0; i < VIR_DOMAIN_PROCES_CAPS_FEATURE_LAST; i++) {
|
||||
capString = virDomainProcessCapsFeatureTypeToString(i);
|
||||
|
@ -1365,7 +1365,7 @@ qemuGetSchedInfo(unsigned long long *cpuWait,
|
||||
if (virFileReadAll(proc, (1<<16), &data) < 0)
|
||||
goto cleanup;
|
||||
|
||||
lines = virStringSplit(data, "\n", 0);
|
||||
lines = g_strsplit(data, "\n", 0);
|
||||
if (!lines)
|
||||
goto cleanup;
|
||||
|
||||
|
@ -440,7 +440,7 @@ virQEMUQAPISchemaPathGet(const char *query,
|
||||
if (entry)
|
||||
*entry = NULL;
|
||||
|
||||
if (!(elems = virStringSplit(query, "/", 0)))
|
||||
if (!(elems = g_strsplit(query, "/", 0)))
|
||||
return -1;
|
||||
|
||||
if (!*elems) {
|
||||
|
@ -961,7 +961,7 @@ virNetSocketNewConnectLibSSH2(const char *host,
|
||||
|
||||
virNetSSHSessionSetChannelCommand(sess, command);
|
||||
|
||||
if (!(authMethodList = virStringSplit(authMethods, ",", 0)))
|
||||
if (!(authMethodList = g_strsplit(authMethods, ",", 0)))
|
||||
goto error;
|
||||
|
||||
for (authMethodNext = authMethodList; *authMethodNext; authMethodNext++) {
|
||||
@ -1092,7 +1092,7 @@ virNetSocketNewConnectLibssh(const char *host,
|
||||
|
||||
virNetLibsshSessionSetChannelCommand(sess, command);
|
||||
|
||||
if (!(authMethodList = virStringSplit(authMethods, ",", 0)))
|
||||
if (!(authMethodList = g_strsplit(authMethods, ",", 0)))
|
||||
goto error;
|
||||
|
||||
for (authMethodNext = authMethodList; *authMethodNext; authMethodNext++) {
|
||||
|
@ -148,14 +148,14 @@ virStorageBackendSheepdogRefreshAllVol(virStoragePoolObjPtr pool)
|
||||
if (virCommandRun(cmd, NULL) < 0)
|
||||
return -1;
|
||||
|
||||
lines = virStringSplit(output, "\n", 0);
|
||||
lines = g_strsplit(output, "\n", 0);
|
||||
if (lines == NULL)
|
||||
return -1;
|
||||
|
||||
for (i = 0; lines[i]; i++) {
|
||||
g_auto(GStrv) cells = NULL;
|
||||
|
||||
cells = virStringSplit(lines[i], " ", 0);
|
||||
cells = g_strsplit(lines[i], " ", 0);
|
||||
|
||||
if (cells != NULL && cells[0] && cells[1]) {
|
||||
if (virStorageBackendSheepdogAddVolume(pool, cells[1]) < 0)
|
||||
|
@ -195,7 +195,7 @@ virStorageBackendZFSFindVols(virStoragePoolObjPtr pool,
|
||||
if (virCommandRun(cmd, NULL) < 0)
|
||||
return -1;
|
||||
|
||||
if (!(lines = virStringSplit(volumes_list, "\n", 0)))
|
||||
if (!(lines = g_strsplit(volumes_list, "\n", 0)))
|
||||
return -1;
|
||||
|
||||
for (i = 0; lines[i]; i++) {
|
||||
@ -230,7 +230,7 @@ virStorageBackendZFSRefreshPool(virStoragePoolObjPtr pool G_GNUC_UNUSED)
|
||||
*
|
||||
* Here we just provide a list of properties we want to see
|
||||
*/
|
||||
if (!(name_tokens = virStringSplit(def->source.name, "/", 0)))
|
||||
if (!(name_tokens = g_strsplit(def->source.name, "/", 0)))
|
||||
goto cleanup;
|
||||
|
||||
cmd = virCommandNewArgList(ZPOOL,
|
||||
@ -242,7 +242,7 @@ virStorageBackendZFSRefreshPool(virStoragePoolObjPtr pool G_GNUC_UNUSED)
|
||||
if (virCommandRun(cmd, NULL) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!(lines = virStringSplit(zpool_props, "\n", 0)))
|
||||
if (!(lines = g_strsplit(zpool_props, "\n", 0)))
|
||||
goto cleanup;
|
||||
|
||||
for (i = 0; lines[i]; i++) {
|
||||
|
@ -54,7 +54,7 @@ virStorageSourceParseBackingURI(virStorageSourcePtr src,
|
||||
src->hosts = g_new0(virStorageNetHostDef, 1);
|
||||
src->nhosts = 1;
|
||||
|
||||
if (!(scheme = virStringSplit(uri->scheme, "+", 2)))
|
||||
if (!(scheme = g_strsplit(uri->scheme, "+", 2)))
|
||||
return -1;
|
||||
|
||||
if (!scheme[0] ||
|
||||
@ -165,7 +165,7 @@ virStorageSourceRBDAddHost(virStorageSourcePtr src,
|
||||
goto error;
|
||||
}
|
||||
|
||||
parts = virStringSplit(hostport, "\\:", 0);
|
||||
parts = g_strsplit(hostport, "\\:", 0);
|
||||
if (!parts)
|
||||
goto error;
|
||||
src->hosts[src->nhosts-1].name = virStringListJoin((const char **)parts, ":");
|
||||
|
@ -606,7 +606,7 @@ virCgroupGetValueForBlkDev(const char *str,
|
||||
if (!(prefix = virCgroupGetBlockDevString(path)))
|
||||
return -1;
|
||||
|
||||
if (!(lines = virStringSplit(str, "\n", -1)))
|
||||
if (!(lines = g_strsplit(str, "\n", -1)))
|
||||
return -1;
|
||||
|
||||
for (tmp = lines; *tmp; tmp++) {
|
||||
@ -855,7 +855,7 @@ virCgroupSetPartitionSuffix(const char *path, char **res)
|
||||
size_t i;
|
||||
int ret = -1;
|
||||
|
||||
if (!(tokens = virStringSplit(path, "/", 0)))
|
||||
if (!(tokens = g_strsplit(path, "/", 0)))
|
||||
return ret;
|
||||
|
||||
for (i = 0; tokens[i] != NULL; i++) {
|
||||
@ -1226,7 +1226,7 @@ virCgroupEnableMissingControllers(char *path,
|
||||
virCgroupPtr *group)
|
||||
{
|
||||
g_autoptr(virCgroup) parent = NULL;
|
||||
g_auto(GStrv) tokens = virStringSplit(path, "/", 0);
|
||||
g_auto(GStrv) tokens = g_strsplit(path, "/", 0);
|
||||
size_t i;
|
||||
|
||||
if (virCgroupNew("/", controllers, &parent) < 0)
|
||||
|
@ -285,7 +285,7 @@ virCgroupV2ParseControllersFile(virCgroupPtr group,
|
||||
|
||||
virTrimSpaces(contStr, NULL);
|
||||
|
||||
contList = virStringSplit(contStr, " ", 20);
|
||||
contList = g_strsplit(contStr, " ", 20);
|
||||
if (!contList)
|
||||
return -1;
|
||||
|
||||
|
@ -3230,7 +3230,7 @@ virCommandRunRegex(virCommandPtr cmd,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!(lines = virStringSplit(outbuf, "\n", 0)))
|
||||
if (!(lines = g_strsplit(outbuf, "\n", 0)))
|
||||
goto cleanup;
|
||||
|
||||
for (k = 0; lines[k]; k++) {
|
||||
|
@ -63,7 +63,7 @@ virDevMapperGetMajor(unsigned int *major)
|
||||
if (virFileReadAll(PROC_DEVICES, BUF_SIZE, &buf) < 0)
|
||||
return -1;
|
||||
|
||||
lines = virStringSplit(buf, "\n", 0);
|
||||
lines = g_strsplit(buf, "\n", 0);
|
||||
if (!lines)
|
||||
return -1;
|
||||
|
||||
|
@ -1711,7 +1711,7 @@ virFindFileInPath(const char *file)
|
||||
* it. return it if found.
|
||||
*/
|
||||
|
||||
if (!(paths = virStringSplit(origpath, ":", 0)))
|
||||
if (!(paths = g_strsplit(origpath, ":", 0)))
|
||||
return NULL;
|
||||
|
||||
for (pathiter = paths; *pathiter; pathiter++) {
|
||||
|
@ -719,7 +719,7 @@ virFirewallApplyRule(virFirewallPtr firewall,
|
||||
}
|
||||
|
||||
if (rule->queryCB && output) {
|
||||
if (!(lines = virStringSplit(output, "\n", -1)))
|
||||
if (!(lines = g_strsplit(output, "\n", -1)))
|
||||
return -1;
|
||||
|
||||
VIR_DEBUG("Invoking query %p with '%s'", rule->queryCB, output);
|
||||
|
@ -61,7 +61,7 @@ virFirmwareParse(const char *str, virFirmwarePtr firmware)
|
||||
int ret = -1;
|
||||
char **token;
|
||||
|
||||
if (!(token = virStringSplit(str, ":", 0)))
|
||||
if (!(token = g_strsplit(str, ":", 0)))
|
||||
goto cleanup;
|
||||
|
||||
if (token[0]) {
|
||||
@ -98,7 +98,7 @@ virFirmwareParseList(const char *list,
|
||||
char **token;
|
||||
size_t i, j;
|
||||
|
||||
if (!(token = virStringSplit(list, ":", 0)))
|
||||
if (!(token = g_strsplit(list, ":", 0)))
|
||||
goto cleanup;
|
||||
|
||||
for (i = 0; token[i]; i += 2) {
|
||||
|
@ -1011,7 +1011,7 @@ int virProcessGetStartTime(pid_t pid,
|
||||
return -1;
|
||||
}
|
||||
|
||||
tokens = virStringSplit(tmp, " ", 0);
|
||||
tokens = g_strsplit(tmp, " ", 0);
|
||||
|
||||
if (!tokens ||
|
||||
g_strv_length(tokens) < 20) {
|
||||
|
@ -745,7 +745,7 @@ prlsdkGetFSInfo(PRL_HANDLE prldisk,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!(matches = virStringSplit(uri->path, "/", 0)) ||
|
||||
if (!(matches = g_strsplit(uri->path, "/", 0)) ||
|
||||
!matches[0]) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("splitting StorageUrl failed %s"), uri->path);
|
||||
|
@ -149,7 +149,7 @@ fakeStorageVolLookupByName(virStoragePoolPtr pool,
|
||||
if (!strchr(name, '+'))
|
||||
goto fallback;
|
||||
|
||||
if (!(volinfo = virStringSplit(name, "+", 2)))
|
||||
if (!(volinfo = g_strsplit(name, "+", 2)))
|
||||
return NULL;
|
||||
|
||||
if (!volinfo[1])
|
||||
|
@ -23,7 +23,7 @@ testFilterXML(char *xml)
|
||||
char **xmlLine;
|
||||
char *ret = NULL;
|
||||
|
||||
if (!(xmlLines = virStringSplit(xml, "\n", 0))) {
|
||||
if (!(xmlLines = g_strsplit(xml, "\n", 0))) {
|
||||
VIR_FREE(xml);
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ virshCommaStringListComplete(const char *input,
|
||||
g_clear_pointer(&inputCopy, g_free);
|
||||
}
|
||||
|
||||
if (inputCopy && !(inputList = virStringSplit(inputCopy, ",", 0)))
|
||||
if (inputCopy && !(inputList = g_strsplit(inputCopy, ",", 0)))
|
||||
return NULL;
|
||||
|
||||
ret = g_new0(char *, optionsLen + 1);
|
||||
|
@ -4057,7 +4057,7 @@ cmdStartGetFDs(vshControl *ctl,
|
||||
if (vshCommandOptStringQuiet(ctl, cmd, "pass-fds", &fdopt) <= 0)
|
||||
return 0;
|
||||
|
||||
if (!(fdlist = virStringSplit(fdopt, ",", -1))) {
|
||||
if (!(fdlist = g_strsplit(fdopt, ",", -1))) {
|
||||
vshError(ctl, _("Unable to split FD list '%s'"), fdopt);
|
||||
return -1;
|
||||
}
|
||||
@ -5929,7 +5929,7 @@ cmdShutdown(vshControl *ctl, const vshCmd *cmd)
|
||||
if (vshCommandOptStringReq(ctl, cmd, "mode", &mode) < 0)
|
||||
return false;
|
||||
|
||||
if (mode && !(modes = virStringSplit(mode, ",", 0))) {
|
||||
if (mode && !(modes = g_strsplit(mode, ",", 0))) {
|
||||
vshError(ctl, "%s", _("Cannot parse mode string"));
|
||||
return false;
|
||||
}
|
||||
@ -6013,7 +6013,7 @@ cmdReboot(vshControl *ctl, const vshCmd *cmd)
|
||||
if (vshCommandOptStringReq(ctl, cmd, "mode", &mode) < 0)
|
||||
return false;
|
||||
|
||||
if (mode && !(modes = virStringSplit(mode, ",", 0))) {
|
||||
if (mode && !(modes = g_strsplit(mode, ",", 0))) {
|
||||
vshError(ctl, "%s", _("Cannot parse mode string"));
|
||||
return false;
|
||||
}
|
||||
@ -10784,7 +10784,7 @@ doMigrate(void *opaque)
|
||||
if (opt) {
|
||||
char **val = NULL;
|
||||
|
||||
val = virStringSplit(opt, ",", 0);
|
||||
val = g_strsplit(opt, ",", 0);
|
||||
|
||||
if (virTypedParamsAddStringList(¶ms,
|
||||
&nparams,
|
||||
@ -10801,7 +10801,7 @@ doMigrate(void *opaque)
|
||||
if (vshCommandOptStringReq(ctl, cmd, "comp-methods", &opt) < 0)
|
||||
goto out;
|
||||
if (opt) {
|
||||
char **val = virStringSplit(opt, ",", 0);
|
||||
char **val = g_strsplit(opt, ",", 0);
|
||||
|
||||
if (virTypedParamsAddStringList(¶ms,
|
||||
&nparams,
|
||||
@ -14388,7 +14388,7 @@ cmdSetUserSSHKeys(vshControl *ctl, const vshCmd *cmd)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!(keys = virStringSplit(buffer, "\n", -1)))
|
||||
if (!(keys = g_strsplit(buffer, "\n", -1)))
|
||||
goto cleanup;
|
||||
|
||||
nkeys = g_strv_length(keys);
|
||||
|
Loading…
x
Reference in New Issue
Block a user