Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
1ea832d6
L
libvirt
项目概览
openeuler
/
libvirt
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libvirt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
1ea832d6
编写于
4月 06, 2006
作者:
K
Karel Zak
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use stdout rather than stderr, improve allocation checks
上级
6bd95bf2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
62 addition
and
45 deletion
+62
-45
ChangeLog
ChangeLog
+5
-0
src/virsh.c
src/virsh.c
+57
-45
未找到文件。
ChangeLog
浏览文件 @
1ea832d6
Thu Apr 6 11:32:46 CEST 2006 Karel Zak <kzak@redhat.com>
* src/virsh.c: use stdout for standard outputs, improve
allocation checks
Wed Apr 5 09:32:54 EDT 2006 Daniel Veillard <veillard@redhat.com>
* src/hash.c: tiny fix
...
...
src/virsh.c
浏览文件 @
1ea832d6
...
...
@@ -202,11 +202,19 @@ static virDomainPtr vshCommandOptDomain(vshControl * ctl, vshCmd * cmd,
static
void
vshPrint
(
vshControl
*
ctl
,
vshOutType
out
,
const
char
*
format
,
...);
static
const
char
*
vshDomainStateToString
(
int
state
);
static
int
vshConnectionUsability
(
vshControl
*
ctl
,
virConnectPtr
conn
,
int
showerror
);
static
void
*
_vshMalloc
(
vshControl
*
ctl
,
size_t
sz
,
const
char
*
filename
,
int
line
);
#define vshMalloc(_ctl, _sz) _vshMalloc(_ctl, _sz, __FILE__, __LINE__)
static
void
*
_vshCalloc
(
vshControl
*
ctl
,
size_t
nmemb
,
size_t
sz
,
const
char
*
filename
,
int
line
);
#define vshCalloc(_ctl, _nmemb, _sz) _vshCalloc(_ctl, _nmemb, _sz, __FILE__, __LINE__)
static
char
*
_vshStrdup
(
vshControl
*
ctl
,
const
char
*
s
,
const
char
*
filename
,
int
line
);
#define vshStrdup(_ctl, _s) _vshStrdup(_ctl, _s, __FILE__, __LINE__)
/* ---------------
* Commands
* ---------------
...
...
@@ -311,12 +319,8 @@ cmdList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
vshError
(
ctl
,
FALSE
,
"failed to list active domains."
);
return
FALSE
;
}
ids
=
malloc
(
sizeof
(
int
)
*
maxid
);
if
(
ids
==
NULL
)
{
fprintf
(
stderr
,
"Failed to allocate %d bytes
\n
"
,
(
int
)
sizeof
(
int
)
*
maxid
);
exit
(
1
);
}
ids
=
vshMalloc
(
ctl
,
sizeof
(
int
)
*
maxid
);
virConnectListDomains
(
ctl
->
conn
,
&
ids
[
0
],
maxid
);
vshPrint
(
ctl
,
VSH_HEADER
,
"%3s %-20s %s
\n
"
,
"Id"
,
"Name"
,
"State"
);
...
...
@@ -1420,11 +1424,7 @@ vshCommandGetToken(vshControl * ctl, char *str, char **end, char **res)
if
(
sz
==
0
)
return
VSH_TK_END
;
*
res
=
malloc
(
sz
+
1
);
if
(
*
res
==
NULL
)
{
fprintf
(
stderr
,
"Failed to allocate %d bytes
\n
"
,
sz
+
1
);
exit
(
1
);
}
*
res
=
vshMalloc
(
ctl
,
sz
+
1
);
memcpy
(
*
res
,
tkstr
,
sz
);
*
(
*
res
+
sz
)
=
'\0'
;
...
...
@@ -1519,12 +1519,7 @@ vshCommandParse(vshControl * ctl, char *cmdstr)
}
if
(
opt
)
{
/* save option */
vshCmdOpt
*
arg
=
malloc
(
sizeof
(
vshCmdOpt
));
if
(
arg
==
NULL
)
{
fprintf
(
stderr
,
"Failed to allocate %d bytes
\n
"
,
(
int
)
sizeof
(
vshCmdOpt
));
exit
(
1
);
}
vshCmdOpt
*
arg
=
vshMalloc
(
ctl
,
sizeof
(
vshCmdOpt
));
arg
->
def
=
opt
;
arg
->
data
=
tkdata
;
...
...
@@ -1549,13 +1544,7 @@ vshCommandParse(vshControl * ctl, char *cmdstr)
/* commad parsed -- allocate new struct for the command */
if
(
cmd
)
{
vshCmd
*
c
=
malloc
(
sizeof
(
vshCmd
));
if
(
c
==
NULL
)
{
fprintf
(
stderr
,
"Failed to allocate %d bytes
\n
"
,
(
int
)
sizeof
(
vshCmd
));
exit
(
1
);
}
vshCmd
*
c
=
vshMalloc
(
ctl
,
sizeof
(
vshCmd
));
c
->
opts
=
first
;
c
->
def
=
cmd
;
...
...
@@ -1666,7 +1655,7 @@ vshPrint(vshControl * ctl, vshOutType type, const char *format, ...)
return
;
va_start
(
ap
,
format
);
vfprintf
(
std
err
,
format
,
ap
);
vfprintf
(
std
out
,
format
,
ap
);
va_end
(
ap
);
}
...
...
@@ -1687,11 +1676,48 @@ vshError(vshControl * ctl, int doexit, const char *format, ...)
fputc
(
'\n'
,
stderr
);
if
(
doexit
)
{
vshDeinit
(
ctl
);
if
(
ctl
)
vshDeinit
(
ctl
);
exit
(
EXIT_FAILURE
);
}
}
static
void
*
_vshMalloc
(
vshControl
*
ctl
,
size_t
size
,
const
char
*
filename
,
int
line
)
{
void
*
x
;
if
((
x
=
malloc
(
size
)))
return
x
;
vshError
(
ctl
,
TRUE
,
"%s: %d: failed to allocate %d bytes
\n
"
,
filename
,
line
,
(
int
)
size
);
return
NULL
;
}
static
void
*
_vshCalloc
(
vshControl
*
ctl
,
size_t
nmemb
,
size_t
size
,
const
char
*
filename
,
int
line
)
{
void
*
x
;
if
((
x
=
calloc
(
nmemb
,
size
)))
return
x
;
vshError
(
ctl
,
TRUE
,
"%s: %d: failed to allocate %d bytes
\n
"
,
filename
,
line
,
(
int
)
(
size
*
nmemb
));
return
NULL
;
}
static
char
*
_vshStrdup
(
vshControl
*
ctl
,
const
char
*
s
,
const
char
*
filename
,
int
line
)
{
char
*
x
;
if
((
x
=
strdup
(
s
)))
return
x
;
vshError
(
ctl
,
TRUE
,
"%s: %d: failed to allocate %d bytes
\n
"
,
filename
,
line
,
strlen
(
s
));
return
NULL
;
}
/*
* Initialize vistsh
*/
...
...
@@ -1749,7 +1775,7 @@ vshReadlineCommandGenerator(const char *text, int state)
while
((
name
=
commands
[
list_index
].
name
))
{
list_index
++
;
if
(
strncmp
(
name
,
text
,
len
)
==
0
)
return
strdup
(
name
);
return
vshStrdup
(
NULL
,
name
);
}
/* If no names matched, then return NULL. */
...
...
@@ -1771,12 +1797,7 @@ vshReadlineOptionsGenerator(const char *text, int state)
if
(
!
(
p
=
strchr
(
rl_line_buffer
,
' '
)))
return
NULL
;
cmdname
=
calloc
((
p
-
rl_line_buffer
)
+
1
,
1
);
if
(
cmdname
==
NULL
)
{
fprintf
(
stderr
,
"Failed to allocate %d bytes
\n
"
,
(
p
-
rl_line_buffer
)
+
1
);
exit
(
1
);
}
cmdname
=
vshCalloc
(
NULL
,
(
p
-
rl_line_buffer
)
+
1
,
1
);
memcpy
(
cmdname
,
rl_line_buffer
,
p
-
rl_line_buffer
);
cmd
=
vshCmddefSearch
(
cmdname
);
...
...
@@ -1802,12 +1823,7 @@ vshReadlineOptionsGenerator(const char *text, int state)
if
(
strncmp
(
name
,
text
+
2
,
len
-
2
))
continue
;
}
res
=
malloc
(
strlen
(
name
)
+
3
);
if
(
res
==
NULL
)
{
fprintf
(
stderr
,
"Failed to allocate %d bytes
\n
"
,
(
int
)
strlen
(
name
)
+
3
);
exit
(
1
);
}
res
=
vshMalloc
(
NULL
,
strlen
(
name
)
+
3
);
sprintf
(
res
,
"--%s"
,
name
);
return
res
;
}
...
...
@@ -1986,11 +2002,7 @@ vshParseArgv(vshControl * ctl, int argc, char **argv)
for
(
i
=
end
;
i
<
argc
;
i
++
)
sz
+=
strlen
(
argv
[
i
])
+
1
;
/* +1 is for blank space between items */
cmdstr
=
calloc
(
sz
+
1
,
1
);
if
(
cmdstr
==
NULL
)
{
fprintf
(
stderr
,
"Failed to allocate %d bytes
\n
"
,
sz
+
1
);
exit
(
1
);
}
cmdstr
=
vshCalloc
(
ctl
,
sz
+
1
,
1
);
for
(
i
=
end
;
i
<
argc
;
i
++
)
{
strncat
(
cmdstr
,
argv
[
i
],
sz
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录