1. 14 6月, 2011 1 次提交
    • 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 14 5月, 2011 1 次提交
  7. 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
  8. 11 5月, 2011 2 次提交
    • 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
    • C
      command: Add virCommandEnvAddFormat · 35c1b35e
      Cole Robinson 提交于
      Similar to virCommandArgAddFormat. We will use this shortly.
      
      v2:
          Convert virCommandEnvAddPair to use the new function
      35c1b35e
  9. 17 4月, 2011 1 次提交
  10. 29 3月, 2011 1 次提交
  11. 25 3月, 2011 3 次提交
    • E
      command: add virCommandAbort for cleanup paths · 9ed54518
      Eric Blake 提交于
      Sometimes, an asynchronous helper is started (such as a compressor
      or iohelper program), but a later error means that we want to
      abort that child.  Make this easier.
      
      Note that since daemons and virCommandRunAsync can't mix, the only
      time virCommandFree can reap a process is if someone did
      virCommandRunAsync for a non-daemon and didn't stash the pid.
      
      * src/util/command.h (virCommandAbort): New prototype.
      * src/util/command.c (_virCommand): Add new field.
      (virCommandRunAsync, virCommandWait): Track whether pid was used.
      (virCommandFree): Reap child if caller did not request pid.
      (virCommandAbort): New function.
      * src/libvirt_private.syms (command.h): Export it.
      * tests/commandtest.c (test19): New test.
      9ed54518
    • E
      command: don't mix RunAsync and daemons · 4e808602
      Eric Blake 提交于
      It doesn't make sense to run a daemon without synchronously
      waiting for the child process to reply whether the daemon has
      been kicked off and pidfile written yet.
      
      * src/util/command.c (VIR_EXEC_RUN_SYNC): New constant.
      (virCommandRun): Set temporary flag.
      (virCommandRunAsync): Use it to prevent async runs of intermediate
      child when spawning asynchronous daemon grandchild.
      4e808602
    • E
      command: properly diagnose process exit via signal · 208a044a
      Eric Blake 提交于
      Child processes don't always reach _exit(); if they die from a
      signal, then any messages should still be accurate.  Most users
      either expect a 0 status (thankfully, if status==0, then
      WIFEXITED(status) is true and WEXITSTATUS(status)==0 for all
      known platforms) or were filtering on WIFEXITED before printing
      a status, but a few were missing this check.  Additionally,
      nwfilter_ebiptables_driver was making an assumption that works
      on Linux (where WEXITSTATUS shifts and WTERMSIG just masks)
      but fails on other platforms (where WEXITSTATUS just masks and
      WTERMSIG shifts).
      
      * src/util/command.h (virCommandTranslateStatus): New helper.
      * src/libvirt_private.syms (command.h): Export it.
      * src/util/command.c (virCommandTranslateStatus): New function.
      (virCommandWait): Use it to also diagnose status from signals.
      * src/security/security_apparmor.c (load_profile): Likewise.
      * src/storage/storage_backend.c
      (virStorageBackendQEMUImgBackingFormat): Likewise.
      * src/util/util.c (virExecDaemonize, virRunWithHook)
      (virFileOperation, virDirCreate): Likewise.
      * daemon/remote.c (remoteDispatchAuthPolkit): Likewise.
      * src/nwfilter/nwfilter_ebiptables_driver.c (ebiptablesExecCLI):
      Likewise.
      208a044a
  12. 24 3月, 2011 1 次提交
  13. 15 3月, 2011 1 次提交
    • D
      Fix misc bugs in virCommandPtr · 2a2a00eb
      Daniel P. Berrange 提交于
      The virCommandNewArgs() method would free the virCommandPtr
      if it failed to add the args. This meant errors reported in
      virCommandAddArgSet() were lost. Simply removing the check
      for errors from the constructor means they can be reported
      correctly later
      
      The virCommandAddEnvPassCommon() method failed to check for
      errors before reallocating the cmd->env array, causing a
      potential SEGV if cmd was NULL
      
      The virCommandAddArgSet() method needs to validate that at
      least 1 element in 'val's parameter is non-NULL, otherwise
      code like
      
          cmd = virCommandNew(binary)
          virCommandAddAtg(cmd, "foo")
      
      Would end up trying todo  execve("foo"), if binary was
      NULL.
      2a2a00eb
  14. 24 2月, 2011 1 次提交
  15. 16 2月, 2011 1 次提交
    • E
      build: address clang reports about virCommand · 3db08aea
      Eric Blake 提交于
      clang had 5 reports against virCommand; three were false positives
      (a NULL deref in ProcessIO solved by sa_assert, and two uninitialized
      memory operations solved by adding an initializer), but two were real.
      
      * src/util/command.c (virCommandProcessIO): Fix real bug of
      possible NULL dereference.  Teach clang that buf is never NULL.
      (virCommandRun): Teach clang that infd is only ever accessed when
      initialized.
      3db08aea
  16. 15 2月, 2011 1 次提交
  17. 22 12月, 2010 1 次提交
  18. 11 12月, 2010 1 次提交
    • E
      command: ease use with virBuffer, and fix qemu leak · e8d05c97
      Eric Blake 提交于
      * src/util/command.h (virCommandAddArgBuffer)
      (virCommandAddEnvBuffer): New prototypes.
      * src/util/command.c (virCommandAddArgBuffer)
      (virCommandAddEnvBuffer): Implement them.
      * src/libvirt_private.syms (command.h): Export them.
      * src/qemu/qemu_conf.c (qemudBuildCommandLine): Use them, plugging
      a memory leak on rbd_hosts in the process.
      e8d05c97
  19. 10 12月, 2010 2 次提交
    • E
      command: plug memory leak · f12d4169
      Eric Blake 提交于
      * src/util/command.c (virCommandFree): Free data from
      virCommandSetInputBuffer.
      f12d4169
    • E
      command: avoid memory leak · 8e9ee30e
      Eric Blake 提交于
      * src/util/command.c (virCommandRun): Fix yesterday's regression
      on logging, and avoid leaking log-only output captures.
      Reported by Hu Tao.
      8e9ee30e
  20. 08 12月, 2010 3 次提交
    • E
      command: improve behavior on no output · cc5e2a84
      Eric Blake 提交于
      Guarantee that outbuf/errbuf are allocated on success, even if to the
      empty string.  Caller always has to free the result, and empty output
      check requires checking if *outbuf=='\0'.  Makes the API easier to use
      safely.  Failure is best effort allocation (some paths, like
      out-of-memory, cannot allocate a buffer, but most do), so caller must
      free buffer on failure.
      
      * docs/internals/command.html.in: Update documentation.
      * src/util/command.c (virCommandSetOutputBuffer)
      (virCommandSetErrorBuffer, virCommandProcessIO) Guarantee empty
      string on no output.
      * tests/commandtest.c (test17): New test.
      cc5e2a84
    • E
      command: enforce fd vs. buffer considerations · ee11729d
      Eric Blake 提交于
      * docs/internals/command.html.in: Better documentation of buffer
      vs. fd considerations.
      * src/util/command.c (virCommandRunAsync): Reject raw execution
      with string io.
      (virCommandRun): Reject execution with user-specified fds not
      visiting a regular file.
      ee11729d
    • E
      command: improve allocation failure reporting · c426d13b
      Eric Blake 提交于
      * src/util/command.c (virCommandAddEnvString): Remove duplicate
      code.
      (virCommandToString, virCommandRun, virCommandRunAsync)
      (virCommandWait): Report NULL command as ENOMEM, not invalid
      usage.
      Reported by Jiri Denemark.
      c426d13b
  21. 07 12月, 2010 1 次提交
    • O
      util: Fix bug which will cause libvirtd crash · 85ccf42c
      Osier Yang 提交于
      "virCommandRun": if "cmd->outbuf" or "cmd->errbuf" is NULL,
      libvirtd will be crashed when trying to start a qemu domain
      (which invokes "virCommandRun"), it caused by we try to use
      "*cmd->outbuf" and "*cmd->errbuf" regardless of cmd->outbuf
      or cmd->errbuf is NULL.
      
      * src/util/command.c (virCommandRun)
      85ccf42c
  22. 03 12月, 2010 1 次提交
    • D
      Introduce new APIs for spawning processes · f16ad06f
      Daniel P. Berrange 提交于
      This introduces a new set of APIs in src/util/command.h
      to use for invoking commands. This is intended to replace
      all current usage of virRun and virExec variants, with a
      more flexible and less error prone API.
      
      * src/util/command.c: New file.
      * src/util/command.h: New header.
      * src/Makefile.am (UTIL_SOURCES): Build it.
      * src/libvirt_private.syms: Export symbols internally.
      * tests/commandtest.c: New test.
      * tests/Makefile.am (check_PROGRAMS): Run it.
      * tests/commandhelper.c: Auxiliary program.
      * tests/commanddata/test2.log - test15.log: New expected outputs.
      * cfg.mk (useless_free_options): Add virCommandFree.
      (msg_gen_function): Add virCommandError.
      * po/POTFILES.in: New translation.
      * .x-sc_avoid_write: Add exemption.
      * tests/.gitignore: Ignore new built file.
      f16ad06f