[Pkg-libvirt-commits] [libguestfs] 81/384: builder: Use automake to build the binary.
Hilko Bengen
bengen at moszumanska.debian.org
Sun Mar 29 16:55:46 UTC 2015
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to branch experimental
in repository libguestfs.
commit 9135129b0f6e8eb171131ea0f7d729a960b74cb3
Author: Richard W.M. Jones <rjones at redhat.com>
Date: Fri Dec 12 09:43:52 2014 +0000
builder: Use automake to build the binary.
As this has the side effect of enabling warnings in the C code, I had
to fix a lot of C problems in this commit too.
---
.gitignore | 1 +
builder/Makefile.am | 233 ++++++++++++++++++++++-------------------------
builder/index-parse.y | 2 +
builder/index-parser-c.c | 2 +
builder/index-scan.l | 9 ++
builder/link.sh.in | 22 +++++
builder/pxzcat-c.c | 87 ++++++++++++------
builder/setlocale-c.c | 2 +
builder/uname-c.c | 2 +
configure.ac | 2 +
mllib/fsync-c.c | 3 +
11 files changed, 214 insertions(+), 151 deletions(-)
diff --git a/.gitignore b/.gitignore
index e3182a6..4ef8b37 100644
--- a/.gitignore
+++ b/.gitignore
@@ -59,6 +59,7 @@ Makefile.in
/builder/index-parse.h
/builder/index-scan.c
/builder/libguestfs.conf
+/builder/link.sh
/builder/*.qcow2
/builder/stamp-virt-builder.pod
/builder/stamp-virt-index-validate.pod
diff --git a/builder/Makefile.am b/builder/Makefile.am
index a964ae1..69fc11b 100644
--- a/builder/Makefile.am
+++ b/builder/Makefile.am
@@ -1,5 +1,5 @@
# libguestfs virt-builder tool
-# Copyright (C) 2013 Red Hat Inc.
+# Copyright (C) 2013-2014 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -18,17 +18,9 @@
include $(top_srcdir)/subdir-rules.mk
AM_YFLAGS = -d
-AM_CFLAGS = \
- -I$(shell $(OCAMLC) -where) \
- -I$(top_srcdir)/gnulib/lib \
- -I$(top_srcdir)/src \
- -I$(top_srcdir)/fish \
- -pthread \
- $(LIBLZMA_CFLAGS) \
- $(LIBTINFO_CFLAGS)
EXTRA_DIST = \
- $(SOURCES) \
+ $(SOURCES_MLI) $(SOURCES_ML) $(SOURCES_C) \
libguestfs.gpg \
test-index \
test-virt-builder.sh \
@@ -43,110 +35,105 @@ EXTRA_DIST = \
CLEANFILES = *~ *.annot *.cmi *.cmo *.cmx *.cmxa *.o virt-builder
-# Alphabetical order.
-SOURCES = \
- architecture.ml \
- builder.ml \
+SOURCES_MLI = \
cache.mli \
- cache.ml \
- cmdline.ml \
downloader.mli \
- downloader.ml \
get_kernel.mli \
- get_kernel.ml \
index_parser.mli \
- index_parser.ml \
- index-parser-c.c \
ini_reader.mli \
- ini_reader.ml \
languages.mli \
- languages.ml \
list_entries.mli \
- list_entries.ml \
- paths.ml \
- pxzcat.ml \
pxzcat.mli \
- pxzcat-c.c \
- setlocale.ml \
setlocale.mli \
- setlocale-c.c \
sigchecker.mli \
- sigchecker.ml \
sources.mli \
- sources.ml \
+ uname.mli
+
+SOURCES_ML = \
+ utils.ml \
+ pxzcat.ml \
+ setlocale.ml \
uname.ml \
- uname.mli \
- uname-c.c \
- utils.ml
+ architecture.ml \
+ ini_reader.ml \
+ paths.ml \
+ languages.ml \
+ get_kernel.ml \
+ cache.ml \
+ sources.ml \
+ downloader.ml \
+ sigchecker.ml \
+ index_parser.ml \
+ list_entries.ml \
+ cmdline.ml \
+ builder.ml
+
+SOURCES_C = \
+ $(top_srcdir)/mllib/fsync-c.c \
+ $(top_srcdir)/mllib/uri-c.c \
+ $(top_srcdir)/mllib/mkdtemp-c.c \
+ $(top_srcdir)/customize/perl_edit-c.c \
+ $(top_srcdir)/customize/crypt-c.c \
+ $(top_srcdir)/fish/uri.c \
+ $(top_srcdir)/fish/file-edit.c \
+ index-scan.c \
+ index-struct.c \
+ index-parse.c \
+ index-parser-c.c \
+ pxzcat-c.c \
+ setlocale-c.c \
+ uname-c.c
man_MANS =
noinst_DATA =
+bin_PROGRAMS =
if HAVE_OCAML
-# Note this list must be in dependency order.
-deps = \
- $(top_builddir)/mllib/libdir.cmx \
- $(top_builddir)/mllib/config.cmx \
- $(top_builddir)/mllib/common_gettext.cmx \
- $(top_builddir)/mllib/common_utils.cmx \
- $(top_builddir)/mllib/fsync-c.o \
- $(top_builddir)/mllib/fsync.cmx \
- $(top_builddir)/mllib/planner.cmx \
- $(top_builddir)/mllib/regedit.cmx \
- $(top_builddir)/mllib/JSON.cmx \
- $(top_builddir)/mllib/uri-c.o \
- $(top_builddir)/mllib/uRI.cmx \
- $(top_builddir)/mllib/mkdtemp-c.o \
- $(top_builddir)/mllib/mkdtemp.cmx \
- $(top_builddir)/customize/customize_utils.cmx \
- $(top_builddir)/customize/urandom.cmx \
- $(top_builddir)/customize/random_seed.cmx \
- $(top_builddir)/customize/hostname.cmx \
- $(top_builddir)/customize/timezone.cmx \
- $(top_builddir)/customize/firstboot.cmx \
- $(top_builddir)/customize/virt_customize-perl_edit-c.o \
- $(top_builddir)/customize/perl_edit.cmx \
- $(top_builddir)/customize/virt_customize-crypt-c.o \
- $(top_builddir)/customize/crypt.cmx \
- $(top_builddir)/customize/password.cmx \
- $(top_builddir)/customize/ssh_key.cmx \
- $(top_builddir)/customize/customize_cmdline.cmx \
- $(top_builddir)/customize/customize_run.cmx \
- $(top_builddir)/fish/guestfish-uri.o \
- $(top_builddir)/fish/guestfish-file-edit.o \
- utils.cmx \
- index-scan.o \
- index-struct.o \
- index-parse.o \
- index-parser-c.o \
- pxzcat-c.o \
- pxzcat.cmx \
- setlocale-c.o \
- setlocale.cmx \
- uname-c.o \
- uname.cmx \
- architecture.cmx \
- ini_reader.cmx \
- paths.cmx \
- languages.cmx \
- get_kernel.cmx \
- cache.cmx \
- sources.cmx \
- downloader.cmx \
- sigchecker.cmx \
- index_parser.cmx \
- list_entries.cmx \
- cmdline.cmx \
- builder.cmx
+bin_PROGRAMS += virt-builder
-if HAVE_OCAMLOPT
-OBJECTS = $(deps)
-else
-OBJECTS = $(patsubst %.cmx,%.cmo,$(deps))
-endif
-
-bin_SCRIPTS = virt-builder
+virt_builder_SOURCES = $(SOURCES_C)
+virt_builder_CPPFLAGS = \
+ -I. \
+ -I$(top_builddir) \
+ -I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib \
+ -I$(shell $(OCAMLC) -where) \
+ -I$(top_srcdir)/gnulib/lib \
+ -I$(top_srcdir)/src \
+ -I$(top_srcdir)/fish
+virt_builder_CFLAGS = \
+ -pthread \
+ $(WARN_CFLAGS) $(WERROR_CFLAGS) \
+ -Wno-unused-macros \
+ $(LIBLZMA_CFLAGS) \
+ $(LIBTINFO_CFLAGS) \
+ $(LIBXML2_CFLAGS)
+
+BOBJECTS = \
+ $(top_builddir)/mllib/libdir.cmo \
+ $(top_builddir)/mllib/config.cmo \
+ $(top_builddir)/mllib/common_gettext.cmo \
+ $(top_builddir)/mllib/common_utils.cmo \
+ $(top_builddir)/mllib/fsync.cmo \
+ $(top_builddir)/mllib/planner.cmo \
+ $(top_builddir)/mllib/regedit.cmo \
+ $(top_builddir)/mllib/JSON.cmo \
+ $(top_builddir)/mllib/uRI.cmo \
+ $(top_builddir)/mllib/mkdtemp.cmo \
+ $(top_builddir)/customize/customize_utils.cmo \
+ $(top_builddir)/customize/urandom.cmo \
+ $(top_builddir)/customize/random_seed.cmo \
+ $(top_builddir)/customize/hostname.cmo \
+ $(top_builddir)/customize/timezone.cmo \
+ $(top_builddir)/customize/firstboot.cmo \
+ $(top_builddir)/customize/perl_edit.cmo \
+ $(top_builddir)/customize/crypt.cmo \
+ $(top_builddir)/customize/password.cmo \
+ $(top_builddir)/customize/ssh_key.cmo \
+ $(top_builddir)/customize/customize_cmdline.cmo \
+ $(top_builddir)/customize/customize_run.cmo \
+ $(SOURCES_ML:.ml=.cmo)
+XOBJECTS = $(BOBJECTS:.cmo=.cmx)
# -I $(top_builddir)/src/.libs is a hack which forces corresponding -L
# option to be passed to gcc, so we don't try linking against an
@@ -154,6 +141,7 @@ bin_SCRIPTS = virt-builder
OCAMLPACKAGES = \
-package str,unix \
-I $(top_builddir)/src/.libs \
+ -I $(top_builddir)/gnulib/lib/.libs \
-I $(top_builddir)/ocaml \
-I $(top_builddir)/mllib \
-I $(top_builddir)/customize
@@ -161,40 +149,31 @@ if HAVE_OCAML_PKG_GETTEXT
OCAMLPACKAGES += -package gettext-stub
endif
-OCAMLCFLAGS = $(OCAML_FLAGS) $(OCAML_WARN_ERROR) $(OCAMLPACKAGES)
-OCAMLOPTFLAGS = $(OCAMLCFLAGS)
-
-OCAMLCLIBS = \
- $(LIBLZMA_LIBS) \
- $(LIBXML2_LIBS) \
- $(LIBINTL) \
- -L../src/.libs -lutils \
- -L../gnulib/lib/.libs -lgnu \
- -pthread -lpthread \
- $(LIBTINFO_LIBS) -lcrypt
+OCAMLFLAGS = $(OCAML_FLAGS) $(OCAML_WARN_ERROR)
-if HAVE_OCAMLOPT
-virt-builder: $(OBJECTS)
- $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) \
- mlguestfs.cmxa -linkpkg $^ \
- -cclib '$(OCAMLCLIBS)' \
- -o $@
+if !HAVE_OCAMLOPT
+OBJECTS = $(BOBJECTS)
+BEST = c
+OCAMLLINKFLAGS = mlguestfs.cma -custom
else
-virt-builder: $(OBJECTS)
- $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) \
- mlguestfs.cma -linkpkg $^ \
- -cclib '$(OCAMLCLIBS)' \
- -custom \
- -o $@
+OBJECTS = $(XOBJECTS)
+BEST = opt
+OCAMLLINKFLAGS = mlguestfs.cmxa
endif
+virt_builder_DEPENDENCIES = $(OBJECTS)
+virt_builder_LINK = \
+ ./link.sh \
+ $(OCAMLFIND) $(BEST) $(OCAMLFLAGS) $(OCAMLPACKAGES) $(OCAMLLINKFLAGS) \
+ $(OBJECTS) -o $@
+
.mli.cmi:
- $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -c $< -o $@
+ $(OCAMLFIND) ocamlc $(OCAMLFLAGS) $(OCAMLPACKAGES) -c $< -o $@
.ml.cmo:
- $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -c $< -o $@
+ $(OCAMLFIND) ocamlc $(OCAMLFLAGS) $(OCAMLPACKAGES) -c $< -o $@
if HAVE_OCAMLOPT
.ml.cmx:
- $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) -c $< -o $@
+ $(OCAMLFIND) ocamlopt $(OCAMLFLAGS) $(OCAMLPACKAGES) -c $< -o $@
endif
# Manual pages and HTML files for the website.
@@ -286,7 +265,7 @@ install-exec-hook:
$(LN_S) xdg/virt-builder $(DESTDIR)$(sysconfdir)/virt-builder
# Build a small C index validator program.
-bin_PROGRAMS = virt-index-validate
+bin_PROGRAMS += virt-index-validate
virt_index_validate_SOURCES = \
index-parse.y \
@@ -296,8 +275,14 @@ virt_index_validate_SOURCES = \
index-validate.c
virt_index_validate_CPPFLAGS = \
- -DLOCALEBASEDIR=\""$(datadir)/locale"\"
-
+ -DLOCALEBASEDIR=\""$(datadir)/locale"\" \
+ -I. \
+ -I$(top_builddir) \
+ -I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib \
+ -I$(top_srcdir)/src
+virt_index_validate_CFLAGS = \
+ $(WARN_CFLAGS) $(WERROR_CFLAGS) \
+ -Wno-unused-macros
virt_index_validate_LDADD = \
$(LTLIBINTL) \
../gnulib/lib/libgnu.la
diff --git a/builder/index-parse.y b/builder/index-parse.y
index 36f9f07..ab8b515 100644
--- a/builder/index-parse.y
+++ b/builder/index-parse.y
@@ -30,6 +30,8 @@
extern void yyerror (YYLTYPE * yylloc, yyscan_t scanner, struct parse_context *context, const char *msg);
extern int yylex (YYSTYPE * yylval, YYLTYPE * yylloc, yyscan_t scanner);
+
+extern int do_parse (struct parse_context *context, FILE *in);
extern void scanner_init (yyscan_t *scanner, struct parse_context *context, FILE *in);
extern void scanner_destroy (yyscan_t scanner);
diff --git a/builder/index-parser-c.c b/builder/index-parser-c.c
index 845abd7..52c8b86 100644
--- a/builder/index-parser-c.c
+++ b/builder/index-parser-c.c
@@ -45,6 +45,8 @@ extern void unix_error (int errcode, char * cmdname, value arg) Noreturn;
extern int do_parse (struct parse_context *context, FILE *in);
+extern value virt_builder_parse_index (value progv, value error_suffixv, value filenamev);
+
value
virt_builder_parse_index (value progv, value error_suffixv, value filenamev)
{
diff --git a/builder/index-scan.l b/builder/index-scan.l
index b5eade5..eddaa83 100644
--- a/builder/index-scan.l
+++ b/builder/index-scan.l
@@ -25,12 +25,21 @@
#include <stdlib.h>
#include <string.h>
+/* Silence gcc moans about unused macros. */
+#if defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-macros"
+#endif
+
#include "index-struct.h"
#include "index-parse.h"
#define YY_EXTRA_TYPE struct parse_context *
#define YY_USER_ACTION yylloc->first_line = yylloc->last_line = yylineno;
+extern void scanner_init (yyscan_t *scanner, struct parse_context *context, FILE *in);
+extern void scanner_destroy (yyscan_t scanner);
+
%}
%option nounput
diff --git a/builder/link.sh.in b/builder/link.sh.in
new file mode 100644
index 0000000..59f3c6f
--- /dev/null
+++ b/builder/link.sh.in
@@ -0,0 +1,22 @@
+# libguestfs Makefile.am
+# @configure_input@
+# (C) Copyright 2014 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+# Hack automake to link binary properly. There is no other way to add
+# the -cclib parameter to the end of the command line.
+
+exec "$@" -linkpkg -cclib '-pthread -lpthread -lutils @LIBTINFO_LIBS@ -lcrypt @LIBLZMA_LIBS@ @LIBXML2_LIBS@ @LIBINTL@ -lgnu'
diff --git a/builder/pxzcat-c.c b/builder/pxzcat-c.c
index 42610c0..bd4c0a8 100644
--- a/builder/pxzcat-c.c
+++ b/builder/pxzcat-c.c
@@ -20,6 +20,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
@@ -34,6 +35,9 @@
#include <caml/memory.h>
#include <caml/mlvalues.h>
+#include "guestfs.h"
+#include "guestfs-internal-frontend.h"
+
#include "ignore-value.h"
#if HAVE_LIBLZMA
@@ -55,6 +59,8 @@ extern void unix_error (int errcode, char * cmdname, value arg) Noreturn;
#define PARALLEL_XZCAT 0
#endif
+extern value virt_builder_using_parallel_xzcat (value unitv);
+
value
virt_builder_using_parallel_xzcat (value unitv)
{
@@ -65,6 +71,8 @@ virt_builder_using_parallel_xzcat (value unitv)
static void pxzcat (value filenamev, value outputfilev, unsigned nr_threads);
#endif /* PARALLEL_XZCAT */
+extern value virt_builder_pxzcat (value inputfilev, value outputfilev);
+
value
virt_builder_pxzcat (value inputfilev, value outputfilev)
{
@@ -98,13 +106,13 @@ virt_builder_pxzcat (value inputfilev, value outputfilev)
fd = open (String_val (outputfilev), O_WRONLY|O_CREAT|O_TRUNC|O_NOCTTY, 0666);
if (fd == -1)
- unix_error (errno, "open", outputfilev);
+ unix_error (errno, (char *) "open", outputfilev);
pid = fork ();
if (pid == -1) {
int err = errno;
close (fd);
- unix_error (err, "fork", Nothing);
+ unix_error (err, (char *) "fork", Nothing);
}
if (pid == 0) { /* child - run xzcat */
@@ -117,7 +125,7 @@ virt_builder_pxzcat (value inputfilev, value outputfilev)
close (fd);
if (waitpid (pid, &status, 0) == -1)
- unix_error (errno, "waitpid", Nothing);
+ unix_error (errno, (char *) "waitpid", Nothing);
if (!WIFEXITED (status) || WEXITSTATUS (status) != 0)
caml_failwith (XZCAT " program failed, see earlier error messages");
@@ -141,8 +149,6 @@ virt_builder_pxzcat (value inputfilev, value outputfilev)
#define XZ_HEADER_MAGIC "\xfd" "7zXZ\0"
#define XZ_HEADER_MAGIC_LEN 6
-#define XZ_FOOTER_MAGIC "YZ"
-#define XZ_FOOTER_MAGIC_LEN 2
static int check_header_magic (int fd);
static lzma_index *parse_indexes (value filenamev, int fd);
@@ -158,7 +164,7 @@ pxzcat (value filenamev, value outputfilev, unsigned nr_threads)
/* Open the file. */
fd = open (String_val (filenamev), O_RDONLY);
if (fd == -1)
- unix_error (errno, "open", filenamev);
+ unix_error (errno, (char *) "open", filenamev);
/* Check file magic. */
if (!check_header_magic (fd)) {
@@ -181,31 +187,31 @@ pxzcat (value filenamev, value outputfilev, unsigned nr_threads)
if (ofd == -1) {
int err = errno;
close (fd);
- unix_error (err, "open", outputfilev);
+ unix_error (err, (char *) "open", outputfilev);
}
if (ftruncate (ofd, 1) == -1) {
int err = errno;
close (fd);
- unix_error (err, "ftruncate", outputfilev);
+ unix_error (err, (char *) "ftruncate", outputfilev);
}
if (lseek (ofd, 0, SEEK_SET) == -1) {
int err = errno;
close (fd);
- unix_error (err, "lseek", outputfilev);
+ unix_error (err, (char *) "lseek", outputfilev);
}
if (write (ofd, "\0", 1) == -1) {
int err = errno;
close (fd);
- unix_error (err, "write", outputfilev);
+ unix_error (err, (char *) "write", outputfilev);
}
if (ftruncate (ofd, size) == -1) {
int err = errno;
close (fd);
- unix_error (err, "ftruncate", outputfilev);
+ unix_error (err, (char *) "ftruncate", outputfilev);
}
/* Tell the kernel we won't read the output file. */
@@ -217,7 +223,7 @@ pxzcat (value filenamev, value outputfilev, unsigned nr_threads)
lzma_index_end (idx, NULL);
if (close (fd) == -1)
- unix_error (errno, "close", filenamev);
+ unix_error (errno, (char *) "close", filenamev);
}
static int
@@ -256,7 +262,7 @@ parse_indexes (value filenamev, int fd)
/* Check file size is a multiple of 4 bytes. */
pos = lseek (fd, 0, SEEK_END);
if (pos == (off_t) -1)
- unix_error (errno, "lseek", filenamev);
+ unix_error (errno, (char *) "lseek", filenamev);
if ((pos & 3) != 0)
caml_invalid_argument ("input not an xz file: size is not a multiple of 4 bytes");
@@ -269,10 +275,10 @@ parse_indexes (value filenamev, int fd)
caml_invalid_argument ("corrupted xz file");
if (lseek (fd, -LZMA_STREAM_HEADER_SIZE, SEEK_CUR) == -1)
- unix_error (errno, "lseek", filenamev);
+ unix_error (errno, (char *) "lseek", filenamev);
if (read (fd, footer, LZMA_STREAM_HEADER_SIZE) != LZMA_STREAM_HEADER_SIZE)
- unix_error (errno, "read", filenamev);
+ unix_error (errno, (char *) "read", filenamev);
/* Skip stream padding. */
if (footer[8] == 0 && footer[9] == 0 &&
@@ -304,7 +310,7 @@ parse_indexes (value filenamev, int fd)
/* Seek backwards to the index of this stream. */
if (lseek (fd, pos, SEEK_SET) == -1)
- unix_error (errno, "lseek", filenamev);
+ unix_error (errno, (char *) "lseek", filenamev);
/* Decode the index. */
r = lzma_index_decoder (&strm, &this_index, UINT64_MAX);
@@ -322,7 +328,7 @@ parse_indexes (value filenamev, int fd)
n = read (fd, &buf, strm.avail_in);
if (n == -1)
- unix_error (errno, "read", filenamev);
+ unix_error (errno, (char *) "read", filenamev);
index_size -= strm.avail_in;
@@ -341,10 +347,10 @@ parse_indexes (value filenamev, int fd)
/* Read and decode the stream header. */
if (lseek (fd, pos, SEEK_SET) == -1)
- unix_error (errno, "lseek", filenamev);
+ unix_error (errno, (char *) "lseek", filenamev);
if (read (fd, header, LZMA_STREAM_HEADER_SIZE) != LZMA_STREAM_HEADER_SIZE)
- unix_error (errno, "read stream header", filenamev);
+ unix_error (errno, (char *) "read stream header", filenamev);
r = lzma_stream_header_decode (&header_flags, header);
if (r != LZMA_OK) {
@@ -456,7 +462,7 @@ iter_blocks (lzma_index *idx, unsigned nr_threads,
global.iter_finished = 0;
err = pthread_mutex_init (&global.iter_mutex, NULL);
if (err != 0)
- unix_error (err, "pthread_mutex_init", Nothing);
+ unix_error (err, (char *) "pthread_mutex_init", Nothing);
global.filename = String_val (filenamev);
global.fd = fd;
@@ -472,7 +478,7 @@ iter_blocks (lzma_index *idx, unsigned nr_threads,
for (u = 0; u < nr_threads; ++u) {
err = pthread_create (&thread[u], NULL, worker_thread, &per_thread[u]);
if (err != 0)
- unix_error (err, "pthread_create", Nothing);
+ unix_error (err, (char *) "pthread_create", Nothing);
}
/* Wait for the threads to exit. */
@@ -491,6 +497,24 @@ iter_blocks (lzma_index *idx, unsigned nr_threads,
caml_invalid_argument ("some threads failed, see earlier errors");
}
+static int
+xpwrite (int fd, const void *bufvp, size_t count, off_t offset)
+{
+ const char *buf = bufvp;
+ ssize_t r;
+
+ while (count > 0) {
+ r = pwrite (fd, buf, count, offset);
+ if (r == -1)
+ return -1;
+ count -= r;
+ offset += r;
+ buf += r;
+ }
+
+ return 0;
+}
+
/* Iterate over the blocks and uncompress. */
static void *
worker_thread (void *vp)
@@ -500,19 +524,29 @@ worker_thread (void *vp)
lzma_index_iter iter;
int err;
off_t position, oposition;
- uint8_t header[LZMA_BLOCK_HEADER_SIZE_MAX];
+ CLEANUP_FREE uint8_t *header = NULL;
ssize_t n;
lzma_block block;
- lzma_filter filters[LZMA_FILTERS_MAX + 1];
+ CLEANUP_FREE lzma_filter *filters = NULL;
lzma_ret r;
lzma_stream strm = LZMA_STREAM_INIT;
- uint8_t buf[BUFFER_SIZE];
- unsigned char outbuf[BUFFER_SIZE];
+ CLEANUP_FREE uint8_t *buf = NULL;
+ CLEANUP_FREE uint8_t *outbuf = NULL;
size_t i;
lzma_bool iter_finished;
state->status = -1;
+ header = malloc (sizeof (uint8_t) * LZMA_BLOCK_HEADER_SIZE_MAX);
+ filters = malloc (sizeof (lzma_filter) * (LZMA_FILTERS_MAX + 1));
+ buf = malloc (sizeof (uint8_t) * BUFFER_SIZE);
+ outbuf = malloc (sizeof (uint8_t) * BUFFER_SIZE);
+
+ if (header == NULL || filters == NULL || buf == NULL || outbuf == NULL) {
+ perror ("malloc");
+ return &state->status;
+ }
+
for (;;) {
/* Get the next block. */
err = pthread_mutex_lock (&global->iter_mutex);
@@ -633,8 +667,7 @@ worker_thread (void *vp)
* sparseness. However we have to update oposition.
*/
if (!is_zero (outbuf, wsz)) {
- if (pwrite (global->ofd, outbuf, wsz, oposition) != wsz) {
- /* XXX Handle short writes. */
+ if (xpwrite (global->ofd, outbuf, wsz, oposition) == -1) {
perror (global->filename);
return &state->status;
}
diff --git a/builder/setlocale-c.c b/builder/setlocale-c.c
index e1ad75d..f2ad853 100644
--- a/builder/setlocale-c.c
+++ b/builder/setlocale-c.c
@@ -37,6 +37,8 @@ static const int lc_string_table[7] = {
#define Val_none (Val_int (0))
+extern value virt_builder_setlocale (value val_category, value val_name);
+
value
virt_builder_setlocale (value val_category, value val_name)
{
diff --git a/builder/uname-c.c b/builder/uname-c.c
index b8a6ef7..fc63233 100644
--- a/builder/uname-c.c
+++ b/builder/uname-c.c
@@ -33,6 +33,8 @@
extern void unix_error (int errcode, char * cmdname, value arg) Noreturn;
#endif
+extern value virt_builder_uname (value unit);
+
value
virt_builder_uname (value unit)
{
diff --git a/configure.ac b/configure.ac
index 3e839c3..531215a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1665,6 +1665,8 @@ mkdir -p \
dnl http://www.mail-archive.com/automake@gnu.org/msg10204.html
AC_CONFIG_FILES([appliance/libguestfs-make-fixed-appliance],
[chmod +x,-w appliance/libguestfs-make-fixed-appliance])
+AC_CONFIG_FILES([builder/link.sh],
+ [chmod +x,-w builder/link.sh])
AC_CONFIG_FILES([customize/link.sh],
[chmod +x,-w customize/link.sh])
AC_CONFIG_FILES([inspector/test-xmllint.sh],
diff --git a/mllib/fsync-c.c b/mllib/fsync-c.c
index 4ba7fd4..a4bf92a 100644
--- a/mllib/fsync-c.c
+++ b/mllib/fsync-c.c
@@ -38,6 +38,9 @@ extern void unix_error (int errcode, char * cmdname, value arg) Noreturn;
/* OCaml doesn't bind any *sync* calls. */
+extern value virt_resize_sync (value unitv);
+extern value virt_resize_fsync_file (value filenamev);
+
/* NB: This is a "noalloc" call. */
value
virt_resize_sync (value unitv)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git
More information about the Pkg-libvirt-commits
mailing list