提交 4af1817d 编写于 作者: C Chris Lalancette

Use unsigned long in cmdSetmem.

The virsh command "setmem" takes as input a number that
should represent an unsigned long number of kilobytes.  Fix
cmdSetmem to properly parse this as an unsigned long instead
of an int.
Signed-off-by: NChris Lalancette <clalance@redhat.com>
上级 e0f26c46
...@@ -223,6 +223,8 @@ static int vshCmddefHelp(vshControl *ctl, const char *name); ...@@ -223,6 +223,8 @@ static int vshCmddefHelp(vshControl *ctl, const char *name);
static vshCmdOpt *vshCommandOpt(const vshCmd *cmd, const char *name); static vshCmdOpt *vshCommandOpt(const vshCmd *cmd, const char *name);
static int vshCommandOptInt(const vshCmd *cmd, const char *name, int *found); static int vshCommandOptInt(const vshCmd *cmd, const char *name, int *found);
static unsigned long vshCommandOptUL(const vshCmd *cmd, const char *name,
int *found);
static char *vshCommandOptString(const vshCmd *cmd, const char *name, static char *vshCommandOptString(const vshCmd *cmd, const char *name,
int *found); int *found);
static long long vshCommandOptLongLong(const vshCmd *cmd, const char *name, static long long vshCommandOptLongLong(const vshCmd *cmd, const char *name,
...@@ -2515,7 +2517,7 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd) ...@@ -2515,7 +2517,7 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd)
{ {
virDomainPtr dom; virDomainPtr dom;
virDomainInfo info; virDomainInfo info;
int kilobytes; unsigned long kilobytes;
int ret = TRUE; int ret = TRUE;
if (!vshConnectionUsability(ctl, ctl->conn)) if (!vshConnectionUsability(ctl, ctl->conn))
...@@ -2524,10 +2526,10 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd) ...@@ -2524,10 +2526,10 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd)
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE; return FALSE;
kilobytes = vshCommandOptInt(cmd, "kilobytes", &kilobytes); kilobytes = vshCommandOptUL(cmd, "kilobytes", NULL);
if (kilobytes <= 0) { if (kilobytes <= 0) {
virDomainFree(dom); virDomainFree(dom);
vshError(ctl, _("Invalid value of %d for memory size"), kilobytes); vshError(ctl, _("Invalid value of %lu for memory size"), kilobytes);
return FALSE; return FALSE;
} }
...@@ -2539,7 +2541,7 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd) ...@@ -2539,7 +2541,7 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd)
if (kilobytes > info.maxMem) { if (kilobytes > info.maxMem) {
virDomainFree(dom); virDomainFree(dom);
vshError(ctl, _("Requested memory size %d kb is larger than maximum of %lu kb"), vshError(ctl, _("Requested memory size %lu kb is larger than maximum of %lu kb"),
kilobytes, info.maxMem); kilobytes, info.maxMem);
return FALSE; return FALSE;
} }
...@@ -9735,6 +9737,26 @@ vshCommandOptInt(const vshCmd *cmd, const char *name, int *found) ...@@ -9735,6 +9737,26 @@ vshCommandOptInt(const vshCmd *cmd, const char *name, int *found)
return res; return res;
} }
static unsigned long
vshCommandOptUL(const vshCmd *cmd, const char *name, int *found)
{
vshCmdOpt *arg = vshCommandOpt(cmd, name);
unsigned long res = 0;
int num_found = FALSE;
char *end_p = NULL;
if ((arg != NULL) && (arg->data != NULL)) {
res = strtoul(arg->data, &end_p, 10);
if ((arg->data == end_p) || (*end_p!= 0))
num_found = FALSE;
else
num_found = TRUE;
}
if (found)
*found = num_found;
return res;
}
/* /*
* Returns option as STRING * Returns option as STRING
*/ */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册