Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
3796e580
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看板
提交
3796e580
编写于
11月 05, 2008
作者:
C
Cole Robinson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Log stdout and stderr in virRun
上级
a9a11b53
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
127 addition
and
19 deletion
+127
-19
ChangeLog
ChangeLog
+4
-0
src/util.c
src/util.c
+123
-19
未找到文件。
ChangeLog
浏览文件 @
3796e580
Wed Nov 5 13:56:00 EST 2008 Cole Robinson <crobinso@redhat.com>
* src/util.c: Log stdout and stderr in virRun
Wed Nov 5 13:39:00 EST 2008 Cole Robinson <crobinso@redhat.com>
* src/util.c: Log the argv passed to virExec and virRun
...
...
src/util.c
浏览文件 @
3796e580
...
...
@@ -31,6 +31,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <poll.h>
#include <sys/types.h>
#include <sys/stat.h>
#if HAVE_SYS_WAIT_H
...
...
@@ -414,6 +415,86 @@ virExec(virConnectPtr conn,
flags
);
}
static
int
virPipeReadUntilEOF
(
virConnectPtr
conn
,
int
outfd
,
int
errfd
,
char
**
outbuf
,
char
**
errbuf
)
{
struct
pollfd
fds
[
2
];
int
i
;
int
finished
[
2
];
fds
[
0
].
fd
=
outfd
;
fds
[
0
].
events
=
POLLIN
;
finished
[
0
]
=
0
;
fds
[
1
].
fd
=
errfd
;
fds
[
1
].
events
=
POLLIN
;
finished
[
1
]
=
0
;
while
(
!
(
finished
[
0
]
&&
finished
[
1
]))
{
if
(
poll
(
fds
,
ARRAY_CARDINALITY
(
fds
),
-
1
)
<
0
)
{
if
(
errno
==
EAGAIN
)
continue
;
goto
pollerr
;
}
for
(
i
=
0
;
i
<
ARRAY_CARDINALITY
(
fds
);
++
i
)
{
char
data
[
1024
],
**
buf
;
int
got
,
size
;
if
(
!
(
fds
[
i
].
revents
))
continue
;
else
if
(
fds
[
i
].
revents
&
POLLHUP
)
finished
[
i
]
=
1
;
if
(
!
(
fds
[
i
].
revents
&
POLLIN
))
{
if
(
fds
[
i
].
revents
&
POLLHUP
)
continue
;
ReportError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"Unknown poll response."
));
goto
error
;
}
got
=
read
(
fds
[
i
].
fd
,
data
,
sizeof
(
data
));
if
(
got
==
0
)
{
finished
[
i
]
=
1
;
continue
;
}
if
(
got
<
0
)
{
if
(
errno
==
EINTR
)
continue
;
if
(
errno
==
EAGAIN
)
break
;
goto
pollerr
;
}
buf
=
((
fds
[
i
].
fd
==
outfd
)
?
outbuf
:
errbuf
);
size
=
(
*
buf
?
strlen
(
*
buf
)
:
0
);
if
(
VIR_REALLOC_N
(
*
buf
,
size
+
got
+
1
)
<
0
)
{
ReportError
(
conn
,
VIR_ERR_NO_MEMORY
,
NULL
);
goto
error
;
}
memmove
(
*
buf
+
size
,
data
,
got
);
(
*
buf
)[
size
+
got
]
=
'\0'
;
}
continue
;
pollerr:
ReportError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
_
(
"poll error: %s"
),
strerror
(
errno
));
goto
error
;
}
return
0
;
error:
VIR_FREE
(
*
outbuf
);
VIR_FREE
(
*
errbuf
);
return
-
1
;
}
/**
* @conn connection to report errors against
* @argv NULL terminated argv to run
...
...
@@ -433,43 +514,66 @@ int
virRun
(
virConnectPtr
conn
,
const
char
*
const
*
argv
,
int
*
status
)
{
int
childpid
,
exitstatus
,
ret
;
char
*
argv_str
;
int
childpid
,
exitstatus
,
execret
,
waitret
;
int
ret
=
-
1
;
int
errfd
=
-
1
,
outfd
=
-
1
;
char
*
outbuf
=
NULL
;
char
*
errbuf
=
NULL
;
char
*
argv_str
=
NULL
;
if
((
argv_str
=
virArgvToString
(
argv
))
==
NULL
)
{
ReportError
(
conn
,
VIR_ERR_NO_MEMORY
,
_
(
"command debug string"
));
return
-
1
;
goto
error
;
}
DEBUG0
(
argv_str
);
VIR_FREE
(
argv_str
);
if
((
ret
=
__virExec
(
conn
,
argv
,
NULL
,
NULL
,
&
childpid
,
-
1
,
NULL
,
NULL
,
VIR_EXEC_NONE
))
<
0
)
return
ret
;
if
((
execret
=
__virExec
(
conn
,
argv
,
NULL
,
NULL
,
&
childpid
,
-
1
,
&
outfd
,
&
errfd
,
VIR_EXEC_NONE
))
<
0
)
{
ret
=
execret
;
goto
error
;
}
if
(
virPipeReadUntilEOF
(
conn
,
outfd
,
errfd
,
&
outbuf
,
&
errbuf
)
<
0
)
goto
error
;
if
(
outbuf
)
DEBUG
(
"Command stdout: %s"
,
outbuf
);
if
(
errbuf
)
DEBUG
(
"Command stderr: %s"
,
errbuf
);
while
((
ret
=
waitpid
(
childpid
,
&
exitstatus
,
0
)
==
-
1
)
&&
errno
==
EINTR
);
if
(
ret
==
-
1
)
{
while
((
waitret
=
waitpid
(
childpid
,
&
exitstatus
,
0
)
==
-
1
)
&&
errno
==
EINTR
);
if
(
waitret
==
-
1
)
{
ReportError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
_
(
"cannot wait for '%s': %s"
),
argv
[
0
],
strerror
(
errno
));
return
-
1
;
goto
error
;
}
if
(
status
==
NULL
)
{
errno
=
EINVAL
;
if
(
WIFEXITED
(
exitstatus
)
&&
WEXITSTATUS
(
exitstatus
)
==
0
)
return
0
;
if
(
WIFEXITED
(
exitstatus
)
&&
WEXITSTATUS
(
exitstatus
)
!=
0
)
{
ReportError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
_
(
"%s exited with non-zero status %d and signal %d"
),
argv
[
0
],
WIFEXITED
(
exitstatus
)
?
WEXITSTATUS
(
exitstatus
)
:
0
,
WIFSIGNALED
(
exitstatus
)
?
WTERMSIG
(
exitstatus
)
:
0
);
return
-
1
;
ReportError
(
conn
,
VIR_ERR_INTERNAL_ERROR
,
_
(
"'%s' exited with non-zero status %d and "
"signal %d: %s"
),
argv_str
,
WIFEXITED
(
exitstatus
)
?
WEXITSTATUS
(
exitstatus
)
:
0
,
WIFSIGNALED
(
exitstatus
)
?
WTERMSIG
(
exitstatus
)
:
0
,
(
errbuf
?
errbuf
:
""
));
goto
error
;
}
}
else
{
*
status
=
exitstatus
;
return
0
;
}
ret
=
0
;
error:
VIR_FREE
(
outbuf
);
VIR_FREE
(
errbuf
);
VIR_FREE
(
argv_str
);
return
ret
;
}
#else
/* __MINGW32__ */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录