提交 d2259ada 编写于 作者: L Laine Stump 提交者: Daniel Veillard

Add virRunWithHook util function

* src/util/util.[ch]: similar to virExecWithHook, but waits for child to
  exit. Useful for doing things like setuid after the fork but before the
  exec.
上级 1671b647
...@@ -804,9 +804,11 @@ error: ...@@ -804,9 +804,11 @@ error:
* only if the command could not be run. * only if the command could not be run.
*/ */
int int
virRun(virConnectPtr conn, virRunWithHook(virConnectPtr conn,
const char *const*argv, const char *const*argv,
int *status) { virExecHook hook,
void *data,
int *status) {
pid_t childpid; pid_t childpid;
int exitstatus, execret, waitret; int exitstatus, execret, waitret;
int ret = -1; int ret = -1;
...@@ -823,7 +825,7 @@ virRun(virConnectPtr conn, ...@@ -823,7 +825,7 @@ virRun(virConnectPtr conn,
if ((execret = __virExec(conn, argv, NULL, NULL, if ((execret = __virExec(conn, argv, NULL, NULL,
&childpid, -1, &outfd, &errfd, &childpid, -1, &outfd, &errfd,
VIR_EXEC_NONE, NULL, NULL, NULL)) < 0) { VIR_EXEC_NONE, hook, data, NULL)) < 0) {
ret = execret; ret = execret;
goto error; goto error;
} }
...@@ -879,9 +881,11 @@ virRun(virConnectPtr conn, ...@@ -879,9 +881,11 @@ virRun(virConnectPtr conn,
#else /* __MINGW32__ */ #else /* __MINGW32__ */
int int
virRun(virConnectPtr conn, virRunWithHook(virConnectPtr conn,
const char *const *argv ATTRIBUTE_UNUSED, const char *const *argv ATTRIBUTE_UNUSED,
int *status) virExecHook hook ATTRIBUTE_UNUSED,
void *data ATTRIBUTE_UNUSED,
int *status)
{ {
if (status) if (status)
*status = ENOTSUP; *status = ENOTSUP;
...@@ -907,6 +911,13 @@ virExec(virConnectPtr conn, ...@@ -907,6 +911,13 @@ virExec(virConnectPtr conn,
#endif /* __MINGW32__ */ #endif /* __MINGW32__ */
int
virRun(virConnectPtr conn,
const char *const*argv,
int *status) {
return virRunWithHook(conn, argv, NULL, NULL, status);
}
/* Like gnulib's fread_file, but read no more than the specified maximum /* Like gnulib's fread_file, but read no more than the specified maximum
number of bytes. If the length of the input is <= max_len, and number of bytes. If the length of the input is <= max_len, and
upon error while reading that data, it works just like fread_file. */ upon error while reading that data, it works just like fread_file. */
......
...@@ -81,6 +81,9 @@ int virExec(virConnectPtr conn, ...@@ -81,6 +81,9 @@ int virExec(virConnectPtr conn,
int *errfd, int *errfd,
int flags) ATTRIBUTE_RETURN_CHECK; int flags) ATTRIBUTE_RETURN_CHECK;
int virRun(virConnectPtr conn, const char *const*argv, int *status) ATTRIBUTE_RETURN_CHECK; int virRun(virConnectPtr conn, const char *const*argv, int *status) ATTRIBUTE_RETURN_CHECK;
int virRunWithHook(virConnectPtr conn, const char *const*argv,
virExecHook hook, void *data,
int *status) ATTRIBUTE_RETURN_CHECK;
int virFileReadLimFD(int fd, int maxlen, char **buf) ATTRIBUTE_RETURN_CHECK; int virFileReadLimFD(int fd, int maxlen, char **buf) ATTRIBUTE_RETURN_CHECK;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册