mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 22:25:25 +00:00
25f87817ab
The old semantics of virFork() violates the priciple of good usability: it requires the caller to check the pid argument after use, *even when virFork returned -1*, in order to properly abort a child process that failed setup done immediately after fork() - that is, the caller must call _exit() in the child. While uses in virfile.c did this correctly, uses in 'virsh lxc-enter-namespace' and 'virt-login-shell' would happily return from the calling function in both the child and the parent, leading to very confusing results. [Thankfully, I found the problem by inspection, and can't actually trigger the double return on error without an LD_PRELOAD library.] It is much better if the semantics of virFork are impossible to abuse. Looking at virFork(), the parent could only ever return -1 with a non-negative pid if it misused pthread_sigmask, but this never happens. Up until this patch series, the child could return -1 with non-negative pid if it fails to set up signals correctly, but we recently fixed that to make the child call _exit() at that point instead of forcing the caller to do it. Thus, the return value and contents of the pid argument are now redundant (a -1 return now happens only for failure to fork, a child 0 return only happens for a successful 0 pid, and a parent 0 return only happens for a successful non-zero pid), so we might as well return the pid directly rather than an integer of whether it succeeded or failed; this is also good from the interface design perspective as users are already familiar with fork() semantics. One last change in this patch: before returning the pid directly, I found cases where using virProcessWait unconditionally on a cleanup path of a virFork's -1 pid return would be nicer if there were a way to avoid it overwriting an earlier message. While such paths are a bit harder to come by with my change to a direct pid return, I decided to keep the virProcessWait change in this patch. * src/util/vircommand.h (virFork): Change signature. * src/util/vircommand.c (virFork): Guarantee that child will only return on success, to simplify callers. Return pid rather than status, now that the situations are always the same. (virExec): Adjust caller, also avoid open-coding process death. * src/util/virprocess.c (virProcessWait): Tweak semantics when pid is -1. (virProcessRunInMountNamespace): Adjust caller. * src/util/virfile.c (virFileAccessibleAs, virFileOpenForked) (virDirCreate): Likewise. * tools/virt-login-shell.c (main): Likewise. * tools/virsh-domain.c (cmdLxcEnterNamespace): Likewise. * tests/commandtest.c (test23): Likewise. Signed-off-by: Eric Blake <eblake@redhat.com> |
||
---|---|---|
.. | ||
capabilityschemadata | ||
commanddata | ||
confdata | ||
cputestdata | ||
domainconfdata | ||
domainschemadata | ||
domainsnapshotxml2xmlin | ||
domainsnapshotxml2xmlout | ||
fchostdata/fc_host | ||
interfaceschemadata | ||
lxcconf2xmldata | ||
lxcxml2xmldata | ||
lxcxml2xmloutdata | ||
networkxml2confdata | ||
networkxml2xmlin | ||
networkxml2xmlout | ||
networkxml2xmlupdatein | ||
networkxml2xmlupdateout | ||
nodedevschemadata | ||
nodeinfodata | ||
nwfilterxml2xmlin | ||
nwfilterxml2xmlout | ||
qemucapabilitiesdata | ||
qemuhelpdata | ||
qemuhotplugtestdata | ||
qemumonitorjsondata | ||
qemuxml2argvdata | ||
qemuxml2xmloutdata | ||
qemuxmlnsdata | ||
secretxml2xmlin | ||
securityselinuxlabeldata | ||
sexpr2xmldata | ||
storagepoolschemadata | ||
storagepoolxml2xmlin | ||
storagepoolxml2xmlout | ||
storagevolschemadata | ||
storagevolxml2argvdata | ||
storagevolxml2xmlin | ||
storagevolxml2xmlout | ||
sysinfodata | ||
virfiledata | ||
virpcitestdata | ||
virscsidata | ||
virusbtestdata/sys_bus_usb/devices | ||
vmwareverdata | ||
vmx2xmldata | ||
xencapsdata | ||
xmconfigdata | ||
xml2sexprdata | ||
xml2vmxdata | ||
.valgrind.supp | ||
capabilityschematest | ||
commandhelper.c | ||
commandtest.c | ||
cpuset | ||
cputest.c | ||
define-dev-segfault | ||
domainconftest.c | ||
domainschematest | ||
domainsnapshotschematest | ||
domainsnapshotxml2xmltest.c | ||
esxutilstest.c | ||
eventtest.c | ||
fchosttest.c | ||
fdstreamtest.c | ||
int-overflow | ||
interfaceschematest | ||
interfacexml2xmltest.c | ||
jsontest.c | ||
libvirtd-fail | ||
libvirtd-pool | ||
libvirtdconftest.c | ||
lxcconf2xmltest.c | ||
lxcxml2xmltest.c | ||
Makefile.am | ||
metadatatest.c | ||
networkschematest | ||
networkxml2conftest.c | ||
networkxml2xmltest.c | ||
networkxml2xmlupdatetest.c | ||
nodedevschematest | ||
nodedevxml2xmltest.c | ||
nodeinfotest.c | ||
nwfilterschematest | ||
nwfilterxml2xmltest.c | ||
object-locking.ml | ||
objecteventtest.c | ||
oomtrace.pl | ||
openvzutilstest.c | ||
openvzutilstest.conf | ||
pkix_asn1_tab.c | ||
qemuagenttest.c | ||
qemuargv2xmltest.c | ||
qemucapabilitiestest.c | ||
qemuhelptest.c | ||
qemuhotplugtest.c | ||
qemumonitorjsontest.c | ||
qemumonitortest.c | ||
qemumonitortestutils.c | ||
qemumonitortestutils.h | ||
qemuxml2argvmock.c | ||
qemuxml2argvtest.c | ||
qemuxml2xmltest.c | ||
qemuxmlnstest.c | ||
read-bufsiz | ||
read-non-seekable | ||
reconnect.c | ||
schematestutils.sh | ||
seclabeltest.c | ||
secretschematest | ||
secretxml2xmltest.c | ||
securityselinuxhelper.c | ||
securityselinuxlabeltest.c | ||
securityselinuxtest.c | ||
sexpr2xmltest.c | ||
shunloadhelper.c | ||
shunloadtest.c | ||
sockettest.c | ||
ssh.c | ||
start | ||
statstest.c | ||
storagebackendsheepdogtest.c | ||
storagepoolschematest | ||
storagepoolxml2xmltest.c | ||
storagevolschematest | ||
storagevolxml2argvtest.c | ||
storagevolxml2xmltest.c | ||
sysinfotest.c | ||
test_conf.c | ||
test_conf.sh | ||
test-lib.sh | ||
testutils.c | ||
testutils.h | ||
testutilslxc.c | ||
testutilslxc.h | ||
testutilsqemu.c | ||
testutilsqemu.h | ||
testutilsxen.c | ||
testutilsxen.h | ||
utiltest.c | ||
vcpupin | ||
viratomictest.c | ||
virauthconfigtest.c | ||
virbitmaptest.c | ||
virbuftest.c | ||
vircapstest.c | ||
vircgroupmock.c | ||
vircgrouptest.c | ||
virdbustest.c | ||
virdrivermoduletest.c | ||
virendiantest.c | ||
virfiletest.c | ||
virhashdata.h | ||
virhashtest.c | ||
viridentitytest.c | ||
virkeycodetest.c | ||
virkeyfiletest.c | ||
virkmodtest.c | ||
virlockspacetest.c | ||
virlogtest.c | ||
virnetdevbandwidthtest.c | ||
virnetmessagetest.c | ||
virnetserverclientmock.c | ||
virnetserverclienttest.c | ||
virnetsockettest.c | ||
virnettlscontexttest.c | ||
virnettlshelpers.c | ||
virnettlshelpers.h | ||
virnettlssessiontest.c | ||
virpcimock.c | ||
virpcitest.c | ||
virportallocatortest.c | ||
virscsitest.c | ||
virsh-all | ||
virsh-optparse | ||
virsh-schedinfo | ||
virsh-synopsis | ||
virsh-undefine | ||
virsh-uriprecedence | ||
virshtest.c | ||
virstoragetest.c | ||
virstringtest.c | ||
virsystemdmock.c | ||
virsystemdtest.c | ||
virt-aa-helper-test | ||
virtimetest.c | ||
viruritest.c | ||
virusbmock.c | ||
virusbtest.c | ||
vmwarevertest.c | ||
vmx2xmltest.c | ||
xencapstest.c | ||
xmconfigtest.c | ||
xml2sexprtest.c | ||
xml2vmxtest.c |