Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
45738083
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,发现更多精彩内容 >>
提交
45738083
编写于
1月 21, 2008
作者:
D
Daniel P. Berrange
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use virFileReadAll in virsh.c
上级
53365f4c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
31 addition
and
78 deletion
+31
-78
ChangeLog
ChangeLog
+7
-0
src/libvirt_sym.version
src/libvirt_sym.version
+2
-0
src/util.c
src/util.c
+3
-3
src/util.h
src/util.h
+4
-3
src/virsh.c
src/virsh.c
+15
-72
未找到文件。
ChangeLog
浏览文件 @
45738083
Mon Jan 21 10:25:04 EST 2008 Daniel P. Berrange <berrange@redhat.com>
* src/util.c, src/util.h: Rename virFileReadAll to __virFileReadAll,
and add macro for compat
* src/libvirt_sym.version: Export __virFileReadAll
* src/virsh.c: Use virFileReadAll for loading XML files
Mon Jan 21 10:12:04 EST 2008 Daniel P. Berrange <berrange@redhat.com>
* src/openvz_driver.c: Remove no-op networking APIs
...
...
src/libvirt_sym.version
浏览文件 @
45738083
...
...
@@ -131,5 +131,7 @@
__virDomainMigratePerform;
__virDomainMigrateFinish;
__virFileReadAll;
local: *;
};
src/util.c
浏览文件 @
45738083
...
...
@@ -316,9 +316,9 @@ ssize_t safewrite(int fd, const void *buf, size_t count)
}
int
virFileReadAll
(
const
char
*
path
,
int
maxlen
,
char
**
buf
)
int
__
virFileReadAll
(
const
char
*
path
,
int
maxlen
,
char
**
buf
)
{
FILE
*
fh
;
struct
stat
st
;
...
...
src/util.h
浏览文件 @
45738083
...
...
@@ -33,9 +33,10 @@ int virRun(virConnectPtr conn, char **argv, int *status);
int
saferead
(
int
fd
,
void
*
buf
,
size_t
count
);
ssize_t
safewrite
(
int
fd
,
const
void
*
buf
,
size_t
count
);
int
virFileReadAll
(
const
char
*
path
,
int
maxlen
,
char
**
buf
);
int
__virFileReadAll
(
const
char
*
path
,
int
maxlen
,
char
**
buf
);
#define virFileReadAll(p,m,b) __virFileReadAll((p),(m),(b))
int
virFileMatchesNameSuffix
(
const
char
*
file
,
const
char
*
name
,
...
...
src/virsh.c
浏览文件 @
45738083
...
...
@@ -48,6 +48,7 @@
#include "internal.h"
#include "console.h"
#include "util.h"
static
char
*
progname
;
...
...
@@ -56,6 +57,8 @@ static char *progname;
#define FALSE 0
#endif
#define VIRSH_MAX_XML_FILE 10*1024*1024
#define VSH_PROMPT_RW "virsh # "
#define VSH_PROMPT_RO "virsh > "
...
...
@@ -858,66 +861,6 @@ static vshCmdOptDef opts_create[] = {
{
NULL
,
0
,
0
,
NULL
}
};
/* Read in a whole file and return it as a string.
* If it fails, it logs an error and returns NULL.
* String must be freed by caller.
*/
static
char
*
readFile
(
vshControl
*
ctl
,
const
char
*
filename
)
{
char
*
retval
;
int
len
=
0
,
fd
;
if
((
fd
=
open
(
filename
,
O_RDONLY
))
==
-
1
)
{
vshError
(
ctl
,
FALSE
,
_
(
"Failed to open '%s': %s"
),
filename
,
strerror
(
errno
));
return
NULL
;
}
if
(
!
(
retval
=
malloc
(
len
+
1
)))
goto
out_of_memory
;
while
(
1
)
{
char
buffer
[
1024
];
char
*
new
;
int
ret
;
if
((
ret
=
read
(
fd
,
buffer
,
sizeof
(
buffer
)))
==
0
)
break
;
if
(
ret
==
-
1
)
{
if
(
errno
==
EINTR
)
continue
;
vshError
(
ctl
,
FALSE
,
_
(
"Failed to open '%s': read: %s"
),
filename
,
strerror
(
errno
));
goto
error
;
}
if
(
!
(
new
=
realloc
(
retval
,
len
+
ret
+
1
)))
goto
out_of_memory
;
retval
=
new
;
memcpy
(
retval
+
len
,
buffer
,
ret
);
len
+=
ret
;
}
retval
[
len
]
=
'\0'
;
return
retval
;
out_of_memory:
vshError
(
ctl
,
FALSE
,
_
(
"Error allocating memory: %s"
),
strerror
(
errno
));
error:
if
(
retval
)
free
(
retval
);
close
(
fd
);
return
NULL
;
}
static
int
cmdCreate
(
vshControl
*
ctl
,
vshCmd
*
cmd
)
{
...
...
@@ -934,8 +877,8 @@ cmdCreate(vshControl * ctl, vshCmd * cmd)
if
(
!
found
)
return
FALSE
;
buffer
=
readFile
(
ctl
,
from
);
if
(
buffer
==
NULL
)
return
FALSE
;
if
(
virFileReadAll
(
from
,
VIRSH_MAX_XML_FILE
,
&
buffer
)
<
0
)
return
FALSE
;
dom
=
virDomainCreateLinux
(
ctl
->
conn
,
buffer
,
0
);
free
(
buffer
);
...
...
@@ -982,8 +925,8 @@ cmdDefine(vshControl * ctl, vshCmd * cmd)
if
(
!
found
)
return
FALSE
;
buffer
=
readFile
(
ctl
,
from
);
if
(
buffer
==
NULL
)
return
FALSE
;
if
(
virFileReadAll
(
from
,
VIRSH_MAX_XML_FILE
,
&
buffer
)
<
0
)
return
FALSE
;
dom
=
virDomainDefineXML
(
ctl
->
conn
,
buffer
);
free
(
buffer
);
...
...
@@ -2372,8 +2315,8 @@ cmdNetworkCreate(vshControl * ctl, vshCmd * cmd)
if
(
!
found
)
return
FALSE
;
buffer
=
readFile
(
ctl
,
from
);
if
(
buffer
==
NULL
)
return
FALSE
;
if
(
virFileReadAll
(
from
,
VIRSH_MAX_XML_FILE
,
&
buffer
)
<
0
)
return
FALSE
;
network
=
virNetworkCreateXML
(
ctl
->
conn
,
buffer
);
free
(
buffer
);
...
...
@@ -2420,8 +2363,8 @@ cmdNetworkDefine(vshControl * ctl, vshCmd * cmd)
if
(
!
found
)
return
FALSE
;
buffer
=
readFile
(
ctl
,
from
);
if
(
buffer
==
NULL
)
return
FALSE
;
if
(
virFileReadAll
(
from
,
VIRSH_MAX_XML_FILE
,
&
buffer
)
<
0
)
return
FALSE
;
network
=
virNetworkDefineXML
(
ctl
->
conn
,
buffer
);
free
(
buffer
);
...
...
@@ -3107,8 +3050,8 @@ cmdAttachDevice(vshControl * ctl, vshCmd * cmd)
return
FALSE
;
}
buffer
=
readFile
(
ctl
,
from
);
if
(
buffer
==
NULL
)
return
FALSE
;
if
(
virFileReadAll
(
from
,
VIRSH_MAX_XML_FILE
,
&
buffer
)
<
0
)
return
FALSE
;
ret
=
virDomainAttachDevice
(
dom
,
buffer
);
free
(
buffer
);
...
...
@@ -3161,8 +3104,8 @@ cmdDetachDevice(vshControl * ctl, vshCmd * cmd)
return
FALSE
;
}
buffer
=
readFile
(
ctl
,
from
);
if
(
buffer
==
NULL
)
return
FALSE
;
if
(
virFileReadAll
(
from
,
VIRSH_MAX_XML_FILE
,
&
buffer
)
<
0
)
return
FALSE
;
ret
=
virDomainDetachDevice
(
dom
,
buffer
);
free
(
buffer
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录