45 Commits

Author SHA1 Message Date
Pino Toscano
eea210dbf7 Use the getprogname gnulib module
Make use of the recently added 'getprogname' module in gnulib: replace
our guestfs_int_program_name with the getprogname() provided by the
module, since it does the same thing, and in a portable way.
As consequence of the above, use gnulib in a couple of tests that use
getprogname().

Since guestfs_int_program_name is gone, drop the configure checks
associated with it.
2016-09-08 09:57:15 +02:00
Richard W.M. Jones
df9782ec3a tests: Enable and fix test-add-libvirt-dom test.
Commit 96158d42f5 enabled the previously
private guestfs_add_libvirt_dom API.  It also tried to enable the
existing test for this API, but failed to do that correctly.  Also the
test was broken.  Fix all of this.

This fixes commit 96158d42f5.
2014-12-12 15:50:07 +00:00
Richard W.M. Jones
0701b24e5c daemon: No longer needs its own copy of gnulib.
Since the daemon has long since used the same build system as the rest
of libguestfs, it no longer needs its own gnulib.

This arcane bit of code was left over from
commit e05ddc70f1 (added 2009-08-03 !)
2014-10-31 18:30:36 +00:00
Richard W.M. Jones
6d6644d52d launch: libvirt: Implement drive secrets (RHBZ#1159016).
Implement the GUESTFS_ADD_DRIVE_OPTS_SECRET argument of
guestfs_add_drive_opts.  For libvirt we have to save the secret in
libvirtd first, get a UUID, and then pass the UUID back through the
domain XML.
2014-10-31 17:24:54 +00:00
Pino Toscano
57512e7785 normalize iconv handling
Since the signature of iconv() changes between implementations (the
constness of the second parameter, in particular), make use of the iconv
module of gnulib to handle these potential differences, including an
external (out of libc) iconv implementation.
2014-10-23 19:03:12 +02:00
Pino Toscano
65f830b84c build: use the ptsname_r gnulib module
virt-p2v uses ptsname_r, which is not portable but implemented by
gnulib.
2014-10-23 19:03:11 +02:00
Martin Kletzander
475f5ce6a4 Get rid of gnulib error
Even though this doesn't stop the compile phase, I find it a bit
distracting that this is what I get with bootstrap:

../.gnulib/gnulib-tool: *** cannot find ./configure.ac - make sure you
run gnulib-tool from within your package's directory
../.gnulib/gnulib-tool: *** Stop.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2013-09-05 10:19:01 +01:00
Richard W.M. Jones
142b874ce8 Remove use of gnulib progname module.
It's simpler to use the glibc 'program_invocation_short_name(3)'
feature, and fall back to a generic solution.  Also remove risky
assignments to argv[0].
2013-04-11 14:42:54 +01:00
Richard W.M. Jones
e73944faf4 RHEL 5: gnulib: Use module mkstemps.
RHEL 5 glibc doesn't have this function.
2013-03-09 18:53:51 +00:00
Richard W.M. Jones
e4495b24bc daemon: link: Remove use of PATH_MAX.
Replace readlink calls with gnulib areadlink function.
2013-02-11 13:21:51 +00:00
Masami HIRATA
7d3f190d90 Mac OS X: Use gnulib stat-time module explicitly.
Signed-off-by: Masami HIRATA <msmhrt@gmail.com>
2012-07-24 19:40:40 +01:00
Masami HIRATA
a47fa7a65e Mac OS X: Use gnulib fstatat module explicitly.
Signed-off-by: Masami HIRATA <msmhrt@gmail.com>
2012-07-24 19:18:37 +01:00
Masami HIRATA
d6ef91d7c4 Mac OS X: Use gnulib memmem module explicitly.
m4/.gitignore: Update.

Signed-off-by: Masami HIRATA <msmhrt@gmail.com>
2012-07-24 19:18:37 +01:00
Richard W.M. Jones
0a1b2f85e6 launch: libvirt: Use <driver name="qemu" type=[format] />.
We were using format= which was bogus and libvirt was ignoring it and
forcing raw format instead.

Also in its default configuration libvirt won't do disk format
autodetection at all, so we must do it instead.
2012-07-23 18:08:16 +01:00
Richard W.M. Jones
6e1b5f0fea gnulib: Don't include or run getlogin_r test (thanks Jim Meyering).
See:
https://lists.gnu.org/archive/html/bug-gnulib/2012-07/msg00194.html
2012-07-19 12:43:55 +01:00
Richard W.M. Jones
5764ac12cf bootstrap: Remove autopoint, po stuff from bootstrap script.
It's not needed since we no longer use gettextize cruft.
2012-05-09 16:13:57 +01:00
Richard W.M. Jones
606732d02e Use O_CLOEXEC / SOCK_CLOEXEC for almost all file descriptors.
The presumption is that all file descriptors should be created with
the close-on-exec flag set.  The only exception are file descriptors
that we want passed through to exec'd subprocesses (mainly pipes and
stdin/stdout/stderr).

