Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
0c0ed675
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,发现更多精彩内容 >>
提交
0c0ed675
编写于
5月 06, 2011
作者:
C
Cole Robinson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
openvz: Convert virExec usage to virCommand
v2: Use virCommand's autocleanup v3: Don't free 'names' on success
上级
1fcafb02
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
45 addition
and
53 deletion
+45
-53
src/openvz/openvz_conf.c
src/openvz/openvz_conf.c
+12
-25
src/openvz/openvz_driver.c
src/openvz/openvz_driver.c
+33
-28
未找到文件。
src/openvz/openvz_conf.c
浏览文件 @
0c0ed675
...
@@ -74,53 +74,40 @@ strtoI(const char *str)
...
@@ -74,53 +74,40 @@ strtoI(const char *str)
static
int
static
int
openvzExtractVersionInfo
(
const
char
*
cmd
,
int
*
retversion
)
openvzExtractVersionInfo
(
const
char
*
cmd
str
,
int
*
retversion
)
{
{
const
char
*
const
vzarg
[]
=
{
cmd
,
"--help"
,
NULL
};
int
ret
=
-
1
;
const
char
*
const
vzenv
[]
=
{
"LC_ALL=C"
,
NULL
};
pid_t
child
;
int
newstdout
=
-
1
;
int
ret
=
-
1
,
status
;
unsigned
long
version
;
unsigned
long
version
;
char
*
help
=
NULL
;
char
*
tmp
;
char
*
tmp
;
virCommandPtr
cmd
=
virCommandNewArgList
(
cmdstr
,
"--help"
,
NULL
);
if
(
retversion
)
if
(
retversion
)
*
retversion
=
0
;
*
retversion
=
0
;
if
(
virExec
(
vzarg
,
vzenv
,
NULL
,
virCommandAddEnvString
(
cmd
,
"LC_ALL=C"
);
&
child
,
-
1
,
&
newstdout
,
NULL
,
VIR_EXEC_NONE
)
<
0
)
virCommandSetOutputBuffer
(
cmd
,
&
help
);
return
-
1
;
char
*
help
=
NULL
;
if
(
virCommandRun
(
cmd
,
NULL
)
<
0
)
int
len
=
virFileReadLimFD
(
newstdout
,
4096
,
&
help
);
goto
cleanup
;
if
(
len
<
0
)
goto
cleanup2
;
tmp
=
help
;
tmp
=
help
;
/* expected format: vzctl version <major>.<minor>.<micro> */
/* expected format: vzctl version <major>.<minor>.<micro> */
if
((
tmp
=
STRSKIP
(
tmp
,
"vzctl version "
))
==
NULL
)
if
((
tmp
=
STRSKIP
(
tmp
,
"vzctl version "
))
==
NULL
)
goto
cleanup
2
;
goto
cleanup
;
if
(
virParseVersionString
(
tmp
,
&
version
)
<
0
)
if
(
virParseVersionString
(
tmp
,
&
version
)
<
0
)
goto
cleanup
2
;
goto
cleanup
;
if
(
retversion
)
if
(
retversion
)
*
retversion
=
version
;
*
retversion
=
version
;
ret
=
0
;
ret
=
0
;
cleanup2:
cleanup:
virCommandFree
(
cmd
);
VIR_FREE
(
help
);
VIR_FREE
(
help
);
if
(
VIR_CLOSE
(
newstdout
)
<
0
)
ret
=
-
1
;
rewait:
if
(
waitpid
(
child
,
&
status
,
0
)
!=
child
)
{
if
(
errno
==
EINTR
)
goto
rewait
;
ret
=
-
1
;
}
return
ret
;
return
ret
;
}
}
...
...
src/openvz/openvz_driver.c
浏览文件 @
0c0ed675
...
@@ -41,7 +41,6 @@
...
@@ -41,7 +41,6 @@
#include <sys/utsname.h>
#include <sys/utsname.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <fcntl.h>
#include <signal.h>
#include <paths.h>
#include <paths.h>
#include <pwd.h>
#include <pwd.h>
#include <stdio.h>
#include <stdio.h>
...
@@ -59,6 +58,7 @@
...
@@ -59,6 +58,7 @@
#include "bridge.h"
#include "bridge.h"
#include "files.h"
#include "files.h"
#include "logging.h"
#include "logging.h"
#include "command.h"
#define VIR_FROM_THIS VIR_FROM_OPENVZ
#define VIR_FROM_THIS VIR_FROM_OPENVZ
...
@@ -1397,21 +1397,16 @@ static int openvzListDomains(virConnectPtr conn ATTRIBUTE_UNUSED,
...
@@ -1397,21 +1397,16 @@ static int openvzListDomains(virConnectPtr conn ATTRIBUTE_UNUSED,
int
*
ids
,
int
nids
)
{
int
*
ids
,
int
nids
)
{
int
got
=
0
;
int
got
=
0
;
int
veid
;
int
veid
;
pid_t
pid
;
int
outfd
=
-
1
;
int
outfd
=
-
1
;
int
rc
=
-
1
;
int
ret
;
int
ret
;
char
buf
[
32
];
char
buf
[
32
];
char
*
endptr
;
char
*
endptr
;
const
char
*
cmd
[]
=
{
VZLIST
,
"-ovpsid"
,
"-H"
,
NULL
}
;
virCommandPtr
cmd
=
virCommandNewArgList
(
VZLIST
,
"-ovpsid"
,
"-H"
,
NULL
)
;
ret
=
virExec
(
cmd
,
NULL
,
NULL
,
virCommandSetOutputFD
(
cmd
,
&
outfd
);
&
pid
,
-
1
,
&
outfd
,
NULL
,
VIR_EXEC_NONE
);
if
(
virCommandRunAsync
(
cmd
,
NULL
)
<
0
)
if
(
ret
==
-
1
)
{
goto
cleanup
;
openvzError
(
VIR_ERR_INTERNAL_ERROR
,
_
(
"Could not exec %s"
),
VZLIST
);
VIR_FORCE_CLOSE
(
outfd
);
return
-
1
;
}
while
(
got
<
nids
)
{
while
(
got
<
nids
)
{
ret
=
openvz_readline
(
outfd
,
buf
,
32
);
ret
=
openvz_readline
(
outfd
,
buf
,
32
);
...
@@ -1425,13 +1420,20 @@ static int openvzListDomains(virConnectPtr conn ATTRIBUTE_UNUSED,
...
@@ -1425,13 +1420,20 @@ static int openvzListDomains(virConnectPtr conn ATTRIBUTE_UNUSED,
ids
[
got
]
=
veid
;
ids
[
got
]
=
veid
;
got
++
;
got
++
;
}
}
waitpid
(
pid
,
NULL
,
0
);
if
(
virCommandWait
(
cmd
,
NULL
)
<
0
)
goto
cleanup
;
if
(
VIR_CLOSE
(
outfd
)
<
0
)
{
if
(
VIR_CLOSE
(
outfd
)
<
0
)
{
virReportSystemError
(
errno
,
"%s"
,
_
(
"failed to close file"
));
virReportSystemError
(
errno
,
"%s"
,
_
(
"failed to close file"
));
return
-
1
;
goto
cleanup
;
}
}
return
got
;
rc
=
got
;
cleanup:
VIR_FORCE_CLOSE
(
outfd
);
virCommandFree
(
cmd
);
return
rc
;
}
}
static
int
openvzNumDomains
(
virConnectPtr
conn
)
{
static
int
openvzNumDomains
(
virConnectPtr
conn
)
{
...
@@ -1449,20 +1451,17 @@ static int openvzListDefinedDomains(virConnectPtr conn ATTRIBUTE_UNUSED,
...
@@ -1449,20 +1451,17 @@ static int openvzListDefinedDomains(virConnectPtr conn ATTRIBUTE_UNUSED,
char
**
const
names
,
int
nnames
)
{
char
**
const
names
,
int
nnames
)
{
int
got
=
0
;
int
got
=
0
;
int
veid
,
outfd
=
-
1
,
ret
;
int
veid
,
outfd
=
-
1
,
ret
;
pid_t
pid
;
int
rc
=
-
1
;
char
vpsname
[
32
];
char
vpsname
[
32
];
char
buf
[
32
];
char
buf
[
32
];
char
*
endptr
;
char
*
endptr
;
const
char
*
cmd
[]
=
{
VZLIST
,
"-ovpsid"
,
"-H"
,
"-S"
,
NULL
};
virCommandPtr
cmd
=
virCommandNewArgList
(
VZLIST
,
"-ovpsid"
,
"-H"
,
"-S"
,
NULL
);
/* the -S options lists only stopped domains */
/* the -S options lists only stopped domains */
ret
=
virExec
(
cmd
,
NULL
,
NULL
,
virCommandSetOutputFD
(
cmd
,
&
outfd
);
&
pid
,
-
1
,
&
outfd
,
NULL
,
VIR_EXEC_NONE
);
if
(
virCommandRunAsync
(
cmd
,
NULL
)
<
0
)
if
(
ret
==
-
1
)
{
openvzError
(
VIR_ERR_INTERNAL_ERROR
,
_
(
"Could not exec %s"
),
VZLIST
);
goto
out
;
goto
out
;
}
while
(
got
<
nnames
)
{
while
(
got
<
nnames
)
{
ret
=
openvz_readline
(
outfd
,
buf
,
32
);
ret
=
openvz_readline
(
outfd
,
buf
,
32
);
...
@@ -1480,18 +1479,24 @@ static int openvzListDefinedDomains(virConnectPtr conn ATTRIBUTE_UNUSED,
...
@@ -1480,18 +1479,24 @@ static int openvzListDefinedDomains(virConnectPtr conn ATTRIBUTE_UNUSED,
}
}
got
++
;
got
++
;
}
}
waitpid
(
pid
,
NULL
,
0
);
if
(
virCommandWait
(
cmd
,
NULL
)
<
0
)
goto
out
;
if
(
VIR_CLOSE
(
outfd
)
<
0
)
{
if
(
VIR_CLOSE
(
outfd
)
<
0
)
{
virReportSystemError
(
errno
,
"%s"
,
_
(
"failed to close file"
));
virReportSystemError
(
errno
,
"%s"
,
_
(
"failed to close file"
));
goto
out
;
goto
out
;
}
}
return
got
;
rc
=
got
;
out:
out:
VIR_FORCE_CLOSE
(
outfd
);
VIR_FORCE_CLOSE
(
outfd
);
virCommandFree
(
cmd
);
if
(
rc
>=
0
)
{
for
(
;
got
>=
0
;
got
--
)
for
(
;
got
>=
0
;
got
--
)
VIR_FREE
(
names
[
got
]);
VIR_FREE
(
names
[
got
]);
return
-
1
;
}
return
rc
;
}
}
static
int
openvzGetProcessInfo
(
unsigned
long
long
*
cpuTime
,
int
vpsid
)
static
int
openvzGetProcessInfo
(
unsigned
long
long
*
cpuTime
,
int
vpsid
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录