1. 28 5月, 2012 2 次提交
    • D
      Add impl of APIs to get user directories on Win32 · 076f2006
      Daniel P. Berrange 提交于
      Add an impl of +virGetUserRuntimeDirectory, virGetUserCacheDirectory
      virGetUserConfigDirectory and virGetUserDirectory for Win32 platform.
      Also create stubs for non-Win32 platforms which lack getpwuid_r()
      
      In adding these two helpers were added virFileIsAbsPath and
      virFileSkipRoot, along with some macros VIR_FILE_DIR_SEPARATOR,
      VIR_FILE_DIR_SEPARATOR_S, VIR_FILE_IS_DIR_SEPARATOR,
      VIR_FILE_PATH_SEPARATOR, VIR_FILE_PATH_SEPARATOR_S
      
      All this code was adapted from GLib2 under terms of LGPLv2+ license.
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      076f2006
    • D
      Remove uid param from directory lookup APIs · 517368a3
      Daniel P. Berrange 提交于
      Remove the uid param from virGetUserConfigDirectory,
      virGetUserCacheDirectory, virGetUserRuntimeDirectory,
      and virGetUserDirectory
      
      These functions were universally called with the
      results of getuid() or geteuid(). To make it practical
      to port to Win32, remove the uid parameter and hardcode
      geteuid()
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      517368a3
  2. 16 5月, 2012 1 次提交
  3. 14 5月, 2012 1 次提交
    • W
      Use XDG Base Directories instead of storing in home directory · 32a9aac2
      William Jon McCann 提交于
      As defined in:
      http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
      
      This offers a number of advantages:
       * Allows sharing a home directory between different machines, or
      sessions (eg. using NFS)
       * Cleanly separates cache, runtime (eg. sockets), or app data from
      user settings
       * Supports performing smart or selective migration of settings
      between different OS versions
       * Supports reseting settings without breaking things
       * Makes it possible to clear cache data to make room when the disk
      is filling up
       * Allows us to write a robust and efficient backup solution
       * Allows an admin flexibility to change where data and settings are stored
       * Dramatically reduces the complexity and incoherence of the
      system for administrators
      32a9aac2
  4. 20 4月, 2012 1 次提交
    • E
      build: avoid strtol and strtod · ae27f341
      Eric Blake 提交于
      Ensure we don't introduce any more lousy integer parsing in new
      code, while avoiding a scrub-down of existing legacy code.
      
      Note that we also need to enable sc_prohibit_atoi_atof (see cfg.mk
      local-checks-to-skip) before we are bulletproof, but that also
      entails scrubbing I'm not ready to do at the moment.
      
      * src/util/util.c (virStrToLong_i, virStrToLong_ui)
      (virStrToLong_l, virStrToLong_ul, virStrToLong_ll)
      (virStrToLong_ull, virStrToDouble): Mark exemptions.
      * src/util/virmacaddr.c (virMacAddrParse): Likewise.
      * cfg.mk (sc_prohibit_strtol): New syntax check.
      (exclude_file_name_regexp--sc_prohibit_strtol): Ignore files that
      I'm not willing to fix yet.
      (local-checks-to-skip): Re-enable sc_prohibit_atoi_atof.
      ae27f341
  5. 19 4月, 2012 1 次提交
    • E
      util: remove dead casts · ee20ec4c
      Eric Blake 提交于
      The sequence:
        long long val;
        if ((long long) val != val)
      is dead code.
      
      * src/util/util.c (virStrToLong_ll, virStrToLong_ull): Remove
      useless cast.
      ee20ec4c
  6. 02 4月, 2012 1 次提交
  7. 30 3月, 2012 1 次提交
  8. 27 3月, 2012 1 次提交
    • M
      Cleanup for a return statement in source files · 9943276f
      Martin Kletzander 提交于
      Return statements with parameter enclosed in parentheses were modified
      and parentheses were removed. The whole change was scripted, here is how:
      
      List of files was obtained using this command:
      git grep -l -e '\<return\s*([^()]*\(([^()]*)[^()]*\)*)\s*;' |             \
      grep -e '\.[ch]$' -e '\.py$'
      
      Found files were modified with this command:
      sed -i -e                                                                 \
      's_^\(.*\<return\)\s*(\(\([^()]*([^()]*)[^()]*\)*\))\s*\(;.*$\)_\1 \2\4_' \
      -e 's_^\(.*\<return\)\s*(\([^()]*\))\s*\(;.*$\)_\1 \2\3_'
      
      Then checked for nonsense.
      
      The whole command looks like this:
      git grep -l -e '\<return\s*([^()]*\(([^()]*)[^()]*\)*)\s*;' |             \
      grep -e '\.[ch]$' -e '\.py$' | xargs sed -i -e                            \
      's_^\(.*\<return\)\s*(\(\([^()]*([^()]*)[^()]*\)*\))\s*\(;.*$\)_\1 \2\4_' \
      -e 's_^\(.*\<return\)\s*(\([^()]*\))\s*\(;.*$\)_\1 \2\3_'
      9943276f
  9. 08 3月, 2012 2 次提交
    • M
      util: Don't overflow on errno in virFileAccessibleAs · f05fb6c5
      Michal Privoznik 提交于
      If we need to virFork() to check assess() under different
      UID+GID we need to translate returned status via WEXITSTATUS().
      Otherwise, we may return values greater than 255 which is
      obviously wrong.
      f05fb6c5
    • E
      util: new function for scaling numbers · 0d90823e
      Eric Blake 提交于
      Scaling an integer based on a suffix is something we plan on reusing
      in several contexts: XML parsing, virsh CLI parsing, and possibly
      elsewhere.  Make it easy to reuse, as well as adding in support for
      powers of 1000.
      
      * src/util/util.h (virScaleInteger): New function.
      * src/util/util.c (virScaleInteger): Implement it.
      * src/libvirt_private.syms (util.h): Export it.
      0d90823e
  10. 22 2月, 2012 1 次提交
  11. 04 2月, 2012 1 次提交
    • L
      util: refactor virFileOpenAs · 90e4d681
      Laine Stump 提交于
      virFileOpenAs previously would only try opening a file as the current
      user, or as a different user, but wouldn't try both methods in a
      single call. This made it cumbersome to use as a replacement for
      open(2). Additionally, it had a lot of historical baggage that led to
      it being difficult to understand.
      
      This patch refactors virFileOpenAs in the following ways:
      
      * reorganize the code so that everything dealing with both the parent
        and child sides of the "fork+setuid+setgid+open" method are in a
        separate function. This makes the public function easier to understand.
      
      * Allow a single call to virFileOpenAs() to first attempt the open as
        the current user, and if that fails to automatically re-try after
        doing fork+setuid (if deemed appropriate, i.e. errno indicates it
        would now be successful, and the file is on a networkFS). This makes
        it possible (in many, but possibly not all, cases) to drop-in
        virFileOpenAs() as a replacement for open(2).
      
        (NB: currently qemuOpenFile() calls virFileOpenAs() twice, once
        without forking, then again with forking. That unfortunately can't
        be changed without at least some discussion of the ramifications,
        because the requested file permissions are different in each case,
        which is something that a single call to virFileOpenAs() can't deal
        with.)
      
      * Add a flag so that any fchown() of the file to a different uid:gid
        is explicitly requested when the function is called, rather than it
        being implied by the presence of the O_CREAT flag. This just makes
        for less subtle surprises to consumers. (Commit
        b1643dc1 added the check for O_CREAT
        before forcing ownership. This patch just makes that restriction
        more explicit.)
      
      * If either the uid or gid is specified as "-1", virFileOpenAs will
        interpret this to mean "the current [gu]id".
      
      All current consumers of virFileOpenAs should retain their present
      behavior (after a few minor changes to their setup code and
      arguments).
      90e4d681
  12. 28 1月, 2012 3 次提交
  13. 26 1月, 2012 2 次提交
    • D
      Introduce new API for generating random numbers · e95ef67b
      Daniel P. Berrange 提交于
      The old virRandom() API was not generating good random numbers.
      Replace it with a new API virRandomBits which instead of being
      told the upper limit, gets told the number of bits of randomness
      required.
      
      * src/util/virrandom.c, src/util/virrandom.h: Add virRandomBits,
        and move virRandomInitialize
      * src/util/util.h, src/util/util.c: Delete virRandom and
        virRandomInitialize
      * src/libvirt.c, src/security/security_selinux.c,
        src/test/test_driver.c, src/util/iohelper.c: Update for
        changes from virRandom to virRandomBits
      * src/storage/storage_backend_iscsi.c: Remove bogus call
        to virRandomInitialize & convert to virRandomBits
      e95ef67b
    • M
      Add missing virGetGroupName() · 5f1767e8
      Marc-André Lureau 提交于
      Add missing function if !HAVE_GETPWUID_R.
      5f1767e8
  14. 20 1月, 2012 1 次提交
    • E
      util: add new file for virTypedParameter utils · 61ca98b0
      Eric Blake 提交于
      Preparation for another patch that refactors common patterns
      into the new file for fewer lines of code overall.
      
      * src/util/util.h (virTypedParameterArrayClear): Move...
      * src/util/virtypedparam.h: ...to new file.
      (virTypedParameterArrayValidate, virTypedParameterAssign): New
      prototypes.
      * src/util/util.c (virTypedParameterArrayClear): Likewise.
      * src/util/virtypedparam.c: New file.
      * po/POTFILES.in: Mark file for translation.
      * src/Makefile.am (UTIL_SOURCES): Build it.
      * src/libvirt_private.syms (util.h): Split...
      (virtypedparam.h): to new section.
      (virkeycode.h): Sort.
      * daemon/remote.c: Adjust callers.
      * tools/virsh.c: Likewise.
      61ca98b0
  15. 19 1月, 2012 1 次提交
  16. 18 1月, 2012 1 次提交
    • D
      Fix startup of LXC containers with filesystems containing symlinks · c53ba61b
      Daniel P. Berrange 提交于
      Given an LXC guest with a root filesystem path of
      
        /export/lxc/roots/helloworld/root
      
      During startup, we will pivot the root filesystem to end up
      at
      
        /.oldroot/export/lxc/roots/helloworld/root
      
      We then try to open
      
        /.oldroot/export/lxc/roots/helloworld/root/dev/pts
      
      Now consider if '/export/lxc' is an absolute symlink pointing
      to '/media/lxc'. The kernel will try to open
      
        /media/lxc/roots/helloworld/root/dev/pts
      
      whereas it should be trying to open
      
        /.oldroot//media/lxc/roots/helloworld/root/dev/pts
      
      To deal with the fact that the root filesystem can be moved,
      we need to resolve symlinks in *any* part of the filesystem
      source path.
      
      * src/libvirt_private.syms, src/util/util.c,
        src/util/util.h: Add virFileResolveAllLinks to resolve
        all symlinks in a path
      * src/lxc/lxc_container.c: Resolve all symlinks in filesystem
        paths during startup
      c53ba61b
  17. 30 11月, 2011 5 次提交
    • D
      Remove time APIs from src/util/util.h · a8bb75a3
      Daniel P. Berrange 提交于
      The virTimestamp and virTimeMs functions in src/util/util.h
      duplicate functionality from virtime.h, in a non-async signal
      safe manner. Remove them, and convert all code over to the new
      APIs.
      
      * src/util/util.c, src/util/util.h: Delete virTimeMs and virTimestamp
      * src/lxc/lxc_driver.c, src/qemu/qemu_domain.c,
        src/qemu/qemu_driver.c, src/qemu/qemu_migration.c,
        src/qemu/qemu_process.c, src/util/event_poll.c: Convert to use
        virtime APIs
      a8bb75a3
    • D
      Move suspend capabilities APIs out of util.h into virnodesuspend.c · c92653f4
      Daniel P. Berrange 提交于
      The node suspend capabilities APIs should not have been put into
      util.[ch]. Instead move them into virnodesuspend.[ch]
      
      * src/util/util.c, src/util/util.h: Remove suspend capabilities APIs
      * src/util/virnodesuspend.c, src/util/virnodesuspend.h: Add
        suspend capabilities APIs
      * src/qemu/qemu_capabilities.c: Include virnodesuspend.h
      c92653f4
    • D
      Rename suspend capabilities APIs · 53c2aad8
      Daniel P. Berrange 提交于
      Rename virGetPMCapabilities to virNodeSuspendGetTargetMask and
      virDiscoverHostPMFeature to virNodeSuspendSupportsTarget.
      
      * src/util/util.c, src/util/util.h: Rename APIs
      * src/qemu/qemu_capabilities.c, src/util/virnodesuspend.c: Adjust
        for new names
      53c2aad8
    • D
      Sanitize virDiscoverHostPMFeature to return a boolean · 33386276
      Daniel P. Berrange 提交于
      Since virDiscoverHostPMFeature is just checking one feature,
      there is no reason for it to return a bitmask. Change it to
      return a boolean
      
      * src/util/util.c, src/util/util.h: Make virDiscoverHostPMFeature
        return a boolean
      33386276
    • D
      Remove internal only virHostPMCapability enum · 6fb5400f
      Daniel P. Berrange 提交于
      The internal virHostPMCapability enum just duplicates the
      public virNodeSuspendTarget enum, but with different names.
      
      * src/util/util.c: Use VIR_NODE_SUSPEND_TARGET constants
      * src/util/util.h: Remove virHostPMCapability enum
      * src/conf/capabilities.c: Use VIR_NODE_SUSPEND_TARGET_LAST
      6fb5400f
  18. 29 11月, 2011 1 次提交
    • S
      Add 'Hybrid-Suspend' power management discovery for the host · 302743f1
      Srivatsa S. Bhat 提交于
      Some systems support a feature known as 'Hybrid-Suspend', apart from the
      usual system-wide sleep states such as Suspend-to-RAM (S3) or Suspend-to-Disk
      (S4). Add the functionality to discover this power management feature and
      export it in the capabilities XML under the <power_management> tag.
      302743f1
  19. 22 11月, 2011 1 次提交
    • S
      Export KVM Host Power Management capabilities · e352b164
      Srivatsa S. Bhat 提交于
      This patch exports KVM Host Power Management capabilities as XML so that
      higher-level systems management software can make use of these features
      available in the host.
      
      The script "pm-is-supported" (from pm-utils package) is run to discover if
      Suspend-to-RAM (S3) or Suspend-to-Disk (S4) is supported by the host.
      If either of them are supported, then a new tag "<power_management>" is
      introduced in the XML under the <host> tag.
      
      However in case the query to check for power management features succeeded,
      but the host does not support any such feature, then the XML will contain
      an empty <power_management/> tag. In the event that the PM query itself
      failed, the XML will not contain any "power_management" tag.
      
      To use this, new APIs could be implemented in libvirt to exploit power
      management features such as S3/S4.
      e352b164
  20. 12 11月, 2011 1 次提交
    • E
      API: add VIR_TYPED_PARAM_STRING · a218c81d
      Eric Blake 提交于
      This allows strings to be transported between client and server
      in the context of name-type-value virTypedParameter functions.
      For compatibility,
      
          o new clients will not send strings to old servers, based on
            a feature check
          o new servers will not send strings to old clients without the
            flag VIR_TYPED_PARAM_STRING_OKAY; this will be enforced at
            the RPC layer in the next patch, so that drivers need not
            worry about it in general.  The one exception is that
            virDomainGetSchedulerParameters lacks a flags argument, so
            it must not return a string; drivers that forward that
            function on to virDomainGetSchedulerParametersFlags will
            have to pay attention to the flag.
          o the flag VIR_TYPED_PARAM_STRING_OKAY is set automatically,
            based on a feature check (so far, no driver implements it),
            so clients do not have to worry about it
      
      Future patches can then enable the feature on a per-driver basis.
      
      This patch also ensures that drivers can blindly strdup() field
      names (previously, a malicious client could stuff 80 non-NUL bytes
      into field and cause a read overrun).
      
      * src/libvirt_internal.h (VIR_DRV_FEATURE_TYPED_PARAM_STRING): New
      driver feature.
      * src/libvirt.c (virTypedParameterValidateSet)
      (virTypedParameterSanitizeGet): New helper functions.
      (virDomainSetMemoryParameters, virDomainSetBlkioParameters)
      (virDomainSetSchedulerParameters)
      (virDomainSetSchedulerParametersFlags)
      (virDomainGetMemoryParameters, virDomainGetBlkioParameters)
      (virDomainGetSchedulerParameters)
      (virDomainGetSchedulerParametersFlags, virDomainBlockStatsFlags):
      Use them.
      * src/util/util.h (virTypedParameterArrayClear): New helper
      function.
      * src/util/util.c (virTypedParameterArrayClear): Implement it.
      * src/libvirt_private.syms (util.h): Export it.
      Based on an initial patch by Hu Tao, with feedback from
      Daniel P. Berrange.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      a218c81d
  21. 08 11月, 2011 1 次提交
    • E
      build: fix build on platforms without ptsname_r · f7bd00c1
      Eric Blake 提交于
      MacOS lacks ptsname_r, and gnulib doesn't (yet) provide it.
      But we can avoid it altogether, by using gnulib openpty()
      instead.  Note that we do _not_ want the pt_chown module;
      gnulib uses it only to implement a replacement openpty() if
      the system lacks both openpty() and granpt(), but all
      systems that we currently port to either have at least one of
      openpty() and/or grantpt(), or lack ptys altogether.  That is,
      we aren't porting to any system that requires us to deal with
      the hassle of installing a setuid pt_chown helper just to use
      gnulib's ability to provide openpty() on obscure platforms.
      
      * .gnulib: Update to latest, for openpty fixes
      * bootstrap.conf (gnulib_modules): Add openpty, ttyname_r.
      (gnulib_tool_option_extras): Exclude pt_chown module.
      * src/util/util.c (virFileOpenTty): Rewrite in terms of openpty
      and ttyname_r.
      * src/util/util.h (virFileOpenTtyAt): Delete dead prototype.
      f7bd00c1
  22. 28 10月, 2011 1 次提交
    • J
      Introduce virXMLSaveFile as a wrapper for virFileRewrite · fef8127c
      Jiri Denemark 提交于
      Every time we write XML into a file we call virEmitXMLWarning to write a
      warning that the file is automatically generated. virXMLSaveFile
      simplifies this into a single step and makes rewriting existing XML file
      safe by using virFileRewrite internally.
      fef8127c
  23. 27 10月, 2011 1 次提交
  24. 25 10月, 2011 1 次提交
  25. 20 10月, 2011 2 次提交
  26. 14 10月, 2011 2 次提交
  27. 16 9月, 2011 1 次提交
  28. 25 8月, 2011 1 次提交
    • L
      util: only fchown newly created files in virFileOpenAs · b1643dc1
      Laine Stump 提交于
      virFileOpenAs takes desired uid:gid as arguments, and not only uses
      them for a fork/setuid/setgid when retrying failed open operations,
      but additionally always forces the opened file to be owned by the
      given uid:gid.
      
      One example of the problems this causes is that, when restoring a
      domain from a file that is owned by the qemu user, opening the file
      chowns it to root. if dynamic_ownership=1 this is coincidentally
      expected, but if dynamic_ownership=0, no existing file should ever
      have its ownership changed.
      
      This patch adds an extra check before calling fchown() - it only does
      it if O_CREAT was passed to virFileOpenAs() in the openflags.
      b1643dc1
  29. 17 8月, 2011 1 次提交
    • S
      maint: fix some compilation issues on non-linux platforms (part 2) · 57c7b40b
      Stefan Berger 提交于
      Get rid of the #if __linux__ check in virPidFileReadPathIfAlive that
      was preventing a check of a symbolic link in /proc/<pid>/exe on
      non-linux platforms against an expected executable. Replace
      this with a run-time check testing whether the /proc/<pid>/exe is a
      symbolic link and if so call the function doing the comparison
      against the expected file the link is supposed to point to.
      57c7b40b