For open calls, we pass O_CLOEXEC as an extra flag, eg:

  fd = open ("foo", O_RDONLY|O_CLOEXEC);

This is a Linux-ism, but using a macro we can easily make it portable.

For sockets, similarly:

  sock = socket (..., SOCK_STREAM|SOCK_CLOEXEC, ...);

For accepted sockets, we use the Linux accept4 system call which
allows flags to be supplied, but we use the Gnulib 'accept4' module to
make this portable.

For dup, dup2, we use the Linux dup3 system call, and the Gnulib
modules 'dup3' and 'cloexec'.
2012-03-14 19:30:46 +00:00
Richard W.M. Jones
60d5a50f4d daemon: Remove separate configure of daemon subdirectory.
Combine the two Gnulib instances together.

Add checks from old daemon/configure.ac into configure.ac.

Fix daemon/Makefile.am so it is like a normal subdirectory
Makefile.am.

Because we are now using the replacement strerror_r function from
Gnulib (instead of the one from glibc directly), this requires a small
change to src/guestfs.c.
2011-08-05 12:34:11 +01:00
Jim Meyering
343ba6d482 bootstrap: use --libtool 2011-06-10 12:29:49 +01:00
Richard W.M. Jones
fbc2555903 New tool: virt-filesystems
This tool replaces virt-list-filesystems and virt-list-partitions with
a new tool written in C with a more uniform command line structure
and output.

This existing Perl tools are deprecated but remain indefinitely.
2010-11-23 10:22:08 +00:00
Richard Jones
e3acf93ce9 Revert "Remove ocaml/.depend from git."
This reverts commit 064569bcbf.

This commit does the wrong thing: creating an empty ocaml/.depend
file is wrong because building the OCaml bindings will fail.
Not having this file will prevent automake from running.  Therefore
this file has to exist with the correct content in git.
2010-11-08 22:35:13 +00:00
Matthew Booth
064569bcbf Remove ocaml/.depend from git.
ocaml/.depend is automatically generated. This patch removes it from git.
2010-10-28 15:16:14 +01:00
Richard Jones
4813311807 po: Don't generate po/Makevars file and include Perl keywords (RHBZ#559963).
I don't see a reason to autogenerate po/Makevars, and in the
earlier commit which changed this file to being autogenerated
we accidentally lost the special Perl keywords, copyright notice
and bug reporting address.  Fix all of that.

This partially reverts commit febff9d2a3.
2010-05-12 18:13:01 +01:00
Richard Jones
f5d52fa3c0 Mac OS X: Use gnulib setenv module explicitly.
See:
https://www.redhat.com/archives/libguestfs/2010-March/thread.html#00094
2010-03-22 08:38:36 +00:00
Richard Jones
cb9613b993 Rewrite libguestfs-supermin-helper in C.
libguestfs-supermin-helper was previously a shell script.  Although
we had steadily optimized it, there were a number of intractable
hot spots:

  (1) cpio still reads input files in 512 byte chunks; this is *very*
    pessimal behaviour, particularly when SELinux is enabled.
  (2) the hostfiles globbing was done very inefficiently by the shell,
    with the shell rereading the same directory over and over again.

This is a rewrite of this shell script in C.  It is approximately
3 times faster without SELinux, and has an even greater speed difference
with SELinux.

