libvirt/tests
Eric Blake 25f87817ab virFork: simplify semantics
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>
2014-03-03 12:40:32 -07:00
..
capabilityschemadata capabilities: add baselabel per sec driver/virt type to secmodel 2013-10-29 07:06:04 -06:00
commanddata
confdata
cputestdata tests: Add more tests for virConnectBaselineCPU 2014-01-28 21:27:37 +01:00
domainconfdata Rename virDomainGetRootFilesystem to virDomainGetFilesystemForTarget 2014-02-20 15:50:46 +00:00
domainschemadata
domainsnapshotxml2xmlin snapshot: Add support for specifying snapshot disk backing type 2014-01-29 12:56:35 +01:00
domainsnapshotxml2xmlout snapshot: Add support for specifying snapshot disk backing type 2014-01-29 12:56:35 +01:00
fchostdata/fc_host
interfaceschemadata
lxcconf2xmldata LXC from native: convert blkio throttle config 2014-02-12 17:52:47 +00:00
lxcxml2xmldata schema: fix idmap validation 2014-01-10 10:54:14 -07:00
lxcxml2xmloutdata Allow root directory in filesystem source dir schema 2013-11-07 18:43:15 +01:00
networkxml2confdata network: change default of forwardPlainNames to 'yes' 2014-02-04 12:00:26 +02:00
networkxml2xmlin Add forwarder attribute to <dns/> element 2013-09-17 17:47:33 -06:00
networkxml2xmlout network: change default of forwardPlainNames to 'yes' 2014-02-04 12:00:26 +02:00
networkxml2xmlupdatein
networkxml2xmlupdateout network: change default of forwardPlainNames to 'yes' 2014-02-04 12:00:26 +02:00
nodedevschemadata
nodeinfodata Add test for linuxNodeGetCPUStats 2014-01-27 11:04:02 +01:00
nwfilterxml2xmlin
nwfilterxml2xmlout
qemucapabilitiesdata qemu: Add USB keyboard capability 2014-02-19 09:16:31 +01:00
qemuhelpdata
qemuhotplugtestdata conf: re-situate <bandwidth> element in <interface> 2014-02-25 16:03:05 +02:00
qemumonitorjsondata qemu: Add monitor APIs to fetch CPUID data from QEMU 2013-11-08 09:44:36 +01:00
qemuxml2argvdata conf: re-situate <bandwidth> element in <interface> 2014-02-25 16:03:05 +02:00
qemuxml2xmloutdata conf: Add keyboard input device type 2014-02-19 09:16:31 +01:00
qemuxmlnsdata
secretxml2xmlin Add tests for secret XML parsing 2014-02-14 16:47:14 +01:00
securityselinuxlabeldata
sexpr2xmldata conf: Add keyboard input device type 2014-02-19 09:16:31 +01:00
storagepoolschemadata
storagepoolxml2xmlin storage: document gluster pool 2013-11-25 11:03:19 -07:00
storagepoolxml2xmlout storage: document gluster pool 2013-11-25 11:03:19 -07:00
storagevolschemadata
storagevolxml2argvdata
storagevolxml2xmlin storage: improve directory support in gluster pool 2013-11-25 12:46:19 -07:00
storagevolxml2xmlout storage: improve directory support in gluster pool 2013-11-25 12:46:19 -07:00
sysinfodata aarch64: Fix sysinfo test. 2014-01-01 16:34:13 +00:00
virfiledata Fix bug in identifying sub-mounts 2013-11-28 11:49:01 +00:00
virpcitestdata tests: Fix PCI test data filenames for Windows 2014-01-25 12:53:11 +01:00
virscsidata tests: Modify the scsi util tests 2014-01-30 16:34:43 +01:00
virusbtestdata/sys_bus_usb/devices Add tests for virUSBDeviceFind functions 2014-03-03 14:35:22 +01:00
vmwareverdata VMware: Add Fusion version test 2013-09-30 16:58:37 -05:00
vmx2xmldata conf: Add keyboard input device type 2014-02-19 09:16:31 +01:00
xencapsdata
xmconfigdata conf: Add keyboard input device type 2014-02-19 09:16:31 +01:00
xml2sexprdata
xml2vmxdata esx: Fix floppy.fileName handling in the vmx file parser 2013-10-15 11:39:02 +01:00
.valgrind.supp
capabilityschematest
commandhelper.c
commandtest.c virFork: simplify semantics 2014-03-03 12:40:32 -07:00
cpuset
cputest.c tests: Add more tests for virConnectBaselineCPU 2014-01-28 21:27:37 +01:00
define-dev-segfault
domainconftest.c Rename virDomainGetRootFilesystem to virDomainGetFilesystemForTarget 2014-02-20 15:50:46 +00:00
domainschematest LXC: Fix handling of RAM filesystem size units 2013-10-09 17:44:45 +02:00
domainsnapshotschematest
domainsnapshotxml2xmltest.c domainsnapshotxml2xmltest: Add test case for empty driver element 2013-12-05 09:41:30 +01:00
esxutilstest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
eventtest.c
fchosttest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
fdstreamtest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
int-overflow
interfaceschematest
interfacexml2xmltest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
jsontest.c Error out on unterminated arrays and objects in JSON parser 2013-11-20 12:35:44 +01:00
libvirtd-fail
libvirtd-pool
libvirtdconftest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
lxcconf2xmltest.c LXC from native: map vlan network type 2014-02-12 17:52:47 +00:00
lxcxml2xmltest.c Exercise the ABI stability check code in test suite 2014-01-10 20:32:48 +00:00
Makefile.am Replace space with a tab in the Makefile 2014-03-03 14:35:22 +01:00
metadatatest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
networkschematest
networkxml2conftest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
networkxml2xmltest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
networkxml2xmlupdatetest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
nodedevschematest
nodedevxml2xmltest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
nodeinfotest.c Add test for linuxNodeGetCPUStats 2014-01-27 11:04:02 +01:00
nwfilterschematest
nwfilterxml2xmltest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
object-locking.ml
objecteventtest.c Fix memory leak in testDomainCreateXMLMixed() 2014-01-14 14:49:07 +01:00
oomtrace.pl
openvzutilstest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
openvzutilstest.conf
pkix_asn1_tab.c
qemuagenttest.c tests: avoid littering /tmp 2014-02-27 18:10:13 -07:00
qemuargv2xmltest.c Introduce new OOM testing support 2014-02-20 15:36:10 +00:00
qemucapabilitiestest.c qemu: ask for -enable-fips when FIPS is required 2013-12-18 07:05:29 -07:00
qemuhelptest.c qemu: Add USB keyboard capability 2014-02-19 09:16:31 +01:00
qemuhotplugtest.c Renamed virDomainEventState to virObjectEventState 2013-12-10 11:35:34 +00:00
qemumonitorjsontest.c maint: align whitespaces with project conventions. 2014-01-20 14:35:08 +01:00
qemumonitortest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
qemumonitortestutils.c Remove (nearly) all use of getuid()/getgid() 2013-10-21 14:03:52 +01:00
qemumonitortestutils.h tests: Learn qemuMonitorTestNew optional greeting 2013-10-01 10:48:47 +02:00
qemuxml2argvmock.c qemuxml2argvmock: Mock time() on non-linux platforms too 2014-02-06 15:15:10 +01:00
qemuxml2argvtest.c Introduce new OOM testing support 2014-02-20 15:36:10 +00:00
qemuxml2xmltest.c qemu: introduce spiceport chardev backend 2014-02-11 13:43:55 +01:00
qemuxmlnstest.c Introduce new OOM testing support 2014-02-20 15:36:10 +00:00
read-bufsiz
read-non-seekable
reconnect.c util: make it easier to grab only regular command exit 2014-03-03 12:40:32 -07:00
schematestutils.sh
seclabeltest.c
secretschematest Add tests for secret XML parsing 2014-02-14 16:47:14 +01:00
secretxml2xmltest.c Add tests for secret XML parsing 2014-02-14 16:47:14 +01:00
securityselinuxhelper.c tests: avoid compile failure on linux kernels older than 2.6.19 2013-10-07 08:40:30 -06:00
securityselinuxlabeltest.c Fix memory leak in securityselinuxlabeltest.c 2014-01-15 11:18:23 +01:00
securityselinuxtest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
sexpr2xmltest.c Exercise the ABI stability check code in test suite 2014-01-10 20:32:48 +00:00
shunloadhelper.c
shunloadtest.c
sockettest.c virsocket: Introduce virSocketAddrIsWildcard 2013-10-11 11:05:06 +02:00
ssh.c
start
statstest.c util: make it easier to grab only regular command exit 2014-03-03 12:40:32 -07:00
storagebackendsheepdogtest.c
storagepoolschematest
storagepoolxml2xmltest.c storage: document gluster pool 2013-11-25 11:03:19 -07:00
storagevolschematest
storagevolxml2argvtest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
storagevolxml2xmltest.c storage: improve directory support in gluster pool 2013-11-25 12:46:19 -07:00
sysinfotest.c tests: sysinfotest: Actual/expected were swapped in error message. 2014-01-01 16:34:13 +00:00
test_conf.c
test_conf.sh
test-lib.sh test-lib: Make case skipping possible 2013-09-13 10:25:56 +02:00
testutils.c util: make it easier to grab only regular process exit 2014-03-03 12:40:31 -07:00
testutils.h Rename virDomainGetRootFilesystem to virDomainGetFilesystemForTarget 2014-02-20 15:50:46 +00:00
testutilslxc.c
testutilslxc.h Add unit test for virCgroupGetBlkioIo*Serviced 2014-02-20 16:20:09 +01:00
testutilsqemu.c util: Add one argument for several scsi utils 2014-01-30 15:48:28 +08:00
testutilsqemu.h
testutilsxen.c
testutilsxen.h
utiltest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
vcpupin
viratomictest.c maint: fix comma style issues: tests, tools 2013-11-20 09:14:55 -07:00
virauthconfigtest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
virbitmaptest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
virbuftest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
vircapstest.c Fix leaks in vircapstest 2014-02-12 14:41:47 +01:00
vircgroupmock.c Fix misspelled cpuacct.usage_percpu in cgroup mock. 2014-02-20 16:20:10 +01:00
vircgrouptest.c build: fix build on 32-bit hosts 2014-02-21 17:21:58 -07:00
virdbustest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
virdrivermoduletest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
virendiantest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
virfiletest.c Fix bug in identifying sub-mounts 2013-11-28 11:49:01 +00:00
virhashdata.h
virhashtest.c maint: avoid 'const fooPtr' in hashes 2013-10-14 11:40:24 -06:00
viridentitytest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
virkeycodetest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
virkeyfiletest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
virkmodtest.c tests: Add test for new virkmod functions 2014-02-04 08:59:37 -05:00
virlockspacetest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
virlogtest.c Fix flaw in detecting log format 2013-10-14 10:31:01 +01:00
virnetdevbandwidthtest.c virnetdevbandwidthtest: Introduce some more tests 2014-01-31 16:52:27 +01:00
virnetmessagetest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
virnetserverclientmock.c Add test case for virNetServerClient object identity code 2013-09-24 09:37:26 +01:00
virnetserverclienttest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
virnetsockettest.c tests: fix syntax in previous patch 2014-01-01 09:58:27 -07:00
virnettlscontexttest.c virnettlscontexttest fails with GNUTLS 3.0.28 2013-12-23 13:16:07 -07:00
virnettlshelpers.c
virnettlshelpers.h
virnettlssessiontest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
virpcimock.c tests: Fix PCI test data filenames for Windows 2014-01-25 12:53:11 +01:00
virpcitest.c virpcitest: Test virPCIDeviceDetach failure 2014-01-20 14:21:41 +01:00
virportallocatortest.c build: skip virportallocatortest on cygwin 2014-02-26 13:30:46 -07:00
virscsitest.c tests: Modify the scsi util tests 2014-01-30 16:34:43 +01:00
virsh-all
virsh-optparse
virsh-schedinfo
virsh-synopsis
virsh-undefine
virsh-uriprecedence tests: Don't test user config file if ran as root 2013-09-13 10:25:56 +02:00
virshtest.c virsh: allow alias to expand to opt=value pair 2013-10-24 11:17:41 +01:00
virstoragetest.c tests: be more explicit on qcow2 versions in virstoragetest 2014-01-15 09:19:14 -07:00
virstringtest.c Add virStringReplace method for substring replacement 2014-02-24 10:51:22 +00:00
virsystemdmock.c Fix indentation in virsystemdmock 2014-03-03 14:35:23 +01:00
virsystemdtest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
virt-aa-helper-test
virtimetest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
viruritest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
virusbmock.c Add tests for virUSBDeviceFind functions 2014-03-03 14:35:22 +01:00
virusbtest.c Add a test for virUSBDeviceList functions 2014-03-03 14:35:22 +01:00
vmwarevertest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
vmx2xmltest.c Add test for transient disk support in VMX files 2014-01-20 09:47:43 -07:00
xencapstest.c Remove test case average timing 2013-10-08 12:39:30 +01:00
xmconfigtest.c Exercise the ABI stability check code in test suite 2014-01-10 20:32:48 +00:00
xml2sexprtest.c Exercise the ABI stability check code in test suite 2014-01-10 20:32:48 +00:00
xml2vmxtest.c Exercise the ABI stability check code in test suite 2014-01-10 20:32:48 +00:00