1. 11 6月, 2012 1 次提交
    • E
      buf: support peeking at string contents · 9202f2c2
      Eric Blake 提交于
      Right now, the only way to get at the contents of a virBuffer is
      to destroy it.  But there are cases in my upcoming patches where
      peeking at the contents makes life easier.  I suppose this does
      open up the potential for bad code to dereference a stale pointer,
      by disregarding the docs that the return value is invalid on the
      next virBuf operation, but such is life.
      
      * src/util/buf.h (virBufferCurrentContent): New declaration.
      * src/util/buf.c (virBufferCurrentContent): Implement it.
      * src/libvirt_private.syms (buf.h): Export it.
      * tests/virbuftest.c (testBufAutoIndent): Test it.
      9202f2c2
  2. 22 5月, 2012 1 次提交
    • E
      virBuffer: add way to trim back extra text · cdb87b1c
      Eric Blake 提交于
      I'm tired of writing:
      
      bool sep = false;
      while (...) {
          if (sep)
             virBufferAddChar(buf, ',');
          sep = true;
          virBufferAdd(buf, str);
      }
      
      This makes it easier, allowing one to write:
      
      while (...)
          virBufferAsprintf(buf, "%s,", str);
      virBufferTrim(buf, ",", -1);
      
      to trim any remaining comma.
      
      * src/util/buf.h (virBufferTrim): Declare.
      * src/util/buf.c (virBufferTrim): New function.
      * tests/virbuftest.c (testBufTrim): Test it.
      cdb87b1c
  3. 12 3月, 2012 1 次提交
    • E
      qemu: support disk filenames with comma · 6e0ff1d4
      Eric Blake 提交于
      If there is a disk file with a comma in the name, QEmu expects a double
      comma instead of a single one (e.g., the file "virtual,disk.img" needs
      to be specified as "virtual,,disk.img" in QEmu's command line). This
      patch fixes libvirt to work with that feature. Fix RHBZ #801036.
      
      Based on an initial patch by Crístian Viana.
      
      * src/util/buf.h (virBufferEscape): Alter signature.
      * src/util/buf.c (virBufferEscape): Add parameter.
      (virBufferEscapeSexpr): Fix caller.
      * src/qemu/qemu_command.c (qemuBuildRBDString): Likewise.  Also
      escape commas in file names.
      (qemuBuildDriveStr): Escape commas in file names.
      * docs/schemas/basictypes.rng (absFilePath): Relax RNG to allow
      commas in input file names.
      * tests/qemuxml2argvdata/*-disk-drive-network-sheepdog.*: Update
      test.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      6e0ff1d4
  4. 16 11月, 2011 1 次提交
    • S
      Fix strchr call triggering gcc 4.3 & 4.4 bug · 39d91e9f
      Stefan Berger 提交于
      Replacing the strchr call with two variables through a strstr call.
      Calling strchr with two variables triggers a gcc 4.3/4.4
      bug when used in combination with -Wlogical-op and at least -O1.
      39d91e9f
  5. 21 10月, 2011 3 次提交
    • E
      virbuf: add auto-indentation support · fd9c052e
      Eric Blake 提交于
      Rather than having to adjust all callers in a chain to deal with
      indentation, it is nicer to have virBuffer do auto-indentation.
      
      * src/util/buf.h (_virBuffer): Increase size.
      (virBufferAdjustIndent, virBufferGetIndent): New prototypes.
      * src/libvirt_private.syms (buf.h): Export new functions.
      * src/util/buf.c (virBufferAdjustIndent, virBufferGetIndent): New
      functions.
      (virBufferSetError, virBufferAdd, virBufferAddChar)
      (virBufferVasprintf, virBufferStrcat, virBufferURIEncodeString):
      Implement auto-indentation.
      * tests/virbuftest.c (testBufAutoIndent): Test it.
      (testBufInfiniteLoop): Don't rely on internals.
      Idea by Daniel P. Berrange.
      fd9c052e
    • E
      virbuf: more detailed error reporting · 818a9665
      Eric Blake 提交于
      The next patch wants to add some sanity checking, which would
      be a different error than ENOMEM.  Many existing callers blindly
      report OOM failure if virBuf reports an error, and this will be
      wrong in the (unlikely) case that they actually had a usage error
      instead; but since the most common error really is ENOMEM, I'm
      not going to fix all callers.  Meanwhile, new discriminating
      callers can react differently depending on what failure happened.
      
      * src/util/buf.c (virBufferSetError): Add parameter.
      (virBufferGrow, virBufferVasprintf, virBufferEscapeString)
      (virBufferEscapeSexpr, virBufferEscapeShell): Adjust callers.
      818a9665
    • E
      virbuf: fix const-correctness · 5c09b81b
      Eric Blake 提交于
      Although the compiler wasn't complaining (since it was the pointer,
      rather than what was being pointed to, that was actually const), it
      looks quite suspicious to call a function with an argument labeled
      const when the nature of the pointer (virBufferPtr) is hidden behind
      a typedef.  Dropping const makes the function declarations easier
      to read.
      
      * src/util/buf.h: Drop const from all functions that modify buffer
      argument.
      * src/util/buf.c (virBufferSetError, virBufferAdd)
      (virBufferContentAndReset, virBufferFreeAndReset)
      (virBufferAsprintf, virBufferVasprintf, virBufferEscapeString)
      (virBufferEscapeSexpr, virBufferEscape): Fix fallout.
      5c09b81b
  6. 19 10月, 2011 2 次提交
  7. 18 10月, 2011 1 次提交
  8. 14 10月, 2011 1 次提交
  9. 13 10月, 2011 1 次提交
  10. 25 6月, 2011 1 次提交
    • E
      buf: protect against integer overflow · 4a27eb13
      Eric Blake 提交于
      It's unlikely that we'll ever want to escape a string as long as
      INT_MAX/6, but adding this check can't hurt.
      
      * src/util/buf.c (virBufferEscapeSexpr, virBufferEscapeString):
      Check for (unlikely) overflow.
      4a27eb13
  11. 06 5月, 2011 2 次提交
    • E
      buf: add virBufferVasprintf · f09acccf
      Eric Blake 提交于
      Match the fact that we have virAsprintf and virVasprintf.
      
      * src/util/buf.h (virBufferVasprintf): New prototype.
      * src/util/buf.c (virBufferAsprintf): Move guts...
      (virBufferVasprintf): ...to new function.
      * src/libvirt_private.syms (buf.h): Export it.
      * bootstrap.conf (gnulib_modules): Add stdarg, for va_copy.
      f09acccf
    • E
      maint: rename virBufferVSprintf to virBufferAsprintf · 68ea80cf
      Eric Blake 提交于
      We already have virAsprintf, so picking a similar name helps for
      seeing a similar purpose.  Furthermore, the prefix V before printf
      generally implies 'va_list', even though this variant was '...', and
      the old name got in the way of adding a new va_list version.
      
      global rename performed with:
      
      $ git grep -l virBufferVSprintf \
        | xargs -L1 sed -i 's/virBufferVSprintf/virBufferAsprintf/g'
      
      then revert the changes in ChangeLog-old.
      68ea80cf
  12. 27 4月, 2011 1 次提交
  13. 23 11月, 2010 2 次提交
  14. 10 9月, 2010 1 次提交
    • C
      buf: Fix possible infinite loop in EscapeString, VSnprintf · 18af6f4e
      Cole Robinson 提交于
      The current code will go into an infinite loop if the printf generated
      string is >= 1000, AND exactly 1 character smaller than the amount of free
      space in the buffer. When this happens, we are dropped into the loop body,
      but nothing will actually change, because count == (buf->size - buf->use - 1),
      and virBufferGrow returns unchanged if count < (buf->size - buf->use)
      
      Fix this by removing the '- 1' bit from 'size'. The *nprintf functions handle
      the NULL byte for us anyways, so we shouldn't need to manually accommodate
      for it.
      
      Here's a bug where we are actually hitting this issue:
      https://bugzilla.redhat.com/show_bug.cgi?id=602772
      
      v2: Eric's improvements: while -> if (), remove extra va_list variable,
          make sure we report buffer error if snprintf fails
      
      v3: Add tests/virbuftest which reproduces the infinite loop before this
          patch, works correctly after
      18af6f4e
  15. 20 2月, 2010 1 次提交
  16. 19 2月, 2010 1 次提交
  17. 10 12月, 2009 1 次提交
    • M
      Add virBufferFreeAndReset() and replace free() · 1b9d0744
      Matthias Bolte 提交于
      Replace free(virBufferContentAndReset()) with virBufferFreeAndReset().
      Update documentation and replace all remaining calls to free() with
      calls to VIR_FREE(). Also add missing calls to virBufferFreeAndReset()
      and virReportOOMError() in OOM error cases.
      1b9d0744
  18. 15 10月, 2009 1 次提交
    • L
      Avoid crash in virBufferEscapeString · 04e06862
      Laine Stump 提交于
      * src/util/buf.c: if virBufferEscapeString was called on a buffer that
        had 0 bytes of space, a size of -1 will be passed to snprintf, resulting
        in a segmentation fault, this preallocate some space.
      04e06862
  19. 21 9月, 2009 1 次提交
    • D
      Move all shared utility files to src/util/ · 1355e055
      Daniel P. Berrange 提交于
      * src/bridge.c, src/bridge.h, src/buf.c, src/buf.h, src/cgroup.c,
        src/cgroup.h, src/conf.c, src/conf.h, src/event.c, src/event.h,
        src/hash.c, src/hash.h, src/hostusb.c, src/hostusb.h,
        src/iptables.c, src/iptables.h, src/logging.c, src/logging.h,
        src/memory.c, src/memory.h, src/pci.c, src/pci.h, src/qparams.c,
        src/qparams.h, src/stats_linux.c, src/stats_linux.h,
        src/threads-pthread.c, src/threads-pthread.h, src/threads-win32.c,
        src/threads-win32.h, src/threads.c, src/threads.h, src/util.c,
        src/util.h, src/uuid.c, src/uuid.h, src/virterror.c,
        src/virterror_internal.h, src/xml.c, src/xml.h: Move all files
        into src/util/
      * daemon/Makefile.am: Add -Isrc/util/ to build flags
      * src/Makefile.am: Add -Isrc/util/ to build flags and update for
        moved files
      * src/libvirt_private.syms: Export cgroup APIs since they're now
        in util rather than linking directly to drivers
      * src/xen/xs_internal.c: Disable bogus virEventRemoveHandle call
        when built under PROXY
      * proxy/Makefile.am: Update for changed file locations. Remove
        bogus build of event.c
      * tools/Makefile.am, tests/Makefile.am: Add -Isrc/util/ to build flags
      1355e055
  20. 05 8月, 2009 1 次提交
  21. 14 5月, 2009 1 次提交
  22. 17 11月, 2008 1 次提交
  23. 30 5月, 2008 1 次提交
  24. 23 5月, 2008 1 次提交
    • R
      Standardize use of header files, making internal.h primary. · 1d8d4f86
      Richard W.M. Jones 提交于
      	* qemud/internal.h, qemud/qemud.h: Rename this file so it
      	doesn't conflict with src/internal.h.
      	* HACKING: Document how header files should be used.
      	* qemud/Makefile.am: Add src/ directory to includes.
      	* qemud/event.c, qemud/mdns.c, qemud/qemud.c, qemud/remote.c,
      	qemud/remote_protocol.c, qemud/remote_protocol.h,
      	qemud/remote_protocol.x, src/buf.c, src/libvirt.c,
      	src/nodeinfo.c, src/qemu_conf.c, src/qemu_driver.c,
      	src/stats_linux.c, src/storage_backend.c, src/storage_backend_fs.c,
      	src/storage_backend_iscsi.c, src/storage_backend_logical.c,
      	src/storage_conf.c, src/storage_driver.c, src/util.c,
      	src/util.h, src/virsh.c, src/virterror.c, src/xend_internal.c,
      	src/xml.c, tests/reconnect.c, tests/xmlrpctest.c,
      	tests/qparamtest.c: Standardize	use of header files.
      	* docs/*, po/*: Rebuild docs.
      1d8d4f86
  25. 16 5月, 2008 1 次提交
    • J
      start using c-ctype functions · c1ee35af
      Jim Meyering 提交于
      Up to now, we've been avoiding ctype functions like isspace, isdigit,
      etc.  because they are locale-dependent.  Now that we have the c-ctype
      functions, we can start using *them*, to make the code more readable
      with changes like these:
      
      -        /* This may not work on EBCDIC. */
      -        if ((*p >= 'a' && *p <= 'z') ||
      -            (*p >= 'A' && *p <= 'Z') ||
      -            (*p >= '0' && *p <= '9'))
      +        if (c_isalnum(*p))
      
      -    while ((*cur >= '0') && (*cur <= '9')) {
      +    while (c_isdigit(*cur)) {
      
      Also, some macros in conf.c used names that conflicted with
      standard meaning of "BLANK" and "SPACE", so I've adjusted them
      to be in line with the definition of e.g., isblank.
      In addition, I've wrapped those statement macros with do {...} while (0),
      so that we can't forget the ";" after a use.  There was one like that
      already (fixed below).  The missing semicolon would mess up automatic
      indenting.
      * src/buf.c (virBufferURIEncodeString):
      * src/conf.c (IS_EOL, SKIP_BLANKS_AND_EOL, SKIP_BLANKS)
      (virConfParseLong, virConfParseValue, virConfParseName)
      (virConfParseSeparator, virConfParseStatement, IS_BLANK, IS_CHAR)
      (IS_DIGIT, IS_SPACE, SKIP_SPACES):
      * src/nodeinfo.c:
      * src/qemu_conf.c (qemudParseInterfaceXML):
      * src/qemu_driver.c (qemudDomainBlockStats):
      * src/sexpr.c:
      * src/stats_linux.c:
      * src/util.c (virParseNumber, virDiskNameToIndex):
      * src/uuid.c (hextobin, virUUIDParse):
      * src/virsh.c:
      * src/xml.c (parseCpuNumber, virParseCpuSet):
      c1ee35af
  26. 09 5月, 2008 1 次提交
    • J
      Use gnulib's c-ctype.h, not <ctype.h>. · 25534052
      Jim Meyering 提交于
      # Convert uses of isspace to c_isspace, isdigit to c_isdigit, etc.
      re=$(man isspace|grep is.....,.is|sed 's/ -.*//' \
        |tr -s ', \n' \||sed 's/^|//;s/|$//')
      git grep -l -E "$re"|grep -Ev 'Chan|gnulib' \
        |xargs perl -pi -e 's/\b('"$re"')\b/c_$1/g'
      # Remove all uses of to_uchar
      git grep -l to_uchar|xargs perl -pi -e 's/to_uchar\((.*?)\)/$1/g'
      * src/util.h (to_uchar): Remove definition.
      (TOLOWER): Remove definition.
      (__virMacAddrCompare): Use c_tolower, not TOLOWER.
      Globally:
        Where needed, change <ctype.h> to <c-ctype.h>.
        Remove unnecessary inclusion of <ctype.h>.
      Ensure the global changes are never needed again:
      * Makefile.maint (sc_avoid_ctype_macros): Prohibit use of ctype
      macros.   Recommend c-ctype.h instead.
      (sc_prohibit_c_ctype_without_use): New rule.
      (sc_prohibit_ctype_h): New rule.  Disallow use of <ctype.h>.
      25534052
  27. 28 4月, 2008 1 次提交
  28. 11 4月, 2008 2 次提交
  29. 20 2月, 2008 1 次提交
  30. 06 2月, 2008 1 次提交
  31. 30 1月, 2008 2 次提交
    • J
      Enable the <config.h>-requiring test; fix violations · a3781881
      Jim Meyering 提交于
      Use <config.h>, not "config.h", per autoconf documentation.
      * Makefile.cfg (local-checks-to-skip) [sc_require_config_h]: Enable.
      * .x-sc_require_config_h: New file, to list exempted files.
      * Makefile.am (EXTRA_DIST): Add .x-sc_require_config_h.
      a3781881
    • J
      Given code like if (foo) free (foo); remove the useless "if (foo) " part. · acff2d11
      Jim Meyering 提交于
      Likewise, given if (foo != NULL) free (foo); remove the useless "if" test.
      
      * proxy/libvirt_proxy.c: Remove unnecessary "if" test before free.
      * python/generator.py: Likewise.
      * qemud/qemud.c: Likewise.
      * src/buf.c: Likewise.
      * src/conf.c: Likewise.
      * src/hash.c: Likewise.
      * src/iptables.c: Likewise.
      * src/libvirt.c: Likewise.
      * src/openvz_conf.c: Likewise.
      * src/qemu_conf.c: Likewise.
      * src/qemu_driver.c: Likewise.
      * src/remote_internal.c: Likewise.
      * src/test.c: Likewise.
      * src/virsh.c: Likewise.
      * src/virterror.c: Likewise.
      * src/xen_internal.c: Likewise.
      * src/xen_unified.c: Likewise.
      * src/xend_internal.c: Likewise.
      * src/xm_internal.c: Likewise.
      * src/xml.c: Likewise.
      * src/xmlrpc.c: Likewise.
      * src/xs_internal.c: Likewise.
      * tests/testutils.c: Likewise.
      * tests/xencapstest.c: Likewise.
      * tests/xmconfigtest.c: Likewise.
      acff2d11
  32. 17 12月, 2007 1 次提交
  33. 13 12月, 2007 1 次提交