1. 30 1月, 2014 1 次提交
    • M
      virCommand: Introduce virCommandSetDryRun · 550a2cef
      Michal Privoznik 提交于
      There are some units within libvirt that utilize virCommand API to run
      some commands and deserve own unit testing. These units are, however,
      not desired to be rewritten to dig virCommand API usage out. As a great
      example virNetDevBandwidth could be used. The problem with the bandwidth
      unit is: it uses virCommand API heavily. Therefore we need a mechanism
      to not really run a command, but rather see its string representation
      after which we can decide if the unit construct the correct sequence of
      commands or not.
      Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
      550a2cef
  2. 21 11月, 2013 1 次提交
    • E
      maint: fix comma style issues: util · c7c84fa5
      Eric Blake 提交于
      Most of our code base uses space after comma but not before;
      fix the remaining uses before adding a syntax check.
      
      * src/util/vircommand.c: Consistently use commas.
      * src/util/virlog.c: Likewise.
      * src/util/virnetdevbandwidth.c: Likewise.
      * src/util/virnetdevmacvlan.c: Likewise.
      * src/util/virnetdevvportprofile.c: Likewise.
      * src/util/virnetlink.c: Likewise.
      * src/util/virpci.c: Likewise.
      * src/util/virsysinfo.c: Likewise.
      * src/util/virusb.c: Likewise.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      c7c84fa5
  3. 21 10月, 2013 1 次提交
  4. 24 9月, 2013 1 次提交
  5. 05 9月, 2013 1 次提交
  6. 18 7月, 2013 1 次提交
  7. 12 7月, 2013 2 次提交
    • E
      util: make virSetUIDGID async-signal-safe · ee777e99
      Eric Blake 提交于
      https://bugzilla.redhat.com/show_bug.cgi?id=964358
      
      POSIX states that multi-threaded apps should not use functions
      that are not async-signal-safe between fork and exec, yet we
      were using getpwuid_r and initgroups.  Although rare, it is
      possible to hit deadlock in the child, when it tries to grab
      a mutex that was already held by another thread in the parent.
      I actually hit this deadlock when testing multiple domains
      being started in parallel with a command hook, with the following
      backtrace in the child:
      
       Thread 1 (Thread 0x7fd56bbf2700 (LWP 3212)):
       #0  __lll_lock_wait ()
           at ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:136
       #1  0x00007fd5761e7388 in _L_lock_854 () from /lib64/libpthread.so.0
       #2  0x00007fd5761e7257 in __pthread_mutex_lock (mutex=0x7fd56be00360)
           at pthread_mutex_lock.c:61
       #3  0x00007fd56bbf9fc5 in _nss_files_getpwuid_r (uid=0, result=0x7fd56bbf0c70,
           buffer=0x7fd55c2a65f0 "", buflen=1024, errnop=0x7fd56bbf25b8)
           at nss_files/files-pwd.c:40
       #4  0x00007fd575aeff1d in __getpwuid_r (uid=0, resbuf=0x7fd56bbf0c70,
           buffer=0x7fd55c2a65f0 "", buflen=1024, result=0x7fd56bbf0cb0)
           at ../nss/getXXbyYY_r.c:253
       #5  0x00007fd578aebafc in virSetUIDGID (uid=0, gid=0) at util/virutil.c:1031
       #6  0x00007fd578aebf43 in virSetUIDGIDWithCaps (uid=0, gid=0, capBits=0,
           clearExistingCaps=true) at util/virutil.c:1388
       #7  0x00007fd578a9a20b in virExec (cmd=0x7fd55c231f10) at util/vircommand.c:654
       #8  0x00007fd578a9dfa2 in virCommandRunAsync (cmd=0x7fd55c231f10, pid=0x0)
           at util/vircommand.c:2247
       #9  0x00007fd578a9d74e in virCommandRun (cmd=0x7fd55c231f10, exitstatus=0x0)
           at util/vircommand.c:2100
       #10 0x00007fd56326fde5 in qemuProcessStart (conn=0x7fd53c000df0,
           driver=0x7fd55c0dc4f0, vm=0x7fd54800b100, migrateFrom=0x0, stdin_fd=-1,
           stdin_path=0x0, snapshot=0x0, vmop=VIR_NETDEV_VPORT_PROFILE_OP_CREATE,
           flags=1) at qemu/qemu_process.c:3694
       ...
      
      The solution is to split the work of getpwuid_r/initgroups into the
      unsafe portions (getgrouplist, called pre-fork) and safe portions
      (setgroups, called post-fork).
      
      * src/util/virutil.h (virSetUIDGID, virSetUIDGIDWithCaps): Adjust
      signature.
      * src/util/virutil.c (virSetUIDGID): Add parameters.
      (virSetUIDGIDWithCaps): Adjust clients.
      * src/util/vircommand.c (virExec): Likewise.
      * src/util/virfile.c (virFileAccessibleAs, virFileOpenForked)
      (virDirCreate): Likewise.
      * src/security/security_dac.c (virSecurityDACSetProcessLabel):
      Likewise.
      * src/lxc/lxc_container.c (lxcContainerSetID): Likewise.
      * configure.ac (AC_CHECK_FUNCS_ONCE): Check for setgroups, not
      initgroups.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      ee777e99
    • J
      testutils: Resolve Coverity issues · 8283ef9e
      John Ferlan 提交于
      Recent changes uncovered a NEGATIVE_RETURNS in the return from sysconf()
      when processing a for loop in virtTestCaptureProgramExecChild() in
      testutils.c
      
      Code review uncovered 3 other code paths with the same condition that
      weren't found by Covirity, so fixed those as well.
      8283ef9e
  8. 11 7月, 2013 1 次提交
  9. 10 7月, 2013 1 次提交
  10. 24 5月, 2013 1 次提交
  11. 21 5月, 2013 1 次提交
  12. 02 5月, 2013 1 次提交
    • M
      virutil: Move string related functions to virstring.c · 7c9a2d88
      Michal Privoznik 提交于
      The source code base needs to be adapted as well. Some files
      include virutil.h just for the string related functions (here,
      the include is substituted to match the new file), some include
      virutil.h without any need (here, the include is removed), and
      some require both.
      7c9a2d88
  13. 26 4月, 2013 1 次提交
    • L
      util: new virCommandSetMax(MemLock|Processes|Files) · 776d49f4
      Laine Stump 提交于
      This patch adds two sets of functions:
      
      1) lower level virProcessSet*() functions that will immediately set
      the RLIMIT_MEMLOCK. RLIMIT_NPROC, or RLIMIT_NOFILE of either the
      current process (using setrlimit()) or any other process (using
      prlimit()). "current process" is indicated by passing a 0 for pid.
      
      2) functions for virCommand* that will setup a virCommand object to
      set those limits at a later time just after it has forked a new
      process, but before it execs the new program.
      
      configure.ac has prlimit and setrlimit added to the list of functions
      to check for, and the low level functions log an "unsupported" error)
      on platforms that don't support those functions.
      776d49f4
  14. 15 3月, 2013 1 次提交
    • L
      util: fix clear_emulator_capabilities=0 · 49fa91b3
      Laine Stump 提交于
      My commit 7a2e845a (and its
      prerequisites) managed to effectively ignore the
      clear_emulator_capabilities setting in qemu.conf (visible in the code
      as the VIR_EXEC_CLEAR_CAPS flag when qemu is being exec'ed), with the
      result that the capabilities are always cleared regardless of the
      qemu.conf setting. This patch fixes it by passing the flag through to
      virSetUIDGIDWithCaps(), which uses it to decide whether or not to
      clear existing capabilities before adding in those that were
      requested.
      
      Note that the existing capabilities are *always* cleared if the new
      process is going to run as non-root, since the whole point of running
      non-root is to have the capabilities removed (it's still possible to
      maintain individual capabilities as needed using the capBits argument
      though).
      49fa91b3
  15. 16 2月, 2013 2 次提交
    • J
      vircommand: Remove unnecessary sa_assert · 277aaeee
      John Ferlan 提交于
      Changes from commit '3178df9a' removed the need for the sa_assert(infd).
      277aaeee
    • E
      build: fix vircommand build on mingw · ec2cc0f8
      Eric Blake 提交于
        CC       libvirt_util_la-vircommand.lo
      ../../src/util/vircommand.c:2358:1: error: 'virCommandHandshakeChild' defined but not used [-Werror=unused-function]
      
      The function is only implemented inside #ifndef WIN32.
      
      * src/util/vircommand.c (virCommandHandshakeChild): Hoist earlier,
      so that win32 build doesn't hit an unused forward declaration.
      ec2cc0f8
  16. 14 2月, 2013 7 次提交
    • L
      util: maintain caps when running command with uid != 0 · 7a2e845a
      Laine Stump 提交于
      virCommand was previously calling virSetUIDGID() to change the uid and
      gid of the child process, then separately calling
      virSetCapabilities(). This did not work if the desired uid was != 0,
      since a setuid to anything other than 0 normally clears all
      capabilities bits.
      
      The solution is to use the new virSetUIDGIDWithCaps(), sending it the
      uid, gid, and capabilities bits. This will get the new process setup
      properly.
      
      Since the static functions virSetCapabilities() and
      virClearCapabilities are no longer called, they have been removed.
      
      NOTE: When combined with "filecap $path-to-qemu sys_rawio", this patch
      will make CAP_SYS_RAWIO (which is required for passthrough of generic
      scsi commands to a guest - see commits e8daeeb1, 177db087, 397e6a70, and
      74e03496) be retained by qemu when necessary. Apparently that
      capability has been broken for non-root qemu ever since it was
      originally added.
      7a2e845a
    • L
      util: drop capabilities immediately after changing uid/gid of child · c0e3e685
      Laine Stump 提交于
      This is an interim measure to make sure everything still works in this
      order. The next step will be to perform capabilities drop and
      setuid/gid as a single operation (which is the only way to keep any
      capabilities when switching to a non-root uid).
      c0e3e685
    • L
      util: add security label setting to virCommand · 6c3f3d0d
      Laine Stump 提交于
      virCommand gets two new APIs: virCommandSetSELinuxLabel() and
      virCommandSetAppArmorProfile(), which both save a copy of a
      null-terminated string in the virCommand. During virCommandRun, if the
      string is non-NULL and we've been compiled with AppArmor and/or
      SELinux security driver support, the appropriate security library
      function is called for the child process, using the string that was
      previously set. In the case of SELinux, setexeccon_raw() is called,
      and for AppArmor, aa_change_profile() is called.
      
      This functionality has been added so that users of virCommand can use
      the upcoming virSecurityManagerSetChildProcessLabel() prior to running
      a child process, rather than needing to setup a hook function to be
      called (and in turn call virSecurityManagerSetProcessLabel()) *during*
      the setup of the child process.
      6c3f3d0d
    • L
      util: add virCommandSetUID and virCommandSetGID · 417182b0
      Laine Stump 提交于
      If a uid and/or gid is specified for a command, it will be set just
      after the user-supplied post-fork "hook" function is called.
      
      The intent is that this can replace user hook functions that set
      uid/gid. This moves the setting of uid/gid and dropping of
      capabilities closer to each other, which is important since the two
      should really be done at the same time (libcapng provides a single
      function that does both, which we will be unable to use, but want to
      mimic as closely as possible).
      417182b0
    • L
    • L
      util: eliminate extra args from virExec · 5f2ce539
      Laine Stump 提交于
      All args except "cmd" in the call to virExec are now redundant, since
      they can all be found in cmd, so remove the args and reference the
      data directly in cmd. One exception to this is that "infd" was being
      modified within virExec, and modifying the original in cmd caused make
      check failures, so cmd->infd is copied to a local, and the local is
      used during virExec().
      5f2ce539
    • L
      util: eliminate generic hook from virExecWithHook · b6decc57
      Laine Stump 提交于
      virExecWithHook is only called from one place, so it always has the
      same "hook" function (virHookCommand), and the data sent to that
      function is always a virCommandPtr, so eliminate the function and
      generic data from the arglist, and replace it with "virCommandPtr
      cmd". The call to (hook)(data) is replaced with
      "virHookCommand(cmd)". Finally, virExecWithHook is renamed to virExec.
      
      Indentation has been updated only for code that will remain after the
      next patch, which will remove all other args to virExec (since they
      are now redundant, as they're all members of virCommandPtr).
      b6decc57
  17. 13 2月, 2013 1 次提交
    • M
      virCommand: Don't misuse the eventloop for async IO · 3178df9a
      Michal Privoznik 提交于
      Currently, if a command wants to do asynchronous IO, a callback
      is registered in the libvirtd eventloop to handle writes and
      reads. However, there's a race in virCommandWait. The eventloop
      may already be executing the callback, while virCommandWait is
      mangling internal state of virCommand. To deal with it, we need
      to either introduce locking or spawn a separate thread where we
      poll() on stdio from child. The former, however, requires to
      unlock all mutexes held, as the event loop may execute other
      callbacks which tries to lock one of the mutexes, deadlock and
      thus never wake us up. So it's safer to spawn a separate thread.
      3178df9a
  18. 05 2月, 2013 1 次提交
    • M
      virCommand: Introduce virCommandDoAsyncIO · 68fb7550
      Michal Privoznik 提交于
      Currently, if we want to feed stdin, or catch stdout or stderr of a
      virCommand we have to use virCommandRun(). When using virCommandRunAsync()
      we have to register FD handles by hand. This may lead to code duplication.
      Hence, introduce an internal API, which does this automatically within
      virCommandRunAsync(). The intended usage looks like this:
      
          virCommandPtr cmd = virCommandNew*(...);
          char *buf = NULL;
      
          ...
      
          virCommandSetOutputBuffer(cmd, &buf);
          virCommandDoAsyncIO(cmd);
      
          if (virCommandRunAsync(cmd, NULL) < 0)
              goto cleanup;
      
          ...
      
          if (virCommandWait(cmd, NULL) < 0)
              goto cleanup;
      
          /* @buf now contains @cmd's stdout */
          VIR_DEBUG("STDOUT: %s", NULLSTR(buf));
      
          ...
      
      cleanup:
          VIR_FREE(buf);
          virCommandFree(cmd);
      
      Note, that both stdout and stderr buffers may change until virCommandWait()
      returns.
      68fb7550
  19. 14 1月, 2013 1 次提交
  20. 21 12月, 2012 6 次提交
  21. 02 11月, 2012 1 次提交
  22. 26 9月, 2012 3 次提交
  23. 25 9月, 2012 2 次提交
  24. 21 9月, 2012 1 次提交