1. 04 6月, 2012 1 次提交
  2. 31 5月, 2012 2 次提交
    • W
      command: check for fork error before closing fd · 746ff701
      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).
      746ff701
    • E
      command: avoid double close bugs · da831afc
      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.
      da831afc
  3. 30 5月, 2012 1 次提交
    • M
      virCommand: Extend debug message for handshake · 7454849e
      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.
      7454849e
  4. 03 5月, 2012 1 次提交
  5. 30 3月, 2012 1 次提交
  6. 02 3月, 2012 1 次提交
    • E
      build: fix output of pid values · 355ec281
      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.
      355ec281
  7. 04 2月, 2012 1 次提交
    • E
      command: allow merging stdout and stderr in string capture · c9ace552
      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.
      c9ace552
  8. 01 2月, 2012 3 次提交
  9. 25 1月, 2012 1 次提交
    • L
      virCommandProcessIO(): make poll() usage more robust · d19149dd
      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>
      d19149dd
  10. 07 1月, 2012 1 次提交
    • E
      build: fix mingw virCommand build · 03ea5673
      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.
      03ea5673
  11. 05 1月, 2012 1 次提交
  12. 04 1月, 2012 1 次提交
    • M
      virCommand: Properly handle POLLHUP · 06b9c5b9
      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.
      06b9c5b9
  13. 04 12月, 2011 1 次提交
    • E
      command: handle empty buffer argument correctly · 2b045d39
      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.
      2b045d39
  14. 14 10月, 2011 1 次提交
    • E
      command: avoid fd leak on failure · 219600c9
      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.
      219600c9
  15. 27 9月, 2011 1 次提交
  16. 13 8月, 2011 1 次提交
    • D
      Move pidfile functions into util/virpidfile.{c,h} · f80a4ed7
      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
      f80a4ed7
  17. 03 8月, 2011 1 次提交
    • E
      build: silence coverity false positives · 44ebb18e
      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.
      44ebb18e
  18. 26 7月, 2011 1 次提交
    • L
      util: change virFile*Pid functions to return < 0 on failure · d6354c16
      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).
      d6354c16
  19. 22 7月, 2011 3 次提交
    • E
      build: rename files.h to virfile.h · 8e22e089
      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.
      8e22e089
    • E
      command: avoid leaking fds across fork · 5d804ffa
      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.
      5d804ffa
    • E
      command: move all docs into .c file · 42891145
      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.
      42891145
  20. 16 7月, 2011 1 次提交
    • E
      build: add syntax check for proper flags use · 761bbb17
      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.
      761bbb17
  21. 15 7月, 2011 1 次提交
    • E
      command: introduce virPidWait, virPidAbort · e208c38b
      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.
      e208c38b
  22. 13 7月, 2011 1 次提交
    • E
      util: reject unknown flags, and prefer unsigned flags · 833fe8ab
      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.
      833fe8ab
  23. 08 7月, 2011 1 次提交
    • E
      build: use gnulib pthread_sigmask · 8437e738
      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.
      8437e738
  24. 22 6月, 2011 1 次提交
  25. 14 6月, 2011 2 次提交
    • E
      command: avoid double close · f3d67544
      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.
      f3d67544
    • E
      command: reduce duplicated debug messages · c668c897
      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.
      c668c897
  26. 08 6月, 2011 2 次提交
    • E
      build: silence coverity false positive · f876c30c
      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.
      f876c30c
    • C
      Move virRun, virExec*, virFork to util/command · 02e86910
      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>
      02e86910
  27. 03 6月, 2011 2 次提交
    • E
      build: silence coverity false positive · 89e651fa
      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.
      89e651fa
    • E
      command: avoid leak on failure · bb889529
      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.
      bb889529
  28. 02 6月, 2011 1 次提交
    • D
      Allow handshake with child process during startup · 285c2fdf
      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
      285c2fdf
  29. 16 5月, 2011 1 次提交
    • D
      Disable virCommandExec on Win32 · 91e5c3dc
      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
      91e5c3dc
  30. 14 5月, 2011 1 次提交
  31. 12 5月, 2011 1 次提交
    • L
      libvirt,logging: cleanup VIR_XXX0() · b65f37a4
      Lai Jiangshan 提交于
      These VIR_XXXX0 APIs make us confused, use the non-0-suffix APIs instead.
      
      How do these coversions works? The magic is using the gcc extension of ##.
      When __VA_ARGS__ is empty, "##" will swallow the "," in "fmt," to
      avoid compile error.
      
      example: origin				after CPP
      	high_level_api("%d", a_int)	low_level_api("%d", a_int)
      	high_level_api("a  string")	low_level_api("a  string")
      
      About 400 conversions.
      
      8 special conversions:
      VIR_XXXX0("") -> VIR_XXXX("msg") (avoid empty format) 2 conversions
      VIR_XXXX0(string_literal_with_%) -> VIR_XXXX(%->%%) 0 conversions
      VIR_XXXX0(non_string_literal) -> VIR_XXXX("%s", non_string_literal)
        (for security) 6 conversions
      Signed-off-by: NLai Jiangshan <laijs@cn.fujitsu.com>
      b65f37a4
  32. 11 5月, 2011 1 次提交
    • C
      command: Add virCommandExec helper · f095398a
      Cole Robinson 提交于
      Actually execs the argv/env we've generated, replacing the current process.
      Kind of has a limited usage, but allows us to use virCommand in LXC
      driver to launch the 'init' process
      f095398a