Setting the uid/gid of the child process was the only thing done by
the hook function in this case, and that can now be done more simply
with virCommandSetUID/GID.
---
src/qemu/qemu_capabilities.c | 61 +++++++++++---------------------------------
1 file changed, 15 insertions(+), 46 deletions(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index e390cb1..be9b69a 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -279,37 +279,10 @@ static const char *qemuCapsArchToString(virArch arch)
}
-struct _qemuCapsHookData {
- uid_t runUid;
- gid_t runGid;
-};
-typedef struct _qemuCapsHookData qemuCapsHookData;
-typedef qemuCapsHookData *qemuCapsHookDataPtr;
-
-static int qemuCapsHook(void * data)
-{
- int ret;
- qemuCapsHookDataPtr hookData = data;
-
- if (!hookData) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("QEMU uid:gid not specified by caller"));
- ret = -1;
- goto cleanup;
- }
-
- VIR_DEBUG("Switch QEMU uid:gid to %d:%d",
- hookData->runUid, hookData->runGid);
- ret = virSetUIDGID(hookData->runUid, hookData->runGid);
-
-cleanup:
- return ret;
-}
-
static virCommandPtr
qemuCapsProbeCommand(const char *qemu,
qemuCapsPtr caps,
- qemuCapsHookDataPtr hookData)
+ uid_t runUid, gid_t runGid)
{
virCommandPtr cmd = virCommandNew(qemu);
@@ -322,7 +295,8 @@ qemuCapsProbeCommand(const char *qemu,
virCommandAddEnvPassCommon(cmd);
virCommandClearCaps(cmd);
- virCommandSetPreExecHook(cmd, qemuCapsHook, hookData);
+ virCommandSetGID(cmd, runGid);
+ virCommandSetUID(cmd, runUid);
return cmd;
}
@@ -416,7 +390,7 @@ no_memory:
}
static int
-qemuCapsProbeMachineTypes(qemuCapsPtr caps, qemuCapsHookDataPtr hookData)
+qemuCapsProbeMachineTypes(qemuCapsPtr caps, uid_t runUid, gid_t runGid)
{
char *output;
int ret = -1;
@@ -433,7 +407,7 @@ qemuCapsProbeMachineTypes(qemuCapsPtr caps, qemuCapsHookDataPtr
hookData)
return -1;
}
- cmd = qemuCapsProbeCommand(caps->binary, caps, hookData);
+ cmd = qemuCapsProbeCommand(caps->binary, caps, runUid, runGid);
virCommandAddArgList(cmd, "-M", "?", NULL);
virCommandSetOutputBuffer(cmd, &output);
@@ -572,7 +546,7 @@ cleanup:
}
static int
-qemuCapsProbeCPUModels(qemuCapsPtr caps, qemuCapsHookDataPtr hookData)
+qemuCapsProbeCPUModels(qemuCapsPtr caps, uid_t runUid, gid_t runGid)
{
char *output = NULL;
int ret = -1;
@@ -590,7 +564,7 @@ qemuCapsProbeCPUModels(qemuCapsPtr caps, qemuCapsHookDataPtr
hookData)
return 0;
}
- cmd = qemuCapsProbeCommand(caps->binary, caps, hookData);
+ cmd = qemuCapsProbeCommand(caps->binary, caps, runUid, runGid);
virCommandAddArgList(cmd, "-cpu", "?", NULL);
virCommandSetOutputBuffer(cmd, &output);
@@ -1601,7 +1575,7 @@ qemuCapsParseDeviceStr(qemuCapsPtr caps, const char *str)
static int
qemuCapsExtractDeviceStr(const char *qemu,
qemuCapsPtr caps,
- qemuCapsHookDataPtr hookData)
+ uid_t runUid, gid_t runGid)
{
char *output = NULL;
virCommandPtr cmd;
@@ -1615,7 +1589,7 @@ qemuCapsExtractDeviceStr(const char *qemu,
* understand '-device name,?', and always exits with status 1 for
* the simpler '-device ?', so this function is really only useful
* if -help includes "device driver,?". */
- cmd = qemuCapsProbeCommand(qemu, caps, hookData);
+ cmd = qemuCapsProbeCommand(qemu, caps, runUid, runGid);
virCommandAddArgList(cmd,
"-device", "?",
"-device", "pci-assign,?",
@@ -2183,7 +2157,6 @@ qemuCapsInitHelp(qemuCapsPtr caps, uid_t runUid, gid_t runGid)
char *help = NULL;
int ret = -1;
const char *tmp;
- qemuCapsHookData hookData;
VIR_DEBUG("caps=%p", caps);
@@ -2196,9 +2169,7 @@ qemuCapsInitHelp(qemuCapsPtr caps, uid_t runUid, gid_t runGid)
caps->arch = virArchFromHost();
}
- hookData.runUid = runUid;
- hookData.runGid = runGid;
- cmd = qemuCapsProbeCommand(caps->binary, NULL, &hookData);
+ cmd = qemuCapsProbeCommand(caps->binary, NULL, runUid, runGid);
virCommandAddArgList(cmd, "-help", NULL);
virCommandSetOutputBuffer(cmd, &help);
@@ -2227,13 +2198,13 @@ qemuCapsInitHelp(qemuCapsPtr caps, uid_t runUid, gid_t runGid)
* understands the 0.13.0+ notion of "-device driver,". */
if (qemuCapsGet(caps, QEMU_CAPS_DEVICE) &&
strstr(help, "-device driver,?") &&
- qemuCapsExtractDeviceStr(caps->binary, caps, &hookData) < 0)
+ qemuCapsExtractDeviceStr(caps->binary, caps, runUid, runGid) < 0)
goto cleanup;
- if (qemuCapsProbeCPUModels(caps, &hookData) < 0)
+ if (qemuCapsProbeCPUModels(caps, runUid, runGid) < 0)
goto cleanup;
- if (qemuCapsProbeMachineTypes(caps, &hookData) < 0)
+ if (qemuCapsProbeMachineTypes(caps, runUid, runGid) < 0)
goto cleanup;
ret = 0;
@@ -2329,7 +2300,6 @@ qemuCapsInitQMP(qemuCapsPtr caps,
char *monarg = NULL;
char *monpath = NULL;
char *pidfile = NULL;
- qemuCapsHookData hookData;
char *archstr;
pid_t pid = 0;
virDomainObj vm;
@@ -2383,9 +2353,8 @@ qemuCapsInitQMP(qemuCapsPtr caps,
NULL);
virCommandAddEnvPassCommon(cmd);
virCommandClearCaps(cmd);
- hookData.runUid = runUid;
- hookData.runGid = runGid;
- virCommandSetPreExecHook(cmd, qemuCapsHook, &hookData);
+ virCommandSetGID(cmd, runGid);
+ virCommandSetUID(cmd, runUid);
if (virCommandRun(cmd, &status) < 0)
goto cleanup;
--
1.8.1