The main features are:

  (a) It never frees memory, making it simpler.  The program is designed
    to run and exit in sub-second times, so this is acceptable.
  (b) It caches directory reads, making the globbing of host files much
    faster (measured this as ~ 4 x speed up).
  (c) It doesn't use external cpio, but instead contains code to write
    newc format cpio files, which is all that the kernel can read.  Unlike
    cpio, this code uses large buffers for reads and writes.
  (d) Ignores missing or unreadable hostfiles, whereas cpio gave a
    warning.
  (e) Checks all return values from system calls.
  (f) With --verbose flag, it will print messages timing itself.

This passes all tests.

Updated with feedback from Jim Meyering.
2010-03-12 16:21:58 +00:00
Richard Jones
4718aeb9f0 hivex: Add HIVEX_OPEN_WRITE flag to allow hive to be opened for writing.
If this flag is omitted (as in the case for all existing callers)
then the hive is still opened read-only.

We add a 'writable' flag to the hive handle, and we change the way
that the hive file (data) is stored.  The data is still mmapped if
the file is opened read-only, since that is more efficient and allows
us to handle larger hives.  However if we need to write to the file
then we have to read it all into memory, since if we had to extend the
file we need to realloc that data.

Note the manpage section L</WRITING TO HIVE FILES> comes in a later
commit.
2010-02-04 11:06:33 +00:00
Richard Jones
58abe782bf guestfish: Use xstrtol to parse integers (RHBZ#557655).
Current code uses atoi to parse the generator Int type and
atoll to parse the generator Int64 type.  The problem with the
ato* functions is that they don't cope with errors very well,
and they cannot parse numbers that begin with 0.. or 0x..
for octal and hexadecimal respectively.

This replaces the atoi call with a call to Gnulib xstrtol
and the atoll call with a call to Gnulib xstrtoll.

The generated code looks like this for all Int arguments:

  {
    strtol_error xerr;
    long r;

    xerr = xstrtol (argv[0], NULL, 0, &r, "");
    if (xerr != LONGINT_OK) {
      fprintf (stderr,
               _("%s: %s: invalid integer parameter (%s returned %d)\n"),
               cmd, "memsize", "xstrtol", xerr);
      return -1;
    }
    /* The Int type in the generator is a signed 31 bit int. */
    if (r < (-(2LL<<30)) || r > ((2LL<<30)-1)) {
      fprintf (stderr, _("%s: %s: integer out of range\n"), cmd, "memsize");
      return -1;
    }
    /* The check above should ensure this assignment does not overflow. */
    memsize = r;
  }

and like this for all Int64 arguments (note we don't need the
range check for these):

  {
    strtol_error xerr;
    long long r;

    xerr = xstrtoll (argv[1], NULL, 0, &r, "");
    if (xerr != LONGINT_OK) {
      fprintf (stderr,
               _("%s: %s: invalid integer parameter (%s returned %d)\n"),
               cmd, "size", "xstrtoll", xerr);
      return -1;
    }
    size = r;
  }

Note this also fixes an unrelated bug in guestfish handling of
RBufferOut.  We were using 'fwrite' without checking the return
value, and this could have caused silent failures, eg. in the case
where there was not enough disk space to store the resulting file,
or even if the program was interrupted (but continued) during the
write.

Replace this with Gnulib 'full-write', and check the return value
and report errors.
2010-01-25 12:07:34 +00:00
Richard Jones
cada248a53 lib: Add thread-safety to global list of handles.
This commit uses the Gnulib 'lock' module to implement a mutex on
the global list of handles which is stored by the library.

Note that Gnulib nicely avoids explicitly linking with -lpthread
unless the application program itself links to -lpthread.  Locks
are only enabled in multithreaded applications.

$ ldd src/.libs/libguestfs.so.0.217.0
	linux-vdso.so.1 =>  (0x00007fffcb7ff000)
	libc.so.6 => /lib64/libc.so.6 (0x00007f96a4e6c000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f96a544d000)

Please enter the commit message for your changes. Lines starting
2009-12-07 11:13:12 +00:00
Richard Jones
429de22541 FUSE filesystem support.
This implements FUSE filesystem support so that any libguestfs-
accessible disk image can be mounted as a local filesystem.

Note: file writes (ie. write(2) system call) is not yet implemented.

The API needs more test coverage, particularly lesser-used system
calls.

The big unresolved issue is UID/GID mapping between guest filesystem
IDs and the host.  It's not easy to automate this because you need
extra details about the guest itself in order to get to its
UID->username map (eg. /etc/passwd from the guest).
2009-11-03 15:57:26 +00:00
Jim Meyering
6a14f1c250 avoid use of all ctype macros
* cfg.mk (disable_temporarily): Don't disable sc_avoid_ctype_macros.
* fish/tilde.c: Remove unnecessary inclusion of ctype.h.
* bootstrap: Add gnulib's c-ctype module to the list.
* daemon/m4/gnulib-cache.m4: Likewise.
* daemon/ext2.c: Include "c-ctype.h", not <ctype.h>.
Use c_isspace, etc, rather than isspace.
* daemon/guestfsd.c: Likewise.
* daemon/lvm.c: Likewise.
* daemon/proto.c: Likewise.
* fish/fish.c: Likewise.
* fish/tilde.c: Likewise.
* src/generator.ml: Likewise.
* src/guestfs.c: Likewise.
* examples/to-xml.c: Likewise.
* examples/Makefile.am (to_xml_CPPFLAGS): Add -I$(top_srcdir)/gnulib/lib
so inclusion of "c-ctype.h" works.
(to_xml_CPPFLAGS): Rename from to_xml_CFLAGS.
2009-09-24 11:00:44 +02:00
Richard Jones
dcb5aa0183 Gnulib: Add arpa-inet and netinet-in modules. 2009-09-22 10:55:03 +01:00
Jim Meyering
cfab42b407 avoid build-from-scratch failure due to missing daemon/configure
* bootstrap: Don't use autoreconf's --norecursive
option.  We require the default --recursive behavior in order
to create daemon/configure.  Reported by Matthew Booth.
2009-09-04 18:00:23 +02:00
Jim Meyering
0fc0e4bd73 build: use only one m4/ directory
* Makefile.am (ACLOCAL_AMFLAGS): Specify only one include dir: m4.
* bootstrap: Tell gnulib-tool to put .m4 files in m4/, not gnulib/m4.
* autogen.sh: Move autoreconf from here into...
* bootstrap: ...here, so that it is run only when gnulib-tool is.
Also, tell it to skip the usual autopoint and libtoolize runs.
* m4/.gitignore: Update.
2009-08-25 18:44:27 +02:00
Jim Meyering
f482e7ea66 build: invoke autopoint with --force
* bootstrap: Invoke autopoint with --force, to avoid warning
about existing build-aux/config.rpath.
Invoke libtoolize before gnulib-tool, to avoid spurious warnings.
* autogen.sh: Add comments.
Remove build-aux/config.rpath before running autoreconf.
2009-08-25 18:44:27 +02:00
Jim Meyering
8817709009 build: don't define _GNU_SOURCE manually
Now that we're using gnulib in earnest, any manual definition
would provoke a redefinition warning.
* fish/fish.c (_GNU_SOURCE): Don't define.
* fish/destpaths.c (_GNU_SOURCE): Likewise.
* src/guestfs.c (_GNU_SOURCE): Likewise.
* bootstrap (modules): Add asprintf, strchrnul, strerror, strndup
and vasprintf.
* fish/fish.c (main): Set argv[0] to sanitized program_name, so
functions like getopt_long that use argv[0] use the clean name.
2009-08-24 18:15:13 +02:00
Jim Meyering
b9a691af0f guestfish: diagnose stdout write failure
Use gnulib's closeout module to ensure any failure to write to
stdout is detected and reported.
* fish/fish.c: Include "closeout.h".
(main): Call atexit (close_stdout);
* bootstrap (modules): Add closeout.
2009-08-24 18:15:13 +02:00
Jim Meyering
6cd965e007 guestfish: write --help to stdout, use gnulib's progname module
* fish/fish.c: Include "progname.h".
(main): Call set_program_name to initialize.
Don't hard-code guestfish everywhere.  Use program_name.
However, be careful when modifying argv[0], since it is used
in the hopes that it is an absolute file name.
(usage): Don't spew all of --help for a mis-typed option.
Split long lines.
2009-08-24 18:15:06 +02:00
Jim Meyering
1d8afa2416 build: suppress an ignored-write-return-value warning
* bootstrap (modules): Add ignore-value.
* src/guestfs.c: Include "ignore-value.h".
(stdout_event): Ignore failure to write to stderr.
Also, prefer STDERR_FILENO over the literal "2".
* src/Makefile.am (libguestfs_la_CPPFLAGS): Include gnulib's .h files.
(libprotocol_la_CFLAGS): Remove -Wall -Wno-unused.
2009-08-18 17:20:06 +02:00
Jim Meyering
9f7ebef3d4 build: avoid first-time configure-from-clone failure
* bootstrap: Run autopoint before using the file it creates,
po/Makevars.template.  Reported by Richard Jones.  Details here:
https://www.redhat.com/archives/libguestfs/2009-August/msg00135.html
2009-08-10 15:37:27 +02:00
Jim Meyering
d35528d240 build: remove bootstrap's --gnulib-srcdir option
...because it probably didn't work, and even if it did, we've
discovered that using a separate git repo like that can lead
to subtle mix-ups.
Also, fix invocation of gnulib-tool in daemon/.
2009-08-06 13:54:56 +02:00
Jim Meyering
03e59ae92a build: fix build failure
* bootstrap (gnulib_tool): Create lib and tests directories
under daemon/ before running gnulib-tool there.
2009-08-06 13:47:48 +02:00
Jim Meyering
e05ddc70f1 daemon: use gnulib
* daemon/Makefile.am (SUBDIRS): Define.
(AM_CPPFLAGS): Define, to include from gnulib's lib/
(LDADD): Define, to link with gnulib's libgnu.a.
* daemon/configure.ac: Use AC_CONFIG_AUX_DIR([build-aux]),
gl_EARLY and gl_INIT.
(AC_CONFIG_FILES): Add lib/Makefile and tests/Makefile
* daemon/m4/gnulib-cache.m4: New file, generated by running
../.gnulib/gnulib-tool --import --with-tests hash
* daemon/.gitignore: Ignore all of the imported files.
build: tell bootstrap about daemon/
* bootstrap: Run gnulib-tool --update in daemon/.
Remove bootstrap's --gnulib-srcdir option, because it probably
didn't work, and even if it did, we've discovered that using
a separate git repo like that can lead to subtle mix-ups.
2009-08-06 12:28:04 +02:00
Jim Meyering
a86f512716 build: generate some just-removed files in po/
* bootstrap: Generate po/Makevars and po/LINGUAS.
2009-08-05 15:23:39 +02:00
Jim Meyering
2f1a50d816 Convert all TABs-as-indentation to spaces.
Do it by running this command:
[exempted files are matched via .x-sc_TAB_in_indentation]

  git ls-files \
    | pcregrep -vf .x-sc_TAB_in_indentation \
    | xargs pcregrep -l '^ *\t' \
    | xargs perl -MText::Tabs -ni -le \
      '$m=/^( *\t[ \t]*)(.*)/; print $m ? expand($1) . $2 : $_'
2009-08-03 17:17:57 +02:00
Jim Meyering
480a489ee4 maint: use a git submodule for gnulib
* .gitmodules: New file, to track gnulib.
* .gnulib: Submodule directory.
* Makefile.am (EXTRA_DIST): Don't list config.rpath or
gitlog-to-changelog.
* autogen.sh: Adapt to use the new submodule.
* cfg.mk: New file.
(SUBDIRS): Add gnulib/lib and gnulib/tests.
(dist-hook): Reflect new location of getlog-to-changelog.
* configure.ac: Set build-aux/ as AUX_DIR.
Invoke gl_EARLY and gl_INIT.
(AC_CONFIG_FILES): Add gnulib/lib/Makefile and gnulib/tests/Makefile.
2009-08-03 15:14:30 +02:00