]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Add virRunWithHook util function
authorLaine Stump <laine@laine.org>
Wed, 20 Jan 2010 23:30:36 +0000 (00:30 +0100)
committerDaniel Veillard <veillard@redhat.com>
Wed, 20 Jan 2010 23:30:36 +0000 (00:30 +0100)
* 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.

src/util/util.c
src/util/util.h

index 67fae0025363e674736f47fceb02910ade0cdaf4..578d12bcd9a8da7e2381abdbd61ad183734f7d8b 100644 (file)
@@ -804,9 +804,11 @@ error:
  * only if the command could not be run.
  */
 int
-virRun(virConnectPtr conn,
-       const char *const*argv,
-       int *status) {
+virRunWithHook(virConnectPtr conn,
+               const char *const*argv,
+               virExecHook hook,
+               void *data,
+               int *status) {
     pid_t childpid;
     int exitstatus, execret, waitret;
     int ret = -1;
@@ -823,7 +825,7 @@ virRun(virConnectPtr conn,
 
     if ((execret = __virExec(conn, argv, NULL, NULL,
                              &childpid, -1, &outfd, &errfd,
-                             VIR_EXEC_NONE, NULL, NULL, NULL)) < 0) {
+                             VIR_EXEC_NONE, hook, data, NULL)) < 0) {
         ret = execret;
         goto error;
     }
@@ -879,9 +881,11 @@ virRun(virConnectPtr conn,
 #else /* __MINGW32__ */
 
 int
-virRun(virConnectPtr conn,
-       const char *const *argv ATTRIBUTE_UNUSED,
-       int *status)
+virRunWithHook(virConnectPtr conn,
+               const char *const *argv ATTRIBUTE_UNUSED,
+               virExecHook hook ATTRIBUTE_UNUSED,
+               void *data ATTRIBUTE_UNUSED,
+               int *status)
 {
     if (status)
         *status = ENOTSUP;
@@ -907,6 +911,13 @@ virExec(virConnectPtr conn,
 
 #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
    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.  */
index d556daa4145136fea2a8de4a2bff9d67be9eb5ee..5e70038e8b4c615d559cd24e063d8a6d5d4883a2 100644 (file)
@@ -81,6 +81,9 @@ int virExec(virConnectPtr conn,
             int *errfd,
             int flags) 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;