You need to sign in or sign up before continuing.
提交 77d22846 编写于 作者: J Ján Tomko

libxl: use GRegex in libxlGetAutoballoonConf

Replace the use of regcomp with GRegex.
Signed-off-by: NJán Tomko <jtomko@redhat.com>
Reviewed-by: NPeter Krempa <pkrempa@redhat.com>
上级 5c89468f
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#include <config.h> #include <config.h>
#include <regex.h>
#include <libxl.h> #include <libxl.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
...@@ -1664,7 +1663,8 @@ static int ...@@ -1664,7 +1663,8 @@ static int
libxlGetAutoballoonConf(libxlDriverConfigPtr cfg, libxlGetAutoballoonConf(libxlDriverConfigPtr cfg,
virConfPtr conf) virConfPtr conf)
{ {
regex_t regex; g_autoptr(GRegex) regex = NULL;
g_autoptr(GError) err = NULL;
int res; int res;
res = virConfGetValueBool(conf, "autoballoon", &cfg->autoballoon); res = virConfGetValueBool(conf, "autoballoon", &cfg->autoballoon);
...@@ -1673,21 +1673,15 @@ libxlGetAutoballoonConf(libxlDriverConfigPtr cfg, ...@@ -1673,21 +1673,15 @@ libxlGetAutoballoonConf(libxlDriverConfigPtr cfg,
else if (res == 1) else if (res == 1)
return 0; return 0;
if ((res = regcomp(&regex, regex = g_regex_new("(^| )dom0_mem=((|min:|max:)[0-9]+[bBkKmMgG]?,?)+($| )",
"(^| )dom0_mem=((|min:|max:)[0-9]+[bBkKmMgG]?,?)+($| )", 0, 0, &err);
REG_NOSUB | REG_EXTENDED)) != 0) { if (!regex) {
char error[100];
regerror(res, &regex, error, sizeof(error));
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to compile regex %s"), _("Failed to compile regex %s"), err->message);
error);
return -1; return -1;
} }
res = regexec(&regex, cfg->verInfo->commandline, 0, NULL, 0); cfg->autoballoon = !g_regex_match(regex, cfg->verInfo->commandline, 0, NULL);
regfree(&regex);
cfg->autoballoon = res == REG_NOMATCH;
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册