- 05 6月, 2012 1 次提交
-
-
由 Eric Blake 提交于
It is possible to deadlock libvirt by having a domain with XML longer than PIPE_BUF, and by writing a hook script that closes stdin early. This is because libvirt was keeping a copy of the child's stdin read fd open, which means the write fd in the parent will never see EPIPE (remember, libvirt should always be run with SIGPIPE ignored, so we should never get a SIGPIPE signal). Since there is no error, libvirt blocks waiting for a write to complete, even though the only reader is also libvirt. The solution is to ensure that only the child can act as a reader before the parent does any writes; and then dealing with the fallout of dealing with EPIPE. Thankfully, this is not a security hole - since the only way to trigger the deadlock is to install a custom hook script, anyone that already has privileges to install a hook script already has privileges to do any number of other equally disruptive things to libvirt; it would only be a security hole if an unprivileged user could install a hook script to DoS a privileged user. * src/util/command.c (virCommandRun): Close parent's copy of child read fd earlier. (virCommandProcessIO): Don't let EPIPE be fatal; the child may be done parsing input. * tests/commandhelper.c (main): Set up a SIGPIPE situation. * tests/commandtest.c (test20): Trigger it. * tests/commanddata/test20.log: New file.
-
- 04 6月, 2012 2 次提交
-
-
由 Jiri Denemark 提交于
EBADF errors are logged as warnings as they normally indicate a double close bug. This patch also provides VIR_MASS_CLOSE helper to be user in the only case of mass close after fork when EBADF should rather be ignored.
-
由 Jiri Denemark 提交于
Probably a result of copy&paste...
-
- 31 5月, 2012 2 次提交
-
-
由 Wen Congyang 提交于
We should not set *outfd or *errfd if virExecWithHook() failed because the caller may close these fds. Bug present since v0.4.5 (commit 60ed1d2a).
-
由 Eric Blake 提交于
KAMEZAWA Hiroyuki reported a nasty double-free bug when virCommand is used to convert a string into input to a child command. The problem is that the poll() loop of virCommandProcessIO would close() the write end of the pipe in order to let the child see EOF, then the caller virCommandRun() would also close the same fd number, with the second close possibly nuking an fd opened by some other thread in the meantime. This in turn can have all sorts of bad effects. The bug has been present since the introduction of virCommand in commit f16ad06f. This is based on his first attempt at a patch, at https://bugzilla.redhat.com/show_bug.cgi?id=823716 * src/util/command.c (_virCommand): Drop inpipe member. (virCommandProcessIO): Add argument, to avoid closing caller's fd without informing caller. (virCommandRun, virCommandNewArgs): Adjust clients.
-
- 30 5月, 2012 1 次提交
-
-
由 Michal Privoznik 提交于
Currently, we are logging only one side of pipes we create in virCommandRequireHandshake(); This is enough in cases where pipe2() returns two consecutive FDs. However, it is not guaranteed and it may return any FDs. Therefore, it's wise to log the other ends as well.
-
- 03 5月, 2012 1 次提交
-
-
由 Marc-André Lureau 提交于
Fix a few more places where pid_t is printed with wrong type
-
- 30 3月, 2012 1 次提交
-
-
由 Daniel P. Berrange 提交于
The code is splattered with a mix of sizeof foo sizeof (foo) sizeof(foo) Standardize on sizeof(foo) and add a syntax check rule to enforce it Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
-
- 02 3月, 2012 1 次提交
-
-
由 Eric Blake 提交于
Nuke the last vestiges of printing pid_t values with the wrong types, at least in code compiled on mingw64. There may be other places, but for now they are only compiled on systems where the existing %d doesn't trigger gcc warnings. * src/rpc/virnetsocket.c (virNetSocketNew): Use %lld and casting, rather than assuming any particular int type for pid_t. * src/util/command.c (virCommandRunAsync, virPidWait) (virPidAbort): Likewise. (verify): Drop a now stale assertion.
-
- 04 2月, 2012 1 次提交
-
-
由 Eric Blake 提交于
Sometimes, its easier to run children with 2>&1 in shell notation, and just deal with stdout and stderr interleaved. This was already possible for fd handling; extend it to also work when doing string capture of a child process. * docs/internals/command.html.in: Document this. * src/util/command.c (virCommandSetErrorBuffer): Likewise. (virCommandRun, virExecWithHook): Implement it. * tests/commandtest.c (test14): Test it. * daemon/remote.c (remoteDispatchAuthPolkit): Use new command feature.
-
- 01 2月, 2012 3 次提交
-
-
由 Michal Privoznik 提交于
If we are building not on a WIN32 architecture and without HAVE_CAPNG virSetCapabilities has unused argument and virClearCapabilities is unused as well.
-
由 Taku Izumi 提交于
This patch extends virExecWithHook() to receive capability information. Signed-off-by: NTaku Izumi <izumi.taku@jp.fujitsu.com> Signed-off-by: NShota Hirae <m11g1401@hibikino.ne.jp>
-
由 Taku Izumi 提交于
This patch introduces virSetCapabilities() function and implements virCommandAllowCap() function. Existing virClearCapabilities() is function to clear all capabilities. Instead virSetCapabilities() is function to set arbitrary capabilities. Signed-off-by: NTaku Izumi <izumi.taku@jp.fujitsu.com> Signed-off-by: NShota Hirae <m11g1401@hibikino.ne.jp>
-
- 25 1月, 2012 1 次提交
-
-
由 Laszlo Ersek 提交于
POLLIN and POLLHUP are not mutually exclusive. Currently the following seems possible: the child writes 3K to its stdout or stderr pipe, and immediately closes it. We get POLLIN|POLLHUP (I'm not sure that's possible on Linux, but SUSv4 seems to allow it). We read 1K and throw away the rest. When poll() returns and we're about to check the /revents/ member in a given array element, let's map all the revents bits to two (independent) ideas: "let's attempt to read()", and "let's attempt to write()". This should cover all errors, EOFs, and normal conditions; the read()/write() call should report any pending error. Under this approach, both POLLHUP and POLLERR are mapped to "needs read()" if we're otherwise prepared for POLLIN. POLLERR also maps to "needs write()" if we're otherwise prepared for POLLOUT. The rest of the mappings (POLLPRI etc.) would be easy, but probably useless for pipes. Additionally, SUSv4 doesn't appear to forbid POLLIN|POLLERR (or POLLOUT|POLLERR) set simultaneously. One could argue that the read() or write() call would return without blocking in these cases (with an error), so POLLIN / POLLOUT would be justified beside POLLERR. The code now penalizes POLLIN|POLLERR differently from plain POLLERR. The former (ie. read() returning -1) is terminal and we jump to cleanup, while plain POLLERR masks only the affected file descriptor for the future. Let's unify those. Signed-off-by: NLaszlo Ersek <lersek@redhat.com>
-
- 07 1月, 2012 1 次提交
-
-
由 Eric Blake 提交于
Commit db371a21 mistakenly added new functions inside a #ifndef WIN32 guard, even though they are needed on all platforms. * src/util/command.c (virCommandFDSet): Move outside WIN32 conditional.
-
- 05 1月, 2012 1 次提交
-
-
由 Michal Privoznik 提交于
Currently, virCommand implementation uses FD_ macros from sys/select.h. However, those cannot handle more opened files than FD_SETSIZE. Therefore switch to generalized implementation based on array of integers.
-
- 04 1月, 2012 1 次提交
-
-
由 Michal Privoznik 提交于
It is a good practise to set revents to zero before doing any poll(). Moreover, we should check if event we waited for really occurred or if any of fds we were polling on didn't encountered hangup.
-
- 04 12月, 2011 1 次提交
-
-
由 Eric Blake 提交于
virBufferContentAndReset (intentionally) returns NULL for a buffer with no content, but it is feasible to invoke a command with an explicit empty string. * src/util/command.c (virCommandAddEnvBuffer): Reject empty string. (virCommandAddArgBuffer): Allow explicit empty argument. * tests/commandtest.c (test9): Test it. * tests/commanddata/test9.log: Adjust.
-
- 14 10月, 2011 1 次提交
-
-
由 Eric Blake 提交于
virCommandTransferFD promises that the fd is no longer owned by the caller. Normally, we want the fd to remain open until the child runs, but in error situations, we must close it earlier. * src/util/command.c (virCommandTransferFD): Close fd now if we can't track it to close later. (virCommandKeepFD): Adjust helper to make this easier.
-
- 27 9月, 2011 1 次提交
-
-
由 Michal Privoznik 提交于
as they are not used with debugging turned off.
-
- 13 8月, 2011 1 次提交
-
-
由 Daniel P. Berrange 提交于
The functions for manipulating pidfiles are in util/util.{c,h}. We will shortly be adding some further pidfile related functions. To avoid further growing util.c, this moves the pidfile related functions into a dedicated virpidfile.{c,h}. The functions are also all renamed to have 'virPidFile' as their name prefix * util/util.h, util/util.c: Remove all pidfile code * util/virpidfile.c, util/virpidfile.h: Add new APIs for pidfile handling. * lxc/lxc_controller.c, lxc/lxc_driver.c, network/bridge_driver.c, qemu/qemu_process.c: Add virpidfile.h include and adapt for API renames
-
- 03 8月, 2011 1 次提交
-
-
由 Eric Blake 提交于
Coverity complained that 395 out of 409 virAsprintf calls are checked, and therefore assumed that the remaining cases are bugs waiting to happen. But in each of these cases, a failed virAsprintf will properly set the target string to NULL, and pass on that failure to the caller, without wasting efforts to check the call. Adding the ignore_value silences Coverity. * src/conf/domain_audit.c (virDomainAuditGetRdev): Ignore virAsprintf return value, when it behaves like we need. * src/network/bridge_driver.c (networkDnsmasqLeaseFileNameDefault) (networkRadvdConfigFileName, networkBridgeDummyNicName) (networkRadvdPidfileBasename): Likewise. * src/util/storage_file.c (absolutePathFromBaseFile): Likewise. * src/openvz/openvz_driver.c (openvzGenerateContainerVethName): Likewise. * src/util/command.c (virCommandTranslateStatus): Likewise.
-
- 26 7月, 2011 1 次提交
-
-
由 Laine Stump 提交于
Although most functions in libvirt return 0 on success and < 0 on failure, there are a few functions lingering around that return errno (a positive value) on failure, and sometimes code calling those functions incorrectly assumes the <0 standard. I noticed one of these the other day when auditing networkStartDhcpDaemon after Guido Gunther found a place where success was improperly returned on failure (that patch has been acked and is pending a push). The problem was that it expected the return value from virFileReadPid to be < 0 on failure, but it was actually positive (it was also neglected to set the return code in this case, similar to the bug found by Guido). This all led to the fact that *all* of the virFile*Pid functions in util.c are returning errno on failure. This patch remedies that problem by changing them all to return -errno on failure, and makes any necessary changes to callers of the functions. (In the meantime, I also properly set the return code on failure of virFileReadPid in networkStartDhcpDaemon).
-
- 22 7月, 2011 3 次提交
-
-
由 Eric Blake 提交于
In preparation for a future patch adding new virFile APIs. * src/util/files.h, src/util/files.c: Move... * src/util/virfile.h, src/util/virfile.c: ...here, and rename functions to virFile prefix. Macro names are intentionally left alone. * *.c: All '#include "files.h"' uses changed. * src/Makefile.am (UTIL_SOURCES): Reflect rename. * cfg.mk (exclude_file_name_regexp--sc_prohibit_close): Likewise. * src/libvirt_private.syms: Likewise. * docs/hacking.html.in: Likewise. * HACKING: Regenerate.
-
由 Eric Blake 提交于
Since libvirt is multi-threaded, we should use FD_CLOEXEC as much as possible in the parent, and only relax fds to inherited after forking, to avoid leaking an fd created in one thread to a fork run in another thread. This gets us closer to that ideal, by making virCommand automatically clear FD_CLOEXEC on fds intended for the child, as well as avoiding a window of time with non-cloexec pipes created for capturing output. * src/util/command.c (virExecWithHook): Use CLOEXEC in parent. In child, guarantee that all fds to pass to child are inheritable. (getDevNull): Use CLOEXEC. (prepareStdFd): New helper function. (virCommandRun, virCommandRequireHandshake): Use pipe2. * src/qemu/qemu_command.c (qemuBuildCommandLine): Simplify caller.
-
由 Eric Blake 提交于
We already have a precedent of function documentation in C files, where it is closer to the implementation (witness libvirt.h vs. libvirt.c); maintaining docs in both files risks docs going stale. While I was at it, I used consistent doxygen style on all comments. * src/util/command.h: Remove duplicate docs, and move unique documentation... * src/util/command.c: ...here. Suggested by Matthias Bolte.
-
- 16 7月, 2011 1 次提交
-
-
由 Eric Blake 提交于
Enforce the recent flags cleanups - we want to use 'unsigned int flags' in any of our APIs (except where backwards compatibility is important, in the public migration APIs), and that all flags are checked for validity (except when there are stub functions that completely ignore the flags argument). There are a few minor tweaks done here to avoid false positives: signed arguments passed to open() are renamed oflags, and flags arguments that are legitimately ignored are renamed flags_unused. * cfg.mk (sc_flags_usage): New rule. (exclude_file_name_regexp--sc_flags_usage): And a few exemptions. (sc_flags_debug): Tweak wording. * src/util/iohelper.c (runIO, main): Rename variable. * src/util/util.c (virSetInherit): Likewise. * src/fdstream.h (virFDStreamOpenFile, virFDStreamCreateFile): Likewise. * src/fdstream.c (virFDStreamOpenFileInternal) (virFDStreamOpenFile, virFDStreamCreateFile): Likewise. * src/util/command.c (virExecWithHook) [WIN32]: Likewise. * src/util/util.c (virFileOpenAs, virDirCreate) [WIN32]: Likewise. * src/locking/lock_manager.c (virLockManagerPluginNew) [!HAVE_DLFCN_H]: Likewise. * src/locking/lock_driver_nop.c (virLockManagerNopNew) (virLockManagerNopAddResource, virLockManagerNopAcquire) (virLockManagerNopRelease, virLockManagerNopInquire): Likewise.
-
- 15 7月, 2011 1 次提交
-
-
由 Eric Blake 提交于
When using virCommandRunAsync and saving the pid for later, it is useful to be able to reap that pid in the same way that it would have been auto-reaped by virCommand if we had passed NULL for the pid argument in the first place. * src/util/command.c (virPidWait, virPidAbort): New functions, created from... (virCommandWait, virCommandAbort): ...bodies of these. (includes): Drop duplicate <stdlib.h>. Ensure that our pid_t assumptions hold. (virCommandRunAsync): Improve documentation. * src/util/command.h (virPidWait, virPidAbort): New prototypes. * src/libvirt_private.syms: Export them. * docs/internals/command.html.in: Document them.
-
- 13 7月, 2011 1 次提交
-
-
由 Eric Blake 提交于
Silently ignored flags get in the way of new features that use those flags. Also, an upcoming syntax check will favor unsigned flags. * src/nodeinfo.h (nodeGetCPUStats, nodeGetMemoryStats): Drop unused attribute. * src/interface/netcf_driver.c (interfaceOpenInterface) (interfaceDefineXML, interfaceCreate, interfaceDestroy): Reject unknown flags. * src/network/bridge_driver.c (networkOpenNetwork) (networkGetXMLDesc): Likewise. * src/nwfilter/nwfilter_driver.c (nwfilterOpen): Likewise. * src/secret/secret_driver.c (secretOpen, secretDefineXML) (secretGetXMLDesc, secretSetValue): Likewise. * src/util/logging.c (virLogDefineFilter, virLogDefineOutput) (virLogMessage): Likewise; also use unsigned flags. * src/util/logging.h (virLogDefineFilter, virLogDefineOutput) (virLogMessage): Change signature. * src/util/command.c (virExecWithHook): Likewise.
-
- 08 7月, 2011 1 次提交
-
-
由 Eric Blake 提交于
Gnulib finally learned how to do pthread_sigmask on mingw. * .gnulib: Update to latest, for pthread_sigmask. * bootstrap.conf (gnulib_modules): Add pthread_sigmask. * configure.ac (AC_CHECK_FUNCS): Drop redundant check. * src/rpc/virnetclient.c (virNetClientSetTLSSession) (virNetClientIOEventLoop): Make code unconditional. * src/util/command.c (virFork): Likewise. * tools/virsh.c (doMigrate, cmdMigrate): Likewise.
-
- 22 6月, 2011 1 次提交
-
-
由 Osier Yang 提交于
virCommandProcessIO: It's reading from stdout or stderr of child, but not writing.
-
- 14 6月, 2011 2 次提交
-
-
由 Eric Blake 提交于
Previously, the parent process opened 'null' to /dev/null, then the child process closes 'null' as well as 'childout'. But if childout was set to be null, then this is a double close. At least the double close was confined to the child process after a fork, and therefore there is no risk of another thread opening an fd of the same value to be bitten by the double close, but it is always better to avoid double-close to begin with. Additionally, if all three fds were specified, then opening 'null' was wasted. This patch fixes things to lazily open null on the first use, then guarantees it gets closed exactly once. * src/util/command.c (getDevNull): New helper function. (virExecWithHook): Use it to avoid spurious opens and double close.
-
由 Eric Blake 提交于
This also reduces malloc pressure for invoking a child when VIR_DEBUG is enabled. * src/util/command.c (virExecWithHook): Drop debug, since the only caller (virCommandRunAsync) also prints debug info.
-
- 08 6月, 2011 2 次提交
-
-
由 Eric Blake 提交于
Similar in nature to commit fd21ecfd, which shut up valgrind. sigaction is apparently a nasty interface for analyzer tools, at least for how many false positives it generates. * src/util/command.c (virExecWithHook): Initialize entire var, since coverity gripes about the (unused and non-standard) sa_restorer.
-
由 Cole Robinson 提交于
Seems reasonable to have all command wrappers in the same place v2: Dont move SetInherit v3: Comment spelling fix Adjust WARN0 comment Remove spurious #include movement Don't include sys/types.h Combine virExec enums Signed-off-by: NCole Robinson <crobinso@redhat.com>
-
- 03 6月, 2011 2 次提交
-
-
由 Eric Blake 提交于
Coverity complained that infd could be -1 at the point where it is passed to write, when in reality, this code can only be reached if infd is non-negative. * src/util/command.c (virCommandProcessIO): Help out coverity.
-
由 Eric Blake 提交于
Detected by Coverity. While it is possible on OOM condition, as well as with bad code that passes binary == NULL, it is unlikely to be encountered in the wild. * src/util/command.c (virCommandNewArgList): Don't leak memory.
-
- 02 6月, 2011 1 次提交
-
-
由 Daniel P. Berrange 提交于
Allow the parent process to perform a bi-directional handshake with the child process during fork/exec. The child process will fork and do its initial setup. Immediately prior to the exec(), it will stop & wait for a handshake from the parent process. The parent process will spawn the child and wait until the child reaches the handshake point. It will do whatever extra setup work is required, before signalling the child to continue. The implementation of this is done using two pairs of blocking pipes. The first pair is used to block the parent, until the child writes a single byte. Then the second pair pair is used to block the child, until the parent confirms with another single byte. * src/util/command.c, src/util/command.h, src/libvirt_private.syms: Add APIs to perform a handshake
-
- 16 5月, 2011 1 次提交
-
-
由 Daniel P. Berrange 提交于
Mingw execve() has a broken signature. Disable this function until gnulib fixes the signature, since we don't really need this on Win32 anyway. * src/util/command.c: Disable virCommandExec on Win32
-
- 14 5月, 2011 1 次提交
-
-
由 Matthias Bolte 提交于
kill, SIGTERM and SIGKILL require additional header.
-