---
align/scan.c | 66 +-
builder/index-parser-c.c | 25 +-
builder/index-struct.h | 2 +-
builder/index-validate.c | 40 +-
builder/pxzcat-c.c | 155 ++--
builder/setlocale-c.c | 18 +-
builder/yajl-c.c | 40 +-
cat/cat.c | 67 +-
cat/filesystems.c | 249 +++---
cat/log.c | 160 ++--
cat/ls.c | 184 ++--
cat/visit.c | 12 +-
cat/visit.h | 8 +-
daemon/9p.c | 14 +-
daemon/acl.c | 5 +-
daemon/augeas.c | 68 +-
daemon/available.c | 9 +-
daemon/base64.c | 12 +-
daemon/blkdiscard.c | 9 +-
daemon/blkid.c | 63 +-
daemon/blockdev.c | 28 +-
daemon/btrfs.c | 215 ++---
daemon/cap.c | 5 +-
daemon/checksum.c | 33 +-
daemon/cleanups.c | 12 +-
daemon/cleanups.h | 15 +-
daemon/cmp.c | 2 +-
daemon/command.c | 70 +-
daemon/command.h | 12 +-
daemon/compress.c | 27 +-
daemon/copy.c | 56 +-
daemon/cpio.c | 17 +-
daemon/cpmv.c | 10 +-
daemon/daemon.h | 180 ++--
daemon/dd.c | 11 +-
daemon/debug-bmap.c | 9 +-
daemon/debug.c | 238 +++---
daemon/devsparts.c | 30 +-
daemon/df.c | 6 +-
daemon/dir.c | 31 +-
daemon/dmesg.c | 4 +-
daemon/du.c | 4 +-
daemon/ext2.c | 249 +++---
daemon/fallocate.c | 5 +-
daemon/file.c | 71 +-
daemon/fill.c | 10 +-
daemon/find.c | 8 +-
daemon/findfs.c | 8 +-
daemon/fs-min-size.c | 7 +-
daemon/fsck.c | 2 +-
daemon/fstrim.c | 9 +-
daemon/glob.c | 10 +-
daemon/grep.c | 16 +-
daemon/grub.c | 6 +-
daemon/guestfsd.c | 162 ++--
daemon/headtail.c | 8 +-
daemon/hexdump.c | 4 +-
daemon/hivex.c | 27 +-
daemon/hotplug.c | 7 +-
daemon/htonl.c | 32 +-
daemon/initrd.c | 25 +-
daemon/inotify.c | 58 +-
daemon/internal.c | 3 +-
daemon/is.c | 23 +-
daemon/isoinfo.c | 77 +-
daemon/journal.c | 36 +-
daemon/labels.c | 9 +-
daemon/ldm.c | 90 +-
daemon/link.c | 16 +-
daemon/ls.c | 17 +-
daemon/luks.c | 20 +-
daemon/lvm-filter.c | 17 +-
daemon/lvm.c | 153 ++--
daemon/md.c | 89 +-
daemon/mkfs.c | 31 +-
daemon/mknod.c | 12 +-
daemon/mktemp.c | 5 +-
daemon/modprobe.c | 2 +-
daemon/mount.c | 57 +-
daemon/ntfs.c | 36 +-
daemon/ntfsclone.c | 55 +-
daemon/parted.c | 219 ++---
daemon/proto.c | 168 ++--
daemon/readdir.c | 41 +-
daemon/realpath.c | 21 +-
daemon/rsync.c | 19 +-
daemon/scrub.c | 2 +-
daemon/selinux.c | 4 +-
daemon/sfdisk.c | 19 +-
daemon/sh.c | 68 +-
daemon/sleep.c | 2 +-
daemon/sleuthkit.c | 11 +-
daemon/stat.c | 6 +-
daemon/statvfs.c | 22 +-
daemon/strings.c | 7 +-
daemon/swap.c | 11 +-
daemon/sync.c | 36 +-
daemon/syslinux.c | 4 +-
daemon/tar.c | 56 +-
daemon/truncate.c | 4 +-
daemon/umask.c | 2 +-
daemon/upload.c | 62 +-
daemon/utimens.c | 3 +-
daemon/utsname.c | 4 +-
daemon/uuids.c | 10 +-
daemon/wc.c | 2 +-
daemon/xattr.c | 121 +--
daemon/xfs.c | 211 +++--
daemon/zero.c | 27 +-
daemon/zerofree.c | 2 +-
df/df.c | 10 +-
df/domains.c | 23 +-
df/estimate-max-threads.c | 3 +-
df/main.c | 90 +-
df/output.c | 68 +-
df/parallel.c | 33 +-
df/parallel.h | 3 +-
df/virt-df.h | 15 +-
diff/diff.c | 245 +++---
edit/edit.c | 98 ++-
erlang/erl-guestfs-proto.c | 23 +-
examples/copy-over.c | 45 +-
examples/create-disk.c | 16 +-
examples/debug-logging.c | 23 +-
examples/display-icon.c | 25 +-
examples/inspect-vm.c | 18 +-
examples/libvirt-auth.c | 87 +-
examples/mount-local.c | 87 +-
examples/virt-dhcp-address.c | 58 +-
fish/alloc.c | 15 +-
fish/cmds-gperf.h | 9 +-
fish/config.c | 15 +-
fish/copy.c | 16 +-
fish/destpaths.c | 88 +-
fish/domain.c | 2 +-
fish/echo.c | 3 +-
fish/edit.c | 3 +-
fish/events.c | 48 +-
fish/file-edit.c | 35 +-
fish/file-edit.h | 4 +-
fish/fish.c | 467 ++++++-----
fish/fish.h | 20 +-
fish/glob.c | 68 +-
fish/help.c | 28 +-
fish/hexedit.c | 28 +-
fish/inspect.c | 101 +--
fish/keys.c | 6 +-
fish/man.c | 11 +-
fish/options.c | 45 +-
fish/options.h | 188 ++---
fish/prep-boot.c | 28 +-
fish/prep-disk.c | 3 +-
fish/prep-fs.c | 3 +-
fish/prep-lv.c | 36 +-
fish/prep-part.c | 3 +-
fish/prep.c | 27 +-
fish/progress.c | 69 +-
fish/progress.h | 3 +-
fish/rc.c | 119 +--
fish/reopen.c | 3 +-
fish/setenv.c | 3 +-
fish/supported.c | 2 +-
fish/tilde.c | 6 +-
fish/time.c | 9 +-
fish/uri.c | 43 +-
fish/uri.h | 10 +-
fish/windows.c | 10 +-
format/format.c | 49 +-
fuse/guestmount.c | 125 +--
fuse/guestunmount.c | 94 +--
fuse/test-fuse.c | 104 +--
fuse/test-guestmount-fd.c | 20 +-
fuse/test-guestunmount-fd.c | 15 +-
inspector/inspector.c | 348 ++++----
make-fs/make-fs.c | 124 +--
mllib/fsync-c.c | 10 +-
mllib/mkdtemp-c.c | 8 +-
mllib/progress-c.c | 8 +-
mllib/uri-c.c | 2 +-
ocaml/guestfs-c.c | 87 +-
ocaml/guestfs-c.h | 9 +-
p2v/about-authors.c | 16 +-
p2v/about-license.c | 3 +-
p2v/config.c | 27 +-
p2v/conversion.c | 356 ++++----
p2v/gui.c | 609 +++++++-------
p2v/kernel-cmdline.c | 66 +-
p2v/kernel.c | 35 +-
p2v/main.c | 126 +--
p2v/miniexpect.c | 27 +-
p2v/miniexpect.h | 12 +-
p2v/p2v.h | 24 +-
p2v/ssh.c | 284 +++----
p2v/utils.c | 4 +-
p2v/whole-file.c | 2 +-
python/guestfs-py-byhand.c | 32 +-
python/guestfs-py.h | 22 +-
rescue/rescue.c | 155 ++--
sparsify/statvfs-c.c | 2 +-
src/actions-support.c | 21 +-
src/alloc.c | 24 +-
src/appliance.c | 96 ++-
src/available.c | 13 +-
src/canonical-name.c | 8 +-
src/cleanup.c | 20 +-
src/command.c | 102 +--
src/conn-socket.c | 48 +-
src/copy-in-out.c | 64 +-
src/create.c | 55 +-
src/dbdump.c | 66 +-
src/drives.c | 272 +++---
src/errors.c | 89 +-
src/events.c | 226 +++--
src/file.c | 108 +--
src/filearch.c | 64 +-
src/fuse.c | 332 ++++----
src/guestfs-internal-all.h | 82 +-
src/guestfs-internal-frontend.h | 95 ++-
src/guestfs-internal.h | 490 ++++++-----
src/guid.c | 5 +-
src/handle.c | 85 +-
src/info.c | 57 +-
src/inspect-apps.c | 269 +++---
src/inspect-fs-cd.c | 100 +--
src/inspect-fs-unix.c | 491 ++++++-----
src/inspect-fs-windows.c | 219 ++---
src/inspect-fs.c | 122 +--
src/inspect-icon.c | 110 +--
src/inspect.c | 313 ++++---
src/journal.c | 44 +-
src/launch-direct.c | 333 ++++----
src/launch-libvirt.c | 1017 +++++++++++++----------
src/launch-uml.c | 81 +-
src/launch-unix.c | 26 +-
src/launch.c | 135 ++-
src/libvirt-auth.c | 119 +--
src/libvirt-domain.c | 365 ++++----
src/libvirt-is-version.c | 10 +-
src/listfs.c | 54 +-
src/lpj.c | 14 +-
src/match.c | 57 +-
src/mountable.c | 7 +-
src/osinfo.c | 97 ++-
src/private-data.c | 8 +-
src/proto.c | 105 +--
src/stringsbuf.c | 8 +-
src/test-utils.c | 29 +-
src/tmpdirs.c | 3 +-
src/utils.c | 60 +-
src/whole-file.c | 2 +-
test-tool/test-tool.c | 108 ++-
tests/c-api/test-add-drive-opts.c | 10 +-
tests/c-api/test-add-libvirt-dom.c | 71 +-
tests/c-api/test-backend-settings.c | 7 +-
tests/c-api/test-command.c | 38 +-
tests/c-api/test-debug-to-file.c | 22 +-
tests/c-api/test-dlopen.c | 8 +-
tests/c-api/test-environment.c | 29 +-
tests/c-api/test-event-string.c | 3 +-
tests/c-api/test-private-data.c | 30 +-
tests/c-api/test-pwd.c | 4 +-
tests/c-api/test-user-cancel.c | 45 +-
tests/c-api/tests-main.c | 56 +-
tests/c-api/tests.h | 6 +-
tests/charsets/test-charset-fidelity.c | 115 +--
tests/events/test-libvirt-auth-callbacks.c | 77 +-
tests/mount-local/test-parallel-mount-local.c | 50 +-
tests/mountable/test-internal-parse-mountable.c | 45 +-
tests/parallel/test-parallel.c | 19 +-
tests/protocol/test-error-messages.c | 15 +-
tests/qemu/boot-analysis-timeline.c | 396 ++++-----
tests/qemu/boot-analysis-utils.c | 7 +-
tests/qemu/boot-analysis-utils.h | 3 +-
tests/qemu/boot-analysis.c | 153 ++--
tests/qemu/boot-analysis.h | 18 +-
tests/qemu/boot-benchmark.c | 49 +-
tests/qemu/qemu-boot.c | 53 +-
tests/qemu/qemu-speed-test.c | 102 +--
tests/regressions/rhbz1055452.c | 9 +-
tests/regressions/rhbz501893.c | 5 +-
tests/regressions/rhbz790721.c | 24 +-
tests/regressions/rhbz914931.c | 5 +-
tests/regressions/test-big-heap.c | 8 +-
tests/xml/fake-libvirt-xml.c | 6 +-
v2v/domainxml-c.c | 73 +-
v2v/utils-c.c | 10 +-
v2v/xml-c.c | 119 +--
287 files changed, 10121 insertions(+), 8506 deletions(-)
diff --git a/align/scan.c b/align/scan.c
index 5f1d98a..c99d34b 100644
--- a/align/scan.c
+++ b/align/scan.c
@@ -64,8 +64,8 @@ int echo_keys = 0;
const char *libvirt_uri = NULL;
int inspector = 0;
-static int quiet = 0; /* --quiet */
-static int uuid = 0; /* --uuid */
+static int quiet = 0; /* --quiet */
+static int uuid = 0; /* --uuid */
static void __attribute__((noreturn))
usage (int status)
@@ -108,18 +108,12 @@ main (int argc, char *argv[])
static const char *options = "a:c:d:P:qvVx";
static const struct option long_options[] = {
- { "add", 1, 0, 'a' },
- { "connect", 1, 0, 'c' },
- { "domain", 1, 0, 'd' },
- { "format", 2, 0, 0 },
- { "help", 0, 0, HELP_OPTION },
- { "long-options", 0, 0, 0 },
- { "quiet", 0, 0, 'q' },
- { "short-options", 0, 0, 0 },
- { "uuid", 0, 0, 0 },
- { "verbose", 0, 0, 'v' },
- { "version", 0, 0, 'V' },
- { 0, 0, 0, 0 }
+ { "add", 1, 0, 'a' }, { "connect", 1, 0,
'c' },
+ { "domain", 1, 0, 'd' }, { "format", 2, 0, 0 },
+ { "help", 0, 0, HELP_OPTION }, { "long-options", 0, 0, 0 },
+ { "quiet", 0, 0, 'q' }, { "short-options", 0, 0, 0
},
+ { "uuid", 0, 0, 0 }, { "verbose", 0, 0, 'v' },
+ { "version", 0, 0, 'V' }, { 0, 0, 0, 0 }
};
struct drv *drvs = NULL;
const char *format = NULL;
@@ -136,21 +130,23 @@ main (int argc, char *argv[])
for (;;) {
c = getopt_long (argc, argv, options, long_options, &option_index);
- if (c == -1) break;
+ if (c == -1)
+ break;
switch (c) {
- case 0: /* options which are long only */
+ case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "long-options"))
display_long_options (long_options);
else if (STREQ (long_options[option_index].name, "short-options"))
display_short_options (options);
else if (STREQ (long_options[option_index].name, "format")) {
OPTION_format;
- } else if (STREQ (long_options[option_index].name, "uuid")) {
+ }
+ else if (STREQ (long_options[option_index].name, "uuid")) {
uuid = 1;
- } else
- error (EXIT_FAILURE, 0,
- _("unknown long option: %s (%d)"),
+ }
+ else
+ error (EXIT_FAILURE, 0, _("unknown long option: %s (%d)"),
long_options[option_index].name, option_index);
break;
@@ -225,9 +221,11 @@ main (int argc, char *argv[])
#else
error (EXIT_FAILURE, 0, _("compiled without support for libvirt"));
#endif
- } else { /* Single guest. */
+ }
+ else { /* Single guest. */
if (uuid)
- error (EXIT_FAILURE, 0, _("--uuid option cannot be used with -a or
-d"));
+ error (EXIT_FAILURE, 0,
+ _("--uuid option cannot be used with -a or -d"));
/* Add domains/drives from the command line (for a single guest). */
add_drives (drvs, 'a');
@@ -297,12 +295,12 @@ scan (guestfs_h *g, const char *prefix, FILE *fp)
if (prefix)
fprintf (fp, "%s:", prefix);
- fprintf (fp, "%s%d %12" PRIu64 " ",
- name, (int) parts->val[j].part_num, start);
+ fprintf (fp, "%s%d %12" PRIu64 " ", name,
+ (int)parts->val[j].part_num, start);
}
/* What's the alignment? */
- if (start == 0) /* Probably not possible, but anyway. */
+ if (start == 0) /* Probably not possible, but anyway. */
alignment = 64;
else
for (alignment = 0; (start & 1) == 0; alignment++, start /= 2)
@@ -310,9 +308,10 @@ scan (guestfs_h *g, const char *prefix, FILE *fp)
if (!quiet) {
if (alignment < 10)
- fprintf (fp, "%12" PRIu64 " ", UINT64_C(1) <<
alignment);
+ fprintf (fp, "%12" PRIu64 " ", UINT64_C (1) <<
alignment);
else if (alignment < 64)
- fprintf (fp, "%12" PRIu64 "K ", UINT64_C(1) <<
(alignment - 10));
+ fprintf (fp, "%12" PRIu64 "K ", UINT64_C (1)
+ << (alignment - 10));
else
fprintf (fp, "- ");
}
@@ -324,13 +323,15 @@ scan (guestfs_h *g, const char *prefix, FILE *fp)
err = pthread_mutex_unlock (&worst_alignment_mutex);
assert (err == 0);
- if (alignment < 12) { /* Bad in general: < 4K alignment */
+ if (alignment < 12) { /* Bad in general: < 4K alignment */
if (!quiet)
fprintf (fp, "bad (%s)\n", _("alignment < 4K"));
- } else if (alignment < 16) { /* Bad on NetApps: < 64K alignment */
+ }
+ else if (alignment < 16) { /* Bad on NetApps: < 64K alignment */
if (!quiet)
fprintf (fp, "bad (%s)\n", _("alignment < 64K"));
- } else {
+ }
+ else {
if (!quiet)
fprintf (fp, "ok\n");
}
@@ -351,9 +352,8 @@ scan_work (guestfs_h *g, size_t i, FILE *fp)
{
struct guestfs_add_libvirt_dom_argv optargs;
- optargs.bitmask =
- GUESTFS_ADD_LIBVIRT_DOM_READONLY_BITMASK |
- GUESTFS_ADD_LIBVIRT_DOM_READONLYDISK_BITMASK;
+ optargs.bitmask = GUESTFS_ADD_LIBVIRT_DOM_READONLY_BITMASK |
+ GUESTFS_ADD_LIBVIRT_DOM_READONLYDISK_BITMASK;
optargs.readonly = 1;
optargs.readonlydisk = "read";
diff --git a/builder/index-parser-c.c b/builder/index-parser-c.c
index 52c8b86..a8f6ad8 100644
--- a/builder/index-parser-c.c
+++ b/builder/index-parser-c.c
@@ -36,8 +36,8 @@
#ifdef HAVE_CAML_UNIXSUPPORT_H
#include <caml/unixsupport.h>
#else
-#define Nothing ((value) 0)
-extern void unix_error (int errcode, char * cmdname, value arg) Noreturn;
+#define Nothing ((value)0)
+extern void unix_error (int errcode, char *cmdname, value arg) Noreturn;
#endif
#include "index-struct.h"
@@ -45,7 +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);
+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)
@@ -64,7 +65,7 @@ virt_builder_parse_index (value progv, value error_suffixv, value
filenamev)
in = fopen (String_val (filenamev), "r");
if (in == NULL)
- unix_error (errno, (char *) "fopen", filenamev);
+ unix_error (errno, (char *)"fopen", filenamev);
if (do_parse (&context, in) != 0) {
fclose (in);
@@ -72,11 +73,12 @@ virt_builder_parse_index (value progv, value error_suffixv, value
filenamev)
}
if (fclose (in) == EOF)
- unix_error (errno, (char *) "fclose", filenamev);
+ unix_error (errno, (char *)"fclose", filenamev);
/* Convert the parsed data to OCaml structures. */
nr_sections = 0;
- for (sections = context.parsed_index; sections != NULL; sections = sections->next)
+ for (sections = context.parsed_index; sections != NULL;
+ sections = sections->next)
nr_sections++;
rv = caml_alloc (nr_sections, 0);
@@ -94,24 +96,25 @@ virt_builder_parse_index (value progv, value error_suffixv, value
filenamev)
j++, fields = fields->next) {
v = caml_alloc_tuple (3);
sv = caml_copy_string (fields->key);
- Store_field (v, 0, sv); /* (key, Some subkey, value) */
+ Store_field (v, 0, sv); /* (key, Some subkey, value) */
if (fields->subkey) {
sv2 = caml_copy_string (fields->subkey);
sv = caml_alloc (1, 0);
Store_field (sv, 0, sv2);
- } else
+ }
+ else
sv = Val_int (0);
Store_field (v, 1, sv);
sv = caml_copy_string (fields->value);
Store_field (v, 2, sv);
- Store_field (fv, j, v); /* assign to return array of fields */
+ Store_field (fv, j, v); /* assign to return array of fields */
}
v = caml_alloc_tuple (2);
sv = caml_copy_string (sections->name);
- Store_field (v, 0, sv); /* (name, fields) */
+ Store_field (v, 0, sv); /* (name, fields) */
Store_field (v, 1, fv);
- Store_field (rv, i, v); /* assign to return array of sections */
+ Store_field (rv, i, v); /* assign to return array of sections */
}
/* Free parsed data. */
diff --git a/builder/index-struct.h b/builder/index-struct.h
index ada35e3..ba27f5b 100644
--- a/builder/index-struct.h
+++ b/builder/index-struct.h
@@ -38,7 +38,7 @@ struct field {
/* A struct holding the data needed during the parsing. */
struct parse_context {
- struct section *parsed_index; /* The result of the parsing. */
+ struct section *parsed_index; /* The result of the parsing. */
/* yyparse sets this if any comments were seen. Required for checking
* compatibility with virt-builder 1.24.
*/
diff --git a/builder/index-validate.c b/builder/index-validate.c
index 6a87d7a..7869882 100644
--- a/builder/index-validate.c
+++ b/builder/index-validate.c
@@ -74,24 +74,23 @@ main (int argc, char *argv[])
for (;;) {
c = getopt_long (argc, argv, options, long_options, &option_index);
- if (c == -1) break;
+ if (c == -1)
+ break;
switch (c) {
- case 0: /* options which are long only */
+ case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "compat-1.24.0"))
compat_1_24_0 = compat_1_24_1 = 1;
else if (STREQ (long_options[option_index].name, "compat-1.24.1"))
compat_1_24_1 = 1;
else
- error (EXIT_FAILURE, 0,
- _("unknown long option: %s (%d)"),
+ error (EXIT_FAILURE, 0, _("unknown long option: %s (%d)"),
long_options[option_index].name, option_index);
break;
case 'V':
- printf ("%s %s%s\n",
- guestfs_int_program_name,
- PACKAGE_VERSION, PACKAGE_VERSION_EXTRA);
+ printf ("%s %s%s\n", guestfs_int_program_name, PACKAGE_VERSION,
+ PACKAGE_VERSION_EXTRA);
exit (EXIT_SUCCESS);
case HELP_OPTION:
@@ -102,7 +101,7 @@ main (int argc, char *argv[])
}
}
- if (optind != argc-1)
+ if (optind != argc - 1)
usage (EXIT_FAILURE);
input = argv[optind++];
@@ -126,13 +125,14 @@ main (int argc, char *argv[])
if (compat_1_24_1 && context.seen_comments) {
parse_context_free (&context);
- error (EXIT_FAILURE, 0,
- _("%s contains comments which will not work with virt-builder
1.24.1"),
+ error (EXIT_FAILURE, 0, _("%s contains comments which will not work "
+ "with virt-builder 1.24.1"),
input);
}
/* Iterate over the parsed sections, semantically validating it. */
- for (sections = context.parsed_index; sections != NULL; sections = sections->next)
{
+ for (sections = context.parsed_index; sections != NULL;
+ sections = sections->next) {
int seen_sig = 0;
struct field *fields;
@@ -140,27 +140,28 @@ main (int argc, char *argv[])
if (strchr (sections->name, '_')) {
parse_context_free (&context);
error (EXIT_FAILURE, 0,
- _("%s: section [%s] has invalid characters which will not work with
virt-builder 1.24.0"),
+ _("%s: section [%s] has invalid characters which will not "
+ "work with virt-builder 1.24.0"),
input, sections->name);
}
}
for (fields = sections->fields; fields != NULL; fields = fields->next) {
if (compat_1_24_0) {
- if (strchr (fields->key, '[') ||
- strchr (fields->key, ']')) {
+ if (strchr (fields->key, '[') || strchr (fields->key, ']'))
{
parse_context_free (&context);
error (EXIT_FAILURE, 0,
- _("%s: section [%s], field '%s' has invalid characters
which will not work with virt-builder 1.24.0"),
+ _("%s: section [%s], field '%s' has invalid characters
"
+ "which will not work with virt-builder 1.24.0"),
input, sections->name, fields->key);
}
}
if (compat_1_24_1) {
- if (strchr (fields->key, '.') ||
- strchr (fields->key, ',')) {
+ if (strchr (fields->key, '.') || strchr (fields->key, ','))
{
parse_context_free (&context);
error (EXIT_FAILURE, 0,
- _("%s: section [%s], field '%s' has invalid characters
which will not work with virt-builder 1.24.1"),
+ _("%s: section [%s], field '%s' has invalid characters
"
+ "which will not work with virt-builder 1.24.1"),
input, sections->name, fields->key);
}
}
@@ -171,7 +172,8 @@ main (int argc, char *argv[])
if (compat_1_24_0 && !seen_sig) {
parse_context_free (&context);
error (EXIT_FAILURE, 0,
- _("%s: section [%s] is missing a 'sig' field which will not
work with virt-builder 1.24.0"),
+ _("%s: section [%s] is missing a 'sig' field which will not
"
+ "work with virt-builder 1.24.0"),
input, sections->name);
}
}
diff --git a/builder/pxzcat-c.c b/builder/pxzcat-c.c
index 1f5ceeb..374d4aa 100644
--- a/builder/pxzcat-c.c
+++ b/builder/pxzcat-c.c
@@ -47,13 +47,12 @@
#ifdef HAVE_CAML_UNIXSUPPORT_H
#include <caml/unixsupport.h>
#else
-#define Nothing ((value) 0)
-extern void unix_error (int errcode, char * cmdname, value arg) Noreturn;
+#define Nothing ((value)0)
+extern void unix_error (int errcode, char *cmdname, value arg) Noreturn;
#endif
-#if defined (HAVE_LIBLZMA) && \
- defined (HAVE_LZMA_INDEX_STREAM_FLAGS) && \
- defined (HAVE_LZMA_INDEX_STREAM_PADDING)
+#if defined(HAVE_LIBLZMA) && defined(HAVE_LZMA_INDEX_STREAM_FLAGS) && \
+ defined(HAVE_LZMA_INDEX_STREAM_PADDING)
#define PARALLEL_XZCAT 1
#else
#define PARALLEL_XZCAT 0
@@ -68,7 +67,8 @@ virt_builder_using_parallel_xzcat (value unitv)
}
#if PARALLEL_XZCAT
-static void pxzcat (value filenamev, value outputfilev, unsigned nr_threads);
+static void pxzcat (value filenamev, value outputfilev,
+ unsigned nr_threads);
#endif /* PARALLEL_XZCAT */
extern value virt_builder_pxzcat (value inputfilev, value outputfilev);
@@ -90,7 +90,7 @@ virt_builder_pxzcat (value inputfilev, value outputfilev)
perror ("could not get number of cores");
i = 1;
}
- nr_threads = (unsigned) i;
+ nr_threads = (unsigned)i;
/* NB: This might throw an exception if something fails. If it
* does, this function won't return as a regular C function.
@@ -104,18 +104,19 @@ virt_builder_pxzcat (value inputfilev, value outputfilev)
pid_t pid;
int status;
- fd = open (String_val (outputfilev), O_WRONLY|O_CREAT|O_TRUNC|O_NOCTTY, 0666);
+ fd = open (String_val (outputfilev),
+ O_WRONLY | O_CREAT | O_TRUNC | O_NOCTTY, 0666);
if (fd == -1)
- unix_error (errno, (char *) "open", outputfilev);
+ unix_error (errno, (char *)"open", outputfilev);
pid = fork ();
if (pid == -1) {
int err = errno;
close (fd);
- unix_error (err, (char *) "fork", Nothing);
+ unix_error (err, (char *)"fork", Nothing);
}
- if (pid == 0) { /* child - run xzcat */
+ if (pid == 0) { /* child - run xzcat */
dup2 (fd, 1);
execlp (XZCAT, XZCAT, String_val (inputfilev), NULL);
perror (XZCAT);
@@ -125,7 +126,7 @@ virt_builder_pxzcat (value inputfilev, value outputfilev)
close (fd);
if (waitpid (pid, &status, 0) == -1)
- unix_error (errno, (char *) "waitpid", Nothing);
+ unix_error (errno, (char *)"waitpid", Nothing);
if (!WIFEXITED (status) || WEXITSTATUS (status) != 0)
caml_failwith (XZCAT " program failed, see earlier error messages");
@@ -139,20 +140,25 @@ virt_builder_pxzcat (value inputfilev, value outputfilev)
#define DEBUG 0
#if DEBUG
-#define debug(fs,...) fprintf (stderr, "pxzcat: debug: " fs "\n", ##
__VA_ARGS__)
+#define debug(fs, ...) \
+ fprintf (stderr, "pxzcat: debug: " fs "\n", ##__VA_ARGS__)
#else
-#define debug(fs,...) /* nothing */
+#define debug(fs, ...) /* nothing */
#endif
/* Size of buffers used in decompression loop. */
-#define BUFFER_SIZE (64*1024)
+#define BUFFER_SIZE (64 * 1024)
-#define XZ_HEADER_MAGIC "\xfd" "7zXZ\0"
+#define XZ_HEADER_MAGIC \
+ "\xfd" \
+ "7zXZ\0"
#define XZ_HEADER_MAGIC_LEN 6
static int check_header_magic (int fd);
static lzma_index *parse_indexes (value filenamev, int fd);
-static void iter_blocks (lzma_index *idx, unsigned nr_threads, value filenamev, int fd,
value outputfilev, int ofd);
+static void iter_blocks (lzma_index *idx, unsigned nr_threads,
+ value filenamev, int fd, value outputfilev,
+ int ofd);
static void
pxzcat (value filenamev, value outputfilev, unsigned nr_threads)
@@ -164,7 +170,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, (char *) "open", filenamev);
+ unix_error (errno, (char *)"open", filenamev);
/* Check file magic. */
if (!check_header_magic (fd)) {
@@ -183,40 +189,42 @@ pxzcat (value filenamev, value outputfilev, unsigned nr_threads)
* unless we are very careful about not truncating a regular file
* from non-zero size to zero size. (Thanks Eric Sandeen)
*/
- ofd = open (String_val (outputfilev), O_WRONLY|O_CREAT|O_NOCTTY, 0644);
+ ofd =
+ open (String_val (outputfilev), O_WRONLY | O_CREAT | O_NOCTTY, 0644);
if (ofd == -1) {
int err = errno;
close (fd);
- unix_error (err, (char *) "open", outputfilev);
+ unix_error (err, (char *)"open", outputfilev);
}
if (ftruncate (ofd, 1) == -1) {
int err = errno;
close (fd);
- unix_error (err, (char *) "ftruncate", outputfilev);
+ unix_error (err, (char *)"ftruncate", outputfilev);
}
if (lseek (ofd, 0, SEEK_SET) == -1) {
int err = errno;
close (fd);
- unix_error (err, (char *) "lseek", outputfilev);
+ unix_error (err, (char *)"lseek", outputfilev);
}
if (write (ofd, "\0", 1) == -1) {
int err = errno;
close (fd);
- unix_error (err, (char *) "write", outputfilev);
+ unix_error (err, (char *)"write", outputfilev);
}
if (ftruncate (ofd, size) == -1) {
int err = errno;
close (fd);
- unix_error (err, (char *) "ftruncate", outputfilev);
+ unix_error (err, (char *)"ftruncate", outputfilev);
}
#if defined HAVE_POSIX_FADVISE
/* Tell the kernel we won't read the output file. */
- ignore_value (posix_fadvise (fd, 0, 0, POSIX_FADV_RANDOM|POSIX_FADV_DONTNEED));
+ ignore_value (
+ posix_fadvise (fd, 0, 0, POSIX_FADV_RANDOM | POSIX_FADV_DONTNEED));
#endif
/* Iterate over blocks. */
@@ -225,7 +233,7 @@ pxzcat (value filenamev, value outputfilev, unsigned nr_threads)
lzma_index_end (idx, NULL);
if (close (fd) == -1)
- unix_error (errno, (char *) "close", filenamev);
+ unix_error (errno, (char *)"close", filenamev);
}
static int
@@ -270,28 +278,30 @@ 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, (char *) "lseek", filenamev);
+ if (pos == (off_t)-1)
+ 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");
+ caml_invalid_argument (
+ "input not an xz file: size is not a multiple of 4 bytes");
/* Jump backwards through the file identifying each stream. */
while (pos > 0) {
- debug ("looping through streams: pos = %" PRIu64, (uint64_t) pos);
+ debug ("looping through streams: pos = %" PRIu64, (uint64_t)pos);
if (pos < LZMA_STREAM_HEADER_SIZE)
caml_invalid_argument ("corrupted xz file");
if (lseek (fd, -LZMA_STREAM_HEADER_SIZE, SEEK_CUR) == -1)
- unix_error (errno, (char *) "lseek", filenamev);
+ unix_error (errno, (char *)"lseek", filenamev);
- if (read (fd, footer, LZMA_STREAM_HEADER_SIZE) != LZMA_STREAM_HEADER_SIZE)
- unix_error (errno, (char *) "read", filenamev);
+ if (read (fd, footer, LZMA_STREAM_HEADER_SIZE) !=
+ LZMA_STREAM_HEADER_SIZE)
+ unix_error (errno, (char *)"read", filenamev);
/* Skip stream padding. */
- if (footer[8] == 0 && footer[9] == 0 &&
- footer[10] == 0 && footer[11] == 0) {
+ if (footer[8] == 0 && footer[9] == 0 && footer[10] == 0 &&
+ footer[11] == 0) {
stream_padding += 4;
pos -= 4;
continue;
@@ -300,7 +310,7 @@ parse_indexes (value filenamev, int fd)
pos -= LZMA_STREAM_HEADER_SIZE;
nr_streams++;
- debug ("decode stream footer at pos = %" PRIu64, (uint64_t) pos);
+ debug ("decode stream footer at pos = %" PRIu64, (uint64_t)pos);
/* Does the stream footer look reasonable? */
r = lzma_stream_footer_decode (&footer_flags, footer);
@@ -309,17 +319,18 @@ parse_indexes (value filenamev, int fd)
caml_invalid_argument ("invalid stream footer");
}
- debug ("backward_size = %" PRIu64, (uint64_t) footer_flags.backward_size);
+ debug ("backward_size = %" PRIu64,
+ (uint64_t)footer_flags.backward_size);
index_size = footer_flags.backward_size;
if (pos < index_size + LZMA_STREAM_HEADER_SIZE)
caml_invalid_argument ("invalid stream footer");
pos -= index_size;
- debug ("decode index at pos = %" PRIu64, (uint64_t) pos);
+ debug ("decode index at pos = %" PRIu64, (uint64_t)pos);
/* Seek backwards to the index of this stream. */
if (lseek (fd, pos, SEEK_SET) == -1)
- unix_error (errno, (char *) "lseek", filenamev);
+ unix_error (errno, (char *)"lseek", filenamev);
/* Decode the index. */
r = lzma_index_decoder (&strm, &this_index, UINT64_MAX);
@@ -335,7 +346,7 @@ parse_indexes (value filenamev, int fd)
n = read (fd, buf, strm.avail_in);
if (n == -1)
- unix_error (errno, (char *) "read", filenamev);
+ unix_error (errno, (char *)"read", filenamev);
index_size -= strm.avail_in;
@@ -350,14 +361,15 @@ parse_indexes (value filenamev, int fd)
pos -= lzma_index_total_size (this_index) + LZMA_STREAM_HEADER_SIZE;
- debug ("decode stream header at pos = %" PRIu64, (uint64_t) pos);
+ debug ("decode stream header at pos = %" PRIu64, (uint64_t)pos);
/* Read and decode the stream header. */
if (lseek (fd, pos, SEEK_SET) == -1)
- unix_error (errno, (char *) "lseek", filenamev);
+ unix_error (errno, (char *)"lseek", filenamev);
- if (read (fd, header, LZMA_STREAM_HEADER_SIZE) != LZMA_STREAM_HEADER_SIZE)
- unix_error (errno, (char *) "read stream header", filenamev);
+ if (read (fd, header, LZMA_STREAM_HEADER_SIZE) !=
+ LZMA_STREAM_HEADER_SIZE)
+ unix_error (errno, (char *)"read stream header", filenamev);
r = lzma_stream_header_decode (&header_flags, header);
if (r != LZMA_OK) {
@@ -368,15 +380,16 @@ parse_indexes (value filenamev, int fd)
/* Header and footer of the stream should be equal. */
r = lzma_stream_flags_compare (&header_flags, &footer_flags);
if (r != LZMA_OK) {
- fprintf (stderr, "header and footer of stream are not equal - error
%u\n",
- r);
+ fprintf (stderr,
+ "header and footer of stream are not equal - error %u\n", r);
caml_invalid_argument ("header and footer of stream are not equal");
}
/* Store the decoded stream flags in this_index. */
r = lzma_index_stream_flags (this_index, &footer_flags);
if (r != LZMA_OK) {
- fprintf (stderr, "cannot read stream_flags from index - error %u\n", r);
+ fprintf (stderr, "cannot read stream_flags from index - error %u\n",
+ r);
caml_invalid_argument ("cannot read stream_flags from index");
}
@@ -385,7 +398,8 @@ parse_indexes (value filenamev, int fd)
*/
r = lzma_index_stream_padding (this_index, stream_padding);
if (r != LZMA_OK) {
- fprintf (stderr, "cannot set stream_padding in index - error %u\n", r);
+ fprintf (stderr, "cannot set stream_padding in index - error %u\n",
+ r);
caml_invalid_argument ("cannot set stream_padding in index");
}
@@ -455,8 +469,8 @@ struct per_thread_state {
static void *worker_thread (void *vp);
static void
-iter_blocks (lzma_index *idx, unsigned nr_threads,
- value filenamev, int fd, value outputfilev, int ofd)
+iter_blocks (lzma_index *idx, unsigned nr_threads, value filenamev, int fd,
+ value outputfilev, int ofd)
{
struct global_state global;
CLEANUP_FREE struct per_thread_state *per_thread = NULL;
@@ -474,7 +488,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, (char *) "pthread_mutex_init", Nothing);
+ unix_error (err, (char *)"pthread_mutex_init", Nothing);
global.filename = String_val (filenamev);
global.fd = fd;
@@ -490,7 +504,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, (char *) "pthread_create", Nothing);
+ unix_error (err, (char *)"pthread_create", Nothing);
}
/* Wait for the threads to exit. */
@@ -562,11 +576,12 @@ worker_thread (void *vp)
for (;;) {
/* Get the next block. */
err = pthread_mutex_lock (&global->iter_mutex);
- if (err != 0) abort ();
+ if (err != 0)
+ abort ();
iter_finished = global->iter_finished;
if (!iter_finished) {
- iter_finished = global->iter_finished =
- lzma_index_iter_next (&global->iter, LZMA_INDEX_ITER_NONEMPTY_BLOCK);
+ iter_finished = global->iter_finished = lzma_index_iter_next (
+ &global->iter, LZMA_INDEX_ITER_NONEMPTY_BLOCK);
if (!iter_finished)
/* Take a local copy of this iterator since another thread will
* update the global version.
@@ -574,7 +589,8 @@ worker_thread (void *vp)
iter = global->iter;
}
err = pthread_mutex_unlock (&global->iter_mutex);
- if (err != 0) abort ();
+ if (err != 0)
+ abort ();
if (iter_finished)
break;
@@ -584,9 +600,10 @@ worker_thread (void *vp)
position = iter.block.compressed_file_offset;
n = pread (global->fd, header, 1, position);
if (n == 0) {
- fprintf (stderr,
- "%s: read: unexpected end of file reading block header byte\n",
- global->filename);
+ fprintf (
+ stderr,
+ "%s: read: unexpected end of file reading block header byte\n",
+ global->filename);
return &state->status;
}
if (n == -1) {
@@ -596,9 +613,10 @@ worker_thread (void *vp)
position++;
if (header[0] == '\0') {
- fprintf (stderr,
- "%s: read: unexpected invalid block in file, header[0] = 0\n",
- global->filename);
+ fprintf (
+ stderr,
+ "%s: read: unexpected invalid block in file, header[0] = 0\n",
+ global->filename);
return &state->status;
}
@@ -608,8 +626,8 @@ worker_thread (void *vp)
block.header_size = lzma_block_header_size_decode (header[0]);
/* Now read and decode the block header. */
- n = pread (global->fd, &header[1], block.header_size-1, position);
- if (n >= 0 && n != (ssize_t) block.header_size-1) {
+ n = pread (global->fd, &header[1], block.header_size - 1, position);
+ if (n >= 0 && n != (ssize_t)block.header_size - 1) {
fprintf (stderr,
"%s: read: unexpected end of file reading block header\n",
global->filename);
@@ -633,8 +651,7 @@ worker_thread (void *vp)
*/
r = lzma_block_compressed_size (&block, iter.block.unpadded_size);
if (r != LZMA_OK) {
- fprintf (stderr,
- "%s: cannot calculate compressed size (error %u)\n",
+ fprintf (stderr, "%s: cannot calculate compressed size (error %u)\n",
global->filename, r);
return &state->status;
}
@@ -645,7 +662,8 @@ worker_thread (void *vp)
/* Read the block data and uncompress it. */
r = lzma_block_decoder (&strm, &block);
if (r != LZMA_OK) {
- fprintf (stderr, "%s: invalid block (error %u)\n", global->filename,
r);
+ fprintf (stderr, "%s: invalid block (error %u)\n", global->filename,
+ r);
return &state->status;
}
@@ -693,8 +711,7 @@ worker_thread (void *vp)
if (r == LZMA_STREAM_END)
break;
if (r != LZMA_OK) {
- fprintf (stderr,
- "%s: could not parse block data (error %u)\n",
+ fprintf (stderr, "%s: could not parse block data (error %u)\n",
global->filename, r);
return &state->status;
}
diff --git a/builder/setlocale-c.c b/builder/setlocale-c.c
index f2ad853..a329425 100644
--- a/builder/setlocale-c.c
+++ b/builder/setlocale-c.c
@@ -25,15 +25,9 @@
#include <caml/memory.h>
#include <caml/mlvalues.h>
-static const int lc_string_table[7] = {
- LC_ALL,
- LC_CTYPE,
- LC_NUMERIC,
- LC_TIME,
- LC_COLLATE,
- LC_MONETARY,
- LC_MESSAGES
-};
+static const int lc_string_table[7] = { LC_ALL, LC_CTYPE, LC_NUMERIC,
+ LC_TIME, LC_COLLATE, LC_MONETARY,
+ LC_MESSAGES };
#define Val_none (Val_int (0))
@@ -48,13 +42,15 @@ virt_builder_setlocale (value val_category, value val_name)
int category;
category = lc_string_table[Int_val (val_category)];
- locstring = val_name == Val_none ? NULL : String_val (Field (val_name, 0));
+ locstring =
+ val_name == Val_none ? NULL : String_val (Field (val_name, 0));
ret = setlocale (category, locstring);
if (ret) {
rv2 = caml_copy_string (ret);
rv = caml_alloc (1, 0);
Store_field (rv, 0, rv2);
- } else
+ }
+ else
rv = Val_none;
CAMLreturn (rv);
diff --git a/builder/yajl-c.c b/builder/yajl-c.c
index f34196e..f65e483 100644
--- a/builder/yajl-c.c
+++ b/builder/yajl-c.c
@@ -42,48 +42,55 @@ convert_yajl_value (yajl_val val, int level)
caml_invalid_argument ("too many levels of object/array nesting");
if (YAJL_IS_OBJECT (val)) {
- size_t len = YAJL_GET_OBJECT(val)->len;
+ size_t len = YAJL_GET_OBJECT (val)->len;
size_t i;
rv = caml_alloc (1, 3);
lv = caml_alloc_tuple (len);
for (i = 0; i < len; ++i) {
v = caml_alloc_tuple (2);
- sv = caml_copy_string (YAJL_GET_OBJECT(val)->keys[i]);
+ sv = caml_copy_string (YAJL_GET_OBJECT (val)->keys[i]);
Store_field (v, 0, sv);
- sv = convert_yajl_value (YAJL_GET_OBJECT(val)->values[i], level + 1);
+ sv = convert_yajl_value (YAJL_GET_OBJECT (val)->values[i], level + 1);
Store_field (v, 1, sv);
Store_field (lv, i, v);
}
Store_field (rv, 0, lv);
- } else if (YAJL_IS_ARRAY (val)) {
- size_t len = YAJL_GET_ARRAY(val)->len;
+ }
+ else if (YAJL_IS_ARRAY (val)) {
+ size_t len = YAJL_GET_ARRAY (val)->len;
size_t i;
rv = caml_alloc (1, 4);
lv = caml_alloc_tuple (len);
for (i = 0; i < len; ++i) {
- v = convert_yajl_value (YAJL_GET_ARRAY(val)->values[i], level + 1);
+ v = convert_yajl_value (YAJL_GET_ARRAY (val)->values[i], level + 1);
Store_field (lv, i, v);
}
Store_field (rv, 0, lv);
- } else if (YAJL_IS_STRING (val)) {
+ }
+ else if (YAJL_IS_STRING (val)) {
rv = caml_alloc (1, 0);
- v = caml_copy_string (YAJL_GET_STRING(val));
+ v = caml_copy_string (YAJL_GET_STRING (val));
Store_field (rv, 0, v);
- } else if (YAJL_IS_DOUBLE (val)) {
+ }
+ else if (YAJL_IS_DOUBLE (val)) {
rv = caml_alloc (1, 2);
- v = caml_copy_double (YAJL_GET_DOUBLE(val));
+ v = caml_copy_double (YAJL_GET_DOUBLE (val));
Store_field (rv, 0, v);
- } else if (YAJL_IS_INTEGER (val)) {
+ }
+ else if (YAJL_IS_INTEGER (val)) {
rv = caml_alloc (1, 1);
- v = caml_copy_int64 (YAJL_GET_INTEGER(val));
+ v = caml_copy_int64 (YAJL_GET_INTEGER (val));
Store_field (rv, 0, v);
- } else if (YAJL_IS_TRUE (val)) {
+ }
+ else if (YAJL_IS_TRUE (val)) {
rv = caml_alloc (1, 5);
Store_field (rv, 0, Val_true);
- } else if (YAJL_IS_FALSE (val)) {
+ }
+ else if (YAJL_IS_FALSE (val)) {
rv = caml_alloc (1, 5);
Store_field (rv, 0, Val_false);
- } else
+ }
+ else
rv = Val_none;
CAMLreturn (rv);
@@ -97,7 +104,8 @@ virt_builder_yajl_tree_parse (value stringv)
yajl_val tree;
char error_buf[256];
- tree = yajl_tree_parse (String_val (stringv), error_buf, sizeof error_buf);
+ tree =
+ yajl_tree_parse (String_val (stringv), error_buf, sizeof error_buf);
if (tree == NULL) {
char buf[256 + sizeof error_buf];
if (strlen (error_buf) > 0)
diff --git a/cat/cat.c b/cat/cat.c
index 0370fbd..8d6e008 100644
--- a/cat/cat.c
+++ b/cat/cat.c
@@ -54,27 +54,28 @@ usage (int status)
fprintf (stderr, _("Try `%s --help' for more information.\n"),
guestfs_int_program_name);
else {
- printf (_("%s: display files in a virtual machine\n"
- "Copyright (C) 2010 Red Hat Inc.\n"
- "Usage:\n"
- " %s [--options] -d domname file [file ...]\n"
- " %s [--options] -a disk.img [-a disk.img ...] file [file
...]\n"
- "Options:\n"
- " -a|--add image Add image\n"
- " -c|--connect uri Specify libvirt URI for -d option\n"
- " -d|--domain guest Add disks from libvirt guest\n"
- " --echo-keys Don't turn off echo for
passphrases\n"
- " --format[=raw|..] Force disk format for -a option\n"
- " --help Display brief help\n"
- " --keys-from-stdin Read passphrases from stdin\n"
- " -m|--mount dev[:mnt[:opts[:fstype]]]\n"
- " Mount dev on mnt (if omitted, /)\n"
- " -v|--verbose Verbose messages\n"
- " -V|--version Display version and exit\n"
- " -x Trace libguestfs API calls\n"
- "For more information, see the manpage %s(1).\n"),
- guestfs_int_program_name, guestfs_int_program_name,
- guestfs_int_program_name, guestfs_int_program_name);
+ printf (
+ _("%s: display files in a virtual machine\n"
+ "Copyright (C) 2010 Red Hat Inc.\n"
+ "Usage:\n"
+ " %s [--options] -d domname file [file ...]\n"
+ " %s [--options] -a disk.img [-a disk.img ...] file [file ...]\n"
+ "Options:\n"
+ " -a|--add image Add image\n"
+ " -c|--connect uri Specify libvirt URI for -d option\n"
+ " -d|--domain guest Add disks from libvirt guest\n"
+ " --echo-keys Don't turn off echo for passphrases\n"
+ " --format[=raw|..] Force disk format for -a option\n"
+ " --help Display brief help\n"
+ " --keys-from-stdin Read passphrases from stdin\n"
+ " -m|--mount dev[:mnt[:opts[:fstype]]]\n"
+ " Mount dev on mnt (if omitted, /)\n"
+ " -v|--verbose Verbose messages\n"
+ " -V|--version Display version and exit\n"
+ " -x Trace libguestfs API calls\n"
+ "For more information, see the manpage %s(1).\n"),
+ guestfs_int_program_name, guestfs_int_program_name,
+ guestfs_int_program_name, guestfs_int_program_name);
}
exit (status);
}
@@ -121,23 +122,26 @@ main (int argc, char *argv[])
for (;;) {
c = getopt_long (argc, argv, options, long_options, &option_index);
- if (c == -1) break;
+ if (c == -1)
+ break;
switch (c) {
- case 0: /* options which are long only */
+ case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "long-options"))
display_long_options (long_options);
else if (STREQ (long_options[option_index].name, "short-options"))
display_short_options (options);
else if (STREQ (long_options[option_index].name, "keys-from-stdin")) {
keys_from_stdin = 1;
- } else if (STREQ (long_options[option_index].name, "echo-keys")) {
+ }
+ else if (STREQ (long_options[option_index].name, "echo-keys")) {
echo_keys = 1;
- } else if (STREQ (long_options[option_index].name, "format")) {
+ }
+ else if (STREQ (long_options[option_index].name, "format")) {
OPTION_format;
- } else
- error (EXIT_FAILURE, 0,
- _("unknown long option: %s (%d)"),
+ }
+ else
+ error (EXIT_FAILURE, 0, _("unknown long option: %s (%d)"),
long_options[option_index].name, option_index);
break;
@@ -195,7 +199,8 @@ main (int argc, char *argv[])
error (EXIT_FAILURE, errno, "strdup");
drv->next = drvs;
drvs = drv;
- } else { /* simulate -d option */
+ }
+ else { /* simulate -d option */
drv = calloc (1, sizeof (struct drv));
if (!drv)
error (EXIT_FAILURE, errno, "calloc");
@@ -276,8 +281,8 @@ do_cat (int argc, char *argv[])
const char *filename = argv[i];
if (windows) {
- filename = filename_to_free = windows_path (g, root, filename,
- 1 /* readonly */);
+ filename = filename_to_free =
+ windows_path (g, root, filename, 1 /* readonly */);
if (filename == NULL) {
errors++;
continue;
diff --git a/cat/filesystems.c b/cat/filesystems.c
index 3f9d931..7a94b1b 100644
--- a/cat/filesystems.c
+++ b/cat/filesystems.c
@@ -48,30 +48,30 @@ int echo_keys = 0;
const char *libvirt_uri = NULL;
int inspector = 0;
-static int csv = 0; /* --csv */
-static int human = 0; /* --human-readable|-h */
+static int csv = 0; /* --csv */
+static int human = 0; /* --human-readable|-h */
/* What is selected for output. */
-#define OUTPUT_FILESYSTEMS 1
-#define OUTPUT_FILESYSTEMS_EXTRA 2
-#define OUTPUT_PARTITIONS 4
-#define OUTPUT_BLOCKDEVS 8
+#define OUTPUT_FILESYSTEMS 1
+#define OUTPUT_FILESYSTEMS_EXTRA 2
+#define OUTPUT_PARTITIONS 4
+#define OUTPUT_BLOCKDEVS 8
#define OUTPUT_LVS 16
#define OUTPUT_VGS 32
#define OUTPUT_PVS 64
-#define OUTPUT_ALL INT_MAX
+#define OUTPUT_ALL INT_MAX
static int output = 0;
/* What columns to output. This is in display order. */
-#define COLUMN_NAME 1 /* always shown */
-#define COLUMN_TYPE 2
-#define COLUMN_VFS_TYPE 4 /* if --filesystems */
-#define COLUMN_VFS_LABEL 8 /* if --filesystems */
-#define COLUMN_MBR 16
-#define COLUMN_SIZE 32 /* bytes, or human-readable if -h */
-#define COLUMN_PARENTS 64
-#define COLUMN_UUID 128 /* if --uuid */
-#define NR_COLUMNS 8
+#define COLUMN_NAME 1 /* always shown */
+#define COLUMN_TYPE 2
+#define COLUMN_VFS_TYPE 4 /* if --filesystems */
+#define COLUMN_VFS_LABEL 8 /* if --filesystems */
+#define COLUMN_MBR 16
+#define COLUMN_SIZE 32 /* bytes, or human-readable if -h */
+#define COLUMN_PARENTS 64
+#define COLUMN_UUID 128 /* if --uuid */
+#define NR_COLUMNS 8
static int columns;
static void do_output_title (void);
@@ -88,42 +88,43 @@ usage (int status)
fprintf (stderr, _("Try `%s --help' for more information.\n"),
guestfs_int_program_name);
else {
- printf (_("%s: list filesystems, partitions, block devices, LVM in a VM\n"
- "Copyright (C) 2010 Red Hat Inc.\n"
- "Usage:\n"
- " %s [--options] -d domname\n"
- " %s [--options] -a disk.img [-a disk.img ...]\n"
- "Options:\n"
- " -a|--add image Add image\n"
- " --all Display everything\n"
- " --blkdevs|--block-devices\n"
- " Display block devices\n"
- " -c|--connect uri Specify libvirt URI for -d option\n"
- " --csv Output as Comma-Separated Values\n"
- " -d|--domain guest Add disks from libvirt guest\n"
- " --echo-keys Don't turn off echo for
passphrases\n"
- " --extra Display swap and data filesystems\n"
- " --filesystems Display mountable filesystems\n"
- " --format[=raw|..] Force disk format for -a option\n"
- " -h|--human-readable Human-readable sizes in --long output\n"
- " --help Display brief help\n"
- " --keys-from-stdin Read passphrases from stdin\n"
- " -l|--long Long output\n"
- " --lvs|--logvols|--logical-volumes\n"
- " Display LVM logical volumes\n"
- " --no-title No title in --long output\n"
- " --parts|--partitions Display partitions\n"
- " --pvs|--physvols|--physical-volumes\n"
- " Display LVM physical volumes\n"
- " --uuid|--uuids Add UUIDs to --long output\n"
- " -v|--verbose Verbose messages\n"
- " -V|--version Display version and exit\n"
- " --vgs|--volgroups|--volume-groups\n"
- " Display LVM volume groups\n"
- " -x Trace libguestfs API calls\n"
- "For more information, see the manpage %s(1).\n"),
- guestfs_int_program_name, guestfs_int_program_name,
- guestfs_int_program_name, guestfs_int_program_name);
+ printf (
+ _("%s: list filesystems, partitions, block devices, LVM in a VM\n"
+ "Copyright (C) 2010 Red Hat Inc.\n"
+ "Usage:\n"
+ " %s [--options] -d domname\n"
+ " %s [--options] -a disk.img [-a disk.img ...]\n"
+ "Options:\n"
+ " -a|--add image Add image\n"
+ " --all Display everything\n"
+ " --blkdevs|--block-devices\n"
+ " Display block devices\n"
+ " -c|--connect uri Specify libvirt URI for -d option\n"
+ " --csv Output as Comma-Separated Values\n"
+ " -d|--domain guest Add disks from libvirt guest\n"
+ " --echo-keys Don't turn off echo for passphrases\n"
+ " --extra Display swap and data filesystems\n"
+ " --filesystems Display mountable filesystems\n"
+ " --format[=raw|..] Force disk format for -a option\n"
+ " -h|--human-readable Human-readable sizes in --long output\n"
+ " --help Display brief help\n"
+ " --keys-from-stdin Read passphrases from stdin\n"
+ " -l|--long Long output\n"
+ " --lvs|--logvols|--logical-volumes\n"
+ " Display LVM logical volumes\n"
+ " --no-title No title in --long output\n"
+ " --parts|--partitions Display partitions\n"
+ " --pvs|--physvols|--physical-volumes\n"
+ " Display LVM physical volumes\n"
+ " --uuid|--uuids Add UUIDs to --long output\n"
+ " -v|--verbose Verbose messages\n"
+ " -V|--version Display version and exit\n"
+ " --vgs|--volgroups|--volume-groups\n"
+ " Display LVM volume groups\n"
+ " -x Trace libguestfs API calls\n"
+ "For more information, see the manpage %s(1).\n"),
+ guestfs_int_program_name, guestfs_int_program_name,
+ guestfs_int_program_name, guestfs_int_program_name);
}
exit (status);
}
@@ -179,9 +180,9 @@ main (int argc, char *argv[])
bool format_consumed = true;
int c;
int option_index;
- int no_title = 0; /* --no-title */
- int long_mode = 0; /* --long|-l */
- int uuid = 0; /* --uuid */
+ int no_title = 0; /* --no-title */
+ int long_mode = 0; /* --long|-l */
+ int uuid = 0; /* --uuid */
int title;
g = guestfs_create ();
@@ -190,55 +191,70 @@ main (int argc, char *argv[])
for (;;) {
c = getopt_long (argc, argv, options, long_options, &option_index);
- if (c == -1) break;
+ if (c == -1)
+ break;
switch (c) {
- case 0: /* options which are long only */
+ case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "long-options"))
display_long_options (long_options);
else if (STREQ (long_options[option_index].name, "short-options"))
display_short_options (options);
else if (STREQ (long_options[option_index].name, "keys-from-stdin")) {
keys_from_stdin = 1;
- } else if (STREQ (long_options[option_index].name, "echo-keys")) {
+ }
+ else if (STREQ (long_options[option_index].name, "echo-keys")) {
echo_keys = 1;
- } else if (STREQ (long_options[option_index].name, "format")) {
+ }
+ else if (STREQ (long_options[option_index].name, "format")) {
OPTION_format;
- } else if (STREQ (long_options[option_index].name, "all")) {
+ }
+ else if (STREQ (long_options[option_index].name, "all")) {
output = OUTPUT_ALL;
- } else if (STREQ (long_options[option_index].name, "blkdevs") ||
- STREQ (long_options[option_index].name, "block-devices")) {
+ }
+ else if (STREQ (long_options[option_index].name, "blkdevs") ||
+ STREQ (long_options[option_index].name, "block-devices")) {
output |= OUTPUT_BLOCKDEVS;
- } else if (STREQ (long_options[option_index].name, "csv")) {
+ }
+ else if (STREQ (long_options[option_index].name, "csv")) {
csv = 1;
- } else if (STREQ (long_options[option_index].name, "extra")) {
+ }
+ else if (STREQ (long_options[option_index].name, "extra")) {
output |= OUTPUT_FILESYSTEMS;
output |= OUTPUT_FILESYSTEMS_EXTRA;
- } else if (STREQ (long_options[option_index].name, "filesystems")) {
+ }
+ else if (STREQ (long_options[option_index].name, "filesystems")) {
output |= OUTPUT_FILESYSTEMS;
- } else if (STREQ (long_options[option_index].name, "logical-volumes") ||
- STREQ (long_options[option_index].name, "logvols") ||
- STREQ (long_options[option_index].name, "lvs")) {
+ }
+ else if (STREQ (long_options[option_index].name, "logical-volumes") ||
+ STREQ (long_options[option_index].name, "logvols") ||
+ STREQ (long_options[option_index].name, "lvs")) {
output |= OUTPUT_LVS;
- } else if (STREQ (long_options[option_index].name, "no-title")) {
+ }
+ else if (STREQ (long_options[option_index].name, "no-title")) {
no_title = 1;
- } else if (STREQ (long_options[option_index].name, "parts") ||
- STREQ (long_options[option_index].name, "partitions")) {
+ }
+ else if (STREQ (long_options[option_index].name, "parts") ||
+ STREQ (long_options[option_index].name, "partitions")) {
output |= OUTPUT_PARTITIONS;
- } else if (STREQ (long_options[option_index].name, "physical-volumes")
||
- STREQ (long_options[option_index].name, "physvols") ||
- STREQ (long_options[option_index].name, "pvs")) {
+ }
+ else if (STREQ (long_options[option_index].name,
+ "physical-volumes") ||
+ STREQ (long_options[option_index].name, "physvols") ||
+ STREQ (long_options[option_index].name, "pvs")) {
output |= OUTPUT_PVS;
- } else if (STREQ (long_options[option_index].name, "uuid") ||
- STREQ (long_options[option_index].name, "uuids")) {
+ }
+ else if (STREQ (long_options[option_index].name, "uuid") ||
+ STREQ (long_options[option_index].name, "uuids")) {
uuid = 1;
- } else if (STREQ (long_options[option_index].name, "vgs") ||
- STREQ (long_options[option_index].name, "volgroups") ||
- STREQ (long_options[option_index].name, "volume-groups")) {
+ }
+ else if (STREQ (long_options[option_index].name, "vgs") ||
+ STREQ (long_options[option_index].name, "volgroups") ||
+ STREQ (long_options[option_index].name, "volume-groups")) {
output |= OUTPUT_VGS;
- } else
- error (EXIT_FAILURE, 0,
- _("unknown long option: %s (%d)"),
+ }
+ else
+ error (EXIT_FAILURE, 0, _("unknown long option: %s (%d)"),
long_options[option_index].name, option_index);
break;
@@ -360,7 +376,10 @@ static void do_output_pvs (void);
static void do_output_partitions (void);
static void do_output_blockdevs (void);
-static void write_row (const char *name, const char *type, const char *vfs_type, const
char *vfs_label, int mbr_id, int64_t size, char **parents, const char *uuid);
+static void write_row (const char *name, const char *type,
+ const char *vfs_type, const char *vfs_label,
+ int mbr_id, int64_t size, char **parents,
+ const char *uuid);
static void write_row_strings (char **strings, size_t len);
static char **no_parents (void);
@@ -393,7 +412,7 @@ do_output_title (void)
headings[len++] = "UUID";
assert (len <= NR_COLUMNS);
- write_row_strings ((char **) headings, len);
+ write_row_strings ((char **)headings, len);
}
static void
@@ -437,7 +456,7 @@ do_output_filesystems (void)
/* Skip swap and unknown, unless --extra flag was given. */
if (!(output & OUTPUT_FILESYSTEMS_EXTRA) &&
- (STREQ (fses[i+1], "swap") || STREQ (fses[i+1], "unknown")))
+ (STREQ (fses[i + 1], "swap") || STREQ (fses[i + 1],
"unknown")))
continue;
dev = guestfs_canonical_device_name (g, fses[i]);
@@ -478,8 +497,8 @@ do_output_filesystems (void)
else
parents = no_parents ();
- write_row (dev, "filesystem",
- fses[i+1], vfs_label, -1, size, parents, vfs_uuid);
+ write_row (dev, "filesystem", fses[i + 1], vfs_label, -1, size, parents,
+ vfs_uuid);
}
}
@@ -518,8 +537,7 @@ do_output_lvs (void)
parents[1] = NULL;
}
- write_row (lvs[i], "lv",
- NULL, NULL, -1, size, (char **) parents, uuid);
+ write_row (lvs[i], "lv", NULL, NULL, -1, size, (char **)parents, uuid);
}
}
@@ -546,8 +564,8 @@ do_output_vgs (void)
parents = parents_of_vg (vgs->val[i].vg_name);
- write_row (name, "vg",
- NULL, NULL, -1, (int64_t) vgs->val[i].vg_size, parents, uuid);
+ write_row (name, "vg", NULL, NULL, -1, (int64_t)vgs->val[i].vg_size,
+ parents, uuid);
}
}
@@ -593,9 +611,8 @@ do_output_pvs (void)
memcpy (uuid, pvs->val[i].pv_uuid, 32);
uuid[32] = '\0';
- write_row (dev, "pv",
- NULL, NULL, -1, (int64_t) pvs->val[i].pv_size,
- (char **) parents, uuid);
+ write_row (dev, "pv", NULL, NULL, -1, (int64_t)pvs->val[i].pv_size,
+ (char **)parents, uuid);
}
}
@@ -630,7 +647,8 @@ do_output_partitions (void)
exit (EXIT_FAILURE);
for (i = 0; parts[i] != NULL; ++i) {
- CLEANUP_FREE char *dev = NULL, *parent_name = NULL, *canonical_name = NULL;
+ CLEANUP_FREE char *dev = NULL, *parent_name = NULL,
+ *canonical_name = NULL;
const char *parents[2];
int64_t size = -1;
int mbr_id = -1;
@@ -660,8 +678,8 @@ do_output_partitions (void)
parents[1] = NULL;
}
- write_row (dev, "partition",
- NULL, NULL, mbr_id, size, (char **) parents, NULL);
+ write_row (dev, "partition", NULL, NULL, mbr_id, size, (char **)parents,
+ NULL);
}
}
@@ -694,8 +712,7 @@ do_output_blockdevs (void)
else
parents = no_parents ();
- write_row (dev, "device",
- NULL, NULL, -1, size, parents, NULL);
+ write_row (dev, "device", NULL, NULL, -1, size, parents, NULL);
}
}
@@ -826,9 +843,9 @@ parents_of_vg (char *vg)
}
static void
-write_row (const char *name, const char *type,
- const char *vfs_type, const char *vfs_label, int mbr_id,
- int64_t size, char **parents, const char *uuid)
+write_row (const char *name, const char *type, const char *vfs_type,
+ const char *vfs_label, int mbr_id, int64_t size, char **parents,
+ const char *uuid)
{
const char *strings[NR_COLUMNS];
CLEANUP_FREE char *parents_str = NULL;
@@ -847,19 +864,19 @@ write_row (const char *name, const char *type,
strings[len++] = vfs_label;
if ((columns & COLUMN_MBR)) {
if (mbr_id >= 0) {
- snprintf (mbr_id_str, sizeof mbr_id_str, "%02x", (unsigned) mbr_id);
+ snprintf (mbr_id_str, sizeof mbr_id_str, "%02x", (unsigned)mbr_id);
strings[len++] = mbr_id_str;
- } else
+ }
+ else
strings[len++] = NULL;
}
if ((columns & COLUMN_SIZE)) {
if (size >= 0) {
if (human) {
- strings[len++] =
- human_readable ((uintmax_t) size, hum,
- human_round_to_nearest|human_autoscale|
- human_base_1024|human_SI,
- 1, 1);
+ strings[len++] = human_readable (
+ (uintmax_t)size, hum, human_round_to_nearest | human_autoscale |
+ human_base_1024 | human_SI,
+ 1, 1);
}
else {
snprintf (num, sizeof num, "%" PRIi64, size);
@@ -878,7 +895,7 @@ write_row (const char *name, const char *type,
strings[len++] = uuid;
assert (len <= NR_COLUMNS);
- write_row_strings ((char **) strings, len);
+ write_row_strings ((char **)strings, len);
}
static void add_row (char **strings, size_t len);
@@ -894,7 +911,7 @@ write_row_strings (char **strings, size_t len)
*/
add_row (strings, len);
}
- else { /* CSV mode: output it directly, quoted */
+ else { /* CSV mode: output it directly, quoted */
size_t i;
for (i = 0; i < len; ++i) {
@@ -919,8 +936,8 @@ write_csv_field (const char *field)
len = strlen (field);
for (i = 0; i < len; ++i) {
- if (field[i] == ' ' || field[i] == '"' ||
- field[i] == '\n' || field[i] == ',') {
+ if (field[i] == ' ' || field[i] == '"' || field[i] ==
'\n' ||
+ field[i] == ',') {
needs_quoting = 1;
break;
}
@@ -937,7 +954,8 @@ write_csv_field (const char *field)
if (field[i] == '"') {
putchar ('"');
putchar ('"');
- } else
+ }
+ else
putchar (field[i]);
}
putchar ('"');
@@ -1026,7 +1044,8 @@ do_output_end (void)
if (row[j] == NULL || STREQ (row[j], "")) {
printf ("-");
len = 1;
- } else {
+ }
+ else {
printf ("%s", row[j]);
len = strlen (row[j]);
}
diff --git a/cat/log.c b/cat/log.c
index daefda7..2468412 100644
--- a/cat/log.c
+++ b/cat/log.c
@@ -63,25 +63,26 @@ usage (int status)
fprintf (stderr, _("Try `%s --help' for more information.\n"),
guestfs_int_program_name);
else {
- printf (_("%s: display log files in a virtual machine\n"
- "Copyright (C) 2010-2016 Red Hat Inc.\n"
- "Usage:\n"
- " %s [--options] -d domname\n"
- " %s [--options] -a disk.img [-a disk.img ...]\n"
- "Options:\n"
- " -a|--add image Add image\n"
- " -c|--connect uri Specify libvirt URI for -d option\n"
- " -d|--domain guest Add disks from libvirt guest\n"
- " --echo-keys Don't turn off echo for
passphrases\n"
- " --format[=raw|..] Force disk format for -a option\n"
- " --help Display brief help\n"
- " --keys-from-stdin Read passphrases from stdin\n"
- " -v|--verbose Verbose messages\n"
- " -V|--version Display version and exit\n"
- " -x Trace libguestfs API calls\n"
- "For more information, see the manpage %s(1).\n"),
- guestfs_int_program_name, guestfs_int_program_name,
- guestfs_int_program_name, guestfs_int_program_name);
+ printf (
+ _("%s: display log files in a virtual machine\n"
+ "Copyright (C) 2010-2016 Red Hat Inc.\n"
+ "Usage:\n"
+ " %s [--options] -d domname\n"
+ " %s [--options] -a disk.img [-a disk.img ...]\n"
+ "Options:\n"
+ " -a|--add image Add image\n"
+ " -c|--connect uri Specify libvirt URI for -d option\n"
+ " -d|--domain guest Add disks from libvirt guest\n"
+ " --echo-keys Don't turn off echo for passphrases\n"
+ " --format[=raw|..] Force disk format for -a option\n"
+ " --help Display brief help\n"
+ " --keys-from-stdin Read passphrases from stdin\n"
+ " -v|--verbose Verbose messages\n"
+ " -V|--version Display version and exit\n"
+ " -x Trace libguestfs API calls\n"
+ "For more information, see the manpage %s(1).\n"),
+ guestfs_int_program_name, guestfs_int_program_name,
+ guestfs_int_program_name, guestfs_int_program_name);
}
exit (status);
}
@@ -97,18 +98,12 @@ main (int argc, char *argv[])
static const char *options = "a:c:d:vVx";
static const struct option long_options[] = {
- { "add", 1, 0, 'a' },
- { "connect", 1, 0, 'c' },
- { "domain", 1, 0, 'd' },
- { "echo-keys", 0, 0, 0 },
- { "format", 2, 0, 0 },
- { "help", 0, 0, HELP_OPTION },
- { "keys-from-stdin", 0, 0, 0 },
- { "long-options", 0, 0, 0 },
- { "short-options", 0, 0, 0 },
- { "verbose", 0, 0, 'v' },
- { "version", 0, 0, 'V' },
- { 0, 0, 0, 0 }
+ { "add", 1, 0, 'a' }, { "connect", 1, 0,
'c' },
+ { "domain", 1, 0, 'd' }, { "echo-keys", 0, 0, 0
},
+ { "format", 2, 0, 0 }, { "help", 0, 0, HELP_OPTION },
+ { "keys-from-stdin", 0, 0, 0 }, { "long-options", 0, 0, 0 },
+ { "short-options", 0, 0, 0 }, { "verbose", 0, 0, 'v'
},
+ { "version", 0, 0, 'V' }, { 0, 0, 0, 0 }
};
struct drv *drvs = NULL;
const char *format = NULL;
@@ -123,23 +118,26 @@ main (int argc, char *argv[])
for (;;) {
c = getopt_long (argc, argv, options, long_options, &option_index);
- if (c == -1) break;
+ if (c == -1)
+ break;
switch (c) {
- case 0: /* options which are long only */
+ case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "long-options"))
display_long_options (long_options);
else if (STREQ (long_options[option_index].name, "short-options"))
display_short_options (options);
else if (STREQ (long_options[option_index].name, "keys-from-stdin")) {
keys_from_stdin = 1;
- } else if (STREQ (long_options[option_index].name, "echo-keys")) {
+ }
+ else if (STREQ (long_options[option_index].name, "echo-keys")) {
echo_keys = 1;
- } else if (STREQ (long_options[option_index].name, "format")) {
+ }
+ else if (STREQ (long_options[option_index].name, "format")) {
OPTION_format;
- } else
- error (EXIT_FAILURE, 0,
- _("unknown long option: %s (%d)"),
+ }
+ else
+ error (EXIT_FAILURE, 0, _("unknown long option: %s (%d)"),
long_options[option_index].name, option_index);
break;
@@ -239,9 +237,10 @@ do_log (void)
if (guestfs_inspect_get_major_version (g, root) >= 6)
return do_log_windows_evtx ();
- fprintf (stderr,
- _("%s: Windows Event Log for pre-Vista guests is not
supported.\n"),
- guestfs_int_program_name);
+ fprintf (
+ stderr,
+ _("%s: Windows Event Log for pre-Vista guests is not supported.\n"),
+ guestfs_int_program_name);
return -1;
}
@@ -249,13 +248,14 @@ do_log (void)
guestfs_push_error_handler (g, NULL, NULL);
journal_files = guestfs_ls (g, JOURNAL_DIR);
guestfs_pop_error_handler (g);
- if (STREQ (type, "linux") &&
- journal_files != NULL && journal_files[0] != NULL)
+ if (STREQ (type, "linux") && journal_files != NULL &&
+ journal_files[0] != NULL)
return do_log_journal ();
/* Regular /var/log text files with different names. */
if (STRNEQ (type, "windows")) {
- const char *logfiles[] = { "/var/log/syslog",
"/var/log/messages", NULL };
+ const char *logfiles[] = { "/var/log/syslog",
"/var/log/messages",
+ NULL };
size_t i;
for (i = 0; logfiles[i] != NULL; ++i) {
@@ -279,8 +279,8 @@ do_log (void)
* function returns the first entry.
*/
static const char *
-get_journal_field (const struct guestfs_xattr_list *xattrs, const char *name,
- size_t *len_rtn)
+get_journal_field (const struct guestfs_xattr_list *xattrs,
+ const char *name, size_t *len_rtn)
{
uint32_t i;
@@ -291,19 +291,17 @@ get_journal_field (const struct guestfs_xattr_list *xattrs, const
char *name,
}
}
- return NULL; /* not found */
+ return NULL; /* not found */
}
-static const char *const log_level_table[] = {
- [LOG_EMERG] = "emerg",
- [LOG_ALERT] = "alert",
- [LOG_CRIT] = "crit",
- [LOG_ERR] = "err",
- [LOG_WARNING] = "warning",
- [LOG_NOTICE] = "notice",
- [LOG_INFO] = "info",
- [LOG_DEBUG] = "debug"
-};
+static const char *const log_level_table[] = {[LOG_EMERG] = "emerg",
+ [LOG_ALERT] = "alert",
+ [LOG_CRIT] = "crit",
+ [LOG_ERR] = "err",
+ [LOG_WARNING] = "warning",
+ [LOG_NOTICE] = "notice",
+ [LOG_INFO] = "info",
+ [LOG_DEBUG] = "debug" };
static int
do_log_journal (void)
@@ -333,9 +331,9 @@ do_log_journal (void)
ts = guestfs_journal_get_realtime_usec (g); /* error checked below */
priority_str = get_journal_field (xattrs, "PRIORITY", &priority_len);
- //hostname = get_journal_field (xattrs, "_HOSTNAME", &hostname_len);
- identifier = get_journal_field (xattrs, "SYSLOG_IDENTIFIER",
- &identifier_len);
+ // hostname = get_journal_field (xattrs, "_HOSTNAME", &hostname_len);
+ identifier =
+ get_journal_field (xattrs, "SYSLOG_IDENTIFIER", &identifier_len);
comm = get_journal_field (xattrs, "_COMM", &comm_len);
pid = get_journal_field (xattrs, "_PID", &pid_len);
message = get_journal_field (xattrs, "MESSAGE", &message_len);
@@ -348,7 +346,8 @@ do_log_journal (void)
if (strftime (buf, sizeof buf, "%b %d %H:%M:%S",
localtime_r (&t, &tm)) <= 0) {
- fprintf (stderr, _("%s: could not format journal entry timestamp\n"),
+ fprintf (stderr,
+ _("%s: could not format journal entry timestamp\n"),
guestfs_int_program_name);
errors++;
continue;
@@ -360,18 +359,18 @@ do_log_journal (void)
/* We don't print this because it is assumed each line from the
* guest will have the same hostname. (XXX)
*/
- //if (hostname)
+ // if (hostname)
// printf (" %.*s", (int) hostname_len, hostname);
/* Identifier. */
if (identifier)
- printf (" %.*s", (int) identifier_len, identifier);
+ printf (" %.*s", (int)identifier_len, identifier);
else if (comm)
- printf (" %.*s", (int) comm_len, comm);
+ printf (" %.*s", (int)comm_len, comm);
/* PID */
if (pid)
- printf ("[%.*s]", (int) pid_len, pid);
+ printf ("[%.*s]", (int)pid_len, pid);
/* Log level. */
if (priority_str && *priority_str >= '0' && *priority_str
<= '7')
@@ -381,11 +380,11 @@ do_log_journal (void)
/* Message. */
if (message)
- printf (" %.*s", (int) message_len, message);
+ printf (" %.*s", (int)message_len, message);
printf ("\n");
}
- if (r == -1) /* error from guestfs_journal_next */
+ if (r == -1) /* error from guestfs_journal_next */
return -1;
if (guestfs_journal_close (g) == -1)
@@ -414,10 +413,14 @@ do_log_windows_evtx (void)
int fd, status;
if (system ("evtxdump.py -h >/dev/null 2>&1") != 0) {
- fprintf (stderr, _("%s: you need to install 'evtxdump.py' (from the
python-evtx package)\n"
- "in order to parse Windows Event Logs. If you cannot install
this, then\n"
- "use virt-copy-out(1) to copy the contents of
/Windows/System32/winevt/Logs\n"
- "from this guest, and examine in a binary file
viewer.\n"),
+ fprintf (stderr,
+ _("%s: you need to install 'evtxdump.py' (from the "
+ "python-evtx package)\n"
+ "in order to parse Windows Event Logs. If you cannot "
+ "install this, then\n"
+ "use virt-copy-out(1) to copy the contents of "
+ "/Windows/System32/winevt/Logs\n"
+ "from this guest, and examine in a binary file viewer.\n"),
guestfs_int_program_name);
return -1;
}
@@ -425,14 +428,14 @@ do_log_windows_evtx (void)
/* Check if System.evtx exists. XXX Allow the filename to be
* configurable, since there are many logs.
*/
- filename = guestfs_case_sensitive_path (g,
"/Windows/System32/winevt/Logs/System.evtx");
+ filename = guestfs_case_sensitive_path (
+ g, "/Windows/System32/winevt/Logs/System.evtx");
if (filename == NULL)
return -1;
/* Note that guestfs_case_sensitive_path does NOT check for existence. */
- if (guestfs_is_file_opts (g, filename,
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1,
- -1) <= 0) {
+ if (guestfs_is_file_opts (
+ g, filename, GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) <= 0) {
fprintf (stderr, _("%s: Windows Event Log file (%s) not found\n"),
guestfs_int_program_name, filename);
return -1;
@@ -465,10 +468,9 @@ do_log_windows_evtx (void)
status = system (cmd);
if (status) {
char buf[256];
- fprintf (stderr, "%s: %s\n",
- guestfs_int_program_name,
- guestfs_int_exit_status_to_string (status, "evtxdump.py",
- buf, sizeof buf));
+ fprintf (stderr, "%s: %s\n", guestfs_int_program_name,
+ guestfs_int_exit_status_to_string (status, "evtxdump.py", buf,
+ sizeof buf));
return -1;
}
diff --git a/cat/ls.c b/cat/ls.c
index 91f2125..a5371d5 100644
--- a/cat/ls.c
+++ b/cat/ls.c
@@ -84,38 +84,39 @@ usage (int status)
fprintf (stderr, _("Try `%s --help' for more information.\n"),
guestfs_int_program_name);
else {
- printf (_("%s: list files in a virtual machine\n"
- "Copyright (C) 2010-2012 Red Hat Inc.\n"
- "Usage:\n"
- " %s [--options] -d domname dir [dir ...]\n"
- " %s [--options] -a disk.img [-a disk.img ...] dir [dir ...]\n"
- "Options:\n"
- " -a|--add image Add image\n"
- " --checksum[=...] Display file checksums\n"
- " -c|--connect uri Specify libvirt URI for -d option\n"
- " --csv Comma-Separated Values output\n"
- " -d|--domain guest Add disks from libvirt guest\n"
- " --echo-keys Don't turn off echo for
passphrases\n"
- " --extra-stats Display extra stats\n"
- " --format[=raw|..] Force disk format for -a option\n"
- " --help Display brief help\n"
- " -h|--human-readable Human-readable sizes in output\n"
- " --keys-from-stdin Read passphrases from stdin\n"
- " -l|--long Long listing\n"
- " -m|--mount dev[:mnt[:opts[:fstype]]]\n"
- " Mount dev on mnt (if omitted, /)\n"
- " -R|--recursive Recursive listing\n"
- " --times Display file times\n"
- " --time-days Display file times as days before now\n"
- " --time-relative Display file times as seconds before
now\n"
- " --time-t Display file times as time_t's\n"
- " --uids Display UID, GID\n"
- " -v|--verbose Verbose messages\n"
- " -V|--version Display version and exit\n"
- " -x Trace libguestfs API calls\n"
- "For more information, see the manpage %s(1).\n"),
- guestfs_int_program_name, guestfs_int_program_name,
- guestfs_int_program_name, guestfs_int_program_name);
+ printf (
+ _("%s: list files in a virtual machine\n"
+ "Copyright (C) 2010-2012 Red Hat Inc.\n"
+ "Usage:\n"
+ " %s [--options] -d domname dir [dir ...]\n"
+ " %s [--options] -a disk.img [-a disk.img ...] dir [dir ...]\n"
+ "Options:\n"
+ " -a|--add image Add image\n"
+ " --checksum[=...] Display file checksums\n"
+ " -c|--connect uri Specify libvirt URI for -d option\n"
+ " --csv Comma-Separated Values output\n"
+ " -d|--domain guest Add disks from libvirt guest\n"
+ " --echo-keys Don't turn off echo for passphrases\n"
+ " --extra-stats Display extra stats\n"
+ " --format[=raw|..] Force disk format for -a option\n"
+ " --help Display brief help\n"
+ " -h|--human-readable Human-readable sizes in output\n"
+ " --keys-from-stdin Read passphrases from stdin\n"
+ " -l|--long Long listing\n"
+ " -m|--mount dev[:mnt[:opts[:fstype]]]\n"
+ " Mount dev on mnt (if omitted, /)\n"
+ " -R|--recursive Recursive listing\n"
+ " --times Display file times\n"
+ " --time-days Display file times as days before now\n"
+ " --time-relative Display file times as seconds before now\n"
+ " --time-t Display file times as time_t's\n"
+ " --uids Display UID, GID\n"
+ " -v|--verbose Verbose messages\n"
+ " -V|--version Display version and exit\n"
+ " -x Trace libguestfs API calls\n"
+ "For more information, see the manpage %s(1).\n"),
+ guestfs_int_program_name, guestfs_int_program_name,
+ guestfs_int_program_name, guestfs_int_program_name);
}
exit (status);
}
@@ -174,7 +175,7 @@ main (int argc, char *argv[])
int option_index;
#define MODE_LS_L 1
#define MODE_LS_R 2
-#define MODE_LS_LR (MODE_LS_L|MODE_LS_R)
+#define MODE_LS_LR (MODE_LS_L | MODE_LS_R)
int mode = 0;
g = guestfs_create ();
@@ -183,51 +184,62 @@ main (int argc, char *argv[])
for (;;) {
c = getopt_long (argc, argv, options, long_options, &option_index);
- if (c == -1) break;
+ if (c == -1)
+ break;
switch (c) {
- case 0: /* options which are long only */
+ case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "long-options"))
display_long_options (long_options);
else if (STREQ (long_options[option_index].name, "short-options"))
display_short_options (options);
else if (STREQ (long_options[option_index].name, "keys-from-stdin")) {
keys_from_stdin = 1;
- } else if (STREQ (long_options[option_index].name, "echo-keys")) {
+ }
+ else if (STREQ (long_options[option_index].name, "echo-keys")) {
echo_keys = 1;
- } else if (STREQ (long_options[option_index].name, "format")) {
+ }
+ else if (STREQ (long_options[option_index].name, "format")) {
OPTION_format;
- } else if (STREQ (long_options[option_index].name, "checksum") ||
- STREQ (long_options[option_index].name, "checksums")) {
+ }
+ else if (STREQ (long_options[option_index].name, "checksum") ||
+ STREQ (long_options[option_index].name, "checksums")) {
if (!optarg || STREQ (optarg, ""))
checksum = "md5";
else
checksum = optarg;
- } else if (STREQ (long_options[option_index].name, "csv")) {
+ }
+ else if (STREQ (long_options[option_index].name, "csv")) {
csv = 1;
- } else if (STREQ (long_options[option_index].name, "extra-stat") ||
- STREQ (long_options[option_index].name, "extra-stats")) {
+ }
+ else if (STREQ (long_options[option_index].name, "extra-stat") ||
+ STREQ (long_options[option_index].name, "extra-stats")) {
enable_extra_stats = 1;
- } else if (STREQ (long_options[option_index].name, "time") ||
- STREQ (long_options[option_index].name, "times")) {
+ }
+ else if (STREQ (long_options[option_index].name, "time") ||
+ STREQ (long_options[option_index].name, "times")) {
enable_times = 1;
- } else if (STREQ (long_options[option_index].name, "time-t")) {
+ }
+ else if (STREQ (long_options[option_index].name, "time-t")) {
enable_times = 1;
time_t_output = 1;
- } else if (STREQ (long_options[option_index].name, "time-relative")) {
+ }
+ else if (STREQ (long_options[option_index].name, "time-relative")) {
enable_times = 1;
time_t_output = 1;
time_relative = 1;
- } else if (STREQ (long_options[option_index].name, "time-days")) {
+ }
+ else if (STREQ (long_options[option_index].name, "time-days")) {
enable_times = 1;
time_t_output = 1;
time_relative = 2;
- } else if (STREQ (long_options[option_index].name, "uid") ||
- STREQ (long_options[option_index].name, "uids")) {
+ }
+ else if (STREQ (long_options[option_index].name, "uid") ||
+ STREQ (long_options[option_index].name, "uids")) {
enable_uids = 1;
- } else
- error (EXIT_FAILURE, 0,
- _("unknown long option: %s (%d)"),
+ }
+ else
+ error (EXIT_FAILURE, 0, _("unknown long option: %s (%d)"),
long_options[option_index].name, option_index);
break;
@@ -297,7 +309,8 @@ main (int argc, char *argv[])
error (EXIT_FAILURE, errno, "strdup");
drv->next = drvs;
drvs = drv;
- } else { /* simulate -d option */
+ }
+ else { /* simulate -d option */
drv = calloc (1, sizeof (struct drv));
if (!drv)
error (EXIT_FAILURE, errno, "calloc");
@@ -322,11 +335,11 @@ main (int argc, char *argv[])
CHECK_OPTION_format_consumed;
/* Many flags only apply to -lR mode. */
- if (mode != MODE_LS_LR &&
- (csv || human || enable_uids || enable_times || enable_extra_stats ||
- checksum))
+ if (mode != MODE_LS_LR && (csv || human || enable_uids || enable_times ||
+ enable_extra_stats || checksum))
error (EXIT_FAILURE, 0,
- _("used a flag which can only be combined with -lR mode\nFor more
information, read the virt-ls(1) man page."));
+ _("used a flag which can only be combined with -lR mode\nFor "
+ "more information, read the virt-ls(1) man page."));
/* CSV && human is unsafe because spreadsheets fail to parse these
* fields correctly. (RHBZ#600977).
@@ -364,28 +377,28 @@ main (int argc, char *argv[])
const char *dir = argv[optind];
switch (mode) {
- case 0: /* no -l or -R option */
+ case 0: /* no -l or -R option */
if (do_ls (dir) == -1)
errors++;
break;
- case MODE_LS_L: /* virt-ls -l */
+ case MODE_LS_L: /* virt-ls -l */
if (do_ls_l (dir) == -1)
errors++;
break;
- case MODE_LS_R: /* virt-ls -R */
+ case MODE_LS_R: /* virt-ls -R */
if (do_ls_R (dir) == -1)
errors++;
break;
- case MODE_LS_LR: /* virt-ls -lR */
+ case MODE_LS_LR: /* virt-ls -lR */
if (do_ls_lR (dir) == -1)
errors++;
break;
default:
- abort (); /* can't happen */
+ abort (); /* can't happen */
}
optind++;
@@ -439,7 +452,10 @@ do_ls_R (const char *dir)
return 0;
}
-static int show_file (const char *dir, const char *name, const struct guestfs_statns
*stat, const struct guestfs_xattr_list *xattrs, void *unused);
+static int show_file (const char *dir, const char *name,
+ const struct guestfs_statns *stat,
+ const struct guestfs_xattr_list *xattrs,
+ void *unused);
static int
do_ls_lR (const char *dir)
@@ -457,8 +473,7 @@ do_ls_lR (const char *dir)
static int
show_file (const char *dir, const char *name,
const struct guestfs_statns *stat,
- const struct guestfs_xattr_list *xattrs,
- void *unused)
+ const struct guestfs_xattr_list *xattrs, void *unused)
{
const char *filetype;
CLEANUP_FREE char *path = NULL, *csum = NULL, *link = NULL;
@@ -521,7 +536,8 @@ show_file (const char *dir, const char *name,
exit (EXIT_FAILURE);
output_string (csum);
- } else if (csv)
+ }
+ else if (csv)
output_string ("");
}
@@ -550,7 +566,8 @@ next_field (void)
int c = csv ? ',' : ' ';
field++;
- if (field == 1) return;
+ if (field == 1)
+ return;
if (putchar (c) == EOF)
error (EXIT_FAILURE, errno, "putchar");
@@ -587,8 +604,7 @@ output_string (const char *s)
len = strlen (s);
for (i = 0; i < len; ++i) {
- if (s[i] == ' ' || s[i] == '"' ||
- s[i] == '\n' || s[i] == ',') {
+ if (s[i] == ' ' || s[i] == '"' || s[i] == '\n' || s[i]
== ',') {
needs_quoting = 1;
break;
}
@@ -604,7 +620,8 @@ output_string (const char *s)
if (s[i] == '"') {
if (putchar ('"') == EOF || putchar ('"') == EOF)
error (EXIT_FAILURE, errno, "putchar");
- } else {
+ }
+ else {
if (putchar (s[i]) == EOF)
error (EXIT_FAILURE, errno, "putchar");
}
@@ -640,7 +657,8 @@ static void
output_int64_size (int64_t size)
{
char buf[LONGEST_HUMAN_READABLE];
- int hopts = human_round_to_nearest|human_autoscale|human_base_1024|human_SI;
+ int hopts =
+ human_round_to_nearest | human_autoscale | human_base_1024 | human_SI;
int r;
next_field ();
@@ -649,15 +667,15 @@ output_int64_size (int64_t size)
if (!human)
r = printf ("%10" PRIi64, size);
else
- r = printf ("%10s",
- human_readable ((uintmax_t) size, buf, hopts, 1, 1));
- } else {
+ r =
+ printf ("%10s", human_readable ((uintmax_t)size, buf, hopts, 1, 1));
+ }
+ else {
/* CSV is the same as non-CSV but we don't need to right-align. */
if (!human)
r = printf ("%" PRIi64, size);
else
- r = printf ("%s",
- human_readable ((uintmax_t) size, buf, hopts, 1, 1));
+ r = printf ("%s", human_readable ((uintmax_t)size, buf, hopts, 1, 1));
}
if (r < 0)
@@ -669,7 +687,7 @@ output_int64_perms (int64_t i)
{
next_field ();
/* csv doesn't need escaping */
- if (printf ("%04" PRIo64, (uint64_t) i) < 0)
+ if (printf ("%04" PRIo64, (uint64_t)i) < 0)
error (EXIT_FAILURE, errno, "printf");
}
@@ -683,20 +701,20 @@ output_int64_time (int64_t secs, int64_t nsecs)
/* csv doesn't need escaping */
if (time_t_output) {
switch (time_relative) {
- case 0: /* --time-t */
+ case 0: /* --time-t */
r = printf ("%10" PRIi64, secs);
break;
- case 1: /* --time-relative */
+ case 1: /* --time-relative */
r = printf ("%8" PRIi64, now - secs);
break;
- case 2: /* --time-days */
+ case 2: /* --time-days */
default:
r = printf ("%3" PRIi64, (now - secs) / 86400);
break;
}
}
else {
- time_t t = (time_t) secs;
+ time_t t = (time_t)secs;
char buf[64];
struct tm *tm;
@@ -731,7 +749,7 @@ output_int64_dev (int64_t i)
next_field ();
/* csv doesn't need escaping */
- if (printf ("%ju:%ju",
- (uintmax_t) major (dev), (uintmax_t) minor (dev)) < 0)
+ if (printf ("%ju:%ju", (uintmax_t)major (dev), (uintmax_t)minor (dev)) <
+ 0)
error (EXIT_FAILURE, errno, "printf");
}
diff --git a/cat/visit.c b/cat/visit.c
index 2e08ccc..ed62af7 100644
--- a/cat/visit.c
+++ b/cat/visit.c
@@ -34,7 +34,8 @@
https://rwmj.wordpress.com/2010/12/15/tip-audit-virtual-machine-for-setui...
#include "visit.h"
-static int _visit (guestfs_h *g, int depth, const char *dir, visitor_function f, void
*opaque);
+static int _visit (guestfs_h *g, int depth, const char *dir,
+ visitor_function f, void *opaque);
int
visit (guestfs_h *g, const char *dir, visitor_function f, void *opaque)
@@ -43,8 +44,8 @@ visit (guestfs_h *g, const char *dir, visitor_function f, void *opaque)
}
static int
-_visit (guestfs_h *g, int depth, const char *dir,
- visitor_function f, void *opaque)
+_visit (guestfs_h *g, int depth, const char *dir, visitor_function f,
+ void *opaque)
{
/* Call 'f' with the top directory. Note that ordinary recursive
* visits will not otherwise do this, so we have to have a special
@@ -114,13 +115,14 @@ _visit (guestfs_h *g, int depth, const char *dir,
xattrs->val[xattrp].attrval_len);
attrval[xattrs->val[xattrp].attrval_len] = '\0';
if (sscanf (attrval, "%zu", &nr_xattrs) != 1) {
- fprintf (stderr, _("%s: error: cannot parse xattr count for %s %s\n"),
+ fprintf (stderr,
+ _("%s: error: cannot parse xattr count for %s %s\n"),
guestfs_int_program_name, dir, names[i]);
return -1;
}
file_xattrs.len = nr_xattrs;
- file_xattrs.val = &xattrs->val[xattrp+1];
+ file_xattrs.val = &xattrs->val[xattrp + 1];
xattrp += nr_xattrs;
/* Call the function. */
diff --git a/cat/visit.h b/cat/visit.h
index d8f7871..ebcf7b9 100644
--- a/cat/visit.h
+++ b/cat/visit.h
@@ -19,9 +19,13 @@
#ifndef VISIT_H
#define VISIT_H
-typedef int (*visitor_function) (const char *dir, const char *name, const struct
guestfs_statns *stat, const struct guestfs_xattr_list *xattrs, void *opaque);
+typedef int (*visitor_function) (const char *dir, const char *name,
+ const struct guestfs_statns *stat,
+ const struct guestfs_xattr_list *xattrs,
+ void *opaque);
-extern int visit (guestfs_h *g, const char *dir, visitor_function f, void *opaque);
+extern int visit (guestfs_h *g, const char *dir, visitor_function f,
+ void *opaque);
extern char *full_path (const char *dir, const char *name);
diff --git a/daemon/9p.c b/daemon/9p.c
index fefbb71..3f5e1a7 100644
--- a/daemon/9p.c
+++ b/daemon/9p.c
@@ -33,7 +33,7 @@
#include "actions.h"
#define BUS_PATH "/sys/bus/virtio/drivers/9pnet_virtio"
-GUESTFSD_EXT_CMD(str_mount, mount);
+GUESTFSD_EXT_CMD (str_mount, mount);
static char *read_whole_file (const char *filename);
@@ -68,7 +68,8 @@ do_list_9p (void)
errno = 0;
d = readdir (dir);
- if (d == NULL) break;
+ if (d == NULL)
+ break;
if (STRPREFIX (d->d_name, "virtio")) {
char mount_tag_path[256];
@@ -127,7 +128,7 @@ read_whole_file (const char *filename)
size_t alloc = 0, size = 0;
int fd;
- fd = open (filename, O_RDONLY|O_CLOEXEC);
+ fd = open (filename, O_RDONLY | O_CLOEXEC);
if (fd == -1) {
perror (filename);
return NULL;
@@ -172,7 +173,8 @@ read_whole_file (const char *filename)
/* Takes optional arguments, consult optargs_bitmask. */
int
-do_mount_9p (const char *mount_tag, const char *mountpoint, const char *options)
+do_mount_9p (const char *mount_tag, const char *mountpoint,
+ const char *options)
{
CLEANUP_FREE char *mp = NULL, *opts = NULL, *err = NULL;
struct stat statbuf;
@@ -212,8 +214,8 @@ do_mount_9p (const char *mount_tag, const char *mountpoint, const char
*options)
}
}
- r = command (NULL, &err,
- str_mount, "-o", opts, "-t", "9p",
mount_tag, mp, NULL);
+ r = command (NULL, &err, str_mount, "-o", opts, "-t",
"9p", mount_tag, mp,
+ NULL);
if (r == -1) {
reply_with_error ("%s on %s: %s", mount_tag, mountpoint, err);
return -1;
diff --git a/daemon/acl.c b/daemon/acl.c
index fcb14e1..998bffc 100644
--- a/daemon/acl.c
+++ b/daemon/acl.c
@@ -85,7 +85,7 @@ do_acl_get_file (const char *path, const char *acltype)
}
acl_free (r);
- return ret; /* caller frees */
+ return ret; /* caller frees */
}
int
@@ -106,7 +106,8 @@ do_acl_set_file (const char *path, const char *acltype, const char
*aclstr)
acl = acl_from_text (aclstr);
if (acl == NULL) {
- reply_with_perror ("could not parse acl string: %s: acl_from_text",
aclstr);
+ reply_with_perror ("could not parse acl string: %s: acl_from_text",
+ aclstr);
return -1;
}
diff --git a/daemon/augeas.c b/daemon/augeas.c
index ea1163f..b885be5 100644
--- a/daemon/augeas.c
+++ b/daemon/augeas.c
@@ -29,20 +29,21 @@
#include "actions.h"
#include "optgroups.h"
-#define FPRINTF_AUGEAS_ERROR(aug,fs,...) \
- do { \
- int code = aug_error (aug); \
- if (code == AUG_ENOMEM) \
- reply_with_error (fs ": augeas out of memory", ##__VA_ARGS__); \
- else { \
- const char *aug_err_message = aug_error_message (aug); \
- const char *aug_err_minor = aug_error_minor_message (aug); \
- const char *aug_err_details = aug_error_details (aug); \
- fprintf (stderr, fs ": %s%s%s%s%s", ##__VA_ARGS__, \
- aug_err_message, \
- aug_err_minor ? ": " : "", aug_err_minor ? aug_err_minor :
"", \
- aug_err_details ? ": " : "", aug_err_details ?
aug_err_details : ""); \
- } \
+#define FPRINTF_AUGEAS_ERROR(aug, fs, ...) \
+ do { \
+ int code = aug_error (aug); \
+ if (code == AUG_ENOMEM) \
+ reply_with_error (fs ": augeas out of memory", ##__VA_ARGS__); \
+ else { \
+ const char *aug_err_message = aug_error_message (aug); \
+ const char *aug_err_minor = aug_error_minor_message (aug); \
+ const char *aug_err_details = aug_error_details (aug); \
+ fprintf (stderr, fs ": %s%s%s%s%s", ##__VA_ARGS__, aug_err_message, \
+ aug_err_minor ? ": " : "",
\
+ aug_err_minor ? aug_err_minor : "", \
+ aug_err_details ? ": " : "",
\
+ aug_err_details ? aug_err_details : ""); \
+ } \
} while (0)
int augeas_version;
@@ -107,14 +108,15 @@ aug_finalize (void)
}
}
-#define NEED_AUG(errcode) \
- do { \
- if (!aug) { \
- reply_with_error ("%s: you must call 'aug-init' first to initialize
Augeas", __func__); \
- return (errcode); \
- } \
- } \
- while (0)
+#define NEED_AUG(errcode) \
+ do { \
+ if (!aug) { \
+ reply_with_error ( \
+ "%s: you must call 'aug-init' first to initialize Augeas", \
+ __func__); \
+ return (errcode); \
+ } \
+ } while (0)
/* We need to rewrite the root path so it is based at /sysroot. */
int
@@ -173,7 +175,7 @@ do_aug_init (const char *root, int flags)
int
do_aug_close (void)
{
- NEED_AUG(-1);
+ NEED_AUG (-1);
aug_close (aug);
aug = NULL;
@@ -257,7 +259,7 @@ do_aug_get (const char *path)
return NULL;
}
- return v; /* Caller frees. */
+ return v; /* Caller frees. */
}
int
@@ -358,7 +360,7 @@ do_aug_match (const char *path)
/* This returns an array of length r, which we must extend
* and add a terminating NULL.
*/
- vp = realloc (matches, sizeof (char *) * (r+1));
+ vp = realloc (matches, sizeof (char *) * (r + 1));
if (vp == NULL) {
reply_with_perror ("realloc");
free (vp);
@@ -367,7 +369,7 @@ do_aug_match (const char *path)
matches = vp;
matches[r] = NULL;
- return matches; /* Caller frees. */
+ return matches; /* Caller frees. */
}
int
@@ -411,8 +413,8 @@ do_aug_ls (const char *path)
len = strlen (path);
- if (len > 1 &&
- (path[len-1] == '/' || path[len-1] == ']' || path[len-1] ==
'*')) {
+ if (len > 1 && (path[len - 1] == '/' || path[len - 1] == ']'
||
+ path[len - 1] == '*')) {
reply_with_error ("don't use aug-ls with a path that ends with / ]
*");
return NULL;
}
@@ -422,7 +424,7 @@ do_aug_ls (const char *path)
else {
CLEANUP_FREE char *buf = NULL;
- len += 3; /* / * + terminating \0 */
+ len += 3; /* / * + terminating \0 */
buf = malloc (len);
if (buf == NULL) {
reply_with_perror ("malloc");
@@ -434,10 +436,10 @@ do_aug_ls (const char *path)
}
if (matches == NULL)
- return NULL; /* do_aug_match has already sent the error */
+ return NULL; /* do_aug_match has already sent the error */
- sort_strings (matches, count_strings ((void *) matches));
- return matches; /* Caller frees. */
+ sort_strings (matches, count_strings ((void *)matches));
+ return matches; /* Caller frees. */
}
int
@@ -489,5 +491,5 @@ do_aug_label (const char *augpath)
return NULL;
}
- return ret; /* caller frees */
+ return ret; /* caller frees */
}
diff --git a/daemon/available.c b/daemon/available.c
index 9716796..4e4e26c 100644
--- a/daemon/available.c
+++ b/daemon/available.c
@@ -30,8 +30,8 @@
#include "actions.h"
#include "optgroups.h"
-GUESTFSD_EXT_CMD(str_grep, grep);
-GUESTFSD_EXT_CMD(str_modprobe, modprobe);
+GUESTFSD_EXT_CMD (str_grep, grep);
+GUESTFSD_EXT_CMD (str_modprobe, modprobe);
int
do_internal_feature_available (const char *group)
@@ -63,7 +63,7 @@ do_available_all_groups (void)
if (end_stringsbuf (&groups) == -1)
return NULL;
- return groups.argv; /* caller frees */
+ return groups.argv; /* caller frees */
}
/* Search for filesystem in /proc/filesystems, ignoring "nodev". */
@@ -127,7 +127,8 @@ do_filesystem_available (const char *filesystem)
for (i = 0; i < len; ++i) {
if (!c_isalnum (filesystem[i]) && filesystem[i] != '_') {
- reply_with_error ("filesystem name contains non-alphanumeric
characters");
+ reply_with_error (
+ "filesystem name contains non-alphanumeric characters");
return -1;
}
}
diff --git a/daemon/base64.c b/daemon/base64.c
index 3f7a630..fb34bb5 100644
--- a/daemon/base64.c
+++ b/daemon/base64.c
@@ -30,7 +30,7 @@
#include "daemon.h"
#include "actions.h"
-GUESTFSD_EXT_CMD(str_base64, base64);
+GUESTFSD_EXT_CMD (str_base64, base64);
static int
write_cb (void *fd_ptr, const void *buf, size_t len)
@@ -74,13 +74,13 @@ do_base64_in (const char *file)
fd = fileno (fp);
r = receive_file (write_cb, &fd);
- if (r == -1) { /* write error */
+ if (r == -1) { /* write error */
cancel_receive ();
reply_with_error ("write error on file: %s", file);
pclose (fp);
return -1;
}
- if (r == -2) { /* cancellation from library */
+ if (r == -2) { /* cancellation from library */
/* This error is ignored by the library since it initiated the
* cancel. Nevertheless we must send an error reply here.
*/
@@ -161,18 +161,18 @@ do_base64_out (const char *file)
if (ferror (fp)) {
fprintf (stderr, "fread: %s: %m\n", file);
- send_file_end (1); /* Cancel. */
+ send_file_end (1); /* Cancel. */
pclose (fp);
return -1;
}
if (pclose (fp) != 0) {
fprintf (stderr, "pclose: %s: %m\n", file);
- send_file_end (1); /* Cancel. */
+ send_file_end (1); /* Cancel. */
return -1;
}
- if (send_file_end (0)) /* Normal end of file. */
+ if (send_file_end (0)) /* Normal end of file. */
return -1;
return 0;
diff --git a/daemon/blkdiscard.c b/daemon/blkdiscard.c
index 612c97f..5aa7cb7 100644
--- a/daemon/blkdiscard.c
+++ b/daemon/blkdiscard.c
@@ -34,7 +34,8 @@
#include "actions.h"
#include "optgroups.h"
-/*
http://rwmj.wordpress.com/2014/03/11/blkdiscard-blkzeroout-blkdiscardzero...
*/
+/*
http://rwmj.wordpress.com/2014/03/11/blkdiscard-blkzeroout-blkdiscardzero...
+ */
#ifdef BLKDISCARD
@@ -70,9 +71,9 @@ do_blkdiscard (const char *device)
return -1;
range[0] = 0;
- range[1] = (uint64_t) size;
+ range[1] = (uint64_t)size;
- fd = open (device, O_WRONLY|O_CLOEXEC);
+ fd = open (device, O_WRONLY | O_CLOEXEC);
if (fd == -1) {
reply_with_perror ("open: %s", device);
return -1;
@@ -106,7 +107,7 @@ do_blkdiscardzeroes (const char *device)
int fd;
unsigned int arg;
- fd = open (device, O_RDONLY|O_CLOEXEC);
+ fd = open (device, O_RDONLY | O_CLOEXEC);
if (fd == -1) {
reply_with_perror ("open: %s", device);
return -1;
diff --git a/daemon/blkid.c b/daemon/blkid.c
index 99546b4..72510b6 100644
--- a/daemon/blkid.c
+++ b/daemon/blkid.c
@@ -28,7 +28,7 @@
#include "actions.h"
#include "optgroups.h"
-GUESTFSD_EXT_CMD(str_blkid, blkid);
+GUESTFSD_EXT_CMD (str_blkid, blkid);
char *
get_blkid_tag (const char *device, const char *tag)
@@ -38,11 +38,9 @@ get_blkid_tag (const char *device, const char *tag)
int r;
size_t len;
- r = commandr (&out, &err,
- str_blkid,
+ r = commandr (&out, &err, str_blkid,
/* Adding -c option kills all caching, even on RHEL 5. */
- "-c", "/dev/null",
- "-o", "value", "-s", tag, device, NULL);
+ "-c", "/dev/null", "-o", "value",
"-s", tag, device, NULL);
if (r != 0 && r != 2) {
if (r >= 0)
reply_with_error ("%s: %s (blkid returned %d)", device, err, r);
@@ -52,7 +50,7 @@ get_blkid_tag (const char *device, const char *tag)
return NULL;
}
- if (r == 2) { /* means UUID etc not found */
+ if (r == 2) { /* means UUID etc not found */
free (out);
out = strdup ("");
if (out == NULL)
@@ -62,10 +60,10 @@ get_blkid_tag (const char *device, const char *tag)
/* Trim trailing \n if present. */
len = strlen (out);
- if (len > 0 && out[len-1] == '\n')
- out[len-1] = '\0';
+ if (len > 0 && out[len - 1] == '\n')
+ out[len - 1] = '\0';
- return out; /* caller frees */
+ return out; /* caller frees */
}
char *
@@ -109,7 +107,7 @@ test_blkid_p_i_opt (void)
r = commandr (NULL, &err, str_blkid, "-p", "/dev/null", NULL);
if (r == -1) {
- /* This means we couldn't run the blkid command at all. */
+ /* This means we couldn't run the blkid command at all. */
command_failed:
reply_with_error ("could not run 'blkid' command: %s", err);
return -1;
@@ -140,8 +138,8 @@ blkid_with_p_i_opt (const char *device)
CLEANUP_FREE_STRING_LIST char **lines = NULL;
DECLARE_STRINGSBUF (ret);
- r = command (&out, &err, str_blkid, "-c", "/dev/null",
- "-p", "-i", "-o", "export",
device, NULL);
+ r = command (&out, &err, str_blkid, "-c", "/dev/null",
"-p", "-i", "-o",
+ "export", device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
goto error;
@@ -172,26 +170,30 @@ blkid_with_p_i_opt (const char *device)
char *line = lines[i];
/* Skip blank lines (shouldn't happen) */
- if (line[0] == '\0') continue;
+ if (line[0] == '\0')
+ continue;
/* Split the line in 2 at the equals sign */
eq = strchr (line, '=');
if (eq) {
- *eq = '\0'; eq++;
+ *eq = '\0';
+ eq++;
/* Add the key/value pair to the output */
- if (add_string (&ret, line) == -1 ||
- add_string (&ret, eq) == -1) goto error;
- } else {
+ if (add_string (&ret, line) == -1 || add_string (&ret, eq) == -1)
+ goto error;
+ }
+ else {
fprintf (stderr, "blkid: unexpected blkid output ignored: %s", line);
}
}
- if (end_stringsbuf (&ret) == -1) goto error;
+ if (end_stringsbuf (&ret) == -1)
+ goto error;
return ret.argv;
- error:
+error:
if (ret.argv)
free_strings (ret.argv);
@@ -204,28 +206,35 @@ blkid_without_p_i_opt (const char *device)
char *s;
DECLARE_STRINGSBUF (ret);
- if (add_string (&ret, "TYPE") == -1) goto error;
+ if (add_string (&ret, "TYPE") == -1)
+ goto error;
s = get_blkid_tag (device, "TYPE");
- if (s == NULL) goto error;
+ if (s == NULL)
+ goto error;
if (add_string_nodup (&ret, s) == -1)
goto error;
- if (add_string (&ret, "LABEL") == -1) goto error;
+ if (add_string (&ret, "LABEL") == -1)
+ goto error;
s = get_blkid_tag (device, "LABEL");
- if (s == NULL) goto error;
+ if (s == NULL)
+ goto error;
if (add_string_nodup (&ret, s) == -1)
goto error;
- if (add_string (&ret, "UUID") == -1) goto error;
+ if (add_string (&ret, "UUID") == -1)
+ goto error;
s = get_blkid_tag (device, "UUID");
- if (s == NULL) goto error;
+ if (s == NULL)
+ goto error;
if (add_string_nodup (&ret, s) == -1)
goto error;
- if (end_stringsbuf (&ret) == -1) goto error;
+ if (end_stringsbuf (&ret) == -1)
+ goto error;
return ret.argv;
- error:
+error:
if (ret.argv)
free_stringslen (ret.argv, ret.size);
return NULL;
diff --git a/daemon/blockdev.c b/daemon/blockdev.c
index 6e8821d..42162da 100644
--- a/daemon/blockdev.c
+++ b/daemon/blockdev.c
@@ -28,24 +28,19 @@
#include "daemon.h"
#include "actions.h"
-GUESTFSD_EXT_CMD(str_blockdev, blockdev);
+GUESTFSD_EXT_CMD (str_blockdev, blockdev);
/* These functions are all about using the blockdev command, so
* we centralize it in one call.
*/
static int64_t
-call_blockdev (const char *device, const char *switc, int extraarg, int prints)
+call_blockdev (const char *device, const char *switc, int extraarg,
+ int prints)
{
int r;
int64_t rv;
CLEANUP_FREE char *out = NULL, *err = NULL;
- const char *argv[] = {
- str_blockdev,
- switc,
- NULL,
- NULL,
- NULL
- };
+ const char *argv[] = { str_blockdev, switc, NULL, NULL, NULL };
char buf[64];
/* When you call close on any block device, udev kicks off a rule
@@ -66,7 +61,8 @@ call_blockdev (const char *device, const char *switc, int extraarg, int
prints)
snprintf (buf, sizeof buf, "%d", extraarg);
argv[2] = buf;
argv[3] = device;
- } else
+ }
+ else
argv[2] = device;
r = commandv (&out, &err, argv);
@@ -95,37 +91,37 @@ do_blockdev_setra (const char *device, int sectors)
reply_with_error ("readahead sectors must be >= 0");
return -1;
}
- return (int) call_blockdev (device, "--setra", sectors, 0);
+ return (int)call_blockdev (device, "--setra", sectors, 0);
}
int
do_blockdev_setro (const char *device)
{
- return (int) call_blockdev (device, "--setro", -1, 0);
+ return (int)call_blockdev (device, "--setro", -1, 0);
}
int
do_blockdev_setrw (const char *device)
{
- return (int) call_blockdev (device, "--setrw", -1, 0);
+ return (int)call_blockdev (device, "--setrw", -1, 0);
}
int
do_blockdev_getro (const char *device)
{
- return (int) call_blockdev (device, "--getro", -1, 1);
+ return (int)call_blockdev (device, "--getro", -1, 1);
}
int
do_blockdev_getss (const char *device)
{
- return (int) call_blockdev (device, "--getss", -1, 1);
+ return (int)call_blockdev (device, "--getss", -1, 1);
}
int
do_blockdev_getbsz (const char *device)
{
- return (int) call_blockdev (device, "--getbsz", -1, 1);
+ return (int)call_blockdev (device, "--getbsz", -1, 1);
}
int
diff --git a/daemon/btrfs.c b/daemon/btrfs.c
index 2a20cb0..db172b4 100644
--- a/daemon/btrfs.c
+++ b/daemon/btrfs.c
@@ -33,17 +33,16 @@
#include "c-ctype.h"
#include "ignore-value.h"
-GUESTFSD_EXT_CMD(str_btrfs, btrfs);
-GUESTFSD_EXT_CMD(str_btrfstune, btrfstune);
-GUESTFSD_EXT_CMD(str_btrfsck, btrfsck);
-GUESTFSD_EXT_CMD(str_mkfs_btrfs, mkfs.btrfs);
-GUESTFSD_EXT_CMD(str_umount, umount);
-GUESTFSD_EXT_CMD(str_btrfsimage, btrfs-image);
+GUESTFSD_EXT_CMD (str_btrfs, btrfs);
+GUESTFSD_EXT_CMD (str_btrfstune, btrfstune);
+GUESTFSD_EXT_CMD (str_btrfsck, btrfsck);
+GUESTFSD_EXT_CMD (str_mkfs_btrfs, mkfs.btrfs);
+GUESTFSD_EXT_CMD (str_umount, umount);
+GUESTFSD_EXT_CMD (str_btrfsimage, btrfs - image);
-COMPILE_REGEXP (re_btrfs_subvolume_list,
- "ID\\s+(\\d+).*\\s"
- "top level\\s+(\\d+).*\\s"
- "path\\s(.*)",
+COMPILE_REGEXP (re_btrfs_subvolume_list, "ID\\s+(\\d+).*\\s"
+ "top level\\s+(\\d+).*\\s"
+ "path\\s(.*)",
0)
COMPILE_REGEXP (re_btrfs_balance_status, "Balance on '.*' is (.*)", 0)
@@ -51,7 +50,7 @@ int
optgroup_btrfs_available (void)
{
return test_mode ||
- (prog_exists (str_btrfs) && filesystem_available ("btrfs") >
0);
+ (prog_exists (str_btrfs) && filesystem_available ("btrfs")
> 0);
}
char *
@@ -62,8 +61,7 @@ btrfs_get_label (const char *device)
char *out = NULL;
size_t len;
- r = command (&out, &err, str_btrfs, "filesystem", "label",
- device, NULL);
+ r = command (&out, &err, str_btrfs, "filesystem", "label",
device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (out);
@@ -72,8 +70,8 @@ btrfs_get_label (const char *device)
/* Trim trailing \n if present. */
len = strlen (out);
- if (len > 0 && out[len-1] == '\n')
- out[len-1] = '\0';
+ if (len > 0 && out[len - 1] == '\n')
+ out[len - 1] = '\0';
return out;
}
@@ -84,8 +82,8 @@ btrfs_set_label (const char *device, const char *label)
int r;
CLEANUP_FREE char *err = NULL;
- r = command (NULL, &err, str_btrfs, "filesystem", "label",
- device, label, NULL);
+ r = command (NULL, &err, str_btrfs, "filesystem", "label",
device, label,
+ NULL);
if (r == -1) {
reply_with_error ("%s", err);
return -1;
@@ -147,10 +145,9 @@ do_btrfs_filesystem_resize (const char *filesystem, int64_t size)
/* Takes optional arguments, consult optargs_bitmask. */
int
-do_mkfs_btrfs (char *const *devices,
- int64_t allocstart, int64_t bytecount, const char *datatype,
- int leafsize, const char *label, const char *metadata,
- int nodesize, int sectorsize)
+do_mkfs_btrfs (char *const *devices, int64_t allocstart, int64_t bytecount,
+ const char *datatype, int leafsize, const char *label,
+ const char *metadata, int nodesize, int sectorsize)
{
size_t nr_devices = count_strings (devices);
size_t MAX_ARGS = nr_devices + 64;
@@ -295,8 +292,7 @@ do_btrfs_subvolume_snapshot (const char *source, const char *dest, int
ro,
ADD_ARG (argv, i, "snapshot");
/* Optional arguments. */
- if ((optargs_bitmask & GUESTFS_BTRFS_SUBVOLUME_SNAPSHOT_RO_BITMASK) &&
- ro)
+ if ((optargs_bitmask & GUESTFS_BTRFS_SUBVOLUME_SNAPSHOT_RO_BITMASK) && ro)
ADD_ARG (argv, i, "-r");
if (optargs_bitmask & GUESTFS_BTRFS_SUBVOLUME_SNAPSHOT_QGROUPID_BITMASK) {
@@ -374,7 +370,6 @@ do_btrfs_subvolume_create (const char *dest, const char *qgroupid)
ADD_ARG (argv, i, qgroupid);
}
-
ADD_ARG (argv, i, dest_buf);
ADD_ARG (argv, i, NULL);
@@ -396,7 +391,8 @@ mount (const mountable_t *fs)
fs_buf = sysroot_path (fs->device);
if (fs_buf == NULL)
reply_with_perror ("malloc");
- } else {
+ }
+ else {
fs_buf = strdup ("/tmp/btrfs.XXXXXX");
if (fs_buf == NULL) {
reply_with_perror ("strdup");
@@ -477,7 +473,8 @@ do_btrfs_subvolume_list (const mountable_t *fs)
}
lines = split_lines (out);
- if (!lines) return NULL;
+ if (!lines)
+ return NULL;
}
/* Output is:
@@ -528,11 +525,12 @@ do_btrfs_subvolume_list (const mountable_t *fs)
if (pcre_exec (re_btrfs_subvolume_list, NULL, line, strlen (line), 0, 0,
ovector, N_MATCHES * 3) < 0)
#undef N_MATCHES
- {
- unexpected_output:
- reply_with_error ("unexpected output from 'btrfs subvolume list' command:
%s", line);
- goto error;
- }
+ {
+ unexpected_output:
+ reply_with_error (
+ "unexpected output from 'btrfs subvolume list' command: %s",
line);
+ goto error;
+ }
struct guestfs_int_btrfssubvolume *this =
&ret->guestfs_int_btrfssubvolume_list_val[i];
@@ -543,8 +541,8 @@ do_btrfs_subvolume_list (const mountable_t *fs)
#define XSTRTOU64 xstrtoull
#endif
- if (XSTRTOU64 (line + ovector[2], NULL, 10,
- &this->btrfssubvolume_id, NULL) != LONGINT_OK)
+ if (XSTRTOU64 (line + ovector[2], NULL, 10, &this->btrfssubvolume_id,
+ NULL) != LONGINT_OK)
goto unexpected_output;
if (XSTRTOU64 (line + ovector[4], NULL, 10,
&this->btrfssubvolume_top_level_id, NULL) != LONGINT_OK)
@@ -560,10 +558,11 @@ do_btrfs_subvolume_list (const mountable_t *fs)
return ret;
- error:
+error:
if (ret->guestfs_int_btrfssubvolume_list_val) {
for (i = 0; i < nr_subvolumes; ++i)
- free (ret->guestfs_int_btrfssubvolume_list_val[i].btrfssubvolume_path);
+ free (
+ ret->guestfs_int_btrfssubvolume_list_val[i].btrfssubvolume_path);
free (ret->guestfs_int_btrfssubvolume_list_val);
}
free (ret);
@@ -639,7 +638,7 @@ do_btrfs_subvolume_get_default (const mountable_t *fs)
goto error;
}
- error:
+error:
if (fs_buf && umount (fs_buf, fs) != 0)
return -1;
return ret;
@@ -818,7 +817,6 @@ do_btrfs_device_delete (char *const *devices, const char *fs)
return 0;
}
-
#if defined(__GNUC__) && GUESTFS_GCC_VERSION >= 40800 /* gcc >= 4.8.0 */
#pragma GCC diagnostic pop
#endif
@@ -1000,7 +998,8 @@ analyze_line (char *line, char **key, char **value, char delimiter)
} while (*del_pos && c_isspace (*del_pos));
assert (value);
*value = del_pos;
- } else
+ }
+ else
*value = NULL;
return next;
@@ -1041,9 +1040,8 @@ do_btrfs_subvolume_show (const char *subvolume)
* <path> is btrfs root [in btrfs-progs < 4.4]
* <path> is toplevel subvolume
*/
- if (out &&
- (strstr (out, "is btrfs root") != NULL ||
- strstr (out, "is toplevel subvolume") != NULL)) {
+ if (out && (strstr (out, "is btrfs root") != NULL ||
+ strstr (out, "is toplevel subvolume") != NULL)) {
reply_with_error ("%s is btrfs root", subvolume);
return NULL;
}
@@ -1087,7 +1085,8 @@ do_btrfs_subvolume_show (const char *subvolume)
return NULL;
if (add_string (&ret, key) == -1)
return NULL;
- } else {
+ }
+ else {
if (add_string (&ret, key) == -1)
return NULL;
if (add_string (&ret, value) == -1)
@@ -1108,18 +1107,18 @@ do_btrfs_subvolume_show (const char *subvolume)
p = analyze_line (p, &key, &value, ':');
while (key && !value) {
- ss = realloc (ss, ss_len + strlen (key) + 1);
- if (!ss)
- return NULL;
+ ss = realloc (ss, ss_len + strlen (key) + 1);
+ if (!ss)
+ return NULL;
- if (ss_len != 0)
- ss[ss_len++] = ',';
+ if (ss_len != 0)
+ ss[ss_len++] = ',';
- memcpy (ss + ss_len, key, strlen (key));
- ss_len += strlen (key);
- ss[ss_len] = '\0';
+ memcpy (ss + ss_len, key, strlen (key));
+ ss_len += strlen (key);
+ ss[ss_len] = '\0';
- p = analyze_line (p, &key, &value, ':');
+ p = analyze_line (p, &key, &value, ':');
}
if (ss) {
@@ -1127,17 +1126,20 @@ do_btrfs_subvolume_show (const char *subvolume)
free (ss);
return NULL;
}
- } else {
+ }
+ else {
if (add_string (&ret, "") == -1)
return NULL;
}
- } else {
+ }
+ else {
if (add_string (&ret, key ? key : "") == -1)
return NULL;
if (value && !STREQ (value, "-")) {
if (add_string (&ret, value) == -1)
return NULL;
- } else {
+ }
+ else {
if (add_string (&ret, "") == -1)
return NULL;
}
@@ -1181,7 +1183,7 @@ do_btrfs_quota_enable (const mountable_t *fs, int enable)
goto error;
}
- error:
+error:
if (fs_buf && umount (fs_buf, fs) != 0)
return -1;
return r;
@@ -1213,7 +1215,7 @@ do_btrfs_quota_rescan (const mountable_t *fs)
goto error;
}
- error:
+error:
if (fs_buf && umount (fs_buf, fs) != 0)
return -1;
return r;
@@ -1334,7 +1336,8 @@ test_btrfs_qgroup_show_raw_opt (void)
CLEANUP_FREE char *err = NULL;
CLEANUP_FREE char *out = NULL;
- int r = commandr (&out, &err, str_btrfs, "qgroup", "show",
"--help", NULL);
+ int r =
+ commandr (&out, &err, str_btrfs, "qgroup", "show",
"--help", NULL);
if (r == -1) {
reply_with_error ("btrfs qgroup show --help: %s", err);
@@ -1417,14 +1420,15 @@ do_btrfs_qgroup_show (const char *path)
if (sscanf (line, "%m[0-9/] %" SCNu64 " %" SCNu64,
&this->btrfsqgroup_id, &this->btrfsqgroup_rfer,
&this->btrfsqgroup_excl) != 3) {
- reply_with_error ("cannot parse output of qgroup show command: %s",
line);
+ reply_with_error ("cannot parse output of qgroup show command: %s",
+ line);
goto error;
}
}
return ret;
- error:
+error:
if (ret->guestfs_int_btrfsqgroup_list_val) {
for (i = 0; i < nr_qgroups; ++i)
free (ret->guestfs_int_btrfsqgroup_list_val[i].btrfsqgroup_id);
@@ -1689,7 +1693,8 @@ do_btrfs_balance_resume (const char *path)
/* Takes optional arguments, consult optargs_bitmask. */
int
-do_btrfs_filesystem_defragment (const char *path, int flush, const char *compress)
+do_btrfs_filesystem_defragment (const char *path, int flush,
+ const char *compress)
{
const size_t MAX_ARGS = 64;
const char *argv[MAX_ARGS];
@@ -1710,9 +1715,12 @@ do_btrfs_filesystem_defragment (const char *path, int flush, const
char *compres
ADD_ARG (argv, i, "-r");
/* Optional arguments. */
- if ((optargs_bitmask & GUESTFS_BTRFS_FILESYSTEM_DEFRAGMENT_FLUSH_BITMASK)
&& flush)
+ if ((optargs_bitmask &
+ GUESTFS_BTRFS_FILESYSTEM_DEFRAGMENT_FLUSH_BITMASK) &&
+ flush)
ADD_ARG (argv, i, "-f");
- if (optargs_bitmask & GUESTFS_BTRFS_FILESYSTEM_DEFRAGMENT_COMPRESS_BITMASK) {
+ if (optargs_bitmask &
+ GUESTFS_BTRFS_FILESYSTEM_DEFRAGMENT_COMPRESS_BITMASK) {
if (STREQ (compress, "zlib"))
ADD_ARG (argv, i, "-czlib");
else if (STREQ (compress, "lzo"))
@@ -1862,10 +1870,11 @@ do_btrfs_balance_status (const char *path)
return ret;
}
- if (pcre_exec (re_btrfs_balance_status,
- NULL, lines[0], strlen (lines[0]), 0, 0,
- ovector, N_MATCH * 3) < 0) {
- reply_with_error ("unexpected output from 'btrfs balance status'
command: %s", lines[0]);
+ if (pcre_exec (re_btrfs_balance_status, NULL, lines[0], strlen (lines[0]),
+ 0, 0, ovector, N_MATCH * 3) < 0) {
+ reply_with_error (
+ "unexpected output from 'btrfs balance status' command: %s",
+ lines[0]);
goto error;
}
#undef N_MATCH
@@ -1875,26 +1884,31 @@ do_btrfs_balance_status (const char *path)
else if (STREQ (lines[0] + ovector[2], "paused"))
ret->btrfsbalance_status = strdup ("paused");
else {
- reply_with_error ("unexpected output from 'btrfs balance status'
command: %s", lines[0]);
+ reply_with_error (
+ "unexpected output from 'btrfs balance status' command: %s",
+ lines[0]);
goto error;
}
if (nlines < 2) {
- reply_with_error ("truncated output from 'btrfs balance status'
command");
+ reply_with_error (
+ "truncated output from 'btrfs balance status' command");
goto error;
}
if (sscanf (lines[1], "%" SCNu64 " out of about %" SCNu64
- " chunks balanced (%" SCNu64 " considered), %" SCNu64
"%% left",
+ " chunks balanced (%" SCNu64
+ " considered), %" SCNu64 "%% left",
&ret->btrfsbalance_balanced, &ret->btrfsbalance_total,
- &ret->btrfsbalance_considered, &ret->btrfsbalance_left) != 4)
{
+ &ret->btrfsbalance_considered,
+ &ret->btrfsbalance_left) != 4) {
reply_with_perror ("sscanf");
goto error;
}
return ret;
- error:
+error:
free (ret->btrfsbalance_status);
free (ret);
@@ -1934,14 +1948,16 @@ do_btrfs_scrub_status (const char *path)
}
if (verbose)
- fprintf (stderr, "output from 'btrfs scrub status -R %s' is:\n%s",
path, out);
+ fprintf (stderr, "output from 'btrfs scrub status -R %s' is:\n%s",
path,
+ out);
lines = split_lines (out);
if (!lines)
return NULL;
if (count_strings (lines) < 2) {
- reply_with_error ("truncated output from 'btrfs scrub status -R'
command");
+ reply_with_error (
+ "truncated output from 'btrfs scrub status -R' command");
return NULL;
}
@@ -1954,7 +1970,8 @@ do_btrfs_scrub_status (const char *path)
/* Output of `btrfs scrub -R status' is like:
*
* scrub status for 346121d1-1847-40f8-9b7b-2bf3d539c68f
- * scrub started at Mon Feb 2 17:39:38 2015, running for 93 seconds
+ * scrub started at Mon Feb 2 17:39:38 2015, running for 93
+ * seconds
* data_extents_scrubbed: 136670
* tree_extents_scrubbed: 30023
* data_bytes_scrubbed: 4474441728
@@ -1982,63 +1999,64 @@ do_btrfs_scrub_status (const char *path)
else if (STRPREFIX (lines[i], "\tscrub started at"))
continue;
else if (sscanf (lines[i], "\tdata_extents_scrubbed: %" SCNu64,
- &ret->btrfsscrub_data_extents_scrubbed) == 1)
+ &ret->btrfsscrub_data_extents_scrubbed) == 1)
continue;
else if (sscanf (lines[i], "\ttree_extents_scrubbed: %" SCNu64,
- &ret->btrfsscrub_tree_extents_scrubbed) == 1)
+ &ret->btrfsscrub_tree_extents_scrubbed) == 1)
continue;
else if (sscanf (lines[i], "\tdata_bytes_scrubbed: %" SCNu64,
- &ret->btrfsscrub_data_bytes_scrubbed) == 1)
+ &ret->btrfsscrub_data_bytes_scrubbed) == 1)
continue;
else if (sscanf (lines[i], "\ttree_bytes_scrubbed: %" SCNu64,
- &ret->btrfsscrub_tree_bytes_scrubbed) == 1)
+ &ret->btrfsscrub_tree_bytes_scrubbed) == 1)
continue;
else if (sscanf (lines[i], "\tread_errors: %" SCNu64,
- &ret->btrfsscrub_read_errors) == 1)
+ &ret->btrfsscrub_read_errors) == 1)
continue;
else if (sscanf (lines[i], "\tcsum_errors: %" SCNu64,
- &ret->btrfsscrub_csum_errors) == 1)
+ &ret->btrfsscrub_csum_errors) == 1)
continue;
else if (sscanf (lines[i], "\tverify_errors: %" SCNu64,
- &ret->btrfsscrub_verify_errors) == 1)
+ &ret->btrfsscrub_verify_errors) == 1)
continue;
else if (sscanf (lines[i], "\tno_csum: %" SCNu64,
- &ret->btrfsscrub_no_csum) == 1)
+ &ret->btrfsscrub_no_csum) == 1)
continue;
else if (sscanf (lines[i], "\tcsum_discards: %" SCNu64,
- &ret->btrfsscrub_csum_discards) == 1)
+ &ret->btrfsscrub_csum_discards) == 1)
continue;
else if (sscanf (lines[i], "\tsuper_errors: %" SCNu64,
- &ret->btrfsscrub_super_errors) == 1)
+ &ret->btrfsscrub_super_errors) == 1)
continue;
else if (sscanf (lines[i], "\tmalloc_errors: %" SCNu64,
- &ret->btrfsscrub_malloc_errors) == 1)
+ &ret->btrfsscrub_malloc_errors) == 1)
continue;
else if (sscanf (lines[i], "\tuncorrectable_errors: %" SCNu64,
- &ret->btrfsscrub_uncorrectable_errors) == 1)
+ &ret->btrfsscrub_uncorrectable_errors) == 1)
continue;
else if (sscanf (lines[i], "\tunverified_errors: %" SCNu64,
- &ret->btrfsscrub_unverified_errors) == 1)
+ &ret->btrfsscrub_unverified_errors) == 1)
continue;
else if (sscanf (lines[i], "\tcorrected_errors: %" SCNu64,
- &ret->btrfsscrub_corrected_errors) == 1)
+ &ret->btrfsscrub_corrected_errors) == 1)
continue;
else if (sscanf (lines[i], "\tlast_physical: %" SCNu64,
- &ret->btrfsscrub_last_physical) == 1)
+ &ret->btrfsscrub_last_physical) == 1)
continue;
else
goto error;
}
if (i < 17) {
- reply_with_error ("truncated output from 'btrfs scrub status -R'
command");
+ reply_with_error (
+ "truncated output from 'btrfs scrub status -R' command");
free (ret);
return NULL;
}
return ret;
- error:
+error:
reply_with_error ("%s: could not parse btrfs scrub status.", lines[i]);
free (ret);
return NULL;
@@ -2123,10 +2141,9 @@ do_btrfstune_enable_skinny_metadata_extent_refs (const char
*device)
#endif
int
-do_btrfs_image (char *const *sources, const char *image,
- int compresslevel)
+do_btrfs_image (char *const *sources, const char *image, int compresslevel)
{
- size_t nr_sources = count_strings (sources);
+ size_t nr_sources = count_strings (sources);
const size_t MAX_ARGS = 64 + nr_sources;
const char *argv[MAX_ARGS];
size_t i = 0, j;
@@ -2141,8 +2158,8 @@ do_btrfs_image (char *const *sources, const char *image,
ADD_ARG (argv, i, str_btrfsimage);
- if ((optargs_bitmask & GUESTFS_BTRFS_IMAGE_COMPRESSLEVEL_BITMASK)
- && compresslevel >= 0) {
+ if ((optargs_bitmask & GUESTFS_BTRFS_IMAGE_COMPRESSLEVEL_BITMASK) &&
+ compresslevel >= 0) {
snprintf (compresslevel_s, sizeof compresslevel_s, "%d", compresslevel);
ADD_ARG (argv, i, "-c");
ADD_ARG (argv, i, compresslevel_s);
@@ -2169,7 +2186,7 @@ do_btrfs_image (char *const *sources, const char *image,
int
do_btrfs_replace (const char *srcdev, const char *targetdev,
- const char* mntpoint)
+ const char *mntpoint)
{
const size_t MAX_ARGS = 64;
const char *argv[MAX_ARGS];
@@ -2256,8 +2273,8 @@ btrfs_minimum_size (const char *path)
return -1;
}
- r = command (&out, &err, str_btrfs, "inspect-internal",
- "min-dev-size", buf, NULL);
+ r = command (&out, &err, str_btrfs, "inspect-internal",
"min-dev-size",
+ buf, NULL);
if (r == -1) {
reply_with_error ("%s", err);
diff --git a/daemon/cap.c b/daemon/cap.c
index 1d732c5..2765992 100644
--- a/daemon/cap.c
+++ b/daemon/cap.c
@@ -86,7 +86,7 @@ do_cap_get_file (const char *path)
}
cap_free (r);
- return ret; /* caller frees */
+ return ret; /* caller frees */
}
int
@@ -97,7 +97,8 @@ do_cap_set_file (const char *path, const char *capstr)
cap = cap_from_text (capstr);
if (cap == NULL) {
- reply_with_perror ("could not parse cap string: %s: cap_from_text",
capstr);
+ reply_with_perror ("could not parse cap string: %s: cap_from_text",
+ capstr);
return -1;
}
diff --git a/daemon/checksum.c b/daemon/checksum.c
index 3045948..2ded039 100644
--- a/daemon/checksum.c
+++ b/daemon/checksum.c
@@ -29,15 +29,15 @@
#include "daemon.h"
#include "actions.h"
-GUESTFSD_EXT_CMD(str_find, find);
-GUESTFSD_EXT_CMD(str_xargs, xargs);
-GUESTFSD_EXT_CMD(str_cksum, cksum);
-GUESTFSD_EXT_CMD(str_md5sum, md5sum);
-GUESTFSD_EXT_CMD(str_sha1sum, sha1sum);
-GUESTFSD_EXT_CMD(str_sha224sum, sha224sum);
-GUESTFSD_EXT_CMD(str_sha256sum, sha256sum);
-GUESTFSD_EXT_CMD(str_sha384sum, sha384sum);
-GUESTFSD_EXT_CMD(str_sha512sum, sha512sum);
+GUESTFSD_EXT_CMD (str_find, find);
+GUESTFSD_EXT_CMD (str_xargs, xargs);
+GUESTFSD_EXT_CMD (str_cksum, cksum);
+GUESTFSD_EXT_CMD (str_md5sum, md5sum);
+GUESTFSD_EXT_CMD (str_sha1sum, sha1sum);
+GUESTFSD_EXT_CMD (str_sha224sum, sha224sum);
+GUESTFSD_EXT_CMD (str_sha256sum, sha256sum);
+GUESTFSD_EXT_CMD (str_sha384sum, sha384sum);
+GUESTFSD_EXT_CMD (str_sha512sum, sha512sum);
static const char *
program_of_csum (const char *csumtype)
@@ -57,7 +57,8 @@ program_of_csum (const char *csumtype)
else if (STRCASEEQ (csumtype, "sha512"))
return str_sha512sum;
else {
- reply_with_error ("unknown checksum type, expecting
crc|md5|sha1|sha224|sha256|sha384|sha512");
+ reply_with_error ("unknown checksum type, expecting "
+ "crc|md5|sha1|sha224|sha256|sha384|sha512");
return NULL;
}
}
@@ -92,7 +93,7 @@ checksum (const char *csumtype, int fd)
pulse_mode_end ();
- return out; /* Caller frees. */
+ return out; /* Caller frees. */
}
char *
@@ -101,7 +102,7 @@ do_checksum (const char *csumtype, const char *path)
CLEANUP_CLOSE int fd = -1;
CHROOT_IN;
- fd = open (path, O_RDONLY|O_CLOEXEC);
+ fd = open (path, O_RDONLY | O_CLOEXEC);
CHROOT_OUT;
if (fd == -1) {
@@ -117,7 +118,7 @@ do_checksum_device (const char *csumtype, const char *device)
{
CLEANUP_CLOSE int fd = -1;
- fd = open (device, O_RDONLY|O_CLOEXEC);
+ fd = open (device, O_RDONLY | O_CLOEXEC);
if (fd == -1) {
reply_with_perror ("%s", device);
return NULL;
@@ -195,18 +196,18 @@ do_checksums_out (const char *csumtype, const char *dir)
if (ferror (fp)) {
fprintf (stderr, "fread: %s: %m\n", dir);
- send_file_end (1); /* Cancel. */
+ send_file_end (1); /* Cancel. */
pclose (fp);
return -1;
}
if (pclose (fp) != 0) {
fprintf (stderr, "pclose: %s: %m\n", dir);
- send_file_end (1); /* Cancel. */
+ send_file_end (1); /* Cancel. */
return -1;
}
- if (send_file_end (0)) /* Normal end of file. */
+ if (send_file_end (0)) /* Normal end of file. */
return -1;
return 0;
diff --git a/daemon/cleanups.c b/daemon/cleanups.c
index 5293ff2..5112456 100644
--- a/daemon/cleanups.c
+++ b/daemon/cleanups.c
@@ -30,7 +30,7 @@
void
cleanup_free (void *ptr)
{
- free (* (void **) ptr);
+ free (*(void **)ptr);
}
extern void free_strings (char **argv);
@@ -38,13 +38,13 @@ extern void free_strings (char **argv);
void
cleanup_free_string_list (void *ptr)
{
- free_strings (* (char ***) ptr);
+ free_strings (*(char ***)ptr);
}
void
cleanup_unlink_free (void *ptr)
{
- char *filename = * (char **) ptr;
+ char *filename = *(char **)ptr;
if (filename) {
unlink (filename);
@@ -55,7 +55,7 @@ cleanup_unlink_free (void *ptr)
void
cleanup_close (void *ptr)
{
- int fd = * (int *) ptr;
+ int fd = *(int *)ptr;
if (fd >= 0)
close (fd);
@@ -64,7 +64,7 @@ cleanup_close (void *ptr)
void
cleanup_aug_close (void *ptr)
{
- augeas *aug = * (augeas **) ptr;
+ augeas *aug = *(augeas **)ptr;
if (aug != NULL)
aug_close (aug);
@@ -76,5 +76,5 @@ extern void free_stringsbuf (struct stringsbuf *sb);
void
cleanup_free_stringsbuf (void *ptr)
{
- free_stringsbuf ((struct stringsbuf *) ptr);
+ free_stringsbuf ((struct stringsbuf *)ptr);
}
diff --git a/daemon/cleanups.h b/daemon/cleanups.h
index 6746e27..2d95188 100644
--- a/daemon/cleanups.h
+++ b/daemon/cleanups.h
@@ -30,13 +30,14 @@ extern void cleanup_aug_close (void *ptr);
extern void cleanup_free_stringsbuf (void *ptr);
#ifdef HAVE_ATTRIBUTE_CLEANUP
-#define CLEANUP_FREE __attribute__((cleanup(cleanup_free)))
-#define CLEANUP_FREE_STRING_LIST \
- __attribute__((cleanup(cleanup_free_string_list)))
-#define CLEANUP_UNLINK_FREE __attribute__((cleanup(cleanup_unlink_free)))
-#define CLEANUP_CLOSE __attribute__((cleanup(cleanup_close)))
-#define CLEANUP_AUG_CLOSE __attribute__((cleanup(cleanup_aug_close)))
-#define CLEANUP_FREE_STRINGSBUF __attribute__((cleanup(cleanup_free_stringsbuf)))
+#define CLEANUP_FREE __attribute__((cleanup (cleanup_free)))
+#define CLEANUP_FREE_STRING_LIST \
+ __attribute__ ((cleanup (cleanup_free_string_list)))
+#define CLEANUP_UNLINK_FREE __attribute__((cleanup (cleanup_unlink_free)))
+#define CLEANUP_CLOSE __attribute__ ((cleanup (cleanup_close)))
+#define CLEANUP_AUG_CLOSE __attribute__ ((cleanup (cleanup_aug_close)))
+#define CLEANUP_FREE_STRINGSBUF \
+ __attribute__ ((cleanup (cleanup_free_stringsbuf)))
#else
#define CLEANUP_FREE
#define CLEANUP_FREE_STRING_LIST
diff --git a/daemon/cmp.c b/daemon/cmp.c
index 61506b6..ab61c00 100644
--- a/daemon/cmp.c
+++ b/daemon/cmp.c
@@ -27,7 +27,7 @@
#include "daemon.h"
#include "actions.h"
-GUESTFSD_EXT_CMD(str_cmp, cmp);
+GUESTFSD_EXT_CMD (str_cmp, cmp);
int
do_equal (const char *file1, const char *file2)
diff --git a/daemon/command.c b/daemon/command.c
index 2423a4e..c34b255 100644
--- a/daemon/command.c
+++ b/daemon/command.c
@@ -41,7 +41,7 @@ extern const char *sysroot;
extern size_t sysroot_len;
/* For improved readability dealing with pipe arrays */
-#define PIPE_READ 0
+#define PIPE_READ 0
#define PIPE_WRITE 1
/* Easy ways to run external commands. For full documentation, see
@@ -65,7 +65,7 @@ commandf (char **stdoutput, char **stderror, unsigned flags,
perror ("malloc");
return -1;
}
- argv[0] = (char *) name;
+ argv[0] = (char *)name;
argv[1] = NULL;
va_start (args, name);
@@ -78,13 +78,13 @@ commandf (char **stdoutput, char **stderror, unsigned flags,
return -1;
}
argv = p;
- argv[i-2] = s;
- argv[i-1] = NULL;
+ argv[i - 2] = s;
+ argv[i - 1] = NULL;
}
va_end (args);
- r = commandvf (stdoutput, stderror, flags, (const char * const*) argv);
+ r = commandvf (stdoutput, stderror, flags, (const char *const *)argv);
return r;
}
@@ -109,7 +109,7 @@ commandrf (char **stdoutput, char **stderror, unsigned flags,
perror ("malloc");
return -1;
}
- argv[0] = (char *) name;
+ argv[0] = (char *)name;
argv[1] = NULL;
va_start (args, name);
@@ -122,8 +122,8 @@ commandrf (char **stdoutput, char **stderror, unsigned flags,
return -1;
}
argv = p;
- argv[i-2] = s;
- argv[i-1] = NULL;
+ argv[i - 2] = s;
+ argv[i - 1] = NULL;
}
va_end (args);
@@ -140,7 +140,7 @@ commandvf (char **stdoutput, char **stderror, unsigned flags,
{
int r;
- r = commandrvf (stdoutput, stderror, flags, (void *) argv);
+ r = commandrvf (stdoutput, stderror, flags, (void *)argv);
if (r == 0)
return 0;
else
@@ -179,12 +179,12 @@ commandvf (char **stdoutput, char **stderror, unsigned flags,
*/
int
commandrvf (char **stdoutput, char **stderror, unsigned flags,
- char const* const *argv)
+ char const *const *argv)
{
size_t so_size = 0, se_size = 0;
int so_fd[2], se_fd[2];
unsigned flag_copy_stdin = flags & COMMAND_FLAG_CHROOT_COPY_FILE_TO_STDIN;
- int flag_copy_fd = (int) (flags & COMMAND_FLAG_FD_MASK);
+ int flag_copy_fd = (int)(flags & COMMAND_FLAG_FD_MASK);
unsigned flag_out_on_err = flags & COMMAND_FLAG_FOLD_STDOUT_ON_STDERR;
pid_t pid;
int r, quit, i;
@@ -192,8 +192,10 @@ commandrvf (char **stdoutput, char **stderror, unsigned flags,
char buf[256];
char *p;
- if (stdoutput) *stdoutput = NULL;
- if (stderror) *stderror = NULL;
+ if (stdoutput)
+ *stdoutput = NULL;
+ if (stderror)
+ *stderror = NULL;
if (verbose) {
printf ("commandrvf: stdout=%s stderr=%s flags=0x%x\n",
@@ -218,9 +220,11 @@ commandrvf (char **stdoutput, char **stderror, unsigned flags,
quote = 0;
putchar (' ');
- if (quote) putchar (quote);
+ if (quote)
+ putchar (quote);
fputs (argv[i], stdout);
- if (quote) putchar (quote);
+ if (quote)
+ putchar (quote);
}
putchar ('\n');
}
@@ -245,7 +249,7 @@ commandrvf (char **stdoutput, char **stderror, unsigned flags,
abort ();
}
- if (pid == 0) { /* Child process running the command. */
+ if (pid == 0) { /* Child process running the command. */
signal (SIGALRM, SIG_DFL);
signal (SIGPIPE, SIG_DFL);
close (0);
@@ -254,7 +258,8 @@ commandrvf (char **stdoutput, char **stderror, unsigned flags,
perror ("dup2/flag_copy_fd");
_exit (EXIT_FAILURE);
}
- } else {
+ }
+ else {
/* Set stdin to /dev/null. */
if (open ("/dev/null", O_RDONLY) == -1) {
perror ("open: /dev/null");
@@ -268,7 +273,8 @@ commandrvf (char **stdoutput, char **stderror, unsigned flags,
perror ("dup2/so_fd[PIPE_WRITE]");
_exit (EXIT_FAILURE);
}
- } else {
+ }
+ else {
if (dup2 (se_fd[PIPE_WRITE], STDOUT_FILENO) == -1) {
perror ("dup2/se_fd[PIPE_WRITE]");
_exit (EXIT_FAILURE);
@@ -293,7 +299,7 @@ commandrvf (char **stdoutput, char **stderror, unsigned flags,
_exit (EXIT_FAILURE);
}
- execvp (argv[0], (void *) argv);
+ execvp (argv[0], (void *)argv);
perror (argv[0]);
_exit (EXIT_FAILURE);
}
@@ -310,8 +316,8 @@ commandrvf (char **stdoutput, char **stderror, unsigned flags,
while (quit < 2) {
again:
rset2 = rset;
- r = select (MAX (so_fd[PIPE_READ], se_fd[PIPE_READ]) + 1, &rset2,
- NULL, NULL, NULL);
+ r = select (MAX (so_fd[PIPE_READ], se_fd[PIPE_READ]) + 1, &rset2, NULL,
+ NULL, NULL);
if (r == -1) {
if (errno == EINTR)
goto again;
@@ -334,7 +340,8 @@ commandrvf (char **stdoutput, char **stderror, unsigned flags,
}
close (so_fd[PIPE_READ]);
close (se_fd[PIPE_READ]);
- if (flag_copy_stdin) close (flag_copy_fd);
+ if (flag_copy_stdin)
+ close (flag_copy_fd);
waitpid (pid, NULL, 0);
return -1;
}
@@ -345,7 +352,10 @@ commandrvf (char **stdoutput, char **stderror, unsigned flags,
perror ("read");
goto quit;
}
- if (r == 0) { FD_CLR (so_fd[PIPE_READ], &rset); quit++; }
+ if (r == 0) {
+ FD_CLR (so_fd[PIPE_READ], &rset);
+ quit++;
+ }
if (r > 0 && stdoutput) {
so_size += r;
@@ -365,7 +375,10 @@ commandrvf (char **stdoutput, char **stderror, unsigned flags,
perror ("read");
goto quit;
}
- if (r == 0) { FD_CLR (se_fd[PIPE_READ], &rset); quit++; }
+ if (r == 0) {
+ FD_CLR (se_fd[PIPE_READ], &rset);
+ quit++;
+ }
if (r > 0) {
if (verbose)
@@ -392,7 +405,7 @@ commandrvf (char **stdoutput, char **stderror, unsigned flags,
* trailing \n characters from the error buffer (not from stdout).
*/
if (stdoutput) {
- void *q = realloc (*stdoutput, so_size+1);
+ void *q = realloc (*stdoutput, so_size + 1);
if (q == NULL) {
perror ("realloc");
free (*stdoutput);
@@ -402,7 +415,7 @@ commandrvf (char **stdoutput, char **stderror, unsigned flags,
(*stdoutput)[so_size] = '\0';
}
if (stderror) {
- void *q = realloc (*stderror, se_size+1);
+ void *q = realloc (*stderror, se_size + 1);
if (q == NULL) {
perror ("realloc");
free (*stderror);
@@ -410,7 +423,7 @@ commandrvf (char **stdoutput, char **stderror, unsigned flags,
*stderror = q;
if (*stderror) {
(*stderror)[se_size] = '\0';
- while (se_size > 0 && (*stderror)[se_size-1] == '\n') {
+ while (se_size > 0 && (*stderror)[se_size - 1] == '\n') {
se_size--;
(*stderror)[se_size] = '\0';
}
@@ -430,6 +443,7 @@ commandrvf (char **stdoutput, char **stderror, unsigned flags,
if (WIFEXITED (r)) {
return WEXITSTATUS (r);
- } else
+ }
+ else
return -1;
}
diff --git a/daemon/command.h b/daemon/command.h
index 60f32b8..9d439b8 100644
--- a/daemon/command.h
+++ b/daemon/command.h
@@ -19,10 +19,12 @@
#ifndef GUESTFSD_COMMAND_H
#define GUESTFSD_COMMAND_H
-#define command(out,err,name,...) commandf((out),(err),0,(name),__VA_ARGS__)
-#define commandr(out,err,name,...) commandrf((out),(err),0,(name),__VA_ARGS__)
-#define commandv(out,err,argv) commandvf((out),(err),0,(argv))
-#define commandrv(out,err,argv) commandrvf((out),(err),0,(argv))
+#define command(out, err, name, ...) \
+ commandf ((out), (err), 0, (name), __VA_ARGS__)
+#define commandr(out, err, name, ...) \
+ commandrf ((out), (err), 0, (name), __VA_ARGS__)
+#define commandv(out, err, argv) commandvf ((out), (err), 0, (argv))
+#define commandrv(out, err, argv) commandrvf ((out), (err), 0, (argv))
#define COMMAND_FLAG_FD_MASK 0x0000ffff
#define COMMAND_FLAG_FOLD_STDOUT_ON_STDERR 0x00010000
@@ -36,6 +38,6 @@ extern int commandrf (char **stdoutput, char **stderror, unsigned
flags,
extern int commandvf (char **stdoutput, char **stderror, unsigned flags,
char const *const *argv);
extern int commandrvf (char **stdoutput, char **stderror, unsigned flags,
- char const* const *argv);
+ char const *const *argv);
#endif /* GUESTFSD_COMMAND_H */
diff --git a/daemon/compress.c b/daemon/compress.c
index 36f4e66..d2d62ed 100644
--- a/daemon/compress.c
+++ b/daemon/compress.c
@@ -27,11 +27,11 @@
#include "daemon.h"
#include "actions.h"
-GUESTFSD_EXT_CMD(str_compress, compress);
-GUESTFSD_EXT_CMD(str_gzip, gzip);
-GUESTFSD_EXT_CMD(str_bzip2, bzip2);
-GUESTFSD_EXT_CMD(str_xz, xz);
-GUESTFSD_EXT_CMD(str_lzop, lzop);
+GUESTFSD_EXT_CMD (str_compress, compress);
+GUESTFSD_EXT_CMD (str_gzip, gzip);
+GUESTFSD_EXT_CMD (str_bzip2, bzip2);
+GUESTFSD_EXT_CMD (str_xz, xz);
+GUESTFSD_EXT_CMD (str_lzop, lzop);
/* Has one FileOut parameter. */
static int
@@ -64,7 +64,8 @@ do_compressX_out (const char *file, const char *filter, int is_device)
reply_with_perror ("asprintf");
return -1;
}
- } else {
+ }
+ else {
if (asprintf_nowarn (&cmd, "%s < %Q", filter, file) == -1) {
reply_with_perror ("asprintf");
return -1;
@@ -95,18 +96,18 @@ do_compressX_out (const char *file, const char *filter, int
is_device)
if (ferror (fp)) {
fprintf (stderr, "fread: %s: %m\n", file);
- send_file_end (1); /* Cancel. */
+ send_file_end (1); /* Cancel. */
pclose (fp);
return -1;
}
if (pclose (fp) != 0) {
fprintf (stderr, "pclose: %s: %m\n", file);
- send_file_end (1); /* Cancel. */
+ send_file_end (1); /* Cancel. */
return -1;
}
- if (send_file_end (0)) /* Normal end of file. */
+ if (send_file_end (0)) /* Normal end of file. */
return -1;
return 0;
@@ -115,7 +116,10 @@ do_compressX_out (const char *file, const char *filter, int
is_device)
#define CHECK_SUPPORTED(prog) \
if (!prog_exists (prog)) \
/* note: substring "not supported" must appear in this error */ \
- NOT_SUPPORTED (-1, "compression type %s is not supported, because external
program '%s' is not available in the appliance", prog, prog);
+ NOT_SUPPORTED (-1, "compression type %s is not supported, because " \
+ "external program '%s' is not available in the "
\
+ "appliance", \
+ prog, prog);
static int
get_filter (const char *ctype, int level, char *ret, size_t n)
@@ -123,7 +127,8 @@ get_filter (const char *ctype, int level, char *ret, size_t n)
if (STREQ (ctype, "compress")) {
CHECK_SUPPORTED ("compress");
if (level != -1) {
- reply_with_error ("compress: cannot use optional level parameter with this
compression type");
+ reply_with_error ("compress: cannot use optional level parameter "
+ "with this compression type");
return -1;
}
snprintf (ret, n, "%s -c", str_compress);
diff --git a/daemon/copy.c b/daemon/copy.c
index 2a6720b..9f1ed9b 100644
--- a/daemon/copy.c
+++ b/daemon/copy.c
@@ -30,7 +30,7 @@
#include "actions.h"
/* wrflags */
-#define DEST_DEVICE_FLAGS O_WRONLY|O_CLOEXEC, 0
+#define DEST_DEVICE_FLAGS O_WRONLY | O_CLOEXEC, 0
/* flags */
#define COPY_UNLINK_DEST_ON_FAILURE 1
@@ -42,10 +42,8 @@
/* Takes optional arguments, consult optargs_bitmask. */
static int
-copy (const char *src, const char *src_display,
- const char *dest, const char *dest_display,
- int wrflags, int wrmode,
- int flags,
+copy (const char *src, const char *src_display, const char *dest,
+ const char *dest_display, int wrflags, int wrmode, int flags,
int64_t srcoffset, int64_t destoffset, int64_t size, int sparse)
{
int64_t saved_size = size;
@@ -70,7 +68,8 @@ copy (const char *src, const char *src_display,
else
srcoffset = 0;
- if ((optargs_bitmask & GUESTFS_COPY_DEVICE_TO_DEVICE_DESTOFFSET_BITMASK)) {
+ if ((optargs_bitmask &
+ GUESTFS_COPY_DEVICE_TO_DEVICE_DESTOFFSET_BITMASK)) {
if (destoffset < 0) {
reply_with_error ("destoffset is negative");
return -1;
@@ -88,17 +87,17 @@ copy (const char *src, const char *src_display,
else
size = -1;
- if (! (optargs_bitmask & GUESTFS_COPY_DEVICE_TO_DEVICE_SPARSE_BITMASK))
+ if (!(optargs_bitmask & GUESTFS_COPY_DEVICE_TO_DEVICE_SPARSE_BITMASK))
sparse = 0;
/* Open source and destination. */
- src_fd = open (src, O_RDONLY|O_CLOEXEC);
+ src_fd = open (src, O_RDONLY | O_CLOEXEC);
if (src_fd == -1) {
reply_with_perror ("%s", src_display);
return -1;
}
- if (srcoffset > 0 && lseek (src_fd, srcoffset, SEEK_SET) == (off_t) -1) {
+ if (srcoffset > 0 && lseek (src_fd, srcoffset, SEEK_SET) == (off_t)-1) {
reply_with_perror ("lseek: %s", src_display);
close (src_fd);
return -1;
@@ -111,7 +110,8 @@ copy (const char *src, const char *src_display,
return -1;
}
- if (destoffset > 0 && lseek (dest_fd, destoffset, SEEK_SET) == (off_t) -1)
{
+ if (destoffset > 0 &&
+ lseek (dest_fd, destoffset, SEEK_SET) == (off_t)-1) {
reply_with_perror ("lseek: %s", dest_display);
close (src_fd);
close (dest_fd);
@@ -161,7 +161,8 @@ copy (const char *src, const char *src_display,
if (size == -1)
pulse_mode_cancel ();
errno = err;
- reply_with_perror ("%s: seek (because of sparse flag)", dest_display);
+ reply_with_perror ("%s: seek (because of sparse flag)",
+ dest_display);
close (src_fd);
close (dest_fd);
if (flags & COPY_UNLINK_DEST_ON_FAILURE)
@@ -187,7 +188,8 @@ copy (const char *src, const char *src_display,
if (size != -1) {
size -= r;
- notify_progress ((uint64_t) (saved_size - size), (uint64_t) saved_size);
+ notify_progress ((uint64_t) (saved_size - size),
+ (uint64_t)saved_size);
}
}
@@ -214,16 +216,16 @@ copy (const char *src, const char *src_display,
int
do_copy_device_to_device (const char *src, const char *dest,
- int64_t srcoffset, int64_t destoffset, int64_t size,
- int sparse, int append)
+ int64_t srcoffset, int64_t destoffset,
+ int64_t size, int sparse, int append)
{
if ((optargs_bitmask & GUESTFS_COPY_DEVICE_TO_DEVICE_APPEND_BITMASK) &&
append) {
reply_with_error ("the append flag cannot be set for this call");
return -1;
}
- return copy (src, src, dest, dest, DEST_DEVICE_FLAGS, 0,
- srcoffset, destoffset, size, sparse);
+ return copy (src, src, dest, dest, DEST_DEVICE_FLAGS, 0, srcoffset,
+ destoffset, size, sparse);
}
int
@@ -232,7 +234,7 @@ do_copy_device_to_file (const char *src, const char *dest,
int sparse, int append)
{
CLEANUP_FREE char *dest_buf = sysroot_path (dest);
- int wrflags = O_WRONLY|O_CREAT|O_NOCTTY|O_CLOEXEC;
+ int wrflags = O_WRONLY | O_CREAT | O_NOCTTY | O_CLOEXEC;
if (!dest_buf) {
reply_with_perror ("malloc");
@@ -245,8 +247,8 @@ do_copy_device_to_file (const char *src, const char *dest,
else
wrflags |= O_TRUNC;
- return copy (src, src, dest_buf, dest, wrflags, 0666, 0,
- srcoffset, destoffset, size, sparse);
+ return copy (src, src, dest_buf, dest, wrflags, 0666, 0, srcoffset,
+ destoffset, size, sparse);
}
int
@@ -267,17 +269,17 @@ do_copy_file_to_device (const char *src, const char *dest,
return -1;
}
- return copy (src_buf, src, dest, dest, DEST_DEVICE_FLAGS, 0,
- srcoffset, destoffset, size, sparse);
+ return copy (src_buf, src, dest, dest, DEST_DEVICE_FLAGS, 0, srcoffset,
+ destoffset, size, sparse);
}
int
-do_copy_file_to_file (const char *src, const char *dest,
- int64_t srcoffset, int64_t destoffset, int64_t size,
- int sparse, int append)
+do_copy_file_to_file (const char *src, const char *dest, int64_t srcoffset,
+ int64_t destoffset, int64_t size, int sparse,
+ int append)
{
CLEANUP_FREE char *src_buf = NULL, *dest_buf = NULL;
- int wrflags = O_WRONLY|O_CREAT|O_NOCTTY|O_CLOEXEC;
+ int wrflags = O_WRONLY | O_CREAT | O_NOCTTY | O_CLOEXEC;
src_buf = sysroot_path (src);
if (!src_buf) {
@@ -298,6 +300,6 @@ do_copy_file_to_file (const char *src, const char *dest,
wrflags |= O_TRUNC;
return copy (src_buf, src, dest_buf, dest, wrflags, 0666,
- COPY_UNLINK_DEST_ON_FAILURE,
- srcoffset, destoffset, size, sparse);
+ COPY_UNLINK_DEST_ON_FAILURE, srcoffset, destoffset, size,
+ sparse);
}
diff --git a/daemon/cpio.c b/daemon/cpio.c
index d1459b1..1b03bea 100644
--- a/daemon/cpio.c
+++ b/daemon/cpio.c
@@ -33,7 +33,7 @@
#include "actions.h"
#include "optgroups.h"
-GUESTFSD_EXT_CMD(str_cpio, cpio);
+GUESTFSD_EXT_CMD (str_cpio, cpio);
/* Has one FileOut parameter. */
/* Takes optional arguments, consult optargs_bitmask. */
@@ -65,7 +65,7 @@ do_cpio_out (const char *dir, const char *format)
return -1;
}
- if (! S_ISDIR (statbuf.st_mode)) {
+ if (!S_ISDIR (statbuf.st_mode)) {
reply_with_error ("%s: not a directory", dir);
return -1;
}
@@ -80,10 +80,9 @@ do_cpio_out (const char *dir, const char *format)
else
format = "newc";
- if (asprintf_nowarn (&cmd, "cd %Q && find -print0 | %s -0 -o -H %s
--quiet",
- buf,
- str_cpio,
- format) == -1) {
+ if (asprintf_nowarn (&cmd,
+ "cd %Q && find -print0 | %s -0 -o -H %s
--quiet",
+ buf, str_cpio, format) == -1) {
reply_with_perror ("asprintf");
return -1;
}
@@ -112,18 +111,18 @@ do_cpio_out (const char *dir, const char *format)
if (ferror (fp)) {
fprintf (stderr, "fread: %s: %m\n", dir);
- send_file_end (1); /* Cancel. */
+ send_file_end (1); /* Cancel. */
pclose (fp);
return -1;
}
if (pclose (fp) != 0) {
fprintf (stderr, "pclose: %s: %m\n", dir);
- send_file_end (1); /* Cancel. */
+ send_file_end (1); /* Cancel. */
return -1;
}
- if (send_file_end (0)) /* Normal end of file. */
+ if (send_file_end (0)) /* Normal end of file. */
return -1;
return 0;
diff --git a/daemon/cpmv.c b/daemon/cpmv.c
index 390b09f..2a8aed2 100644
--- a/daemon/cpmv.c
+++ b/daemon/cpmv.c
@@ -25,10 +25,11 @@
#include "daemon.h"
#include "actions.h"
-GUESTFSD_EXT_CMD(str_cp, cp);
-GUESTFSD_EXT_CMD(str_mv, mv);
+GUESTFSD_EXT_CMD (str_cp, cp);
+GUESTFSD_EXT_CMD (str_mv, mv);
-static int cpmv_cmd (const char *cmd, const char *flags, const char *src, const char
*dest);
+static int cpmv_cmd (const char *cmd, const char *flags, const char *src,
+ const char *dest);
int
do_cp (const char *src, const char *dest)
@@ -55,7 +56,8 @@ do_mv (const char *src, const char *dest)
}
static int
-cpmv_cmd (const char *cmd, const char *flags, const char *src, const char *dest)
+cpmv_cmd (const char *cmd, const char *flags, const char *src,
+ const char *dest)
{
CLEANUP_FREE char *srcbuf = NULL, *destbuf = NULL;
CLEANUP_FREE char *err = NULL;
diff --git a/daemon/daemon.h b/daemon/daemon.h
index 994b47a..66b48b2 100644
--- a/daemon/daemon.h
+++ b/daemon/daemon.h
@@ -70,8 +70,8 @@ extern char *mountable_to_string (const mountable_t *mountable);
/*-- in mount.c --*/
extern int mount_vfs_nochroot (const char *options, const char *vfstype,
- const mountable_t *mountable,
- const char *mp, const char *user_mp);
+ const mountable_t *mountable, const char *mp,
+ const char *user_mp);
/* Growable strings buffer. */
struct stringsbuf {
@@ -80,7 +80,7 @@ struct stringsbuf {
size_t alloc;
};
#define DECLARE_STRINGSBUF(v) \
- struct stringsbuf (v) = { .argv = NULL, .size = 0, .alloc = 0 }
+ struct stringsbuf (v) = {.argv = NULL, .size = 0, .alloc = 0 }
/* Append a string to the strings buffer.
*
@@ -95,7 +95,7 @@ struct stringsbuf {
extern int add_string_nodup (struct stringsbuf *sb, char *str);
extern int add_string (struct stringsbuf *sb, const char *str);
extern int add_sprintf (struct stringsbuf *sb, const char *fs, ...)
- __attribute__((format (printf,2,3)));
+ __attribute__((format (printf, 2, 3)));
extern int end_stringsbuf (struct stringsbuf *sb);
extern char **take_stringsbuf (struct stringsbuf *sb);
extern void free_stringsbuf (struct stringsbuf *sb);
@@ -120,8 +120,10 @@ extern char **split_lines (char *str);
extern char **empty_list (void);
-#define __external_command __attribute__((__section__(".guestfsd_ext_cmds")))
-#define GUESTFSD_EXT_CMD(___ext_cmd_var, ___ext_cmd_str) static const char
___ext_cmd_var[] __external_command = #___ext_cmd_str
+#define __external_command \
+ __attribute__((__section__(".guestfsd_ext_cmds")))
+#define GUESTFSD_EXT_CMD(___ext_cmd_var, ___ext_cmd_str) \
+ static const char ___ext_cmd_var[] __external_command = #___ext_cmd_str
extern int is_power_of_2 (unsigned long v);
@@ -162,8 +164,8 @@ extern guestfs_int_lvm_lv_list *parse_command_line_lvs (void);
/*-- in optgroups.c (auto-generated) --*/
struct optgroup {
- const char *group; /* Name of the optional group. */
- int (*available) (void); /* Function to test availability. */
+ const char *group; /* Name of the optional group. */
+ int (*available) (void); /* Function to test availability. */
};
extern struct optgroup optgroups[];
@@ -227,9 +229,12 @@ extern int xfs_set_label (const char *device, const char *label);
extern int64_t xfs_minimum_size (const char *path);
/*-- debug-bmap.c --*/
-extern char *debug_bmap (const char *subcmd, size_t argc, char *const *const argv);
-extern char *debug_bmap_file (const char *subcmd, size_t argc, char *const *const argv);
-extern char *debug_bmap_device (const char *subcmd, size_t argc, char *const *const
argv);
+extern char *debug_bmap (const char *subcmd, size_t argc,
+ char *const *const argv);
+extern char *debug_bmap_file (const char *subcmd, size_t argc,
+ char *const *const argv);
+extern char *debug_bmap_device (const char *subcmd, size_t argc,
+ char *const *const argv);
/*-- in btrfs.c --*/
extern char *btrfs_get_label (const char *device);
@@ -251,17 +256,18 @@ extern int swap_set_uuid (const char *device, const char *uuid);
* it is added automatically by the client-side RPC stubs.
*/
extern void reply_with_error_errno (int err, const char *fs, ...)
- __attribute__((format (printf,2,3)));
+ __attribute__((format (printf, 2, 3)));
extern void reply_with_perror_errno (int err, const char *fs, ...)
- __attribute__((format (printf,2,3)));
-#define reply_with_error(...) reply_with_error_errno(0, __VA_ARGS__)
-#define reply_with_perror(...) reply_with_perror_errno(errno, __VA_ARGS__)
-#define reply_with_unavailable_feature(feature) \
- reply_with_error_errno (ENOTSUP, \
- "feature '%s' is not available in this\n" \
- "build of libguestfs. Read 'AVAILABILITY' in the guestfs(3) man page
for\n" \
- "how to check for the availability of features.", \
- feature)
+ __attribute__((format (printf, 2, 3)));
+#define reply_with_error(...) reply_with_error_errno (0, __VA_ARGS__)
+#define reply_with_perror(...) reply_with_perror_errno (errno, __VA_ARGS__)
+#define reply_with_unavailable_feature(feature) \
+ reply_with_error_errno ( \
+ ENOTSUP, "feature '%s' is not available in this\n" \
+ "build of libguestfs. Read 'AVAILABILITY' in the " \
+ "guestfs(3) man page for\n" \
+ "how to check for the availability of features.", \
+ feature)
/* daemon functions that receive files (FileIn) should call
* receive_file for each FileIn parameter.
@@ -310,7 +316,8 @@ extern void pulse_mode_cancel (void);
/* Send a progress message without rate-limiting. This is just
* for debugging - DON'T use it in regular code!
*/
-extern void notify_progress_no_ratelimit (uint64_t position, uint64_t total, const struct
timeval *now);
+extern void notify_progress_no_ratelimit (uint64_t position, uint64_t total,
+ const struct timeval *now);
/* Return true iff the buffer is all zero bytes.
*
@@ -333,38 +340,42 @@ is_zero (const char *buffer, size_t size)
/* Helper for building up short lists of arguments. Your code has to
* define MAX_ARGS to a suitable value.
*/
-#define ADD_ARG(argv,i,v) \
- do { \
- if ((i) >= MAX_ARGS) { \
- fprintf (stderr, "%s: %d: internal error: exceeded MAX_ARGS (%zu) when
constructing the command line\n", __FILE__, __LINE__, (size_t) MAX_ARGS); \
- abort (); \
- } \
- (argv)[(i)++] = (v); \
+#define ADD_ARG(argv, i, v) \
+ do { \
+ if ((i) >= MAX_ARGS) { \
+ fprintf (stderr, "%s: %d: internal error: exceeded MAX_ARGS (%zu) " \
+ "when constructing the command line\n", \
+ __FILE__, __LINE__, (size_t)MAX_ARGS); \
+ abort (); \
+ } \
+ (argv)[(i)++] = (v); \
} while (0)
/* Helper for functions that need a root filesystem mounted.
* NB. Cannot be used for FileIn functions.
*/
-#define NEED_ROOT(cancel_stmt,fail_stmt) \
- do { \
- if (!is_root_mounted ()) { \
+#define NEED_ROOT(cancel_stmt, fail_stmt) \
+ do { \
+ if (!is_root_mounted ()) { \
cancel_stmt; \
- reply_with_error ("%s: you must call 'mount' first to mount the root
filesystem", __func__); \
- fail_stmt; \
- } \
- } \
- while (0)
+ reply_with_error ( \
+ "%s: you must call 'mount' first to mount the root filesystem",
\
+ __func__); \
+ fail_stmt; \
+ } \
+ } while (0)
/* Helper for functions that need an argument ("path") that is absolute.
* NB. Cannot be used for FileIn functions.
*/
-#define ABS_PATH(path,cancel_stmt,fail_stmt) \
- do { \
- if ((path)[0] != '/') { \
- cancel_stmt; \
- reply_with_error ("%s: path must start with a / character", __func__); \
- fail_stmt; \
- } \
+#define ABS_PATH(path, cancel_stmt, fail_stmt) \
+ do { \
+ if ((path)[0] != '/') { \
+ cancel_stmt; \
+ reply_with_error ("%s: path must start with a / character", \
+ __func__); \
+ fail_stmt; \
+ } \
} while (0)
/* NB:
@@ -374,58 +385,55 @@ is_zero (const char *buffer, size_t size)
* (3) All paths specified must be absolute.
* (4) Neither macro affects errno.
*/
-#define CHROOT_IN \
- do { \
- if (sysroot_len > 0) { \
- int __old_errno = errno; \
- if (chroot (sysroot) == -1) \
- perror ("CHROOT_IN: sysroot"); \
- errno = __old_errno; \
- } \
+#define CHROOT_IN \
+ do { \
+ if (sysroot_len > 0) { \
+ int __old_errno = errno; \
+ if (chroot (sysroot) == -1) \
+ perror ("CHROOT_IN: sysroot"); \
+ errno = __old_errno; \
+ } \
} while (0)
-#define CHROOT_OUT \
- do { \
- if (sysroot_len > 0) { \
- int __old_errno = errno; \
- if (chroot (".") == -1) \
- perror ("CHROOT_OUT: ."); \
- errno = __old_errno; \
- } \
+#define CHROOT_OUT \
+ do { \
+ if (sysroot_len > 0) { \
+ int __old_errno = errno; \
+ if (chroot (".") == -1) \
+ perror ("CHROOT_OUT: ."); \
+ errno = __old_errno; \
+ } \
} while (0)
/* Marks functions which are not implemented.
* NB. Cannot be used for FileIn functions.
*/
-#define XXX_NOT_IMPL(errcode) \
- do { \
- reply_with_error ("%s: function not implemented", __func__); \
- return (errcode); \
- } \
- while (0)
+#define XXX_NOT_IMPL(errcode) \
+ do { \
+ reply_with_error ("%s: function not implemented", __func__); \
+ return (errcode); \
+ } while (0)
/* Marks functions which are not supported. */
-#define NOT_SUPPORTED(errcode,...) \
- do { \
- reply_with_error_errno (ENOTSUP, __VA_ARGS__); \
- return (errcode); \
- } \
- while (0)
+#define NOT_SUPPORTED(errcode, ...) \
+ do { \
+ reply_with_error_errno (ENOTSUP, __VA_ARGS__); \
+ return (errcode); \
+ } while (0)
/* Calls reply_with_error, but includes the Augeas error details. */
-#define AUGEAS_ERROR(fs,...) \
- do { \
- int code = aug_error (aug); \
- if (code == AUG_ENOMEM) \
- reply_with_error (fs ": augeas out of memory", ##__VA_ARGS__); \
- else { \
- const char *message = aug_error_message (aug); \
- const char *minor = aug_error_minor_message (aug); \
- const char *details = aug_error_details (aug); \
- reply_with_error (fs ": %s%s%s%s%s", ##__VA_ARGS__, \
- message, \
- minor ? ": " : "", minor ? minor :
"", \
- details ? ": " : "", details ? details :
""); \
- } \
+#define AUGEAS_ERROR(fs, ...) \
+ do { \
+ int code = aug_error (aug); \
+ if (code == AUG_ENOMEM) \
+ reply_with_error (fs ": augeas out of memory", ##__VA_ARGS__); \
+ else { \
+ const char *message = aug_error_message (aug); \
+ const char *minor = aug_error_minor_message (aug); \
+ const char *details = aug_error_details (aug); \
+ reply_with_error (fs ": %s%s%s%s%s", ##__VA_ARGS__, message, \
+ minor ? ": " : "", minor ? minor :
"", \
+ details ? ": " : "", details ? details :
""); \
+ } \
} while (0)
#endif /* GUESTFSD_DAEMON_H */
diff --git a/daemon/dd.c b/daemon/dd.c
index d0390d8..5dfe71f 100644
--- a/daemon/dd.c
+++ b/daemon/dd.c
@@ -27,7 +27,7 @@
#include "daemon.h"
#include "actions.h"
-GUESTFSD_EXT_CMD(str_dd, dd);
+GUESTFSD_EXT_CMD (str_dd, dd);
int
do_dd (const char *src, const char *dest)
@@ -97,7 +97,8 @@ do_copy_size (const char *src, const char *dest, int64_t ssize)
close (src_fd);
return -1;
}
- dest_fd = open (buf, O_WRONLY|O_CREAT|O_TRUNC|O_NOCTTY|O_CLOEXEC, 0666);
+ dest_fd =
+ open (buf, O_WRONLY | O_CREAT | O_TRUNC | O_NOCTTY | O_CLOEXEC, 0666);
}
if (dest_fd == -1) {
reply_with_perror ("%s", dest);
@@ -105,7 +106,7 @@ do_copy_size (const char *src, const char *dest, int64_t ssize)
return -1;
}
- uint64_t position = 0, size = (uint64_t) ssize;
+ uint64_t position = 0, size = (uint64_t)ssize;
CLEANUP_FREE char *buf = NULL;
buf = malloc (BUFSIZ);
if (buf == NULL) {
@@ -122,7 +123,7 @@ do_copy_size (const char *src, const char *dest, int64_t ssize)
if (n64 > BUFSIZ)
n = BUFSIZ;
else
- n = (size_t) n64; /* safe because of if condition */
+ n = (size_t)n64; /* safe because of if condition */
ssize_t r = read (src_fd, buf, n);
if (r == -1) {
@@ -146,7 +147,7 @@ do_copy_size (const char *src, const char *dest, int64_t ssize)
}
position += r;
- notify_progress ((uint64_t) position, (uint64_t) size);
+ notify_progress ((uint64_t)position, (uint64_t)size);
}
if (close (src_fd) == -1) {
diff --git a/daemon/debug-bmap.c b/daemon/debug-bmap.c
index fcf3ede..8db9ee0 100644
--- a/daemon/debug-bmap.c
+++ b/daemon/debug-bmap.c
@@ -85,10 +85,8 @@ bmap_prepare (const char *path, const char *orig_path)
return NULL;
}
- posix_fadvise (fd, 0, 0,
- POSIX_FADV_SEQUENTIAL |
- POSIX_FADV_NOREUSE |
- POSIX_FADV_DONTNEED);
+ posix_fadvise (fd, 0, 0, POSIX_FADV_SEQUENTIAL | POSIX_FADV_NOREUSE |
+ POSIX_FADV_DONTNEED);
}
ret = strdup ("ok");
@@ -187,7 +185,8 @@ debug_bmap (const char *subcmd, size_t argc, char *const *const argv)
for (;;) {
errno = 0;
d = readdir (dir);
- if (!d) break;
+ if (!d)
+ break;
}
/* Check readdir didn't fail */
diff --git a/daemon/debug.c b/daemon/debug.c
index dac6482..da06341 100644
--- a/daemon/debug.c
+++ b/daemon/debug.c
@@ -33,15 +33,15 @@
#include "daemon.h"
#include "actions.h"
-GUESTFSD_EXT_CMD(str_printenv, printenv);
-GUESTFSD_EXT_CMD(str_ldd, ldd);
-GUESTFSD_EXT_CMD(str_ls, ls);
-GUESTFSD_EXT_CMD(str_find, find);
-GUESTFSD_EXT_CMD(str_xargs, xargs);
-GUESTFSD_EXT_CMD(str_file, file);
-GUESTFSD_EXT_CMD(str_grep, grep);
-GUESTFSD_EXT_CMD(str_gawk, gawk);
-GUESTFSD_EXT_CMD(str_sh, sh);
+GUESTFSD_EXT_CMD (str_printenv, printenv);
+GUESTFSD_EXT_CMD (str_ldd, ldd);
+GUESTFSD_EXT_CMD (str_ls, ls);
+GUESTFSD_EXT_CMD (str_find, find);
+GUESTFSD_EXT_CMD (str_xargs, xargs);
+GUESTFSD_EXT_CMD (str_file, file);
+GUESTFSD_EXT_CMD (str_grep, grep);
+GUESTFSD_EXT_CMD (str_gawk, gawk);
+GUESTFSD_EXT_CMD (str_sh, sh);
/* This command exposes debugging information, internals and
* status. There is no comprehensive documentation for this
@@ -58,51 +58,66 @@ GUESTFSD_EXT_CMD(str_sh, sh);
struct cmd {
const char *cmd;
- char * (*f) (const char *subcmd, size_t argc, char *const *const argv);
+ char *(*f) (const char *subcmd, size_t argc, char *const *const argv);
};
-static char *debug_help (const char *subcmd, size_t argc, char *const *const argv);
-static char *debug_binaries (const char *subcmd, size_t argc, char *const *const argv);
-static char *debug_core_pattern (const char *subcmd, size_t argc, char *const *const
argv);
-static char *debug_device_speed (const char *subcmd, size_t argc, char *const *const
argv);
-static char *debug_env (const char *subcmd, size_t argc, char *const *const argv);
-static char *debug_error (const char *subcmd, size_t argc, char *const *const argv);
-static char *debug_fds (const char *subcmd, size_t argc, char *const *const argv);
-static char *debug_ldd (const char *subcmd, size_t argc, char *const *const argv);
-static char *debug_ls (const char *subcmd, size_t argc, char *const *const argv);
-static char *debug_ll (const char *subcmd, size_t argc, char *const *const argv);
-static char *debug_print (const char *subcmd, size_t argc, char *const *const argv);
-static char *debug_progress (const char *subcmd, size_t argc, char *const *const argv);
-static char *debug_qtrace (const char *subcmd, size_t argc, char *const *const argv);
-static char *debug_segv (const char *subcmd, size_t argc, char *const *const argv);
-static char *debug_setenv (const char *subcmd, size_t argc, char *const *const argv);
-static char *debug_sh (const char *subcmd, size_t argc, char *const *const argv);
-static char *debug_spew (const char *subcmd, size_t argc, char *const *const argv);
+static char *debug_help (const char *subcmd, size_t argc,
+ char *const *const argv);
+static char *debug_binaries (const char *subcmd, size_t argc,
+ char *const *const argv);
+static char *debug_core_pattern (const char *subcmd, size_t argc,
+ char *const *const argv);
+static char *debug_device_speed (const char *subcmd, size_t argc,
+ char *const *const argv);
+static char *debug_env (const char *subcmd, size_t argc,
+ char *const *const argv);
+static char *debug_error (const char *subcmd, size_t argc,
+ char *const *const argv);
+static char *debug_fds (const char *subcmd, size_t argc,
+ char *const *const argv);
+static char *debug_ldd (const char *subcmd, size_t argc,
+ char *const *const argv);
+static char *debug_ls (const char *subcmd, size_t argc,
+ char *const *const argv);
+static char *debug_ll (const char *subcmd, size_t argc,
+ char *const *const argv);
+static char *debug_print (const char *subcmd, size_t argc,
+ char *const *const argv);
+static char *debug_progress (const char *subcmd, size_t argc,
+ char *const *const argv);
+static char *debug_qtrace (const char *subcmd, size_t argc,
+ char *const *const argv);
+static char *debug_segv (const char *subcmd, size_t argc,
+ char *const *const argv);
+static char *debug_setenv (const char *subcmd, size_t argc,
+ char *const *const argv);
+static char *debug_sh (const char *subcmd, size_t argc,
+ char *const *const argv);
+static char *debug_spew (const char *subcmd, size_t argc,
+ char *const *const argv);
static void deliberately_cause_a_segfault (void);
-static struct cmd cmds[] = {
- { "help", debug_help },
- { "binaries", debug_binaries },
- { "bmap", debug_bmap },
- { "bmap_device", debug_bmap_device },
- { "bmap_file", debug_bmap_file },
- { "core_pattern", debug_core_pattern },
- { "device_speed", debug_device_speed },
- { "env", debug_env },
- { "error", debug_error },
- { "fds", debug_fds },
- { "ldd", debug_ldd },
- { "ls", debug_ls },
- { "ll", debug_ll },
- { "print", debug_print },
- { "progress", debug_progress },
- { "qtrace", debug_qtrace },
- { "segv", debug_segv },
- { "setenv", debug_setenv },
- { "sh", debug_sh },
- { "spew", debug_spew },
- { NULL, NULL }
-};
+static struct cmd cmds[] = { { "help", debug_help },
+ { "binaries", debug_binaries },
+ { "bmap", debug_bmap },
+ { "bmap_device", debug_bmap_device },
+ { "bmap_file", debug_bmap_file },
+ { "core_pattern", debug_core_pattern },
+ { "device_speed", debug_device_speed },
+ { "env", debug_env },
+ { "error", debug_error },
+ { "fds", debug_fds },
+ { "ldd", debug_ldd },
+ { "ls", debug_ls },
+ { "ll", debug_ll },
+ { "print", debug_print },
+ { "progress", debug_progress },
+ { "qtrace", debug_qtrace },
+ { "segv", debug_segv },
+ { "setenv", debug_setenv },
+ { "sh", debug_sh },
+ { "spew", debug_spew },
+ { NULL, NULL } };
char *
do_debug (const char *subcmd, char *const *argv)
@@ -136,7 +151,7 @@ debug_help (const char *subcmd, size_t argc, char *const *const argv)
len = strlen (r);
for (i = 0; cmds[i].cmd != NULL; ++i) {
len += strlen (cmds[i].cmd) + 1; /* space + new command */
- p = realloc (r, len + 1); /* +1 for the final NUL */
+ p = realloc (r, len + 1); /* +1 for the final NUL */
if (p == NULL) {
reply_with_perror ("realloc");
free (r);
@@ -204,7 +219,8 @@ debug_fds (const char *subcmd, size_t argc, char *const *const argv)
link[r] = '\0';
fprintf (fp, "%2s %s\n", d->d_name, link);
- } else
+ }
+ else
fprintf (fp, "%2s 0%o\n", d->d_name, statbuf.st_mode);
}
@@ -260,7 +276,7 @@ debug_sh (const char *subcmd, size_t argc, char *const *const argv)
cmd[j] = ' ';
j++;
}
- cmd[j-1] = '\0';
+ cmd[j - 1] = '\0';
/* Set up some environment variables. */
setenv ("root", sysroot, 1);
@@ -285,7 +301,8 @@ debug_sh (const char *subcmd, size_t argc, char *const *const argv)
return err;
}
-/* Print the environment that commands get (by running external printenv). */
+/* Print the environment that commands get (by running external printenv).
+ */
static char *
debug_env (const char *subcmd, size_t argc, char *const *const argv)
{
@@ -334,7 +351,8 @@ debug_error (const char *subcmd, size_t argc, char *const *const
argv)
if (argc != 1) {
error:
- reply_with_error ("debug error: expecting one arg: length of error
message");
+ reply_with_error (
+ "debug error: expecting one arg: length of error message");
return NULL;
}
@@ -374,11 +392,10 @@ debug_binaries (const char *subcmd, size_t argc, char *const *const
argv)
CLEANUP_FREE char *err = NULL;
char cmd[256];
- snprintf (cmd, sizeof (cmd),
- "%s / -xdev -type f -executable "
- "| %s %s -i "
- "| %s application/x-executable "
- "| %s -F: '{print $1}'",
+ snprintf (cmd, sizeof (cmd), "%s / -xdev -type f -executable "
+ "| %s %s -i "
+ "| %s application/x-executable "
+ "| %s -F: '{print $1}'",
str_find, str_xargs, str_file, str_grep, str_gawk);
r = command (&out, &err, str_sh, "-c", cmd, NULL);
@@ -443,7 +460,7 @@ debug_ls (const char *subcmd, size_t argc, char *const *const argv)
char *out;
CLEANUP_FREE char *err = NULL;
- cargv = malloc (sizeof (char *) * (len+3));
+ cargv = malloc (sizeof (char *) * (len + 3));
if (cargv == NULL) {
reply_with_perror ("malloc");
return NULL;
@@ -452,10 +469,10 @@ debug_ls (const char *subcmd, size_t argc, char *const *const argv)
cargv[0] = str_ls;
cargv[1] = "-a";
for (i = 0; i < len; ++i)
- cargv[2+i] = argv[i];
- cargv[2+len] = NULL;
+ cargv[2 + i] = argv[i];
+ cargv[2 + len] = NULL;
- r = commandv (&out, &err, (void *) cargv);
+ r = commandv (&out, &err, (void *)cargv);
if (r == -1) {
reply_with_error ("ls: %s", err);
free (out);
@@ -476,7 +493,7 @@ debug_ll (const char *subcmd, size_t argc, char *const *const argv)
char *out;
CLEANUP_FREE char *err = NULL;
- cargv = malloc (sizeof (char *) * (len+3));
+ cargv = malloc (sizeof (char *) * (len + 3));
if (cargv == NULL) {
reply_with_perror ("malloc");
return NULL;
@@ -485,10 +502,10 @@ debug_ll (const char *subcmd, size_t argc, char *const *const argv)
cargv[0] = str_ls;
cargv[1] = "-la";
for (i = 0; i < len; ++i)
- cargv[2+i] = argv[i];
- cargv[2+len] = NULL;
+ cargv[2 + i] = argv[i];
+ cargv[2 + len] = NULL;
- r = commandv (&out, &err, (void *) cargv);
+ r = commandv (&out, &err, (void *)cargv);
if (r == -1) {
reply_with_error ("ll: %s", err);
free (out);
@@ -523,7 +540,8 @@ debug_print (const char *subcmd, size_t argc, char *const *const
argv)
return ret;
}
-/* Generate progress notification messages in order to test progress bars. */
+/* Generate progress notification messages in order to test progress bars.
+ */
static char *
debug_progress (const char *subcmd, size_t argc, char *const *const argv)
{
@@ -532,7 +550,8 @@ debug_progress (const char *subcmd, size_t argc, char *const *const
argv)
if (argc < 1) {
error:
- reply_with_error ("progress: expecting one or more args: time in seconds [, rate
in microseconds]");
+ reply_with_error ("progress: expecting one or more args: time in "
+ "seconds [, rate in microseconds]");
return NULL;
}
@@ -555,16 +574,16 @@ debug_progress (const char *subcmd, size_t argc, char *const *const
argv)
/* Note the inner loops go to '<= limit' because we want to ensure
* that the final 100% completed message is set.
*/
- if (rate == 0) { /* Ordinary rate-limited progress messages. */
+ if (rate == 0) { /* Ordinary rate-limited progress messages. */
uint64_t tsecs = secs * 10; /* 1/10ths of seconds */
uint64_t i;
- for (i = 1; i < tsecs+1; ++i) {
+ for (i = 1; i < tsecs + 1; ++i) {
usleep (100000);
notify_progress (i, tsecs);
}
}
- else { /* Send messages at a given rate. */
+ else { /* Send messages at a given rate. */
uint64_t usecs = secs * 1000000; /* microseconds */
uint64_t i;
struct timeval now;
@@ -587,12 +606,14 @@ debug_progress (const char *subcmd, size_t argc, char *const *const
argv)
/* Enable core dumping to the given core pattern.
* Note that this pattern is relative to any chroot of the process which
- * crashes. This means that if you want to write the core file to the guest's
+ * crashes. This means that if you want to write the core file to the
+ * guest's
* storage the pattern must start with /sysroot only if the command which
* crashes doesn't chroot.
*/
static char *
-debug_core_pattern (const char *subcmd, size_t argc, char *const *const argv)
+debug_core_pattern (const char *subcmd, size_t argc,
+ char *const *const argv)
{
if (argc < 1) {
reply_with_error ("core_pattern: expecting a core pattern");
@@ -603,12 +624,12 @@ debug_core_pattern (const char *subcmd, size_t argc, char *const
*const argv)
const size_t pattern_len = strlen (pattern);
#define CORE_PATTERN "/proc/sys/kernel/core_pattern"
- int fd = open (CORE_PATTERN, O_WRONLY|O_CLOEXEC);
+ int fd = open (CORE_PATTERN, O_WRONLY | O_CLOEXEC);
if (fd == -1) {
reply_with_perror ("open: " CORE_PATTERN);
return NULL;
}
- if (write (fd, pattern, pattern_len) < (ssize_t) pattern_len) {
+ if (write (fd, pattern, pattern_len) < (ssize_t)pattern_len) {
reply_with_perror ("write: " CORE_PATTERN);
close (fd);
return NULL;
@@ -618,10 +639,8 @@ debug_core_pattern (const char *subcmd, size_t argc, char *const
*const argv)
return NULL;
}
- struct rlimit limit = {
- .rlim_cur = RLIM_INFINITY,
- .rlim_max = RLIM_INFINITY
- };
+ struct rlimit limit = {.rlim_cur = RLIM_INFINITY,
+ .rlim_max = RLIM_INFINITY };
if (setrlimit (RLIMIT_CORE, &limit) == -1) {
reply_with_perror ("setrlimit (RLIMIT_CORE)");
return NULL;
@@ -652,16 +671,16 @@ debug_spew (const char *subcmd, size_t argc, char *const *const
argv)
}
if (sscanf (argv[0], "%zu", &n) != 1) {
- reply_with_error ("spew: could not parse number of lines '%s'",
argv[0]);
+ reply_with_error ("spew: could not parse number of lines '%s'",
+ argv[0]);
return NULL;
}
for (i = 0; i < n; ++i)
- fprintf (stderr,
- "abcdefghijklmnopqrstuvwxyz" /* 26 */
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ" /* 52 */
- "01234567890123456789" /* 72 */
- "\n");
+ fprintf (stderr, "abcdefghijklmnopqrstuvwxyz" /* 26 */
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ" /* 52 */
+ "01234567890123456789" /* 72 */
+ "\n");
ret = strdup ("ok");
if (!ret) {
@@ -679,7 +698,8 @@ write_cb (void *fd_ptr, const void *buf, size_t len)
return xwrite (fd, buf, len);
}
-/* This requires a non-upstream qemu patch. See contrib/visualize-alignment/
+/* This requires a non-upstream qemu patch. See
+ * contrib/visualize-alignment/
* directory in the libguestfs source tree.
*/
static char *
@@ -704,20 +724,21 @@ debug_qtrace (const char *subcmd, size_t argc, char *const *const
argv)
if (do_drop_caches (3) == -1)
return NULL;
- /* Note this doesn't do device name translation or check this is a device. */
- int fd = open (argv[0], O_RDONLY|O_DIRECT|O_CLOEXEC);
+ /* Note this doesn't do device name translation or check this is a device.
+ */
+ int fd = open (argv[0], O_RDONLY | O_DIRECT | O_CLOEXEC);
if (fd == -1) {
reply_with_perror ("qtrace: %s: open", argv[0]);
return NULL;
}
- /* The pattern of reads is what signals to the analysis program that
- * tracing should be started or stopped. Note this assumes both 512
- * byte sectors, and that O_DIRECT will let us do 512 byte aligned
- * reads. We ought to read the sector size of the device and use
- * that instead (XXX). The analysis program currently assumes 512
- * byte sectors anyway.
- */
+/* The pattern of reads is what signals to the analysis program that
+ * tracing should be started or stopped. Note this assumes both 512
+ * byte sectors, and that O_DIRECT will let us do 512 byte aligned
+ * reads. We ought to read the sector size of the device and use
+ * that instead (XXX). The analysis program currently assumes 512
+ * byte sectors anyway.
+ */
#define QTRACE_SIZE 512
const int patterns[2][5] = {
{ 2, 15, 21, 2, -1 }, /* disable trace */
@@ -738,7 +759,7 @@ debug_qtrace (const char *subcmd, size_t argc, char *const *const
argv)
}
for (i = 0; patterns[enable][i] >= 0; ++i) {
- if (lseek (fd, patterns[enable][i]*QTRACE_SIZE, SEEK_SET) == -1) {
+ if (lseek (fd, patterns[enable][i] * QTRACE_SIZE, SEEK_SET) == -1) {
reply_with_perror ("qtrace: %s: lseek", argv[0]);
close (fd);
return NULL;
@@ -768,7 +789,8 @@ debug_qtrace (const char *subcmd, size_t argc, char *const *const
argv)
/* Used to test read and write speed. */
static char *
-debug_device_speed (const char *subcmd, size_t argc, char *const *const argv)
+debug_device_speed (const char *subcmd, size_t argc,
+ char *const *const argv)
{
const char *device;
int writing, err;
@@ -816,7 +838,8 @@ debug_device_speed (const char *subcmd, size_t argc, char *const
*const argv)
/* Any non-zero data will do. */
memset (buf, 100, BUFSIZ);
- fd = open (device, (writing ? O_WRONLY : O_RDONLY) | O_CLOEXEC | O_DIRECT);
+ fd =
+ open (device, (writing ? O_WRONLY : O_RDONLY) | O_CLOEXEC | O_DIRECT);
if (fd == -1) {
reply_with_perror ("open: %s", device);
return NULL;
@@ -837,7 +860,7 @@ debug_device_speed (const char *subcmd, size_t argc, char *const
*const argv)
(now.tv_sec == end.tv_sec && now.tv_usec > end.tv_usec))
break;
- /* Because of O_DIRECT, only write whole, aligned buffers. */
+ /* Because of O_DIRECT, only write whole, aligned buffers. */
again:
if (size - position < BUFSIZ) {
position = 0;
@@ -885,7 +908,7 @@ debug_device_speed (const char *subcmd, size_t argc, char *const
*const argv)
return ret;
- error:
+error:
close (fd);
return NULL;
}
@@ -897,7 +920,8 @@ do_debug_upload (const char *filename, int mode)
/* Not chrooted - this command lets you upload a file to anywhere
* in the appliance.
*/
- int fd = open (filename, O_WRONLY|O_CREAT|O_TRUNC|O_NOCTTY|O_CLOEXEC, mode);
+ int fd = open (filename,
+ O_WRONLY | O_CREAT | O_TRUNC | O_NOCTTY | O_CLOEXEC, mode);
if (fd == -1) {
int err = errno;
@@ -908,7 +932,7 @@ do_debug_upload (const char *filename, int mode)
}
int r = receive_file (write_cb, &fd);
- if (r == -1) { /* write error */
+ if (r == -1) { /* write error */
int err = errno;
cancel_receive ();
errno = err;
@@ -916,7 +940,7 @@ do_debug_upload (const char *filename, int mode)
close (fd);
return -1;
}
- if (r == -2) { /* cancellation from library */
+ if (r == -2) { /* cancellation from library */
/* This error is ignored by the library since it initiated the
* cancel. Nevertheless we must send an error reply here.
*/
@@ -971,14 +995,14 @@ do_internal_rhbz914931 (int count)
}
r = receive_file (crash_cb, &count);
- if (r == -1) { /* write error */
+ if (r == -1) { /* write error */
int err = errno;
cancel_receive ();
errno = err;
reply_with_error ("write error");
return -1;
}
- if (r == -2) { /* cancellation from library */
+ if (r == -2) { /* cancellation from library */
/* This error is ignored by the library since it initiated the
* cancel. Nevertheless we must send an error reply here.
*/
diff --git a/daemon/devsparts.c b/daemon/devsparts.c
index 7c690f8..e8e1b32 100644
--- a/daemon/devsparts.c
+++ b/daemon/devsparts.c
@@ -54,12 +54,11 @@ foreach_block_device (block_dev_func_t func)
for (;;) {
errno = 0;
d = readdir (dir);
- if (!d) break;
+ if (!d)
+ break;
- if (STREQLEN (d->d_name, "sd", 2) ||
- STREQLEN (d->d_name, "hd", 2) ||
- STREQLEN (d->d_name, "ubd", 3) ||
- STREQLEN (d->d_name, "vd", 2) ||
+ if (STREQLEN (d->d_name, "sd", 2) || STREQLEN (d->d_name,
"hd", 2) ||
+ STREQLEN (d->d_name, "ubd", 3) || STREQLEN (d->d_name,
"vd", 2) ||
STREQLEN (d->d_name, "sr", 2)) {
snprintf (dev_path, sizeof dev_path, "/dev/%s", d->d_name);
@@ -71,7 +70,7 @@ foreach_block_device (block_dev_func_t func)
* CD-ROM device even though we didn't request it. Try to
* detect this by seeing if the device contains media.
*/
- fd = open (dev_path, O_RDONLY|O_CLOEXEC);
+ fd = open (dev_path, O_RDONLY | O_CLOEXEC);
if (fd == -1) {
perror (dev_path);
continue;
@@ -79,7 +78,7 @@ foreach_block_device (block_dev_func_t func)
close (fd);
/* Call the map function for this device */
- if ((*func)(d->d_name, &r) != 0) {
+ if ((*func) (d->d_name, &r) != 0) {
err = 1;
break;
}
@@ -201,7 +200,7 @@ do_part_to_dev (const char *part)
int err = 1;
size_t n = strlen (part);
- while (n >= 1 && c_isdigit (part[n-1])) {
+ while (n >= 1 && c_isdigit (part[n - 1])) {
err = 0;
n--;
}
@@ -226,7 +225,7 @@ do_part_to_partnum (const char *part)
int err = 1;
size_t n = strlen (part);
- while (n >= 1 && c_isdigit (part[n-1])) {
+ while (n >= 1 && c_isdigit (part[n - 1])) {
err = 0;
n--;
}
@@ -259,7 +258,8 @@ do_is_whole_device (const char *device)
struct stat statbuf;
if (stat (devpath, &statbuf) == -1) {
- if (errno == ENOENT || errno == ENOTDIR) return 0;
+ if (errno == ENOENT || errno == ENOTDIR)
+ return 0;
reply_with_perror ("stat");
return -1;
@@ -280,7 +280,7 @@ do_device_index (const char *device)
for (i = 0; devices[i] != NULL; ++i) {
if (STREQ (device, devices[i]))
- ret = (int) i;
+ ret = (int)i;
}
if (ret == -1)
@@ -301,7 +301,7 @@ do_nr_devices (void)
for (i = 0; devices[i] != NULL; ++i)
;
- return (int) i;
+ return (int)i;
}
#define GUESTFSDIR "/dev/disk/guestfs"
@@ -352,7 +352,7 @@ do_list_disk_labels (void)
if (add_string_nodup (&ret, rawdev) == -1)
goto error;
- rawdev = NULL; /* buffer now owned by the stringsbuf */
+ rawdev = NULL; /* buffer now owned by the stringsbuf */
}
/* Check readdir didn't fail */
@@ -375,9 +375,9 @@ do_list_disk_labels (void)
if (end_stringsbuf (&ret) == -1)
goto error;
- return ret.argv; /* caller frees */
+ return ret.argv; /* caller frees */
- error:
+error:
if (dir)
closedir (dir);
free (rawdev);
diff --git a/daemon/df.c b/daemon/df.c
index f177084..a7039cd 100644
--- a/daemon/df.c
+++ b/daemon/df.c
@@ -27,7 +27,7 @@
#include "daemon.h"
#include "actions.h"
-GUESTFSD_EXT_CMD(str_df, df);
+GUESTFSD_EXT_CMD (str_df, df);
char *
do_df (void)
@@ -45,7 +45,7 @@ do_df (void)
return NULL;
}
- return out; /* Caller frees. */
+ return out; /* Caller frees. */
}
char *
@@ -64,5 +64,5 @@ do_df_h (void)
return NULL;
}
- return out; /* Caller frees. */
+ return out; /* Caller frees. */
}
diff --git a/daemon/dir.c b/daemon/dir.c
index 07dc68f..060e33a 100644
--- a/daemon/dir.c
+++ b/daemon/dir.c
@@ -29,7 +29,7 @@
#include "daemon.h"
#include "actions.h"
-GUESTFSD_EXT_CMD(str_rm, rm);
+GUESTFSD_EXT_CMD (str_rm, rm);
int
do_rmdir (const char *path)
@@ -131,35 +131,42 @@ recursive_mkdir (const char *path)
char *p;
struct stat buf;
- again:
+again:
r = mkdir (path, 0777);
if (r == -1) {
- if (errno == EEXIST) { /* Something exists here, might not be a dir. */
+ if (errno == EEXIST) { /* Something exists here, might not be a dir. */
r = lstat (path, &buf);
- if (r == -1) return -1;
- if (!S_ISDIR (buf.st_mode)) return -2;
- return 0; /* OK - directory exists here already. */
+ if (r == -1)
+ return -1;
+ if (!S_ISDIR (buf.st_mode))
+ return -2;
+ return 0; /* OK - directory exists here already. */
}
if (!loop && errno == ENOENT) {
- loop = 1; /* Stops it looping forever. */
+ loop = 1; /* Stops it looping forever. */
/* If we're at the root, and we failed, just give up. */
- if (path[0] == '/' && path[1] == '\0') return -1;
+ if (path[0] == '/' && path[1] == '\0')
+ return -1;
/* Try to make the parent directory first. */
CLEANUP_FREE char *ppath = strdup (path);
- if (ppath == NULL) return -1;
+ if (ppath == NULL)
+ return -1;
p = strrchr (ppath, '/');
- if (p) *p = '\0';
+ if (p)
+ *p = '\0';
r = recursive_mkdir (ppath);
- if (r != 0) return r;
+ if (r != 0)
+ return r;
goto again;
- } else /* Failed for some other reason, so return error. */
+ }
+ else /* Failed for some other reason, so return error. */
return -1;
}
return 0;
diff --git a/daemon/dmesg.c b/daemon/dmesg.c
index 5e16861..8c4455b 100644
--- a/daemon/dmesg.c
+++ b/daemon/dmesg.c
@@ -27,7 +27,7 @@
#include "daemon.h"
#include "actions.h"
-GUESTFSD_EXT_CMD(str_dmesg, dmesg);
+GUESTFSD_EXT_CMD (str_dmesg, dmesg);
char *
do_dmesg (void)
@@ -43,5 +43,5 @@ do_dmesg (void)
return NULL;
}
- return out; /* caller frees */
+ return out; /* caller frees */
}
diff --git a/daemon/du.c b/daemon/du.c
index 1f31783..cb8e2b1 100644
--- a/daemon/du.c
+++ b/daemon/du.c
@@ -28,7 +28,7 @@
#include "daemon.h"
#include "actions.h"
-GUESTFSD_EXT_CMD(str_du, du);
+GUESTFSD_EXT_CMD (str_du, du);
int64_t
do_du (const char *path)
@@ -53,7 +53,7 @@ do_du (const char *path)
return -1;
}
- if (sscanf (out, "%"SCNi64, &rv) != 1) {
+ if (sscanf (out, "%" SCNi64, &rv) != 1) {
pulse_mode_cancel ();
reply_with_error ("%s: could not read output: %s", path, out);
return -1;
diff --git a/daemon/ext2.c b/daemon/ext2.c
index 5dd67c7..d566cc7 100644
--- a/daemon/ext2.c
+++ b/daemon/ext2.c
@@ -33,20 +33,20 @@
#define MAX_ARGS 128
-GUESTFSD_EXT_CMD(str_tune2fs, tune2fs);
-GUESTFSD_EXT_CMD(str_e2fsck, e2fsck);
-GUESTFSD_EXT_CMD(str_resize2fs, resize2fs);
-GUESTFSD_EXT_CMD(str_mke2fs, mke2fs);
-GUESTFSD_EXT_CMD(str_lsattr, lsattr);
-GUESTFSD_EXT_CMD(str_chattr, chattr);
-GUESTFSD_EXT_CMD(str_e2label, e2label);
+GUESTFSD_EXT_CMD (str_tune2fs, tune2fs);
+GUESTFSD_EXT_CMD (str_e2fsck, e2fsck);
+GUESTFSD_EXT_CMD (str_resize2fs, resize2fs);
+GUESTFSD_EXT_CMD (str_mke2fs, mke2fs);
+GUESTFSD_EXT_CMD (str_lsattr, lsattr);
+GUESTFSD_EXT_CMD (str_chattr, chattr);
+GUESTFSD_EXT_CMD (str_e2label, e2label);
/*
https://bugzilla.redhat.com/show_bug.cgi?id=978302#c1 */
int
fstype_is_extfs (const char *fstype)
{
- return STREQ (fstype, "ext2") || STREQ (fstype, "ext3")
- || STREQ (fstype, "ext4");
+ return STREQ (fstype, "ext2") || STREQ (fstype, "ext3") ||
+ STREQ (fstype, "ext4");
}
char **
@@ -68,7 +68,8 @@ do_tune2fs_l (const char *device)
/* Discard the first line if it contains "tune2fs ...". */
if (STRPREFIX (p, "tune2fs ") || STRPREFIX (p, "tune4fs ")) {
p = strchr (p, '\n');
- if (p) p++;
+ if (p)
+ p++;
else {
reply_with_error ("truncated output");
return NULL;
@@ -83,24 +84,27 @@ do_tune2fs_l (const char *device)
pend++;
}
- if (!*p) continue;
+ if (!*p)
+ continue;
colon = strchr (p, ':');
if (colon) {
*colon = '\0';
- do { colon++; } while (*colon && c_isspace (*colon));
+ do {
+ colon++;
+ } while (*colon && c_isspace (*colon));
if (add_string (&ret, p) == -1) {
return NULL;
}
- if (STREQ (colon, "<none>") ||
- STREQ (colon, "<not available>") ||
+ if (STREQ (colon, "<none>") || STREQ (colon, "<not
available>") ||
STREQ (colon, "(none)")) {
if (add_string (&ret, "") == -1) {
return NULL;
}
- } else {
+ }
+ else {
if (add_string (&ret, colon) == -1) {
return NULL;
}
@@ -131,8 +135,8 @@ do_set_e2label (const char *device, const char *label)
CLEANUP_FREE char *err = NULL;
if (strlen (label) > EXT2_LABEL_MAX) {
- reply_with_error ("%s: ext2/3/4 labels are limited to %d bytes",
- label, EXT2_LABEL_MAX);
+ reply_with_error ("%s: ext2/3/4 labels are limited to %d bytes", label,
+ EXT2_LABEL_MAX);
return -1;
}
@@ -150,7 +154,7 @@ do_get_e2label (const char *device)
{
const mountable_t mountable = {
.type = MOUNTABLE_DEVICE,
- .device = /* not really ... */ (char *) device,
+ .device = /* not really ... */ (char *)device,
.volume = NULL,
};
return do_vfs_label (&mountable);
@@ -182,7 +186,7 @@ do_get_e2uuid (const char *device)
{
const mountable_t mountable = {
.type = MOUNTABLE_DEVICE,
- .device = /* not really ... */ (char *) device,
+ .device = /* not really ... */ (char *)device,
.volume = NULL,
};
return do_vfs_uuid (&mountable);
@@ -200,8 +204,7 @@ if_not_mounted_run_e2fsck (const char *device)
return -1;
if (!mounted) {
- r = commandf (NULL, &err,
- COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
+ r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
str_e2fsck, "-fy", device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
@@ -241,8 +244,8 @@ do_resize2fs_size (const char *device, int64_t size)
* kilobytes.
*/
if (size & 1023) {
- reply_with_error ("%" PRIi64 ": size must be a round number of
kilobytes",
- size);
+ reply_with_error (
+ "%" PRIi64 ": size must be a round number of kilobytes",
size);
return -1;
}
size /= 1024;
@@ -294,7 +297,8 @@ get_block_size (const char *device)
for (i = 0; params[i] != NULL; i += 2) {
if (STREQ (params[i], block_pattern)) {
- if (xstrtol (params[i + 1], NULL, 10, &block_size, NULL) != LONGINT_OK) {
+ if (xstrtol (params[i + 1], NULL, 10, &block_size, NULL) !=
+ LONGINT_OK) {
reply_with_error ("cannot parse block size");
return -1;
}
@@ -335,16 +339,17 @@ ext_minimum_size (const char *device)
for (i = 0; lines[i] != NULL; ++i) {
if (STRPREFIX (lines[i], pattern)) {
- if (XSTRTOD64 (lines[i] + strlen (pattern),
- NULL, 10, &ret, NULL) != LONGINT_OK) {
+ if (XSTRTOD64 (lines[i] + strlen (pattern), NULL, 10, &ret, NULL) !=
+ LONGINT_OK) {
reply_with_error ("cannot parse minimum size");
return -1;
}
if ((block_size = get_block_size (device)) == -1)
return -1;
if (verbose) {
- fprintf (stderr, "Minimum size in blocks: %" SCNd64 \
- "\nBlock count: %ld\n", ret, block_size);
+ fprintf (stderr,
+ "Minimum size in blocks: %" SCNd64 "\nBlock count:
%ld\n",
+ ret, block_size);
}
if (INT64_MAX / block_size < ret) {
reply_with_error ("filesystem size too big: overflow");
@@ -356,15 +361,14 @@ ext_minimum_size (const char *device)
#undef XSTRTOD64
- reply_with_error ("minimum size not found. Check output format:\n%s", out);
+ reply_with_error ("minimum size not found. Check output format:\n%s",
+ out);
return -1;
}
/* Takes optional arguments, consult optargs_bitmask. */
int
-do_e2fsck (const char *device,
- int correct,
- int forceall)
+do_e2fsck (const char *device, int correct, int forceall)
{
const char *argv[MAX_ARGS];
CLEANUP_FREE char *err = NULL;
@@ -378,7 +382,8 @@ do_e2fsck (const char *device,
forceall = 0;
if (correct && forceall) {
- reply_with_error ("only one of the options 'correct', 'forceall'
may be specified");
+ reply_with_error (
+ "only one of the options 'correct', 'forceall' may be
specified");
return -1;
}
@@ -394,9 +399,7 @@ do_e2fsck (const char *device,
ADD_ARG (argv, i, device);
ADD_ARG (argv, i, NULL);
- r = commandrvf (NULL, &err,
- COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
- argv);
+ r = commandrvf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR, argv);
/* 0 = no errors, 1 = errors corrected.
*
* >= 4 means uncorrected or other errors.
@@ -430,9 +433,8 @@ do_mke2journal (int blocksize, const char *device)
wipe_device_before_mkfs (device);
- r = command (NULL, &err,
- str_mke2fs, "-F", "-O", "journal_dev",
"-b", blocksize_s,
- device, NULL);
+ r = command (NULL, &err, str_mke2fs, "-F", "-O",
"journal_dev", "-b",
+ blocksize_s, device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
return -1;
@@ -448,8 +450,8 @@ do_mke2journal_L (int blocksize, const char *label, const char
*device)
int r;
if (strlen (label) > EXT2_LABEL_MAX) {
- reply_with_error ("%s: ext2/3/4 labels are limited to %d bytes",
- label, EXT2_LABEL_MAX);
+ reply_with_error ("%s: ext2/3/4 labels are limited to %d bytes", label,
+ EXT2_LABEL_MAX);
return -1;
}
@@ -458,10 +460,8 @@ do_mke2journal_L (int blocksize, const char *label, const char
*device)
wipe_device_before_mkfs (device);
- r = command (NULL, &err,
- str_mke2fs, "-F", "-O", "journal_dev",
"-b", blocksize_s,
- "-L", label,
- device, NULL);
+ r = command (NULL, &err, str_mke2fs, "-F", "-O",
"journal_dev", "-b",
+ blocksize_s, "-L", label, device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
return -1;
@@ -481,10 +481,8 @@ do_mke2journal_U (int blocksize, const char *uuid, const char
*device)
wipe_device_before_mkfs (device);
- r = command (NULL, &err,
- str_mke2fs, "-F", "-O", "journal_dev",
"-b", blocksize_s,
- "-U", uuid,
- device, NULL);
+ r = command (NULL, &err, str_mke2fs, "-F", "-O",
"journal_dev", "-b",
+ blocksize_s, "-U", uuid, device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
return -1;
@@ -516,9 +514,8 @@ do_mke2fs_J (const char *fstype, int blocksize, const char *device,
wipe_device_before_mkfs (device);
- r = command (NULL, &err,
- str_mke2fs, "-F", "-t", fstype, "-J", jdev,
"-b", blocksize_s,
- device, NULL);
+ r = command (NULL, &err, str_mke2fs, "-F", "-t", fstype,
"-J", jdev, "-b",
+ blocksize_s, device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
return -1;
@@ -542,8 +539,8 @@ do_mke2fs_JL (const char *fstype, int blocksize, const char *device,
}
if (strlen (label) > EXT2_LABEL_MAX) {
- reply_with_error ("%s: ext2/3/4 labels are limited to %d bytes",
- label, EXT2_LABEL_MAX);
+ reply_with_error ("%s: ext2/3/4 labels are limited to %d bytes", label,
+ EXT2_LABEL_MAX);
return -1;
}
@@ -556,9 +553,8 @@ do_mke2fs_JL (const char *fstype, int blocksize, const char *device,
wipe_device_before_mkfs (device);
- r = command (NULL, &err,
- str_mke2fs, "-F", "-t", fstype, "-J", jdev,
"-b", blocksize_s,
- device, NULL);
+ r = command (NULL, &err, str_mke2fs, "-F", "-t", fstype,
"-J", jdev, "-b",
+ blocksize_s, device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
return -1;
@@ -590,9 +586,8 @@ do_mke2fs_JU (const char *fstype, int blocksize, const char *device,
wipe_device_before_mkfs (device);
- r = command (NULL, &err,
- str_mke2fs, "-F", "-t", fstype, "-J", jdev,
"-b", blocksize_s,
- device, NULL);
+ r = command (NULL, &err, str_mke2fs, "-F", "-t", fstype,
"-J", jdev, "-b",
+ blocksize_s, device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
return -1;
@@ -604,15 +599,10 @@ do_mke2fs_JU (const char *fstype, int blocksize, const char
*device,
/* Takes optional arguments, consult optargs_bitmask. */
int
do_tune2fs (const char *device, /* only required parameter */
- int force,
- int maxmountcount,
- int mountcount,
- const char *errorbehavior,
- int64_t group,
- int intervalbetweenchecks,
- int reservedblockspercentage,
- const char *lastmounteddirectory,
- int64_t reservedblockscount,
+ int force, int maxmountcount, int mountcount,
+ const char *errorbehavior, int64_t group,
+ int intervalbetweenchecks, int reservedblockspercentage,
+ const char *lastmounteddirectory, int64_t reservedblockscount,
int64_t user)
{
const char *argv[MAX_ARGS];
@@ -658,7 +648,8 @@ do_tune2fs (const char *device, /* only required parameter */
if (STRNEQ (errorbehavior, "continue") &&
STRNEQ (errorbehavior, "remount-ro") &&
STRNEQ (errorbehavior, "panic")) {
- reply_with_error ("invalid errorbehavior parameter: %s", errorbehavior);
+ reply_with_error ("invalid errorbehavior parameter: %s",
+ errorbehavior);
return -1;
}
ADD_ARG (argv, i, "-e");
@@ -745,8 +736,8 @@ do_tune2fs (const char *device, /* only required parameter */
static int
compare_chars (const void *vc1, const void *vc2)
{
- char c1 = * (char *) vc1;
- char c2 = * (char *) vc2;
+ char c1 = *(char *)vc1;
+ char c2 = *(char *)vc2;
return c1 - c2;
}
@@ -798,7 +789,7 @@ do_set_e2attrs (const char *filename, const char *attrs, int clear)
CLEANUP_FREE char *err = NULL;
size_t i, j;
int lowers[26], uppers[26];
- char attr_arg[26*2+1+1]; /* '+'/'-' + attrs + trailing '\0' */
+ char attr_arg[26 * 2 + 1 + 1]; /* '+'/'-' + attrs + trailing
'\0' */
if (!(optargs_bitmask & GUESTFS_SET_E2ATTRS_CLEAR_BITMASK))
attr_arg[0] = '+';
@@ -885,8 +876,8 @@ do_get_e2generation (const char *filename)
}
if (sscanf (out, "%" SCNi64, &ret) != 1) {
- reply_with_error ("cannot parse output from '%s' command: %s",
- "lsattr", out);
+ reply_with_error ("cannot parse output from '%s' command: %s",
"lsattr",
+ out);
return -1;
}
if (ret < 0) {
@@ -911,10 +902,11 @@ do_set_e2generation (const char *filename, int64_t generation)
return -1;
}
- snprintf (generation_str, sizeof generation_str,
- "%" PRIu64, (uint64_t) generation);
+ snprintf (generation_str, sizeof generation_str, "%" PRIu64,
+ (uint64_t)generation);
- r = command (NULL, &err, str_chattr, "-v", generation_str,
"--", buf, NULL);
+ r =
+ command (NULL, &err, str_chattr, "-v", generation_str, "--",
buf, NULL);
if (r == -1) {
reply_with_error ("%s: %s: %s", "chattr", filename, err);
return -1;
@@ -924,45 +916,24 @@ do_set_e2generation (const char *filename, int64_t generation)
}
int
-do_mke2fs (const char *device, /* 0 */
- int64_t blockscount,
- int64_t blocksize,
- int64_t fragsize,
- int64_t blockspergroup,
- int64_t numberofgroups, /* 5 */
- int64_t bytesperinode,
- int64_t inodesize,
- int64_t journalsize,
- int64_t numberofinodes,
- int64_t stridesize, /* 10 */
- int64_t stripewidth,
- int64_t maxonlineresize,
- int reservedblockspercentage,
- int mmpupdateinterval,
- const char *journaldevice, /* 15 */
- const char *label,
- const char *lastmounteddir,
- const char *creatoros,
- const char *fstype,
- const char *usagetype, /* 20 */
- const char *uuid,
- int forcecreate,
- int writesbandgrouponly,
- int lazyitableinit,
- int lazyjournalinit, /* 25 */
- int testfs,
- int discard,
- int quotatype,
- int extent,
- int filetype, /* 30 */
- int flexbg,
- int hasjournal,
- int journaldev,
- int largefile,
- int quota, /* 35 */
- int resizeinode,
- int sparsesuper,
- int uninitbg)
+do_mke2fs (const char *device, /* 0 */
+ int64_t blockscount, int64_t blocksize, int64_t fragsize,
+ int64_t blockspergroup, int64_t numberofgroups, /* 5 */
+ int64_t bytesperinode, int64_t inodesize, int64_t journalsize,
+ int64_t numberofinodes, int64_t stridesize, /* 10 */
+ int64_t stripewidth, int64_t maxonlineresize,
+ int reservedblockspercentage, int mmpupdateinterval,
+ const char *journaldevice, /* 15 */
+ const char *label, const char *lastmounteddir,
+ const char *creatoros, const char *fstype,
+ const char *usagetype, /* 20 */
+ const char *uuid, int forcecreate, int writesbandgrouponly,
+ int lazyitableinit, int lazyjournalinit, /* 25 */
+ int testfs, int discard, int quotatype, int extent,
+ int filetype, /* 30 */
+ int flexbg, int hasjournal, int journaldev, int largefile,
+ int quota, /* 35 */
+ int resizeinode, int sparsesuper, int uninitbg)
{
int r;
CLEANUP_FREE char *err = NULL;
@@ -1014,8 +985,8 @@ do_mke2fs (const char *device, /* 0 */
reply_with_error ("blockspergroup must be >= 0");
return -1;
}
- snprintf (blockspergroup_s, sizeof blockspergroup_s,
- "%" PRIi64, blockspergroup);
+ snprintf (blockspergroup_s, sizeof blockspergroup_s, "%" PRIi64,
+ blockspergroup);
ADD_ARG (argv, i, "-g");
ADD_ARG (argv, i, blockspergroup_s);
}
@@ -1024,8 +995,8 @@ do_mke2fs (const char *device, /* 0 */
reply_with_error ("numberofgroups must be >= 0");
return -1;
}
- snprintf (numberofgroups_s, sizeof numberofgroups_s,
- "%" PRIi64, numberofgroups);
+ snprintf (numberofgroups_s, sizeof numberofgroups_s, "%" PRIi64,
+ numberofgroups);
ADD_ARG (argv, i, "-G");
ADD_ARG (argv, i, numberofgroups_s);
}
@@ -1034,7 +1005,8 @@ do_mke2fs (const char *device, /* 0 */
reply_with_error ("bytesperinode must be >= 0");
return -1;
}
- snprintf (bytesperinode_s, sizeof bytesperinode_s, "%" PRIi64,
bytesperinode);
+ snprintf (bytesperinode_s, sizeof bytesperinode_s, "%" PRIi64,
+ bytesperinode);
ADD_ARG (argv, i, "-i");
ADD_ARG (argv, i, bytesperinode_s);
}
@@ -1052,8 +1024,9 @@ do_mke2fs (const char *device, /* 0 */
reply_with_error ("journalsize must be >= 0");
return -1;
}
- snprintf (journalsize_s, sizeof journalsize_s,
- "size=" "%" PRIi64, journalsize);
+ snprintf (journalsize_s, sizeof journalsize_s, "size="
+ "%" PRIi64,
+ journalsize);
ADD_ARG (argv, i, "-J");
ADD_ARG (argv, i, journalsize_s);
}
@@ -1123,8 +1096,8 @@ do_mke2fs (const char *device, /* 0 */
reply_with_error ("numberofinodes must be >= 0");
return -1;
}
- snprintf (numberofinodes_s, sizeof numberofinodes_s,
- "%" PRIi64, numberofinodes);
+ snprintf (numberofinodes_s, sizeof numberofinodes_s, "%" PRIi64,
+ numberofinodes);
ADD_ARG (argv, i, "-N");
ADD_ARG (argv, i, numberofinodes_s);
}
@@ -1141,7 +1114,8 @@ do_mke2fs (const char *device, /* 0 */
if (optargs_bitmask & GUESTFS_MKE2FS_FSTYPE_BITMASK) {
if (fstype) {
if (!fstype_is_extfs (fstype)) {
- reply_with_error ("%s: not a valid extended filesystem type", fstype);
+ reply_with_error ("%s: not a valid extended filesystem type",
+ fstype);
return -1;
}
@@ -1167,7 +1141,9 @@ do_mke2fs (const char *device, /* 0 */
return -1;
}
snprintf (mmpupdateinterval_s, sizeof mmpupdateinterval_s,
- "mmp_update_interval=" "%" PRIi32, mmpupdateinterval);
+ "mmp_update_interval="
+ "%" PRIi32,
+ mmpupdateinterval);
ADD_ARG (argv, i, "-E");
ADD_ARG (argv, i, mmpupdateinterval_s);
}
@@ -1176,18 +1152,20 @@ do_mke2fs (const char *device, /* 0 */
reply_with_error ("stridesize must be >= 0");
return -1;
}
- snprintf (stridesize_s, sizeof stridesize_s,
- "stride=" "%" PRIi64, stridesize);
+ snprintf (stridesize_s, sizeof stridesize_s, "stride="
+ "%" PRIi64,
+ stridesize);
ADD_ARG (argv, i, "-E");
ADD_ARG (argv, i, stridesize_s);
}
if (optargs_bitmask & GUESTFS_MKE2FS_STRIPEWIDTH_BITMASK) {
- if (stripewidth< 0) {
+ if (stripewidth < 0) {
reply_with_error ("stripewidth must be >= 0");
return -1;
}
- snprintf (stripewidth_s, sizeof stripewidth_s,
- "stripe_width=" "%" PRIi64, stripewidth);
+ snprintf (stripewidth_s, sizeof stripewidth_s, "stripe_width="
+ "%" PRIi64,
+ stripewidth);
ADD_ARG (argv, i, "-E");
ADD_ARG (argv, i, stripewidth_s);
}
@@ -1196,8 +1174,9 @@ do_mke2fs (const char *device, /* 0 */
reply_with_error ("maxonlineresize must be >= 0");
return -1;
}
- snprintf (maxonlineresize_s, sizeof maxonlineresize_s,
- "resize=" "%" PRIi64, maxonlineresize);
+ snprintf (maxonlineresize_s, sizeof maxonlineresize_s, "resize="
+ "%" PRIi64,
+ maxonlineresize);
ADD_ARG (argv, i, "-E");
ADD_ARG (argv, i, maxonlineresize_s);
}
diff --git a/daemon/fallocate.c b/daemon/fallocate.c
index f98babf..c0f44bf 100644
--- a/daemon/fallocate.c
+++ b/daemon/fallocate.c
@@ -45,7 +45,8 @@ do_fallocate64 (const char *path, int64_t len)
int fd;
CHROOT_IN;
- fd = open (path, O_WRONLY|O_CREAT|O_TRUNC|O_NOCTTY|O_CLOEXEC, 0666);
+ fd =
+ open (path, O_WRONLY | O_CREAT | O_TRUNC | O_NOCTTY | O_CLOEXEC, 0666);
CHROOT_OUT;
if (fd == -1) {
reply_with_perror ("open: %s", path);
@@ -63,7 +64,7 @@ do_fallocate64 (const char *path, int64_t len)
#else
ssize_t r;
char buf[BUFSIZ];
- const size_t len_sz = (size_t) len;
+ const size_t len_sz = (size_t)len;
size_t n;
memset (buf, 0, BUFSIZ);
diff --git a/daemon/file.c b/daemon/file.c
index 35f41d3..6e8d2e4 100644
--- a/daemon/file.c
+++ b/daemon/file.c
@@ -30,9 +30,9 @@
#include "actions.h"
#include "optgroups.h"
-GUESTFSD_EXT_CMD(str_file, file);
-GUESTFSD_EXT_CMD(str_zcat, zcat);
-GUESTFSD_EXT_CMD(str_bzcat, bzcat);
+GUESTFSD_EXT_CMD (str_file, file);
+GUESTFSD_EXT_CMD (str_zcat, zcat);
+GUESTFSD_EXT_CMD (str_bzcat, bzcat);
int
do_touch (const char *path)
@@ -59,15 +59,17 @@ do_touch (const char *path)
reply_with_perror ("lstat: %s", path);
return -1;
}
- } else {
- if (! S_ISREG (buf.st_mode)) {
- reply_with_error ("%s: touch can only be used on a regular files",
path);
+ }
+ else {
+ if (!S_ISREG (buf.st_mode)) {
+ reply_with_error ("%s: touch can only be used on a regular files",
+ path);
return -1;
}
}
CHROOT_IN;
- fd = open (path, O_WRONLY|O_CREAT|O_NOCTTY|O_CLOEXEC, 0666);
+ fd = open (path, O_WRONLY | O_CREAT | O_NOCTTY | O_CLOEXEC, 0666);
CHROOT_OUT;
if (fd == -1) {
@@ -140,7 +142,7 @@ do_chmod (int mode, const char *path)
CHROOT_OUT;
if (r == -1) {
- reply_with_perror ("%s: 0%o", path, (unsigned) mode);
+ reply_with_perror ("%s: 0%o", path, (unsigned)mode);
return -1;
}
@@ -201,7 +203,7 @@ do_write_file (const char *path, const char *content, int size)
/* Note content_len must be small because of the limits on protocol
* message size.
*/
- int content_len = (int) strlen (content);
+ int content_len = (int)strlen (content);
if (size == 0)
size = content_len;
@@ -211,7 +213,8 @@ do_write_file (const char *path, const char *content, int size)
}
CHROOT_IN;
- fd = open (path, O_WRONLY|O_TRUNC|O_CREAT|O_NOCTTY|O_CLOEXEC, 0666);
+ fd =
+ open (path, O_WRONLY | O_TRUNC | O_CREAT | O_NOCTTY | O_CLOEXEC, 0666);
CHROOT_OUT;
if (fd == -1) {
@@ -239,7 +242,8 @@ do_internal_write (const char *path, const char *content, size_t
size)
int fd;
CHROOT_IN;
- fd = open (path, O_WRONLY|O_TRUNC|O_CREAT|O_NOCTTY|O_CLOEXEC, 0666);
+ fd =
+ open (path, O_WRONLY | O_TRUNC | O_CREAT | O_NOCTTY | O_CLOEXEC, 0666);
CHROOT_OUT;
if (fd == -1) {
@@ -262,12 +266,14 @@ do_internal_write (const char *path, const char *content, size_t
size)
}
int
-do_internal_write_append (const char *path, const char *content, size_t size)
+do_internal_write_append (const char *path, const char *content,
+ size_t size)
{
int fd;
CHROOT_IN;
- fd = open (path, O_WRONLY|O_APPEND|O_CREAT|O_NOCTTY|O_CLOEXEC, 0666);
+ fd =
+ open (path, O_WRONLY | O_APPEND | O_CREAT | O_NOCTTY | O_CLOEXEC, 0666);
CHROOT_OUT;
if (fd == -1) {
@@ -314,7 +320,9 @@ pread_fd (int fd, int count, int64_t offset, size_t *size_r,
* will be caught later when we try to serialize the message.
*/
if (count >= GUESTFS_MESSAGE_MAX) {
- reply_with_error ("%s: count is too large for the protocol, use smaller
reads", display_path);
+ reply_with_error (
+ "%s: count is too large for the protocol, use smaller reads",
+ display_path);
close (fd);
return NULL;
}
@@ -353,7 +361,7 @@ do_pread (const char *path, int count, int64_t offset, size_t
*size_r)
int fd;
CHROOT_IN;
- fd = open (path, O_RDONLY|O_CLOEXEC);
+ fd = open (path, O_RDONLY | O_CLOEXEC);
CHROOT_OUT;
if (fd == -1) {
@@ -365,9 +373,10 @@ do_pread (const char *path, int count, int64_t offset, size_t
*size_r)
}
char *
-do_pread_device (const char *device, int count, int64_t offset, size_t *size_r)
+do_pread_device (const char *device, int count, int64_t offset,
+ size_t *size_r)
{
- int fd = open (device, O_RDONLY|O_CLOEXEC);
+ int fd = open (device, O_RDONLY | O_CLOEXEC);
if (fd == -1) {
reply_with_perror ("open: %s", device);
return NULL;
@@ -410,7 +419,8 @@ pwrite_fd (int fd, const char *content, size_t size, int64_t offset,
}
int
-do_pwrite (const char *path, const char *content, size_t size, int64_t offset)
+do_pwrite (const char *path, const char *content, size_t size,
+ int64_t offset)
{
int fd;
@@ -420,7 +430,7 @@ do_pwrite (const char *path, const char *content, size_t size, int64_t
offset)
}
CHROOT_IN;
- fd = open (path, O_WRONLY|O_CLOEXEC);
+ fd = open (path, O_WRONLY | O_CLOEXEC);
CHROOT_OUT;
if (fd == -1) {
@@ -440,7 +450,7 @@ do_pwrite_device (const char *device, const char *content, size_t
size,
return -1;
}
- int fd = open (device, O_WRONLY|O_CLOEXEC);
+ int fd = open (device, O_WRONLY | O_CLOEXEC);
if (fd == -1) {
reply_with_perror ("open: %s", device);
return -1;
@@ -475,7 +485,7 @@ do_file (const char *path)
return NULL;
}
- if (! S_ISREG (statbuf.st_mode)) {
+ if (!S_ISREG (statbuf.st_mode)) {
char *ret;
if (S_ISDIR (statbuf.st_mode))
@@ -516,17 +526,17 @@ do_file (const char *path)
/* We need to remove the trailing \n from output of file(1). */
size_t len = strlen (out);
- if (len > 0 && out[len-1] == '\n')
+ if (len > 0 && out[len - 1] == '\n')
out[--len] = '\0';
/* Some upstream versions of file add a space at the end of the
* output. This is fixed in the Fedora version, but we might as
* well fix it here too. (RHBZ#928995).
*/
- if (len > 0 && out[len-1] == ' ')
+ if (len > 0 && out[len - 1] == ' ')
out[--len] = '\0';
- return out; /* caller frees */
+ return out; /* caller frees */
}
/* zcat | file */
@@ -574,8 +584,8 @@ do_zfile (const char *method, const char *path)
}
len = strlen (line);
- if (len > 0 && line[len-1] == '\n')
- line[len-1] = '\0';
+ if (len > 0 && line[len - 1] == '\n')
+ line[len - 1] = '\0';
return strdup (line);
}
@@ -587,7 +597,7 @@ do_filesize (const char *path)
struct stat buf;
CHROOT_IN;
- r = stat (path, &buf); /* follow symlinks */
+ r = stat (path, &buf); /* follow symlinks */
CHROOT_OUT;
if (r == -1) {
@@ -599,7 +609,8 @@ do_filesize (const char *path)
}
int
-do_copy_attributes (const char *src, const char *dest, int all, int mode, int
xattributes, int ownership)
+do_copy_attributes (const char *src, const char *dest, int all, int mode,
+ int xattributes, int ownership)
{
int r;
struct stat srcstat, deststat;
@@ -648,8 +659,8 @@ do_copy_attributes (const char *src, const char *dest, int all, int
mode, int xa
}
}
- if (ownership &&
- (srcstat.st_uid != deststat.st_uid || srcstat.st_gid != deststat.st_gid)) {
+ if (ownership && (srcstat.st_uid != deststat.st_uid ||
+ srcstat.st_gid != deststat.st_gid)) {
CHROOT_IN;
r = chown (dest, srcstat.st_uid, srcstat.st_gid);
CHROOT_OUT;
diff --git a/daemon/fill.c b/daemon/fill.c
index 2d19df5..44bc6f2 100644
--- a/daemon/fill.c
+++ b/daemon/fill.c
@@ -52,7 +52,7 @@ do_fill (int c, int len, const char *path)
reply_with_error ("%d: length is < 0", len);
return -1;
}
- len_sz = (size_t) len;
+ len_sz = (size_t)len;
CHROOT_IN;
fd = open (path, O_WRONLY | O_CREAT | O_NOCTTY, 0666);
@@ -72,7 +72,7 @@ do_fill (int c, int len, const char *path)
return -1;
}
n += r;
- notify_progress ((uint64_t) n, (uint64_t) len_sz);
+ notify_progress ((uint64_t)n, (uint64_t)len_sz);
}
if (close (fd) == -1) {
@@ -97,7 +97,7 @@ do_fill_pattern (const char *pattern, int len, const char *path)
reply_with_error ("%d: length is < 0", len);
return -1;
}
- size_t len_sz = (size_t) len;
+ size_t len_sz = (size_t)len;
int fd;
CHROOT_IN;
@@ -119,7 +119,7 @@ do_fill_pattern (const char *pattern, int len, const char *path)
return -1;
}
n += wrlen;
- notify_progress ((uint64_t) n, (uint64_t) len_sz);
+ notify_progress ((uint64_t)n, (uint64_t)len_sz);
}
if (close (fd) == -1) {
@@ -145,7 +145,7 @@ do_fill_dir (const char *dir, int n)
}
CHROOT_IN;
- fd = open (filename, O_WRONLY|O_CREAT|O_NOCTTY|O_CLOEXEC, 0666);
+ fd = open (filename, O_WRONLY | O_CREAT | O_NOCTTY | O_CLOEXEC, 0666);
CHROOT_OUT;
if (fd == -1) {
diff --git a/daemon/find.c b/daemon/find.c
index b47caa8..a34968e 100644
--- a/daemon/find.c
+++ b/daemon/find.c
@@ -30,7 +30,7 @@
#include "daemon.h"
#include "actions.h"
-GUESTFSD_EXT_CMD(str_find, find);
+GUESTFSD_EXT_CMD (str_find, find);
static int
input_to_nul (FILE *fp, char *buf, size_t maxlen)
@@ -126,18 +126,18 @@ do_find0 (const char *dir)
if (ferror (fp)) {
fprintf (stderr, "fgetc: %s: %m\n", dir);
- send_file_end (1); /* Cancel. */
+ send_file_end (1); /* Cancel. */
pclose (fp);
return -1;
}
if (pclose (fp) != 0) {
fprintf (stderr, "pclose: %s: %m\n", dir);
- send_file_end (1); /* Cancel. */
+ send_file_end (1); /* Cancel. */
return -1;
}
- if (send_file_end (0)) /* Normal end of file. */
+ if (send_file_end (0)) /* Normal end of file. */
return -1;
return 0;
diff --git a/daemon/findfs.c b/daemon/findfs.c
index f441370..3bcfc03 100644
--- a/daemon/findfs.c
+++ b/daemon/findfs.c
@@ -26,7 +26,7 @@
#include "daemon.h"
#include "actions.h"
-GUESTFSD_EXT_CMD(str_findfs, findfs);
+GUESTFSD_EXT_CMD (str_findfs, findfs);
static char *
findfs (const char *tag, const char *label_or_uuid)
@@ -59,8 +59,8 @@ findfs (const char *tag, const char *label_or_uuid)
/* Trim trailing \n if present. */
len = strlen (out);
- if (len > 0 && out[len-1] == '\n')
- out[len-1] = '\0';
+ if (len > 0 && out[len - 1] == '\n')
+ out[len - 1] = '\0';
if (STRPREFIX (out, "/dev/mapper/") || STRPREFIX (out, "/dev/dm-"))
{
char *canonical;
@@ -78,7 +78,7 @@ findfs (const char *tag, const char *label_or_uuid)
*/
}
- return out; /* caller frees */
+ return out; /* caller frees */
}
char *
diff --git a/daemon/fs-min-size.c b/daemon/fs-min-size.c
index ba0f739..a1ebf2b 100644
--- a/daemon/fs-min-size.c
+++ b/daemon/fs-min-size.c
@@ -25,10 +25,10 @@
#include "daemon.h"
#include "actions.h"
-static char*
+static char *
get_mount_point (const char *device)
{
- CLEANUP_FREE_STRING_LIST char **mountpoints = do_mountpoints();
+ CLEANUP_FREE_STRING_LIST char **mountpoints = do_mountpoints ();
size_t i;
char *path;
@@ -81,7 +81,8 @@ do_vfs_minimum_size (const mountable_t *mountable)
}
else
- NOT_SUPPORTED (-1, "don't know how to get minimum size of '%s'
filesystems",
+ NOT_SUPPORTED (-1,
+ "don't know how to get minimum size of '%s'
filesystems",
vfs_type);
return r;
diff --git a/daemon/fsck.c b/daemon/fsck.c
index 540f779..546e39d 100644
--- a/daemon/fsck.c
+++ b/daemon/fsck.c
@@ -26,7 +26,7 @@
#include "daemon.h"
#include "actions.h"
-GUESTFSD_EXT_CMD(str_fsck, fsck);
+GUESTFSD_EXT_CMD (str_fsck, fsck);
int
do_fsck (const char *fstype, const char *device)
diff --git a/daemon/fstrim.c b/daemon/fstrim.c
index 1ad3630..a57d081 100644
--- a/daemon/fstrim.c
+++ b/daemon/fstrim.c
@@ -30,7 +30,7 @@
#define MAX_ARGS 64
-GUESTFSD_EXT_CMD(str_fstrim, fstrim);
+GUESTFSD_EXT_CMD (str_fstrim, fstrim);
int
optgroup_fstrim_available (void)
@@ -40,8 +40,8 @@ optgroup_fstrim_available (void)
/* Takes optional arguments, consult optargs_bitmask. */
int
-do_fstrim (const char *path,
- int64_t offset, int64_t length, int64_t minimumfreeextent)
+do_fstrim (const char *path, int64_t offset, int64_t length,
+ int64_t minimumfreeextent)
{
const char *argv[MAX_ARGS];
size_t i = 0;
@@ -90,7 +90,8 @@ do_fstrim (const char *path,
ADD_ARG (argv, i, mfe_s);
}
- /* When running in debug mode, use -v, capture stdout and print it below. */
+ /* When running in debug mode, use -v, capture stdout and print it below.
+ */
if (verbose)
ADD_ARG (argv, i, "-v");
diff --git a/daemon/glob.c b/daemon/glob.c
index a22fd33..cee2c1e 100644
--- a/daemon/glob.c
+++ b/daemon/glob.c
@@ -29,12 +29,12 @@ char **
do_glob_expand (const char *pattern, int directoryslash)
{
int r;
- glob_t buf = { .gl_pathc = 0, .gl_pathv = NULL, .gl_offs = 0 };
+ glob_t buf = {.gl_pathc = 0, .gl_pathv = NULL, .gl_offs = 0 };
int flags = GLOB_BRACE | GLOB_MARK;
/* GLOB_MARK is default, unless the user explicitly disabled it. */
- if ((optargs_bitmask & GUESTFS_GLOB_EXPAND_DIRECTORYSLASH_BITMASK)
- && !directoryslash) {
+ if ((optargs_bitmask & GUESTFS_GLOB_EXPAND_DIRECTORYSLASH_BITMASK) &&
+ !directoryslash) {
flags &= ~GLOB_MARK;
}
@@ -43,7 +43,7 @@ do_glob_expand (const char *pattern, int directoryslash)
r = glob (pattern, flags, NULL, &buf);
CHROOT_OUT;
- if (r == GLOB_NOMATCH) { /* Return an empty list instead of an error. */
+ if (r == GLOB_NOMATCH) { /* Return an empty list instead of an error. */
char **rv;
rv = malloc (sizeof (char *) * 1);
@@ -52,7 +52,7 @@ do_glob_expand (const char *pattern, int directoryslash)
return NULL;
}
rv[0] = NULL;
- return rv; /* Caller frees. */
+ return rv; /* Caller frees. */
}
if (r != 0) {
diff --git a/daemon/grep.c b/daemon/grep.c
index 6dd9a99..61a0f21 100644
--- a/daemon/grep.c
+++ b/daemon/grep.c
@@ -31,8 +31,8 @@
#define MAX_ARGS 64
static char **
-grep (const char *regex, const char *path,
- int extended, int fixed, int insensitive, int compressed)
+grep (const char *regex, const char *path, int extended, int fixed,
+ int insensitive, int compressed)
{
const char *argv[MAX_ARGS];
size_t i = 0;
@@ -41,7 +41,8 @@ grep (const char *regex, const char *path,
char **lines;
if (extended && fixed) {
- reply_with_error ("can't use 'extended' and 'fixed' flags at
the same time");
+ reply_with_error (
+ "can't use 'extended' and 'fixed' flags at the same
time");
return NULL;
}
@@ -63,7 +64,7 @@ grep (const char *regex, const char *path,
ADD_ARG (argv, i, NULL);
CHROOT_IN;
- fd = open (path, O_RDONLY|O_CLOEXEC);
+ fd = open (path, O_RDONLY | O_CLOEXEC);
CHROOT_OUT;
if (fd == -1) {
@@ -82,15 +83,16 @@ grep (const char *regex, const char *path,
}
lines = split_lines (out);
- if (lines == NULL) return NULL;
+ if (lines == NULL)
+ return NULL;
return lines;
}
/* Takes optional arguments, consult optargs_bitmask. */
char **
-do_grep (const char *regex, const char *path,
- int extended, int fixed, int insensitive, int compressed)
+do_grep (const char *regex, const char *path, int extended, int fixed,
+ int insensitive, int compressed)
{
if (!(optargs_bitmask & GUESTFS_GREP_EXTENDED_BITMASK))
extended = 0;
diff --git a/daemon/grub.c b/daemon/grub.c
index 06324b3..4fa7980 100644
--- a/daemon/grub.c
+++ b/daemon/grub.c
@@ -26,7 +26,7 @@
#include "actions.h"
#include "optgroups.h"
-GUESTFSD_EXT_CMD(str_grub_install, grub-install);
+GUESTFSD_EXT_CMD (str_grub_install, grub - install);
int
optgroup_grub_available (void)
@@ -45,8 +45,8 @@ do_grub_install (const char *root, const char *device)
return -1;
}
- r = command (verbose ? &out : NULL, &err,
- str_grub_install, buf, device, NULL);
+ r = command (verbose ? &out : NULL, &err, str_grub_install, buf, device,
+ NULL);
if (r == -1) {
if (verbose)
diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c
index b76b5a4..4503bef 100644
--- a/daemon/guestfsd.c
+++ b/daemon/guestfsd.c
@@ -19,7 +19,7 @@
#include <config.h>
#ifdef HAVE_WINDOWS_H
-# include <windows.h>
+#include <windows.h>
#endif
#include <stdio.h>
@@ -45,7 +45,7 @@
#include <termios.h>
#ifdef HAVE_PRINTF_H
-# include <printf.h>
+#include <printf.h>
#endif
#include <augeas.h>
@@ -57,16 +57,16 @@
#include "daemon.h"
-GUESTFSD_EXT_CMD(str_udevadm, udevadm);
-GUESTFSD_EXT_CMD(str_uuidgen, uuidgen);
+GUESTFSD_EXT_CMD (str_udevadm, udevadm);
+GUESTFSD_EXT_CMD (str_uuidgen, uuidgen);
#ifndef MAX
-# define MAX(a,b) ((a)>(b)?(a):(b))
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif
/* Not the end of the world if this open flag is not defined. */
#ifndef O_CLOEXEC
-# define O_CLOEXEC 0
+#define O_CLOEXEC 0
#endif
/* If root device is an ext2 filesystem, this is the major and minor.
@@ -79,13 +79,18 @@ int verbose = 0;
int enable_network = 0;
static void makeraw (const char *channel, int fd);
-static int print_shell_quote (FILE *stream, const struct printf_info *info, const void
*const *args);
-static int print_sysroot_shell_quote (FILE *stream, const struct printf_info *info, const
void *const *args);
+static int print_shell_quote (FILE *stream, const struct printf_info *info,
+ const void *const *args);
+static int print_sysroot_shell_quote (FILE *stream,
+ const struct printf_info *info,
+ const void *const *args);
#ifdef HAVE_REGISTER_PRINTF_SPECIFIER
-static int print_arginfo (const struct printf_info *info, size_t n, int *argtypes, int
*size);
+static int print_arginfo (const struct printf_info *info, size_t n,
+ int *argtypes, int *size);
#else
#ifdef HAVE_REGISTER_PRINTF_FUNCTION
-static int print_arginfo (const struct printf_info *info, size_t n, int *argtypes);
+static int print_arginfo (const struct printf_info *info, size_t n,
+ int *argtypes);
#else
#error "HAVE_REGISTER_PRINTF_{SPECIFIER|FUNCTION} not defined"
#endif
@@ -101,7 +106,7 @@ winsock_init (void)
r = gl_sockets_startup (SOCKETS_2_2);
return r == 0 ? 0 : -1;
}
-#else /* !WIN32 */
+#else /* !WIN32 */
static int
winsock_init (void)
{
@@ -128,8 +133,7 @@ const char *program_name = "guestfsd";
static void
usage (void)
{
- fprintf (stderr,
- "guestfsd [-r] [-v|--verbose]\n");
+ fprintf (stderr, "guestfsd [-r] [-v|--verbose]\n");
}
int
@@ -137,12 +141,9 @@ main (int argc, char *argv[])
{
static const char *options = "c:lnrtv?";
static const struct option long_options[] = {
- { "help", 0, 0, '?' },
- { "channel", 1, 0, 'c' },
- { "listen", 0, 0, 'l' },
- { "network", 0, 0, 'n' },
- { "test", 0, 0, 't' },
- { "verbose", 0, 0, 'v' },
+ { "help", 0, 0, '?' }, { "channel", 1, 0, 'c'
},
+ { "listen", 0, 0, 'l' }, { "network", 0, 0, 'n'
},
+ { "test", 0, 0, 't' }, { "verbose", 0, 0, 'v'
},
{ 0, 0, 0, 0 }
};
int c;
@@ -183,7 +184,8 @@ main (int argc, char *argv[])
for (;;) {
c = getopt_long (argc, argv, options, long_options, NULL);
- if (c == -1) break;
+ if (c == -1)
+ break;
switch (c) {
case 'c':
@@ -198,16 +200,16 @@ main (int argc, char *argv[])
enable_network = 1;
break;
- /* The -r flag is used when running standalone. It changes
- * several aspects of the daemon.
- */
+ /* The -r flag is used when running standalone. It changes
+ * several aspects of the daemon.
+ */
case 'r':
sysroot = "";
sysroot_len = 0;
autosync_umount = 0;
break;
- /* Undocumented --test option used for testing guestfsd. */
+ /* Undocumented --test option used for testing guestfsd. */
case 't':
test_mode = 1;
break;
@@ -221,8 +223,8 @@ main (int argc, char *argv[])
exit (EXIT_SUCCESS);
default:
- error (EXIT_FAILURE, 0,
- "unexpected command line option 0x%x\n", (unsigned) c);
+ error (EXIT_FAILURE, 0, "unexpected command line option 0x%x\n",
+ (unsigned)c);
}
}
@@ -242,7 +244,7 @@ main (int argc, char *argv[])
#endif
#ifdef WIN32
-# define setenv(n,v,f) _putenv(n "=" v)
+#define setenv(n, v, f) _putenv (n "=" v)
#endif
/* Set up a basic environment. After we are called by /init the
* environment is essentially empty.
@@ -281,25 +283,26 @@ main (int argc, char *argv[])
int sock;
if (!listen_mode) {
if (STRPREFIX (channel, "fd:")) {
- if (sscanf (channel+3, "%d", &sock) != 1)
+ if (sscanf (channel + 3, "%d", &sock) != 1)
error (EXIT_FAILURE, 0, "cannot parse --channel %s", channel);
}
else {
- sock = open (channel, O_RDWR|O_CLOEXEC);
+ sock = open (channel, O_RDWR | O_CLOEXEC);
if (sock == -1) {
- fprintf (stderr,
- "\n"
- "Failed to connect to virtio-serial channel.\n"
- "\n"
- "This is a fatal error and the appliance will now exit.\n"
- "\n"
- "Usually this error is caused by either QEMU or the
appliance\n"
- "kernel not supporting the vmchannel method that the\n"
- "libguestfs library chose to use. Please run\n"
- "'libguestfs-test-tool' and provide the complete,
unedited\n"
- "output to the libguestfs developers, either in a bug
report\n"
- "or on the libguestfs redhat com mailing list.\n"
- "\n");
+ fprintf (
+ stderr,
+ "\n"
+ "Failed to connect to virtio-serial channel.\n"
+ "\n"
+ "This is a fatal error and the appliance will now exit.\n"
+ "\n"
+ "Usually this error is caused by either QEMU or the appliance\n"
+ "kernel not supporting the vmchannel method that the\n"
+ "libguestfs library chose to use. Please run\n"
+ "'libguestfs-test-tool' and provide the complete,
unedited\n"
+ "output to the libguestfs developers, either in a bug report\n"
+ "or on the libguestfs redhat com mailing list.\n"
+ "\n");
error (EXIT_FAILURE, errno, "open: %s", channel);
}
}
@@ -307,15 +310,15 @@ main (int argc, char *argv[])
else {
struct sockaddr_un addr;
- sock = socket (AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0);
+ sock = socket (AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
if (sock == -1)
error (EXIT_FAILURE, errno, "socket");
addr.sun_family = AF_UNIX;
- if (strlen (channel) > UNIX_PATH_MAX-1)
+ if (strlen (channel) > UNIX_PATH_MAX - 1)
error (EXIT_FAILURE, 0, "%s: socket path is too long", channel);
strcpy (addr.sun_path, channel);
- if (bind (sock, (struct sockaddr *) &addr, sizeof addr) == -1)
+ if (bind (sock, (struct sockaddr *)&addr, sizeof addr) == -1)
error (EXIT_FAILURE, errno, "bind: %s", channel);
if (listen (sock, 4) == -1)
@@ -388,7 +391,8 @@ makeraw (const char *channel, int fd)
static int
is_root_device_stat (struct stat *statbuf)
{
- if (statbuf->st_rdev == root_device) return 1;
+ if (statbuf->st_rdev == root_device)
+ return 1;
return 0;
}
@@ -584,7 +588,8 @@ count_strings (char *const *argv)
return argc;
}
-/*
http://graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2 */
+/*
http://graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2
+ */
int
is_power_of_2 (unsigned long v)
{
@@ -594,8 +599,8 @@ is_power_of_2 (unsigned long v)
static int
compare (const void *vp1, const void *vp2)
{
- char * const *p1 = (char * const *) vp1;
- char * const *p2 = (char * const *) vp2;
+ char *const *p1 = (char *const *)vp1;
+ char *const *p2 = (char *const *)vp2;
return strcmp (*p1, *p2);
}
@@ -693,8 +698,8 @@ compare_device_names (const char *a, const char *b)
static int
compare_device_names_vp (const void *vp1, const void *vp2)
{
- char * const *p1 = (char * const *) vp1;
- char * const *p2 = (char * const *) vp2;
+ char *const *p1 = (char *const *)vp1;
+ char *const *p2 = (char *const *)vp2;
return compare_device_names (*p1, *p2);
}
@@ -835,8 +840,8 @@ trim (char *str)
{
size_t len = strlen (str);
- while (len > 0 && c_isspace (str[len-1])) {
- str[len-1] = '\0';
+ while (len > 0 && c_isspace (str[len - 1])) {
+ str[len - 1] = '\0';
len--;
}
@@ -846,7 +851,7 @@ trim (char *str)
len--;
}
- memmove (str, p, len+1);
+ memmove (str, p, len + 1);
}
/* printf helper function so we can use %Q ("quoted") and %R to print
@@ -858,26 +863,25 @@ print_shell_quote (FILE *stream,
const struct printf_info *info ATTRIBUTE_UNUSED,
const void *const *args)
{
-#define SAFE(c) (c_isalnum((c)) || \
- (c) == '/' || (c) == '-' || (c) == '_' || (c) ==
'.')
+#define SAFE(c) \
+ (c_isalnum ((c)) || (c) == '/' || (c) == '-' || (c) == '_' ||
(c) == '.')
int i, len;
- const char *str = *((const char **) (args[0]));
+ const char *str = *((const char **)(args[0]));
for (i = len = 0; str[i]; ++i) {
if (!SAFE (str[i])) {
putc ('\\', stream);
- len ++;
+ len++;
}
putc (str[i], stream);
- len ++;
+ len++;
}
return len;
}
static int
-print_sysroot_shell_quote (FILE *stream,
- const struct printf_info *info,
+print_sysroot_shell_quote (FILE *stream, const struct printf_info *info,
const void *const *args)
{
fputs (sysroot, stream);
@@ -886,8 +890,8 @@ print_sysroot_shell_quote (FILE *stream,
#ifdef HAVE_REGISTER_PRINTF_SPECIFIER
static int
-print_arginfo (const struct printf_info *info ATTRIBUTE_UNUSED,
- size_t n, int *argtypes, int *size)
+print_arginfo (const struct printf_info *info ATTRIBUTE_UNUSED, size_t n,
+ int *argtypes, int *size)
{
if (n > 0) {
argtypes[0] = PA_STRING;
@@ -925,7 +929,7 @@ device_name_translation (const char *device)
int fd;
char *ret;
- fd = open (device, O_RDONLY|O_CLOEXEC);
+ fd = open (device, O_RDONLY | O_CLOEXEC);
if (fd >= 0) {
close (fd);
return strdup (device);
@@ -937,12 +941,12 @@ device_name_translation (const char *device)
/* If the name begins with "/dev/sd" then try the alternatives. */
if (!STRPREFIX (device, "/dev/sd"))
return NULL;
- device += 7; /* device == "a1" etc. */
+ device += 7; /* device == "a1" etc. */
/* /dev/vd (virtio-blk) */
if (asprintf (&ret, "/dev/vd%s", device) == -1)
return NULL;
- fd = open (ret, O_RDONLY|O_CLOEXEC);
+ fd = open (ret, O_RDONLY | O_CLOEXEC);
if (fd >= 0) {
close (fd);
return ret;
@@ -952,7 +956,7 @@ device_name_translation (const char *device)
/* /dev/hd (old IDE driver) */
if (asprintf (&ret, "/dev/hd%s", device) == -1)
return NULL;
- fd = open (ret, O_RDONLY|O_CLOEXEC);
+ fd = open (ret, O_RDONLY | O_CLOEXEC);
if (fd >= 0) {
close (fd);
return ret;
@@ -962,7 +966,7 @@ device_name_translation (const char *device)
/* User-Mode Linux */
if (asprintf (&ret, "/dev/ubd%s", device) == -1)
return NULL;
- fd = open (ret, O_RDONLY|O_CLOEXEC);
+ fd = open (ret, O_RDONLY | O_CLOEXEC);
if (fd >= 0) {
close (fd);
return ret;
@@ -1022,8 +1026,7 @@ parse_btrfsvol (const char *desc_orig, mountable_t *mountable)
return -1;
}
- if (!S_ISDIR (statbuf.st_mode) &&
- !is_root_device_stat (&statbuf)) {
+ if (!S_ISDIR (statbuf.st_mode) && !is_root_device_stat (&statbuf)) {
volume = slash + 1;
break;
}
@@ -1031,9 +1034,11 @@ parse_btrfsvol (const char *desc_orig, mountable_t *mountable)
*slash = '/';
}
- if (!device) return -1;
+ if (!device)
+ return -1;
- if (!volume) return -1;
+ if (!volume)
+ return -1;
mountable->volume = strdup (volume);
if (!mountable->volume) {
@@ -1063,8 +1068,8 @@ mountable_to_string (const mountable_t *mountable)
return strdup (mountable->device);
case MOUNTABLE_BTRFSVOL:
- if (asprintf (&desc, "btrfsvol:%s/%s",
- mountable->device, mountable->volume) == -1)
+ if (asprintf (&desc, "btrfsvol:%s/%s", mountable->device,
+ mountable->volume) == -1)
return NULL;
return desc;
@@ -1136,13 +1141,13 @@ random_name (char *template)
unsigned char c;
char *p;
- fd = open ("/dev/urandom", O_RDONLY|O_CLOEXEC);
+ fd = open ("/dev/urandom", O_RDONLY | O_CLOEXEC);
if (fd == -1)
return -1;
p = strrchr (template, '/');
if (p == NULL)
- abort (); /* internal error - bad template */
+ abort (); /* internal error - bad template */
while (*p) {
if (*p == 'X') {
@@ -1174,8 +1179,8 @@ udev_settle (void)
char cmd[80];
int r;
- snprintf (cmd, sizeof cmd, "%s%s settle",
- str_udevadm, verbose ? " --debug" : "");
+ snprintf (cmd, sizeof cmd, "%s%s settle", str_udevadm,
+ verbose ? " --debug" : "");
if (verbose)
printf ("%s\n", cmd);
r = system (cmd);
@@ -1200,5 +1205,4 @@ get_random_uuid (void)
/* caller free */
return out;
-
}
diff --git a/daemon/headtail.c b/daemon/headtail.c
index 1614074..2018099 100644
--- a/daemon/headtail.c
+++ b/daemon/headtail.c
@@ -29,14 +29,15 @@
#include "actions.h"
static char **
-headtail (const char *prog, const char *flag, const char *n, const char *path)
+headtail (const char *prog, const char *flag, const char *n,
+ const char *path)
{
CLEANUP_FREE char *out = NULL, *err = NULL;
int fd, flags, r;
char **lines;
CHROOT_IN;
- fd = open (path, O_RDONLY|O_CLOEXEC);
+ fd = open (path, O_RDONLY | O_CLOEXEC);
CHROOT_OUT;
if (fd == -1) {
@@ -58,7 +59,8 @@ headtail (const char *prog, const char *flag, const char *n, const char
*path)
#endif
lines = split_lines (out);
- if (lines == NULL) return NULL;
+ if (lines == NULL)
+ return NULL;
return lines;
}
diff --git a/daemon/hexdump.c b/daemon/hexdump.c
index 3afa48f..310d5d2 100644
--- a/daemon/hexdump.c
+++ b/daemon/hexdump.c
@@ -35,7 +35,7 @@ do_hexdump (const char *path)
CLEANUP_FREE char *err = NULL;
CHROOT_IN;
- fd = open (path, O_RDONLY|O_CLOEXEC);
+ fd = open (path, O_RDONLY | O_CLOEXEC);
CHROOT_OUT;
if (fd == -1) {
@@ -51,5 +51,5 @@ do_hexdump (const char *path)
return NULL;
}
- return out; /* caller frees */
+ return out; /* caller frees */
}
diff --git a/daemon/hivex.c b/daemon/hivex.c
index b47329e..b7c9606 100644
--- a/daemon/hivex.c
+++ b/daemon/hivex.c
@@ -57,14 +57,15 @@ hivex_finalize (void)
}
}
-#define NEED_HANDLE(errcode) \
- do { \
- if (!h) { \
- reply_with_error ("%s: you must call 'hivex-open' first to initialize
the hivex handle", __func__); \
- return (errcode); \
- } \
- } \
- while (0)
+#define NEED_HANDLE(errcode) \
+ do { \
+ if (!h) { \
+ reply_with_error ("%s: you must call 'hivex-open' first to " \
+ "initialize the hivex handle", \
+ __func__); \
+ return (errcode); \
+ } \
+ } while (0)
/* Takes optional arguments, consult optargs_bitmask. */
int
@@ -257,7 +258,7 @@ do_hivex_node_values (int64_t nodeh)
}
for (i = 0; i < len; ++i)
- ret->guestfs_int_hivex_value_list_val[i].hivex_value_h = (int64_t) r[i];
+ ret->guestfs_int_hivex_value_list_val[i].hivex_value_h = (int64_t)r[i];
return ret;
}
@@ -396,12 +397,12 @@ do_hivex_node_delete_child (int64_t nodeh)
}
int
-do_hivex_node_set_value (int64_t nodeh,
- const char *key, int64_t t,
+do_hivex_node_set_value (int64_t nodeh, const char *key, int64_t t,
const char *val, size_t val_size)
{
- const hive_set_value v =
- { .key = (char *) key, .t = t, .len = val_size, .value = (char *) val };
+ const hive_set_value v = {
+ .key = (char *)key, .t = t, .len = val_size, .value = (char *)val
+ };
NEED_HANDLE (-1);
diff --git a/daemon/hotplug.c b/daemon/hotplug.c
index 234f51e..9eaecfd 100644
--- a/daemon/hotplug.c
+++ b/daemon/hotplug.c
@@ -29,7 +29,7 @@
#include "daemon.h"
#include "actions.h"
-#define HOT_ADD_TIMEOUT 30 /* seconds */
+#define HOT_ADD_TIMEOUT 30 /* seconds */
#define HOT_REMOVE_TIMEOUT HOT_ADD_TIMEOUT
static void
@@ -77,7 +77,7 @@ do_internal_hot_add_drive (const char *label)
return -1;
}
-GUESTFSD_EXT_CMD(str_fuser, fuser);
+GUESTFSD_EXT_CMD (str_fuser, fuser);
/* This function is called before a drive is hot-unplugged. */
int
@@ -108,7 +108,8 @@ do_internal_hot_remove_drive_precheck (const char *label)
*/
if (r == 0) {
reply_with_error ("disk with label '%s' is in use "
- "(eg. mounted or belongs to a volume group)", label);
+ "(eg. mounted or belongs to a volume group)",
+ label);
/* Useful for debugging when a drive cannot be unplugged. */
if (verbose)
diff --git a/daemon/htonl.c b/daemon/htonl.c
index c9f1af0..329d397 100644
--- a/daemon/htonl.c
+++ b/daemon/htonl.c
@@ -31,12 +31,10 @@
#ifndef HAVE_NTOHL
-#undef htonl
-#undef ntohl
+#undef htonl
+#undef ntohl
-uint32_t
-htonl (x)
- uint32_t x;
+uint32_t htonl (x) uint32_t x;
{
#if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && defined(LITTLE_ENDIAN)
#if BYTE_ORDER == BIG_ENDIAN
@@ -44,25 +42,27 @@ htonl (x)
#elif BYTE_ORDER == LITTLE_ENDIAN
return bswap_32 (x);
#else
-# error "What kind of system is this?"
+#error "What kind of system is this?"
#endif
#else
#error "BYTE_ORDER/BIG_ENDIAN/LITTLE_ENDIAN are not defined"
#endif
}
-uint32_t ntohl (uint32_t x) { return htonl (x); }
+uint32_t
+ntohl (uint32_t x)
+{
+ return htonl (x);
+}
#endif /* !HAVE_NTOHL */
#ifndef HAVE_NTOHS
-#undef htons
-#undef ntohs
+#undef htons
+#undef ntohs
-uint16_t
-htons (x)
- uint16_t x;
+uint16_t htons (x) uint16_t x;
{
#if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && defined(LITTLE_ENDIAN)
#if BYTE_ORDER == BIG_ENDIAN
@@ -70,13 +70,17 @@ htons (x)
#elif BYTE_ORDER == LITTLE_ENDIAN
return bswap_16 (x);
#else
-# error "What kind of system is this?"
+#error "What kind of system is this?"
#endif
#else
#error "BYTE_ORDER/BIG_ENDIAN/LITTLE_ENDIAN are not defined"
#endif
}
-uint16_t ntohs (uint16_t x) { return htons (x); }
+uint16_t
+ntohs (uint16_t x)
+{
+ return htons (x);
+}
#endif /* !HAVE_NTOHS */
diff --git a/daemon/initrd.c b/daemon/initrd.c
index c9fc2dd..eec98c4 100644
--- a/daemon/initrd.c
+++ b/daemon/initrd.c
@@ -31,8 +31,8 @@
#include "daemon.h"
#include "actions.h"
-GUESTFSD_EXT_CMD(str_zcat, zcat);
-GUESTFSD_EXT_CMD(str_cpio, cpio);
+GUESTFSD_EXT_CMD (str_zcat, zcat);
+GUESTFSD_EXT_CMD (str_cpio, cpio);
char **
do_initrd_list (const char *path)
@@ -46,7 +46,8 @@ do_initrd_list (const char *path)
int ret;
/* "zcat /sysroot/<path> | cpio --quiet -it", but path must be quoted.
*/
- if (asprintf_nowarn (&cmd, "%s %R | %s --quiet -it", str_zcat, path,
str_cpio) == -1) {
+ if (asprintf_nowarn (&cmd, "%s %R | %s --quiet -it", str_zcat, path,
+ str_cpio) == -1) {
reply_with_perror ("asprintf");
return NULL;
}
@@ -62,8 +63,8 @@ do_initrd_list (const char *path)
allocsize = 0;
while ((len = getline (&filename, &allocsize, fp)) != -1) {
- if (len > 0 && filename[len-1] == '\n')
- filename[len-1] = '\0';
+ if (len > 0 && filename[len - 1] == '\n')
+ filename[len - 1] = '\0';
if (add_string (&filenames, filename) == -1) {
pclose (fp);
return NULL;
@@ -111,7 +112,8 @@ do_initrd_cat (const char *path, const char *filename, size_t
*size_r)
* (eg. if the named file does not exist in the cpio archive) --
* cpio is silent in this case.
*/
- /* "zcat /sysroot/<path> | cpio --quiet -id file", but paths must be
quoted */
+ /* "zcat /sysroot/<path> | cpio --quiet -id file", but paths must be
+ * quoted */
if (asprintf_nowarn (&cmd, "cd %Q && zcat %R | cpio --quiet -id
%Q",
tmpdir, path, filename) == -1) {
reply_with_perror ("asprintf");
@@ -140,7 +142,7 @@ do_initrd_cat (const char *path, const char *filename, size_t
*size_r)
}
/* See if we got a file. */
- fd = open (fullpath, O_RDONLY|O_CLOEXEC);
+ fd = open (fullpath, O_RDONLY | O_CLOEXEC);
if (fd == -1) {
reply_with_perror ("open: %s:%s", path, filename);
rmdir (tmpdir);
@@ -161,8 +163,8 @@ do_initrd_cat (const char *path, const char *filename, size_t
*size_r)
* be caught later when we try to serialize the message.
*/
if (statbuf.st_size >= GUESTFS_MESSAGE_MAX) {
- reply_with_error ("%s:%s: file is too large for the protocol",
- path, filename);
+ reply_with_error ("%s:%s: file is too large for the protocol", path,
+ filename);
goto cleanup;
}
@@ -192,7 +194,7 @@ do_initrd_cat (const char *path, const char *filename, size_t
*size_r)
*/
*size_r = statbuf.st_size;
- cleanup:
+cleanup:
if (fd >= 0)
close (fd);
@@ -205,7 +207,8 @@ do_initrd_cat (const char *path, const char *filename, size_t
*size_r)
/* Remove the directories up to and including the temp directory. */
do {
char *p = strrchr (fullpath, '/');
- if (!p) break;
+ if (!p)
+ break;
*p = '\0';
if (rmdir (fullpath) == -1) {
fprintf (stderr, "rmdir: %s: %m\n", fullpath);
diff --git a/daemon/inotify.c b/daemon/inotify.c
index 562365b..b1cb01e 100644
--- a/daemon/inotify.c
+++ b/daemon/inotify.c
@@ -35,12 +35,13 @@
#include "optgroups.h"
#ifdef HAVE_SYS_INOTIFY_H
-GUESTFSD_EXT_CMD(str_sort, sort);
+GUESTFSD_EXT_CMD (str_sort, sort);
/* Currently open inotify handle, or -1 if not opened. */
static int inotify_fd = -1;
-static char inotify_buf[64*1024*1024]; /* Event buffer, [0..posn-1] is valid */
+static char
+ inotify_buf[64 * 1024 * 1024]; /* Event buffer, [0..posn-1] is valid */
static size_t inotify_posn = 0;
/* Because of use of arbitrary offsets within inotify_buf. */
@@ -64,12 +65,14 @@ optgroup_inotify_available (void)
}
/* Because inotify_init does NEED_ROOT, NEED_INOTIFY implies NEED_ROOT. */
-#define NEED_INOTIFY(errcode) \
- do { \
- if (inotify_fd == -1) { \
- reply_with_error ("%s: you must call 'inotify_init' first to
initialize inotify", __func__); \
- return (errcode); \
- } \
+#define NEED_INOTIFY(errcode) \
+ do { \
+ if (inotify_fd == -1) { \
+ reply_with_error ( \
+ "%s: you must call 'inotify_init' first to initialize inotify",
\
+ __func__); \
+ return (errcode); \
+ } \
} while (0)
#define MQE_PATH "/proc/sys/fs/inotify/max_queued_events"
@@ -216,14 +219,14 @@ do_inotify_read (void)
r = read (inotify_fd, inotify_buf + inotify_posn,
sizeof (inotify_buf) - inotify_posn);
if (r == -1) {
- /* End of list? */
+ /* End of list? */
if (errno == EWOULDBLOCK ||
(EWOULDBLOCK != EAGAIN && errno == EAGAIN))
break;
reply_with_perror ("read");
goto error;
}
- if (r == 0) { /* End of file - we're not expecting it. */
+ if (r == 0) { /* End of file - we're not expecting it. */
reply_with_error ("unexpected end of file");
goto error;
}
@@ -236,9 +239,9 @@ do_inotify_read (void)
guestfs_int_inotify_event *np;
guestfs_int_inotify_event *in;
- event = (struct inotify_event *) &inotify_buf[n];
+ event = (struct inotify_event *)&inotify_buf[n];
- /* Have we got a complete event in the buffer? */
+/* Have we got a complete event in the buffer? */
#ifdef __GNUC__
if (n + sizeof (struct inotify_event) > inotify_posn ||
n + sizeof (struct inotify_event) + event->len > inotify_posn)
@@ -249,19 +252,21 @@ do_inotify_read (void)
/* Check event->len is reasonable (note the field is uint32_t). */
if (event->len > PATH_MAX) {
- reply_with_error ("event->len = %" PRIu32 " >
PATH_MAX", event->len);
+ reply_with_error ("event->len = %" PRIu32 " >
PATH_MAX",
+ event->len);
goto error;
}
np = realloc (ret->guestfs_int_inotify_event_list_val,
(ret->guestfs_int_inotify_event_list_len + 1) *
- sizeof (guestfs_int_inotify_event));
+ sizeof (guestfs_int_inotify_event));
if (np == NULL) {
reply_with_perror ("realloc");
goto error;
}
ret->guestfs_int_inotify_event_list_val = np;
- in =
&ret->guestfs_int_inotify_event_list_val[ret->guestfs_int_inotify_event_list_len];
+ in = &ret->guestfs_int_inotify_event_list_val
+ [ret->guestfs_int_inotify_event_list_len];
ret->guestfs_int_inotify_event_list_len++;
in->in_wd = event->wd;
@@ -271,7 +276,8 @@ do_inotify_read (void)
if (event->len > 0)
in->in_name = strdup (event->name);
else
- in->in_name = strdup (""); /* Should have optional string fields
XXX. */
+ in->in_name =
+ strdup (""); /* Should have optional string fields XXX. */
if (in->in_name == NULL) {
reply_with_perror ("strdup");
goto error;
@@ -280,7 +286,7 @@ do_inotify_read (void)
/* Estimate space used by this event in the message. */
space -= 16 + 4 + strlen (in->in_name) + 4;
- /* Move pointer to next event. */
+/* Move pointer to next event. */
#ifdef __GNUC__
n += sizeof (struct inotify_event) + event->len;
#else
@@ -298,8 +304,8 @@ do_inotify_read (void)
/* Return the messages. */
return ret;
- error:
- xdr_free ((xdrproc_t) xdr_guestfs_int_inotify_event_list, (char *) ret);
+error:
+ xdr_free ((xdrproc_t)xdr_guestfs_int_inotify_event_list, (char *)ret);
free (ret);
return NULL;
}
@@ -339,17 +345,19 @@ do_inotify_files (void)
if (events->guestfs_int_inotify_event_list_len == 0) {
free (events);
- break; /* End of list of events. */
+ break; /* End of list of events. */
}
for (i = 0; i < events->guestfs_int_inotify_event_list_len; ++i) {
- const char *name = events->guestfs_int_inotify_event_list_val[i].in_name;
+ const char *name =
+ events->guestfs_int_inotify_event_list_val[i].in_name;
if (name[0] != '\0')
fprintf (fp, "%s\n", name);
}
- xdr_free ((xdrproc_t) xdr_guestfs_int_inotify_event_list, (char *) events);
+ xdr_free ((xdrproc_t)xdr_guestfs_int_inotify_event_list,
+ (char *)events);
free (events);
}
@@ -366,8 +374,8 @@ do_inotify_files (void)
while (fgets (buf, sizeof buf, fp) != NULL) {
size_t len = strlen (buf);
- if (len > 0 && buf[len-1] == '\n')
- buf[len-1] = '\0';
+ if (len > 0 && buf[len - 1] == '\n')
+ buf[len - 1] = '\0';
if (add_string (&ret, buf) == -1)
goto error;
@@ -382,7 +390,7 @@ do_inotify_files (void)
unlink (tempfile);
return ret.argv;
- error:
+error:
if (fp != NULL)
fclose (fp);
diff --git a/daemon/internal.c b/daemon/internal.c
index 5fb3d54..f726f9c 100644
--- a/daemon/internal.c
+++ b/daemon/internal.c
@@ -46,8 +46,7 @@ do_internal_autosync (void)
}
/* NB: Only called when valgrinding the daemon. */
-int __attribute__((noreturn))
-do_internal_exit (void)
+int __attribute__((noreturn)) do_internal_exit (void)
{
/* Send a reply before exiting so the protocol doesn't get confused. */
reply (NULL, NULL);
diff --git a/daemon/is.c b/daemon/is.c
index 6b5c9a2..ed820fb 100644
--- a/daemon/is.c
+++ b/daemon/is.c
@@ -48,7 +48,8 @@ do_is_file (const char *path, int followsymlinks)
followsymlinks = 0;
r = get_mode (path, &mode, followsymlinks);
- if (r <= 0) return r;
+ if (r <= 0)
+ return r;
return S_ISREG (mode);
}
@@ -63,7 +64,8 @@ do_is_dir (const char *path, int followsymlinks)
followsymlinks = 0;
r = get_mode (path, &mode, followsymlinks);
- if (r <= 0) return r;
+ if (r <= 0)
+ return r;
return S_ISDIR (mode);
}
@@ -78,7 +80,8 @@ do_is_chardev (const char *path, int followsymlinks)
followsymlinks = 0;
r = get_mode (path, &mode, followsymlinks);
- if (r <= 0) return r;
+ if (r <= 0)
+ return r;
return S_ISCHR (mode);
}
@@ -93,7 +96,8 @@ do_is_blockdev (const char *path, int followsymlinks)
followsymlinks = 0;
r = get_mode (path, &mode, followsymlinks);
- if (r <= 0) return r;
+ if (r <= 0)
+ return r;
return S_ISBLK (mode);
}
@@ -108,7 +112,8 @@ do_is_fifo (const char *path, int followsymlinks)
followsymlinks = 0;
r = get_mode (path, &mode, followsymlinks);
- if (r <= 0) return r;
+ if (r <= 0)
+ return r;
return S_ISFIFO (mode);
}
@@ -119,7 +124,8 @@ do_is_symlink (const char *path)
int r;
r = get_mode (path, &mode, 0);
- if (r <= 0) return r;
+ if (r <= 0)
+ return r;
return S_ISLNK (mode);
}
@@ -134,7 +140,8 @@ do_is_socket (const char *path, int followsymlinks)
followsymlinks = 0;
r = get_mode (path, &mode, followsymlinks);
- if (r <= 0) return r;
+ if (r <= 0)
+ return r;
return S_ISSOCK (mode);
}
@@ -154,7 +161,7 @@ get_mode (const char *path, mode_t *mode, int followsymlinks)
return -1;
}
else
- return 0; /* Doesn't exist, means return false. */
+ return 0; /* Doesn't exist, means return false. */
}
if (mode)
diff --git a/daemon/isoinfo.c b/daemon/isoinfo.c
index 3e1acf8..84e7574 100644
--- a/daemon/isoinfo.c
+++ b/daemon/isoinfo.c
@@ -30,7 +30,7 @@
#include "daemon.h"
#include "actions.h"
-GUESTFSD_EXT_CMD(str_isoinfo, isoinfo);
+GUESTFSD_EXT_CMD (str_isoinfo, isoinfo);
static int
parse_uint32 (uint32_t *ret, const char *str)
@@ -63,9 +63,8 @@ parse_time_t (int64_t *ret, const char *str)
return 0;
}
- if (sscanf (str, "%04d %02d %02d %02d:%02d:%02d",
- &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
- &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) {
+ if (sscanf (str, "%04d %02d %02d %02d:%02d:%02d", &tm.tm_year,
&tm.tm_mon,
+ &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) {
reply_with_error ("cannot parse date from isoinfo: %s", str);
return -1;
}
@@ -99,10 +98,10 @@ parse_isoinfo (char **lines)
}
/* Default each int field in the struct to -1. */
- ret->iso_volume_space_size = (uint32_t) -1;
- ret->iso_volume_set_size = (uint32_t) -1;
- ret->iso_volume_sequence_number = (uint32_t) -1;
- ret->iso_logical_block_size = (uint32_t) -1;
+ ret->iso_volume_space_size = (uint32_t)-1;
+ ret->iso_volume_set_size = (uint32_t)-1;
+ ret->iso_volume_sequence_number = (uint32_t)-1;
+ ret->iso_logical_block_size = (uint32_t)-1;
ret->iso_volume_creation_t = -1;
ret->iso_volume_modification_t = -1;
ret->iso_volume_expiration_t = -1;
@@ -111,39 +110,48 @@ parse_isoinfo (char **lines)
for (i = 0; lines[i] != NULL; ++i) {
if (STRPREFIX (lines[i], "System id: ")) {
ret->iso_system_id = strdup (&lines[i][11]);
- if (ret->iso_system_id == NULL) goto error;
+ if (ret->iso_system_id == NULL)
+ goto error;
}
else if (STRPREFIX (lines[i], "Volume id: ")) {
ret->iso_volume_id = strdup (&lines[i][11]);
- if (ret->iso_volume_id == NULL) goto error;
+ if (ret->iso_volume_id == NULL)
+ goto error;
}
else if (STRPREFIX (lines[i], "Volume set id: ")) {
ret->iso_volume_set_id = strdup (&lines[i][15]);
- if (ret->iso_volume_set_id == NULL) goto error;
+ if (ret->iso_volume_set_id == NULL)
+ goto error;
}
else if (STRPREFIX (lines[i], "Publisher id: ")) {
ret->iso_publisher_id = strdup (&lines[i][14]);
- if (ret->iso_publisher_id == NULL) goto error;
+ if (ret->iso_publisher_id == NULL)
+ goto error;
}
else if (STRPREFIX (lines[i], "Data preparer id: ")) {
ret->iso_data_preparer_id = strdup (&lines[i][18]);
- if (ret->iso_data_preparer_id == NULL) goto error;
+ if (ret->iso_data_preparer_id == NULL)
+ goto error;
}
else if (STRPREFIX (lines[i], "Application id: ")) {
ret->iso_application_id = strdup (&lines[i][16]);
- if (ret->iso_application_id == NULL) goto error;
+ if (ret->iso_application_id == NULL)
+ goto error;
}
else if (STRPREFIX (lines[i], "Copyright File id: ")) {
ret->iso_copyright_file_id = strdup (&lines[i][19]);
- if (ret->iso_copyright_file_id == NULL) goto error;
+ if (ret->iso_copyright_file_id == NULL)
+ goto error;
}
else if (STRPREFIX (lines[i], "Abstract File id: ")) {
ret->iso_abstract_file_id = strdup (&lines[i][18]);
- if (ret->iso_abstract_file_id == NULL) goto error;
+ if (ret->iso_abstract_file_id == NULL)
+ goto error;
}
else if (STRPREFIX (lines[i], "Bibliographic File id: ")) {
ret->iso_bibliographic_file_id = strdup (&lines[i][23]);
- if (ret->iso_bibliographic_file_id == NULL) goto error;
+ if (ret->iso_bibliographic_file_id == NULL)
+ goto error;
}
else if (STRPREFIX (lines[i], "Volume size is: ")) {
if (parse_uint32 (&ret->iso_volume_space_size, &lines[i][16]) == -1)
@@ -154,7 +162,8 @@ parse_isoinfo (char **lines)
goto error;
}
else if (STRPREFIX (lines[i], "Volume set sequence number is: ")) {
- if (parse_uint32 (&ret->iso_volume_sequence_number, &lines[i][31]) ==
-1)
+ if (parse_uint32 (&ret->iso_volume_sequence_number, &lines[i][31]) ==
+ -1)
goto error;
}
else if (STRPREFIX (lines[i], "Logical block size is: ")) {
@@ -166,7 +175,8 @@ parse_isoinfo (char **lines)
goto error;
}
else if (STRPREFIX (lines[i], "Modification Date: ")) {
- if (parse_time_t (&ret->iso_volume_modification_t, &lines[i][19]) ==
-1)
+ if (parse_time_t (&ret->iso_volume_modification_t, &lines[i][19]) ==
+ -1)
goto error;
}
else if (STRPREFIX (lines[i], "Expiration Date: ")) {
@@ -185,44 +195,53 @@ parse_isoinfo (char **lines)
*/
if (ret->iso_system_id == NULL) {
ret->iso_system_id = strdup ("");
- if (ret->iso_system_id == NULL) goto error;
+ if (ret->iso_system_id == NULL)
+ goto error;
}
if (ret->iso_volume_id == NULL) {
ret->iso_volume_id = strdup ("");
- if (ret->iso_volume_id == NULL) goto error;
+ if (ret->iso_volume_id == NULL)
+ goto error;
}
if (ret->iso_volume_set_id == NULL) {
ret->iso_volume_set_id = strdup ("");
- if (ret->iso_volume_set_id == NULL) goto error;
+ if (ret->iso_volume_set_id == NULL)
+ goto error;
}
if (ret->iso_publisher_id == NULL) {
ret->iso_publisher_id = strdup ("");
- if (ret->iso_publisher_id == NULL) goto error;
+ if (ret->iso_publisher_id == NULL)
+ goto error;
}
if (ret->iso_data_preparer_id == NULL) {
ret->iso_data_preparer_id = strdup ("");
- if (ret->iso_data_preparer_id == NULL) goto error;
+ if (ret->iso_data_preparer_id == NULL)
+ goto error;
}
if (ret->iso_application_id == NULL) {
ret->iso_application_id = strdup ("");
- if (ret->iso_application_id == NULL) goto error;
+ if (ret->iso_application_id == NULL)
+ goto error;
}
if (ret->iso_copyright_file_id == NULL) {
ret->iso_copyright_file_id = strdup ("");
- if (ret->iso_copyright_file_id == NULL) goto error;
+ if (ret->iso_copyright_file_id == NULL)
+ goto error;
}
if (ret->iso_abstract_file_id == NULL) {
ret->iso_abstract_file_id = strdup ("");
- if (ret->iso_abstract_file_id == NULL) goto error;
+ if (ret->iso_abstract_file_id == NULL)
+ goto error;
}
if (ret->iso_bibliographic_file_id == NULL) {
ret->iso_bibliographic_file_id = strdup ("");
- if (ret->iso_bibliographic_file_id == NULL) goto error;
+ if (ret->iso_bibliographic_file_id == NULL)
+ goto error;
}
return ret;
- error:
+error:
free (ret->iso_system_id);
free (ret->iso_volume_id);
free (ret->iso_volume_set_id);
diff --git a/daemon/journal.c b/daemon/journal.c
index a2a1c73..15c1b64 100644
--- a/daemon/journal.c
+++ b/daemon/journal.c
@@ -60,14 +60,15 @@ journal_finalize (void)
}
}
-#define NEED_HANDLE(errcode) \
- do { \
- if (!j) { \
- reply_with_error ("%s: you must call 'journal-open' first to
initialize the journal handle", __func__); \
- return (errcode); \
- } \
- } \
- while (0)
+#define NEED_HANDLE(errcode) \
+ do { \
+ if (!j) { \
+ reply_with_error ("%s: you must call 'journal-open' first to " \
+ "initialize the journal handle", \
+ __func__); \
+ return (errcode); \
+ } \
+ } while (0)
int
do_journal_open (const char *directory)
@@ -88,7 +89,8 @@ do_journal_open (const char *directory)
r = sd_journal_open_directory (&j, buf, 0);
if (r < 0) {
- reply_with_perror_errno (-r, "sd_journal_open_directory: %s", directory);
+ reply_with_perror_errno (-r, "sd_journal_open_directory: %s",
+ directory);
return -1;
}
@@ -133,12 +135,12 @@ do_journal_skip (int64_t skip)
return 0;
if (skip > 0)
- r = sd_journal_next_skip (j, (uint64_t) skip);
+ r = sd_journal_next_skip (j, (uint64_t)skip);
else /* skip < 0 */
- r = sd_journal_previous_skip (j, (uint64_t) -skip);
+ r = sd_journal_previous_skip (j, (uint64_t)-skip);
if (r < 0) {
- reply_with_perror_errno (-r, "failed to skip %" PRIi64 " journal
entries",
- skip);
+ reply_with_perror_errno (
+ -r, "failed to skip %" PRIi64 " journal entries", skip);
return -1;
}
@@ -164,8 +166,8 @@ do_internal_journal_get (void)
sd_journal_restart_data (j);
while ((r = sd_journal_enumerate_data (j, &data, &len)) > 0) {
- //fprintf (stderr, "data[%zu] = %.*s\n", len, (int) len, (char*) data);
- len_be = htobe64 ((uint64_t) len);
+ // fprintf (stderr, "data[%zu] = %.*s\n", len, (int) len, (char*) data);
+ len_be = htobe64 ((uint64_t)len);
if (send_file_write (&len_be, sizeof (len_be)) < 0)
return -1;
if (send_file_write (data, len) < 0)
@@ -174,7 +176,7 @@ do_internal_journal_get (void)
/* Failure while enumerating the fields. */
if (r < 0) {
- send_file_end (1); /* Cancel. */
+ send_file_end (1); /* Cancel. */
errno = -r;
perror ("sd_journal_enumerate_data");
return -1;
@@ -233,7 +235,7 @@ do_journal_get_realtime_usec (void)
return -1;
}
- return (int64_t) usec;
+ return (int64_t)usec;
}
#else /* !HAVE_SD_JOURNAL */
diff --git a/daemon/labels.c b/daemon/labels.c
index 20f27cb..386d23c 100644
--- a/daemon/labels.c
+++ b/daemon/labels.c
@@ -27,7 +27,7 @@
#include "actions.h"
#include "optgroups.h"
-GUESTFSD_EXT_CMD(str_dosfslabel, dosfslabel);
+GUESTFSD_EXT_CMD (str_dosfslabel, dosfslabel);
static int
dosfslabel (const char *device, const char *label)
@@ -71,8 +71,7 @@ do_set_label (const mountable_t *mountable, const char *label)
if (STREQ (vfs_type, "btrfs"))
r = btrfs_set_label (mountable->device, label);
- else if (STREQ (vfs_type, "msdos") ||
- STREQ (vfs_type, "fat") ||
+ else if (STREQ (vfs_type, "msdos") || STREQ (vfs_type, "fat") ||
STREQ (vfs_type, "vfat"))
r = dosfslabel (mountable->device, label);
@@ -86,8 +85,8 @@ do_set_label (const mountable_t *mountable, const char *label)
r = xfslabel (mountable->device, label);
else
- NOT_SUPPORTED (-1, "don't know how to set the label for '%s'
filesystems",
- vfs_type);
+ NOT_SUPPORTED (
+ -1, "don't know how to set the label for '%s' filesystems",
vfs_type);
return r;
}
diff --git a/daemon/ldm.c b/daemon/ldm.c
index 71cdf46..de9afdd 100644
--- a/daemon/ldm.c
+++ b/daemon/ldm.c
@@ -32,7 +32,7 @@
#include "actions.h"
#include "optgroups.h"
-GUESTFSD_EXT_CMD(str_ldmtool, ldmtool);
+GUESTFSD_EXT_CMD (str_ldmtool, ldmtool);
int
optgroup_ldm_available (void)
@@ -43,7 +43,8 @@ optgroup_ldm_available (void)
static int
glob_errfunc (const char *epath, int eerrno)
{
- fprintf (stderr, "glob: failure reading %s: %s\n", epath, strerror
(eerrno));
+ fprintf (stderr, "glob: failure reading %s: %s\n", epath,
+ strerror (eerrno));
return 1;
}
@@ -62,7 +63,8 @@ get_devices (const char *pattern)
reply_with_error ("glob: returned GLOB_NOSPACE: "
"rerun with LIBGUESTFS_DEBUG=1");
goto error;
- } else if (err == GLOB_ABORTED) {
+ }
+ else if (err == GLOB_ABORTED) {
reply_with_error ("glob: returned GLOB_ABORTED: "
"rerun with LIBGUESTFS_DEBUG=1");
goto error;
@@ -73,12 +75,13 @@ get_devices (const char *pattern)
goto error;
}
- if (end_stringsbuf (&ret) == -1) goto error;
+ if (end_stringsbuf (&ret) == -1)
+ goto error;
globfree (&devs);
return ret.argv;
- error:
+error:
globfree (&devs);
if (ret.argv != NULL)
free_stringslen (ret.argv, ret.size);
@@ -171,7 +174,7 @@ parse_json (const char *json, const char *func)
return tree;
}
-#define TYPE_ERROR ((char **) -1)
+#define TYPE_ERROR ((char **)-1)
static char **
json_value_to_string_list (yajl_val node)
@@ -180,13 +183,13 @@ json_value_to_string_list (yajl_val node)
yajl_val n;
size_t i, len;
- if (! YAJL_IS_ARRAY (node))
+ if (!YAJL_IS_ARRAY (node))
return TYPE_ERROR;
len = YAJL_GET_ARRAY (node)->len;
for (i = 0; i < len; ++i) {
n = YAJL_GET_ARRAY (node)->values[i];
- if (! YAJL_IS_STRING (n))
+ if (!YAJL_IS_STRING (n))
return TYPE_ERROR;
if (add_string (&strs, YAJL_GET_STRING (n)) == -1)
return NULL;
@@ -198,8 +201,8 @@ json_value_to_string_list (yajl_val node)
}
static char **
-parse_json_get_string_list (const char *json,
- const char *func, const char *cmd)
+parse_json_get_string_list (const char *json, const char *func,
+ const char *cmd)
{
char **ret;
yajl_val tree = NULL;
@@ -211,7 +214,8 @@ parse_json_get_string_list (const char *json,
ret = json_value_to_string_list (tree);
yajl_tree_free (tree);
if (ret == TYPE_ERROR) {
- reply_with_error ("output of '%s' was not a JSON array of strings",
cmd);
+ reply_with_error ("output of '%s' was not a JSON array of
strings",
+ cmd);
return NULL;
}
return ret;
@@ -231,7 +235,7 @@ parse_json_get_object_string (const char *json, const char *key, int
flags,
if (tree == NULL)
return NULL;
- if (! YAJL_IS_OBJECT (tree))
+ if (!YAJL_IS_OBJECT (tree))
goto bad_type;
len = YAJL_GET_OBJECT (tree)->len;
@@ -256,9 +260,10 @@ parse_json_get_object_string (const char *json, const char *key, int
flags,
}
}
- bad_type:
+bad_type:
reply_with_error ("output of '%s' was not a JSON object "
- "containing a key '%s' of type string", cmd, key);
+ "containing a key '%s' of type string",
+ cmd, key);
yajl_tree_free (tree);
return NULL;
}
@@ -275,7 +280,7 @@ parse_json_get_object_string_list (const char *json, const char *key,
if (tree == NULL)
return NULL;
- if (! YAJL_IS_OBJECT (tree))
+ if (!YAJL_IS_OBJECT (tree))
goto bad_type;
len = YAJL_GET_OBJECT (tree)->len;
@@ -290,7 +295,7 @@ parse_json_get_object_string_list (const char *json, const char *key,
}
}
- bad_type:
+bad_type:
reply_with_error ("output of '%s' was not a JSON object "
"containing a key '%s' of type array of strings",
cmd, key);
@@ -303,11 +308,11 @@ do_ldmtool_scan (void)
{
const char *empty_list[] = { NULL };
- return do_ldmtool_scan_devices ((char * const *) empty_list);
+ return do_ldmtool_scan_devices ((char *const *)empty_list);
}
char **
-do_ldmtool_scan_devices (char * const * devices)
+do_ldmtool_scan_devices (char *const *devices)
{
char **ret;
size_t i, nr_devices;
@@ -325,8 +330,8 @@ do_ldmtool_scan_devices (char * const * devices)
argv[0] = str_ldmtool;
argv[1] = "scan";
for (i = 0; i < nr_devices; ++i)
- argv[2+i] = devices[i];
- argv[2+i] = NULL;
+ argv[2 + i] = devices[i];
+ argv[2 + i] = NULL;
r = commandv (&out, &err, argv);
if (r == -1) {
@@ -344,14 +349,15 @@ do_ldmtool_diskgroup_name (const char *diskgroup)
int r;
CLEANUP_FREE char *out = NULL, *err = NULL;
- r = command (&out, &err, str_ldmtool, "show", "diskgroup",
diskgroup, NULL);
+ r =
+ command (&out, &err, str_ldmtool, "show", "diskgroup",
diskgroup, NULL);
if (r == -1) {
reply_with_error ("%s", err);
return NULL;
}
- return parse_json_get_object_string (out, "name", 0,
- __func__, "ldmtool show diskgroup");
+ return parse_json_get_object_string (out, "name", 0, __func__,
+ "ldmtool show diskgroup");
}
char **
@@ -360,15 +366,16 @@ do_ldmtool_diskgroup_volumes (const char *diskgroup)
int r;
CLEANUP_FREE char *out = NULL, *err = NULL;
- r = command (&out, &err, str_ldmtool, "show", "diskgroup",
diskgroup, NULL);
+ r =
+ command (&out, &err, str_ldmtool, "show", "diskgroup",
diskgroup, NULL);
if (r == -1) {
reply_with_error ("%s", err);
return NULL;
}
free (err);
- return parse_json_get_object_string_list (out, "volumes",
- __func__, "ldmtool show
diskgroup");
+ return parse_json_get_object_string_list (out, "volumes", __func__,
+ "ldmtool show diskgroup");
}
char **
@@ -377,14 +384,15 @@ do_ldmtool_diskgroup_disks (const char *diskgroup)
int r;
CLEANUP_FREE char *out = NULL, *err = NULL;
- r = command (&out, &err, str_ldmtool, "show", "diskgroup",
diskgroup, NULL);
+ r =
+ command (&out, &err, str_ldmtool, "show", "diskgroup",
diskgroup, NULL);
if (r == -1) {
reply_with_error ("%s", err);
return NULL;
}
- return parse_json_get_object_string_list (out, "disks",
- __func__, "ldmtool show
diskgroup");
+ return parse_json_get_object_string_list (out, "disks", __func__,
+ "ldmtool show diskgroup");
}
char *
@@ -393,15 +401,15 @@ do_ldmtool_volume_type (const char *diskgroup, const char *volume)
int r;
CLEANUP_FREE char *out = NULL, *err = NULL;
- r = command (&out, &err,
- str_ldmtool, "show", "volume", diskgroup, volume,
NULL);
+ r = command (&out, &err, str_ldmtool, "show", "volume",
diskgroup, volume,
+ NULL);
if (r == -1) {
reply_with_error ("%s", err);
return NULL;
}
- return parse_json_get_object_string (out, "type", 0,
- __func__, "ldmtool show volume");
+ return parse_json_get_object_string (out, "type", 0, __func__,
+ "ldmtool show volume");
}
char *
@@ -410,15 +418,15 @@ do_ldmtool_volume_hint (const char *diskgroup, const char *volume)
int r;
CLEANUP_FREE char *out = NULL, *err = NULL;
- r = command (&out, &err,
- str_ldmtool, "show", "volume", diskgroup, volume,
NULL);
+ r = command (&out, &err, str_ldmtool, "show", "volume",
diskgroup, volume,
+ NULL);
if (r == -1) {
reply_with_error ("%s", err);
return NULL;
}
- return parse_json_get_object_string (out, "hint", GET_STRING_NULL_TO_EMPTY,
- __func__, "ldmtool show volume");
+ return parse_json_get_object_string (
+ out, "hint", GET_STRING_NULL_TO_EMPTY, __func__, "ldmtool show
volume");
}
char **
@@ -427,13 +435,13 @@ do_ldmtool_volume_partitions (const char *diskgroup, const char
*volume)
int r;
CLEANUP_FREE char *out = NULL, *err = NULL;
- r = command (&out, &err,
- str_ldmtool, "show", "volume", diskgroup, volume,
NULL);
+ r = command (&out, &err, str_ldmtool, "show", "volume",
diskgroup, volume,
+ NULL);
if (r == -1) {
reply_with_error ("%s", err);
return NULL;
}
- return parse_json_get_object_string_list (out, "partitions",
- __func__, "ldmtool show volume");
+ return parse_json_get_object_string_list (out, "partitions", __func__,
+ "ldmtool show volume");
}
diff --git a/daemon/link.c b/daemon/link.c
index 43c55f8..0027511 100644
--- a/daemon/link.c
+++ b/daemon/link.c
@@ -30,7 +30,7 @@
#include "daemon.h"
#include "actions.h"
-GUESTFSD_EXT_CMD(str_ln, ln);
+GUESTFSD_EXT_CMD (str_ln, ln);
char *
do_readlink (const char *path)
@@ -45,7 +45,7 @@ do_readlink (const char *path)
return NULL;
}
- return link; /* caller frees */
+ return link; /* caller frees */
}
char **
@@ -56,7 +56,7 @@ do_internal_readlinklist (const char *path, char *const *names)
DECLARE_STRINGSBUF (ret);
CHROOT_IN;
- fd_cwd = open (path, O_RDONLY|O_DIRECTORY|O_CLOEXEC);
+ fd_cwd = open (path, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
CHROOT_OUT;
if (fd_cwd == -1) {
@@ -76,7 +76,8 @@ do_internal_readlinklist (const char *path, char *const *names)
close (fd_cwd);
return NULL;
}
- } else {
+ }
+ else {
if (add_string (&ret, "") == -1)
goto add_string_failed;
}
@@ -139,12 +140,11 @@ _symlink (const char *flag, const char *target, const char
*linkname)
return -1;
}
- r = command (NULL, &err,
- str_ln, flag, "--", /* target could begin with '-' */
+ r = command (NULL, &err, str_ln, flag,
+ "--", /* target could begin with '-' */
target, buf_linkname, NULL);
if (r == -1) {
- reply_with_error ("ln %s: %s: %s: %s",
- flag, target, linkname, err);
+ reply_with_error ("ln %s: %s: %s: %s", flag, target, linkname, err);
return -1;
}
diff --git a/daemon/ls.c b/daemon/ls.c
index 0e2f110..e591808 100644
--- a/daemon/ls.c
+++ b/daemon/ls.c
@@ -30,7 +30,7 @@
#include "daemon.h"
#include "actions.h"
-GUESTFSD_EXT_CMD(str_ls, ls);
+GUESTFSD_EXT_CMD (str_ls, ls);
/* Has one FileOut parameter. */
int
@@ -58,7 +58,8 @@ do_ls0 (const char *path)
while (1) {
errno = 0;
d = readdir (dir);
- if (d == NULL) break;
+ if (d == NULL)
+ break;
/* Ignore . and .. */
if (STREQ (d->d_name, ".") || STREQ (d->d_name, ".."))
@@ -70,7 +71,7 @@ do_ls0 (const char *path)
* output.
*/
len = strlen (d->d_name);
- if (send_file_write (d->d_name, len+1) < 0) {
+ if (send_file_write (d->d_name, len + 1) < 0) {
closedir (dir);
return -1;
}
@@ -78,18 +79,18 @@ do_ls0 (const char *path)
if (errno != 0) {
fprintf (stderr, "readdir: %s: %m\n", path);
- send_file_end (1); /* Cancel. */
+ send_file_end (1); /* Cancel. */
closedir (dir);
return -1;
}
if (closedir (dir) == -1) {
fprintf (stderr, "closedir: %s: %m\n", path);
- send_file_end (1); /* Cancel. */
+ send_file_end (1); /* Cancel. */
return -1;
}
- if (send_file_end (0)) /* Normal end of file. */
+ if (send_file_end (0)) /* Normal end of file. */
return -1;
return 0;
@@ -125,7 +126,7 @@ do_ll (const char *path)
return NULL;
}
- return out; /* caller frees */
+ return out; /* caller frees */
}
char *
@@ -158,5 +159,5 @@ do_llz (const char *path)
return NULL;
}
- return out; /* caller frees */
+ return out; /* caller frees */
}
diff --git a/daemon/luks.c b/daemon/luks.c
index 53bb820..f5b9698 100644
--- a/daemon/luks.c
+++ b/daemon/luks.c
@@ -28,7 +28,7 @@
#define MAX_ARGS 64
-GUESTFSD_EXT_CMD(str_cryptsetup, cryptsetup);
+GUESTFSD_EXT_CMD (str_cryptsetup, cryptsetup);
int
optgroup_luks_available (void)
@@ -70,7 +70,7 @@ write_key_to_temp (const char *key)
return tempfile;
- error:
+error:
unlink (tempfile);
free (tempfile);
return NULL;
@@ -111,14 +111,15 @@ luks_open (const char *device, const char *key, const char
*mapname,
ADD_ARG (argv, i, str_cryptsetup);
ADD_ARG (argv, i, "-d");
ADD_ARG (argv, i, tempfile);
- if (readonly) ADD_ARG (argv, i, "--readonly");
+ if (readonly)
+ ADD_ARG (argv, i, "--readonly");
ADD_ARG (argv, i, "luksOpen");
ADD_ARG (argv, i, device);
ADD_ARG (argv, i, mapname);
ADD_ARG (argv, i, NULL);
CLEANUP_FREE char *err = NULL;
- int r = commandv (NULL, &err, (const char * const *) argv);
+ int r = commandv (NULL, &err, (const char *const *)argv);
remove_temp (tempfile);
if (r == -1) {
@@ -147,8 +148,9 @@ int
do_luks_close (const char *device)
{
/* Must be /dev/mapper/... */
- if (! STRPREFIX (device, "/dev/mapper/")) {
- reply_with_error ("luks_close: you must call this on the /dev/mapper device
created by luks_open");
+ if (!STRPREFIX (device, "/dev/mapper/")) {
+ reply_with_error ("luks_close: you must call this on the /dev/mapper "
+ "device created by luks_open");
return -1;
}
@@ -193,7 +195,7 @@ luks_format (const char *device, const char *key, int keyslot,
ADD_ARG (argv, i, NULL);
CLEANUP_FREE char *err = NULL;
- int r = commandv (NULL, &err, (const char * const *) argv);
+ int r = commandv (NULL, &err, (const char *const *)argv);
remove_temp (tempfile);
if (r == -1) {
@@ -250,7 +252,7 @@ do_luks_add_key (const char *device, const char *key, const char
*newkey,
ADD_ARG (argv, i, NULL);
CLEANUP_FREE char *err = NULL;
- int r = commandv (NULL, &err, (const char * const *) argv);
+ int r = commandv (NULL, &err, (const char *const *)argv);
remove_temp (keyfile);
remove_temp (newkeyfile);
@@ -284,7 +286,7 @@ do_luks_kill_slot (const char *device, const char *key, int keyslot)
ADD_ARG (argv, i, NULL);
CLEANUP_FREE char *err = NULL;
- int r = commandv (NULL, &err, (const char * const *) argv);
+ int r = commandv (NULL, &err, (const char *const *)argv);
remove_temp (tempfile);
if (r == -1) {
diff --git a/daemon/lvm-filter.c b/daemon/lvm-filter.c
index eadc472..ad389e2 100644
--- a/daemon/lvm-filter.c
+++ b/daemon/lvm-filter.c
@@ -36,9 +36,9 @@
#include "daemon.h"
#include "actions.h"
-GUESTFSD_EXT_CMD(str_lvm, lvm);
-GUESTFSD_EXT_CMD(str_cp, cp);
-GUESTFSD_EXT_CMD(str_rm, rm);
+GUESTFSD_EXT_CMD (str_lvm, lvm);
+GUESTFSD_EXT_CMD (str_cp, cp);
+GUESTFSD_EXT_CMD (str_rm, rm);
/* This runs during daemon start up and creates a complete copy of
* /etc/lvm so that we can modify it as we desire. We set
@@ -69,7 +69,7 @@ copy_lvm (void)
perror ("copy_lvm: stat: /etc/lvm");
return;
}
- if (! S_ISDIR (statbuf.st_mode)) {
+ if (!S_ISDIR (statbuf.st_mode)) {
fprintf (stderr, "copy_lvm: warning: /etc/lvm is not a directory\n");
return;
}
@@ -218,7 +218,8 @@ static int
rescan (void)
{
char lvm_cache[64];
- snprintf (lvm_cache, sizeof lvm_cache, "%s/lvm/cache/.cache",
lvm_system_dir);
+ snprintf (lvm_cache, sizeof lvm_cache, "%s/lvm/cache/.cache",
+ lvm_system_dir);
unlink (lvm_cache);
@@ -256,7 +257,7 @@ make_filter_strings (char *const *devices)
if (add_sprintf (&ret, "a|^%s$|", devices[i]) == -1)
goto error;
- if (!c_isdigit (devices[i][slen-1])) {
+ if (!c_isdigit (devices[i][slen - 1])) {
/* whole block device */
if (add_sprintf (&ret, "a|^%s[0-9]|", devices[i]) == -1)
goto error;
@@ -270,7 +271,7 @@ make_filter_strings (char *const *devices)
return ret.argv;
- error:
+error:
if (ret.argv)
free_stringslen (ret.argv, ret.size);
return NULL;
@@ -304,7 +305,7 @@ do_lvm_clear_filter (void)
if (deactivate () == -1)
return -1;
- if (set_filter ((char *const *) filters) == -1)
+ if (set_filter ((char *const *)filters) == -1)
return -1;
if (rescan () == -1)
diff --git a/daemon/lvm.c b/daemon/lvm.c
index 2b61357..ad82050 100644
--- a/daemon/lvm.c
+++ b/daemon/lvm.c
@@ -32,7 +32,7 @@
#include "actions.h"
#include "optgroups.h"
-GUESTFSD_EXT_CMD(str_lvm, lvm);
+GUESTFSD_EXT_CMD (str_lvm, lvm);
int
optgroup_lvm2_available (void)
@@ -55,21 +55,21 @@ convert_lvm_output (char *out, const char *prefix)
p = out;
while (p) {
- pend = strchr (p, '\n'); /* Get the next line of output. */
+ pend = strchr (p, '\n'); /* Get the next line of output. */
if (pend) {
*pend = '\0';
pend++;
}
- while (*p && c_isspace (*p)) /* Skip any leading whitespace. */
+ while (*p && c_isspace (*p)) /* Skip any leading whitespace. */
p++;
/* Sigh, skip trailing whitespace too. "pvs", I'm looking at you. */
- len = strlen (p)-1;
+ len = strlen (p) - 1;
while (*p && c_isspace (p[len]))
p[len--] = '\0';
- if (!*p) { /* Empty line? Skip it. */
+ if (!*p) { /* Empty line? Skip it. */
p = pend;
continue;
}
@@ -78,7 +78,8 @@ convert_lvm_output (char *out, const char *prefix)
if (prefix) {
snprintf (buf, sizeof buf, "%s%s", prefix, p);
str = buf;
- } else
+ }
+ else
str = p;
/* Ignore "unknown device" message (RHBZ#1054761). */
@@ -121,21 +122,21 @@ filter_convert_old_lvs_output (char *out)
char *saveptr;
char *lv_attr, *vg_name, *lv_name;
- pend = strchr (p, '\n'); /* Get the next line of output. */
+ pend = strchr (p, '\n'); /* Get the next line of output. */
if (pend) {
*pend = '\0';
pend++;
}
- while (*p && c_isspace (*p)) /* Skip any leading whitespace. */
+ while (*p && c_isspace (*p)) /* Skip any leading whitespace. */
p++;
/* Sigh, skip trailing whitespace too. "pvs", I'm looking at you. */
- len = strlen (p)-1;
+ len = strlen (p) - 1;
while (*p && c_isspace (p[len]))
p[len--] = '\0';
- if (!*p) { /* Empty line? Skip it. */
+ if (!*p) { /* Empty line? Skip it. */
skip_line:
p = pend;
continue;
@@ -193,8 +194,8 @@ do_pvs (void)
CLEANUP_FREE char *err = NULL;
int r;
- r = command (&out, &err,
- str_lvm, "pvs", "-o", "pv_name",
"--noheadings", NULL);
+ r = command (&out, &err, str_lvm, "pvs", "-o",
"pv_name", "--noheadings",
+ NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (out);
@@ -211,8 +212,8 @@ do_vgs (void)
CLEANUP_FREE char *err = NULL;
int r;
- r = command (&out, &err,
- str_lvm, "vgs", "-o", "vg_name",
"--noheadings", NULL);
+ r = command (&out, &err, str_lvm, "vgs", "-o",
"vg_name", "--noheadings",
+ NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (out);
@@ -261,11 +262,8 @@ do_lvs (void)
return NULL;
if (has_S > 0) {
- r = command (&out, &err,
- str_lvm, "lvs",
- "-o", "vg_name,lv_name",
- "-S", "lv_role=public && lv_active=active",
- "--noheadings",
+ r = command (&out, &err, str_lvm, "lvs", "-o",
"vg_name,lv_name", "-S",
+ "lv_role=public && lv_active=active",
"--noheadings",
"--separator", "/", NULL);
if (r == -1) {
reply_with_error ("%s", err);
@@ -274,12 +272,11 @@ do_lvs (void)
}
return convert_lvm_output (out, "/dev/");
- } else {
- r = command (&out, &err,
- str_lvm, "lvs",
- "-o", "lv_attr,vg_name,lv_name",
- "--noheadings",
- "--separator", ":", NULL);
+ }
+ else {
+ r =
+ command (&out, &err, str_lvm, "lvs", "-o",
"lv_attr,vg_name,lv_name",
+ "--noheadings", "--separator", ":", NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (out);
@@ -318,8 +315,7 @@ do_pvcreate (const char *device)
CLEANUP_FREE char *err = NULL;
int r;
- r = command (NULL, &err,
- str_lvm, "pvcreate", "--force", device, NULL);
+ r = command (NULL, &err, str_lvm, "pvcreate", "--force",
device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
return -1;
@@ -346,10 +342,10 @@ do_vgcreate (const char *volgroup, char *const *physvols)
argv[0] = str_lvm;
argv[1] = "vgcreate";
argv[2] = volgroup;
- for (i = 3; i < argc+1; ++i)
- argv[i] = physvols[i-3];
+ for (i = 3; i < argc + 1; ++i)
+ argv[i] = physvols[i - 3];
- r = commandv (NULL, &err, (const char * const*) argv);
+ r = commandv (NULL, &err, (const char *const *)argv);
if (r == -1) {
reply_with_error ("%s", err);
return -1;
@@ -369,9 +365,8 @@ do_lvcreate (const char *logvol, const char *volgroup, int mbytes)
snprintf (size, sizeof size, "%d", mbytes);
- r = command (NULL, &err,
- str_lvm, "lvcreate",
- "-L", size, "-n", logvol, volgroup, NULL);
+ r = command (NULL, &err, str_lvm, "lvcreate", "-L", size,
"-n", logvol,
+ volgroup, NULL);
if (r == -1) {
reply_with_error ("%s", err);
return -1;
@@ -396,9 +391,8 @@ do_lvcreate_free (const char *logvol, const char *volgroup, int
percent)
char size[64];
snprintf (size, sizeof size, "%d%%FREE", percent);
- r = command (NULL, &err,
- str_lvm, "lvcreate",
- "-l", size, "-n", logvol, volgroup, NULL);
+ r = command (NULL, &err, str_lvm, "lvcreate", "-l", size,
"-n", logvol,
+ volgroup, NULL);
if (r == -1) {
reply_with_error ("%s", err);
return -1;
@@ -417,7 +411,7 @@ static int
ignore_same_size_error (const char *err)
{
return strstr (err, "New size (") != NULL &&
- strstr (err, "extents) matches existing size (") != NULL;
+ strstr (err, "extents) matches existing size (") != NULL;
}
int
@@ -429,9 +423,8 @@ do_lvresize (const char *logvol, int mbytes)
snprintf (size, sizeof size, "%d", mbytes);
- r = command (NULL, &err,
- str_lvm, "lvresize",
- "--force", "-L", size, logvol, NULL);
+ r = command (NULL, &err, str_lvm, "lvresize", "--force",
"-L", size,
+ logvol, NULL);
if (r == -1) {
if (!ignore_same_size_error (err)) {
reply_with_error ("%s", err);
@@ -456,8 +449,7 @@ do_lvresize_free (const char *logvol, int percent)
char size[64];
snprintf (size, sizeof size, "+%d%%FREE", percent);
- r = command (NULL, &err,
- str_lvm, "lvresize", "-l", size, logvol, NULL);
+ r = command (NULL, &err, str_lvm, "lvresize", "-l", size,
logvol, NULL);
if (r == -1) {
if (!ignore_same_size_error (err)) {
reply_with_error ("%s", err);
@@ -489,7 +481,7 @@ do_lvm_remove_all (void)
/* Deactivate the LV first. On Ubuntu, lvremove '-f' option
* does not remove active LVs reliably.
*/
- (void) command (NULL, NULL, str_lvm, "lvchange", "-an", xs[i],
NULL);
+ (void)command (NULL, NULL, str_lvm, "lvchange", "-an", xs[i],
NULL);
udev_settle ();
r = command (NULL, &err, str_lvm, "lvremove", "-f", xs[i],
NULL);
@@ -510,7 +502,7 @@ do_lvm_remove_all (void)
CLEANUP_FREE char *err = NULL;
/* Deactivate the VG first, see note above. */
- (void) command (NULL, NULL, str_lvm, "vgchange", "-an", xs[i],
NULL);
+ (void)command (NULL, NULL, str_lvm, "vgchange", "-an", xs[i],
NULL);
udev_settle ();
r = command (NULL, &err, str_lvm, "vgremove", "-f", xs[i],
NULL);
@@ -550,8 +542,7 @@ do_lvremove (const char *device)
CLEANUP_FREE char *err = NULL;
int r;
- r = command (NULL, &err,
- str_lvm, "lvremove", "-f", device, NULL);
+ r = command (NULL, &err, str_lvm, "lvremove", "-f", device,
NULL);
if (r == -1) {
reply_with_error ("%s", err);
return -1;
@@ -568,8 +559,7 @@ do_vgremove (const char *device)
CLEANUP_FREE char *err = NULL;
int r;
- r = command (NULL, &err,
- str_lvm, "vgremove", "-f", device, NULL);
+ r = command (NULL, &err, str_lvm, "vgremove", "-f", device,
NULL);
if (r == -1) {
reply_with_error ("%s", err);
return -1;
@@ -586,8 +576,7 @@ do_pvremove (const char *device)
CLEANUP_FREE char *err = NULL;
int r;
- r = command (NULL, &err,
- str_lvm, "pvremove", "-ff", device, NULL);
+ r = command (NULL, &err, str_lvm, "pvremove", "-ff", device,
NULL);
if (r == -1) {
reply_with_error ("%s", err);
return -1;
@@ -604,8 +593,7 @@ do_pvresize (const char *device)
CLEANUP_FREE char *err = NULL;
int r;
- r = command (NULL, &err,
- str_lvm, "pvresize", device, NULL);
+ r = command (NULL, &err, str_lvm, "pvresize", device, NULL);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
return -1;
@@ -623,10 +611,8 @@ do_pvresize_size (const char *device, int64_t size)
char buf[32];
snprintf (buf, sizeof buf, "%" PRIi64 "b", size);
- r = command (NULL, &err,
- str_lvm, "pvresize",
- "--setphysicalvolumesize", buf,
- device, NULL);
+ r = command (NULL, &err, str_lvm, "pvresize",
"--setphysicalvolumesize",
+ buf, device, NULL);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
return -1;
@@ -643,7 +629,7 @@ do_vg_activate (int activate, char *const *volgroups)
CLEANUP_FREE const char **argv = NULL;
argc = count_strings (volgroups) + 4;
- argv = malloc (sizeof (char *) * (argc+1));
+ argv = malloc (sizeof (char *) * (argc + 1));
if (argv == NULL) {
reply_with_perror ("malloc");
return -1;
@@ -653,10 +639,10 @@ do_vg_activate (int activate, char *const *volgroups)
argv[1] = "vgchange";
argv[2] = "-a";
argv[3] = activate ? "y" : "n";
- for (i = 4; i < argc+1; ++i)
- argv[i] = volgroups[i-4];
+ for (i = 4; i < argc + 1; ++i)
+ argv[i] = volgroups[i - 4];
- r = commandv (NULL, &err, (const char * const*) argv);
+ r = commandv (NULL, &err, (const char *const *)argv);
if (r == -1) {
reply_with_error ("vgchange: %s", err);
return -1;
@@ -680,9 +666,7 @@ do_lvrename (const char *logvol, const char *newlogvol)
CLEANUP_FREE char *err = NULL;
int r;
- r = command (NULL, &err,
- str_lvm, "lvrename",
- logvol, newlogvol, NULL);
+ r = command (NULL, &err, str_lvm, "lvrename", logvol, newlogvol, NULL);
if (r == -1) {
reply_with_error ("%s -> %s: %s", logvol, newlogvol, err);
return -1;
@@ -699,9 +683,8 @@ do_vgrename (const char *volgroup, const char *newvolgroup)
CLEANUP_FREE char *err = NULL;
int r;
- r = command (NULL, &err,
- str_lvm, "vgrename",
- volgroup, newvolgroup, NULL);
+ r =
+ command (NULL, &err, str_lvm, "vgrename", volgroup, newvolgroup,
NULL);
if (r == -1) {
reply_with_error ("%s -> %s: %s", volgroup, newvolgroup, err);
return -1;
@@ -717,10 +700,8 @@ get_lvm_field (const char *cmd, const char *field, const char
*device)
{
char *out;
CLEANUP_FREE char *err = NULL;
- int r = command (&out, &err,
- str_lvm, cmd,
- "--unbuffered", "--noheadings", "-o",
field,
- device, NULL);
+ int r = command (&out, &err, str_lvm, cmd, "--unbuffered",
"--noheadings",
+ "-o", field, device, NULL);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
free (out);
@@ -728,7 +709,7 @@ get_lvm_field (const char *cmd, const char *field, const char
*device)
}
trim (out);
- return out; /* Caller frees. */
+ return out; /* Caller frees. */
}
char *
@@ -754,10 +735,8 @@ get_lvm_fields (const char *cmd, const char *field, const char
*device)
{
CLEANUP_FREE char *out = NULL, *err = NULL;
- int r = command (&out, &err,
- str_lvm, cmd,
- "--unbuffered", "--noheadings", "-o",
field,
- device, NULL);
+ int r = command (&out, &err, str_lvm, cmd, "--unbuffered",
"--noheadings",
+ "-o", field, device, NULL);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
return NULL;
@@ -793,8 +772,7 @@ do_vgscan (void)
CLEANUP_FREE char *err = NULL;
int r;
- r = command (NULL, &err,
- str_lvm, "vgscan", NULL);
+ r = command (NULL, &err, str_lvm, "vgscan", NULL);
if (r == -1) {
reply_with_error ("%s", err);
return -1;
@@ -882,7 +860,7 @@ do_lvm_canonical_lv_name (const char *device)
return NULL;
}
- return canonical; /* caller frees */
+ return canonical; /* caller frees */
}
/* List everything in /dev/mapper which *isn't* an LV (RHBZ#688062). */
@@ -905,7 +883,8 @@ do_list_dm_devices (void)
errno = 0;
d = readdir (dir);
- if (d == NULL) break;
+ if (d == NULL)
+ break;
/* Ignore . and .. */
if (STREQ (d->d_name, ".") || STREQ (d->d_name, ".."))
@@ -991,7 +970,7 @@ do_vgmeta (const char *vg, size_t *size_r)
}
/* Now read back the temporary file. */
- fd = open (tmp, O_RDONLY|O_CLOEXEC);
+ fd = open (tmp, O_RDONLY | O_CLOEXEC);
if (fd == -1) {
reply_with_error ("%s", tmp);
return NULL;
@@ -1047,7 +1026,7 @@ do_vgmeta (const char *vg, size_t *size_r)
*size_r = size;
- return buf; /* caller will free */
+ return buf; /* caller will free */
}
int
@@ -1056,8 +1035,7 @@ do_pvchange_uuid (const char *device)
CLEANUP_FREE char *err = NULL;
int r;
- r = command (NULL, &err,
- str_lvm, "pvchange", "-u", device, NULL);
+ r = command (NULL, &err, str_lvm, "pvchange", "-u", device,
NULL);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
return -1;
@@ -1074,8 +1052,7 @@ do_pvchange_uuid_all (void)
CLEANUP_FREE char *err = NULL;
int r;
- r = command (NULL, &err,
- str_lvm, "pvchange", "-u", "-a", NULL);
+ r = command (NULL, &err, str_lvm, "pvchange", "-u",
"-a", NULL);
if (r == -1) {
reply_with_error ("%s", err);
return -1;
@@ -1092,8 +1069,7 @@ do_vgchange_uuid (const char *vg)
CLEANUP_FREE char *err = NULL;
int r;
- r = command (NULL, &err,
- str_lvm, "vgchange", "-u", vg, NULL);
+ r = command (NULL, &err, str_lvm, "vgchange", "-u", vg, NULL);
if (r == -1) {
reply_with_error ("%s: %s", vg, err);
return -1;
@@ -1110,8 +1086,7 @@ do_vgchange_uuid_all (void)
CLEANUP_FREE char *err = NULL;
int r;
- r = command (NULL, &err,
- str_lvm, "vgchange", "-u", NULL);
+ r = command (NULL, &err, str_lvm, "vgchange", "-u", NULL);
if (r == -1) {
reply_with_error ("%s", err);
return -1;
diff --git a/daemon/md.c b/daemon/md.c
index 5d60b62..3c5ec50 100644
--- a/daemon/md.c
+++ b/daemon/md.c
@@ -37,7 +37,7 @@
#include "optgroups.h"
#include "c-ctype.h"
-GUESTFSD_EXT_CMD(str_mdadm, mdadm);
+GUESTFSD_EXT_CMD (str_mdadm, mdadm);
int
optgroup_mdadm_available (void)
@@ -65,9 +65,8 @@ count_bits (uint64_t bitmap)
/* Takes optional arguments, consult optargs_bitmask. */
int
-do_md_create (const char *name, char *const *devices,
- int64_t missingbitmap, int nrdevices, int spare,
- int64_t chunk, const char *level)
+do_md_create (const char *name, char *const *devices, int64_t missingbitmap,
+ int nrdevices, int spare, int64_t chunk, const char *level)
{
char nrdevices_s[32];
char spare_s[32];
@@ -75,7 +74,7 @@ do_md_create (const char *name, char *const *devices,
size_t j;
int r;
CLEANUP_FREE char *err = NULL;
- uint64_t umissingbitmap = (uint64_t) missingbitmap;
+ uint64_t umissingbitmap = (uint64_t)missingbitmap;
/* Check the optional parameters and set defaults where appropriate. */
if (!(optargs_bitmask & GUESTFS_MD_CREATE_MISSINGBITMAP_BITMASK))
@@ -103,11 +102,11 @@ do_md_create (const char *name, char *const *devices,
if (STRNEQ (level, "linear") && STRNEQ (level, "raid0")
&&
STRNEQ (level, "0") && STRNEQ (level, "stripe")
&&
STRNEQ (level, "raid1") && STRNEQ (level, "1")
&&
- STRNEQ (level, "mirror") &&
- STRNEQ (level, "raid4") && STRNEQ (level, "4")
&&
- STRNEQ (level, "raid5") && STRNEQ (level, "5")
&&
- STRNEQ (level, "raid6") && STRNEQ (level, "6")
&&
- STRNEQ (level, "raid10") && STRNEQ (level, "10")) {
+ STRNEQ (level, "mirror") && STRNEQ (level, "raid4")
&&
+ STRNEQ (level, "4") && STRNEQ (level, "raid5")
&&
+ STRNEQ (level, "5") && STRNEQ (level, "raid6")
&&
+ STRNEQ (level, "6") && STRNEQ (level, "raid10")
&&
+ STRNEQ (level, "10")) {
reply_with_error ("unknown level parameter: %s", level);
return -1;
}
@@ -116,7 +115,8 @@ do_md_create (const char *name, char *const *devices,
level = "raid1";
if (optargs_bitmask & GUESTFS_MD_CREATE_CHUNK_BITMASK) {
- /* chunk is bytes in the libguestfs API, but K when we pass it to mdadm */
+ /* chunk is bytes in the libguestfs API, but K when we pass it to mdadm
+ */
if ((chunk & 1023) != 0) {
reply_with_error ("chunk size must be a multiple of 1024 bytes");
return -1;
@@ -126,7 +126,8 @@ do_md_create (const char *name, char *const *devices,
/* Check invariant. */
if (count_strings (devices) + count_bits (umissingbitmap) !=
(size_t) (nrdevices + spare)) {
- reply_with_error ("devices (%zu) + bits set in missingbitmap (%zu) is not equal
to nrdevices (%d) + spare (%d)",
+ reply_with_error ("devices (%zu) + bits set in missingbitmap (%zu) is "
+ "not equal to nrdevices (%d) + spare (%d)",
count_strings (devices), count_bits (umissingbitmap),
nrdevices, spare);
return -1;
@@ -189,7 +190,8 @@ do_md_create (const char *name, char *const *devices,
static int
glob_errfunc (const char *epath, int eerrno)
{
- fprintf (stderr, "glob: failure reading %s: %s\n", epath, strerror
(eerrno));
+ fprintf (stderr, "glob: failure reading %s: %s\n", epath,
+ strerror (eerrno));
return 1;
}
@@ -236,7 +238,8 @@ do_list_md_devices (void)
reply_with_error ("glob: returned GLOB_NOSPACE: "
"rerun with LIBGUESTFS_DEBUG=1");
goto error;
- } else if (err == GLOB_ABORTED) {
+ }
+ else if (err == GLOB_ABORTED) {
reply_with_error ("glob: returned GLOB_ABORTED: "
"rerun with LIBGUESTFS_DEBUG=1");
goto error;
@@ -265,15 +268,17 @@ do_list_md_devices (void)
continue;
}
- if (add_string_nodup (&ret, dev) == -1) goto error;
+ if (add_string_nodup (&ret, dev) == -1)
+ goto error;
}
- if (end_stringsbuf (&ret) == -1) goto error;
+ if (end_stringsbuf (&ret) == -1)
+ goto error;
globfree (&mds);
return ret.argv;
- error:
+error:
globfree (&mds);
if (ret.argv != NULL)
free_stringslen (ret.argv, ret.size);
@@ -315,14 +320,17 @@ do_md_detail (const char *md)
char *line = lines[i];
/* Skip blank lines (shouldn't happen) */
- if (line[0] == '\0') continue;
+ if (line[0] == '\0')
+ continue;
/* Split the line in 2 at the equals sign */
char *eq = strchr (line, '=');
if (eq) {
- *eq = '\0'; eq++;
+ *eq = '\0';
+ eq++;
- /* Remove the MD_ prefix from the key and translate the remainder to lower
+ /* Remove the MD_ prefix from the key and translate the remainder to
+ * lower
* case */
if (STRPREFIX (line, "MD_")) {
line += 3;
@@ -332,12 +340,15 @@ do_md_detail (const char *md)
}
/* Add the key/value pair to the output */
- if (add_string (&ret, line) == -1 ||
- add_string (&ret, eq) == -1) goto error;
- } else {
- /* Ignore lines with no equals sign (shouldn't happen). Log to stderr so
+ if (add_string (&ret, line) == -1 || add_string (&ret, eq) == -1)
+ goto error;
+ }
+ else {
+ /* Ignore lines with no equals sign (shouldn't happen). Log to stderr
+ * so
* it will show up in LIBGUESTFS_DEBUG. */
- fprintf (stderr, "md-detail: unexpected mdadm output ignored: %s",
line);
+ fprintf (stderr, "md-detail: unexpected mdadm output ignored: %s",
+ line);
}
}
@@ -346,7 +357,7 @@ do_md_detail (const char *md)
return ret.argv;
- error:
+error:
if (ret.argv != NULL)
free_stringslen (ret.argv, ret.size);
@@ -359,7 +370,7 @@ do_md_stop (const char *md)
int r;
CLEANUP_FREE char *err = NULL;
- const char *mdadm[] = { str_mdadm, "--stop", md, NULL};
+ const char *mdadm[] = { str_mdadm, "--stop", md, NULL };
r = commandv (NULL, &err, mdadm);
if (r == -1) {
reply_with_error ("%s", err);
@@ -401,7 +412,7 @@ parse_md_stat_line (char *line)
*/
spaces = count_spaces (line);
ret->guestfs_int_mdstat_list_val =
- calloc (spaces+1, sizeof (struct guestfs_int_mdstat));
+ calloc (spaces + 1, sizeof (struct guestfs_int_mdstat));
if (ret->guestfs_int_mdstat_list_val == NULL) {
reply_with_perror ("calloc");
free (ret);
@@ -414,7 +425,7 @@ parse_md_stat_line (char *line)
next = &line[len];
else {
line[len] = '\0';
- next = &line[len+1];
+ next = &line[len + 1];
}
if (verbose)
@@ -430,7 +441,7 @@ parse_md_stat_line (char *line)
if (p > q)
continue;
- ret->guestfs_int_mdstat_list_len = n+1;
+ ret->guestfs_int_mdstat_list_len = n + 1;
t = &ret->guestfs_int_mdstat_list_val[n];
/* Device name is everything before the '[' character, but we
@@ -448,7 +459,7 @@ parse_md_stat_line (char *line)
}
/* Device index is the number after '['. */
- line = p+1;
+ line = p + 1;
*q = '\0';
if (sscanf (line, "%" SCNi32, &t->mdstat_index) != 1) {
reply_with_error ("not a device number: %s", line);
@@ -456,9 +467,9 @@ parse_md_stat_line (char *line)
}
/* Looking for flags "(F)(S)...". */
- line = q+1;
+ line = q + 1;
len = strlen (line);
- t->mdstat_flags = malloc (len+1);
+ t->mdstat_flags = malloc (len + 1);
if (!t->mdstat_flags) {
reply_with_error ("malloc");
goto error;
@@ -475,8 +486,8 @@ parse_md_stat_line (char *line)
return ret;
- error:
- for (i = 0; i < spaces+1; ++i) {
+error:
+ for (i = 0; i < spaces + 1; ++i) {
free (ret->guestfs_int_mdstat_list_val[i].mdstat_device);
free (ret->guestfs_int_mdstat_list_val[i].mdstat_flags);
}
@@ -507,10 +518,10 @@ do_md_stat (const char *md)
/* Search for a line which begins with "<md> : ". */
while ((n = getline (&line, &allocsize, fp)) != -1) {
- if (STRPREFIX (line, md) &&
- line[mdlen] == ' ' && line[mdlen+1] == ':' &&
line[mdlen+2] == ' ') {
+ if (STRPREFIX (line, md) && line[mdlen] == ' ' &&
+ line[mdlen + 1] == ':' && line[mdlen + 2] == ' ') {
/* Found it. */
- ret = parse_md_stat_line (&line[mdlen+3]);
+ ret = parse_md_stat_line (&line[mdlen + 3]);
if (!ret) {
fclose (fp);
return NULL;
@@ -525,7 +536,7 @@ do_md_stat (const char *md)
if (fclose (fp) == EOF) {
reply_with_perror ("fclose: %s", "/proc/mdstat");
- xdr_free ((xdrproc_t) xdr_guestfs_int_mdstat_list, (char *) ret);
+ xdr_free ((xdrproc_t)xdr_guestfs_int_mdstat_list, (char *)ret);
return NULL;
}
diff --git a/daemon/mkfs.c b/daemon/mkfs.c
index cef3574..3898d2f 100644
--- a/daemon/mkfs.c
+++ b/daemon/mkfs.c
@@ -30,8 +30,8 @@
#define MAX_ARGS 64
-GUESTFSD_EXT_CMD(str_mke2fs, mke2fs);
-GUESTFSD_EXT_CMD(str_mkfs, mkfs);
+GUESTFSD_EXT_CMD (str_mke2fs, mke2fs);
+GUESTFSD_EXT_CMD (str_mkfs, mkfs);
/* Takes optional arguments, consult optargs_bitmask. */
int
@@ -111,8 +111,7 @@ do_mkfs (const char *fstype, const char *device, int blocksize,
return -1;
}
- if (STREQ (fstype, "vfat") ||
- STREQ (fstype, "msdos")) {
+ if (STREQ (fstype, "vfat") || STREQ (fstype, "msdos")) {
/* For VFAT map the blocksize into a cluster size. However we
* have to determine the block device sector size in order to do
* this.
@@ -123,12 +122,15 @@ do_mkfs (const char *fstype, const char *device, int blocksize,
int sectors_per_cluster = blocksize / ss;
if (sectors_per_cluster < 1 || sectors_per_cluster > 128) {
- reply_with_error ("unsupported cluster size for %s filesystem (requested
cluster size = %d, sector size = %d, trying sectors per cluster = %d)",
+ reply_with_error ("unsupported cluster size for %s filesystem "
+ "(requested cluster size = %d, sector size = %d, "
+ "trying sectors per cluster = %d)",
fstype, blocksize, ss, sectors_per_cluster);
return -1;
}
- snprintf (blocksize_str, sizeof blocksize_str, "%d",
sectors_per_cluster);
+ snprintf (blocksize_str, sizeof blocksize_str, "%d",
+ sectors_per_cluster);
ADD_ARG (argv, i, "-s");
ADD_ARG (argv, i, blocksize_str);
}
@@ -140,7 +142,8 @@ do_mkfs (const char *fstype, const char *device, int blocksize,
}
else if (STREQ (fstype, "btrfs")) {
/* For btrfs, blocksize cannot be specified (RHBZ#807905). */
- reply_with_error ("blocksize cannot be set on btrfs filesystems, use
'mkfs-btrfs'");
+ reply_with_error (
+ "blocksize cannot be set on btrfs filesystems, use
'mkfs-btrfs'");
return -1;
}
else if (STREQ (fstype, "xfs")) {
@@ -164,7 +167,8 @@ do_mkfs (const char *fstype, const char *device, int blocksize,
if (optargs_bitmask & GUESTFS_MKFS_INODE_BITMASK) {
if (!extfs) {
- reply_with_error ("inode size (-I) can only be set on ext2/3/4
filesystems");
+ reply_with_error (
+ "inode size (-I) can only be set on ext2/3/4 filesystems");
return -1;
}
@@ -180,7 +184,8 @@ do_mkfs (const char *fstype, const char *device, int blocksize,
if (optargs_bitmask & GUESTFS_MKFS_SECTORSIZE_BITMASK) {
if (!STREQ (fstype, "ufs")) {
- reply_with_error ("sector size (-S) can only be set on ufs
filesystems");
+ reply_with_error (
+ "sector size (-S) can only be set on ufs filesystems");
return -1;
}
@@ -216,8 +221,8 @@ do_mkfs (const char *fstype, const char *device, int blocksize,
}
else if (STREQ (fstype, "xfs")) {
if (strlen (label) > XFS_LABEL_MAX) {
- reply_with_error ("%s: xfs labels are limited to %d bytes",
- label, XFS_LABEL_MAX);
+ reply_with_error ("%s: xfs labels are limited to %d bytes", label,
+ XFS_LABEL_MAX);
return -1;
}
@@ -229,8 +234,8 @@ do_mkfs (const char *fstype, const char *device, int blocksize,
ADD_ARG (argv, i, label);
}
else {
- reply_with_error ("don't know how to set the label for '%s'
filesystems",
- fstype);
+ reply_with_error (
+ "don't know how to set the label for '%s' filesystems",
fstype);
return -1;
}
}
diff --git a/daemon/mknod.c b/daemon/mknod.c
index d2ae02d..bea9411 100644
--- a/daemon/mknod.c
+++ b/daemon/mknod.c
@@ -38,13 +38,13 @@ optgroup_mknod_available (void)
return 1;
}
-#define CHECK_MODE \
- do { \
- if ((mode & ~07777) != 0) { \
+#define CHECK_MODE \
+ do { \
+ if ((mode & ~07777) != 0) { \
reply_with_error ("%o: mode must specify only file permission bits", \
- (unsigned int) mode); \
- return -1; \
- } \
+ (unsigned int)mode); \
+ return -1; \
+ } \
} while (0)
int
diff --git a/daemon/mktemp.c b/daemon/mktemp.c
index 39231adf..9dcffb7 100644
--- a/daemon/mktemp.c
+++ b/daemon/mktemp.c
@@ -49,8 +49,7 @@ do_mkdtemp (const char *template)
}
char *
-do_mktemp (const char *template,
- const char *suffix)
+do_mktemp (const char *template, const char *suffix)
{
char *dest_name = NULL;
size_t suffix_len = 0;
@@ -83,7 +82,7 @@ do_mktemp (const char *template,
}
CHROOT_IN;
- fd = mkstemps (dest_name, (int) suffix_len);
+ fd = mkstemps (dest_name, (int)suffix_len);
CHROOT_OUT;
if (fd == -1) {
diff --git a/daemon/modprobe.c b/daemon/modprobe.c
index 0b7896a..97fcf93 100644
--- a/daemon/modprobe.c
+++ b/daemon/modprobe.c
@@ -27,7 +27,7 @@
#include "actions.h"
#include "optgroups.h"
-GUESTFSD_EXT_CMD(str_modprobe, modprobe);
+GUESTFSD_EXT_CMD (str_modprobe, modprobe);
int
optgroup_linuxmodules_available (void)
diff --git a/daemon/mount.c b/daemon/mount.c
index ef51d48..a538423 100644
--- a/daemon/mount.c
+++ b/daemon/mount.c
@@ -33,8 +33,8 @@
#define MAX_ARGS 64
-GUESTFSD_EXT_CMD(str_mount, mount);
-GUESTFSD_EXT_CMD(str_umount, umount);
+GUESTFSD_EXT_CMD (str_mount, mount);
+GUESTFSD_EXT_CMD (str_umount, umount);
/* You must mount something on "/" first before many operations.
* Hence we have an internal function which can test if something is
@@ -96,7 +96,8 @@ is_device_mounted (const char *device)
while ((m = getmntent (fp)) != NULL) {
if ((sysroot_len > 0 && STREQ (m->mnt_dir, sysroot)) ||
- (STRPREFIX (m->mnt_dir, sysroot) && m->mnt_dir[sysroot_len] ==
'/')) {
+ (STRPREFIX (m->mnt_dir, sysroot) &&
+ m->mnt_dir[sysroot_len] == '/')) {
if (stat (m->mnt_fsname, &stat2) == 0) {
if (stat1.st_rdev == stat2.st_rdev) {
/* found it */
@@ -141,7 +142,8 @@ do_mount_vfs (const char *options, const char *vfstype,
return -1;
}
if (!S_ISDIR (statbuf.st_mode)) {
- reply_with_perror ("mount: %s: mount point is not a directory",
mountpoint);
+ reply_with_perror ("mount: %s: mount point is not a directory",
+ mountpoint);
return -1;
}
@@ -150,20 +152,20 @@ do_mount_vfs (const char *options, const char *vfstype,
int
mount_vfs_nochroot (const char *options, const char *vfstype,
- const mountable_t *mountable,
- const char *mp, const char *user_mp)
+ const mountable_t *mountable, const char *mp,
+ const char *user_mp)
{
CLEANUP_FREE char *options_plus = NULL;
const char *device = mountable->device;
if (mountable->type == MOUNTABLE_BTRFSVOL) {
if (options && strlen (options) > 0) {
- if (asprintf (&options_plus, "subvol=%s,%s",
- mountable->volume, options) == -1) {
+ if (asprintf (&options_plus, "subvol=%s,%s", mountable->volume,
+ options) == -1) {
reply_with_perror ("asprintf");
return -1;
}
}
-
+
else {
if (asprintf (&options_plus, "subvol=%s", mountable->volume) ==
-1) {
reply_with_perror ("asprintf");
@@ -175,16 +177,15 @@ mount_vfs_nochroot (const char *options, const char *vfstype,
CLEANUP_FREE char *error = NULL;
int r;
if (vfstype)
- r = command (NULL, &error,
- str_mount, "-o", options_plus ? options_plus : options,
- "-t", vfstype, device, mp, NULL);
- else
- r = command (NULL, &error,
- str_mount, "-o", options_plus ? options_plus : options,
+ r = command (NULL, &error, str_mount, "-o",
+ options_plus ? options_plus : options, "-t", vfstype,
device, mp, NULL);
+ else
+ r = command (NULL, &error, str_mount, "-o",
+ options_plus ? options_plus : options, device, mp, NULL);
if (r == -1) {
- reply_with_error ("%s on %s (options: '%s'): %s",
- device, user_mp, options, error);
+ reply_with_error ("%s on %s (options: '%s'): %s", device, user_mp,
+ options, error);
return -1;
}
@@ -212,8 +213,7 @@ do_mount_options (const char *options, const mountable_t *mountable,
/* Takes optional arguments, consult optargs_bitmask. */
int
-do_umount (const char *pathordevice,
- int force, int lazyunmount)
+do_umount (const char *pathordevice, int force, int lazyunmount)
{
int r;
CLEANUP_FREE char *err = NULL;
@@ -223,8 +223,7 @@ do_umount (const char *pathordevice,
size_t i = 0;
is_dev = STREQLEN (pathordevice, "/dev/", 5);
- buf = is_dev ? strdup (pathordevice)
- : sysroot_path (pathordevice);
+ buf = is_dev ? strdup (pathordevice) : sysroot_path (pathordevice);
if (buf == NULL) {
reply_with_perror ("malloc");
return -1;
@@ -283,16 +282,14 @@ mounts_or_mountpoints (int mp)
endmntent (fp);
return NULL;
}
- if (mp &&
- add_string (&ret, "/") == -1)
+ if (mp && add_string (&ret, "/") == -1)
goto error;
}
/* Or allow a mount directory like "/sysroot/...". */
if (STRPREFIX (m->mnt_dir, sysroot) && m->mnt_dir[sysroot_len] ==
'/') {
if (add_string (&ret, m->mnt_fsname) == -1)
goto error;
- if (mp &&
- add_string (&ret, &m->mnt_dir[sysroot_len]) == -1)
+ if (mp && add_string (&ret, &m->mnt_dir[sysroot_len]) == -1)
goto error;
}
}
@@ -351,8 +348,8 @@ do_mountpoints (void)
static int
compare_longest_first (const void *vp1, const void *vp2)
{
- char * const *p1 = (char * const *) vp1;
- char * const *p2 = (char * const *) vp2;
+ char *const *p1 = (char *const *)vp1;
+ char *const *p2 = (char *const *)vp2;
int n1 = strlen (*p1);
int n2 = strlen (*p2);
return n2 - n1;
@@ -384,7 +381,8 @@ do_umount_all (void)
while ((m = getmntent (fp)) != NULL) {
if (verbose) {
- fprintf (stderr, "umount-all: /proc/mounts: fsname=%s dir=%s type=%s opts=%s
freq=%d passno=%d\n",
+ fprintf (stderr, "umount-all: /proc/mounts: fsname=%s dir=%s type=%s "
+ "opts=%s freq=%d passno=%d\n",
m->mnt_fsname, m->mnt_dir, m->mnt_type, m->mnt_opts,
m->mnt_freq, m->mnt_passno);
}
@@ -408,7 +406,8 @@ do_umount_all (void)
endmntent (fp);
if (mounts.size > 0)
- qsort (mounts.argv, mounts.size, sizeof (char *), compare_longest_first);
+ qsort (mounts.argv, mounts.size, sizeof (char *),
+ compare_longest_first);
/* Unmount them. */
for (i = 0; i < mounts.size; ++i) {
diff --git a/daemon/ntfs.c b/daemon/ntfs.c
index e191a19..111cb46 100644
--- a/daemon/ntfs.c
+++ b/daemon/ntfs.c
@@ -31,10 +31,10 @@
#define MAX_ARGS 64
-GUESTFSD_EXT_CMD(str_ntfs3g_probe, ntfs-3g.probe);
-GUESTFSD_EXT_CMD(str_ntfsresize, ntfsresize);
-GUESTFSD_EXT_CMD(str_ntfsfix, ntfsfix);
-GUESTFSD_EXT_CMD(str_ntfslabel, ntfslabel);
+GUESTFSD_EXT_CMD (str_ntfs3g_probe, ntfs - 3g.probe);
+GUESTFSD_EXT_CMD (str_ntfsresize, ntfsresize);
+GUESTFSD_EXT_CMD (str_ntfsfix, ntfsfix);
+GUESTFSD_EXT_CMD (str_ntfslabel, ntfslabel);
int
optgroup_ntfs3g_available (void)
@@ -65,8 +65,8 @@ ntfs_get_label (const char *device)
/* Trim trailing \n if present. */
len = strlen (out);
- if (len > 0 && out[len-1] == '\n')
- out[len-1] = '\0';
+ if (len > 0 && out[len - 1] == '\n')
+ out[len - 1] = '\0';
return out;
}
@@ -178,7 +178,8 @@ ntfs_minimum_size (const char *device)
if (verbose) {
for (i = 0; lines[i] != NULL; ++i)
- fprintf (stderr, "ntfs_minimum_size: lines[%zu] = \"%s\"\n", i,
lines[i]);
+ fprintf (stderr, "ntfs_minimum_size: lines[%zu] = \"%s\"\n",
i,
+ lines[i]);
}
#if __WORDSIZE == 64
@@ -200,8 +201,8 @@ ntfs_minimum_size (const char *device)
}
}
else if (STRPREFIX (lines[i], volume_size_pattern)) {
- if (XSTRTOD64 (lines[i] + strlen (volume_size_pattern),
- NULL, 10, &volume_size, NULL) != LONGINT_OK) {
+ if (XSTRTOD64 (lines[i] + strlen (volume_size_pattern), NULL, 10,
+ &volume_size, NULL) != LONGINT_OK) {
reply_with_error ("cannot parse volume size");
return -1;
}
@@ -225,8 +226,8 @@ ntfs_minimum_size (const char *device)
for (i = 0; lines[i] != NULL; ++i) {
if (STRPREFIX (lines[i], size_pattern)) {
int64_t ret;
- if (XSTRTOD64 (lines[i] + strlen (size_pattern),
- NULL, 10, &ret, NULL) != LONGINT_OK) {
+ if (XSTRTOD64 (lines[i] + strlen (size_pattern), NULL, 10, &ret,
+ NULL) != LONGINT_OK) {
reply_with_error ("cannot parse minimum size");
return -1;
}
@@ -236,7 +237,8 @@ ntfs_minimum_size (const char *device)
#undef XSTRTOD64
- reply_with_error ("minimum size not found. Check output format:\n%s", out);
+ reply_with_error ("minimum size not found. Check output format:\n%s",
+ out);
return -1;
}
@@ -288,8 +290,8 @@ do_ntfscat_i (const mountable_t *mountable, int64_t inode)
}
/* Construct the command. */
- if (asprintf (&cmd, "ntfscat -i %" PRIi64 " %s",
- inode, mountable->device) == -1) {
+ if (asprintf (&cmd, "ntfscat -i %" PRIi64 " %s", inode,
+ mountable->device) == -1) {
reply_with_perror ("asprintf");
return -1;
}
@@ -318,18 +320,18 @@ do_ntfscat_i (const mountable_t *mountable, int64_t inode)
if (ferror (fp)) {
fprintf (stderr, "fread: %" PRIi64 ": %m\n", inode);
- send_file_end (1); /* Cancel. */
+ send_file_end (1); /* Cancel. */
pclose (fp);
return -1;
}
if (pclose (fp) != 0) {
fprintf (stderr, "pclose: %" PRIi64 ": %m\n", inode);
- send_file_end (1); /* Cancel. */
+ send_file_end (1); /* Cancel. */
return -1;
}
- if (send_file_end (0)) /* Normal end of file. */
+ if (send_file_end (0)) /* Normal end of file. */
return -1;
return 0;
diff --git a/daemon/ntfsclone.c b/daemon/ntfsclone.c
index f04017c..9ffbbba 100644
--- a/daemon/ntfsclone.c
+++ b/daemon/ntfsclone.c
@@ -32,7 +32,7 @@
#include "actions.h"
#include "optgroups.h"
-GUESTFSD_EXT_CMD(str_ntfsclone, ntfsclone);
+GUESTFSD_EXT_CMD (str_ntfsclone, ntfsclone);
/* Read the error file. Returns a string that the caller must free. */
static char *
@@ -50,10 +50,10 @@ read_error_file (char *error_file)
}
/* Remove trailing \n character if any. */
- if (len > 0 && str[len-1] == '\n')
+ if (len > 0 && str[len - 1] == '\n')
str[--len] = '\0';
- return str; /* caller frees */
+ return str; /* caller frees */
}
static int
@@ -82,8 +82,8 @@ do_ntfsclone_in (const char *device)
close (fd);
/* Construct the command. */
- if (asprintf (&cmd, "%s -O %s --restore-image - 2> %s",
- str_ntfsclone, device, error_file) == -1) {
+ if (asprintf (&cmd, "%s -O %s --restore-image - 2> %s",
str_ntfsclone,
+ device, error_file) == -1) {
err = errno;
r = cancel_receive ();
errno = err;
@@ -111,7 +111,7 @@ do_ntfsclone_in (const char *device)
fd = fileno (fp);
r = receive_file (write_cb, &fd);
- if (r == -1) { /* write error */
+ if (r == -1) { /* write error */
cancel_receive ();
CLEANUP_FREE char *errstr = read_error_file (error_file);
reply_with_error ("write error on device: %s: %s", device, errstr);
@@ -119,7 +119,7 @@ do_ntfsclone_in (const char *device)
pclose (fp);
return -1;
}
- if (r == -2) { /* cancellation from library */
+ if (r == -2) { /* cancellation from library */
/* This error is ignored by the library since it initiated the
* cancel. Nevertheless we must send an error reply here.
*/
@@ -145,9 +145,8 @@ do_ntfsclone_in (const char *device)
/* Has one FileOut parameter. */
/* Takes optional arguments, consult optargs_bitmask. */
int
-do_ntfsclone_out (const char *device,
- int metadataonly, int rescue, int ignorefscheck,
- int preservetimestamps, int force)
+do_ntfsclone_out (const char *device, int metadataonly, int rescue,
+ int ignorefscheck, int preservetimestamps, int force)
{
int r;
FILE *fp;
@@ -161,14 +160,28 @@ do_ntfsclone_out (const char *device,
}
/* Construct the ntfsclone command. */
- if (asprintf (&cmd, "%s -o - --save-image%s%s%s%s%s %s",
- str_ntfsclone,
- (optargs_bitmask & GUESTFS_NTFSCLONE_OUT_METADATAONLY_BITMASK)
&& metadataonly ? " --metadata" : "",
- (optargs_bitmask & GUESTFS_NTFSCLONE_OUT_RESCUE_BITMASK) &&
rescue ? " --rescue" : "",
- (optargs_bitmask & GUESTFS_NTFSCLONE_OUT_IGNOREFSCHECK_BITMASK)
&& ignorefscheck ? " --ignore-fs-check" : "",
- (optargs_bitmask & GUESTFS_NTFSCLONE_OUT_PRESERVETIMESTAMPS_BITMASK)
&& preservetimestamps ? " --preserve-timestamps" : "",
- (optargs_bitmask & GUESTFS_NTFSCLONE_OUT_FORCE_BITMASK) &&
force ? " --force" : "",
- device) == -1) {
+ if (asprintf (
+ &cmd, "%s -o - --save-image%s%s%s%s%s %s", str_ntfsclone,
+ (optargs_bitmask & GUESTFS_NTFSCLONE_OUT_METADATAONLY_BITMASK) &&
+ metadataonly
+ ? " --metadata"
+ : "",
+ (optargs_bitmask & GUESTFS_NTFSCLONE_OUT_RESCUE_BITMASK) && rescue
+ ? " --rescue"
+ : "",
+ (optargs_bitmask & GUESTFS_NTFSCLONE_OUT_IGNOREFSCHECK_BITMASK) &&
+ ignorefscheck
+ ? " --ignore-fs-check"
+ : "",
+ (optargs_bitmask &
+ GUESTFS_NTFSCLONE_OUT_PRESERVETIMESTAMPS_BITMASK) &&
+ preservetimestamps
+ ? " --preserve-timestamps"
+ : "",
+ (optargs_bitmask & GUESTFS_NTFSCLONE_OUT_FORCE_BITMASK) && force
+ ? " --force"
+ : "",
+ device) == -1) {
reply_with_perror ("asprintf");
return -1;
}
@@ -197,18 +210,18 @@ do_ntfsclone_out (const char *device,
if (ferror (fp)) {
fprintf (stderr, "fread: %s: %m\n", device);
- send_file_end (1); /* Cancel. */
+ send_file_end (1); /* Cancel. */
pclose (fp);
return -1;
}
if (pclose (fp) != 0) {
fprintf (stderr, "pclose: %s: %m\n", device);
- send_file_end (1); /* Cancel. */
+ send_file_end (1); /* Cancel. */
return -1;
}
- if (send_file_end (0)) /* Normal end of file. */
+ if (send_file_end (0)) /* Normal end of file. */
return -1;
return 0;
diff --git a/daemon/parted.c b/daemon/parted.c
index 00ae424..ca72627 100644
--- a/daemon/parted.c
+++ b/daemon/parted.c
@@ -30,9 +30,9 @@
#include "actions.h"
#include "optgroups.h"
-GUESTFSD_EXT_CMD(str_parted, parted);
-GUESTFSD_EXT_CMD(str_sfdisk, sfdisk);
-GUESTFSD_EXT_CMD(str_sgdisk, sgdisk);
+GUESTFSD_EXT_CMD (str_parted, parted);
+GUESTFSD_EXT_CMD (str_sfdisk, sfdisk);
+GUESTFSD_EXT_CMD (str_sgdisk, sgdisk);
/* Notes:
*
@@ -52,16 +52,11 @@ static const char *
check_parttype (const char *parttype)
{
/* Check and translate parttype. */
- if (STREQ (parttype, "aix") ||
- STREQ (parttype, "amiga") ||
- STREQ (parttype, "bsd") ||
- STREQ (parttype, "dasd") ||
- STREQ (parttype, "dvh") ||
- STREQ (parttype, "gpt") ||
- STREQ (parttype, "mac") ||
- STREQ (parttype, "msdos") ||
- STREQ (parttype, "pc98") ||
- STREQ (parttype, "sun"))
+ if (STREQ (parttype, "aix") || STREQ (parttype, "amiga") ||
+ STREQ (parttype, "bsd") || STREQ (parttype, "dasd") ||
+ STREQ (parttype, "dvh") || STREQ (parttype, "gpt") ||
+ STREQ (parttype, "mac") || STREQ (parttype, "msdos") ||
+ STREQ (parttype, "pc98") || STREQ (parttype, "sun"))
return parttype;
else if (STREQ (parttype, "rdb"))
return "amiga";
@@ -81,14 +76,15 @@ do_part_init (const char *device, const char *parttype)
parttype = check_parttype (parttype);
if (!parttype) {
- reply_with_error ("unknown partition type: common choices are \"gpt\"
and \"msdos\"");
+ reply_with_error (
+ "unknown partition type: common choices are \"gpt\" and
\"msdos\"");
return -1;
}
udev_settle ();
- r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
- str_parted, "-s", "--", device, "mklabel",
parttype, NULL);
+ r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR, str_parted,
+ "-s", "--", device, "mklabel", parttype,
NULL);
if (r == -1) {
reply_with_error ("parted: %s: %s", device, err);
return -1;
@@ -100,8 +96,8 @@ do_part_init (const char *device, const char *parttype)
}
int
-do_part_add (const char *device, const char *prlogex,
- int64_t startsect, int64_t endsect)
+do_part_add (const char *device, const char *prlogex, int64_t startsect,
+ int64_t endsect)
{
int r;
CLEANUP_FREE char *err = NULL;
@@ -109,8 +105,7 @@ do_part_add (const char *device, const char *prlogex,
char endstr[32];
/* Check and translate prlogex. */
- if (STREQ (prlogex, "primary") ||
- STREQ (prlogex, "logical") ||
+ if (STREQ (prlogex, "primary") || STREQ (prlogex, "logical") ||
STREQ (prlogex, "extended"))
;
else if (STREQ (prlogex, "p"))
@@ -120,7 +115,9 @@ do_part_add (const char *device, const char *prlogex,
else if (STREQ (prlogex, "e"))
prlogex = "extended";
else {
- reply_with_error ("unknown partition type: %s: this should be
\"primary\", \"logical\" or \"extended\"", prlogex);
+ reply_with_error ("unknown partition type: %s: this should be "
+ "\"primary\", \"logical\" or
\"extended\"",
+ prlogex);
return -1;
}
@@ -140,9 +137,9 @@ do_part_add (const char *device, const char *prlogex,
* name_ to prlogex, eg. "primary". I would essentially describe
* this as a bug in the parted mkpart command.
*/
- r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
- str_parted, "-s", "--",
- device, "mkpart", prlogex, startstr, endstr, NULL);
+ r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR, str_parted,
+ "-s", "--", device, "mkpart", prlogex,
startstr, endstr,
+ NULL);
if (r == -1) {
reply_with_error ("parted: %s: %s", device, err);
return -1;
@@ -169,8 +166,8 @@ do_part_del (const char *device, int partnum)
udev_settle ();
- r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
- str_parted, "-s", "--", device, "rm",
partnum_str, NULL);
+ r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR, str_parted,
+ "-s", "--", device, "rm", partnum_str,
NULL);
if (r == -1) {
reply_with_error ("parted: %s: %s", device, err);
return -1;
@@ -189,7 +186,8 @@ do_part_disk (const char *device, const char *parttype)
parttype = check_parttype (parttype);
if (!parttype) {
- reply_with_error ("unknown partition type: common choices are \"gpt\"
and \"msdos\"");
+ reply_with_error (
+ "unknown partition type: common choices are \"gpt\" and
\"msdos\"");
return -1;
}
@@ -208,10 +206,8 @@ do_part_disk (const char *device, const char *parttype)
udev_settle ();
- r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
- str_parted, "-s", "--",
- device,
- "mklabel", parttype,
+ r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR, str_parted,
+ "-s", "--", device, "mklabel", parttype,
/* See comment about about the parted mkpart command. */
"mkpart", STREQ (parttype, "gpt") ? "p1" :
"primary",
startstr, endstr, NULL);
@@ -242,9 +238,9 @@ do_part_set_bootable (const char *device, int partnum, int bootable)
udev_settle ();
- r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
- str_parted, "-s", "--",
- device, "set", partstr, "boot", bootable ?
"on" : "off", NULL);
+ r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR, str_parted,
+ "-s", "--", device, "set", partstr,
"boot",
+ bootable ? "on" : "off", NULL);
if (r == -1) {
reply_with_error ("parted: %s: %s", device, err);
return -1;
@@ -272,8 +268,8 @@ do_part_set_name (const char *device, int partnum, const char *name)
udev_settle ();
- r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
- str_parted, "-s", "--", device, "name",
partstr, name, NULL);
+ r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR, str_parted,
+ "-s", "--", device, "name", partstr, name,
NULL);
if (r == -1) {
reply_with_error ("parted: %s: %s", device, err);
return -1;
@@ -298,8 +294,8 @@ get_table_field (const char *line, int n)
}
if (n > 0) {
- reply_with_error ("not enough fields in output of parted print command:
%s",
- line);
+ reply_with_error (
+ "not enough fields in output of parted print command: %s", line);
return NULL;
}
@@ -321,12 +317,10 @@ print_partition_table (const char *device, bool add_m_option)
int r;
if (add_m_option)
- r = command (&out, &err, str_parted, "-m", "-s",
"--", device,
- "unit", "b",
- "print", NULL);
+ r = command (&out, &err, str_parted, "-m", "-s",
"--", device, "unit",
+ "b", "print", NULL);
else
- r = command (&out, &err, str_parted, "-s", "--", device,
- "unit", "b",
+ r = command (&out, &err, str_parted, "-s", "--", device,
"unit", "b",
"print", NULL);
if (r == -1) {
int errcode = 0;
@@ -355,7 +349,8 @@ do_part_get_parttype (const char *device)
return NULL;
if (lines[0] == NULL || STRNEQ (lines[0], "BYT;")) {
- reply_with_error ("unknown signature, expected \"BYT;\" as first line
of the output: %s",
+ reply_with_error ("unknown signature, expected \"BYT;\" as first line
"
+ "of the output: %s",
lines[0] ? lines[0] : "(signature was null)");
return NULL;
}
@@ -424,16 +419,18 @@ do_part_list (const char *device)
&r->guestfs_int_partition_list_val[i].part_start,
&r->guestfs_int_partition_list_val[i].part_end,
&r->guestfs_int_partition_list_val[i].part_size) != 4) {
- reply_with_error ("could not parse row from output of parted print command:
%s", lines[row]);
+ reply_with_error (
+ "could not parse row from output of parted print command: %s",
+ lines[row]);
goto error3;
}
}
return r;
- error3:
+error3:
free (r->guestfs_int_partition_list_val);
- error2:
+error2:
free (r);
return NULL;
}
@@ -459,7 +456,8 @@ do_part_get_bootable (const char *device, int partnum)
* the matching partition number (RHBZ#602997).
*/
if (lines[0] == NULL || STRNEQ (lines[0], "BYT;")) {
- reply_with_error ("unknown signature, expected \"BYT;\" as first line
of the output: %s",
+ reply_with_error ("unknown signature, expected \"BYT;\" as first line
"
+ "of the output: %s",
lines[0] ? lines[0] : "(signature was null)");
return -1;
}
@@ -473,7 +471,9 @@ do_part_get_bootable (const char *device, int partnum)
int pnum;
for (row = 2; lines[row] != NULL; ++row) {
if (sscanf (lines[row], "%d:", &pnum) != 1) {
- reply_with_error ("could not parse row from output of parted print command:
%s", lines[row]);
+ reply_with_error (
+ "could not parse row from output of parted print command: %s",
+ lines[row]);
return -1;
}
if (pnum == partnum)
@@ -530,7 +530,8 @@ do_part_get_mbr_id (const char *device, int partnum)
return -1;
}
- const char *param = test_sfdisk_has_part_type () ? "--part-type" :
"--print-id";
+ const char *param =
+ test_sfdisk_has_part_type () ? "--part-type" : "--print-id";
char partnum_str[16];
snprintf (partnum_str, sizeof partnum_str, "%d", partnum);
@@ -566,22 +567,23 @@ do_part_set_mbr_id (const char *device, int partnum, int idbyte)
return -1;
}
- const char *param = test_sfdisk_has_part_type () ? "--part-type" :
"--change-id";
+ const char *param =
+ test_sfdisk_has_part_type () ? "--part-type" : "--change-id";
char partnum_str[16];
snprintf (partnum_str, sizeof partnum_str, "%d", partnum);
char idbyte_str[16];
/* NB: hex */
- snprintf (idbyte_str, sizeof partnum_str, "%x", (unsigned) idbyte);
+ snprintf (idbyte_str, sizeof partnum_str, "%x", (unsigned)idbyte);
CLEANUP_FREE char *err = NULL;
int r;
udev_settle ();
- r = command (NULL, &err, str_sfdisk,
- param, device, partnum_str, idbyte_str, NULL);
+ r = command (NULL, &err, str_sfdisk, param, device, partnum_str,
+ idbyte_str, NULL);
if (r == -1) {
reply_with_error ("sfdisk %s: %s", param, err);
return -1;
@@ -651,7 +653,8 @@ do_part_set_gpt_guid (const char *device, int partnum, const char
*guid)
}
static char *
-sgdisk_info_extract_field (const char *device, int partnum, const char *field,
+sgdisk_info_extract_field (const char *device, int partnum,
+ const char *field,
char *(*extract) (const char *path))
{
if (partnum <= 0) {
@@ -670,21 +673,23 @@ sgdisk_info_extract_field (const char *device, int partnum, const
char *field,
str_sgdisk, device, "-i", partnum_str, NULL);
if (r == -1) {
- reply_with_error ("%s %s -i %s: %s", str_sgdisk, device, partnum_str,
err);
+ reply_with_error ("%s %s -i %s: %s", str_sgdisk, device, partnum_str,
+ err);
return NULL;
}
CLEANUP_FREE_STRING_LIST char **lines = split_lines (err);
if (lines == NULL) {
- reply_with_error ("'%s %s -i %i' returned no output",
- str_sgdisk, device, partnum);
+ reply_with_error ("'%s %s -i %i' returned no output", str_sgdisk,
+ device, partnum);
return NULL;
}
int fieldlen = strlen (field);
/* Parse the output of sgdisk -i:
- * Partition GUID code: 21686148-6449-6E6F-744E-656564454649 (BIOS boot partition)
+ * Partition GUID code: 21686148-6449-6E6F-744E-656564454649 (BIOS boot
+ * partition)
* Partition unique GUID: 19AEC5FE-D63A-4A15-9D37-6FCBFB873DC0
* First sector: 2048 (at 1024.0 KiB)
* Last sector: 411647 (at 201.0 MiB)
@@ -696,14 +701,13 @@ sgdisk_info_extract_field (const char *device, int partnum, const
char *field,
char *line = *i;
/* Skip blank lines */
- if (line[0] == '\0') continue;
+ if (line[0] == '\0')
+ continue;
/* Split the line in 2 at the colon */
char *colon = strchr (line, ':');
if (colon) {
- if (colon - line == fieldlen &&
- memcmp (line, field, fieldlen) == 0)
- {
+ if (colon - line == fieldlen && memcmp (line, field, fieldlen) == 0) {
/* The value starts after the colon */
char *value = colon + 1;
@@ -719,11 +723,13 @@ sgdisk_info_extract_field (const char *device, int partnum, const
char *field,
return ret;
}
- } else {
+ }
+ else {
/* Ignore lines with no colon. Log to stderr so it will show up in
* LIBGUESTFS_DEBUG. */
if (verbose) {
- fprintf (stderr, "get-gpt-type: unexpected sgdisk output ignored:
%s\n",
+ fprintf (stderr,
+ "get-gpt-type: unexpected sgdisk output ignored: %s\n",
line);
}
}
@@ -731,7 +737,8 @@ sgdisk_info_extract_field (const char *device, int partnum, const char
*field,
/* If we got here it means we didn't find the field */
reply_with_error ("sgdisk output did not contain '%s'. "
- "See LIBGUESTFS_DEBUG output for more details", field);
+ "See LIBGUESTFS_DEBUG output for more details",
+ field);
return NULL;
}
@@ -755,8 +762,8 @@ extract_uuid (const char *value)
char *
do_part_get_gpt_type (const char *device, int partnum)
{
- return sgdisk_info_extract_field (device, partnum,
- "Partition GUID code", extract_uuid);
+ return sgdisk_info_extract_field (device, partnum, "Partition GUID code",
+ extract_uuid);
}
char *
@@ -786,13 +793,15 @@ do_part_get_name (const char *device, int partnum)
return NULL;
if (lines[0] == NULL || STRNEQ (lines[0], "BYT;")) {
- reply_with_error ("unknown signature, expected \"BYT;\" as first
line of the output: %s",
+ reply_with_error ("unknown signature, expected \"BYT;\" as first
"
+ "line of the output: %s",
lines[0] ? lines[0] : "(signature was null)");
return NULL;
}
if (lines[1] == NULL) {
- reply_with_error ("parted didn't return a line describing the
device");
+ reply_with_error (
+ "parted didn't return a line describing the device");
return NULL;
}
@@ -800,7 +809,9 @@ do_part_get_name (const char *device, int partnum)
int pnum;
for (row = 2; lines[row] != NULL; ++row) {
if (sscanf (lines[row], "%d:", &pnum) != 1) {
- reply_with_error ("could not parse row from output of parted print command:
%s", lines[row]);
+ reply_with_error (
+ "could not parse row from output of parted print command: %s",
+ lines[row]);
return NULL;
}
if (pnum == partnum)
@@ -817,8 +828,10 @@ do_part_get_name (const char *device, int partnum)
reply_with_error ("cannot get the name field from '%s'",
lines[row]);
return name;
- } else {
- reply_with_error ("part-get-name can only be used on GUID Partition
Tables");
+ }
+ else {
+ reply_with_error (
+ "part-get-name can only be used on GUID Partition Tables");
return NULL;
}
}
@@ -874,26 +887,26 @@ do_part_get_mbr_part_type (const char *device, int partnum)
size_t i;
int64_t temp_int64;
int part_num;
- char temp_type[16] = {'\0'};
- for (i = 0, row = start; row < end; ++i, ++row) {
+ char temp_type[16] = { '\0' };
+ for (i = 0, row = start; row < end; ++i, ++row) {
if (STREQ (parttype, "gpt")) {
memcpy (temp_type, "primary", strlen ("primary"));
if (sscanf (lines[row], "%d%" SCNi64 "B%" SCNi64 "B%"
SCNi64 "B",
- &part_num,
- &temp_int64,
- &temp_int64,
- &temp_int64) != 4) {
- reply_with_error ("could not parse row from output of parted print command:
%s", lines[row]);
+ &part_num, &temp_int64, &temp_int64, &temp_int64) != 4)
{
+ reply_with_error (
+ "could not parse row from output of parted print command: %s",
+ lines[row]);
return NULL;
}
- } else {
- if (sscanf (lines[row], "%d%" SCNi64 "B%" SCNi64 "B%"
SCNi64 "B" "%15s",
- &part_num,
- &temp_int64,
- &temp_int64,
- &temp_int64,
- temp_type) != 5) {
- reply_with_error ("could not parse row from output of parted print command:
%s", lines[row]);
+ }
+ else {
+ if (sscanf (lines[row], "%d%" SCNi64 "B%" SCNi64 "B%"
SCNi64 "B"
+ "%15s",
+ &part_num, &temp_int64, &temp_int64, &temp_int64,
+ temp_type) != 5) {
+ reply_with_error (
+ "could not parse row from output of parted print command: %s",
+ lines[row]);
return NULL;
}
}
@@ -904,16 +917,19 @@ do_part_get_mbr_part_type (const char *device, int partnum)
if (STRPREFIX (temp_type, "primary")) {
part_type = strdup ("primary");
if (part_type == NULL)
- goto error;
- } else if (STRPREFIX (temp_type, "logical")) {
+ goto error;
+ }
+ else if (STRPREFIX (temp_type, "logical")) {
part_type = strdup ("logical");
if (part_type == NULL)
- goto error;
- } else if (STRPREFIX (temp_type, "extended")) {
+ goto error;
+ }
+ else if (STRPREFIX (temp_type, "extended")) {
part_type = strdup ("extended");
if (part_type == NULL)
- goto error;
- } else
+ goto error;
+ }
+ else
goto error;
return part_type;
@@ -924,7 +940,7 @@ do_part_get_mbr_part_type (const char *device, int partnum)
return NULL;
}
- error:
+error:
reply_with_error ("strdup failed");
return NULL;
}
@@ -945,8 +961,7 @@ do_part_get_disk_guid (const char *device)
CLEANUP_FREE_STRING_LIST char **lines = split_lines (err);
if (lines == NULL) {
- reply_with_error ("'%s %s -p' returned no output",
- str_sgdisk, device);
+ reply_with_error ("'%s %s -p' returned no output", str_sgdisk,
device);
return NULL;
}
@@ -1005,7 +1020,7 @@ do_part_set_disk_guid_random (const char *device)
}
int
-do_part_expand_gpt(const char *device)
+do_part_expand_gpt (const char *device)
{
CLEANUP_FREE char *err = NULL;
@@ -1019,16 +1034,16 @@ do_part_expand_gpt(const char *device)
reply_with_error ("%s --pretend -e %s: %s", str_sgdisk, device, err);
return -1;
}
- if (err && strlen(err) != 0) {
+ if (err && strlen (err) != 0) {
/* Unexpected actions. */
reply_with_error ("%s --pretend -e %s: %s", str_sgdisk, device, err);
return -1;
}
- free(err);
+ free (err);
/* Now we can do a real run. */
- r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
- str_sgdisk, "-e", device, NULL);
+ r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR, str_sgdisk,
+ "-e", device, NULL);
if (r == -1) {
reply_with_error ("%s -e %s: %s", str_sgdisk, device, err);
diff --git a/daemon/proto.c b/daemon/proto.c
index 654dd3a..b0b9e18 100644
--- a/daemon/proto.c
+++ b/daemon/proto.c
@@ -27,7 +27,7 @@
#include <unistd.h>
#include <errno.h>
#include <error.h>
-#include <sys/param.h> /* defines MIN */
+#include <sys/param.h> /* defines MIN */
#include <sys/select.h>
#include <sys/time.h>
#include <rpc/types.h>
@@ -98,8 +98,8 @@ main_loop (int _sock)
if (verbose)
fprintf (stderr,
- "guestfsd: main_loop: new request, len 0x%" PRIx32 "\n",
- len);
+ "guestfsd: main_loop: new request, len 0x%" PRIx32
"\n",
+ len);
/* Cancellation sent from the library and received after the
* previous request has finished processing. Just ignore it.
@@ -108,7 +108,8 @@ main_loop (int _sock)
continue;
if (len > GUESTFS_MESSAGE_MAX)
- error (EXIT_FAILURE, 0, "incoming message is too long (%u bytes)", len);
+ error (EXIT_FAILURE, 0, "incoming message is too long (%u bytes)",
+ len);
buf = malloc (len);
if (!buf) {
@@ -125,17 +126,17 @@ main_loop (int _sock)
for (i = 0; i < len; i += 16) {
printf ("%04zx: ", i);
- for (j = i; j < MIN (i+16, len); ++j)
- printf ("%02x ", (unsigned char) buf[j]);
- for (; j < i+16; ++j)
+ for (j = i; j < MIN (i + 16, len); ++j)
+ printf ("%02x ", (unsigned char)buf[j]);
+ for (; j < i + 16; ++j)
printf (" ");
printf ("|");
- for (j = i; j < MIN (i+16, len); ++j)
+ for (j = i; j < MIN (i + 16, len); ++j)
if (c_isprint (buf[j]))
printf ("%c", buf[j]);
else
printf (".");
- for (; j < i+16; ++j)
+ for (; j < i + 16; ++j)
printf (" ");
printf ("|\n");
}
@@ -162,11 +163,11 @@ main_loop (int _sock)
}
if (hdr.direction != GUESTFS_DIRECTION_CALL) {
reply_with_error ("unexpected message direction (%d)",
- (int) hdr.direction);
+ (int)hdr.direction);
goto cont;
}
if (hdr.status != GUESTFS_STATUS_OK) {
- reply_with_error ("unexpected message status (%d)", (int) hdr.status);
+ reply_with_error ("unexpected message status (%d)", (int)hdr.status);
goto cont;
}
@@ -195,17 +196,16 @@ main_loop (int _sock)
gettimeofday (&end_t, NULL);
int64_t start_us, end_us, elapsed_us;
- start_us = (int64_t) start_t.tv_sec * 1000000 + start_t.tv_usec;
- end_us = (int64_t) end_t.tv_sec * 1000000 + end_t.tv_usec;
+ start_us = (int64_t)start_t.tv_sec * 1000000 + start_t.tv_usec;
+ end_us = (int64_t)end_t.tv_sec * 1000000 + end_t.tv_usec;
elapsed_us = end_us - start_us;
- fprintf (stderr,
- "guestfsd: main_loop: proc %d (%s) took %d.%02d seconds\n",
- proc_nr,
- proc_nr >= 0 && proc_nr <= GUESTFS_MAX_PROC_NR
- ? function_names[proc_nr] : "UNKNOWN PROCEDURE",
- (int) (elapsed_us / 1000000),
- (int) ((elapsed_us / 10000) % 100));
+ fprintf (
+ stderr, "guestfsd: main_loop: proc %d (%s) took %d.%02d seconds\n",
+ proc_nr, proc_nr >= 0 && proc_nr <= GUESTFS_MAX_PROC_NR
+ ? function_names[proc_nr]
+ : "UNKNOWN PROCEDURE",
+ (int)(elapsed_us / 1000000), (int)((elapsed_us / 10000) % 100));
}
cont:
@@ -247,7 +247,7 @@ reply_with_perror_errno (int err, const char *fs, ...)
if (r == -1)
error:
- error (EXIT_FAILURE, errno, "vasprintf");
+ error (EXIT_FAILURE, errno, "vasprintf");
r = asprintf (&buf2, "%s: %s", buf1, strerror (err));
if (r == -1)
@@ -298,8 +298,8 @@ send_error (int errnum, char *msg)
* to (char *) because they are defined that way in the XDR structs.
*/
err.errno_string =
- (char *) (errnum > 0 ? guestfs_int_errno_to_string (errnum) : "");
- err.error_message = (char *) msg;
+ (char *)(errnum > 0 ? guestfs_int_errno_to_string (errnum) : "");
+ err.error_message = (char *)msg;
if (!xdr_guestfs_message_error (&xdr, &err))
error (EXIT_FAILURE, 0, "failed to encode error message body");
@@ -348,7 +348,9 @@ reply (xdrproc_t xdrp, char *ret)
* we want to return an error message instead. (RHBZ#509597).
*/
if (!(*xdrp) (&xdr, ret)) {
- reply_with_error ("guestfsd: failed to encode reply body\n(maybe the reply
exceeds the maximum message size in the protocol?)");
+ reply_with_error ("guestfsd: failed to encode reply body\n(maybe the "
+ "reply exceeds the maximum message size in the "
+ "protocol?)");
xdr_destroy (&xdr);
return;
}
@@ -363,7 +365,7 @@ reply (xdrproc_t xdrp, char *ret)
if (xwrite (sock, lenbuf, 4) == -1)
error (EXIT_FAILURE, 0, "xwrite failed");
- if (xwrite (sock, buf, (size_t) len) == -1)
+ if (xwrite (sock, buf, (size_t)len) == -1)
error (EXIT_FAILURE, 0, "xwrite failed");
}
@@ -392,10 +394,11 @@ receive_file (receive_cb cb, void *opaque)
xdr_destroy (&xdr);
if (len == GUESTFS_CANCEL_FLAG)
- continue; /* Just ignore it. */
+ continue; /* Just ignore it. */
if (len > GUESTFS_MESSAGE_MAX)
- error (EXIT_FAILURE, 0, "incoming message is too long (%u bytes)", len);
+ error (EXIT_FAILURE, 0, "incoming message is too long (%u bytes)",
+ len);
buf = malloc (len);
if (!buf) {
@@ -415,31 +418,32 @@ receive_file (receive_cb cb, void *opaque)
xdr_destroy (&xdr);
if (verbose)
- fprintf (stderr,
- "guestfsd: receive_file: got chunk: cancel = 0x%x, len = %u, buf =
%p\n",
- (unsigned) chunk.cancel,
- chunk.data.data_len, chunk.data.data_val);
+ fprintf (stderr, "guestfsd: receive_file: got chunk: cancel = 0x%x, "
+ "len = %u, buf = %p\n",
+ (unsigned)chunk.cancel, chunk.data.data_len,
+ chunk.data.data_val);
if (chunk.cancel != 0 && chunk.cancel != 1) {
- fprintf (stderr,
- "guestfsd: receive_file: chunk.cancel != [0|1] ... "
- "continuing even though we have probably lost synchronization with
the library\n");
+ fprintf (stderr, "guestfsd: receive_file: chunk.cancel != [0|1] ... "
+ "continuing even though we have probably lost "
+ "synchronization with the library\n");
return -1;
}
if (chunk.cancel) {
if (verbose)
- fprintf (stderr,
- "guestfsd: receive_file: received cancellation from library\n");
- xdr_free ((xdrproc_t) xdr_guestfs_chunk, (char *) &chunk);
+ fprintf (
+ stderr,
+ "guestfsd: receive_file: received cancellation from library\n");
+ xdr_free ((xdrproc_t)xdr_guestfs_chunk, (char *)&chunk);
return -2;
}
if (chunk.data.data_len == 0) {
if (verbose)
fprintf (stderr,
- "guestfsd: receive_file: end of file, leaving function\n");
- xdr_free ((xdrproc_t) xdr_guestfs_chunk, (char *) &chunk);
- return 0; /* end of file */
+ "guestfsd: receive_file: end of file, leaving function\n");
+ xdr_free ((xdrproc_t)xdr_guestfs_chunk, (char *)&chunk);
+ return 0; /* end of file */
}
/* Note that the callback can generate progress messages. */
@@ -448,8 +452,8 @@ receive_file (receive_cb cb, void *opaque)
else
r = 0;
- xdr_free ((xdrproc_t) xdr_guestfs_chunk, (char *) &chunk);
- if (r == -1) { /* write error */
+ xdr_free ((xdrproc_t)xdr_guestfs_chunk, (char *)&chunk);
+ if (r == -1) { /* write error */
if (verbose)
fprintf (stderr, "guestfsd: receive_file: write error\n");
return -1;
@@ -489,7 +493,8 @@ send_file_write (const void *buf, size_t len)
int cancel;
if (len > GUESTFS_MAX_CHUNK_SIZE) {
- fprintf (stderr, "guestfsd: send_file_write: len (%zu) >
GUESTFS_MAX_CHUNK_SIZE (%d)\n",
+ fprintf (stderr, "guestfsd: send_file_write: len (%zu) > "
+ "GUESTFS_MAX_CHUNK_SIZE (%d)\n",
len, GUESTFS_MAX_CHUNK_SIZE);
return -1;
}
@@ -500,16 +505,18 @@ send_file_write (const void *buf, size_t len)
chunk.cancel = 1;
chunk.data.data_len = 0;
chunk.data.data_val = NULL;
- } else {
+ }
+ else {
chunk.cancel = 0;
chunk.data.data_len = len;
- chunk.data.data_val = (char *) buf;
+ chunk.data.data_val = (char *)buf;
}
if (send_chunk (&chunk) == -1)
return -1;
- if (cancel) return -2;
+ if (cancel)
+ return -2;
return 0;
}
@@ -527,7 +534,7 @@ check_for_library_cancellation (void)
FD_SET (sock, &rset);
tv.tv_sec = 0;
tv.tv_usec = 0;
- r = select (sock+1, &rset, NULL, NULL, &tv);
+ r = select (sock + 1, &rset, NULL, NULL, &tv);
if (r == -1) {
perror ("select");
return 0;
@@ -545,7 +552,8 @@ check_for_library_cancellation (void)
xdr_destroy (&xdr);
if (flag != GUESTFS_CANCEL_FLAG) {
- fprintf (stderr, "guestfsd: check_for_library_cancellation: read 0x%x from
library, expected 0x%x\n",
+ fprintf (stderr, "guestfsd: check_for_library_cancellation: read 0x%x "
+ "from library, expected 0x%x\n",
flag, GUESTFS_CANCEL_FLAG);
return 0;
}
@@ -580,7 +588,7 @@ send_chunk (const guestfs_chunk *chunk)
}
xdrmem_create (&xdr, buf, buf_len, XDR_ENCODE);
- if (!xdr_guestfs_chunk (&xdr, (guestfs_chunk *) chunk)) {
+ if (!xdr_guestfs_chunk (&xdr, (guestfs_chunk *)chunk)) {
fprintf (stderr, "guestfsd: send_chunk: failed to encode chunk\n");
xdr_destroy (&xdr);
return -1;
@@ -593,8 +601,9 @@ send_chunk (const guestfs_chunk *chunk)
xdr_u_int (&xdr, &len);
xdr_destroy (&xdr);
- int err = (xwrite (sock, lenbuf, 4) == 0
- && xwrite (sock, buf, len) == 0 ? 0 : -1);
+ int err =
+ (xwrite (sock, lenbuf, 4) == 0 && xwrite (sock, buf, len) == 0 ? 0
+ : -1);
if (err)
error (EXIT_FAILURE, 0, "send_chunk: write failed");
@@ -606,7 +615,7 @@ send_chunk (const guestfs_chunk *chunk)
* are in microseconds.
*/
#define NOTIFICATION_INITIAL_DELAY 2000000
-#define NOTIFICATION_PERIOD 333333
+#define NOTIFICATION_PERIOD 333333
void
notify_progress (uint64_t position, uint64_t total)
@@ -629,8 +638,8 @@ notify_progress (uint64_t position, uint64_t total)
* was sent out (or since the start of the call).
*/
last_us =
- (int64_t) last_progress_t.tv_sec * 1000000 + last_progress_t.tv_usec;
- now_us = (int64_t) now_t.tv_sec * 1000000 + now_t.tv_usec;
+ (int64_t)last_progress_t.tv_sec * 1000000 + last_progress_t.tv_usec;
+ now_us = (int64_t)now_t.tv_sec * 1000000 + now_t.tv_usec;
elapsed_us = now_us - last_us;
/* Rate limit. */
@@ -670,7 +679,8 @@ notify_progress_no_ratelimit (uint64_t position, uint64_t total,
xdrmem_create (&xdr, buf, sizeof buf, XDR_ENCODE);
if (!xdr_guestfs_progress (&xdr, &message)) {
- fprintf (stderr, "guestfsd: xdr_guestfs_progress: failed to encode
message\n");
+ fprintf (stderr,
+ "guestfsd: xdr_guestfs_progress: failed to encode message\n");
xdr_destroy (&xdr);
return;
}
@@ -714,7 +724,7 @@ pulse_mode_start (void)
void
pulse_mode_end (void)
{
- pulse_mode_cancel (); /* Cancel the itimer. */
+ pulse_mode_cancel (); /* Cancel the itimer. */
notify_progress (1, 1);
}
@@ -722,7 +732,7 @@ pulse_mode_end (void)
void
pulse_mode_cancel (void)
{
- int err = errno; /* Function must preserve errno. */
+ int err = errno; /* Function must preserve errno. */
struct itimerval it;
struct sigaction act;
@@ -752,22 +762,34 @@ static void
async_safe_send_pulse (int sig)
{
/* XDR is a RFC ... */
- unsigned char msg[] = {
- (GUESTFS_PROGRESS_FLAG & 0xff000000) >> 24,
- (GUESTFS_PROGRESS_FLAG & 0x00ff0000) >> 16,
- (GUESTFS_PROGRESS_FLAG & 0x0000ff00) >> 8,
- GUESTFS_PROGRESS_FLAG & 0x000000ff,
- (proc_nr & 0xff000000) >> 24,
- (proc_nr & 0x00ff0000) >> 16,
- (proc_nr & 0x0000ff00) >> 8,
- proc_nr & 0x000000ff,
- (serial & 0xff000000) >> 24,
- (serial & 0x00ff0000) >> 16,
- (serial & 0x0000ff00) >> 8,
- serial & 0x000000ff,
- /* 64 bit position = 0 */ 0, 0, 0, 0, 0, 0, 0, 0,
- /* 64 bit total = 1 */ 0, 0, 0, 0, 0, 0, 0, 1
- };
+ unsigned char msg[] = { (GUESTFS_PROGRESS_FLAG & 0xff000000) >> 24,
+ (GUESTFS_PROGRESS_FLAG & 0x00ff0000) >> 16,
+ (GUESTFS_PROGRESS_FLAG & 0x0000ff00) >> 8,
+ GUESTFS_PROGRESS_FLAG & 0x000000ff,
+ (proc_nr & 0xff000000) >> 24,
+ (proc_nr & 0x00ff0000) >> 16,
+ (proc_nr & 0x0000ff00) >> 8,
+ proc_nr & 0x000000ff,
+ (serial & 0xff000000) >> 24,
+ (serial & 0x00ff0000) >> 16,
+ (serial & 0x0000ff00) >> 8,
+ serial & 0x000000ff,
+ /* 64 bit position = 0 */ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ /* 64 bit total = 1 */ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 1 };
if (xwrite (sock, msg, sizeof msg) == -1)
exit (EXIT_FAILURE);
diff --git a/daemon/readdir.c b/daemon/readdir.c
index e488f93..545f603 100644
--- a/daemon/readdir.c
+++ b/daemon/readdir.c
@@ -71,13 +71,14 @@ do_readdir (const char *path)
guestfs_int_dirent *p;
p = realloc (ret->guestfs_int_dirent_list_val,
- sizeof (guestfs_int_dirent) * (i+1));
+ sizeof (guestfs_int_dirent) * (i + 1));
v.name = strdup (d->d_name);
if (!p || !v.name) {
reply_with_perror ("allocate");
if (p) {
free_int_dirent_list (p, i);
- } else {
+ }
+ else {
free_int_dirent_list (ret->guestfs_int_dirent_list_val, i);
}
free (v.name);
@@ -90,15 +91,33 @@ do_readdir (const char *path)
v.ino = d->d_ino;
#ifdef HAVE_STRUCT_DIRENT_D_TYPE
switch (d->d_type) {
- case DT_BLK: v.ftyp = 'b'; break;
- case DT_CHR: v.ftyp = 'c'; break;
- case DT_DIR: v.ftyp = 'd'; break;
- case DT_FIFO: v.ftyp = 'f'; break;
- case DT_LNK: v.ftyp = 'l'; break;
- case DT_REG: v.ftyp = 'r'; break;
- case DT_SOCK: v.ftyp = 's'; break;
- case DT_UNKNOWN: v.ftyp = 'u'; break;
- default: v.ftyp = '?'; break;
+ case DT_BLK:
+ v.ftyp = 'b';
+ break;
+ case DT_CHR:
+ v.ftyp = 'c';
+ break;
+ case DT_DIR:
+ v.ftyp = 'd';
+ break;
+ case DT_FIFO:
+ v.ftyp = 'f';
+ break;
+ case DT_LNK:
+ v.ftyp = 'l';
+ break;
+ case DT_REG:
+ v.ftyp = 'r';
+ break;
+ case DT_SOCK:
+ v.ftyp = 's';
+ break;
+ case DT_UNKNOWN:
+ v.ftyp = 'u';
+ break;
+ default:
+ v.ftyp = '?';
+ break;
}
#else
v.ftyp = 'u';
diff --git a/daemon/realpath.c b/daemon/realpath.c
index 8f28a12..6a43ac4 100644
--- a/daemon/realpath.c
+++ b/daemon/realpath.c
@@ -46,10 +46,11 @@ do_realpath (const char *path)
return NULL;
}
- return ret; /* caller frees */
+ return ret; /* caller frees */
}
-static int find_path_element (int fd_cwd, int is_end, const char *name, char
**name_ret);
+static int find_path_element (int fd_cwd, int is_end, const char *name,
+ char **name_ret);
char *
do_case_sensitive_path (const char *path)
@@ -68,7 +69,7 @@ do_case_sensitive_path (const char *path)
/* 'fd_cwd' here is a surrogate for the current working directory, so
* that we don't have to actually call chdir(2).
*/
- fd_cwd = open (sysroot, O_RDONLY|O_DIRECTORY|O_CLOEXEC);
+ fd_cwd = open (sysroot, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
if (fd_cwd == -1) {
reply_with_perror ("%s", sysroot);
goto error;
@@ -116,7 +117,7 @@ do_case_sensitive_path (const char *path)
if (next > 1)
ret[next++] = '/';
- t = realloc (ret, next+len+1);
+ t = realloc (ret, next + len + 1);
if (t == NULL) {
reply_with_perror ("realloc");
goto error;
@@ -127,7 +128,7 @@ do_case_sensitive_path (const char *path)
next += len;
/* Is it a directory? Try going into it. */
- fd2 = openat (fd_cwd, name_out, O_RDONLY|O_DIRECTORY|O_CLOEXEC);
+ fd2 = openat (fd_cwd, name_out, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
err = errno;
close (fd_cwd);
fd_cwd = fd2;
@@ -145,9 +146,9 @@ do_case_sensitive_path (const char *path)
if (fd_cwd >= 0)
close (fd_cwd);
- return ret; /* caller frees */
+ return ret; /* caller frees */
- error:
+error:
if (fd_cwd >= 0)
close (fd_cwd);
free (ret);
@@ -166,7 +167,8 @@ do_case_sensitive_path (const char *path)
* and return -1.
*/
static int
-find_path_element (int fd_cwd, int is_end, const char *name, char **name_ret)
+find_path_element (int fd_cwd, int is_end, const char *name,
+ char **name_ret)
{
int fd2;
DIR *dir;
@@ -213,7 +215,8 @@ find_path_element (int fd_cwd, int is_end, const char *name, char
**name_ret)
}
if (d == NULL) {
- reply_with_error ("%s: no file or directory found with this name", name);
+ reply_with_error ("%s: no file or directory found with this name",
+ name);
closedir (dir);
return -1;
}
diff --git a/daemon/rsync.c b/daemon/rsync.c
index d238d61..de1cbf7 100644
--- a/daemon/rsync.c
+++ b/daemon/rsync.c
@@ -30,7 +30,7 @@
#define MAX_ARGS 64
-GUESTFSD_EXT_CMD(str_rsync, rsync);
+GUESTFSD_EXT_CMD (str_rsync, rsync);
int
optgroup_rsync_available (void)
@@ -39,9 +39,8 @@ optgroup_rsync_available (void)
}
static int
-rsync (const char *src, const char *src_orig,
- const char *dest, const char *dest_orig,
- int archive, int deletedest)
+rsync (const char *src, const char *src_orig, const char *dest,
+ const char *dest_orig, int archive, int deletedest)
{
const char *argv[MAX_ARGS];
size_t i = 0;
@@ -71,8 +70,8 @@ rsync (const char *src, const char *src_orig,
/* Takes optional arguments, consult optargs_bitmask. */
int
-do_rsync (const char *src_orig, const char *dest_orig,
- int archive, int deletedest)
+do_rsync (const char *src_orig, const char *dest_orig, int archive,
+ int deletedest)
{
CLEANUP_FREE char *src = NULL, *dest = NULL;
@@ -93,8 +92,8 @@ do_rsync (const char *src_orig, const char *dest_orig,
/* Takes optional arguments, consult optargs_bitmask. */
int
-do_rsync_in (const char *remote, const char *dest_orig,
- int archive, int deletedest)
+do_rsync_in (const char *remote, const char *dest_orig, int archive,
+ int deletedest)
{
CLEANUP_FREE char *dest = NULL;
@@ -114,8 +113,8 @@ do_rsync_in (const char *remote, const char *dest_orig,
/* Takes optional arguments, consult optargs_bitmask. */
int
-do_rsync_out (const char *src_orig, const char *remote,
- int archive, int deletedest)
+do_rsync_out (const char *src_orig, const char *remote, int archive,
+ int deletedest)
{
CLEANUP_FREE char *src = NULL;
diff --git a/daemon/scrub.c b/daemon/scrub.c
index c10b0a0..bea585a 100644
--- a/daemon/scrub.c
+++ b/daemon/scrub.c
@@ -28,7 +28,7 @@
#include "actions.h"
#include "optgroups.h"
-GUESTFSD_EXT_CMD(str_scrub, scrub);
+GUESTFSD_EXT_CMD (str_scrub, scrub);
int
optgroup_scrub_available (void)
diff --git a/daemon/selinux.c b/daemon/selinux.c
index 1c1446d..a6b7346 100644
--- a/daemon/selinux.c
+++ b/daemon/selinux.c
@@ -47,7 +47,7 @@ int
do_setcon (const char *context)
{
#if defined(HAVE_SETCON)
- if (setcon ((char *) context) == -1) {
+ if (setcon ((char *)context) == -1) {
reply_with_perror ("setcon");
return -1;
}
@@ -78,7 +78,7 @@ do_getcon (void)
return NULL;
}
- return r; /* caller frees */
+ return r; /* caller frees */
#else
reply_with_error ("function not available");
return NULL;
diff --git a/daemon/sfdisk.c b/daemon/sfdisk.c
index e32e637..62ad2ad 100644
--- a/daemon/sfdisk.c
+++ b/daemon/sfdisk.c
@@ -28,13 +28,12 @@
#include "daemon.h"
#include "actions.h"
-GUESTFSD_EXT_CMD(str_sfdisk, sfdisk);
-GUESTFSD_EXT_CMD(str_blockdev, blockdev);
+GUESTFSD_EXT_CMD (str_sfdisk, sfdisk);
+GUESTFSD_EXT_CMD (str_blockdev, blockdev);
static int
sfdisk (const char *device, int n, int cyls, int heads, int sectors,
- const char *extra_flag,
- char *const *lines)
+ const char *extra_flag, char *const *lines)
{
FILE *fp;
char buf[256];
@@ -57,14 +56,16 @@ sfdisk (const char *device, int n, int cyls, int heads, int sectors,
if (extra_flag) {
if (strlen (buf) + 1 + strlen (extra_flag) >= sizeof buf) {
- reply_with_error ("internal buffer overflow: sfdisk extra_flag too
long");
+ reply_with_error (
+ "internal buffer overflow: sfdisk extra_flag too long");
return -1;
}
sprintf (buf + strlen (buf), " %s", extra_flag);
}
if (strlen (buf) + 1 + strlen (device) >= sizeof buf) {
- reply_with_error ("internal buffer overflow: sfdisk device name too
long");
+ reply_with_error (
+ "internal buffer overflow: sfdisk device name too long");
return -1;
}
sprintf (buf + strlen (buf), " %s", device);
@@ -103,7 +104,7 @@ sfdisk (const char *device, int n, int cyls, int heads, int sectors,
* other component. In any case, reread the partition table
* unconditionally here.
*/
- (void) command (NULL, NULL, str_blockdev, "--rereadpt", device, NULL);
+ (void)command (NULL, NULL, str_blockdev, "--rereadpt", device, NULL);
udev_settle ();
@@ -123,7 +124,7 @@ do_sfdisk_N (const char *device, int n, int cyls, int heads, int
sectors,
{
char const *const lines[2] = { line, NULL };
- return sfdisk (device, n, cyls, heads, sectors, NULL, (void *) lines);
+ return sfdisk (device, n, cyls, heads, sectors, NULL, (void *)lines);
}
int
@@ -148,7 +149,7 @@ sfdisk_flag (const char *device, const char *flag)
udev_settle ();
- return out; /* caller frees */
+ return out; /* caller frees */
}
char *
diff --git a/daemon/sh.c b/daemon/sh.c
index 94f348b..bd103d8 100644
--- a/daemon/sh.c
+++ b/daemon/sh.c
@@ -32,13 +32,14 @@
#include "ignore-value.h"
-GUESTFSD_EXT_CMD(str_cp, cp);
-GUESTFSD_EXT_CMD(str_mount, mount);
-GUESTFSD_EXT_CMD(str_umount, umount);
+GUESTFSD_EXT_CMD (str_cp, cp);
+GUESTFSD_EXT_CMD (str_mount, mount);
+GUESTFSD_EXT_CMD (str_umount, umount);
#ifdef HAVE_ATTRIBUTE_CLEANUP
-#define CLEANUP_BIND_STATE __attribute__((cleanup(free_bind_state)))
-#define CLEANUP_RESOLVER_STATE __attribute__((cleanup(free_resolver_state)))
+#define CLEANUP_BIND_STATE __attribute__((cleanup (free_bind_state)))
+#define CLEANUP_RESOLVER_STATE \
+ __attribute__ ((cleanup (free_resolver_state)))
#else
#define CLEANUP_BIND_STATE
#define CLEANUP_RESOLVER_STATE
@@ -100,20 +101,26 @@ bind_mount (struct bind_state *bs)
* However I have not found a reliable way to unmount the same set
* of directories (umount -R does NOT work).
*/
- r = command (NULL, NULL, str_mount, "--bind", "/dev",
bs->sysroot_dev, NULL);
+ r = command (NULL, NULL, str_mount, "--bind", "/dev",
bs->sysroot_dev,
+ NULL);
bs->dev_ok = r != -1;
- r = command (NULL, NULL, str_mount, "--bind", "/dev/pts",
bs->sysroot_dev_pts, NULL);
+ r = command (NULL, NULL, str_mount, "--bind", "/dev/pts",
+ bs->sysroot_dev_pts, NULL);
bs->dev_pts_ok = r != -1;
- r = command (NULL, NULL, str_mount, "--bind", "/proc",
bs->sysroot_proc, NULL);
+ r = command (NULL, NULL, str_mount, "--bind", "/proc",
bs->sysroot_proc,
+ NULL);
bs->proc_ok = r != -1;
/* Note on the next line we have to bind-mount /sys/fs/selinux (appliance
* kernel) on top of /selinux (where guest is expecting selinux).
*/
- r = command (NULL, NULL, str_mount, "--bind", "/sys/fs/selinux",
bs->sysroot_selinux, NULL);
+ r = command (NULL, NULL, str_mount, "--bind", "/sys/fs/selinux",
+ bs->sysroot_selinux, NULL);
bs->selinux_ok = r != -1;
- r = command (NULL, NULL, str_mount, "--bind", "/sys",
bs->sysroot_sys, NULL);
+ r = command (NULL, NULL, str_mount, "--bind", "/sys",
bs->sysroot_sys,
+ NULL);
bs->sys_ok = r != -1;
- r = command (NULL, NULL, str_mount, "--bind", "/sys/fs/selinux",
bs->sysroot_sys_fs_selinux, NULL);
+ r = command (NULL, NULL, str_mount, "--bind", "/sys/fs/selinux",
+ bs->sysroot_sys_fs_selinux, NULL);
bs->sys_fs_selinux_ok = r != -1;
bs->mounted = true;
@@ -131,17 +138,23 @@ static void
free_bind_state (struct bind_state *bs)
{
if (bs->mounted) {
- if (bs->sys_fs_selinux_ok) umount_ignore_fail (bs->sysroot_sys_fs_selinux);
+ if (bs->sys_fs_selinux_ok)
+ umount_ignore_fail (bs->sysroot_sys_fs_selinux);
free (bs->sysroot_sys_fs_selinux);
- if (bs->sys_ok) umount_ignore_fail (bs->sysroot_sys);
+ if (bs->sys_ok)
+ umount_ignore_fail (bs->sysroot_sys);
free (bs->sysroot_sys);
- if (bs->selinux_ok) umount_ignore_fail (bs->sysroot_selinux);
+ if (bs->selinux_ok)
+ umount_ignore_fail (bs->sysroot_selinux);
free (bs->sysroot_selinux);
- if (bs->proc_ok) umount_ignore_fail (bs->sysroot_proc);
+ if (bs->proc_ok)
+ umount_ignore_fail (bs->sysroot_proc);
free (bs->sysroot_proc);
- if (bs->dev_pts_ok) umount_ignore_fail (bs->sysroot_dev_pts);
+ if (bs->dev_pts_ok)
+ umount_ignore_fail (bs->sysroot_dev_pts);
free (bs->sysroot_dev_pts);
- if (bs->dev_ok) umount_ignore_fail (bs->sysroot_dev);
+ if (bs->dev_ok)
+ umount_ignore_fail (bs->sysroot_dev);
free (bs->sysroot_dev);
bs->mounted = false;
}
@@ -211,7 +224,7 @@ set_up_etc_resolv_conf (struct resolver_state *rs)
rs->mounted = true;
return 0;
- error:
+error:
free (rs->sysroot_etc_resolv_conf);
free (rs->sysroot_etc_resolv_conf_old);
return -1;
@@ -225,7 +238,8 @@ free_resolver_state (struct resolver_state *rs)
if (rs->sysroot_etc_resolv_conf_old) {
if (verbose)
- fprintf (stderr, "renaming %s to %s\n",
rs->sysroot_etc_resolv_conf_old,
+ fprintf (stderr, "renaming %s to %s\n",
+ rs->sysroot_etc_resolv_conf_old,
rs->sysroot_etc_resolv_conf);
if (rename (rs->sysroot_etc_resolv_conf_old,
@@ -246,9 +260,9 @@ do_command (char *const *argv)
char *out;
CLEANUP_FREE char *err = NULL;
int r, flags;
- CLEANUP_BIND_STATE struct bind_state bind_state = { .mounted = false };
- CLEANUP_RESOLVER_STATE struct resolver_state resolver_state =
- { .mounted = false };
+ CLEANUP_BIND_STATE struct bind_state bind_state = {.mounted = false };
+ CLEANUP_RESOLVER_STATE struct resolver_state resolver_state = {.mounted =
+ false };
/* We need a root filesystem mounted to do this. */
NEED_ROOT (, return NULL);
@@ -271,7 +285,7 @@ do_command (char *const *argv)
flags = COMMAND_FLAG_DO_CHROOT;
- r = commandvf (&out, &err, flags, (const char * const *) argv);
+ r = commandvf (&out, &err, flags, (const char *const *)argv);
free_bind_state (&bind_state);
free_resolver_state (&resolver_state);
@@ -282,7 +296,7 @@ do_command (char *const *argv)
return NULL;
}
- return out; /* Caller frees. */
+ return out; /* Caller frees. */
}
char **
@@ -300,7 +314,7 @@ do_command_lines (char *const *argv)
if (lines == NULL)
return NULL;
- return lines; /* Caller frees. */
+ return lines; /* Caller frees. */
}
char *
@@ -308,7 +322,7 @@ do_sh (const char *cmd)
{
const char *argv[] = { "/bin/sh", "-c", cmd, NULL };
- return do_command ((char **) argv);
+ return do_command ((char **)argv);
}
char **
@@ -316,5 +330,5 @@ do_sh_lines (const char *cmd)
{
const char *argv[] = { "/bin/sh", "-c", cmd, NULL };
- return do_command_lines ((char **) argv);
+ return do_command_lines ((char **)argv);
}
diff --git a/daemon/sleep.c b/daemon/sleep.c
index af01d25..d5f201f 100644
--- a/daemon/sleep.c
+++ b/daemon/sleep.c
@@ -30,6 +30,6 @@ int
do_sleep (int secs)
{
/* According to the man page, this syscall never fails. */
- (void) sleep (secs);
+ (void)sleep (secs);
return 0;
}
diff --git a/daemon/sleuthkit.c b/daemon/sleuthkit.c
index 2f8c97b..c9be89d 100644
--- a/daemon/sleuthkit.c
+++ b/daemon/sleuthkit.c
@@ -31,7 +31,7 @@
static int file_out (const char *cmd);
-GUESTFSD_EXT_CMD(str_sleuthkit_probe, icat);
+GUESTFSD_EXT_CMD (str_sleuthkit_probe, icat);
int
optgroup_sleuthkit_available (void)
@@ -51,7 +51,8 @@ do_download_inode (const mountable_t *mountable, int64_t inode)
}
/* Construct the command. */
- if (asprintf (&cmd, "icat -r %s %" PRIi64, mountable->device, inode)
== -1) {
+ if (asprintf (&cmd, "icat -r %s %" PRIi64, mountable->device, inode)
==
+ -1) {
reply_with_perror ("asprintf");
return -1;
}
@@ -96,18 +97,18 @@ file_out (const char *cmd)
if (ferror (fp)) {
fprintf (stderr, "fread: %m");
- send_file_end (1); /* Cancel. */
+ send_file_end (1); /* Cancel. */
pclose (fp);
return -1;
}
if (pclose (fp) != 0) {
fprintf (stderr, "pclose: %m");
- send_file_end (1); /* Cancel. */
+ send_file_end (1); /* Cancel. */
return -1;
}
- if (send_file_end (0)) /* Normal end of file. */
+ if (send_file_end (0)) /* Normal end of file. */
return -1;
return 0;
diff --git a/daemon/stat.c b/daemon/stat.c
index 73f1922..8cbf54d 100644
--- a/daemon/stat.c
+++ b/daemon/stat.c
@@ -78,8 +78,8 @@ stat_to_statns (guestfs_int_statns *ret, const struct stat *statbuf)
ret->st_ctime_nsec = 0;
#endif
- ret->st_spare1 = ret->st_spare2 = ret->st_spare3 =
- ret->st_spare4 = ret->st_spare5 = ret->st_spare6 = 0;
+ ret->st_spare1 = ret->st_spare2 = ret->st_spare3 = ret->st_spare4 =
+ ret->st_spare5 = ret->st_spare6 = 0;
return ret;
}
@@ -144,7 +144,7 @@ do_internal_lstatnslist (const char *path, char *const *names)
}
CHROOT_IN;
- path_fd = open (path, O_RDONLY|O_DIRECTORY|O_CLOEXEC);
+ path_fd = open (path, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
CHROOT_OUT;
if (path_fd == -1) {
diff --git a/daemon/statvfs.c b/daemon/statvfs.c
index 987537d..af563e4 100644
--- a/daemon/statvfs.c
+++ b/daemon/statvfs.c
@@ -78,7 +78,7 @@ do_statvfs (const char *path)
return ret;
#else /* !HAVE_STATVFS */
-# if WIN32
+#if WIN32
CLEANUP_FREE char *disk = NULL;
guestfs_int_statvfs *ret;
@@ -92,10 +92,9 @@ do_statvfs (const char *path)
return NULL;
}
- if (!GetDiskFreeSpaceEx (disk,
- (PULARGE_INTEGER) &free_bytes_available,
- (PULARGE_INTEGER) &total_number_of_bytes,
- (PULARGE_INTEGER) &total_number_of_free_bytes)) {
+ if (!GetDiskFreeSpaceEx (disk, (PULARGE_INTEGER)&free_bytes_available,
+ (PULARGE_INTEGER)&total_number_of_bytes,
+ (PULARGE_INTEGER)&total_number_of_free_bytes)) {
reply_with_perror ("GetDiskFreeSpaceEx");
return NULL;
}
@@ -115,11 +114,14 @@ do_statvfs (const char *path)
*/
if (total_number_of_bytes < UINT64_C (16) * 1024 * 1024 * 1024 * 1024)
ret->bsize = 4096;
- else if (total_number_of_bytes < UINT64_C (32) * 1024 * 1024 * 1024 * 1024)
+ else if (total_number_of_bytes <
+ UINT64_C (32) * 1024 * 1024 * 1024 * 1024)
ret->bsize = 8192;
- else if (total_number_of_bytes < UINT64_C (64) * 1024 * 1024 * 1024 * 1024)
+ else if (total_number_of_bytes <
+ UINT64_C (64) * 1024 * 1024 * 1024 * 1024)
ret->bsize = 16384;
- else if (total_number_of_bytes < UINT64_C (128) * 1024 * 1024 * 1024 * 1024)
+ else if (total_number_of_bytes <
+ UINT64_C (128) * 1024 * 1024 * 1024 * 1024)
ret->bsize = 32768;
else
ret->bsize = 65536;
@@ -138,7 +140,7 @@ do_statvfs (const char *path)
return ret;
-# else /* !WIN32 */
+#else /* !WIN32 */
CLEANUP_FREE char *disk = NULL;
int r;
@@ -179,6 +181,6 @@ do_statvfs (const char *path)
return ret;
-# endif /* !WIN32 */
+#endif /* !WIN32 */
#endif /* !HAVE_STATVFS */
}
diff --git a/daemon/strings.c b/daemon/strings.c
index 6e81b9e..84c83cb 100644
--- a/daemon/strings.c
+++ b/daemon/strings.c
@@ -34,14 +34,13 @@ do_strings_e (const char *encoding, const char *path)
CLEANUP_FREE char *out = NULL, *err = NULL;
char **lines;
- if (strlen (encoding) != 1 ||
- strchr ("sSblBL", encoding[0]) == NULL) {
+ if (strlen (encoding) != 1 || strchr ("sSblBL", encoding[0]) == NULL) {
reply_with_error ("%s: invalid encoding", encoding);
return NULL;
}
CHROOT_IN;
- fd = open (path, O_RDONLY|O_CLOEXEC);
+ fd = open (path, O_RDONLY | O_CLOEXEC);
CHROOT_OUT;
if (fd == -1) {
@@ -61,7 +60,7 @@ do_strings_e (const char *encoding, const char *path)
if (lines == NULL)
return NULL;
- return lines; /* Caller frees. */
+ return lines; /* Caller frees. */
}
char **
diff --git a/daemon/swap.c b/daemon/swap.c
index 9d7839e..2606159 100644
--- a/daemon/swap.c
+++ b/daemon/swap.c
@@ -30,12 +30,13 @@
#include "ignore-value.h"
-GUESTFSD_EXT_CMD(str_mkswap, mkswap);
-GUESTFSD_EXT_CMD(str_swapon, swapon);
-GUESTFSD_EXT_CMD(str_swapoff, swapoff);
-GUESTFSD_EXT_CMD(str_swaplabel, swaplabel);
+GUESTFSD_EXT_CMD (str_mkswap, mkswap);
+GUESTFSD_EXT_CMD (str_swapon, swapon);
+GUESTFSD_EXT_CMD (str_swapoff, swapoff);
+GUESTFSD_EXT_CMD (str_swaplabel, swaplabel);
-/* Confirmed this is true for Linux swap partitions from the Linux sources. */
+/* Confirmed this is true for Linux swap partitions from the Linux sources.
+ */
#define SWAP_LABEL_MAX 16
int
diff --git a/daemon/sync.c b/daemon/sync.c
index 632995c..74ec575 100644
--- a/daemon/sync.c
+++ b/daemon/sync.c
@@ -61,13 +61,13 @@ sync_disks (void)
#if defined(HAVE_SYNC)
sync ();
- /* On Linux, sync(2) doesn't perform a barrier, so qemu (which may
- * have a writeback cache, even with cache=none) will still have
- * some unwritten data. Force the data out of any qemu caches, by
- * calling fsync on all block devices. Note we still need the
- * call to sync above in order to schedule the writes.
- * Thanks to: Avi Kivity, Kevin Wolf.
- */
+/* On Linux, sync(2) doesn't perform a barrier, so qemu (which may
+ * have a writeback cache, even with cache=none) will still have
+ * some unwritten data. Force the data out of any qemu caches, by
+ * calling fsync on all block devices. Note we still need the
+ * call to sync above in order to schedule the writes.
+ * Thanks to: Avi Kivity, Kevin Wolf.
+ */
#ifdef HAVE_FSYNC
fsync_devices ();
#endif
@@ -98,12 +98,11 @@ fsync_devices (void)
for (;;) {
errno = 0;
d = readdir (dir);
- if (!d) break;
+ if (!d)
+ break;
- if (STREQLEN (d->d_name, "sd", 2) ||
- STREQLEN (d->d_name, "hd", 2) ||
- STREQLEN (d->d_name, "ubd", 3) ||
- STREQLEN (d->d_name, "vd", 2) ||
+ if (STREQLEN (d->d_name, "sd", 2) || STREQLEN (d->d_name,
"hd", 2) ||
+ STREQLEN (d->d_name, "ubd", 3) || STREQLEN (d->d_name,
"vd", 2) ||
STREQLEN (d->d_name, "sr", 2)) {
snprintf (dev_path, sizeof dev_path, "/dev/%s", d->d_name);
@@ -111,7 +110,7 @@ fsync_devices (void)
if (is_root_device (dev_path))
continue;
- fd = open (dev_path, O_RDONLY|O_CLOEXEC);
+ fd = open (dev_path, O_RDONLY | O_CLOEXEC);
if (fd == -1) {
perror (dev_path);
continue;
@@ -149,7 +148,7 @@ sync_win32 (void)
if (n1 == 0)
return -1;
- TCHAR buffer[n1+2]; /* sic */
+ TCHAR buffer[n1 + 2]; /* sic */
n2 = GetLogicalDriveStrings (n1, buffer);
if (n2 == 0)
return -1;
@@ -175,9 +174,9 @@ sync_win32 (void)
if (!GetVolumeNameForVolumeMountPoint (p, volname, 50))
return -1;
- drive = CreateFile (volname, GENERIC_READ|GENERIC_WRITE,
- FILE_SHARE_READ|FILE_SHARE_WRITE,
- NULL, OPEN_EXISTING, 0, 0);
+ drive = CreateFile (volname, GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
+ OPEN_EXISTING, 0, 0);
if (drive == INVALID_HANDLE_VALUE)
return -1;
@@ -192,7 +191,8 @@ sync_win32 (void)
}
/* Skip to next \0 character. */
- while (*p++);
+ while (*p++)
+ ;
}
return 0;
diff --git a/daemon/syslinux.c b/daemon/syslinux.c
index 08da170..58130c0 100644
--- a/daemon/syslinux.c
+++ b/daemon/syslinux.c
@@ -28,8 +28,8 @@
#include "actions.h"
#include "optgroups.h"
-GUESTFSD_EXT_CMD(str_syslinux, syslinux);
-GUESTFSD_EXT_CMD(str_extlinux, extlinux);
+GUESTFSD_EXT_CMD (str_syslinux, syslinux);
+GUESTFSD_EXT_CMD (str_extlinux, extlinux);
int
optgroup_syslinux_available (void)
diff --git a/daemon/tar.c b/daemon/tar.c
index 6d0403a..dd797f6 100644
--- a/daemon/tar.c
+++ b/daemon/tar.c
@@ -35,7 +35,7 @@
#include "actions.h"
#include "optgroups.h"
-GUESTFSD_EXT_CMD(str_tar, tar);
+GUESTFSD_EXT_CMD (str_tar, tar);
int
optgroup_xz_available (void)
@@ -67,7 +67,7 @@ is_chown_supported (const char *dir)
}
/* Maybe 'dir' is not a directory or filesystem not writable? */
- fd = open (buf, O_WRONLY|O_CREAT|O_NOCTTY|O_CLOEXEC, 0666);
+ fd = open (buf, O_WRONLY | O_CREAT | O_NOCTTY | O_CLOEXEC, 0666);
if (fd == -1) {
err = errno;
r = cancel_receive ();
@@ -118,10 +118,10 @@ read_error_file (char *error_file)
}
/* Remove trailing \n character if any. */
- if (len > 0 && str[len-1] == '\n')
+ if (len > 0 && str[len - 1] == '\n')
str[--len] = '\0';
- return str; /* caller frees */
+ return str; /* caller frees */
}
static int
@@ -134,7 +134,8 @@ write_cb (void *fd_ptr, const void *buf, size_t len)
/* Has one FileIn parameter. */
/* Takes optional arguments, consult optargs_bitmask. */
int
-do_tar_in (const char *dir, const char *compress, int xattrs, int selinux, int acls)
+do_tar_in (const char *dir, const char *compress, int xattrs, int selinux,
+ int acls)
{
const char *filter;
int err, r;
@@ -162,7 +163,8 @@ do_tar_in (const char *dir, const char *compress, int xattrs, int
selinux, int a
reply_with_error ("unknown compression type: %s", compress);
return -1;
}
- } else
+ }
+ else
filter = "";
if (!(optargs_bitmask & GUESTFS_TAR_IN_XATTRS_BITMASK))
@@ -186,13 +188,10 @@ do_tar_in (const char *dir, const char *compress, int xattrs, int
selinux, int a
close (fd);
/* "tar -C /sysroot%s -xf -" but we have to quote the dir. */
- if (asprintf_nowarn (&cmd, "%s -C %R%s -xf - %s%s%s%s2> %s",
- str_tar,
- dir, filter,
- chown_supported ? "" : "--no-same-owner ",
+ if (asprintf_nowarn (&cmd, "%s -C %R%s -xf - %s%s%s%s2> %s", str_tar,
dir,
+ filter, chown_supported ? "" : "--no-same-owner
",
xattrs ? "--xattrs " : "",
- selinux ? "--selinux " : "",
- acls ? "--acls " : "",
+ selinux ? "--selinux " : "", acls ?
"--acls " : "",
error_file) == -1) {
err = errno;
r = cancel_receive ();
@@ -221,7 +220,7 @@ do_tar_in (const char *dir, const char *compress, int xattrs, int
selinux, int a
fd = fileno (fp);
r = receive_file (write_cb, &fd);
- if (r == -1) { /* write error */
+ if (r == -1) { /* write error */
cancel_receive ();
CLEANUP_FREE char *errstr = read_error_file (error_file);
reply_with_error ("write error on directory: %s: %s", dir, errstr);
@@ -229,7 +228,7 @@ do_tar_in (const char *dir, const char *compress, int xattrs, int
selinux, int a
pclose (fp);
return -1;
}
- if (r == -2) { /* cancellation from library */
+ if (r == -2) { /* cancellation from library */
/* This error is ignored by the library since it initiated the
* cancel. Nevertheless we must send an error reply here.
*/
@@ -241,8 +240,8 @@ do_tar_in (const char *dir, const char *compress, int xattrs, int
selinux, int a
if (pclose (fp) != 0) {
CLEANUP_FREE char *errstr = read_error_file (error_file);
- reply_with_error ("tar subcommand failed on directory: %s: %s",
- dir, errstr);
+ reply_with_error ("tar subcommand failed on directory: %s: %s", dir,
+ errstr);
unlink (error_file);
return -1;
}
@@ -288,7 +287,8 @@ make_exclude_from_file (char *const *excludes)
for (i = 0; excludes[i] != NULL; ++i) {
if (strchr (excludes[i], '\n')) {
- reply_with_error ("tar-out: excludes file patterns cannot contain \\n
character");
+ reply_with_error (
+ "tar-out: excludes file patterns cannot contain \\n character");
goto error;
}
@@ -299,7 +299,8 @@ make_exclude_from_file (char *const *excludes)
}
if (verbose)
- fprintf (stderr, "tar-out: adding excludes pattern '%s'\n",
excludes[i]);
+ fprintf (stderr, "tar-out: adding excludes pattern '%s'\n",
+ excludes[i]);
}
if (close (fd) == -1) {
@@ -317,7 +318,7 @@ make_exclude_from_file (char *const *excludes)
return ret;
- error:
+error:
if (fd >= 0)
close (fd);
unlink (template);
@@ -360,7 +361,8 @@ do_tar_out (const char *dir, const char *compress, int numericowner,
reply_with_error ("unknown compression type: %s", compress);
return -1;
}
- } else
+ }
+ else
filter = "";
if (!(optargs_bitmask & GUESTFS_TAR_OUT_NUMERICOWNER_BITMASK))
@@ -393,16 +395,14 @@ do_tar_out (const char *dir, const char *compress, int
numericowner,
return -1;
}
- if (! S_ISDIR (statbuf.st_mode)) {
+ if (!S_ISDIR (statbuf.st_mode)) {
reply_with_error ("%s: not a directory", dir);
return -1;
}
/* "tar -C /sysroot%s -cf - ." but we have to quote the dir. */
- if (asprintf_nowarn (&cmd, "%s -C %Q%s%s%s%s%s%s%s -cf - .",
- str_tar,
- buf, filter,
- numericowner ? " --numeric-owner" : "",
+ if (asprintf_nowarn (&cmd, "%s -C %Q%s%s%s%s%s%s%s -cf - .", str_tar,
buf,
+ filter, numericowner ? " --numeric-owner" :
"",
exclude_from_file ? " -X " : "",
exclude_from_file ? exclude_from_file : "",
xattrs ? " --xattrs" : "",
@@ -436,18 +436,18 @@ do_tar_out (const char *dir, const char *compress, int
numericowner,
if (ferror (fp)) {
fprintf (stderr, "fread: %s: %m\n", dir);
- send_file_end (1); /* Cancel. */
+ send_file_end (1); /* Cancel. */
pclose (fp);
return -1;
}
if (pclose (fp) != 0) {
fprintf (stderr, "pclose: %s: %m\n", dir);
- send_file_end (1); /* Cancel. */
+ send_file_end (1); /* Cancel. */
return -1;
}
- if (send_file_end (0)) /* Normal end of file. */
+ if (send_file_end (0)) /* Normal end of file. */
return -1;
return 0;
diff --git a/daemon/truncate.c b/daemon/truncate.c
index 0c3731c..f72adc7 100644
--- a/daemon/truncate.c
+++ b/daemon/truncate.c
@@ -35,7 +35,7 @@ do_truncate_size (const char *path, int64_t size)
int r;
CHROOT_IN;
- fd = open (path, O_WRONLY|O_NOCTTY|O_CLOEXEC);
+ fd = open (path, O_WRONLY | O_NOCTTY | O_CLOEXEC);
CHROOT_OUT;
if (fd == -1) {
@@ -43,7 +43,7 @@ do_truncate_size (const char *path, int64_t size)
return -1;
}
- r = ftruncate (fd, (off_t) size);
+ r = ftruncate (fd, (off_t)size);
if (r == -1) {
reply_with_perror ("ftruncate: %s", path);
close (fd);
diff --git a/daemon/umask.c b/daemon/umask.c
index 475c820..3255b04 100644
--- a/daemon/umask.c
+++ b/daemon/umask.c
@@ -36,7 +36,7 @@ do_umask (int mask)
int r;
if (mask < 0 || mask > 0777) {
- reply_with_error ("0%o: mask negative or out of range", (unsigned) mask);
+ reply_with_error ("0%o: mask negative or out of range", (unsigned)mask);
return -1;
}
diff --git a/daemon/upload.c b/daemon/upload.c
index aeb7306..fa78bc0 100644
--- a/daemon/upload.c
+++ b/daemon/upload.c
@@ -32,8 +32,8 @@
#include "actions.h"
struct write_cb_data {
- int fd; /* file descriptor */
- uint64_t written; /* bytes written so far */
+ int fd; /* file descriptor */
+ uint64_t written; /* bytes written so far */
};
static int
@@ -58,14 +58,16 @@ write_cb (void *data_vp, const void *buf, size_t len)
static int
upload (const char *filename, int flags, int64_t offset)
{
- struct write_cb_data data = { .written = 0 };
+ struct write_cb_data data = {.written = 0 };
int err, r, is_dev;
is_dev = STRPREFIX (filename, "/dev/");
- if (!is_dev) CHROOT_IN;
+ if (!is_dev)
+ CHROOT_IN;
data.fd = open (filename, flags, 0666);
- if (!is_dev) CHROOT_OUT;
+ if (!is_dev)
+ CHROOT_OUT;
if (data.fd == -1) {
err = errno;
r = cancel_receive ();
@@ -85,7 +87,7 @@ upload (const char *filename, int flags, int64_t offset)
}
r = receive_file (write_cb, &data.fd);
- if (r == -1) { /* write error */
+ if (r == -1) { /* write error */
err = errno;
r = cancel_receive ();
errno = err;
@@ -93,7 +95,7 @@ upload (const char *filename, int flags, int64_t offset)
close (data.fd);
return -1;
}
- if (r == -2) { /* cancellation from library */
+ if (r == -2) { /* cancellation from library */
/* This error is ignored by the library since it initiated the
* cancel. Nevertheless we must send an error reply here.
*/
@@ -114,7 +116,8 @@ upload (const char *filename, int flags, int64_t offset)
int
do_upload (const char *filename)
{
- return upload (filename, O_WRONLY|O_CREAT|O_TRUNC|O_NOCTTY|O_CLOEXEC, 0);
+ return upload (filename,
+ O_WRONLY | O_CREAT | O_TRUNC | O_NOCTTY | O_CLOEXEC, 0);
}
/* Has one FileIn parameter. */
@@ -126,7 +129,8 @@ do_upload_offset (const char *filename, int64_t offset)
return -1;
}
- return upload (filename, O_WRONLY|O_CREAT|O_NOCTTY|O_CLOEXEC, offset);
+ return upload (filename, O_WRONLY | O_CREAT | O_NOCTTY | O_CLOEXEC,
+ offset);
}
/* Extra check to prevent RHBZ#908321. */
@@ -162,9 +166,11 @@ do_download (const char *filename)
is_dev = STRPREFIX (filename, "/dev/");
- if (!is_dev) CHROOT_IN;
- fd = open (filename, O_RDONLY|O_CLOEXEC);
- if (!is_dev) CHROOT_OUT;
+ if (!is_dev)
+ CHROOT_IN;
+ fd = open (filename, O_RDONLY | O_CLOEXEC);
+ if (!is_dev)
+ CHROOT_OUT;
if (fd == -1) {
reply_with_perror ("%s", filename);
return -1;
@@ -185,14 +191,15 @@ do_download (const char *filename)
return -1;
}
total = statbuf.st_size;
- } else {
+ }
+ else {
int64_t size = do_blockdev_getsize64 (filename);
if (size == -1) {
/* do_blockdev_getsize64 has already sent a reply. */
close (fd);
return -1;
}
- total = (uint64_t) size;
+ total = (uint64_t)size;
}
/* Now we must send the reply message, before the file contents. After
@@ -213,18 +220,18 @@ do_download (const char *filename)
if (r == -1) {
fprintf (stderr, "read: %s: %m\n", filename);
- send_file_end (1); /* Cancel. */
+ send_file_end (1); /* Cancel. */
close (fd);
return -1;
}
if (close (fd) == -1) {
fprintf (stderr, "close: %s: %m\n", filename);
- send_file_end (1); /* Cancel. */
+ send_file_end (1); /* Cancel. */
return -1;
}
- if (send_file_end (0)) /* Normal end of file. */
+ if (send_file_end (0)) /* Normal end of file. */
return -1;
return 0;
@@ -252,13 +259,15 @@ do_download_offset (const char *filename, int64_t offset, int64_t
size)
reply_with_perror ("%s: size is negative", filename);
return -1;
}
- uint64_t usize = (uint64_t) size;
+ uint64_t usize = (uint64_t)size;
is_dev = STRPREFIX (filename, "/dev/");
- if (!is_dev) CHROOT_IN;
- fd = open (filename, O_RDONLY|O_CLOEXEC);
- if (!is_dev) CHROOT_OUT;
+ if (!is_dev)
+ CHROOT_IN;
+ fd = open (filename, O_RDONLY | O_CLOEXEC);
+ if (!is_dev)
+ CHROOT_OUT;
if (fd == -1) {
reply_with_perror ("%s", filename);
return -1;
@@ -286,11 +295,12 @@ do_download_offset (const char *filename, int64_t offset, int64_t
size)
reply (NULL, NULL);
while (usize > 0) {
- r = read (fd, buf,
- usize > GUESTFS_MAX_CHUNK_SIZE ? GUESTFS_MAX_CHUNK_SIZE : usize);
+ r =
+ read (fd, buf, usize > GUESTFS_MAX_CHUNK_SIZE ? GUESTFS_MAX_CHUNK_SIZE
+ : usize);
if (r == -1) {
fprintf (stderr, "read: %s: %m\n", filename);
- send_file_end (1); /* Cancel. */
+ send_file_end (1); /* Cancel. */
close (fd);
return -1;
}
@@ -313,11 +323,11 @@ do_download_offset (const char *filename, int64_t offset, int64_t
size)
if (close (fd) == -1) {
fprintf (stderr, "close: %s: %m\n", filename);
- send_file_end (1); /* Cancel. */
+ send_file_end (1); /* Cancel. */
return -1;
}
- if (send_file_end (0)) /* Normal end of file. */
+ if (send_file_end (0)) /* Normal end of file. */
return -1;
return 0;
diff --git a/daemon/utimens.c b/daemon/utimens.c
index 2df6fc7..6f84fa3 100644
--- a/daemon/utimens.c
+++ b/daemon/utimens.c
@@ -29,8 +29,7 @@
#include "actions.h"
int
-do_utimens (const char *path,
- int64_t atsecs, int64_t atnsecs,
+do_utimens (const char *path, int64_t atsecs, int64_t atnsecs,
int64_t mtsecs, int64_t mtnsecs)
{
int r;
diff --git a/daemon/utsname.c b/daemon/utsname.c
index 17a82c3..9373fc8 100644
--- a/daemon/utsname.c
+++ b/daemon/utsname.c
@@ -48,8 +48,8 @@ do_utsname (void)
ret->uts_release = strdup (uts.release);
ret->uts_version = strdup (uts.version);
ret->uts_machine = strdup (uts.machine);
- if (!ret->uts_sysname || !ret->uts_release ||
- !ret->uts_version || !ret->uts_machine) {
+ if (!ret->uts_sysname || !ret->uts_release || !ret->uts_version ||
+ !ret->uts_machine) {
reply_with_perror ("strdup");
free (ret->uts_sysname);
free (ret->uts_release);
diff --git a/daemon/uuids.c b/daemon/uuids.c
index 7e69862..8abf7cc 100644
--- a/daemon/uuids.c
+++ b/daemon/uuids.c
@@ -27,7 +27,6 @@
#include "actions.h"
#include "optgroups.h"
-
static int
e2uuid (const char *device, const char *uuid)
{
@@ -78,8 +77,8 @@ do_set_uuid (const char *device, const char *uuid)
r = btrfs_set_uuid (device, uuid);
else
- NOT_SUPPORTED (-1, "don't know how to set the UUID for '%s'
filesystems",
- vfs_type);
+ NOT_SUPPORTED (
+ -1, "don't know how to set the UUID for '%s' filesystems",
vfs_type);
return r;
}
@@ -111,7 +110,8 @@ do_set_uuid_random (const char *device)
r = btrfs_set_uuid_random (device);
else
- NOT_SUPPORTED (-1, "don't know how to set the random UUID for '%s'
filesystems",
- vfs_type);
+ NOT_SUPPORTED (
+ -1, "don't know how to set the random UUID for '%s'
filesystems",
+ vfs_type);
return r;
}
diff --git a/daemon/wc.c b/daemon/wc.c
index 454cdf3..8ed6124 100644
--- a/daemon/wc.c
+++ b/daemon/wc.c
@@ -35,7 +35,7 @@ wc (const char *flag, const char *path)
int fd, flags, r;
CHROOT_IN;
- fd = open (path, O_RDONLY|O_CLOEXEC);
+ fd = open (path, O_RDONLY | O_CLOEXEC);
CHROOT_OUT;
if (fd == -1) {
diff --git a/daemon/xattr.c b/daemon/xattr.c
index 7de5554..58311d0 100644
--- a/daemon/xattr.c
+++ b/daemon/xattr.c
@@ -27,23 +27,23 @@
#include "actions.h"
#include "optgroups.h"
-#if (defined(HAVE_ATTR_XATTR_H) || defined(HAVE_SYS_XATTR_H)) && \
- defined(HAVE_LISTXATTR) && defined(HAVE_LLISTXATTR) && \
- defined(HAVE_GETXATTR) && defined(HAVE_LGETXATTR) && \
- defined(HAVE_REMOVEXATTR) && defined(HAVE_LREMOVEXATTR) && \
+#if (defined(HAVE_ATTR_XATTR_H) || defined(HAVE_SYS_XATTR_H)) && \
+ defined(HAVE_LISTXATTR) && defined(HAVE_LLISTXATTR) && \
+ defined(HAVE_GETXATTR) && defined(HAVE_LGETXATTR) && \
+ defined(HAVE_REMOVEXATTR) && defined(HAVE_LREMOVEXATTR) && \
defined(HAVE_SETXATTR) && defined(HAVE_LSETXATTR)
-# define HAVE_LINUX_XATTRS
+#define HAVE_LINUX_XATTRS
#endif
#ifdef HAVE_LINUX_XATTRS
-# ifdef HAVE_ATTR_XATTR_H
-# include <attr/xattr.h>
-# else
-# ifdef HAVE_SYS_XATTR_H
-# include <sys/xattr.h>
-# endif
-# endif
+#ifdef HAVE_ATTR_XATTR_H
+#include <attr/xattr.h>
+#else
+#ifdef HAVE_SYS_XATTR_H
+#include <sys/xattr.h>
+#endif
+#endif
int
optgroup_linuxxattrs_available (void)
@@ -51,11 +51,27 @@ optgroup_linuxxattrs_available (void)
return 1;
}
-static guestfs_int_xattr_list *getxattrs (const char *path, ssize_t (*listxattr) (const
char *path, char *list, size_t size), ssize_t (*getxattr) (const char *path, const char
*name, void *value, size_t size));
-static int _setxattr (const char *xattr, const char *val, int vallen, const char *path,
int (*setxattr) (const char *path, const char *name, const void *value, size_t size, int
flags));
-static int _removexattr (const char *xattr, const char *path, int (*removexattr) (const
char *path, const char *name));
-static char *_listxattrs (const char *path, ssize_t (*listxattr) (const char *path, char
*list, size_t size), ssize_t *size);
-static char *_getxattr (const char *name, const char *path, ssize_t (*getxattr) (const
char *path, const char *name, void *value, size_t size), size_t *size_r);
+static guestfs_int_xattr_list *
+getxattrs (const char *path,
+ ssize_t (*listxattr) (const char *path, char *list, size_t size),
+ ssize_t (*getxattr) (const char *path, const char *name,
+ void *value, size_t size));
+static int
+_setxattr (const char *xattr, const char *val, int vallen, const char *path,
+ int (*setxattr) (const char *path, const char *name,
+ const void *value, size_t size, int flags));
+static int _removexattr (const char *xattr, const char *path,
+ int (*removexattr) (const char *path,
+ const char *name));
+static char *_listxattrs (const char *path,
+ ssize_t (*listxattr) (const char *path,
+ char *list, size_t size),
+ ssize_t *size);
+static char *_getxattr (const char *name, const char *path,
+ ssize_t (*getxattr) (const char *path,
+ const char *name, void *value,
+ size_t size),
+ size_t *size_r);
guestfs_int_xattr_list *
do_getxattrs (const char *path)
@@ -70,13 +86,15 @@ do_lgetxattrs (const char *path)
}
int
-do_setxattr (const char *xattr, const char *val, int vallen, const char *path)
+do_setxattr (const char *xattr, const char *val, int vallen,
+ const char *path)
{
return _setxattr (xattr, val, vallen, path, setxattr);
}
int
-do_lsetxattr (const char *xattr, const char *val, int vallen, const char *path)
+do_lsetxattr (const char *xattr, const char *val, int vallen,
+ const char *path)
{
return _setxattr (xattr, val, vallen, path, lsetxattr);
}
@@ -128,7 +146,7 @@ getxattrs (const char *path,
* len. First count the strings.
*/
r->guestfs_int_xattr_list_len = 0;
- for (i = 0; i < (size_t) len; i += strlen (&buf[i]) + 1)
+ for (i = 0; i < (size_t)len; i += strlen (&buf[i]) + 1)
r->guestfs_int_xattr_list_len++;
r->guestfs_int_xattr_list_val =
@@ -138,7 +156,7 @@ getxattrs (const char *path,
goto error;
}
- for (i = 0, j = 0; i < (size_t) len; i += strlen (&buf[i]) + 1, ++j) {
+ for (i = 0, j = 0; i < (size_t)len; i += strlen (&buf[i]) + 1, ++j) {
CHROOT_IN;
vlen = getxattr (path, &buf[i], NULL, 0);
CHROOT_OUT;
@@ -164,9 +182,9 @@ getxattrs (const char *path,
}
CHROOT_IN;
- vlen = getxattr (path, &buf[i],
- r->guestfs_int_xattr_list_val[j].attrval.attrval_val,
- vlen);
+ vlen =
+ getxattr (path, &buf[i],
+ r->guestfs_int_xattr_list_val[j].attrval.attrval_val, vlen);
CHROOT_OUT;
if (vlen == -1) {
reply_with_perror ("getxattr");
@@ -176,13 +194,12 @@ getxattrs (const char *path,
/* Sort the entries by attrname. */
qsort (&r->guestfs_int_xattr_list_val[0],
- (size_t) r->guestfs_int_xattr_list_len,
- sizeof (guestfs_int_xattr),
+ (size_t)r->guestfs_int_xattr_list_len, sizeof (guestfs_int_xattr),
compare_xattrs);
return r;
- error:
+error:
if (r) {
if (r->guestfs_int_xattr_list_val) {
size_t k;
@@ -239,7 +256,8 @@ _removexattr (const char *xattr, const char *path,
static char *
_listxattrs (const char *path,
- ssize_t (*listxattr) (const char *path, char *list, size_t size),
+ ssize_t (*listxattr) (const char *path, char *list,
+ size_t size),
ssize_t *size)
{
char *buf = NULL;
@@ -271,7 +289,7 @@ _listxattrs (const char *path,
*size = len;
return buf;
- error:
+error:
free (buf);
return NULL;
}
@@ -315,8 +333,8 @@ do_internal_lxattrlist (const char *path, char *const *names)
/* Reserve space for the special attribute. */
newptr = realloc (ret->guestfs_int_xattr_list_val,
- (ret->guestfs_int_xattr_list_len+1) *
- sizeof (guestfs_int_xattr));
+ (ret->guestfs_int_xattr_list_len + 1) *
+ sizeof (guestfs_int_xattr));
if (newptr == NULL) {
reply_with_perror ("realloc");
goto error;
@@ -325,7 +343,7 @@ do_internal_lxattrlist (const char *path, char *const *names)
ret->guestfs_int_xattr_list_len++;
guestfs_int_xattr *entry =
- &ret->guestfs_int_xattr_list_val[ret->guestfs_int_xattr_list_len-1];
+ &ret->guestfs_int_xattr_list_val[ret->guestfs_int_xattr_list_len - 1];
entry->attrname = NULL;
entry->attrval.attrval_len = 0;
entry->attrval.attrval_val = NULL;
@@ -358,13 +376,12 @@ do_internal_lxattrlist (const char *path, char *const *names)
* len. First count the strings.
*/
nr_attrs = 0;
- for (i = 0; i < (size_t) len; i += strlen (&buf[i]) + 1)
+ for (i = 0; i < (size_t)len; i += strlen (&buf[i]) + 1)
nr_attrs++;
- newptr =
- realloc (ret->guestfs_int_xattr_list_val,
- (ret->guestfs_int_xattr_list_len+nr_attrs) *
- sizeof (guestfs_int_xattr));
+ newptr = realloc (ret->guestfs_int_xattr_list_val,
+ (ret->guestfs_int_xattr_list_len + nr_attrs) *
+ sizeof (guestfs_int_xattr));
if (newptr == NULL) {
reply_with_perror ("realloc");
goto error;
@@ -375,14 +392,16 @@ do_internal_lxattrlist (const char *path, char *const *names)
/* entry[0] is the special attribute,
* entry[1..nr_attrs] are the attributes.
*/
- entry =
&ret->guestfs_int_xattr_list_val[ret->guestfs_int_xattr_list_len-nr_attrs-1];
- for (m = 1; m < nr_attrs+1; ++m) {
+ entry =
+ &ret->guestfs_int_xattr_list_val[ret->guestfs_int_xattr_list_len -
+ nr_attrs - 1];
+ for (m = 1; m < nr_attrs + 1; ++m) {
entry[m].attrname = NULL;
entry[m].attrval.attrval_len = 0;
entry[m].attrval.attrval_val = NULL;
}
- for (i = 0, j = 0; i < (size_t) len; i += strlen (&buf[i]) + 1, ++j) {
+ for (i = 0, j = 0; i < (size_t)len; i += strlen (&buf[i]) + 1, ++j) {
CHROOT_IN;
vlen = lgetxattr (pathname, &buf[i], NULL, 0);
CHROOT_OUT;
@@ -396,19 +415,19 @@ do_internal_lxattrlist (const char *path, char *const *names)
goto error;
}
- entry[j+1].attrname = strdup (&buf[i]);
- entry[j+1].attrval.attrval_val = malloc (vlen);
- entry[j+1].attrval.attrval_len = vlen;
+ entry[j + 1].attrname = strdup (&buf[i]);
+ entry[j + 1].attrval.attrval_val = malloc (vlen);
+ entry[j + 1].attrval.attrval_len = vlen;
- if (entry[j+1].attrname == NULL ||
- entry[j+1].attrval.attrval_val == NULL) {
+ if (entry[j + 1].attrname == NULL ||
+ entry[j + 1].attrval.attrval_val == NULL) {
reply_with_perror ("malloc");
goto error;
}
CHROOT_IN;
- vlen = lgetxattr (pathname, &buf[i],
- entry[j+1].attrval.attrval_val, vlen);
+ vlen = lgetxattr (pathname, &buf[i], entry[j + 1].attrval.attrval_val,
+ vlen);
CHROOT_OUT;
if (vlen == -1) {
reply_with_perror ("getxattr");
@@ -432,7 +451,7 @@ do_internal_lxattrlist (const char *path, char *const *names)
return ret;
- error:
+error:
if (ret) {
if (ret->guestfs_int_xattr_list_val) {
for (k = 0; k < ret->guestfs_int_xattr_list_len; ++k) {
@@ -492,7 +511,7 @@ _getxattr (const char *name, const char *path,
return NULL;
}
- if (len != (size_t) r) {
+ if (len != (size_t)r) {
reply_with_error ("getxattr: unexpected size (%zu/%zd)", len, r);
free (buf);
return NULL;
@@ -524,7 +543,7 @@ copy_xattrs (const char *src, const char *dest)
/* What we get from the kernel is a string "foo\0bar\0baz" of length
* len.
*/
- for (i = 0; i < (size_t) len; i += strlen (&buf[i]) + 1) {
+ for (i = 0; i < (size_t)len; i += strlen (&buf[i]) + 1) {
CHROOT_IN;
vlen = getxattr (src, &buf[i], NULL, 0);
CHROOT_OUT;
@@ -568,7 +587,7 @@ copy_xattrs (const char *src, const char *dest)
return 1;
- error:
+error:
return 0;
}
diff --git a/daemon/xfs.c b/daemon/xfs.c
index 7f72e6a..a3ea77d 100644
--- a/daemon/xfs.c
+++ b/daemon/xfs.c
@@ -32,11 +32,11 @@
#define MAX_ARGS 64
-GUESTFSD_EXT_CMD(str_mkfs_xfs, mkfs.xfs);
-GUESTFSD_EXT_CMD(str_xfs_admin, xfs_admin);
-GUESTFSD_EXT_CMD(str_xfs_info, xfs_info);
-GUESTFSD_EXT_CMD(str_xfs_growfs, xfs_growfs);
-GUESTFSD_EXT_CMD(str_xfs_repair, xfs_repair);
+GUESTFSD_EXT_CMD (str_mkfs_xfs, mkfs.xfs);
+GUESTFSD_EXT_CMD (str_xfs_admin, xfs_admin);
+GUESTFSD_EXT_CMD (str_xfs_info, xfs_info);
+GUESTFSD_EXT_CMD (str_xfs_growfs, xfs_growfs);
+GUESTFSD_EXT_CMD (str_xfs_repair, xfs_repair);
int
optgroup_xfs_available (void)
@@ -94,7 +94,7 @@ parse_uint64 (uint64_t *ret, const char *str)
*
* meta-data=/dev/sda1 isize=256 agcount=4, agsize=6392 blks
* = sectsz=512 attr=2
- *[ = crc=0 ]
+ *[ = crc=0 ]
* data = bsize=4096 blocks=25568, imaxpct=25
* = sunit=0 swidth=0 blks
* naming =version 2 bsize=4096 ascii-ci=0
@@ -111,7 +111,8 @@ static guestfs_int_xfsinfo *
parse_xfs_info (char **lines)
{
guestfs_int_xfsinfo *ret;
- CLEANUP_FREE char *section = NULL; /* first column, eg "meta-data",
"data" */
+ CLEANUP_FREE char *section =
+ NULL; /* first column, eg "meta-data", "data" */
char *p;
size_t i;
@@ -157,145 +158,170 @@ parse_xfs_info (char **lines)
if (c_isalpha (lines[i][0])) {
free (section);
section = split_strdup (lines[i]);
- if (!section) goto error;
+ if (!section)
+ goto error;
if (verbose)
- fprintf (stderr, "xfs_info: new section %s\n", section);
+ fprintf (stderr, "xfs_info: new section %s\n", section);
}
if ((p = strstr (lines[i], "meta-data="))) {
ret->xfs_mntpoint = split_strdup (p + 10);
- if (ret->xfs_mntpoint == NULL) goto error;
+ if (ret->xfs_mntpoint == NULL)
+ goto error;
}
if ((p = strstr (lines[i], "isize="))) {
CLEANUP_FREE char *buf = split_strdup (p + 6);
- if (buf == NULL) goto error;
+ if (buf == NULL)
+ goto error;
if (parse_uint32 (&ret->xfs_inodesize, buf) == -1)
goto error;
}
if ((p = strstr (lines[i], "agcount="))) {
CLEANUP_FREE char *buf = split_strdup (p + 8);
- if (buf == NULL) goto error;
+ if (buf == NULL)
+ goto error;
if (parse_uint32 (&ret->xfs_agcount, buf) == -1)
goto error;
}
if ((p = strstr (lines[i], "agsize="))) {
CLEANUP_FREE char *buf = split_strdup (p + 7);
- if (buf == NULL) goto error;
+ if (buf == NULL)
+ goto error;
if (parse_uint32 (&ret->xfs_agsize, buf) == -1)
goto error;
}
if ((p = strstr (lines[i], "sectsz="))) {
if (section) {
- CLEANUP_FREE char *buf = split_strdup (p + 7);
- if (buf == NULL) goto error;
- if (STREQ (section, "meta-data")) {
- if (parse_uint32 (&ret->xfs_sectsize, buf) == -1)
- goto error;
- } else if (STREQ (section, "log")) {
- if (parse_uint32 (&ret->xfs_logsectsize, buf) == -1)
- goto error;
- }
+ CLEANUP_FREE char *buf = split_strdup (p + 7);
+ if (buf == NULL)
+ goto error;
+ if (STREQ (section, "meta-data")) {
+ if (parse_uint32 (&ret->xfs_sectsize, buf) == -1)
+ goto error;
+ }
+ else if (STREQ (section, "log")) {
+ if (parse_uint32 (&ret->xfs_logsectsize, buf) == -1)
+ goto error;
+ }
}
}
if ((p = strstr (lines[i], "attr="))) {
CLEANUP_FREE char *buf = split_strdup (p + 5);
- if (buf == NULL) goto error;
+ if (buf == NULL)
+ goto error;
if (parse_uint32 (&ret->xfs_attr, buf) == -1)
goto error;
}
if ((p = strstr (lines[i], "bsize="))) {
if (section) {
- CLEANUP_FREE char *buf = split_strdup (p + 6);
- if (buf == NULL) goto error;
- if (STREQ (section, "data")) {
- if (parse_uint32 (&ret->xfs_blocksize, buf) == -1)
- goto error;
- } else if (STREQ (section, "naming")) {
- if (parse_uint32 (&ret->xfs_dirblocksize, buf) == -1)
- goto error;
- } else if (STREQ (section, "log")) {
- if (parse_uint32 (&ret->xfs_logblocksize, buf) == -1)
- goto error;
- }
+ CLEANUP_FREE char *buf = split_strdup (p + 6);
+ if (buf == NULL)
+ goto error;
+ if (STREQ (section, "data")) {
+ if (parse_uint32 (&ret->xfs_blocksize, buf) == -1)
+ goto error;
+ }
+ else if (STREQ (section, "naming")) {
+ if (parse_uint32 (&ret->xfs_dirblocksize, buf) == -1)
+ goto error;
+ }
+ else if (STREQ (section, "log")) {
+ if (parse_uint32 (&ret->xfs_logblocksize, buf) == -1)
+ goto error;
+ }
}
}
if ((p = strstr (lines[i], "blocks="))) {
if (section) {
- CLEANUP_FREE char *buf = split_strdup (p + 7);
- if (buf == NULL) goto error;
- if (STREQ (section, "data")) {
- if (parse_uint64 (&ret->xfs_datablocks, buf) == -1)
- goto error;
- } else if (STREQ (section, "log")) {
- if (parse_uint32 (&ret->xfs_logblocks, buf) == -1)
- goto error;
- } else if (STREQ (section, "realtime")) {
- if (parse_uint64 (&ret->xfs_rtblocks, buf) == -1)
- goto error;
- }
+ CLEANUP_FREE char *buf = split_strdup (p + 7);
+ if (buf == NULL)
+ goto error;
+ if (STREQ (section, "data")) {
+ if (parse_uint64 (&ret->xfs_datablocks, buf) == -1)
+ goto error;
+ }
+ else if (STREQ (section, "log")) {
+ if (parse_uint32 (&ret->xfs_logblocks, buf) == -1)
+ goto error;
+ }
+ else if (STREQ (section, "realtime")) {
+ if (parse_uint64 (&ret->xfs_rtblocks, buf) == -1)
+ goto error;
+ }
}
}
if ((p = strstr (lines[i], "imaxpct="))) {
CLEANUP_FREE char *buf = split_strdup (p + 8);
- if (buf == NULL) goto error;
+ if (buf == NULL)
+ goto error;
if (parse_uint32 (&ret->xfs_imaxpct, buf) == -1)
goto error;
}
if ((p = strstr (lines[i], "sunit="))) {
if (section) {
- CLEANUP_FREE char *buf = split_strdup (p + 6);
- if (buf == NULL) goto error;
- if (STREQ (section, "data")) {
- if (parse_uint32 (&ret->xfs_sunit, buf) == -1)
- goto error;
- } else if (STREQ (section, "log")) {
- if (parse_uint32 (&ret->xfs_logsunit, buf) == -1)
- goto error;
- }
+ CLEANUP_FREE char *buf = split_strdup (p + 6);
+ if (buf == NULL)
+ goto error;
+ if (STREQ (section, "data")) {
+ if (parse_uint32 (&ret->xfs_sunit, buf) == -1)
+ goto error;
+ }
+ else if (STREQ (section, "log")) {
+ if (parse_uint32 (&ret->xfs_logsunit, buf) == -1)
+ goto error;
+ }
}
}
if ((p = strstr (lines[i], "swidth="))) {
CLEANUP_FREE char *buf = split_strdup (p + 7);
- if (buf == NULL) goto error;
+ if (buf == NULL)
+ goto error;
if (parse_uint32 (&ret->xfs_swidth, buf) == -1)
goto error;
}
if ((p = strstr (lines[i], "naming =version "))) {
CLEANUP_FREE char *buf = split_strdup (p + 18);
- if (buf == NULL) goto error;
+ if (buf == NULL)
+ goto error;
if (parse_uint32 (&ret->xfs_dirversion, buf) == -1)
goto error;
}
if ((p = strstr (lines[i], "ascii-ci="))) {
CLEANUP_FREE char *buf = split_strdup (p + 9);
- if (buf == NULL) goto error;
+ if (buf == NULL)
+ goto error;
if (parse_uint32 (&ret->xfs_cimode, buf) == -1)
goto error;
}
if ((p = strstr (lines[i], "log ="))) {
ret->xfs_logname = split_strdup (p + 10);
- if (ret->xfs_logname == NULL) goto error;
+ if (ret->xfs_logname == NULL)
+ goto error;
}
if ((p = strstr (lines[i], "version="))) {
CLEANUP_FREE char *buf = split_strdup (p + 8);
- if (buf == NULL) goto error;
+ if (buf == NULL)
+ goto error;
if (parse_uint32 (&ret->xfs_logversion, buf) == -1)
goto error;
}
if ((p = strstr (lines[i], "lazy-count="))) {
CLEANUP_FREE char *buf = split_strdup (p + 11);
- if (buf == NULL) goto error;
+ if (buf == NULL)
+ goto error;
if (parse_uint32 (&ret->xfs_lazycount, buf) == -1)
goto error;
}
if ((p = strstr (lines[i], "realtime ="))) {
ret->xfs_rtname = split_strdup (p + 10);
- if (ret->xfs_rtname == NULL) goto error;
+ if (ret->xfs_rtname == NULL)
+ goto error;
}
if ((p = strstr (lines[i], "rtextents="))) {
CLEANUP_FREE char *buf = split_strdup (p + 10);
- if (buf == NULL) goto error;
+ if (buf == NULL)
+ goto error;
if (parse_uint64 (&ret->xfs_rtextents, buf) == -1)
goto error;
}
@@ -303,20 +329,23 @@ parse_xfs_info (char **lines)
if (ret->xfs_mntpoint == NULL) {
ret->xfs_mntpoint = strdup ("");
- if (ret->xfs_mntpoint == NULL) goto error;
+ if (ret->xfs_mntpoint == NULL)
+ goto error;
}
if (ret->xfs_logname == NULL) {
ret->xfs_logname = strdup ("");
- if (ret->xfs_logname == NULL) goto error;
+ if (ret->xfs_logname == NULL)
+ goto error;
}
if (ret->xfs_rtname == NULL) {
ret->xfs_rtname = strdup ("");
- if (ret->xfs_rtname == NULL) goto error;
+ if (ret->xfs_rtname == NULL)
+ goto error;
}
return ret;
- error:
+error:
free (ret->xfs_mntpoint);
free (ret->xfs_logname);
free (ret->xfs_rtname);
@@ -334,8 +363,7 @@ do_xfs_info (const char *pathordevice)
int is_dev;
is_dev = STREQLEN (pathordevice, "/dev/", 5);
- buf = is_dev ? strdup (pathordevice)
- : sysroot_path (pathordevice);
+ buf = is_dev ? strdup (pathordevice) : sysroot_path (pathordevice);
if (buf == NULL) {
reply_with_perror ("malloc");
return NULL;
@@ -355,8 +383,7 @@ do_xfs_info (const char *pathordevice)
}
int
-do_xfs_growfs (const char *path,
- int datasec, int logsec, int rtsec,
+do_xfs_growfs (const char *path, int datasec, int logsec, int rtsec,
int64_t datasize, int64_t logsize, int64_t rtsize,
int64_t rtextsize, int32_t maxpct)
{
@@ -477,10 +504,9 @@ xfs_set_label (const char *device, const char *label)
}
int
-do_xfs_admin (const char *device,
- int extunwritten, int imgfile, int v2log,
- int projid32bit,
- int lazycounter, const char *label, const char *uuid)
+do_xfs_admin (const char *device, int extunwritten, int imgfile, int v2log,
+ int projid32bit, int lazycounter, const char *label,
+ const char *uuid)
{
int r;
CLEANUP_FREE char *err = NULL;
@@ -512,7 +538,8 @@ do_xfs_admin (const char *device,
if (lazycounter) {
ADD_ARG (argv, i, "-c");
ADD_ARG (argv, i, "1");
- } else {
+ }
+ else {
ADD_ARG (argv, i, "-c");
ADD_ARG (argv, i, "0");
}
@@ -520,8 +547,8 @@ do_xfs_admin (const char *device,
if (optargs_bitmask & GUESTFS_XFS_ADMIN_LABEL_BITMASK) {
if (strlen (label) > XFS_LABEL_MAX) {
- reply_with_error ("%s: xfs labels are limited to %d bytes",
- label, XFS_LABEL_MAX);
+ reply_with_error ("%s: xfs labels are limited to %d bytes", label,
+ XFS_LABEL_MAX);
return -1;
}
@@ -547,11 +574,9 @@ do_xfs_admin (const char *device,
}
int
-do_xfs_repair (const char *device,
- int forcelogzero, int nomodify,
- int noprefetch, int forcegeometry,
- int64_t maxmem, int64_t ihashsize,
- int64_t bhashsize, int64_t agstride,
+do_xfs_repair (const char *device, int forcelogzero, int nomodify,
+ int noprefetch, int forcegeometry, int64_t maxmem,
+ int64_t ihashsize, int64_t bhashsize, int64_t agstride,
const char *logdev, const char *rtdev)
{
int r;
@@ -601,7 +626,9 @@ do_xfs_repair (const char *device,
reply_with_error ("ihashsize must be >= 0");
return -1;
}
- snprintf (ihashsize_s, sizeof ihashsize_s, "ihash=" "%" PRIi64,
ihashsize);
+ snprintf (ihashsize_s, sizeof ihashsize_s, "ihash="
+ "%" PRIi64,
+ ihashsize);
ADD_ARG (argv, i, "-o");
ADD_ARG (argv, i, ihashsize_s);
}
@@ -611,7 +638,9 @@ do_xfs_repair (const char *device,
reply_with_error ("bhashsize must be >= 0");
return -1;
}
- snprintf (bhashsize_s, sizeof bhashsize_s, "bhash=" "%" PRIi64,
bhashsize);
+ snprintf (bhashsize_s, sizeof bhashsize_s, "bhash="
+ "%" PRIi64,
+ bhashsize);
ADD_ARG (argv, i, "-o");
ADD_ARG (argv, i, bhashsize_s);
}
@@ -621,12 +650,13 @@ do_xfs_repair (const char *device,
reply_with_error ("agstride must be >= 0");
return -1;
}
- snprintf (agstride_s, sizeof agstride_s, "ag_stride=" "%" PRIi64,
agstride);
+ snprintf (agstride_s, sizeof agstride_s, "ag_stride="
+ "%" PRIi64,
+ agstride);
ADD_ARG (argv, i, "-o");
ADD_ARG (argv, i, agstride_s);
}
-
if (optargs_bitmask & GUESTFS_XFS_REPAIR_LOGDEV_BITMASK) {
ADD_ARG (argv, i, "-l");
ADD_ARG (argv, i, logdev);
@@ -646,7 +676,8 @@ do_xfs_repair (const char *device,
}
ADD_ARG (argv, i, "-f");
ADD_ARG (argv, i, buf);
- } else {
+ }
+ else {
ADD_ARG (argv, i, device);
}
diff --git a/daemon/zero.c b/daemon/zero.c
index c545753..02e9fae 100644
--- a/daemon/zero.c
+++ b/daemon/zero.c
@@ -32,7 +32,7 @@
#include "actions.h"
#include "optgroups.h"
-GUESTFSD_EXT_CMD(str_wipefs, wipefs);
+GUESTFSD_EXT_CMD (str_wipefs, wipefs);
static const char zero_buf[4096];
@@ -43,7 +43,7 @@ do_zero (const char *device)
int fd;
size_t i, offset;
- fd = open (device, O_RDWR|O_CLOEXEC);
+ fd = open (device, O_RDWR | O_CLOEXEC);
if (fd == -1) {
reply_with_perror ("%s", device);
return -1;
@@ -60,14 +60,15 @@ do_zero (const char *device)
}
if (!is_zero (buf, sizeof buf)) {
- if (pwrite (fd, zero_buf, sizeof zero_buf, offset) != sizeof zero_buf) {
+ if (pwrite (fd, zero_buf, sizeof zero_buf, offset) !=
+ sizeof zero_buf) {
reply_with_perror ("pwrite: %s", device);
close (fd);
return -1;
}
}
- notify_progress ((uint64_t) i, 32);
+ notify_progress ((uint64_t)i, 32);
}
if (close (fd) == -1) {
@@ -140,9 +141,9 @@ do_zero_device (const char *device)
int64_t ssize = do_blockdev_getsize64 (device);
if (ssize == -1)
return -1;
- uint64_t size = (uint64_t) ssize;
+ uint64_t size = (uint64_t)ssize;
- int fd = open (device, O_RDWR|O_CLOEXEC);
+ int fd = open (device, O_RDWR | O_CLOEXEC);
if (fd == -1) {
reply_with_perror ("%s", device);
return -1;
@@ -158,7 +159,7 @@ do_zero_device (const char *device)
if (n64 > sizeof buf)
n = sizeof buf;
else
- n = (size_t) n64; /* safe because of if condition */
+ n = (size_t)n64; /* safe because of if condition */
/* Check if the block is already zero before overwriting it. */
ssize_t r;
@@ -172,7 +173,8 @@ do_zero_device (const char *device)
if (!is_zero (buf, sizeof buf)) {
r = pwrite (fd, zero_buf, n, pos);
if (r == -1) {
- reply_with_perror ("pwrite: %s (with %" PRIu64 " bytes left to
write)",
+ reply_with_perror ("pwrite: %s (with %" PRIu64
+ " bytes left to write)",
device, size);
close (fd);
return -1;
@@ -207,7 +209,7 @@ do_is_zero (const char *path)
}
CHROOT_IN;
- fd = open (path, O_RDONLY|O_CLOEXEC);
+ fd = open (path, O_RDONLY | O_CLOEXEC);
CHROOT_OUT;
if (fd == -1) {
@@ -249,7 +251,7 @@ do_is_zero_device (const char *device)
return -1;
}
- fd = open (device, O_RDONLY|O_CLOEXEC);
+ fd = open (device, O_RDONLY | O_CLOEXEC);
if (fd == -1) {
reply_with_perror ("open: %s", device);
return -1;
@@ -311,7 +313,8 @@ do_zero_free_space (const char *dir)
printf ("random filename: %s\n", filename);
/* Open file and fill with zeroes until we run out of space. */
- fd = open (filename, O_WRONLY|O_CREAT|O_EXCL|O_NOCTTY|O_CLOEXEC, 0600);
+ fd = open (filename, O_WRONLY | O_CREAT | O_EXCL | O_NOCTTY | O_CLOEXEC,
+ 0600);
if (fd == -1) {
reply_with_perror ("open: %s", filename);
return -1;
@@ -329,7 +332,7 @@ do_zero_free_space (const char *dir)
for (;;) {
if (write (fd, zero_buf, sizeof zero_buf) == -1) {
- if (errno == ENOSPC) /* expected error */
+ if (errno == ENOSPC) /* expected error */
break;
reply_with_perror ("write: %s", filename);
close (fd);
diff --git a/daemon/zerofree.c b/daemon/zerofree.c
index 4ba17dd..624ec85 100644
--- a/daemon/zerofree.c
+++ b/daemon/zerofree.c
@@ -28,7 +28,7 @@
#include "actions.h"
#include "optgroups.h"
-GUESTFSD_EXT_CMD(str_zerofree, zerofree);
+GUESTFSD_EXT_CMD (str_zerofree, zerofree);
int
optgroup_zerofree_available (void)
diff --git a/df/df.c b/df/df.c
index a13cc59..d67e92a 100644
--- a/df/df.c
+++ b/df/df.c
@@ -54,9 +54,8 @@ df_on_handle (guestfs_h *g, const char *name, const char *uuid, FILE
*fp)
return -1;
for (i = 0; fses[i] != NULL; i += 2) {
- if (STRNEQ (fses[i+1], "") &&
- STRNEQ (fses[i+1], "swap") &&
- STRNEQ (fses[i+1], "unknown")) {
+ if (STRNEQ (fses[i + 1], "") && STRNEQ (fses[i + 1],
"swap") &&
+ STRNEQ (fses[i + 1], "unknown")) {
const char *dev = fses[i];
CLEANUP_FREE_STATVFS struct guestfs_statvfs *stat = NULL;
@@ -96,9 +95,8 @@ df_work (guestfs_h *g, size_t i, FILE *fp)
{
struct guestfs_add_libvirt_dom_argv optargs;
- optargs.bitmask =
- GUESTFS_ADD_LIBVIRT_DOM_READONLY_BITMASK |
- GUESTFS_ADD_LIBVIRT_DOM_READONLYDISK_BITMASK;
+ optargs.bitmask = GUESTFS_ADD_LIBVIRT_DOM_READONLY_BITMASK |
+ GUESTFS_ADD_LIBVIRT_DOM_READONLYDISK_BITMASK;
optargs.readonly = 1;
optargs.readonlydisk = "read";
diff --git a/df/domains.c b/df/domains.c
index c651645..651a14a 100644
--- a/df/domains.c
+++ b/df/domains.c
@@ -67,7 +67,8 @@ free_domains (void)
}
static void add_domains_by_id (virConnectPtr conn, int *ids, size_t n);
-static void add_domains_by_name (virConnectPtr conn, char **names, size_t n);
+static void add_domains_by_name (virConnectPtr conn, char **names,
+ size_t n);
static void add_domain (virDomainPtr dom);
void
@@ -92,9 +93,11 @@ get_all_libvirt_domains (const char *libvirt_uri)
n = virConnectNumOfDomains (conn);
if (n == -1) {
err = virGetLastError ();
- error (EXIT_FAILURE, 0,
- _("could not get number of running domains (code %d, domain %d):
%s"),
- err->code, err->domain, err->message);
+ error (
+ EXIT_FAILURE, 0,
+ _ (
+ "could not get number of running domains (code %d, domain %d): %s"),
+ err->code, err->domain, err->message);
}
ids = malloc (sizeof (int) * n);
@@ -113,8 +116,8 @@ get_all_libvirt_domains (const char *libvirt_uri)
n = virConnectNumOfDefinedDomains (conn);
if (n == -1) {
err = virGetLastError ();
- error (EXIT_FAILURE, 0,
- _("could not get number of inactive domains (code %d, domain %d):
%s"),
+ error (EXIT_FAILURE, 0, _("could not get number of inactive domains "
+ "(code %d, domain %d): %s"),
err->code, err->domain, err->message);
}
@@ -134,7 +137,7 @@ get_all_libvirt_domains (const char *libvirt_uri)
/* You must free these even though the libvirt documentation doesn't
* mention it.
*/
- for (i = 0; i < (size_t) n; ++i)
+ for (i = 0; i < (size_t)n; ++i)
free (names[i]);
/* No domains? */
@@ -152,9 +155,9 @@ add_domains_by_id (virConnectPtr conn, int *ids, size_t n)
virDomainPtr dom;
for (i = 0; i < n; ++i) {
- if (ids[i] != 0) { /* RHBZ#538041 */
+ if (ids[i] != 0) { /* RHBZ#538041 */
dom = virDomainLookupByID (conn, ids[i]);
- if (dom) /* transient errors are possible here, ignore them */
+ if (dom) /* transient errors are possible here, ignore them */
add_domain (dom);
}
}
@@ -168,7 +171,7 @@ add_domains_by_name (virConnectPtr conn, char **names, size_t n)
for (i = 0; i < n; ++i) {
dom = virDomainLookupByName (conn, names[i]);
- if (dom) /* transient errors are possible here, ignore them */
+ if (dom) /* transient errors are possible here, ignore them */
add_domain (dom);
}
}
diff --git a/df/estimate-max-threads.c b/df/estimate-max-threads.c
index ca1fd42..c7e4026 100644
--- a/df/estimate-max-threads.c
+++ b/df/estimate-max-threads.c
@@ -67,7 +67,8 @@ read_line_from (const char *cmd)
error (EXIT_FAILURE, errno, "%s: external command failed", cmd);
if (getline (&ret, &allocsize, pp) == -1)
- error (EXIT_FAILURE, errno, "could not read line from external command");
+ error (EXIT_FAILURE, errno,
+ "could not read line from external command");
if (pclose (pp) == -1)
error (EXIT_FAILURE, errno, "pclose");
diff --git a/df/main.c b/df/main.c
index e04b14e..a00a242 100644
--- a/df/main.c
+++ b/df/main.c
@@ -53,10 +53,10 @@ int echo_keys = 0;
const char *libvirt_uri = NULL;
int inspector = 0;
-int csv = 0; /* --csv */
-int human = 0; /* --human-readable|-h */
-int inodes = 0; /* --inodes */
-int uuid = 0; /* --uuid */
+int csv = 0; /* --csv */
+int human = 0; /* --human-readable|-h */
+int inodes = 0; /* --inodes */
+int uuid = 0; /* --uuid */
static char *make_display_name (struct drv *drvs);
@@ -67,29 +67,30 @@ usage (int status)
fprintf (stderr, _("Try `%s --help' for more information.\n"),
guestfs_int_program_name);
else {
- printf (_("%s: display free space on virtual filesystems\n"
- "Copyright (C) 2010 Red Hat Inc.\n"
- "Usage:\n"
- " %s [--options] -d domname\n"
- " %s [--options] -a disk.img [-a disk.img ...]\n"
- "Options:\n"
- " -a|--add image Add image\n"
- " -c|--connect uri Specify libvirt URI for -d option\n"
- " --csv Output as Comma-Separated Values\n"
- " -d|--domain guest Add disks from libvirt guest\n"
- " --format[=raw|..] Force disk format for -a option\n"
- " -h|--human-readable Human-readable sizes in --long output\n"
- " --help Display brief help\n"
- " -i|--inodes Display inodes\n"
- " --one-per-guest Separate appliance per guest\n"
- " -P nr_threads Use at most nr_threads\n"
- " --uuid Add UUIDs to --long output\n"
- " -v|--verbose Verbose messages\n"
- " -V|--version Display version and exit\n"
- " -x Trace libguestfs API calls\n"
- "For more information, see the manpage %s(1).\n"),
- guestfs_int_program_name, guestfs_int_program_name,
- guestfs_int_program_name, guestfs_int_program_name);
+ printf (
+ _("%s: display free space on virtual filesystems\n"
+ "Copyright (C) 2010 Red Hat Inc.\n"
+ "Usage:\n"
+ " %s [--options] -d domname\n"
+ " %s [--options] -a disk.img [-a disk.img ...]\n"
+ "Options:\n"
+ " -a|--add image Add image\n"
+ " -c|--connect uri Specify libvirt URI for -d option\n"
+ " --csv Output as Comma-Separated Values\n"
+ " -d|--domain guest Add disks from libvirt guest\n"
+ " --format[=raw|..] Force disk format for -a option\n"
+ " -h|--human-readable Human-readable sizes in --long output\n"
+ " --help Display brief help\n"
+ " -i|--inodes Display inodes\n"
+ " --one-per-guest Separate appliance per guest\n"
+ " -P nr_threads Use at most nr_threads\n"
+ " --uuid Add UUIDs to --long output\n"
+ " -v|--verbose Verbose messages\n"
+ " -V|--version Display version and exit\n"
+ " -x Trace libguestfs API calls\n"
+ "For more information, see the manpage %s(1).\n"),
+ guestfs_int_program_name, guestfs_int_program_name,
+ guestfs_int_program_name, guestfs_int_program_name);
}
exit (status);
}
@@ -136,25 +137,29 @@ main (int argc, char *argv[])
for (;;) {
c = getopt_long (argc, argv, options, long_options, &option_index);
- if (c == -1) break;
+ if (c == -1)
+ break;
switch (c) {
- case 0: /* options which are long only */
+ case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "long-options"))
display_long_options (long_options);
else if (STREQ (long_options[option_index].name, "short-options"))
display_short_options (options);
else if (STREQ (long_options[option_index].name, "format")) {
OPTION_format;
- } else if (STREQ (long_options[option_index].name, "csv")) {
+ }
+ else if (STREQ (long_options[option_index].name, "csv")) {
csv = 1;
- } else if (STREQ (long_options[option_index].name, "one-per-guest")) {
+ }
+ else if (STREQ (long_options[option_index].name, "one-per-guest")) {
/* nothing - left for backwards compatibility */
- } else if (STREQ (long_options[option_index].name, "uuid")) {
+ }
+ else if (STREQ (long_options[option_index].name, "uuid")) {
uuid = 1;
- } else
- error (EXIT_FAILURE, 0,
- _("unknown long option: %s (%d)"),
+ }
+ else
+ error (EXIT_FAILURE, 0, _("unknown long option: %s (%d)"),
long_options[option_index].name, option_index);
break;
@@ -219,7 +224,8 @@ main (int argc, char *argv[])
error (EXIT_FAILURE, errno, "strdup");
drv->next = drvs;
drvs = drv;
- } else { /* simulate -d option */
+ }
+ else { /* simulate -d option */
drv = calloc (1, sizeof (struct drv));
if (!drv)
error (EXIT_FAILURE, errno, "calloc");
@@ -251,7 +257,8 @@ main (int argc, char *argv[])
* fields. (RHBZ#600977).
*/
if (human && csv)
- error (EXIT_FAILURE, 0, _("you cannot use -h and --csv options
together."));
+ error (EXIT_FAILURE, 0,
+ _("you cannot use -h and --csv options together."));
/* virt-df has two modes. If the user didn't specify any drives,
* then we do the df on every libvirt guest. That's the if-clause
@@ -265,11 +272,10 @@ main (int argc, char *argv[])
err = start_threads (max_threads, g, df_work);
free_domains ();
#else
- error (EXIT_FAILURE, 0,
- _("compiled without support for libvirt."));
+ error (EXIT_FAILURE, 0, _("compiled without support for libvirt."));
#endif
}
- else { /* Single guest. */
+ else { /* Single guest. */
CLEANUP_FREE char *name = NULL;
/* Add domains/drives from the command line (for a single guest). */
@@ -318,7 +324,7 @@ single_drive_display_name (struct drv *drvs)
if (name == NULL)
name = drvs->a.filename;
else
- name++; /* skip '/' character */
+ name++; /* skip '/' character */
name = strdup (name);
if (name == NULL)
error (EXIT_FAILURE, errno, "strdup");
@@ -333,7 +339,7 @@ single_drive_display_name (struct drv *drvs)
*/
p = strrchr (name, '/');
if (p && strlen (p) > 1) {
- p = strdup (p+1);
+ p = strdup (p + 1);
if (!p)
error (EXIT_FAILURE, errno, "strdup");
free (name);
diff --git a/df/output.c b/df/output.c
index b9bbcb6..2b6377a 100644
--- a/df/output.c
+++ b/df/output.c
@@ -56,7 +56,8 @@ print_title (void)
cols[3] = _("Used");
cols[4] = _("Available");
cols[5] = _("Use%");
- } else {
+ }
+ else {
cols[2] = _("Inodes");
cols[3] = _("IUsed");
cols[4] = _("IFree");
@@ -65,8 +66,8 @@ print_title (void)
if (!csv) {
/* ignore cols[0] in this mode */
- printf ("%-36s%10s %10s %10s %5s\n",
- cols[1], cols[2], cols[3], cols[4], cols[5]);
+ printf ("%-36s%10s %10s %10s %5s\n", cols[1], cols[2], cols[3], cols[4],
+ cols[5]);
}
else {
size_t i;
@@ -81,23 +82,23 @@ print_title (void)
}
void
-print_stat (FILE *fp,
- const char *name, const char *uuid_param,
- const char *dev_param,
- const struct guestfs_statvfs *stat)
+print_stat (FILE *fp, const char *name, const char *uuid_param,
+ const char *dev_param, const struct guestfs_statvfs *stat)
{
- /* First two columns are always 'name' and 'dev', followed by four
- * other data columns. In text mode the 'name' and 'dev' are
- * combined into a single 'name:dev' column. In CSV mode they are
- * kept as two separate columns. In UUID mode the name might be
- * replaced by 'uuid', if available.
- */
-#define MAX_LEN (LONGEST_HUMAN_READABLE > 128 ? LONGEST_HUMAN_READABLE : 128)
+/* First two columns are always 'name' and 'dev', followed by four
+ * other data columns. In text mode the 'name' and 'dev' are
+ * combined into a single 'name:dev' column. In CSV mode they are
+ * kept as two separate columns. In UUID mode the name might be
+ * replaced by 'uuid', if available.
+ */
+#define MAX_LEN \
+ (LONGEST_HUMAN_READABLE > 128 ? LONGEST_HUMAN_READABLE : 128)
char buf[4][MAX_LEN];
const char *cols[4];
int64_t factor, v;
float percent;
- int hopts = human_round_to_nearest|human_autoscale|human_base_1024|human_SI;
+ int hopts =
+ human_round_to_nearest | human_autoscale | human_base_1024 | human_SI;
size_t i, len;
char *dev;
@@ -106,7 +107,7 @@ print_stat (FILE *fp,
if (!dev)
exit (EXIT_FAILURE);
- if (!inodes) { /* 1K blocks */
+ if (!inodes) { /* 1K blocks */
if (!human) {
factor = stat->bsize / 1024;
@@ -119,16 +120,15 @@ print_stat (FILE *fp,
v = stat->bavail * factor;
snprintf (buf[2], MAX_LEN, "%" PRIi64, v);
cols[2] = buf[2];
- } else {
- cols[0] =
- human_readable ((uintmax_t) stat->blocks, buf[0],
- hopts, stat->bsize, 1);
+ }
+ else {
+ cols[0] = human_readable ((uintmax_t)stat->blocks, buf[0], hopts,
+ stat->bsize, 1);
v = stat->blocks - stat->bfree;
cols[1] =
- human_readable ((uintmax_t) v, buf[1], hopts, stat->bsize, 1);
- cols[2] =
- human_readable ((uintmax_t) stat->bavail, buf[2],
- hopts, stat->bsize, 1);
+ human_readable ((uintmax_t)v, buf[1], hopts, stat->bsize, 1);
+ cols[2] = human_readable ((uintmax_t)stat->bavail, buf[2], hopts,
+ stat->bsize, 1);
}
if (stat->blocks != 0)
@@ -136,7 +136,7 @@ print_stat (FILE *fp,
else
percent = 0;
}
- else { /* inodes */
+ else { /* inodes */
snprintf (buf[0], MAX_LEN, "%" PRIi64, stat->files);
cols[0] = buf[0];
snprintf (buf[1], MAX_LEN, "%" PRIi64, stat->files - stat->ffree);
@@ -151,10 +151,11 @@ print_stat (FILE *fp,
}
if (!csv)
- /* Use 'ceil' on the percentage in order to emulate what df itself does. */
+ /* Use 'ceil' on the percentage in order to emulate what df itself does.
+ */
snprintf (buf[3], MAX_LEN, "%3.0f%%", ceil (percent));
else
- snprintf (buf[3], MAX_LEN, "%.1f", (double) percent);
+ snprintf (buf[3], MAX_LEN, "%.1f", (double)percent);
cols[3] = buf[3];
#undef MAX_LEN
@@ -168,11 +169,13 @@ print_stat (FILE *fp,
if (len <= 36) {
for (i = len; i < 36; ++i)
fputc (' ', fp);
- } else {
+ }
+ else {
fprintf (fp, "\n ");
}
- fprintf (fp, "%10s %10s %10s %5s\n", cols[0], cols[1], cols[2], cols[3]);
+ fprintf (fp, "%10s %10s %10s %5s\n", cols[0], cols[1], cols[2],
+ cols[3]);
}
else {
write_csv_field (fp, name);
@@ -202,8 +205,8 @@ write_csv_field (FILE *fp, const char *field)
len = strlen (field);
for (i = 0; i < len; ++i) {
- if (field[i] == ' ' || field[i] == '"' ||
- field[i] == '\n' || field[i] == ',') {
+ if (field[i] == ' ' || field[i] == '"' || field[i] ==
'\n' ||
+ field[i] == ',') {
needs_quoting = 1;
break;
}
@@ -220,7 +223,8 @@ write_csv_field (FILE *fp, const char *field)
if (field[i] == '"') {
fputc ('"', fp);
fputc ('"', fp);
- } else
+ }
+ else
fputc (field[i], fp);
}
fputc ('"', fp);
diff --git a/df/parallel.c b/df/parallel.c
index aa37bc3..83dc16c 100644
--- a/df/parallel.c
+++ b/df/parallel.c
@@ -70,10 +70,10 @@ static void thread_failure (const char *fn, int err);
static void *worker_thread (void *arg);
struct thread_data {
- size_t thread_num; /* Thread number. */
- int trace, verbose; /* Flags from the options_handle. */
+ size_t thread_num; /* Thread number. */
+ int trace, verbose; /* Flags from the options_handle. */
work_fn work;
- int r; /* Used to store the error status. */
+ int r; /* Used to store the error status. */
};
/* Start threads. */
@@ -81,21 +81,24 @@ int
start_threads (size_t option_P, guestfs_h *options_handle, work_fn work)
{
const int trace = options_handle ? guestfs_get_trace (options_handle) : 0;
- const int verbose = options_handle ? guestfs_get_verbose (options_handle) : 0;
+ const int verbose =
+ options_handle ? guestfs_get_verbose (options_handle) : 0;
size_t i, nr_threads;
int err, errors;
void *status;
CLEANUP_FREE struct thread_data *thread_data = NULL;
CLEANUP_FREE pthread_t *threads = NULL;
- if (nr_domains == 0) /* Nothing to do. */
+ if (nr_domains == 0) /* Nothing to do. */
return 0;
- /* If the user selected the -P option, then we use up to that many threads. */
+ /* If the user selected the -P option, then we use up to that many
+ * threads. */
if (option_P > 0)
nr_threads = MIN (nr_domains, option_P);
else
- nr_threads = MIN (nr_domains, MIN (MAX_THREADS, estimate_max_threads ()));
+ nr_threads =
+ MIN (nr_domains, MIN (MAX_THREADS, estimate_max_threads ()));
if (verbose)
fprintf (stderr, "parallel: creating %zu threads\n", nr_threads);
@@ -114,7 +117,8 @@ start_threads (size_t option_P, guestfs_h *options_handle, work_fn
work)
/* Start the worker threads. */
for (i = 0; i < nr_threads; ++i) {
- err = pthread_create (&threads[i], NULL, worker_thread, &thread_data[i]);
+ err =
+ pthread_create (&threads[i], NULL, worker_thread, &thread_data[i]);
if (err != 0)
error (EXIT_FAILURE, err, "pthread_create [%zu]", i);
}
@@ -147,7 +151,7 @@ worker_thread (void *thread_data_vp)
thread_data->thread_num);
while (1) {
- size_t i; /* The current domain we're working on. */
+ size_t i; /* The current domain we're working on. */
FILE *fp;
CLEANUP_FREE char *output = NULL;
size_t output_len = 0;
@@ -174,7 +178,7 @@ worker_thread (void *thread_data_vp)
return &thread_data->r;
}
- if (i >= nr_domains) /* Work finished. */
+ if (i >= nr_domains) /* Work finished. */
break;
if (thread_data->verbose)
@@ -222,7 +226,8 @@ worker_thread (void *thread_data_vp)
* may mean waiting for another thread to finish here.
*/
if (thread_data->verbose)
- fprintf (stderr, "parallel: thread %zu waiting to retire domain %zu\n",
+ fprintf (stderr,
+ "parallel: thread %zu waiting to retire domain %zu\n",
thread_data->thread_num, i);
err = pthread_mutex_lock (&retire_mutex);
@@ -249,7 +254,7 @@ worker_thread (void *thread_data_vp)
printf ("%s", output);
/* Update next_domain_to_retire and tell other threads. */
- next_domain_to_retire = i+1;
+ next_domain_to_retire = i + 1;
pthread_cond_broadcast (&retire_cond);
err = pthread_mutex_unlock (&retire_mutex);
if (err != 0) {
@@ -269,8 +274,8 @@ worker_thread (void *thread_data_vp)
static void
thread_failure (const char *fn, int err)
{
- fprintf (stderr, "%s: %s: %s\n",
- guestfs_int_program_name, fn, strerror (err));
+ fprintf (stderr, "%s: %s: %s\n", guestfs_int_program_name, fn,
+ strerror (err));
}
#endif /* HAVE_LIBVIRT */
diff --git a/df/parallel.h b/df/parallel.h
index 44f03bc..cdb7880 100644
--- a/df/parallel.h
+++ b/df/parallel.h
@@ -41,7 +41,8 @@ typedef int (*work_fn) (guestfs_h *g, size_t i, FILE *fp);
* Returns 0 if all work items completed successfully, or -1 if there
* was an error.
*/
-extern int start_threads (size_t option_P, guestfs_h *options_handle, work_fn work);
+extern int start_threads (size_t option_P, guestfs_h *options_handle,
+ work_fn work);
#endif /* HAVE_LIBVIRT */
diff --git a/df/virt-df.h b/df/virt-df.h
index a93a5a6..365340c 100644
--- a/df/virt-df.h
+++ b/df/virt-df.h
@@ -19,19 +19,22 @@
#ifndef GUESTFS_VIRT_DF_H_
#define GUESTFS_VIRT_DF_H_
-extern int csv; /* --csv */
-extern int human; /* --human-readable|-h */
-extern int inodes; /* --inodes */
-extern int uuid; /* --uuid */
+extern int csv; /* --csv */
+extern int human; /* --human-readable|-h */
+extern int inodes; /* --inodes */
+extern int uuid; /* --uuid */
/* df.c */
-extern int df_on_handle (guestfs_h *g, const char *name, const char *uuid, FILE *fp);
+extern int df_on_handle (guestfs_h *g, const char *name, const char *uuid,
+ FILE *fp);
#if defined(HAVE_LIBVIRT)
extern int df_work (guestfs_h *g, size_t i, FILE *fp);
#endif
/* output.c */
extern void print_title (void);
-extern void print_stat (FILE *fp, const char *name, const char *uuid, const char *dev,
const struct guestfs_statvfs *stat);
+extern void print_stat (FILE *fp, const char *name, const char *uuid,
+ const char *dev,
+ const struct guestfs_statvfs *stat);
#endif /* GUESTFS_VIRT_DF_H_ */
diff --git a/diff/diff.c b/diff/diff.c
index d7542fc..53cb63b 100644
--- a/diff/diff.c
+++ b/diff/diff.c
@@ -93,41 +93,43 @@ usage (int status)
fprintf (stderr, _("Try `%s --help' for more information.\n"),
guestfs_int_program_name);
else {
- printf (_("%s: list differences between virtual machines\n"
- "Copyright (C) 2010-2016 Red Hat Inc.\n"
- "Usage:\n"
- " %s [--options] -d domain1 -D domain2\n"
- " %s [--options] -a disk1.img -A disk2.img [-a|-A ...]\n"
- "Options:\n"
- " -a|--add image Add image from first guest\n"
- " --all Same as: --extra-stats --times --uids
--xattrs\n"
- " --atime Don't ignore access time changes\n"
- " -A image Add image from second guest\n"
- " --checksum[=...] Use checksum of file content\n"
- " -c|--connect uri Specify libvirt URI for -d option\n"
- " --csv Comma-Separated Values output\n"
- " --dir-links Don't ignore directory nlink
changes\n"
- " --dir-times Don't ignore directory time
changes\n"
- " -d|--domain guest Add disks from first libvirt guest\n"
- " -D guest Add disks from second libvirt guest\n"
- " --echo-keys Don't turn off echo for
passphrases\n"
- " --extra-stats Display extra stats\n"
- " --format[=raw|..] Force disk format for -a or -A option\n"
- " --help Display brief help\n"
- " -h|--human-readable Human-readable sizes in output\n"
- " --keys-from-stdin Read passphrases from stdin\n"
- " --times Display file times\n"
- " --time-days Display file times as days before now\n"
- " --time-relative Display file times as seconds before
now\n"
- " --time-t Display file times as time_t's\n"
- " --uids Display UID, GID\n"
- " -v|--verbose Verbose messages\n"
- " -V|--version Display version and exit\n"
- " -x Trace libguestfs API calls\n"
- " --xattrs Display extended attributes\n"
- "For more information, see the manpage %s(1).\n"),
- guestfs_int_program_name, guestfs_int_program_name,
- guestfs_int_program_name, guestfs_int_program_name);
+ printf (
+ _("%s: list differences between virtual machines\n"
+ "Copyright (C) 2010-2016 Red Hat Inc.\n"
+ "Usage:\n"
+ " %s [--options] -d domain1 -D domain2\n"
+ " %s [--options] -a disk1.img -A disk2.img [-a|-A ...]\n"
+ "Options:\n"
+ " -a|--add image Add image from first guest\n"
+ " --all Same as: --extra-stats --times --uids "
+ "--xattrs\n"
+ " --atime Don't ignore access time changes\n"
+ " -A image Add image from second guest\n"
+ " --checksum[=...] Use checksum of file content\n"
+ " -c|--connect uri Specify libvirt URI for -d option\n"
+ " --csv Comma-Separated Values output\n"
+ " --dir-links Don't ignore directory nlink changes\n"
+ " --dir-times Don't ignore directory time changes\n"
+ " -d|--domain guest Add disks from first libvirt guest\n"
+ " -D guest Add disks from second libvirt guest\n"
+ " --echo-keys Don't turn off echo for passphrases\n"
+ " --extra-stats Display extra stats\n"
+ " --format[=raw|..] Force disk format for -a or -A option\n"
+ " --help Display brief help\n"
+ " -h|--human-readable Human-readable sizes in output\n"
+ " --keys-from-stdin Read passphrases from stdin\n"
+ " --times Display file times\n"
+ " --time-days Display file times as days before now\n"
+ " --time-relative Display file times as seconds before now\n"
+ " --time-t Display file times as time_t's\n"
+ " --uids Display UID, GID\n"
+ " -v|--verbose Verbose messages\n"
+ " -V|--version Display version and exit\n"
+ " -x Trace libguestfs API calls\n"
+ " --xattrs Display extended attributes\n"
+ "For more information, see the manpage %s(1).\n"),
+ guestfs_int_program_name, guestfs_int_program_name,
+ guestfs_int_program_name, guestfs_int_program_name);
}
exit (status);
}
@@ -181,8 +183,8 @@ main (int argc, char *argv[])
{ "xattrs", 0, 0, 0 },
{ 0, 0, 0, 0 }
};
- struct drv *drvs = NULL; /* First guest. */
- struct drv *drvs2 = NULL; /* Second guest. */
+ struct drv *drvs = NULL; /* First guest. */
+ struct drv *drvs2 = NULL; /* Second guest. */
const char *format = NULL;
bool format_consumed = true;
int c;
@@ -199,66 +201,82 @@ main (int argc, char *argv[])
for (;;) {
c = getopt_long (argc, argv, options, long_options, &option_index);
- if (c == -1) break;
+ if (c == -1)
+ break;
switch (c) {
- case 0: /* options which are long only */
+ case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "long-options"))
display_long_options (long_options);
else if (STREQ (long_options[option_index].name, "short-options"))
display_short_options (options);
else if (STREQ (long_options[option_index].name, "keys-from-stdin")) {
keys_from_stdin = 1;
- } else if (STREQ (long_options[option_index].name, "echo-keys")) {
+ }
+ else if (STREQ (long_options[option_index].name, "echo-keys")) {
echo_keys = 1;
- } else if (STREQ (long_options[option_index].name, "format")) {
+ }
+ else if (STREQ (long_options[option_index].name, "format")) {
OPTION_format;
- } else if (STREQ (long_options[option_index].name, "all")) {
+ }
+ else if (STREQ (long_options[option_index].name, "all")) {
enable_extra_stats = enable_times = enable_uids = enable_xattrs = 1;
- } else if (STREQ (long_options[option_index].name, "atime")) {
+ }
+ else if (STREQ (long_options[option_index].name, "atime")) {
atime = 1;
- } else if (STREQ (long_options[option_index].name, "csv")) {
+ }
+ else if (STREQ (long_options[option_index].name, "csv")) {
csv = 1;
- } else if (STREQ (long_options[option_index].name, "checksum") ||
- STREQ (long_options[option_index].name, "checksums")) {
+ }
+ else if (STREQ (long_options[option_index].name, "checksum") ||
+ STREQ (long_options[option_index].name, "checksums")) {
if (!optarg || STREQ (optarg, ""))
checksum = "md5";
else
checksum = optarg;
- } else if (STREQ (long_options[option_index].name, "dir-link") ||
- STREQ (long_options[option_index].name, "dir-links") ||
- STREQ (long_options[option_index].name, "dir-nlink") ||
- STREQ (long_options[option_index].name, "dir-nlinks")) {
+ }
+ else if (STREQ (long_options[option_index].name, "dir-link") ||
+ STREQ (long_options[option_index].name, "dir-links") ||
+ STREQ (long_options[option_index].name, "dir-nlink") ||
+ STREQ (long_options[option_index].name, "dir-nlinks")) {
dir_links = 1;
- } else if (STREQ (long_options[option_index].name, "dir-time") ||
- STREQ (long_options[option_index].name, "dir-times")) {
+ }
+ else if (STREQ (long_options[option_index].name, "dir-time") ||
+ STREQ (long_options[option_index].name, "dir-times")) {
dir_times = 1;
- } else if (STREQ (long_options[option_index].name, "extra-stat") ||
- STREQ (long_options[option_index].name, "extra-stats")) {
+ }
+ else if (STREQ (long_options[option_index].name, "extra-stat") ||
+ STREQ (long_options[option_index].name, "extra-stats")) {
enable_extra_stats = 1;
- } else if (STREQ (long_options[option_index].name, "time") ||
- STREQ (long_options[option_index].name, "times")) {
+ }
+ else if (STREQ (long_options[option_index].name, "time") ||
+ STREQ (long_options[option_index].name, "times")) {
enable_times = 1;
- } else if (STREQ (long_options[option_index].name, "time-t")) {
+ }
+ else if (STREQ (long_options[option_index].name, "time-t")) {
enable_times = 1;
time_t_output = 1;
- } else if (STREQ (long_options[option_index].name, "time-relative")) {
+ }
+ else if (STREQ (long_options[option_index].name, "time-relative")) {
enable_times = 1;
time_t_output = 1;
time_relative = 1;
- } else if (STREQ (long_options[option_index].name, "time-days")) {
+ }
+ else if (STREQ (long_options[option_index].name, "time-days")) {
enable_times = 1;
time_t_output = 1;
time_relative = 2;
- } else if (STREQ (long_options[option_index].name, "uid") ||
- STREQ (long_options[option_index].name, "uids")) {
+ }
+ else if (STREQ (long_options[option_index].name, "uid") ||
+ STREQ (long_options[option_index].name, "uids")) {
enable_uids = 1;
- } else if (STREQ (long_options[option_index].name, "xattr") ||
- STREQ (long_options[option_index].name, "xattrs")) {
+ }
+ else if (STREQ (long_options[option_index].name, "xattr") ||
+ STREQ (long_options[option_index].name, "xattrs")) {
enable_xattrs = 1;
- } else
- error (EXIT_FAILURE, 0,
- _("unknown long option: %s (%d)"),
+ }
+ else
+ error (EXIT_FAILURE, 0, _("unknown long option: %s (%d)"),
long_options[option_index].name, option_index);
break;
@@ -312,9 +330,10 @@ main (int argc, char *argv[])
}
if (drvs == NULL || drvs2 == NULL) {
- fprintf (stderr,
- _("%s: you must specify some -a|-A|-d|-D options, see %s(1)\n"),
- guestfs_int_program_name, guestfs_int_program_name);
+ fprintf (
+ stderr,
+ _("%s: you must specify some -a|-A|-d|-D options, see %s(1)\n"),
+ guestfs_int_program_name, guestfs_int_program_name);
usage (EXIT_FAILURE);
}
@@ -322,7 +341,8 @@ main (int argc, char *argv[])
* fields correctly. (RHBZ#600977).
*/
if (human && csv)
- error (EXIT_FAILURE, 0, _("you cannot use -h and --csv options
together."));
+ error (EXIT_FAILURE, 0,
+ _("you cannot use -h and --csv options together."));
if (optind != argc)
error (EXIT_FAILURE, 0, _("extra arguments on the command line"));
@@ -393,7 +413,7 @@ struct file {
char *path;
struct guestfs_statns *stat;
struct guestfs_xattr_list *xattrs;
- char *csum; /* Checksum. If NULL, use file times and size. */
+ char *csum; /* Checksum. If NULL, use file times and size. */
};
static void
@@ -413,7 +433,9 @@ free_tree (struct tree *t)
free (t);
}
-static int visit_entry (const char *dir, const char *name, const struct guestfs_statns
*stat, const struct guestfs_xattr_list *xattrs, void *vt);
+static int visit_entry (const char *dir, const char *name,
+ const struct guestfs_statns *stat,
+ const struct guestfs_xattr_list *xattrs, void *vt);
static struct tree *
visit_guest (guestfs_h *g)
@@ -448,8 +470,7 @@ visit_guest (guestfs_h *g)
static int
visit_entry (const char *dir, const char *name,
const struct guestfs_statns *stat_orig,
- const struct guestfs_xattr_list *xattrs_orig,
- void *vt)
+ const struct guestfs_xattr_list *xattrs_orig, void *vt)
{
struct tree *t = vt;
char *path = NULL, *csum = NULL;
@@ -526,7 +547,7 @@ visit_entry (const char *dir, const char *name,
return 0;
- error:
+error:
free (path);
free (csum);
guestfs_free_statns (stat);
@@ -537,7 +558,8 @@ visit_entry (const char *dir, const char *name,
static void deleted (guestfs_h *, struct file *);
static void added (guestfs_h *, struct file *);
static int compare_stats (struct file *, struct file *);
-static void changed (guestfs_h *, struct file *, guestfs_h *, struct file *, int st, int
cst);
+static void changed (guestfs_h *, struct file *, guestfs_h *, struct file *,
+ int st, int cst);
static void diff (struct file *, guestfs_h *, struct file *, guestfs_h *);
static void output_file (guestfs_h *, struct file *);
@@ -628,9 +650,8 @@ compare_stats (struct file *file1, struct file *file2)
}
static void
-changed (guestfs_h *g1, struct file *file1,
- guestfs_h *g2, struct file *file2,
- int st, int cst)
+changed (guestfs_h *g1, struct file *file1, guestfs_h *g2,
+ struct file *file2, int st, int cst)
{
/* Did file content change? */
if (cst != 0 ||
@@ -665,8 +686,9 @@ changed (guestfs_h *g1, struct file *file1,
output_start_line ();
output_string ("#");
output_string ("changed:");
-#define COMPARE_STAT(n) \
- if (file1->stat->n != file2->stat->n) output_string (#n)
+#define COMPARE_STAT(n) \
+ if (file1->stat->n != file2->stat->n) \
+ output_string (#n)
COMPARE_STAT (st_dev);
COMPARE_STAT (st_ino);
COMPARE_STAT (st_mode);
@@ -722,13 +744,14 @@ diff (struct file *file1, guestfs_h *g1, struct file *file2,
guestfs_h *g2)
fprintf (stderr, "%s\n", cmd);
r = system (cmd);
if (!WIFEXITED (r) || WEXITSTATUS (r) != 0) {
- fprintf (stderr, _("%s: external diff command failed\n"),
guestfs_int_program_name);
+ fprintf (stderr, _("%s: external diff command failed\n"),
+ guestfs_int_program_name);
goto out;
}
printf ("@@ %s @@\n", _("End of diff"));
- out:
+out:
unlink (tmpda);
unlink (tmpdb);
rmdir (tmpd);
@@ -771,7 +794,8 @@ output_file (guestfs_h *g, struct file *file)
if (enable_times) {
if (atime)
- output_int64_time (file->stat->st_atime_sec,
file->stat->st_atime_nsec);
+ output_int64_time (file->stat->st_atime_sec,
+ file->stat->st_atime_nsec);
output_int64_time (file->stat->st_mtime_sec, file->stat->st_mtime_nsec);
output_int64_time (file->stat->st_ctime_sec, file->stat->st_ctime_nsec);
}
@@ -817,7 +841,8 @@ next_field (void)
int c = csv ? ',' : ' ';
field++;
- if (field == 1) return;
+ if (field == 1)
+ return;
if (putchar (c) == EOF)
error (EXIT_FAILURE, errno, "putchar");
@@ -861,8 +886,7 @@ output_string (const char *s)
len = strlen (s);
for (i = 0; i < len; ++i) {
- if (s[i] == ' ' || s[i] == '"' ||
- s[i] == '\n' || s[i] == ',') {
+ if (s[i] == ' ' || s[i] == '"' || s[i] == '\n' || s[i]
== ',') {
needs_quoting = 1;
break;
}
@@ -878,7 +902,8 @@ output_string (const char *s)
if (s[i] == '"') {
if (putchar ('"') == EOF || putchar ('"') == EOF)
error (EXIT_FAILURE, errno, "putchar");
- } else {
+ }
+ else {
if (putchar (s[i]) == EOF)
error (EXIT_FAILURE, errno, "putchar");
}
@@ -914,8 +939,9 @@ output_binary (const char *s, size_t len)
if (c_isprint (s[i])) {
if (putchar (s[i]) == EOF)
error (EXIT_FAILURE, errno, "putchar");
- } else {
- if (printf ("\\x%02x", (unsigned char) s[i]) < 0)
+ }
+ else {
+ if (printf ("\\x%02x", (unsigned char)s[i]) < 0)
error (EXIT_FAILURE, errno, "putchar");
}
}
@@ -925,8 +951,8 @@ output_binary (const char *s, size_t len)
int needs_quoting = 0;
for (i = 0; i < len; ++i) {
- if (!c_isprint (s[i]) || s[i] == ' ' || s[i] == '"' ||
- s[i] == '\n' || s[i] == ',') {
+ if (!c_isprint (s[i]) || s[i] == ' ' || s[i] == '"' || s[i] ==
'\n' ||
+ s[i] == ',') {
needs_quoting = 1;
break;
}
@@ -942,12 +968,14 @@ output_binary (const char *s, size_t len)
if (s[i] == '"') {
if (putchar ('"') == EOF || putchar ('"') == EOF)
error (EXIT_FAILURE, errno, "putchar");
- } else {
+ }
+ else {
if (c_isprint (s[i])) {
if (putchar (s[i]) == EOF)
error (EXIT_FAILURE, errno, "putchar");
- } else {
- if (printf ("\\x%2x", (unsigned) s[i]) < 0)
+ }
+ else {
+ if (printf ("\\x%2x", (unsigned)s[i]) < 0)
error (EXIT_FAILURE, errno, "printf");
}
}
@@ -970,7 +998,8 @@ static void
output_int64_size (int64_t size)
{
char buf[LONGEST_HUMAN_READABLE];
- int hopts = human_round_to_nearest|human_autoscale|human_base_1024|human_SI;
+ int hopts =
+ human_round_to_nearest | human_autoscale | human_base_1024 | human_SI;
int r;
next_field ();
@@ -979,15 +1008,15 @@ output_int64_size (int64_t size)
if (!human)
r = printf ("%10" PRIi64, size);
else
- r = printf ("%10s",
- human_readable ((uintmax_t) size, buf, hopts, 1, 1));
- } else {
+ r =
+ printf ("%10s", human_readable ((uintmax_t)size, buf, hopts, 1, 1));
+ }
+ else {
/* CSV is the same as non-CSV but we don't need to right-align. */
if (!human)
r = printf ("%" PRIi64, size);
else
- r = printf ("%s",
- human_readable ((uintmax_t) size, buf, hopts, 1, 1));
+ r = printf ("%s", human_readable ((uintmax_t)size, buf, hopts, 1, 1));
}
if (r < 0)
@@ -999,7 +1028,7 @@ output_int64_perms (int64_t i)
{
next_field ();
/* csv doesn't need escaping */
- if (printf ("%04" PRIo64, (uint64_t) i) < 0)
+ if (printf ("%04" PRIo64, (uint64_t)i) < 0)
error (EXIT_FAILURE, errno, "printf");
}
@@ -1013,20 +1042,20 @@ output_int64_time (int64_t secs, int64_t nsecs)
/* csv doesn't need escaping */
if (time_t_output) {
switch (time_relative) {
- case 0: /* --time-t */
+ case 0: /* --time-t */
r = printf ("%10" PRIi64, secs);
break;
- case 1: /* --time-relative */
+ case 1: /* --time-relative */
r = printf ("%8" PRIi64, now - secs);
break;
- case 2: /* --time-days */
+ case 2: /* --time-days */
default:
r = printf ("%3" PRIi64, (now - secs) / 86400);
break;
}
}
else {
- time_t t = (time_t) secs;
+ time_t t = (time_t)secs;
char buf[64];
struct tm *tm;
@@ -1061,7 +1090,7 @@ output_int64_dev (int64_t i)
next_field ();
/* csv doesn't need escaping */
- if (printf ("%ju:%ju",
- (uintmax_t) major (dev), (uintmax_t) minor (dev)) < 0)
+ if (printf ("%ju:%ju", (uintmax_t)major (dev), (uintmax_t)minor (dev)) <
+ 0)
error (EXIT_FAILURE, errno, "printf");
}
diff --git a/edit/edit.c b/edit/edit.c
index 6e7aee4..9e55957 100644
--- a/edit/edit.c
+++ b/edit/edit.c
@@ -64,29 +64,30 @@ usage (int status)
fprintf (stderr, _("Try `%s --help' for more information.\n"),
guestfs_int_program_name);
else {
- printf (_("%s: Edit a file in a virtual machine\n"
- "Copyright (C) 2009-2016 Red Hat Inc.\n"
- "Usage:\n"
- " %s [--options] -d domname file [file ...]\n"
- " %s [--options] -a disk.img [-a disk.img ...] file [file
...]\n"
- "Options:\n"
- " -a|--add image Add image\n"
- " -b|--backup .ext Backup original as original.ext\n"
- " -c|--connect uri Specify libvirt URI for -d option\n"
- " -d|--domain guest Add disks from libvirt guest\n"
- " --echo-keys Don't turn off echo for
passphrases\n"
- " -e|--expr expr Non-interactive editing using Perl
expr\n"
- " --format[=raw|..] Force disk format for -a option\n"
- " --help Display brief help\n"
- " --keys-from-stdin Read passphrases from stdin\n"
- " -m|--mount dev[:mnt[:opts[:fstype]]]\n"
- " Mount dev on mnt (if omitted, /)\n"
- " -v|--verbose Verbose messages\n"
- " -V|--version Display version and exit\n"
- " -x Trace libguestfs API calls\n"
- "For more information, see the manpage %s(1).\n"),
- guestfs_int_program_name, guestfs_int_program_name,
- guestfs_int_program_name, guestfs_int_program_name);
+ printf (
+ _("%s: Edit a file in a virtual machine\n"
+ "Copyright (C) 2009-2016 Red Hat Inc.\n"
+ "Usage:\n"
+ " %s [--options] -d domname file [file ...]\n"
+ " %s [--options] -a disk.img [-a disk.img ...] file [file ...]\n"
+ "Options:\n"
+ " -a|--add image Add image\n"
+ " -b|--backup .ext Backup original as original.ext\n"
+ " -c|--connect uri Specify libvirt URI for -d option\n"
+ " -d|--domain guest Add disks from libvirt guest\n"
+ " --echo-keys Don't turn off echo for passphrases\n"
+ " -e|--expr expr Non-interactive editing using Perl expr\n"
+ " --format[=raw|..] Force disk format for -a option\n"
+ " --help Display brief help\n"
+ " --keys-from-stdin Read passphrases from stdin\n"
+ " -m|--mount dev[:mnt[:opts[:fstype]]]\n"
+ " Mount dev on mnt (if omitted, /)\n"
+ " -v|--verbose Verbose messages\n"
+ " -V|--version Display version and exit\n"
+ " -x Trace libguestfs API calls\n"
+ "For more information, see the manpage %s(1).\n"),
+ guestfs_int_program_name, guestfs_int_program_name,
+ guestfs_int_program_name, guestfs_int_program_name);
}
exit (status);
}
@@ -105,22 +106,14 @@ main (int argc, char *argv[])
static const char *options = "a:b:c:d:e:m:vVx";
static const struct option long_options[] = {
- { "add", 1, 0, 'a' },
- { "backup", 1, 0, 'b' },
- { "connect", 1, 0, 'c' },
- { "domain", 1, 0, 'd' },
- { "echo-keys", 0, 0, 0 },
- { "edit", 1, 0, 'e' },
- { "expr", 1, 0, 'e' },
- { "format", 2, 0, 0 },
- { "help", 0, 0, HELP_OPTION },
- { "keys-from-stdin", 0, 0, 0 },
- { "long-options", 0, 0, 0 },
- { "mount", 1, 0, 'm' },
- { "short-options", 0, 0, 0 },
- { "verbose", 0, 0, 'v' },
- { "version", 0, 0, 'V' },
- { 0, 0, 0, 0 }
+ { "add", 1, 0, 'a' }, { "backup", 1, 0,
'b' },
+ { "connect", 1, 0, 'c' }, { "domain", 1, 0,
'd' },
+ { "echo-keys", 0, 0, 0 }, { "edit", 1, 0, 'e' },
+ { "expr", 1, 0, 'e' }, { "format", 2, 0, 0 },
+ { "help", 0, 0, HELP_OPTION }, { "keys-from-stdin", 0, 0, 0 },
+ { "long-options", 0, 0, 0 }, { "mount", 1, 0, 'm' },
+ { "short-options", 0, 0, 0 }, { "verbose", 0, 0, 'v' },
+ { "version", 0, 0, 'V' }, { 0, 0, 0, 0 }
};
struct drv *drvs = NULL;
struct drv *drv;
@@ -138,23 +131,26 @@ main (int argc, char *argv[])
for (;;) {
c = getopt_long (argc, argv, options, long_options, &option_index);
- if (c == -1) break;
+ if (c == -1)
+ break;
switch (c) {
- case 0: /* options which are long only */
+ case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "long-options"))
display_long_options (long_options);
else if (STREQ (long_options[option_index].name, "short-options"))
display_short_options (options);
else if (STREQ (long_options[option_index].name, "keys-from-stdin")) {
keys_from_stdin = 1;
- } else if (STREQ (long_options[option_index].name, "echo-keys")) {
+ }
+ else if (STREQ (long_options[option_index].name, "echo-keys")) {
echo_keys = 1;
- } else if (STREQ (long_options[option_index].name, "format")) {
+ }
+ else if (STREQ (long_options[option_index].name, "format")) {
OPTION_format;
- } else
- error (EXIT_FAILURE, 0,
- _("unknown long option: %s (%d)"),
+ }
+ else
+ error (EXIT_FAILURE, 0, _("unknown long option: %s (%d)"),
long_options[option_index].name, option_index);
break;
@@ -224,7 +220,8 @@ main (int argc, char *argv[])
error (EXIT_FAILURE, errno, "strdup");
drv->next = drvs;
drvs = drv;
- } else { /* simulate -d option */
+ }
+ else { /* simulate -d option */
drv = calloc (1, sizeof (struct drv));
if (!drv)
error (EXIT_FAILURE, errno, "calloc");
@@ -312,15 +309,16 @@ edit (const char *filename, const char *root)
/* Windows? Special handling is required. */
if (root != NULL && is_windows (g, root)) {
- filename = filename_to_free = windows_path (g, root, filename,
- 0 /* not read only */);
+ filename = filename_to_free =
+ windows_path (g, root, filename, 0 /* not read only */);
if (filename == NULL)
exit (EXIT_FAILURE);
}
if (perl_expr != NULL) {
r = edit_file_perl (g, filename, perl_expr, backup_extension, verbose);
- } else
+ }
+ else
r = edit_file_editor (g, filename, NULL /* use $EDITOR */,
backup_extension, verbose);
diff --git a/erlang/erl-guestfs-proto.c b/erlang/erl-guestfs-proto.c
index 24295ef..7c93541 100644
--- a/erlang/erl-guestfs-proto.c
+++ b/erlang/erl-guestfs-proto.c
@@ -56,7 +56,7 @@ extern int64_t get_int64 (ETERM *term);
/* This stops things getting out of hand, but also lets us detect
* protocol problems quickly.
*/
-#define MAX_MESSAGE_SIZE (32*1024*1024)
+#define MAX_MESSAGE_SIZE (32 * 1024 * 1024)
static unsigned char *read_message (void);
static void write_reply (ETERM *);
@@ -165,7 +165,8 @@ atom_equals (ETERM *atom, const char *name)
{
size_t namelen = strlen (name);
size_t atomlen = ERL_ATOM_SIZE (atom);
- if (namelen != atomlen) return 0;
+ if (namelen != atomlen)
+ return 0;
return strncmp (ERL_ATOM_PTR (atom), name, atomlen) == 0;
}
@@ -229,17 +230,17 @@ make_table (char **r)
for (size = 0; r[size] != NULL; ++size)
;
- t = malloc (sizeof (ETERM *) * (size/2));
+ t = malloc (sizeof (ETERM *) * (size / 2));
if (t == NULL)
return make_error ("make_table");
for (i = 0; r[i] != NULL; i += 2) {
a[0] = erl_mk_string (r[i]);
- a[1] = erl_mk_string (r[i+1]);
- t[i/2] = erl_mk_tuple (a, 2);
+ a[1] = erl_mk_string (r[i + 1]);
+ t[i / 2] = erl_mk_tuple (a, 2);
}
- return erl_mk_list (t, size/2);
+ return erl_mk_list (t, size / 2);
}
ETERM *
@@ -262,7 +263,7 @@ get_string_list (ETERM *term)
size++, t = ERL_CONS_TAIL (t))
;
- r = malloc ((size+1) * sizeof (char *));
+ r = malloc ((size + 1) * sizeof (char *));
if (r == NULL)
error (EXIT_FAILURE, errno, "malloc");
@@ -289,13 +290,13 @@ get_int (ETERM *term)
case ERL_INTEGER:
return ERL_INT_VALUE (term);
case ERL_U_INTEGER:
- return (int) ERL_INT_UVALUE (term);
+ return (int)ERL_INT_UVALUE (term);
case ERL_LONGLONG:
/* XXX check for overflow */
- return (int) ERL_LL_VALUE (term);
+ return (int)ERL_LL_VALUE (term);
case ERL_U_LONGLONG:
/* XXX check for overflow */
- return (int) ERL_LL_UVALUE (term);
+ return (int)ERL_LL_UVALUE (term);
default:
/* XXX fail in some way */
return -1;
@@ -313,7 +314,7 @@ get_int64 (ETERM *term)
case ERL_LONGLONG:
return ERL_LL_VALUE (term);
case ERL_U_LONGLONG:
- return (int64_t) ERL_LL_UVALUE (term);
+ return (int64_t)ERL_LL_UVALUE (term);
default:
/* XXX fail in some way */
return -1;
diff --git a/examples/copy-over.c b/examples/copy-over.c
index d92a4d2..7cec118 100644
--- a/examples/copy-over.c
+++ b/examples/copy-over.c
@@ -31,25 +31,27 @@ struct threaddata {
static void *start_srcthread (void *);
static int open_guest (guestfs_h *g, const char *dom, int readonly);
-static int64_t timeval_diff (const struct timeval *x, const struct timeval *y);
+static int64_t timeval_diff (const struct timeval *x,
+ const struct timeval *y);
static int compare_keys_len (const void *p1, const void *p2);
static size_t count_strings (char *const *argv);
static void
usage (void)
{
- fprintf (stderr,
- "Usage: copy-over source srcdir dest destdir\n"
- "\n"
- " source : the source domain (a libvirt guest name)\n"
- " srcdir : the directory to copy from the source guest\n"
- " dest : the destination domain (a libvirt guest name)\n"
- " destdir : the destination directory (must exist at destination)\n"
- "\n"
- "eg: copy-over Src /home/rjones Dest /tmp/dir\n"
- "would copy /home/rjones from Src to /tmp/dir on Dest\n"
- "\n"
- "The destination guest cannot be running.\n");
+ fprintf (
+ stderr,
+ "Usage: copy-over source srcdir dest destdir\n"
+ "\n"
+ " source : the source domain (a libvirt guest name)\n"
+ " srcdir : the directory to copy from the source guest\n"
+ " dest : the destination domain (a libvirt guest name)\n"
+ " destdir : the destination directory (must exist at destination)\n"
+ "\n"
+ "eg: copy-over Src /home/rjones Dest /tmp/dir\n"
+ "would copy /home/rjones from Src to /tmp/dir on Dest\n"
+ "\n"
+ "The destination guest cannot be running.\n");
}
int
@@ -205,8 +207,7 @@ open_guest (guestfs_h *g, const char *dom, int readonly)
size_t i;
/* Use libvirt to find the guest disks and add them to the handle. */
- if (guestfs_add_domain (g, dom,
- GUESTFS_ADD_DOMAIN_READONLY, readonly,
+ if (guestfs_add_domain (g, dom, GUESTFS_ADD_DOMAIN_READONLY, readonly,
-1) == -1)
return -1;
@@ -219,7 +220,9 @@ open_guest (guestfs_h *g, const char *dom, int readonly)
return -1;
if (roots[0] == NULL || roots[1] != NULL) {
- fprintf (stderr, "copy-over: %s: no operating systems or multiple operating
systems found\n", dom);
+ fprintf (stderr, "copy-over: %s: no operating systems or multiple "
+ "operating systems found\n",
+ dom);
return -1;
}
@@ -236,10 +239,10 @@ open_guest (guestfs_h *g, const char *dom, int readonly)
/* Ignore failures from this call, since bogus entries can
* appear in the guest's /etc/fstab.
*/
- (readonly ? guestfs_mount_ro : guestfs_mount)
- (g, mountpoints[i+1], mountpoints[i]);
+ (readonly ? guestfs_mount_ro : guestfs_mount) (g, mountpoints[i + 1],
+ mountpoints[i]);
free (mountpoints[i]);
- free (mountpoints[i+1]);
+ free (mountpoints[i + 1]);
}
free (mountpoints);
@@ -268,8 +271,8 @@ timeval_diff (const struct timeval *x, const struct timeval *y)
static int
compare_keys_len (const void *p1, const void *p2)
{
- const char *key1 = * (char * const *) p1;
- const char *key2 = * (char * const *) p2;
+ const char *key1 = *(char *const *)p1;
+ const char *key2 = *(char *const *)p2;
return strlen (key1) - strlen (key2);
}
diff --git a/examples/create-disk.c b/examples/create-disk.c
index 81e4dbd..ff5c83c 100644
--- a/examples/create-disk.c
+++ b/examples/create-disk.c
@@ -23,15 +23,16 @@ main (int argc, char *argv[])
guestfs_set_trace (g, 1);
/* Create a raw-format sparse disk image, 512 MB in size. */
- if (guestfs_disk_create (g, "disk.img", "raw",
UINT64_C(512)*1024*1024,
- -1) == -1)
+ if (guestfs_disk_create (g, "disk.img", "raw",
+ UINT64_C (512) * 1024 * 1024, -1) == -1)
exit (EXIT_FAILURE);
/* Add the disk image to libguestfs. */
- if (guestfs_add_drive_opts (g, "disk.img",
- GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw", /* raw format */
- GUESTFS_ADD_DRIVE_OPTS_READONLY, 0, /* for write */
- -1) /* this marks end of optional arguments */
+ if (guestfs_add_drive_opts (g, "disk.img", GUESTFS_ADD_DRIVE_OPTS_FORMAT,
+ "raw", /* raw format */
+ GUESTFS_ADD_DRIVE_OPTS_READONLY,
+ 0, /* for write */
+ -1) /* this marks end of optional arguments */
== -1)
exit (EXIT_FAILURE);
@@ -62,7 +63,8 @@ main (int argc, char *argv[])
if (partitions == NULL)
exit (EXIT_FAILURE);
if (partitions[0] == NULL || partitions[1] != NULL) {
- fprintf (stderr, "error: expected a single partition from
list-partitions\n");
+ fprintf (stderr,
+ "error: expected a single partition from list-partitions\n");
exit (EXIT_FAILURE);
}
diff --git a/examples/debug-logging.c b/examples/debug-logging.c
index 755e69b..754ce74 100644
--- a/examples/debug-logging.c
+++ b/examples/debug-logging.c
@@ -11,15 +11,16 @@
#include <syslog.h>
#include <guestfs.h>
-static void message_callback (guestfs_h *g, void *opaque, uint64_t event, int
event_handle, int flags, const char *buf, size_t buf_len, const uint64_t *array, size_t
array_len);
+static void message_callback (guestfs_h *g, void *opaque, uint64_t event,
+ int event_handle, int flags, const char *buf,
+ size_t buf_len, const uint64_t *array,
+ size_t array_len);
/* Events we are interested in. This bitmask covers all trace and
* debug messages.
*/
static const uint64_t event_bitmask =
- GUESTFS_EVENT_LIBRARY |
- GUESTFS_EVENT_WARNING |
- GUESTFS_EVENT_APPLIANCE |
+ GUESTFS_EVENT_LIBRARY | GUESTFS_EVENT_WARNING | GUESTFS_EVENT_APPLIANCE |
GUESTFS_EVENT_TRACE;
int
@@ -40,8 +41,8 @@ main (int argc, char *argv[])
*
* For more information see EVENTS in guestfs(3).
*/
- if (guestfs_set_event_callback (g, message_callback,
- event_bitmask, 0, NULL) == -1)
+ if (guestfs_set_event_callback (g, message_callback, event_bitmask, 0,
+ NULL) == -1)
exit (EXIT_FAILURE);
/* This is how debugging is enabled:
@@ -97,13 +98,11 @@ main (int argc, char *argv[])
* obviously you could do something more advanced here.
*/
static void
-message_callback (guestfs_h *g, void *opaque,
- uint64_t event, int event_handle,
- int flags,
- const char *buf, size_t buf_len,
- const uint64_t *array, size_t array_len)
+message_callback (guestfs_h *g, void *opaque, uint64_t event,
+ int event_handle, int flags, const char *buf,
+ size_t buf_len, const uint64_t *array, size_t array_len)
{
- const int priority = LOG_USER|LOG_INFO;
+ const int priority = LOG_USER | LOG_INFO;
char *event_name, *msg;
if (buf_len > 0) {
diff --git a/examples/display-icon.c b/examples/display-icon.c
index b408364..ef7ace1 100644
--- a/examples/display-icon.c
+++ b/examples/display-icon.c
@@ -11,8 +11,8 @@
static int
compare_keys_len (const void *p1, const void *p2)
{
- const char *key1 = * (char * const *) p1;
- const char *key2 = * (char * const *) p2;
+ const char *key1 = *(char *const *)p1;
+ const char *key2 = *(char *const *)p2;
return strlen (key1) - strlen (key2);
}
@@ -49,9 +49,9 @@ main (int argc, char *argv[])
/* Attach the disk image read-only to libguestfs. */
if (guestfs_add_drive_opts (g, disk,
- /* GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw", */
- GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,
- -1) /* this marks end of optional arguments */
+ /* GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw", */
+ GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,
+ -1) /* this marks end of optional arguments */
== -1)
exit (EXIT_FAILURE);
@@ -80,15 +80,15 @@ main (int argc, char *argv[])
if (mountpoints == NULL)
exit (EXIT_FAILURE);
- qsort (mountpoints, count_strings (mountpoints) / 2, 2 * sizeof (char *),
- compare_keys_len);
+ qsort (mountpoints, count_strings (mountpoints) / 2,
+ 2 * sizeof (char *), compare_keys_len);
for (i = 0; mountpoints[i] != NULL; i += 2) {
/* Ignore failures from this call, since bogus entries can
* appear in the guest's /etc/fstab.
*/
- guestfs_mount_ro (g, mountpoints[i+1], mountpoints[i]);
+ guestfs_mount_ro (g, mountpoints[i + 1], mountpoints[i]);
free (mountpoints[i]);
- free (mountpoints[i+1]);
+ free (mountpoints[i + 1]);
}
free (mountpoints);
@@ -99,10 +99,11 @@ main (int argc, char *argv[])
* was an error.
*/
icon = guestfs_inspect_get_icon (g, root, &icon_size, -1);
- if (!icon) /* actual libguestfs error */
+ if (!icon) /* actual libguestfs error */
exit (EXIT_FAILURE);
- if (icon_size == 0) /* no icon available */
- fprintf (stderr, "%s: %s: no icon available for this operating
system\n",
+ if (icon_size == 0) /* no icon available */
+ fprintf (stderr,
+ "%s: %s: no icon available for this operating system\n",
disk, root);
else {
/* Display the icon. */
diff --git a/examples/inspect-vm.c b/examples/inspect-vm.c
index 50fe49a..6a415ed 100644
--- a/examples/inspect-vm.c
+++ b/examples/inspect-vm.c
@@ -8,8 +8,8 @@
static int
compare_keys_len (const void *p1, const void *p2)
{
- const char *key1 = * (char * const *) p1;
- const char *key2 = * (char * const *) p2;
+ const char *key1 = *(char *const *)p1;
+ const char *key2 = *(char *const *)p2;
return strlen (key1) - strlen (key2);
}
@@ -45,9 +45,9 @@ main (int argc, char *argv[])
/* Attach the disk image read-only to libguestfs. */
if (guestfs_add_drive_opts (g, disk,
- /* GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw", */
- GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,
- -1) /* this marks end of optional arguments */
+ /* GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw", */
+ GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,
+ -1) /* this marks end of optional arguments */
== -1)
exit (EXIT_FAILURE);
@@ -97,15 +97,15 @@ main (int argc, char *argv[])
if (mountpoints == NULL)
exit (EXIT_FAILURE);
- qsort (mountpoints, count_strings (mountpoints) / 2, 2 * sizeof (char *),
- compare_keys_len);
+ qsort (mountpoints, count_strings (mountpoints) / 2,
+ 2 * sizeof (char *), compare_keys_len);
for (i = 0; mountpoints[i] != NULL; i += 2) {
/* Ignore failures from this call, since bogus entries can
* appear in the guest's /etc/fstab.
*/
- guestfs_mount_ro (g, mountpoints[i+1], mountpoints[i]);
+ guestfs_mount_ro (g, mountpoints[i + 1], mountpoints[i]);
free (mountpoints[i]);
- free (mountpoints[i+1]);
+ free (mountpoints[i + 1]);
}
free (mountpoints);
diff --git a/examples/libvirt-auth.c b/examples/libvirt-auth.c
index 12825f4..6ca1509 100644
--- a/examples/libvirt-auth.c
+++ b/examples/libvirt-auth.c
@@ -13,37 +13,43 @@
static void
usage (void)
{
- fprintf (stderr,
- "Usage:\n"
- "\n"
- " libvirt-auth URI domain\n"
- "\n"
- "where:\n"
- "\n"
- " URI is the libvirt URI, eg. qemu+libssh2://USER@localhost/system\n"
- " domain is the name of the guest\n"
- "\n"
- "Example:\n"
- "\n"
- " libvirt-auth 'qemu+libssh2://USER@localhost/system'
'foo'\n"
- "\n"
- "would connect (read-only) to libvirt URI given and open the guest\n"
- "called 'foo' and list some information about its filesystems.\n"
- "\n"
- "The important point of this example is that any libvirt authentication\n"
- "required to connect to the server should be done.\n"
- "\n");
+ fprintf (
+ stderr,
+ "Usage:\n"
+ "\n"
+ " libvirt-auth URI domain\n"
+ "\n"
+ "where:\n"
+ "\n"
+ " URI is the libvirt URI, eg. "
+ "qemu+libssh2://USER@localhost/system\n"
+ " domain is the name of the guest\n"
+ "\n"
+ "Example:\n"
+ "\n"
+ " libvirt-auth 'qemu+libssh2://USER@localhost/system'
'foo'\n"
+ "\n"
+ "would connect (read-only) to libvirt URI given and open the guest\n"
+ "called 'foo' and list some information about its filesystems.\n"
+ "\n"
+ "The important point of this example is that any libvirt "
+ "authentication\n"
+ "required to connect to the server should be done.\n"
+ "\n");
}
-static void auth_callback (guestfs_h *g, void *opaque, uint64_t event, int event_handle,
int flags, const char *buf, size_t buf_len, const uint64_t *array, size_t array_len);
+static void auth_callback (guestfs_h *g, void *opaque, uint64_t event,
+ int event_handle, int flags, const char *buf,
+ size_t buf_len, const uint64_t *array,
+ size_t array_len);
int
main (int argc, char *argv[])
{
const char *uri, *dom;
guestfs_h *g;
- const char *creds[] = { "authname", "passphrase",
- "echoprompt", "noechoprompt", NULL };
+ const char *creds[] = { "authname", "passphrase",
"echoprompt",
+ "noechoprompt", NULL };
int r, eh;
char **filesystems;
size_t i;
@@ -59,7 +65,7 @@ main (int argc, char *argv[])
if (!g)
exit (EXIT_FAILURE);
- r = guestfs_set_libvirt_supported_credentials (g, (char **) creds);
+ r = guestfs_set_libvirt_supported_credentials (g, (char **)creds);
if (r == -1)
exit (EXIT_FAILURE);
@@ -70,9 +76,7 @@ main (int argc, char *argv[])
exit (EXIT_FAILURE);
/* Add the named domain. */
- r = guestfs_add_domain (g, dom,
- GUESTFS_ADD_DOMAIN_LIBVIRTURI, uri,
- -1);
+ r = guestfs_add_domain (g, dom, GUESTFS_ADD_DOMAIN_LIBVIRTURI, uri, -1);
if (r == -1)
exit (EXIT_FAILURE);
@@ -86,10 +90,10 @@ main (int argc, char *argv[])
exit (EXIT_FAILURE);
for (i = 0; filesystems[i] != NULL; i += 2) {
- printf ("%s:%s is a %s filesystem\n",
- dom, filesystems[i], filesystems[i+1]);
+ printf ("%s:%s is a %s filesystem\n", dom, filesystems[i],
+ filesystems[i + 1]);
free (filesystems[i]);
- free (filesystems[i+1]);
+ free (filesystems[i + 1]);
}
free (filesystems);
@@ -97,12 +101,8 @@ main (int argc, char *argv[])
}
static void
-auth_callback (guestfs_h *g,
- void *opaque,
- uint64_t event,
- int event_handle,
- int flags,
- const char *buf, size_t buf_len,
+auth_callback (guestfs_h *g, void *opaque, uint64_t event, int event_handle,
+ int flags, const char *buf, size_t buf_len,
const uint64_t *array, size_t array_len)
{
char **creds;
@@ -114,8 +114,9 @@ auth_callback (guestfs_h *g,
ssize_t len;
int r;
- printf ("libvirt-auth.c: authentication required for libvirt URI
'%s'\n\n",
- buf);
+ printf (
+ "libvirt-auth.c: authentication required for libvirt URI
'%s'\n\n",
+ buf);
/* Ask libguestfs what credentials libvirt is demanding. */
creds = guestfs_get_libvirt_requested_credentials (g);
@@ -123,8 +124,7 @@ auth_callback (guestfs_h *g,
exit (EXIT_FAILURE);
/* Now ask the user for answers. */
- for (i = 0; creds[i] != NULL; ++i)
- {
+ for (i = 0; creds[i] != NULL; ++i) {
printf ("libvirt-auth.c: credential '%s'\n", creds[i]);
if (strcmp (creds[i], "authname") == 0 ||
@@ -139,14 +139,15 @@ auth_callback (guestfs_h *g,
perror ("getline");
exit (EXIT_FAILURE);
}
- if (len > 0 && reply[len-1] == '\n')
+ if (len > 0 && reply[len - 1] == '\n')
reply[--len] = '\0';
r = guestfs_set_libvirt_requested_credential (g, i, reply, len);
if (r == -1)
exit (EXIT_FAILURE);
- } else if (strcmp (creds[i], "passphrase") == 0 ||
- strcmp (creds[i], "noechoprompt") == 0) {
+ }
+ else if (strcmp (creds[i], "passphrase") == 0 ||
+ strcmp (creds[i], "noechoprompt") == 0) {
prompt = guestfs_get_libvirt_requested_credential_prompt (g, i);
if (prompt && strcmp (prompt, "") != 0)
printf ("%s: ", prompt);
diff --git a/examples/mount-local.c b/examples/mount-local.c
index ce12ffe..d90d07d 100644
--- a/examples/mount-local.c
+++ b/examples/mount-local.c
@@ -32,11 +32,10 @@
static void
usage (void)
{
- fprintf (stderr,
- "Usage: mount-local disk.img\n"
- "\n"
- "NOTE: disk.img will be created or overwritten.\n"
- "\n");
+ fprintf (stderr, "Usage: mount-local disk.img\n"
+ "\n"
+ "NOTE: disk.img will be created or overwritten.\n"
+ "\n");
}
int
@@ -58,11 +57,12 @@ main (int argc, char *argv[])
exit (EXIT_FAILURE);
}
- printf ("\n"
- "This is the 'mount-local' demonstration program. Follow
the\n"
- "instructions on screen.\n"
- "\n"
- "Creating and formatting the disk image, please wait a moment
...\n");
+ printf (
+ "\n"
+ "This is the 'mount-local' demonstration program. Follow the\n"
+ "instructions on screen.\n"
+ "\n"
+ "Creating and formatting the disk image, please wait a moment ...\n");
fflush (stdout);
/* Guestfs handle. */
@@ -73,13 +73,14 @@ main (int argc, char *argv[])
}
/* Create the output disk image: raw sparse. */
- if (guestfs_disk_create (g, argv[1], "raw", SIZE_MB * 1024 * 1024, -1) ==
-1)
+ if (guestfs_disk_create (g, argv[1], "raw", SIZE_MB * 1024 * 1024, -1) ==
+ -1)
exit (EXIT_FAILURE);
- /* Create the disk image and format it with a partition and a filesystem. */
- if (guestfs_add_drive_opts (g, argv[1],
- GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
- -1) == -1)
+ /* Create the disk image and format it with a partition and a filesystem.
+ */
+ if (guestfs_add_drive_opts (g, argv[1], GUESTFS_ADD_DRIVE_OPTS_FORMAT,
+ "raw", -1) == -1)
exit (EXIT_FAILURE);
if (guestfs_launch (g) == -1)
@@ -116,23 +117,24 @@ main (int argc, char *argv[])
exit (EXIT_FAILURE);
}
- if (pid == 0) { /* Child. */
+ if (pid == 0) { /* Child. */
if (chdir (tempdir) == -1) {
perror (tempdir);
_exit (EXIT_FAILURE);
}
- printf ("\n"
- "The *current directory* is a FUSE filesystem backed by the
disk\n"
- "image which is managed by libguestfs. Any files or
directories\n"
- "you copy into here (up to %d MB) will be saved into the disk\n"
- "image. You can also delete files, create certain special
files\n"
- "and so on.\n"
- "\n"
- "When you have finished adding files, hit ^D or type 'exit'
to\n"
- "exit the shell and return to the mount-local program.\n"
- "\n",
- SIZE_MB);
+ printf (
+ "\n"
+ "The *current directory* is a FUSE filesystem backed by the disk\n"
+ "image which is managed by libguestfs. Any files or directories\n"
+ "you copy into here (up to %d MB) will be saved into the disk\n"
+ "image. You can also delete files, create certain special files\n"
+ "and so on.\n"
+ "\n"
+ "When you have finished adding files, hit ^D or type 'exit'
to\n"
+ "exit the shell and return to the mount-local program.\n"
+ "\n",
+ SIZE_MB);
shell = getenv ("SHELL");
if (!shell)
@@ -140,7 +142,7 @@ main (int argc, char *argv[])
else {
/* Set a magic prompt. We only know how to do this for bash. */
p = strrchr (shell, '/');
- if (p && strcmp (p+1, "bash") == 0) {
+ if (p && strcmp (p + 1, "bash") == 0) {
size_t len = 64 + strlen (shell);
char *buf;
@@ -149,17 +151,19 @@ main (int argc, char *argv[])
perror ("malloc");
_exit (EXIT_FAILURE);
}
- snprintf (buf, len, "PS1='mount-local-shell> ' %s --norc
-i", shell);
+ snprintf (buf, len, "PS1='mount-local-shell> ' %s --norc
-i",
+ shell);
r = system (buf);
free (buf);
- } else
+ }
+ else
r = system (shell);
}
if (r == -1) {
fprintf (stderr, "error: failed to run sub-shell (%s) "
- "(is $SHELL set correctly?)\n",
+ "(is $SHELL set correctly?)\n",
shell);
- //FALLTHROUGH
+ // FALLTHROUGH
}
if (chdir ("/") == -1)
@@ -191,15 +195,16 @@ main (int argc, char *argv[])
guestfs_close (g);
- printf ("\n"
- "Any files or directories that you copied in have been saved into\n"
- "the disk image called '%s'.\n"
- "\n"
- "Try opening the disk image with guestfish to see those files:\n"
- "\n"
- " guestfish -a %s -m /dev/sda1\n"
- "\n",
- argv[1], argv[1]);
+ printf (
+ "\n"
+ "Any files or directories that you copied in have been saved into\n"
+ "the disk image called '%s'.\n"
+ "\n"
+ "Try opening the disk image with guestfish to see those files:\n"
+ "\n"
+ " guestfish -a %s -m /dev/sda1\n"
+ "\n",
+ argv[1], argv[1]);
exit (EXIT_SUCCESS);
}
diff --git a/examples/virt-dhcp-address.c b/examples/virt-dhcp-address.c
index df06ebe..d271d9b 100644
--- a/examples/virt-dhcp-address.c
+++ b/examples/virt-dhcp-address.c
@@ -23,7 +23,8 @@ static size_t count_strings (char *const *argv);
static void free_strings (char **argv);
static void mount_disks (guestfs_h *g, char *root);
static void print_dhcp_address (guestfs_h *g, char *root);
-static void print_dhcp_address_linux (guestfs_h *g, char *root, const char *logfile);
+static void print_dhcp_address_linux (guestfs_h *g, char *root,
+ const char *logfile);
static void print_dhcp_address_windows (guestfs_h *g, char *root);
int
@@ -34,9 +35,10 @@ main (int argc, char *argv[])
char **roots, *root;
if (argc < 2) {
- fprintf (stderr,
- "Usage: virt-dhcp-address disk.img [disk.img [...]]\n"
- "Note that all disks must come from a single virtual
machine.\n");
+ fprintf (
+ stderr,
+ "Usage: virt-dhcp-address disk.img [disk.img [...]]\n"
+ "Note that all disks must come from a single virtual machine.\n");
exit (EXIT_FAILURE);
}
@@ -46,12 +48,13 @@ main (int argc, char *argv[])
exit (EXIT_FAILURE);
}
- for (i = 1; i < (size_t) argc; ++i) {
+ for (i = 1; i < (size_t)argc; ++i) {
/* Attach the disk image(s) read-only to libguestfs. */
- if (guestfs_add_drive_opts (g, argv[i],
- /* GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw", */
- GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,
- -1) /* this marks end of optional arguments */
+ if (guestfs_add_drive_opts (
+ g, argv[i],
+ /* GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw", */
+ GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,
+ -1) /* this marks end of optional arguments */
== -1)
exit (EXIT_FAILURE);
}
@@ -110,7 +113,7 @@ mount_disks (guestfs_h *g, char *root)
/* Ignore failures from this call, since bogus entries can
* appear in the guest's /etc/fstab.
*/
- guestfs_mount_ro (g, mountpoints[i+1], mountpoints[i]);
+ guestfs_mount_ro (g, mountpoints[i + 1], mountpoints[i]);
}
free_strings (mountpoints);
@@ -141,8 +144,10 @@ print_dhcp_address (guestfs_h *g, char *root)
print_dhcp_address_linux (g, root, "/var/log/syslog");
}
else {
- fprintf (stderr, "virt-dhcp-address: don't know how to get DHCP address
from '%s'\n",
- guest_distro);
+ fprintf (
+ stderr,
+ "virt-dhcp-address: don't know how to get DHCP address from
'%s'\n",
+ guest_distro);
exit (EXIT_FAILURE);
}
@@ -152,8 +157,10 @@ print_dhcp_address (guestfs_h *g, char *root)
print_dhcp_address_windows (g, root);
}
else {
- fprintf (stderr, "virt-dhcp-address: don't know how to get DHCP address from
'%s'\n",
- guest_type);
+ fprintf (
+ stderr,
+ "virt-dhcp-address: don't know how to get DHCP address from
'%s'\n",
+ guest_type);
exit (EXIT_FAILURE);
}
@@ -169,19 +176,20 @@ print_dhcp_address_linux (guestfs_h *g, char *root, const char
*logfile)
size_t len;
lines = guestfs_grep_opts (g, "dhclient.*: bound to ", logfile,
- GUESTFS_GREP_OPTS_EXTENDED, 1,
- -1);
+ GUESTFS_GREP_OPTS_EXTENDED, 1, -1);
if (lines == NULL)
exit (EXIT_FAILURE);
len = count_strings (lines);
if (len == 0) {
- fprintf (stderr, "virt-dhcp-address: cannot find DHCP address for this
guest.\n");
+ fprintf (
+ stderr,
+ "virt-dhcp-address: cannot find DHCP address for this guest.\n");
exit (EXIT_FAILURE);
}
/* Only want the last message. */
- p = strstr (lines[len-1], "bound to ");
+ p = strstr (lines[len - 1], "bound to ");
assert (p);
p += 9;
len = strcspn (p, " ");
@@ -238,7 +246,11 @@ print_dhcp_address_windows (guestfs_h *g, char *root_fs)
exit (EXIT_FAILURE);
if (node == 0) {
- fprintf (stderr, "virt-dhcp-address:
HKLM\\System\\%s\\Services\\Tcpip\\Parameters\\Interfaces not found.", controlset);
+ fprintf (stderr, "virt-dhcp-address: "
+ "HKLM\\System\\%"
+ "s\\Services\\Tcpip\\Parameters\\Interfaces not "
+ "found.",
+ controlset);
exit (EXIT_FAILURE);
}
@@ -258,7 +270,9 @@ print_dhcp_address_windows (guestfs_h *g, char *root_fs)
}
if (value == 0) {
- fprintf (stderr, "virt-dhcp-address: cannot find DHCP address for this
guest.\n");
+ fprintf (
+ stderr,
+ "virt-dhcp-address: cannot find DHCP address for this guest.\n");
exit (EXIT_FAILURE);
}
@@ -282,8 +296,8 @@ print_dhcp_address_windows (guestfs_h *g, char *root_fs)
static int
compare_keys_len (const void *p1, const void *p2)
{
- const char *key1 = * (char * const *) p1;
- const char *key2 = * (char * const *) p2;
+ const char *key1 = *(char *const *)p1;
+ const char *key2 = *(char *const *)p2;
return strlen (key1) - strlen (key2);
}
diff --git a/fish/alloc.c b/fish/alloc.c
index 7ec6a15..785a129 100644
--- a/fish/alloc.c
+++ b/fish/alloc.c
@@ -49,7 +49,8 @@ int
run_sparse (const char *cmd, size_t argc, char *argv[])
{
if (argc != 2) {
- fprintf (stderr, _("use 'sparse file size' to create a sparse
image\n"));
+ fprintf (stderr,
+ _("use 'sparse file size' to create a sparse image\n"));
return -1;
}
@@ -71,15 +72,14 @@ alloc_disk (const char *filename, const char *size_str, int add, int
sparse)
if (parse_size (size_str, &size) == -1)
return -1;
- if (guestfs_disk_create (g, filename, "raw", (int64_t) size,
+ if (guestfs_disk_create (g, filename, "raw", (int64_t)size,
GUESTFS_DISK_CREATE_PREALLOCATION, prealloc,
-1) == -1)
return -1;
if (add) {
- if (guestfs_add_drive_opts (g, filename,
- GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
- -1) == -1) {
+ if (guestfs_add_drive_opts (g, filename, GUESTFS_ADD_DRIVE_OPTS_FORMAT,
+ "raw", -1) == -1) {
unlink (filename);
return -1;
}
@@ -96,9 +96,8 @@ parse_size (const char *str, off_t *size_rtn)
xerr = xstrtoull (str, NULL, 0, &size, "0kKMGTPEZY");
if (xerr != LONGINT_OK) {
- fprintf (stderr,
- _("%s: invalid integer parameter (%s returned %u)\n"),
- "parse_size", "xstrtoull", xerr);
+ fprintf (stderr, _("%s: invalid integer parameter (%s returned %u)\n"),
+ "parse_size", "xstrtoull", xerr);
return -1;
}
diff --git a/fish/cmds-gperf.h b/fish/cmds-gperf.h
index bcb3b5d..71ae855 100644
--- a/fish/cmds-gperf.h
+++ b/fish/cmds-gperf.h
@@ -23,9 +23,9 @@
* guestfish can execute.
*/
struct command_entry {
- const char *name; /* Short name. */
- const char *help; /* Online help. */
- const char *synopsis; /* Synopsis. */
+ const char *name; /* Short name. */
+ const char *help; /* Online help. */
+ const char *synopsis; /* Synopsis. */
/* The run_* function. */
int (*run) (const char *cmd, size_t argc, char *argv[]);
@@ -40,6 +40,7 @@ struct command_table {
struct command_entry *entry;
};
-const struct command_table *lookup_fish_command (register const char *str, register
unsigned int len);
+const struct command_table *lookup_fish_command (register const char *str,
+ register unsigned int len);
#endif /* FISH_CMDS_GPERF_H */
diff --git a/fish/config.c b/fish/config.c
index 17c801c..921d6b7 100644
--- a/fish/config.c
+++ b/fish/config.c
@@ -64,7 +64,8 @@ read_config_from_file (const char *filename)
if (config_read (&conf, fp) == CONFIG_FALSE)
error (EXIT_FAILURE, 0,
_("%s: line %d: error parsing configuration file: %s"),
- filename, config_error_line (&conf), config_error_text (&conf));
+ filename, config_error_line (&conf),
+ config_error_text (&conf));
if (fclose (fp) == -1)
error (EXIT_FAILURE, errno, "fclose: %s", filename);
@@ -97,7 +98,8 @@ parse_config (void)
CLEANUP_FREE char *path = NULL;
const char *dir = xdg_config_dirs[i - 1];
- if (asprintf (&path, "%s/libguestfs/" GLOBAL_CONFIG_FILENAME, dir) ==
-1)
+ if (asprintf (&path, "%s/libguestfs/" GLOBAL_CONFIG_FILENAME, dir)
==
+ -1)
error (EXIT_FAILURE, errno, "asprintf");
read_config_from_file (path);
@@ -128,10 +130,12 @@ parse_config (void)
xdg_env = getenv ("XDG_CONFIG_HOME");
if (xdg_env == NULL) {
- if (asprintf (&path, "%s/.config/libguestfs/"
GLOBAL_CONFIG_FILENAME,
+ if (asprintf (&path,
+ "%s/.config/libguestfs/" GLOBAL_CONFIG_FILENAME,
home_copy) == -1)
error (EXIT_FAILURE, errno, "asprintf");
- } else {
+ }
+ else {
if (asprintf (&path, "%s/libguestfs/" GLOBAL_CONFIG_FILENAME,
xdg_env) == -1)
error (EXIT_FAILURE, errno, "asprintf");
@@ -150,7 +154,8 @@ parse_config (void)
/*
if (verbose)
fprintf (stderr,
- _("%s: compiled without libconfig, guestfish configuration file
ignored\n"),
+ _("%s: compiled without libconfig, guestfish configuration file
+ ignored\n"),
guestfs_int_program_name);
*/
}
diff --git a/fish/copy.c b/fish/copy.c
index e5655e1..541770c 100644
--- a/fish/copy.c
+++ b/fish/copy.c
@@ -33,19 +33,19 @@ run_copy_in (const char *cmd, size_t argc, char *argv[])
CLEANUP_FREE char *remote = NULL;
if (argc < 2) {
- fprintf (stderr,
- _("use 'copy-in <local> [<local>...]
<remotedir>' to copy files into the image\n"));
+ fprintf (stderr, _("use 'copy-in <local> [<local>...]
<remotedir>' to "
+ "copy files into the image\n"));
return -1;
}
/* Remote directory is always the last arg.
* Allow "win:" prefix on remote.
*/
- remote = win_prefix (argv[argc-1]);
+ remote = win_prefix (argv[argc - 1]);
if (remote == NULL)
return -1;
- int nr_locals = argc-1;
+ int nr_locals = argc - 1;
/* Upload each local one at a time using copy-in. */
int i;
@@ -62,14 +62,14 @@ int
run_copy_out (const char *cmd, size_t argc, char *argv[])
{
if (argc < 2) {
- fprintf (stderr,
- _("use 'copy-out <remote> [<remote>...]
<localdir>' to copy files out of the image\n"));
+ fprintf (stderr, _("use 'copy-out <remote> [<remote>...]
<localdir>' "
+ "to copy files out of the image\n"));
return -1;
}
/* Local directory is always the last arg. */
- const char *local = argv[argc-1];
- int nr_remotes = argc-1;
+ const char *local = argv[argc - 1];
+ int nr_remotes = argc - 1;
/* Download each remote one at a time using copy-out. */
int i, r;
diff --git a/fish/destpaths.c b/fish/destpaths.c
index 31dd6a9..c65e5fb 100644
--- a/fish/destpaths.c
+++ b/fish/destpaths.c
@@ -45,7 +45,7 @@
sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for
exactly-SIZE_MAX allocations on such hosts; this avoids a test and
branch when S is known to be 1. */
-# define xalloc_oversized(n, s) \
+#define xalloc_oversized(n, s) \
((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n))
#endif
@@ -75,8 +75,8 @@ free_words (struct word *words, size_t nr_words)
static int
compare_words (const void *vp1, const void *vp2)
{
- const struct word *w1 = (const struct word *) vp1;
- const struct word *w2 = (const struct word *) vp2;
+ const struct word *w1 = (const struct word *)vp1;
+ const struct word *w2 = (const struct word *)vp2;
return strcmp (w1->name, w2->name);
}
#endif
@@ -96,40 +96,43 @@ complete_dest_paths_generator (const char *text, int state)
len = strlen (text);
index = 0;
- if (words) free_words (words, nr_words);
+ if (words)
+ free_words (words, nr_words);
words = NULL;
nr_words = 0;
guestfs_push_error_handler (g, NULL, NULL);
- /* Silently do nothing if an allocation fails */
-#define APPEND_STRS_AND_FREE \
- do { \
- if (strs) { \
- size_t i; \
- size_t n = guestfs_int_count_strings (strs); \
- \
- if ( n > 0 && ! xalloc_oversized (nr_words + n, sizeof (struct word))) { \
- struct word *w; \
- w = realloc (words, sizeof (struct word) * (nr_words + n)); \
- \
- if (w == NULL) { \
- free_words (words, nr_words); \
- words = NULL; \
- nr_words = 0; \
- } else { \
- words = w; \
- for (i = 0; i < n; ++i) { \
- words[nr_words].name = strs[i]; \
- words[nr_words].is_dir = 0; \
- nr_words++; \
- } \
- } \
- } \
- free (strs); \
- } \
- } while (0)
+/* Silently do nothing if an allocation fails */
+#define APPEND_STRS_AND_FREE \
+ do { \
+ if (strs) { \
+ size_t i; \
+ size_t n = guestfs_int_count_strings (strs); \
+ \
+ if (n > 0 && \
+ !xalloc_oversized (nr_words + n, sizeof (struct word))) { \
+ struct word *w; \
+ w = realloc (words, sizeof (struct word) * (nr_words + n)); \
+ \
+ if (w == NULL) { \
+ free_words (words, nr_words); \
+ words = NULL; \
+ nr_words = 0; \
+ } \
+ else { \
+ words = w; \
+ for (i = 0; i < n; ++i) { \
+ words[nr_words].name = strs[i]; \
+ words[nr_words].is_dir = 0; \
+ nr_words++; \
+ } \
+ } \
+ } \
+ free (strs); \
+ } \
+ } while (0)
/* Is it a device? */
if (len < 5 || STREQLEN (text, "/dev/", 5)) {
@@ -179,10 +182,12 @@ complete_dest_paths_generator (const char *text, int state)
else
err = asprintf (&p, "%s/%s", dir,
dirents->val[i].name);
if (err >= 0) {
- if (!xalloc_oversized (nr_words+1, sizeof (struct word))) {
+ if (!xalloc_oversized (nr_words + 1,
+ sizeof (struct word))) {
struct word *w;
- w = realloc (words, sizeof (struct word) * (nr_words+1));
+ w =
+ realloc (words, sizeof (struct word) * (nr_words + 1));
if (w == NULL) {
free_words (words, nr_words);
words = NULL;
@@ -191,13 +196,15 @@ complete_dest_paths_generator (const char *text, int state)
else {
words = w;
words[nr_words].name = p;
- if (dirents->val[i].ftyp == 'u'
- || dirents->val[i].ftyp == 'l'
- || dirents->val[i].ftyp == '?') {
- int is_dir = guestfs_is_dir_opts (g, words[nr_words].name,
+ if (dirents->val[i].ftyp == 'u' ||
+ dirents->val[i].ftyp == 'l' ||
+ dirents->val[i].ftyp == '?') {
+ int is_dir = guestfs_is_dir_opts (
+ g, words[nr_words].name,
GUESTFS_IS_DIR_OPTS_FOLLOWSYMLINKS, 1, -1);
words[nr_words].is_dir = is_dir;
- } else
+ }
+ else
words[nr_words].is_dir = dirents->val[i].ftyp == 'd';
nr_words++;
}
@@ -241,9 +248,8 @@ complete_dest_paths_generator (const char *text, int state)
if (cic_var && STREQ (cic_var, "off"))
cic = 0;
- int matches =
- cic ? STRCASEEQLEN (word->name, text, len)
- : STREQLEN (word->name, text, len);
+ int matches = cic ? STRCASEEQLEN (word->name, text, len)
+ : STREQLEN (word->name, text, len);
if (matches) {
if (word->is_dir)
diff --git a/fish/domain.c b/fish/domain.c
index d3be8e7..9528dd8 100644
--- a/fish/domain.c
+++ b/fish/domain.c
@@ -32,7 +32,7 @@
int
add_libvirt_drives (guestfs_h *g, const char *guest)
{
- struct guestfs_add_domain_argv optargs = { .bitmask = 0 };
+ struct guestfs_add_domain_argv optargs = {.bitmask = 0 };
if (libvirt_uri) {
optargs.bitmask |= GUESTFS_ADD_DOMAIN_LIBVIRTURI_BITMASK;
diff --git a/fish/echo.c b/fish/echo.c
index 810243b..d474610 100644
--- a/fish/echo.c
+++ b/fish/echo.c
@@ -30,7 +30,8 @@ run_echo (const char *cmd, size_t argc, char *argv[])
size_t i;
for (i = 0; i < argc; ++i) {
- if (i > 0) printf (" ");
+ if (i > 0)
+ printf (" ");
printf ("%s", argv[i]);
}
printf ("\n");
diff --git a/fish/edit.c b/fish/edit.c
index bf9fdb5..b5d6e05 100644
--- a/fish/edit.c
+++ b/fish/edit.c
@@ -55,7 +55,8 @@ run_edit (const char *cmd, size_t argc, char *argv[])
if (remotefilename == NULL)
return -1;
- r = edit_file_editor (g, remotefilename, editor, NULL, 0 /* not verbose */);
+ r =
+ edit_file_editor (g, remotefilename, editor, NULL, 0 /* not verbose */);
return r == -1 ? -1 : 0;
}
diff --git a/fish/events.c b/fish/events.c
index 8660fc4..1cfb0c7 100644
--- a/fish/events.c
+++ b/fish/events.c
@@ -41,11 +41,11 @@
static Hash_table *event_handlers;
struct entry {
- struct entry *next; /* Next entry in linked list. */
- char *name; /* Event name. */
- char *command; /* Shell script / command that runs. */
- uint64_t event_bitmask; /* Events this is registered for. */
- int eh; /* Event handle (from guestfs_set_event_callback). */
+ struct entry *next; /* Next entry in linked list. */
+ char *name; /* Event name. */
+ char *command; /* Shell script / command that runs. */
+ uint64_t event_bitmask; /* Events this is registered for. */
+ int eh; /* Event handle (from guestfs_set_event_callback). */
};
static void
@@ -92,13 +92,9 @@ free_event_handlers (void)
}
static void
-do_event_handler (guestfs_h *g,
- void *opaque,
- uint64_t event,
- int event_handle,
- int flags,
- const char *buf, size_t buf_len,
- const uint64_t *array, size_t array_len)
+do_event_handler (guestfs_h *g, void *opaque, uint64_t event,
+ int event_handle, int flags, const char *buf,
+ size_t buf_len, const uint64_t *array, size_t array_len)
{
pid_t pid;
CLEANUP_FREE const char **argv = NULL;
@@ -119,7 +115,7 @@ do_event_handler (guestfs_h *g,
return;
}
- if (pid == 0) { /* Child process. */
+ if (pid == 0) { /* Child process. */
char *str;
shell = getenv ("SHELL");
@@ -153,7 +149,7 @@ do_event_handler (guestfs_h *g,
argv[i++] = NULL;
- execvp (argv[0], (void *) argv);
+ execvp (argv[0], (void *)argv);
perror (argv[0]);
_exit (EXIT_FAILURE);
@@ -170,8 +166,8 @@ run_event (const char *cmd, size_t argc, char *argv[])
struct entry *entry = NULL, *old_entry;
if (argc != 3) {
- fprintf (stderr,
- _("use 'event <name> <eventset> <script>' to
register an event handler\n"));
+ fprintf (stderr, _("use 'event <name> <eventset>
<script>' to "
+ "register an event handler\n"));
goto error;
}
@@ -197,16 +193,16 @@ run_event (const char *cmd, size_t argc, char *argv[])
goto error;
}
- entry->eh =
- guestfs_set_event_callback (g, do_event_handler,
- entry->event_bitmask, 0, entry);
+ entry->eh = guestfs_set_event_callback (g, do_event_handler,
+ entry->event_bitmask, 0, entry);
if (entry->eh == -1)
goto error;
- r = hash_insert_if_absent (event_handlers, entry, (const void **) &old_entry);
+ r = hash_insert_if_absent (event_handlers, entry,
+ (const void **)&old_entry);
if (r == -1)
goto error;
- if (r == 0) { /* old_entry set to existing entry */
+ if (r == 0) { /* old_entry set to existing entry */
entry->next = old_entry->next;
/* XXX are we allowed to update the old entry? */
old_entry->next = entry;
@@ -214,7 +210,7 @@ run_event (const char *cmd, size_t argc, char *argv[])
return 0;
- error:
+error:
if (entry) {
if (entry->eh >= 0)
guestfs_delete_event_callback (g, entry->eh);
@@ -234,12 +230,13 @@ run_delete_event (const char *cmd, size_t argc, char *argv[])
return -1;
}
- const struct entry key = { .name = argv[0] };
+ const struct entry key = {.name = argv[0] };
struct entry *entry, *p;
entry = hash_delete (event_handlers, &key);
if (!entry) {
- fprintf (stderr, _("delete-event: %s: no such event handler\n"), argv[0]);
+ fprintf (stderr, _("delete-event: %s: no such event handler\n"),
+ argv[0]);
return -1;
}
@@ -288,8 +285,7 @@ int
run_list_events (const char *cmd, size_t argc, char *argv[])
{
if (argc != 0) {
- fprintf (stderr,
- _("use 'list-events' to list event handlers\n"));
+ fprintf (stderr, _("use 'list-events' to list event handlers\n"));
return -1;
}
diff --git a/fish/file-edit.c b/fish/file-edit.c
index 713b741..a2466c1 100644
--- a/fish/file-edit.c
+++ b/fish/file-edit.c
@@ -36,9 +36,10 @@
#include "guestfs-internal-frontend.h"
-static int do_download (guestfs_h *g, const char *filename, char **tempfile);
-static int do_upload (guestfs_h *g, const char *filename, const char *tempfile,
- const char *backup_extension);
+static int do_download (guestfs_h *g, const char *filename,
+ char **tempfile);
+static int do_upload (guestfs_h *g, const char *filename,
+ const char *tempfile, const char *backup_extension);
static char *generate_random_name (const char *filename);
static char *generate_backup_name (const char *filename,
const char *backup_extension);
@@ -142,18 +143,17 @@ edit_file_perl (guestfs_h *g, const char *filename, const char
*perl_expr,
setenv ("virt_edit_expr", perl_expr, 1);
/* Call out to a canned Perl script. */
- if (asprintf (&cmd,
- "perl -e '"
- "$lineno = 0; "
- "$expr = $ENV{virt_edit_expr}; "
- "while (<STDIN>) { "
- " $lineno++; "
- " eval $expr; "
- " die if $@; "
- " print STDOUT $_ or die \"print: $!\"; "
- "} "
- "close STDOUT or die \"close: $!\"; "
- "' < %s > %s",
+ if (asprintf (&cmd, "perl -e '"
+ "$lineno = 0; "
+ "$expr = $ENV{virt_edit_expr}; "
+ "while (<STDIN>) { "
+ " $lineno++; "
+ " eval $expr; "
+ " die if $@; "
+ " print STDOUT $_ or die \"print: $!\"; "
+ "} "
+ "close STDOUT or die \"close: $!\"; "
+ "' < %s > %s",
tmpfilename, outfile) == -1) {
perror ("asprintf");
return -1;
@@ -252,7 +252,7 @@ do_upload (guestfs_h *g, const char *fn, const char *tempfile,
* file to match the old file (RHBZ#788641).
*/
if (guestfs_copy_attributes (g, filename, newname,
- GUESTFS_COPY_ATTRIBUTES_ALL, 1, -1) == -1)
+ GUESTFS_COPY_ATTRIBUTES_ALL, 1, -1) == -1)
return -1;
/* Backup or overwrite the file. */
@@ -275,7 +275,8 @@ do_upload (guestfs_h *g, const char *fn, const char *tempfile,
static char
random_char (void)
{
- const char c[] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+ const char c[] =
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
return c[random () % (sizeof c - 1)];
}
diff --git a/fish/file-edit.h b/fish/file-edit.h
index cd92e5a..8a07537 100644
--- a/fish/file-edit.h
+++ b/fish/file-edit.h
@@ -33,8 +33,8 @@
* the file (e.g. the user closed the editor without saving).
*/
extern int edit_file_editor (guestfs_h *g, const char *filename,
- const char *editor, const char *backup_extension,
- int verbose);
+ const char *editor,
+ const char *backup_extension, int verbose);
/**
* Edit 'filename' running the specified 'perl_expr' using Perl.
diff --git a/fish/fish.c b/fish/fish.c
index bfb4f82..d64f121 100644
--- a/fish/fish.c
+++ b/fish/fish.c
@@ -64,7 +64,8 @@ static void interactive (void);
static void shell_script (void);
static void script (int prompt);
static void cmdline (char *argv[], size_t optind, size_t argc);
-static struct parsed_command parse_command_line (char *buf, int *exit_on_error_rtn);
+static struct parsed_command parse_command_line (char *buf,
+ int *exit_on_error_rtn);
static ssize_t parse_quoted_string (char *p);
static int execute_and_inline (const char *cmd, int exit_on_error);
static void error_cb (guestfs_h *g, void *data, const char *msg);
@@ -106,56 +107,61 @@ usage (int status)
fprintf (stderr, _("Try `%s --help' for more information.\n"),
guestfs_int_program_name);
else {
- printf (_("%s: guest filesystem shell\n"
- "%s lets you edit virtual machine filesystems\n"
- "Copyright (C) 2009-2016 Red Hat Inc.\n"
- "Usage:\n"
- " %s [--options] cmd [: cmd : cmd ...]\n"
- "Options:\n"
- " -h|--cmd-help List available commands\n"
- " -h|--cmd-help cmd Display detailed help on
'cmd'\n"
- " -a|--add image Add image\n"
- " -c|--connect uri Specify libvirt URI for -d option\n"
- " --csh Make --listen csh-compatible\n"
- " -d|--domain guest Add disks from libvirt guest\n"
- " --echo-keys Don't turn off echo for
passphrases\n"
- " -f|--file file Read commands from file\n"
- " --format[=raw|..] Force disk format for -a option\n"
- " -i|--inspector Automatically mount filesystems\n"
- " --keys-from-stdin Read passphrases from stdin\n"
- " --listen Listen for remote commands\n"
- " --live Connect to a live virtual machine\n"
- " -m|--mount dev[:mnt[:opts[:fstype]]]\n"
- " Mount dev on mnt (if omitted, /)\n"
- " --network Enable network\n"
- " -N|--new [filename=]type\n"
- " Create prepared disk (test<N>.img or
filename)\n"
- " -n|--no-sync Don't autosync\n"
- " --no-dest-paths Don't tab-complete paths from guest
fs\n"
- " --pipe-error Pipe commands can detect write errors\n"
- " --progress-bars Enable progress bars even when not
interactive\n"
- " --no-progress-bars Disable progress bars\n"
- " --remote[=pid] Send commands to remote %s\n"
- " -r|--ro Mount read-only\n"
- " --selinux Enable SELinux support\n"
- " -v|--verbose Verbose messages\n"
- " -V|--version Display version and exit\n"
- " -w|--rw Mount read-write\n"
- " -x Echo each command before executing it\n"
- "\n"
- "To examine a disk image, ISO, hard disk, filesystem etc:\n"
- " %s [--ro|--rw] -i -a /path/to/disk.img\n"
- "or\n"
- " %s [--ro|--rw] -i -d name-of-libvirt-domain\n"
- "\n"
- "--ro recommended to avoid any writes to the disk image. If -i option
fails\n"
- "run again without -i and use 'run' +
'list-filesystems' + 'mount' cmds.\n"
- "\n"
- "For more information, see the manpage %s(1).\n"),
- guestfs_int_program_name, guestfs_int_program_name,
- guestfs_int_program_name, guestfs_int_program_name,
- guestfs_int_program_name, guestfs_int_program_name,
- guestfs_int_program_name);
+ printf (
+ _("%s: guest filesystem shell\n"
+ "%s lets you edit virtual machine filesystems\n"
+ "Copyright (C) 2009-2016 Red Hat Inc.\n"
+ "Usage:\n"
+ " %s [--options] cmd [: cmd : cmd ...]\n"
+ "Options:\n"
+ " -h|--cmd-help List available commands\n"
+ " -h|--cmd-help cmd Display detailed help on 'cmd'\n"
+ " -a|--add image Add image\n"
+ " -c|--connect uri Specify libvirt URI for -d option\n"
+ " --csh Make --listen csh-compatible\n"
+ " -d|--domain guest Add disks from libvirt guest\n"
+ " --echo-keys Don't turn off echo for passphrases\n"
+ " -f|--file file Read commands from file\n"
+ " --format[=raw|..] Force disk format for -a option\n"
+ " -i|--inspector Automatically mount filesystems\n"
+ " --keys-from-stdin Read passphrases from stdin\n"
+ " --listen Listen for remote commands\n"
+ " --live Connect to a live virtual machine\n"
+ " -m|--mount dev[:mnt[:opts[:fstype]]]\n"
+ " Mount dev on mnt (if omitted, /)\n"
+ " --network Enable network\n"
+ " -N|--new [filename=]type\n"
+ " Create prepared disk (test<N>.img or "
+ "filename)\n"
+ " -n|--no-sync Don't autosync\n"
+ " --no-dest-paths Don't tab-complete paths from guest fs\n"
+ " --pipe-error Pipe commands can detect write errors\n"
+ " --progress-bars Enable progress bars even when not "
+ "interactive\n"
+ " --no-progress-bars Disable progress bars\n"
+ " --remote[=pid] Send commands to remote %s\n"
+ " -r|--ro Mount read-only\n"
+ " --selinux Enable SELinux support\n"
+ " -v|--verbose Verbose messages\n"
+ " -V|--version Display version and exit\n"
+ " -w|--rw Mount read-write\n"
+ " -x Echo each command before executing it\n"
+ "\n"
+ "To examine a disk image, ISO, hard disk, filesystem etc:\n"
+ " %s [--ro|--rw] -i -a /path/to/disk.img\n"
+ "or\n"
+ " %s [--ro|--rw] -i -d name-of-libvirt-domain\n"
+ "\n"
+ "--ro recommended to avoid any writes to the disk image. If -i "
+ "option fails\n"
+ "run again without -i and use 'run' + 'list-filesystems' +
"
+ "'mount' cmds.\n"
+ "\n"
+ "For more information, see the manpage %s(1).\n"),
+ guestfs_int_program_name, guestfs_int_program_name,
+ guestfs_int_program_name, guestfs_int_program_name,
+ guestfs_int_program_name, guestfs_int_program_name,
+ guestfs_int_program_name);
}
exit (status);
}
@@ -239,10 +245,11 @@ main (int argc, char *argv[])
for (;;) {
c = getopt_long (argc, argv, options, long_options, &option_index);
- if (c == -1) break;
+ if (c == -1)
+ break;
switch (c) {
- case 0: /* options which are long only */
+ case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "long-options"))
display_long_options (long_options);
else if (STREQ (long_options[option_index].name, "short-options"))
@@ -254,40 +261,53 @@ main (int argc, char *argv[])
if (sscanf (optarg, "%d", &remote_control) != 1)
error (EXIT_FAILURE, 0,
_("--listen=PID: PID was not a number: %s"), optarg);
- } else {
+ }
+ else {
p = getenv ("GUESTFISH_PID");
if (!p || sscanf (p, "%d", &remote_control) != 1)
error (EXIT_FAILURE, 0,
_("remote: $GUESTFISH_PID must be set"
" to the PID of the remote process"));
}
- } else if (STREQ (long_options[option_index].name, "selinux")) {
+ }
+ else if (STREQ (long_options[option_index].name, "selinux")) {
if (guestfs_set_selinux (g, 1) == -1)
exit (EXIT_FAILURE);
- } else if (STREQ (long_options[option_index].name, "keys-from-stdin")) {
+ }
+ else if (STREQ (long_options[option_index].name, "keys-from-stdin")) {
keys_from_stdin = 1;
- } else if (STREQ (long_options[option_index].name, "progress-bars")) {
+ }
+ else if (STREQ (long_options[option_index].name, "progress-bars")) {
override_progress_bars = 1;
- } else if (STREQ (long_options[option_index].name, "no-progress-bars"))
{
+ }
+ else if (STREQ (long_options[option_index].name,
+ "no-progress-bars")) {
override_progress_bars = 0;
- } else if (STREQ (long_options[option_index].name, "echo-keys")) {
+ }
+ else if (STREQ (long_options[option_index].name, "echo-keys")) {
echo_keys = 1;
- } else if (STREQ (long_options[option_index].name, "format")) {
+ }
+ else if (STREQ (long_options[option_index].name, "format")) {
OPTION_format;
- } else if (STREQ (long_options[option_index].name, "csh")) {
+ }
+ else if (STREQ (long_options[option_index].name, "csh")) {
remote_control_csh = 1;
- } else if (STREQ (long_options[option_index].name, "live")) {
+ }
+ else if (STREQ (long_options[option_index].name, "live")) {
live = 1;
- } else if (STREQ (long_options[option_index].name, "pipe-error")) {
+ }
+ else if (STREQ (long_options[option_index].name, "pipe-error")) {
pipe_error = 1;
- } else if (STREQ (long_options[option_index].name, "network")) {
+ }
+ else if (STREQ (long_options[option_index].name, "network")) {
if (guestfs_set_network (g, 1) == -1)
exit (EXIT_FAILURE);
- } else if (STREQ (long_options[option_index].name, "no-dest-paths")) {
+ }
+ else if (STREQ (long_options[option_index].name, "no-dest-paths")) {
complete_dest_paths = 0;
- } else
- error (EXIT_FAILURE, 0,
- _("unknown long option: %s (%d)"),
+ }
+ else
+ error (EXIT_FAILURE, 0, _("unknown long option: %s (%d)"),
long_options[option_index].name, option_index);
break;
@@ -304,7 +324,8 @@ main (int argc, char *argv[])
break;
case 'D':
- fprintf (stderr, _("%s: warning: -D option is deprecated, use --no-dest-paths
instead\n"),
+ fprintf (stderr, _("%s: warning: -D option is deprecated, use "
+ "--no-dest-paths instead\n"),
guestfs_int_program_name);
complete_dest_paths = 0;
break;
@@ -343,10 +364,8 @@ main (int argc, char *argv[])
case 'N': {
char *p;
- if (STRCASEEQ (optarg, "list") ||
- STRCASEEQ (optarg, "help") ||
- STRCASEEQ (optarg, "h") ||
- STRCASEEQ (optarg, "?")) {
+ if (STRCASEEQ (optarg, "list") || STRCASEEQ (optarg, "help")
||
+ STRCASEEQ (optarg, "h") || STRCASEEQ (optarg, "?")) {
list_prepared_drives ();
exit (EXIT_SUCCESS);
}
@@ -358,11 +377,12 @@ main (int argc, char *argv[])
p = strchr (optarg, '=');
if (p != NULL) {
*p = '\0';
- p = p+1;
+ p = p + 1;
drv->N.filename = strdup (optarg);
if (drv->N.filename == NULL)
error (EXIT_FAILURE, errno, "strdup");
- } else {
+ }
+ else {
if (asprintf (&drv->N.filename, "test%d.img",
next_prepared_drive) == -1)
error (EXIT_FAILURE, errno, "asprintf");
@@ -441,7 +461,8 @@ main (int argc, char *argv[])
error (EXIT_FAILURE, errno, "strdup");
drv->next = drvs;
drvs = drv;
- } else { /* simulate -d option */
+ }
+ else { /* simulate -d option */
drv = calloc (1, sizeof (struct drv));
if (!drv)
error (EXIT_FAILURE, errno, "calloc");
@@ -477,7 +498,8 @@ main (int argc, char *argv[])
exit (EXIT_FAILURE);
}
- if (launch () == -1) exit (EXIT_FAILURE);
+ if (launch () == -1)
+ exit (EXIT_FAILURE);
if (inspector)
inspect_mount ();
@@ -509,7 +531,7 @@ main (int argc, char *argv[])
/* -f (file) parameter? */
if (file) {
close (0);
- if (open (file, O_RDONLY|O_CLOEXEC) == -1)
+ if (open (file, O_RDONLY | O_CLOEXEC) == -1)
error (EXIT_FAILURE, errno, "open: %s", file);
}
@@ -526,10 +548,9 @@ main (int argc, char *argv[])
input_lineno = 0;
/* Decide if we display progress bars. */
- progress_bars =
- override_progress_bars >= 0
- ? override_progress_bars
- : (optind >= argc && is_interactive);
+ progress_bars = override_progress_bars >= 0
+ ? override_progress_bars
+ : (optind >= argc && is_interactive);
if (progress_bars) {
bar = progress_bar_init (0);
@@ -555,7 +576,7 @@ main (int argc, char *argv[])
guestfs_close (g);
- out_after_handle_close:
+out_after_handle_close:
cleanup_readline ();
if (progress_bars)
@@ -612,7 +633,7 @@ static char *ps1 = NULL; /* GUESTFISH_PS1 */
static char *ps_output = NULL; /* GUESTFISH_OUTPUT */
static char *ps_init = NULL; /* GUESTFISH_INIT */
static char *ps_restore = NULL; /* GUESTFISH_RESTORE */
-#endif /* HAVE_LIBREADLINE */
+#endif /* HAVE_LIBREADLINE */
static char *line_read = NULL;
static char *
@@ -630,7 +651,7 @@ rl_gets (int prompt)
p = ps1 ? decode_ps1 (ps1) : NULL;
line_read = readline (ps1 ? p : FISH);
- if (ps_output) { /* GUESTFISH_OUTPUT */
+ if (ps_output) { /* GUESTFISH_OUTPUT */
CLEANUP_FREE char *po = decode_ps1 (ps_output);
printf ("%s", po);
}
@@ -646,12 +667,14 @@ rl_gets (int prompt)
static char buf[8192];
size_t len;
- if (prompt) printf (FISH);
+ if (prompt)
+ printf (FISH);
line_read = fgets (buf, sizeof buf, stdin);
if (line_read) {
len = strlen (line_read);
- if (len > 0 && buf[len-1] == '\n') buf[len-1] = '\0';
+ if (len > 0 && buf[len - 1] == '\n')
+ buf[len - 1] = '\0';
}
return line_read;
@@ -667,7 +690,7 @@ script (int prompt)
if (prompt) {
#ifdef HAVE_LIBREADLINE
- if (ps_init) { /* GUESTFISH_INIT */
+ if (ps_init) { /* GUESTFISH_INIT */
CLEANUP_FREE char *pi = decode_ps1 (ps_init);
printf ("%s", pi);
}
@@ -703,8 +726,10 @@ script (int prompt)
if (pcmd.status == -1 && exit_on_error)
exit (EXIT_FAILURE);
if (pcmd.status == 1) {
- if (issue_command (pcmd.cmd, pcmd.argv, pcmd.pipe, exit_on_error) == -1) {
- if (exit_on_error) exit (EXIT_FAILURE);
+ if (issue_command (pcmd.cmd, pcmd.argv, pcmd.pipe, exit_on_error) ==
+ -1) {
+ if (exit_on_error)
+ exit (EXIT_FAILURE);
}
}
}
@@ -712,7 +737,7 @@ script (int prompt)
#ifdef HAVE_LIBREADLINE
if (prompt) {
printf ("\n");
- if (ps_restore) { /* GUESTFISH_RESTORE */
+ if (ps_restore) { /* GUESTFISH_RESTORE */
CLEANUP_FREE char *pr = decode_ps1 (ps_restore);
printf ("%s", pr);
}
@@ -747,7 +772,7 @@ parse_command_line (char *buf, int *exit_on_error_rtn)
*/
memset (&pcmd, 0, sizeof pcmd);
- again:
+again:
/* Skip any initial whitespace before the command. */
while (*buf && c_isspace (*buf))
buf++;
@@ -765,10 +790,9 @@ parse_command_line (char *buf, int *exit_on_error_rtn)
/* If the next character is '!' then pass the whole lot to system(3). */
if (*buf == '!') {
- r = system (buf+1);
- if (r == -1 ||
- (WIFSIGNALED (r) &&
- (WTERMSIG (r) == SIGINT || WTERMSIG (r) == SIGQUIT)) ||
+ r = system (buf + 1);
+ if (r == -1 || (WIFSIGNALED (r) &&
+ (WTERMSIG (r) == SIGINT || WTERMSIG (r) == SIGQUIT)) ||
WEXITSTATUS (r) != 0)
pcmd.status = -1;
else
@@ -814,7 +838,7 @@ parse_command_line (char *buf, int *exit_on_error_rtn)
}
buf[len] = '\0';
- p = &buf[len+1];
+ p = &buf[len + 1];
p += strspn (p, " \t");
/* Get the parameters. */
@@ -831,23 +855,25 @@ parse_command_line (char *buf, int *exit_on_error_rtn)
pcmd.status = -1;
return pcmd;
}
- if (p[len+1] && (p[len+1] != ' ' && p[len+1] !=
'\t')) {
+ if (p[len + 1] && (p[len + 1] != ' ' && p[len + 1] !=
'\t')) {
fprintf (stderr,
_("%s: command arguments not separated by whitespace\n"),
guestfs_int_program_name);
pcmd.status = -1;
return pcmd;
}
- pend = p[len+1] ? &p[len+2] : &p[len+1];
- } else if (*p == '\'') {
+ pend = p[len + 1] ? &p[len + 2] : &p[len + 1];
+ }
+ else if (*p == '\'') {
p++;
len = strcspn (p, "'");
if (p[len] == '\0') {
- fprintf (stderr, _("%s: unterminated single quote\n"),
guestfs_int_program_name);
+ fprintf (stderr, _("%s: unterminated single quote\n"),
+ guestfs_int_program_name);
pcmd.status = -1;
return pcmd;
}
- if (p[len+1] && (p[len+1] != ' ' && p[len+1] !=
'\t')) {
+ if (p[len + 1] && (p[len + 1] != ' ' && p[len + 1] !=
'\t')) {
fprintf (stderr,
_("%s: command arguments not separated by whitespace\n"),
guestfs_int_program_name);
@@ -855,12 +881,14 @@ parse_command_line (char *buf, int *exit_on_error_rtn)
return pcmd;
}
p[len] = '\0';
- pend = p[len+1] ? &p[len+2] : &p[len+1];
- } else if (*p == '|') {
+ pend = p[len + 1] ? &p[len + 2] : &p[len + 1];
+ }
+ else if (*p == '|') {
*p = '\0';
- pcmd.pipe = p+1;
+ pcmd.pipe = p + 1;
continue;
- } else if (*p != ' ' && *p != '\t') {
+ }
+ else if (*p != ' ' && *p != '\t') {
/* If the first character is a ~ then note that this parameter
* is a candidate for ~username expansion. NB this does not
* apply to quoted parameters.
@@ -869,10 +897,12 @@ parse_command_line (char *buf, int *exit_on_error_rtn)
len = strcspn (p, " \t");
if (p[len]) {
p[len] = '\0';
- pend = &p[len+1];
- } else
+ pend = &p[len + 1];
+ }
+ else
pend = &p[len];
- } else {
+ }
+ else {
fprintf (stderr, _("%s: internal error parsing string at
'%s'\n"),
guestfs_int_program_name, p);
abort ();
@@ -890,7 +920,8 @@ parse_command_line (char *buf, int *exit_on_error_rtn)
}
if (i == argv_len) {
- fprintf (stderr, _("%s: too many arguments\n"), guestfs_int_program_name);
+ fprintf (stderr, _("%s: too many arguments\n"),
+ guestfs_int_program_name);
pcmd.status = -1;
return pcmd;
}
@@ -905,10 +936,14 @@ static int
hexdigit (char d)
{
switch (d) {
- case '0'...'9': return d - '0';
- case 'a'...'f': return d - 'a' + 10;
- case 'A'...'F': return d - 'A' + 10;
- default: return -1;
+ case '0' ... '9':
+ return d - '0';
+ case 'a' ... 'f':
+ return d - 'a' + 10;
+ case 'A' ... 'F':
+ return d - 'A' + 10;
+ default:
+ return -1;
}
}
@@ -926,22 +961,42 @@ parse_quoted_string (char *p)
int m = 1, c;
switch (p[1]) {
- case '\\': break;
- case 'a': *p = '\a'; break;
- case 'b': *p = '\b'; break;
- case 'f': *p = '\f'; break;
- case 'n': *p = '\n'; break;
- case 'r': *p = '\r'; break;
- case 't': *p = '\t'; break;
- case 'v': *p = '\v'; break;
- case '"': *p = '"'; break;
- case '\'': *p = '\''; break;
- case '?': *p = '?'; break;
+ case '\\':
+ break;
+ case 'a':
+ *p = '\a';
+ break;
+ case 'b':
+ *p = '\b';
+ break;
+ case 'f':
+ *p = '\f';
+ break;
+ case 'n':
+ *p = '\n';
+ break;
+ case 'r':
+ *p = '\r';
+ break;
+ case 't':
+ *p = '\t';
+ break;
+ case 'v':
+ *p = '\v';
+ break;
+ case '"':
+ *p = '"';
+ break;
+ case '\'':
+ *p = '\'';
+ break;
+ case '?':
+ *p = '?';
+ break;
- case '0'...'7': /* octal escape - always 3 digits */
+ case '0' ... '7': /* octal escape - always 3 digits */
m = 3;
- if (p[2] >= '0' && p[2] <= '7' &&
- p[3] >= '0' && p[3] <= '7') {
+ if (p[2] >= '0' && p[2] <= '7' && p[3]
>= '0' && p[3] <= '7') {
c = (p[1] - '0') * 0100 + (p[2] - '0') * 010 + (p[3] -
'0');
if (c < 1 || c > 255)
goto error;
@@ -951,7 +1006,7 @@ parse_quoted_string (char *p)
goto error;
break;
- case 'x': /* hex escape - always 2 digits */
+ case 'x': /* hex escape - always 2 digits */
m = 3;
if (c_isxdigit (p[2]) && c_isxdigit (p[3])) {
c = hexdigit (p[2]) * 0x10 + hexdigit (p[3]);
@@ -965,16 +1020,18 @@ parse_quoted_string (char *p)
default:
error:
- fprintf (stderr, _("%s: invalid escape sequence in string (starting at
offset %d)\n"),
- guestfs_int_program_name, (int) (p - start));
+ fprintf (stderr, _("%s: invalid escape sequence in string "
+ "(starting at offset %d)\n"),
+ guestfs_int_program_name, (int)(p - start));
return -1;
}
- memmove (p+1, p+1+m, strlen (p+1+m) + 1);
+ memmove (p + 1, p + 1 + m, strlen (p + 1 + m) + 1);
}
}
if (!*p) {
- fprintf (stderr, _("%s: unterminated double quote\n"),
guestfs_int_program_name);
+ fprintf (stderr, _("%s: unterminated double quote\n"),
+ guestfs_int_program_name);
return -1;
}
@@ -1003,15 +1060,17 @@ execute_and_inline (const char *cmd, int global_exit_on_error)
exit_on_error = global_exit_on_error;
/* Chomp final line ending which parse_command_line would not expect. */
- if (n > 0 && line[n-1] == '\n')
- line[n-1] = '\0';
+ if (n > 0 && line[n - 1] == '\n')
+ line[n - 1] = '\0';
pcmd = parse_command_line (line, &exit_on_error);
if (pcmd.status == -1 && exit_on_error)
exit (EXIT_FAILURE);
if (pcmd.status == 1) {
- if (issue_command (pcmd.cmd, pcmd.argv, pcmd.pipe, exit_on_error) == -1) {
- if (exit_on_error) exit (EXIT_FAILURE);
+ if (issue_command (pcmd.cmd, pcmd.argv, pcmd.pipe, exit_on_error) ==
+ -1) {
+ if (exit_on_error)
+ exit (EXIT_FAILURE);
}
}
}
@@ -1033,7 +1092,8 @@ cmdline (char *argv[], size_t optind, size_t argc)
exit_on_error = 1;
- if (optind >= argc) return;
+ if (optind >= argc)
+ return;
cmd = argv[optind++];
if (STREQ (cmd, ":"))
@@ -1054,13 +1114,16 @@ cmdline (char *argv[], size_t optind, size_t argc)
optind++;
if (optind == argc) {
- if (issue_command (cmd, params, NULL, exit_on_error) == -1 && exit_on_error)
+ if (issue_command (cmd, params, NULL, exit_on_error) == -1 &&
+ exit_on_error)
exit (EXIT_FAILURE);
- } else {
+ }
+ else {
argv[optind] = NULL;
- if (issue_command (cmd, params, NULL, exit_on_error) == -1 && exit_on_error)
+ if (issue_command (cmd, params, NULL, exit_on_error) == -1 &&
+ exit_on_error)
exit (EXIT_FAILURE);
- cmdline (argv, optind+1, argc);
+ cmdline (argv, optind + 1, argc);
}
}
@@ -1101,7 +1164,7 @@ issue_command (const char *cmd, char *argv[], const char *pipecmd,
return -1;
}
- if (pid == 0) { /* Child process. */
+ if (pid == 0) { /* Child process. */
close (fd[1]);
if (dup2 (fd[0], 0) < 0) {
perror ("dup2 of stdin failed");
@@ -1141,11 +1204,11 @@ issue_command (const char *cmd, char *argv[], const char
*pipecmd,
if (argc == 0) {
display_help ();
r = 0;
- } else
+ }
+ else
r = display_command (argv[0]);
}
- else if (STRCASEEQ (cmd, "quit") ||
- STRCASEEQ (cmd, "exit") ||
+ else if (STRCASEEQ (cmd, "quit") || STRCASEEQ (cmd, "exit") ||
STRCASEEQ (cmd, "q")) {
quit = 1;
r = 0;
@@ -1192,10 +1255,9 @@ void
list_builtin_commands (void)
{
/* help and quit should appear at the top */
- printf ("%-20s %s\n",
- "help", _("display a list of commands or help on a
command"));
- printf ("%-20s %s\n",
- "quit", _("quit guestfish"));
+ printf ("%-20s %s\n", "help",
+ _("display a list of commands or help on a command"));
+ printf ("%-20s %s\n", "quit", _("quit guestfish"));
/* actions are printed after this (see list_commands) */
}
@@ -1211,15 +1273,15 @@ display_builtin_command (const char *cmd)
" help\n"));
return 0;
}
- else if (STRCASEEQ (cmd, "quit") ||
- STRCASEEQ (cmd, "exit") ||
+ else if (STRCASEEQ (cmd, "quit") || STRCASEEQ (cmd, "exit") ||
STRCASEEQ (cmd, "q")) {
printf (_("quit - quit guestfish\n"
" quit\n"));
return 0;
}
else {
- fprintf (stderr, _("%s: command not known, use -h to list all
commands\n"),
+ fprintf (stderr,
+ _("%s: command not known, use -h to list all commands\n"),
cmd);
return -1;
}
@@ -1244,8 +1306,8 @@ extended_help_message (void)
static void
error_cb (guestfs_h *g, void *data, const char *msg)
{
- fprintf (stderr, _("%s:%d: libguestfs: error: %s\n"),
- input_file, input_lineno, msg);
+ fprintf (stderr, _("%s:%d: libguestfs: error: %s\n"), input_file,
+ input_lineno, msg);
}
void
@@ -1263,7 +1325,7 @@ print_table (char *const *argv)
size_t i;
for (i = 0; argv[i] != NULL; i += 2)
- printf ("%s: %s\n", argv[i], argv[i+1]);
+ printf ("%s: %s\n", argv[i], argv[i + 1]);
}
/* Free strings from a non-NULL terminated char** */
@@ -1294,7 +1356,8 @@ parse_string_list (const char *str)
* or contain embedded single-quoted sections:
* This' is a sing'l'e to'ken
*
- * The latter may seem over-complicated, but it's what a normal shell does.
+ * The latter may seem over-complicated, but it's what a normal shell
+ * does.
* Not doing it risks surprising somebody.
*
* This outer loop is over complete tokens.
@@ -1308,9 +1371,12 @@ parse_string_list (const char *str)
char in_quote = 0;
- /* This loop is over token 'fragments'. A token can be in multiple bits if
- * it contains single quotes. We also treat both sides of an escaped quote
- * as separate fragments because we can't just copy it: we have to remove
+ /* This loop is over token 'fragments'. A token can be in multiple bits
+ * if
+ * it contains single quotes. We also treat both sides of an escaped
+ * quote
+ * as separate fragments because we can't just copy it: we have to
+ * remove
* the \.
*/
while (*p && (!c_isblank (*p) || in_quote)) {
@@ -1322,7 +1388,8 @@ parse_string_list (const char *str)
in_quote = !in_quote;
/* Skip the quote */
- p++; end++;
+ p++;
+ end++;
}
/* If we're in a quote, look for an end quote */
@@ -1348,12 +1415,12 @@ parse_string_list (const char *str)
tok = tok_new;
/* Check if we stopped on an escaped quote */
- if ('\'' == *end && end != p && *(end-1) ==
'\\') {
+ if ('\'' == *end && end != p && *(end - 1) ==
'\\') {
/* Add everything before \' to the token */
memcpy (&tok[tok_end], p, end - p - 1);
/* Add the quote */
- tok[tok_len-1] = '\'';
+ tok[tok_len - 1] = '\'';
/* Already processed the quote */
p = end + 1;
@@ -1386,13 +1453,13 @@ parse_string_list (const char *str)
char **argv_new = realloc (argv, sizeof (*argv) * argv_len);
if (NULL == argv_new) {
perror ("realloc");
- free_n_strings (argv, argv_len-1);
+ free_n_strings (argv, argv_len - 1);
free (tok);
exit (EXIT_FAILURE);
}
argv = argv_new;
- argv[argv_len-1] = tok;
+ argv[argv_len - 1] = tok;
}
}
@@ -1401,12 +1468,12 @@ parse_string_list (const char *str)
char **argv_new = realloc (argv, sizeof (*argv) * argv_len);
if (NULL == argv_new) {
perror ("realloc");
- free_n_strings (argv, argv_len-1);
+ free_n_strings (argv, argv_len - 1);
exit (EXIT_FAILURE);
}
argv = argv_new;
- argv[argv_len-1] = NULL;
+ argv[argv_len - 1] = NULL;
return argv;
}
@@ -1430,14 +1497,14 @@ initialize_readline (void)
* provide default values which can be overridden by the user if
* they wish.
*/
- (void) rl_variable_bind ("completion-ignore-case", "on");
+ (void)rl_variable_bind ("completion-ignore-case", "on");
/* Set up the history file. */
str = getenv ("HOME");
if (str) {
snprintf (histfile, sizeof histfile, "%s/.guestfish", str);
using_history ();
- (void) read_history (histfile);
+ (void)read_history (histfile);
}
/* Set up the prompt. */
@@ -1474,7 +1541,7 @@ cleanup_readline (void)
int fd;
if (histfile[0] != '\0') {
- fd = open (histfile, O_WRONLY|O_CREAT|O_NOCTTY|O_CLOEXEC, 0600);
+ fd = open (histfile, O_WRONLY | O_CREAT | O_NOCTTY | O_CLOEXEC, 0600);
if (fd == -1) {
perror (histfile);
return;
@@ -1482,9 +1549,9 @@ cleanup_readline (void)
close (fd);
#ifdef HAVE_APPEND_HISTORY
- (void) append_history (nr_history_lines, histfile);
+ (void)append_history (nr_history_lines, histfile);
#else
- (void) write_history (histfile);
+ (void)write_history (histfile);
#endif
clear_history ();
}
@@ -1519,8 +1586,8 @@ decode_ps1 (const char *str)
error (EXIT_FAILURE, errno, "malloc");
for (i = j = 0; i < len; ++i) {
- if (str[i] == '\\') { /* Start of an escape sequence. */
- if (i < len-1)
+ if (str[i] == '\\') { /* Start of an escape sequence. */
+ if (i < len - 1)
i++;
switch (str[i]) {
case '\\':
@@ -1544,7 +1611,7 @@ decode_ps1 (const char *str)
case 'r':
ret[j++] = '\r';
break;
- case '0'...'7':
+ case '0' ... '7':
ret[j++] = decode_ps1_octal (str, &i);
i--;
break;
@@ -1562,7 +1629,7 @@ decode_ps1 (const char *str)
}
ret[j] = '\0';
- return ret; /* caller frees */
+ return ret; /* caller frees */
}
static int
@@ -1599,7 +1666,7 @@ decode_ps1_hex (const char *s, size_t *i)
lim--;
}
- if (lim == 2) /* \x not followed by any hex digits */
+ if (lim == 2) /* \x not followed by any hex digits */
return '?';
return ret;
@@ -1639,7 +1706,8 @@ win_prefix (const char *path)
char *ret;
size_t i;
- /* If there is not a "win:..." prefix on the path, return strdup'd
string. */
+ /* If there is not a "win:..." prefix on the path, return strdup'd
string.
+ */
if (STRCASENEQLEN (path, "win:", 4)) {
ret = strdup (path);
if (ret == NULL)
@@ -1698,27 +1766,33 @@ win_prefix_drive_letter (char drive_letter, const char *path)
if (roots == NULL)
return NULL;
if (roots[0] == NULL) {
- fprintf (stderr, _("%s: to use Windows drive letters, you must inspect the guest
(\"-i\" option or run \"inspect-os\" command)\n"),
+ fprintf (stderr,
+ _("%s: to use Windows drive letters, you must inspect the "
+ "guest (\"-i\" option or run \"inspect-os\"
command)\n"),
guestfs_int_program_name);
return NULL;
}
drives = guestfs_inspect_get_drive_mappings (g, roots[0]);
if (drives == NULL || drives[0] == NULL) {
- fprintf (stderr, _("%s: to use Windows drive letters, this must be a Windows
guest\n"),
- guestfs_int_program_name);
+ fprintf (
+ stderr,
+ _ (
+ "%s: to use Windows drive letters, this must be a Windows guest\n"),
+ guestfs_int_program_name);
return NULL;
}
device = NULL;
for (i = 0; drives[i] != NULL; i += 2) {
if (c_tolower (drives[i][0]) == drive_letter && drives[i][1] == '\0')
{
- device = drives[i+1];
+ device = drives[i + 1];
break;
}
}
if (device == NULL) {
- fprintf (stderr, _("%s: drive '%c:' not found. To list available drives
do:\n inspect-get-drive-mappings %s\n"),
+ fprintf (stderr, _("%s: drive '%c:' not found. To list available
"
+ "drives do:\n inspect-get-drive-mappings %s\n"),
guestfs_int_program_name, drive_letter, roots[0]);
return NULL;
}
@@ -1731,20 +1805,21 @@ win_prefix_drive_letter (char drive_letter, const char *path)
mountpoint = NULL;
for (i = 0; mountpoints[i] != NULL; i += 2) {
if (STREQ (mountpoints[i], device)) {
- mountpoint = mountpoints[i+1];
+ mountpoint = mountpoints[i + 1];
break;
}
}
if (mountpoint == NULL) {
- fprintf (stderr, _("%s: to access '%c:', mount %s first. One way to do
this is:\n umount-all\n mount %s /\n"),
+ fprintf (stderr, _("%s: to access '%c:', mount %s first. One way to
"
+ "do this is:\n umount-all\n mount %s /\n"),
guestfs_int_program_name, drive_letter, device, device);
return NULL;
}
/* Rewrite the path, eg. if C: => /c then C:/foo => /c/foo */
- if (asprintf (&ret, "%s%s%s",
- mountpoint, STRNEQ (mountpoint, "/") ? "/" :
"", path) == -1) {
+ if (asprintf (&ret, "%s%s%s", mountpoint,
+ STRNEQ (mountpoint, "/") ? "/" : "", path)
== -1) {
perror ("asprintf");
return NULL;
}
@@ -1832,11 +1907,12 @@ file_in_heredoc (const char *endmarker)
size_t blen = strlen (buffer);
if (STREQLEN (buffer, endmarker, markerlen) &&
(blen == markerlen ||
- (blen == markerlen+1 && buffer[markerlen] == '\n')))
+ (blen == markerlen + 1 && buffer[markerlen] == '\n')))
goto found_end;
if (xwrite (fd, buffer, blen) == -1) {
- if (!write_error) perror ("write");
+ if (!write_error)
+ perror ("write");
write_error = 1;
/* continue reading up to the end marker */
}
@@ -1849,7 +1925,7 @@ file_in_heredoc (const char *endmarker)
guestfs_int_program_name, endmarker);
goto error2;
- found_end:
+found_end:
if (write_error) {
close (fd);
goto error2;
@@ -1862,10 +1938,10 @@ file_in_heredoc (const char *endmarker)
return file_in_tmpfile;
- error2:
+error2:
unlink (file_in_tmpfile);
- error1:
+error1:
free (file_in_tmpfile);
file_in_tmpfile = NULL;
return NULL;
@@ -1909,10 +1985,9 @@ file_out (const char *arg)
/* Callback which displays a progress bar. */
void
-progress_callback (guestfs_h *g, void *data,
- uint64_t event, int event_handle, int flags,
- const char *buf, size_t buf_len,
- const uint64_t *array, size_t array_len)
+progress_callback (guestfs_h *g, void *data, uint64_t event,
+ int event_handle, int flags, const char *buf,
+ size_t buf_len, const uint64_t *array, size_t array_len)
{
if (array_len < 4)
return;
diff --git a/fish/fish.h b/fish/fish.h
index df22e34..85b2987 100644
--- a/fish/fish.h
+++ b/fish/fish.h
@@ -36,7 +36,8 @@ extern int remote_control_csh;
extern const char *libvirt_uri;
extern int input_lineno;
-extern int issue_command (const char *cmd, char *argv[], const char *pipe, int
rc_exit_on_error_flag);
+extern int issue_command (const char *cmd, char *argv[], const char *pipe,
+ int rc_exit_on_error_flag);
extern void list_builtin_commands (void);
extern int display_builtin_command (const char *cmd);
extern void print_strings (char *const *argv);
@@ -49,7 +50,10 @@ extern char *file_in (const char *arg);
extern void free_file_in (char *s);
extern char *file_out (const char *arg);
extern void extended_help_message (void);
-extern void progress_callback (guestfs_h *g, void *data, uint64_t event, int
event_handle, int flags, const char *buf, size_t buf_len, const uint64_t *array, size_t
array_len);
+extern void progress_callback (guestfs_h *g, void *data, uint64_t event,
+ int event_handle, int flags, const char *buf,
+ size_t buf_len, const uint64_t *array,
+ size_t array_len);
/* in cmds.c (auto-generated) */
extern void list_commands (void);
@@ -71,8 +75,8 @@ extern void free_event_handlers (void);
extern int event_bitmask_of_event_set (const char *arg, uint64_t *);
/* in alloc.c */
-extern int alloc_disk (const char *filename, const char *size,
- int add, int sparse);
+extern int alloc_disk (const char *filename, const char *size, int add,
+ int sparse);
extern int parse_size (const char *str, off_t *size_rtn);
/* in help.c */
@@ -90,7 +94,9 @@ extern prep_data *create_prepared_file (const char *type_string,
const char *filename);
extern void prepare_drive (const char *filename, prep_data *data,
const char *device);
-extern void prep_error (prep_data *data, const char *filename, const char *fs, ...)
__attribute__((noreturn, format (printf,3,4)));
+extern void prep_error (prep_data *data, const char *filename,
+ const char *fs, ...)
+ __attribute__((noreturn, format (printf, 3, 4)));
extern void free_prep_data (void *data);
/* in prep_lv.c */
@@ -107,8 +113,6 @@ extern char *try_tilde_expansion (char *path);
/* This should just list all the built-in commands so they can
* be added to the generated auto-completion code.
*/
-#define BUILTIN_COMMANDS_FOR_COMPLETION \
- "help", \
- "quit", "exit", "q"
+#define BUILTIN_COMMANDS_FOR_COMPLETION "help", "quit",
"exit", "q"
#endif /* FISH_H */
diff --git a/fish/glob.c b/fish/glob.c
index 5bf1ad6..9757f24 100644
--- a/fish/glob.c
+++ b/fish/glob.c
@@ -34,10 +34,12 @@
static char **expand_pathname (guestfs_h *g, const char *path);
static char **expand_devicename (guestfs_h *g, const char *device);
-static int add_strings_matching (char **pp, const char *glob, char ***ret, size_t
*size_r);
+static int add_strings_matching (char **pp, const char *glob, char ***ret,
+ size_t *size_r);
static int add_string (const char *str, char ***ret, size_t *size_r);
static char **single_element_list (const char *element);
-static int glob_issue (char *cmd, size_t argc, char ***globs, size_t *posn, size_t
*count, int *r);
+static int glob_issue (char *cmd, size_t argc, char ***globs, size_t *posn,
+ size_t *count, int *r);
int
run_glob (const char *cmd, size_t argc, char *argv[])
@@ -120,8 +122,8 @@ run_glob (const char *cmd, size_t argc, char *argv[])
goto error;
}
- /* Free resources. */
- error:
+/* Free resources. */
+error:
for (i = 1; i < argc; ++i)
if (globs[i])
guestfs_int_free_string_list (globs[i]);
@@ -134,8 +136,9 @@ expand_pathname (guestfs_h *g, const char *path)
char **pp;
pp = guestfs_glob_expand (g, path);
- if (pp == NULL) { /* real error in glob_expand */
- fprintf (stderr, _("glob: guestfs_glob_expand call failed: %s\n"), path);
+ if (pp == NULL) { /* real error in glob_expand */
+ fprintf (stderr, _("glob: guestfs_glob_expand call failed: %s\n"),
+ path);
return NULL;
}
@@ -179,24 +182,32 @@ expand_devicename (guestfs_h *g, const char *device)
const char *lvm2[] = { "lvm2", NULL };
pp = guestfs_list_devices (g);
- if (pp == NULL) goto error;
- if (add_strings_matching (pp, device, &ret, &size) == -1) goto error;
+ if (pp == NULL)
+ goto error;
+ if (add_strings_matching (pp, device, &ret, &size) == -1)
+ goto error;
guestfs_int_free_string_list (pp);
pp = guestfs_list_partitions (g);
- if (pp == NULL) goto error;
- if (add_strings_matching (pp, device, &ret, &size) == -1) goto error;
+ if (pp == NULL)
+ goto error;
+ if (add_strings_matching (pp, device, &ret, &size) == -1)
+ goto error;
guestfs_int_free_string_list (pp);
pp = guestfs_list_md_devices (g);
- if (pp == NULL) goto error;
- if (add_strings_matching (pp, device, &ret, &size) == -1) goto error;
+ if (pp == NULL)
+ goto error;
+ if (add_strings_matching (pp, device, &ret, &size) == -1)
+ goto error;
guestfs_int_free_string_list (pp);
- if (guestfs_feature_available (g, (char **) lvm2)) {
+ if (guestfs_feature_available (g, (char **)lvm2)) {
pp = guestfs_lvs (g);
- if (pp == NULL) goto error;
- if (add_strings_matching (pp, device, &ret, &size) == -1) goto error;
+ if (pp == NULL)
+ goto error;
+ if (add_strings_matching (pp, device, &ret, &size) == -1)
+ goto error;
guestfs_int_free_string_list (pp);
pp = NULL;
}
@@ -206,7 +217,7 @@ expand_devicename (guestfs_h *g, const char *device)
ret = single_element_list (device);
return ret;
- error:
+error:
if (pp)
guestfs_int_free_string_list (pp);
if (ret)
@@ -221,8 +232,8 @@ expand_devicename (guestfs_h *g, const char *device)
* size.
*/
static int
-add_strings_matching (char **pp, const char *glob,
- char ***ret, size_t *size_r)
+add_strings_matching (char **pp, const char *glob, char ***ret,
+ size_t *size_r)
{
size_t i;
int r;
@@ -230,7 +241,7 @@ add_strings_matching (char **pp, const char *glob,
for (i = 0; pp[i] != NULL; ++i) {
errno = 0;
r = fnmatch (glob, pp[i], FNM_PATHNAME);
- if (r == 0) { /* matches - add it */
+ if (r == 0) { /* matches - add it */
if (add_string (pp[i], ret, size_r) == -1)
return -1;
}
@@ -239,8 +250,8 @@ add_strings_matching (char **pp, const char *glob,
* numbers for errors. It doesn't always set errno. Do our
* best here to record the error state.
*/
- fprintf (stderr, "glob: fnmatch: error (r = %d, errno = %d)\n",
- r, errno);
+ fprintf (stderr, "glob: fnmatch: error (r = %d, errno = %d)\n", r,
+ errno);
return -1;
}
}
@@ -297,14 +308,13 @@ single_element_list (const char *element)
}
static int
-glob_issue (char *cmd, size_t argc,
- char ***globs, size_t *posn, size_t *count,
- int *r)
+glob_issue (char *cmd, size_t argc, char ***globs, size_t *posn,
+ size_t *count, int *r)
{
size_t i;
CLEANUP_FREE char **argv = NULL;
- argv = malloc (sizeof (char *) * (argc+1));
+ argv = malloc (sizeof (char *) * (argc + 1));
if (argv == NULL) {
perror ("malloc");
return -1;
@@ -313,20 +323,20 @@ glob_issue (char *cmd, size_t argc,
argv[0] = cmd;
argv[argc] = NULL;
- again:
+again:
for (i = 1; i < argc; ++i)
argv[i] = globs[i][posn[i]];
if (issue_command (argv[0], &argv[1], NULL, 0) == -1)
- *r = -1; /* ... but don't exit */
+ *r = -1; /* ... but don't exit */
- for (i = argc-1; i >= 1; --i) {
+ for (i = argc - 1; i >= 1; --i) {
posn[i]++;
if (posn[i] < count[i])
break;
posn[i] = 0;
}
- if (i == 0) /* All done. */
+ if (i == 0) /* All done. */
return 0;
goto again;
diff --git a/fish/help.c b/fish/help.c
index cf00dce..d923445 100644
--- a/fish/help.c
+++ b/fish/help.c
@@ -35,25 +35,23 @@ void
display_help (void)
{
if (guestfs_is_config (g))
- printf (_(
-"Add disk images to examine using the -a or -d options, or the 'add'
command.\n"
-"Or create a new disk image using -N, or the 'alloc' or 'sparse'
commands.\n"
-"Once you have done this, use the 'run' command.\n"
- ));
+ printf (_("Add disk images to examine using the -a or -d options, or "
+ "the 'add' command.\n"
+ "Or create a new disk image using -N, or the 'alloc' or
"
+ "'sparse' commands.\n"
+ "Once you have done this, use the 'run' command.\n"));
else
- printf (_(
-"Find out what filesystems are available using 'list-filesystems' and
then\n"
-"mount them to examine or modify the contents using 'mount-ro' or\n"
-"'mount'.\n"
- ));
+ printf (_ (
+ "Find out what filesystems are available using 'list-filesystems'
"
+ "and then\n"
+ "mount them to examine or modify the contents using 'mount-ro'
or\n"
+ "'mount'.\n"));
printf ("\n");
- printf (_(
-"For more information about a command, use 'help cmd'.\n"
-"\n"
-"To read the manual, type 'man'.\n"
- ));
+ printf (_("For more information about a command, use 'help cmd'.\n"
+ "\n"
+ "To read the manual, type 'man'.\n"));
printf ("\n");
}
diff --git a/fish/hexedit.c b/fish/hexedit.c
index e30352f..b54189f 100644
--- a/fish/hexedit.c
+++ b/fish/hexedit.c
@@ -30,7 +30,7 @@
#include "fish.h"
-#define MAX_DOWNLOAD_SIZE (16 * 1024 * 1024)
+#define MAX_DOWNLOAD_SIZE (16 * 1024 * 1024)
#define MAX_DOWNLOAD_SIZE_TEXT "16MB"
static off_t get_size (const char *filename);
@@ -49,24 +49,23 @@ run_hexedit (const char *cmd, size_t argc, char *argv[])
return -1;
if (size == 0) {
- fprintf (stderr,
- _("hexedit: %s is a zero length file or device\n"), filename);
+ fprintf (stderr, _("hexedit: %s is a zero length file or device\n"),
+ filename);
return -1;
}
off_t start;
off_t max;
- if (argc == 1) { /* hexedit device */
+ if (argc == 1) { /* hexedit device */
/* Check we're not going to download a huge file. */
if (size > MAX_DOWNLOAD_SIZE) {
- fprintf (stderr,
- _("hexedit: %s is larger than %s. You must supply a limit using\n"
- " 'hexedit %s <max>' (eg. 'hexedit %s 1M') or a
range using\n"
- " 'hexedit %s <start> <max>'.\n"),
- filename, MAX_DOWNLOAD_SIZE_TEXT,
- filename, filename,
- filename);
+ fprintf (
+ stderr,
+ _("hexedit: %s is larger than %s. You must supply a limit using\n"
+ " 'hexedit %s <max>' (eg. 'hexedit %s 1M') or a
range using\n"
+ " 'hexedit %s <start> <max>'.\n"),
+ filename, MAX_DOWNLOAD_SIZE_TEXT, filename, filename, filename);
return -1;
}
@@ -74,12 +73,13 @@ run_hexedit (const char *cmd, size_t argc, char *argv[])
max = size;
}
else {
- if (argc == 3) { /* hexedit device start max */
+ if (argc == 3) { /* hexedit device start max */
if (parse_size (argv[1], &start) == -1)
return -1;
if (parse_size (argv[2], &max) == -1)
return -1;
- } else { /* hexedit device max */
+ }
+ else { /* hexedit device max */
start = 0;
if (parse_size (argv[1], &max) == -1)
return -1;
@@ -197,5 +197,5 @@ get_size (const char *filename)
/* This case should be safe because we always compile with
* 64 bit file offsets.
*/
- return (off_t) size;
+ return (off_t)size;
}
diff --git a/fish/inspect.c b/fish/inspect.c
index 0b93e83..d5633bd 100644
--- a/fish/inspect.c
+++ b/fish/inspect.c
@@ -29,8 +29,9 @@
#include "guestfs.h"
-/* These definitions ensure we get all extern definitions from the header. */
-#define COMPILING_GUESTFISH 1
+/* These definitions ensure we get all extern definitions from the header.
+ */
+#define COMPILING_GUESTFISH 1
#define COMPILING_VIRT_INSPECTOR 1
#include "options.h"
@@ -42,16 +43,16 @@ static char *root = NULL;
static int
compare_keys_len (const void *p1, const void *p2)
{
- const char *key1 = * (char * const *) p1;
- const char *key2 = * (char * const *) p2;
+ const char *key1 = *(char *const *)p1;
+ const char *key2 = *(char *const *)p2;
return strlen (key1) - strlen (key2);
}
static int
compare_keys (const void *p1, const void *p2)
{
- const char *key1 = * (char * const *) p1;
- const char *key2 = * (char * const *) p2;
+ const char *key1 = *(char *const *)p1;
+ const char *key2 = *(char *const *)p2;
return strcasecmp (key1, key2);
}
@@ -69,43 +70,48 @@ inspect_mount_handle (guestfs_h *g)
exit (EXIT_FAILURE);
if (roots[0] == NULL) {
- fprintf (stderr,
- _("%s: no operating system was found on this disk\n"
- "\n"
- "If using guestfish '-i' option, remove this option and
instead\n"
- "use the commands 'run' followed by
'list-filesystems'.\n"
- "You can then mount filesystems you want by hand using the\n"
- "'mount' or 'mount-ro' command.\n"
- "\n"
- "If using guestmount '-i', remove this option and choose
the\n"
- "filesystem(s) you want to see by manually adding '-m'
option(s).\n"
- "Use 'virt-filesystems' to see what filesystems are
available.\n"
- "\n"
- "If using other virt tools, this disk image won't work\n"
- "with these tools. Use the guestfish equivalent commands\n"
- "(see the virt tool manual page).\n"),
- guestfs_int_program_name);
+ fprintf (
+ stderr,
+ _ (
+ "%s: no operating system was found on this disk\n"
+ "\n"
+ "If using guestfish '-i' option, remove this option and
instead\n"
+ "use the commands 'run' followed by
'list-filesystems'.\n"
+ "You can then mount filesystems you want by hand using the\n"
+ "'mount' or 'mount-ro' command.\n"
+ "\n"
+ "If using guestmount '-i', remove this option and choose
the\n"
+ "filesystem(s) you want to see by manually adding '-m'
option(s).\n"
+ "Use 'virt-filesystems' to see what filesystems are
available.\n"
+ "\n"
+ "If using other virt tools, this disk image won't work\n"
+ "with these tools. Use the guestfish equivalent commands\n"
+ "(see the virt tool manual page).\n"),
+ guestfs_int_program_name);
guestfs_int_free_string_list (roots);
exit (EXIT_FAILURE);
}
if (roots[1] != NULL) {
- fprintf (stderr,
- _("%s: multi-boot operating systems are not supported\n"
- "\n"
- "If using guestfish '-i' option, remove this option and
instead\n"
- "use the commands 'run' followed by
'list-filesystems'.\n"
- "You can then mount filesystems you want by hand using the\n"
- "'mount' or 'mount-ro' command.\n"
- "\n"
- "If using guestmount '-i', remove this option and choose
the\n"
- "filesystem(s) you want to see by manually adding '-m'
option(s).\n"
- "Use 'virt-filesystems' to see what filesystems are
available.\n"
- "\n"
- "If using other virt tools, multi-boot operating systems won't
work\n"
- "with these tools. Use the guestfish equivalent commands\n"
- "(see the virt tool manual page).\n"),
- guestfs_int_program_name);
+ fprintf (
+ stderr,
+ _ (
+ "%s: multi-boot operating systems are not supported\n"
+ "\n"
+ "If using guestfish '-i' option, remove this option and
instead\n"
+ "use the commands 'run' followed by
'list-filesystems'.\n"
+ "You can then mount filesystems you want by hand using the\n"
+ "'mount' or 'mount-ro' command.\n"
+ "\n"
+ "If using guestmount '-i', remove this option and choose
the\n"
+ "filesystem(s) you want to see by manually adding '-m'
option(s).\n"
+ "Use 'virt-filesystems' to see what filesystems are
available.\n"
+ "\n"
+ "If using other virt tools, multi-boot operating systems won't "
+ "work\n"
+ "with these tools. Use the guestfish equivalent commands\n"
+ "(see the virt tool manual page).\n"),
+ guestfs_int_program_name);
guestfs_int_free_string_list (roots);
exit (EXIT_FAILURE);
}
@@ -131,17 +137,16 @@ inspect_mount_root (guestfs_h *g, const char *root)
* mounting the filesystems in the correct order.
*/
qsort (mountpoints, guestfs_int_count_strings (mountpoints) / 2,
- 2 * sizeof (char *),
- compare_keys_len);
+ 2 * sizeof (char *), compare_keys_len);
size_t i;
size_t mount_errors = 0;
for (i = 0; mountpoints[i] != NULL; i += 2) {
int r;
if (!read_only)
- r = guestfs_mount (g, mountpoints[i+1], mountpoints[i]);
+ r = guestfs_mount (g, mountpoints[i + 1], mountpoints[i]);
else
- r = guestfs_mount_ro (g, mountpoints[i+1], mountpoints[i]);
+ r = guestfs_mount_ro (g, mountpoints[i + 1], mountpoints[i]);
if (r == -1) {
/* If the "/" filesystem could not be mounted, give up, else
* just count the errors and print a warning.
@@ -153,7 +158,8 @@ inspect_mount_root (guestfs_h *g, const char *root)
}
if (mount_errors)
- fprintf (stderr, _("%s: some filesystems could not be mounted
(ignored)\n"),
+ fprintf (stderr,
+ _("%s: some filesystems could not be mounted (ignored)\n"),
guestfs_int_program_name);
}
@@ -177,18 +183,17 @@ print_inspect_prompt (void)
/* Sort by key. */
qsort (mountpoints, guestfs_int_count_strings (mountpoints) / 2,
- 2 * sizeof (char *),
- compare_keys);
+ 2 * sizeof (char *), compare_keys);
for (i = 0; mountpoints[i] != NULL; i += 2) {
/* Try to make the device name canonical for printing, but don't
* worry if this fails.
*/
CLEANUP_FREE char *dev =
- guestfs_canonical_device_name (g, mountpoints[i+1]);
+ guestfs_canonical_device_name (g, mountpoints[i + 1]);
- printf (_("%s mounted on %s\n"),
- dev ? dev : mountpoints[i+1], mountpoints[i]);
+ printf (_("%s mounted on %s\n"), dev ? dev : mountpoints[i + 1],
+ mountpoints[i]);
}
}
diff --git a/fish/keys.c b/fish/keys.c
index 4749cfc..5ee436a 100644
--- a/fish/keys.c
+++ b/fish/keys.c
@@ -77,10 +77,10 @@ read_key (const char *param)
}
/* Remove the terminating \n if there is one. */
- if (len > 0 && ret[len-1] == '\n')
- ret[len-1] = '\0';
+ if (len > 0 && ret[len - 1] == '\n')
+ ret[len - 1] = '\0';
- error:
+error:
/* Restore echo, close file descriptor. */
if (tty && tcset) {
printf ("\n");
diff --git a/fish/man.c b/fish/man.c
index 85b7a82..fe5279d 100644
--- a/fish/man.c
+++ b/fish/man.c
@@ -33,12 +33,14 @@ int
run_man (const char *cmd, size_t argc, char *argv[])
{
if (argc != 0) {
- fprintf (stderr, _("use 'man' without parameters to open the
manual\n"));
+ fprintf (stderr,
+ _("use 'man' without parameters to open the manual\n"));
return -1;
}
/* We have to restore SIGPIPE to the default action around the
- * external 'man' command to avoid the warning 'gzip: stdout: Broken
pipe'.
+ * external 'man' command to avoid the warning 'gzip: stdout: Broken
+ * pipe'.
*/
struct sigaction sa, old_sa;
memset (&sa, 0, sizeof sa);
@@ -55,9 +57,8 @@ run_man (const char *cmd, size_t argc, char *argv[])
char status_string[80];
fprintf (stderr, "%s\n",
- guestfs_int_exit_status_to_string (r, "man",
- status_string,
- sizeof status_string));
+ guestfs_int_exit_status_to_string (r, "man", status_string,
+ sizeof status_string));
return -1;
}
diff --git a/fish/options.c b/fish/options.c
index ab5131b..d80d153 100644
--- a/fish/options.c
+++ b/fish/options.c
@@ -98,7 +98,8 @@ add_drives_handle (guestfs_h *g, struct drv *drv, char next_drive)
struct guestfs_add_drive_opts_argv ad_optargs;
if (next_drive > 'z')
- error (EXIT_FAILURE, 0, _("too many drives added on the command line"));
+ error (EXIT_FAILURE, 0,
+ _("too many drives added on the command line"));
if (drv) {
next_drive = add_drives (drv->next, next_drive);
@@ -183,8 +184,7 @@ add_drives_handle (guestfs_h *g, struct drv *drv, char next_drive)
case drv_N:
/* -N option is not affected by --ro */
r = guestfs_add_drive_opts (g, drv->N.filename,
- GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
- -1);
+ GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw", -1);
if (r == -1)
exit (EXIT_FAILURE);
@@ -212,7 +212,9 @@ add_drives_handle (guestfs_h *g, struct drv *drv, char next_drive)
return next_drive;
}
-static void display_mountpoints_on_failure (const char *mp_device, const char
*user_supplied_options);
+static void
+display_mountpoints_on_failure (const char *mp_device,
+ const char *user_supplied_options);
/* List is built in reverse order, so mount them in reverse order. */
void
@@ -235,8 +237,7 @@ mount_mps (struct mp *mp)
r = guestfs_mount_vfs (g, options, mp->fstype, mp->device,
mp->mountpoint);
else
- r = guestfs_mount_options (g, options, mp->device,
- mp->mountpoint);
+ r = guestfs_mount_options (g, options, mp->device, mp->mountpoint);
if (r == -1) {
display_mountpoints_on_failure (mp->device, mp->options);
exit (EXIT_FAILURE);
@@ -261,11 +262,15 @@ display_mountpoints_on_failure (const char *mp_device,
guestfs_int_program_name, mp_device);
if (user_supplied_options)
- fprintf (stderr, _("%s: Check mount(8) man page to ensure options
'%s'\n"
- "%s: are supported by the filesystem that is being
mounted.\n"),
- guestfs_int_program_name, user_supplied_options, guestfs_int_program_name);
+ fprintf (
+ stderr,
+ _("%s: Check mount(8) man page to ensure options '%s'\n"
+ "%s: are supported by the filesystem that is being mounted.\n"),
+ guestfs_int_program_name, user_supplied_options,
+ guestfs_int_program_name);
- fprintf (stderr, _("%s: Did you mean to mount one of these filesystems?\n"),
+ fprintf (stderr,
+ _("%s: Did you mean to mount one of these filesystems?\n"),
guestfs_int_program_name);
for (i = 0; fses[i] != NULL; i += 2) {
@@ -278,8 +283,8 @@ display_mountpoints_on_failure (const char *mp_device,
subvolume = guestfs_mountable_subvolume (g, fses[i]);
if (subvolume == NULL && guestfs_last_errno (g) != EINVAL)
error (EXIT_FAILURE, 0,
- _("cannot determine the subvolume for %s: %s (%d)"),
- fses[i], guestfs_last_error (g), guestfs_last_errno (g));
+ _("cannot determine the subvolume for %s: %s (%d)"), fses[i],
+ guestfs_last_error (g), guestfs_last_errno (g));
guestfs_pop_error_handler (g);
@@ -287,19 +292,21 @@ display_mountpoints_on_failure (const char *mp_device,
if (device && subvolume) {
if (asprintf (&p, "%s:/:subvol=%s", device, subvolume) == -1)
error (EXIT_FAILURE, errno, "asprintf");
- } else {
+ }
+ else {
p = guestfs_canonical_device_name (g, fses[i]);
}
fprintf (stderr, "%s: \t%s (%s)\n", guestfs_int_program_name,
- p ? p : fses[i], fses[i+1]);
+ p ? p : fses[i], fses[i + 1]);
}
}
void
free_drives (struct drv *drv)
{
- if (!drv) return;
+ if (!drv)
+ return;
free_drives (drv->next);
free (drv->device);
@@ -332,7 +339,7 @@ free_drives (struct drv *drv)
/* nothing */
break;
#endif
- default: ; /* keep GCC happy */
+ default:; /* keep GCC happy */
}
free (drv);
}
@@ -340,7 +347,8 @@ free_drives (struct drv *drv)
void
free_mps (struct mp *mp)
{
- if (!mp) return;
+ if (!mp)
+ return;
free_mps (mp->next);
/* The drive and mountpoint fields are not allocated
@@ -371,7 +379,8 @@ void
display_long_options (const struct option *long_options)
{
while (long_options->name) {
- if (STRNEQ (long_options->name, "long-options") && STRNEQ
(long_options->name, "short-options"))
+ if (STRNEQ (long_options->name, "long-options") &&
+ STRNEQ (long_options->name, "short-options"))
printf ("--%s\n", long_options->name);
long_options++;
}
diff --git a/fish/options.h b/fish/options.h
index bbe38aa..b269fbf 100644
--- a/fish/options.h
+++ b/fish/options.h
@@ -42,32 +42,33 @@ extern const char *libvirt_uri;
struct drv {
struct drv *next;
- char *device; /* Device name inside the appliance (eg. /dev/sda).
- * This is filled in when we add the drives in
- * add_drives. Note that guests (-d option) may
- * have multiple drives, in which case this is the
- * first drive, and nr_drives is the number of
- * drives used.
- */
- int nr_drives; /* number of drives for this guest */
+ char *device; /* Device name inside the appliance (eg. /dev/sda).
+ * This is filled in when we add the drives in
+ * add_drives. Note that guests (-d option) may
+ * have multiple drives, in which case this is the
+ * first drive, and nr_drives is the number of
+ * drives used.
+ */
+ int nr_drives; /* number of drives for this guest */
enum {
- drv_a, /* -a option (without URI) */
- drv_uri, /* -a option (with URI) */
- drv_d, /* -d option */
+ drv_a, /* -a option (without URI) */
+ drv_uri, /* -a option (with URI) */
+ drv_d, /* -d option */
#if COMPILING_GUESTFISH
- drv_N, /* -N option (guestfish only) */
+ drv_N, /* -N option (guestfish only) */
#endif
#if COMPILING_VIRT_RESCUE
- drv_scratch, /* --scratch option (virt-rescue only) */
+ drv_scratch, /* --scratch option (virt-rescue only) */
#endif
} type;
- union {
+ union
+ {
struct {
- char *filename; /* disk filename */
- const char *format; /* format (NULL == autodetect) */
- const char *cachemode;/* cachemode (NULL == default) */
- const char *discard; /* discard (NULL == disable) */
+ char *filename; /* disk filename */
+ const char *format; /* format (NULL == autodetect) */
+ const char *cachemode; /* cachemode (NULL == default) */
+ const char *discard; /* discard (NULL == disable) */
} a;
struct {
char *path; /* disk path */
@@ -79,18 +80,18 @@ struct drv {
const char *orig_uri; /* original URI (for error messages etc.) */
} uri;
struct {
- char *guest; /* guest name */
+ char *guest; /* guest name */
} d;
#if COMPILING_GUESTFISH
struct {
- char *filename; /* disk filename (testX.img) */
- void *data; /* prepared type */
- void (*data_free)(void*); /* function to free 'data' */
+ char *filename; /* disk filename (testX.img) */
+ void *data; /* prepared type */
+ void (*data_free) (void *); /* function to free 'data' */
} N;
#endif
#if COMPILING_VIRT_RESCUE
struct {
- int64_t size; /* size of the disk in bytes */
+ int64_t size; /* size of the disk in bytes */
} scratch;
#endif
};
@@ -133,112 +134,107 @@ extern void inspect_mount_root (guestfs_h *g, const char *root);
extern char *read_key (const char *param);
/* in options.c */
-extern void option_a (const char *arg, const char *format, struct drv **drvsp);
+extern void option_a (const char *arg, const char *format,
+ struct drv **drvsp);
extern void option_d (const char *arg, struct drv **drvsp);
-extern char add_drives_handle (guestfs_h *g, struct drv *drv, char next_drive);
+extern char add_drives_handle (guestfs_h *g, struct drv *drv,
+ char next_drive);
#define add_drives(drv, next_drive) add_drives_handle (g, drv, next_drive)
extern void mount_mps (struct mp *mp);
extern void free_drives (struct drv *drv);
extern void free_mps (struct mp *mp);
extern void display_short_options (const char *) __attribute__((noreturn));
-extern void display_long_options (const struct option *) __attribute__((noreturn));
+extern void display_long_options (const struct option *)
+ __attribute__((noreturn));
-#define OPTION_a \
- do { \
- option_a (optarg, format, &drvs); \
- format_consumed = true; \
+#define OPTION_a \
+ do { \
+ option_a (optarg, format, &drvs); \
+ format_consumed = true; \
} while (0)
-#define OPTION_A \
- do { \
- option_a (optarg, format, &drvs2); \
- format_consumed = true; \
+#define OPTION_A \
+ do { \
+ option_a (optarg, format, &drvs2); \
+ format_consumed = true; \
} while (0)
-#define OPTION_c \
- libvirt_uri = optarg
+#define OPTION_c libvirt_uri = optarg
-#define OPTION_d \
- option_d (optarg, &drvs)
+#define OPTION_d option_d (optarg, &drvs)
-#define OPTION_D \
- option_d (optarg, &drvs2)
+#define OPTION_D option_d (optarg, &drvs2)
-#define OPTION_format \
- do { \
- if (!optarg || STREQ (optarg, "")) \
- format = NULL; \
- else \
- format = optarg; \
- format_consumed = false; \
+#define OPTION_format \
+ do { \
+ if (!optarg || STREQ (optarg, "")) \
+ format = NULL; \
+ else \
+ format = optarg; \
+ format_consumed = false; \
} while (0)
-#define OPTION_i \
- inspector = 1
-
-#define OPTION_m \
- mp = malloc (sizeof (struct mp)); \
- if (!mp) \
- error (EXIT_FAILURE, errno, "malloc"); \
- mp->fstype = NULL; \
- mp->options = NULL; \
- mp->mountpoint = (char *) "/"; \
- p = strchr (optarg, ':'); \
- if (p) { \
- *p = '\0'; \
- p++; \
- mp->mountpoint = p; \
- p = strchr (p, ':'); \
- if (p) { \
- *p = '\0'; \
- p++; \
- mp->options = p; \
- p = strchr (p, ':'); \
- if (p) { \
- *p = '\0'; \
- p++; \
- mp->fstype = p; \
- } \
- } \
- } \
- mp->device = optarg; \
- mp->next = mps; \
+#define OPTION_i inspector = 1
+
+#define OPTION_m \
+ mp = malloc (sizeof (struct mp)); \
+ if (!mp) \
+ error (EXIT_FAILURE, errno, "malloc"); \
+ mp->fstype = NULL; \
+ mp->options = NULL; \
+ mp->mountpoint = (char *)"/"; \
+ p = strchr (optarg, ':'); \
+ if (p) { \
+ *p = '\0'; \
+ p++; \
+ mp->mountpoint = p; \
+ p = strchr (p, ':'); \
+ if (p) { \
+ *p = '\0'; \
+ p++; \
+ mp->options = p; \
+ p = strchr (p, ':'); \
+ if (p) { \
+ *p = '\0'; \
+ p++; \
+ mp->fstype = p; \
+ } \
+ } \
+ } \
+ mp->device = optarg; \
+ mp->next = mps; \
mps = mp
-#define OPTION_n \
- guestfs_set_autosync (g, 0)
+#define OPTION_n guestfs_set_autosync (g, 0)
-#define OPTION_r \
- read_only = 1
+#define OPTION_r read_only = 1
-#define OPTION_v \
- verbose++; \
+#define OPTION_v \
+ verbose++; \
guestfs_set_verbose (g, verbose)
#define OPTION_V \
{ \
- printf ("%s %s\n", \
- guestfs_int_program_name, \
- PACKAGE_VERSION_FULL); \
+ printf ("%s %s\n", guestfs_int_program_name, PACKAGE_VERSION_FULL); \
exit (EXIT_SUCCESS); \
}
-#define OPTION_w \
- if (read_only) { \
- fprintf (stderr, _("%s: cannot mix --ro and --rw options\n"), \
- guestfs_int_program_name); \
- exit (EXIT_FAILURE); \
+#define OPTION_w \
+ if (read_only) { \
+ fprintf (stderr, _("%s: cannot mix --ro and --rw options\n"), \
+ guestfs_int_program_name); \
+ exit (EXIT_FAILURE); \
}
-#define OPTION_x \
- guestfs_set_trace (g, 1)
+#define OPTION_x guestfs_set_trace (g, 1)
#define CHECK_OPTION_format_consumed \
do { \
if (!format_consumed) { \
- fprintf (stderr, \
- _("%s: --format parameter must appear before -a parameter\n"),
\
- guestfs_int_program_name); \
+ fprintf ( \
+ stderr, \
+ _("%s: --format parameter must appear before -a parameter\n"), \
+ guestfs_int_program_name); \
exit (EXIT_FAILURE); \
} \
} while (0)
diff --git a/fish/prep-boot.c b/fish/prep-boot.c
index 45a5a8f..b9bb4ec 100644
--- a/fish/prep-boot.c
+++ b/fish/prep-boot.c
@@ -38,7 +38,8 @@ prep_prelaunch_bootroot (const char *filename, prep_data *data)
}
void
-prep_postlaunch_bootroot (const char *filename, prep_data *data, const char *device)
+prep_postlaunch_bootroot (const char *filename, prep_data *data,
+ const char *device)
{
off_t bootsize;
if (parse_size (data->params[3], &bootsize) == -1)
@@ -53,12 +54,12 @@ prep_postlaunch_bootroot (const char *filename, prep_data *data, const
char *dev
prep_error (data, filename, _("failed to partition disk: %s"),
guestfs_last_error (g));
- off_t lastbootsect = 64 + bootsize/sector - 1;
+ off_t lastbootsect = 64 + bootsize / sector - 1;
if (guestfs_part_add (g, device, "primary", 64, lastbootsect) == -1)
prep_error (data, filename, _("failed to add boot partition: %s"),
guestfs_last_error (g));
- if (guestfs_part_add (g, device, "primary", lastbootsect+1, -64) == -1)
+ if (guestfs_part_add (g, device, "primary", lastbootsect + 1, -64) == -1)
prep_error (data, filename, _("failed to add root partition: %s"),
guestfs_last_error (g));
@@ -81,14 +82,16 @@ void
prep_prelaunch_bootrootlv (const char *filename, prep_data *data)
{
if (vg_lv_parse (data->params[0], NULL, NULL) == -1)
- prep_error (data, filename, _("incorrect format for LV name, use
'/dev/VG/LV'"));
+ prep_error (data, filename,
+ _("incorrect format for LV name, use '/dev/VG/LV'"));
if (alloc_disk (filename, data->params[3], 0, 1) == -1)
prep_error (data, filename, _("failed to allocate disk"));
}
void
-prep_postlaunch_bootrootlv (const char *filename, prep_data *data, const char *device)
+prep_postlaunch_bootrootlv (const char *filename, prep_data *data,
+ const char *device)
{
off_t bootsize;
if (parse_size (data->params[4], &bootsize) == -1)
@@ -103,19 +106,20 @@ prep_postlaunch_bootrootlv (const char *filename, prep_data *data,
const char *d
prep_error (data, filename, _("failed to partition disk: %s"),
guestfs_last_error (g));
- off_t lastbootsect = 64 + bootsize/sector - 1;
+ off_t lastbootsect = 64 + bootsize / sector - 1;
if (guestfs_part_add (g, device, "primary", 64, lastbootsect) == -1)
prep_error (data, filename, _("failed to add boot partition: %s"),
guestfs_last_error (g));
- if (guestfs_part_add (g, device, "primary", lastbootsect+1, -64) == -1)
+ if (guestfs_part_add (g, device, "primary", lastbootsect + 1, -64) == -1)
prep_error (data, filename, _("failed to add root partition: %s"),
guestfs_last_error (g));
CLEANUP_FREE char *vg;
CLEANUP_FREE char *lv;
if (vg_lv_parse (data->params[0], &vg, &lv) == -1)
- prep_error (data, filename, _("incorrect format for LV name, use
'/dev/VG/LV'"));
+ prep_error (data, filename,
+ _("incorrect format for LV name, use '/dev/VG/LV'"));
CLEANUP_FREE char *part;
if (asprintf (&part, "%s1", device) == -1)
@@ -128,13 +132,13 @@ prep_postlaunch_bootrootlv (const char *filename, prep_data *data,
const char *d
if (asprintf (&part2, "%s2", device) == -1)
error (EXIT_FAILURE, errno, "asprintf");
if (guestfs_pvcreate (g, part2) == -1)
- prep_error (data, filename, _("failed to create PV: %s: %s"),
- part2, guestfs_last_error (g));
+ prep_error (data, filename, _("failed to create PV: %s: %s"), part2,
+ guestfs_last_error (g));
char *parts[] = { part2, NULL };
if (guestfs_vgcreate (g, vg, parts) == -1)
- prep_error (data, filename, _("failed to create VG: %s: %s"),
- vg, guestfs_last_error (g));
+ prep_error (data, filename, _("failed to create VG: %s: %s"), vg,
+ guestfs_last_error (g));
/* Create the largest possible LV. */
if (guestfs_lvcreate_free (g, lv, vg, 100) == -1)
diff --git a/fish/prep-disk.c b/fish/prep-disk.c
index 246b9f1..4c4f16d 100644
--- a/fish/prep-disk.c
+++ b/fish/prep-disk.c
@@ -36,7 +36,8 @@ prep_prelaunch_disk (const char *filename, prep_data *data)
}
void
-prep_postlaunch_disk (const char *filename, prep_data *data, const char *device)
+prep_postlaunch_disk (const char *filename, prep_data *data,
+ const char *device)
{
/* nothing */
}
diff --git a/fish/prep-fs.c b/fish/prep-fs.c
index 6670aa6..6d0005d 100644
--- a/fish/prep-fs.c
+++ b/fish/prep-fs.c
@@ -38,7 +38,8 @@ prep_prelaunch_fs (const char *filename, prep_data *data)
}
void
-prep_postlaunch_fs (const char *filename, prep_data *data, const char *device)
+prep_postlaunch_fs (const char *filename, prep_data *data,
+ const char *device)
{
if (guestfs_part_disk (g, device, data->params[2]) == -1)
prep_error (data, filename, _("failed to partition disk: %s"),
diff --git a/fish/prep-lv.c b/fish/prep-lv.c
index 93de9ae..23995a9 100644
--- a/fish/prep-lv.c
+++ b/fish/prep-lv.c
@@ -50,7 +50,7 @@ vg_lv_parse (const char *device, char **vg, char **lv)
}
if (lv) {
- *lv = strdup (p+1);
+ *lv = strdup (p + 1);
if (*lv == NULL)
error (EXIT_FAILURE, errno, "strndup");
}
@@ -62,14 +62,16 @@ void
prep_prelaunch_lv (const char *filename, prep_data *data)
{
if (vg_lv_parse (data->params[0], NULL, NULL) == -1)
- prep_error (data, filename, _("incorrect format for LV name, use
'/dev/VG/LV'"));
+ prep_error (data, filename,
+ _("incorrect format for LV name, use '/dev/VG/LV'"));
if (alloc_disk (filename, data->params[1], 0, 1) == -1)
prep_error (data, filename, _("failed to allocate disk"));
}
void
-prep_postlaunch_lv (const char *filename, prep_data *data, const char *device)
+prep_postlaunch_lv (const char *filename, prep_data *data,
+ const char *device)
{
if (guestfs_part_disk (g, device, data->params[2]) == -1)
prep_error (data, filename, _("failed to partition disk: %s"),
@@ -78,20 +80,21 @@ prep_postlaunch_lv (const char *filename, prep_data *data, const char
*device)
CLEANUP_FREE char *vg;
CLEANUP_FREE char *lv;
if (vg_lv_parse (data->params[0], &vg, &lv) == -1)
- prep_error (data, filename, _("incorrect format for LV name, use
'/dev/VG/LV'"));
+ prep_error (data, filename,
+ _("incorrect format for LV name, use '/dev/VG/LV'"));
CLEANUP_FREE char *part;
if (asprintf (&part, "%s1", device) == -1)
error (EXIT_FAILURE, errno, "asprintf");
if (guestfs_pvcreate (g, part) == -1)
- prep_error (data, filename, _("failed to create PV: %s: %s"),
- part, guestfs_last_error (g));
+ prep_error (data, filename, _("failed to create PV: %s: %s"), part,
+ guestfs_last_error (g));
char *parts[] = { part, NULL };
if (guestfs_vgcreate (g, vg, parts) == -1)
- prep_error (data, filename, _("failed to create VG: %s: %s"),
- vg, guestfs_last_error (g));
+ prep_error (data, filename, _("failed to create VG: %s: %s"), vg,
+ guestfs_last_error (g));
/* Create the largest possible LV. */
if (guestfs_lvcreate_free (g, lv, vg, 100) == -1)
@@ -103,14 +106,16 @@ void
prep_prelaunch_lvfs (const char *filename, prep_data *data)
{
if (vg_lv_parse (data->params[0], NULL, NULL) == -1)
- prep_error (data, filename, _("incorrect format for LV name, use
'/dev/VG/LV'"));
+ prep_error (data, filename,
+ _("incorrect format for LV name, use '/dev/VG/LV'"));
if (alloc_disk (filename, data->params[2], 0, 1) == -1)
prep_error (data, filename, _("failed to allocate disk"));
}
void
-prep_postlaunch_lvfs (const char *filename, prep_data *data, const char *device)
+prep_postlaunch_lvfs (const char *filename, prep_data *data,
+ const char *device)
{
if (guestfs_part_disk (g, device, data->params[3]) == -1)
prep_error (data, filename, _("failed to partition disk: %s"),
@@ -119,20 +124,21 @@ prep_postlaunch_lvfs (const char *filename, prep_data *data, const
char *device)
CLEANUP_FREE char *vg;
CLEANUP_FREE char *lv;
if (vg_lv_parse (data->params[0], &vg, &lv) == -1)
- prep_error (data, filename, _("incorrect format for LV name, use
'/dev/VG/LV'"));
+ prep_error (data, filename,
+ _("incorrect format for LV name, use '/dev/VG/LV'"));
CLEANUP_FREE char *part;
if (asprintf (&part, "%s1", device) == -1)
error (EXIT_FAILURE, errno, "asprintf");
if (guestfs_pvcreate (g, part) == -1)
- prep_error (data, filename, _("failed to create PV: %s: %s"),
- part, guestfs_last_error (g));
+ prep_error (data, filename, _("failed to create PV: %s: %s"), part,
+ guestfs_last_error (g));
char *parts[] = { part, NULL };
if (guestfs_vgcreate (g, vg, parts) == -1)
- prep_error (data, filename, _("failed to create VG: %s: %s"),
- vg, guestfs_last_error (g));
+ prep_error (data, filename, _("failed to create VG: %s: %s"), vg,
+ guestfs_last_error (g));
/* Create the largest possible LV. */
if (guestfs_lvcreate_free (g, lv, vg, 100) == -1)
diff --git a/fish/prep-part.c b/fish/prep-part.c
index 83363f5..b433efb 100644
--- a/fish/prep-part.c
+++ b/fish/prep-part.c
@@ -36,7 +36,8 @@ prep_prelaunch_part (const char *filename, prep_data *data)
}
void
-prep_postlaunch_part (const char *filename, prep_data *data, const char *device)
+prep_postlaunch_part (const char *filename, prep_data *data,
+ const char *device)
{
if (guestfs_part_disk (g, device, data->params[1]) == -1)
prep_error (data, filename, _("failed to partition disk: %s"),
diff --git a/fish/prep.c b/fish/prep.c
index dfa5507..a3cb87a 100644
--- a/fish/prep.c
+++ b/fish/prep.c
@@ -55,10 +55,8 @@ guestfish -N %-8s - %s\n\
printf ("\n");
for (j = 0; j < preps[i].nr_params; ++j) {
printf (" ");
- printf (_("<%s> %s (default: %s)\n"),
- preps[i].params[j].pname,
- preps[i].params[j].pdesc,
- preps[i].params[j].pdefault);
+ printf (_("<%s> %s (default: %s)\n"), preps[i].params[j].pname,
+ preps[i].params[j].pdesc, preps[i].params[j].pdefault);
}
}
@@ -102,7 +100,8 @@ parse_type_string (const char *type_string)
if (i == NR_PREPS)
error (EXIT_FAILURE, 0,
_("-N parameter '%s': no such prepared disk image known.\n"
- "Use 'guestfish -N help' to list possible values for the -N
parameter."),
+ "Use 'guestfish -N help' to list possible values for the -N
"
+ "parameter."),
type_string);
prep_data *data = malloc (sizeof *data);
@@ -117,11 +116,12 @@ parse_type_string (const char *type_string)
error (EXIT_FAILURE, errno, "malloc");
for (i = 0; i < data->prep->nr_params; ++i)
- data->params[i] = (char *) data->prep->params[i].pdefault;
+ data->params[i] = (char *)data->prep->params[i].pdefault;
/* Parse the optional parameters. */
const char *p = type_string + len;
- if (*p) p++; /* skip colon char */
+ if (*p)
+ p++; /* skip colon char */
i = 0;
while (*p) {
@@ -131,7 +131,8 @@ parse_type_string (const char *type_string)
error (EXIT_FAILURE, errno, "strndup");
p += len;
- if (*p) p++; /* skip colon char */
+ if (*p)
+ p++; /* skip colon char */
i++;
}
@@ -143,8 +144,7 @@ parse_type_string (const char *type_string)
* is just used for error messages.
*/
void
-prepare_drive (const char *filename, prep_data *data,
- const char *device)
+prepare_drive (const char *filename, prep_data *data, const char *device)
{
if (data->prep->postlaunch)
data->prep->postlaunch (filename, data, device);
@@ -153,9 +153,10 @@ prepare_drive (const char *filename, prep_data *data,
void
prep_error (prep_data *data, const char *filename, const char *fs, ...)
{
- fprintf (stderr,
- _("guestfish: error creating prepared disk image '%s' on
'%s': "),
- data->orig_type_string, filename);
+ fprintf (
+ stderr,
+ _("guestfish: error creating prepared disk image '%s' on '%s':
"),
+ data->orig_type_string, filename);
va_list args;
va_start (args, fs);
diff --git a/fish/progress.c b/fish/progress.c
index 363419e..2fca555 100644
--- a/fish/progress.c
+++ b/fish/progress.c
@@ -50,8 +50,8 @@ extern const char *UP;
* Checked in a test program against answers given by Wolfram Alpha.
*/
struct rmsd {
- double a; /* mean */
- double i; /* number of samples */
+ double a; /* mean */
+ double i; /* number of samples */
double q;
};
@@ -88,13 +88,13 @@ rmsd_get_standard_deviation (const struct rmsd *r)
}
struct progress_bar {
- double start; /* start time of command */
- size_t count; /* number of progress notifications per cmd */
- struct rmsd rmsd; /* running mean and standard deviation */
+ double start; /* start time of command */
+ size_t count; /* number of progress notifications per cmd */
+ struct rmsd rmsd; /* running mean and standard deviation */
int have_terminfo;
int utf8_mode;
int machine_readable;
- FILE *fp; /* output device, only used when !dumb mode */
+ FILE *fp; /* output device, only used when !dumb mode */
};
struct progress_bar *
@@ -111,7 +111,8 @@ progress_bar_init (unsigned flags)
bar->machine_readable = 1;
bar->utf8_mode = 0;
bar->have_terminfo = 0;
- } else {
+ }
+ else {
bar->machine_readable = 0;
bar->utf8_mode = STREQ (nl_langinfo (CODESET), "UTF-8");
@@ -174,19 +175,19 @@ spinner (struct progress_bar *bar, size_t count)
* I prefer something which doesn't point, just spins.
*/
/* Black pointing triangle. */
- //static const char *us[] = { "\u25b2", "\u25b6",
"\u25bc", "\u25c0" };
+ // static const char *us[] = { "\u25b2", "\u25b6",
"\u25bc", "\u25c0" };
/* White pointing triangle. */
- //static const char *us[] = { "\u25b3", "\u25b7",
"\u25bd", "\u25c1" };
+ // static const char *us[] = { "\u25b3", "\u25b7",
"\u25bd", "\u25c1" };
/* Circle with half black. */
static const char *us[] = { "\u25d0", "\u25d3", "\u25d1",
"\u25d2" };
/* White square white quadrant. */
- //static const char *us[] = { "\u25f0", "\u25f3",
"\u25f2", "\u25f1" };
+ // static const char *us[] = { "\u25f0", "\u25f3",
"\u25f2", "\u25f1" };
/* White circle white quadrant. */
- //static const char *us[] = { "\u25f4", "\u25f7",
"\u25f6", "\u25f5" };
+ // static const char *us[] = { "\u25f4", "\u25f7",
"\u25f6", "\u25f5" };
/* Black triangle. */
- //static const char *us[] = { "\u25e2", "\u25e3",
"\u25e4", "\u25e5" };
+ // static const char *us[] = { "\u25e2", "\u25e3",
"\u25e4", "\u25e5" };
/* Spinning arrow in 8 directions. */
- //static const char *us[] = { "\u2190", "\u2196",
"\u2191", "\u2197",
+ // static const char *us[] = { "\u2190", "\u2196",
"\u2191", "\u2197",
// "\u2192", "\u2198",
"\u2193", "\u2199" };
/* ASCII spinner. */
@@ -237,7 +238,7 @@ estimate_remaining_time (struct progress_bar *bar, double ratio)
double mean = rmsd_get_mean (&bar->rmsd);
double sd = rmsd_get_standard_deviation (&bar->rmsd);
- if (fabs (total_time - mean) >= 2.0*sd)
+ if (fabs (total_time - mean) >= 2.0 * sd)
return -1.0;
/* Don't return early estimates. */
@@ -265,8 +266,8 @@ estimate_remaining_time (struct progress_bar *bar, double ratio)
#define COLS_OVERHEAD 15
void
-progress_bar_set (struct progress_bar *bar,
- uint64_t position, uint64_t total)
+progress_bar_set (struct progress_bar *bar, uint64_t position,
+ uint64_t total)
{
size_t i, cols;
int pulse_mode;
@@ -278,11 +279,14 @@ progress_bar_set (struct progress_bar *bar,
dumb:
printf ("%" PRIu64 "/%" PRIu64 "\n", position, total);
fflush (stdout);
- } else {
- cols = tgetnum ((char *) "co");
- if (cols < 32) goto dumb;
+ }
+ else {
+ cols = tgetnum ((char *)"co");
+ if (cols < 32)
+ goto dumb;
- /* Send progress bar output to /dev/tty if we could open it, else stdout. */
+ /* Send progress bar output to /dev/tty if we could open it, else
+ * stdout. */
fp = bar->fp;
if (!fp)
fp = stdout;
@@ -301,8 +305,11 @@ progress_bar_set (struct progress_bar *bar,
/* Find out if we're in "pulse mode". */
pulse_mode = position == 0 && total == 1;
- ratio = (double) position / total;
- if (ratio < 0) ratio = 0; else if (ratio > 1) ratio = 1;
+ ratio = (double)position / total;
+ if (ratio < 0)
+ ratio = 0;
+ else if (ratio > 1)
+ ratio = 1;
if (pulse_mode) {
fprintf (fp, "%s --- ", spinner (bar, bar->count));
@@ -320,21 +327,25 @@ progress_bar_set (struct progress_bar *bar,
s_dot = "\u2592";
s_dash = "\u2550";
s_close = "\u27e7";
- } else {
- s_open = "["; s_dot = "#"; s_dash = "-"; s_close =
"]";
+ }
+ else {
+ s_open = "[";
+ s_dot = "#";
+ s_dash = "-";
+ s_close = "]";
}
fputs (s_open, fp);
if (!pulse_mode) {
- size_t dots = ratio * (double) (cols - COLS_OVERHEAD);
+ size_t dots = ratio * (double)(cols - COLS_OVERHEAD);
for (i = 0; i < dots; ++i)
fputs (s_dot, fp);
for (i = dots; i < cols - COLS_OVERHEAD; ++i)
fputs (s_dash, fp);
}
- else { /* "Pulse mode": the progress bar just pulses. */
+ else { /* "Pulse mode": the progress bar just pulses. */
for (i = 0; i < cols - COLS_OVERHEAD; ++i) {
int cc = (bar->count * 3 - i) % (cols - COLS_OVERHEAD);
if (cc >= 0 && cc <= 3)
@@ -354,14 +365,16 @@ progress_bar_set (struct progress_bar *bar,
estimate /= 60. * 60.;
int hh = floor (estimate);
fprintf (fp, ">%dh", hh);
- } else if (estimate >= 100.0 * 60.0 /* >= 100 minutes */) {
+ }
+ else if (estimate >= 100.0 * 60.0 /* >= 100 minutes */) {
/* Display hours<h>minutes */
estimate /= 60. * 60.;
int hh = floor (estimate);
double ignore;
int mm = floor (modf (estimate, &ignore) * 60.);
fprintf (fp, "%02dh%02d", hh, mm);
- } else if (estimate >= 0.0) {
+ }
+ else if (estimate >= 0.0) {
/* Display minutes:seconds */
estimate /= 60.;
int mm = floor (estimate);
diff --git a/fish/progress.h b/fish/progress.h
index 4fc0eaf..99641a5 100644
--- a/fish/progress.h
+++ b/fish/progress.h
@@ -36,7 +36,8 @@ extern void progress_bar_reset (struct progress_bar *);
/* This should be called from the progress bar callback. It displays
* the progress bar.
*/
-extern void progress_bar_set (struct progress_bar *, uint64_t position, uint64_t total);
+extern void progress_bar_set (struct progress_bar *, uint64_t position,
+ uint64_t total);
/* Free up progress bar handle and resources. */
extern void progress_bar_free (struct progress_bar *);
diff --git a/fish/rc.c b/fish/rc.c
index bc8d31c..5363c4e 100644
--- a/fish/rc.c
+++ b/fish/rc.c
@@ -41,7 +41,7 @@
/* Because this is a Unix domain socket, the total path length must be
* under 108 bytes.
*/
-#define SOCKET_DIR "/tmp/.guestfish-%ju" /* euid */
+#define SOCKET_DIR "/tmp/.guestfish-%ju" /* euid */
#define SOCKET_PATH "/tmp/.guestfish-%ju/socket-%ju" /* euid, pid */
static void
@@ -53,19 +53,19 @@ create_sockdir (void)
struct stat statbuf;
/* Create the directory, and ensure it is owned by the user. */
- snprintf (dir, sizeof dir, SOCKET_DIR, (uintmax_t) euid);
+ snprintf (dir, sizeof dir, SOCKET_DIR, (uintmax_t)euid);
r = mkdir (dir, 0700);
if (r == -1 && errno != EEXIST)
error:
- error (EXIT_FAILURE, errno, "%s", dir);
+ error (EXIT_FAILURE, errno, "%s", dir);
if (lstat (dir, &statbuf) == -1)
goto error;
- if (!S_ISDIR (statbuf.st_mode) ||
- (statbuf.st_mode & 0777) != 0700 ||
+ if (!S_ISDIR (statbuf.st_mode) || (statbuf.st_mode & 0777) != 0700 ||
statbuf.st_uid != euid)
- error (EXIT_FAILURE, 0,
- _("'%s' is not a directory or has insecure owner or
permissions"),
- dir);
+ error (
+ EXIT_FAILURE, 0,
+ _("'%s' is not a directory or has insecure owner or
permissions"),
+ dir);
}
static void
@@ -76,7 +76,7 @@ create_sockpath (pid_t pid, char *sockpath, size_t len,
create_sockdir ();
- snprintf (sockpath, len, SOCKET_PATH, (uintmax_t) euid, (uintmax_t) pid);
+ snprintf (sockpath, len, SOCKET_PATH, (uintmax_t)euid, (uintmax_t)pid);
addr->sun_family = AF_UNIX;
strcpy (addr->sun_path, sockpath);
@@ -88,8 +88,8 @@ static void
receive_stdout (int s)
{
static struct cmsghdr *cmptr = NULL, *h;
- struct msghdr msg;
- struct iovec iov[1];
+ struct msghdr msg;
+ struct iovec iov[1];
/* Our 1 byte buffer */
char buf[1];
@@ -107,20 +107,20 @@ receive_stdout (int s)
/* Initialise the msghdr to receive zero byte */
iov[0].iov_base = buf;
- iov[0].iov_len = 1;
- msg.msg_iov = iov;
- msg.msg_iovlen = 1;
+ iov[0].iov_len = 1;
+ msg.msg_iov = iov;
+ msg.msg_iovlen = 1;
/* Initialise the control data */
- msg.msg_control = cmptr;
- msg.msg_controllen = controllen;
+ msg.msg_control = cmptr;
+ msg.msg_controllen = controllen;
/* Read a message from the socket */
ssize_t n = recvmsg (s, &msg, 0);
if (n < 0)
error (EXIT_FAILURE, errno, "recvmsg stdout fd");
- h = CMSG_FIRSTHDR(&msg);
+ h = CMSG_FIRSTHDR (&msg);
if (NULL == h) {
fprintf (stderr, "didn't receive a stdout file descriptor\n");
}
@@ -140,22 +140,22 @@ static void
send_stdout (int s)
{
static struct cmsghdr *cmptr = NULL;
- struct msghdr msg;
- struct iovec iov[1];
+ struct msghdr msg;
+ struct iovec iov[1];
/* Our 1 byte dummy buffer */
char buf[1];
/* Don't specify a destination */
memset (&msg, 0, sizeof msg);
- msg.msg_name = NULL;
+ msg.msg_name = NULL;
msg.msg_namelen = 0;
/* Initialise the msghdr to send zero byte */
iov[0].iov_base = buf;
- iov[0].iov_len = 1;
- msg.msg_iov = iov;
- msg.msg_iovlen = 1;
+ iov[0].iov_len = 1;
+ msg.msg_iov = iov;
+ msg.msg_iovlen = 1;
/* Initialize the zero byte */
buf[0] = 0;
@@ -167,12 +167,12 @@ send_stdout (int s)
error (EXIT_FAILURE, errno, "malloc");
}
cmptr->cmsg_level = SOL_SOCKET;
- cmptr->cmsg_type = SCM_RIGHTS;
- cmptr->cmsg_len = controllen;
+ cmptr->cmsg_type = SCM_RIGHTS;
+ cmptr->cmsg_len = controllen;
/* Add control header to the message */
- msg.msg_control = cmptr;
- msg.msg_controllen = controllen;
+ msg.msg_control = cmptr;
+ msg.msg_controllen = controllen;
/* Add STDOUT to the control data */
void *data = CMSG_DATA (cmptr);
@@ -246,11 +246,11 @@ rc_listen (void)
pid = getpid ();
create_sockpath (pid, sockpath, sizeof sockpath, &addr);
- sock = socket (AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0);
+ sock = socket (AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
if (sock == -1)
error (EXIT_FAILURE, errno, "socket");
unlink (sockpath);
- if (bind (sock, (struct sockaddr *) &addr, sizeof addr) == -1)
+ if (bind (sock, (struct sockaddr *)&addr, sizeof addr) == -1)
error (EXIT_FAILURE, errno, "bind: %s", sockpath);
if (listen (sock, 4) == -1)
error (EXIT_FAILURE, errno, "listen: %s", sockpath);
@@ -267,29 +267,34 @@ rc_listen (void)
if (s == -1)
perror ("accept");
else {
- receive_stdout(s);
+ receive_stdout (s);
fp = fdopen (s, "r+");
xdrstdio_create (&xdr, fp, XDR_DECODE);
if (!xdr_guestfish_hello (&xdr, &hello)) {
- fprintf (stderr, _("guestfish: protocol error: could not read
'hello' message\n"));
+ fprintf (
+ stderr,
+ _ (
+ "guestfish: protocol error: could not read 'hello'
message\n"));
goto error;
}
if (STRNEQ (hello.vers, PACKAGE_VERSION)) {
- fprintf (stderr, _("guestfish: protocol error: version mismatch, server
version '%s' does not match client version '%s'. The two versions must
match exactly.\n"),
- PACKAGE_VERSION,
- hello.vers);
- xdr_free ((xdrproc_t) xdr_guestfish_hello, (char *) &hello);
+ fprintf (stderr,
+ _("guestfish: protocol error: version mismatch, server "
+ "version '%s' does not match client version '%s'.
The "
+ "two versions must match exactly.\n"),
+ PACKAGE_VERSION, hello.vers);
+ xdr_free ((xdrproc_t)xdr_guestfish_hello, (char *)&hello);
goto error;
}
- xdr_free ((xdrproc_t) xdr_guestfish_hello, (char *) &hello);
+ xdr_free ((xdrproc_t)xdr_guestfish_hello, (char *)&hello);
while (xdr_guestfish_call (&xdr, &call)) {
/* We have to extend and NULL-terminate the argv array. */
argc = call.args.args_len;
- argv = realloc (call.args.args_val, (argc+1) * sizeof (char *));
+ argv = realloc (call.args.args_val, (argc + 1) * sizeof (char *));
if (argv == NULL)
error (EXIT_FAILURE, errno, "realloc");
call.args.args_val = argv;
@@ -305,7 +310,7 @@ rc_listen (void)
/* Run the command. */
reply.r = issue_command (call.cmd, argv, NULL, 0);
- xdr_free ((xdrproc_t) xdr_guestfish_call, (char *) &call);
+ xdr_free ((xdrproc_t)xdr_guestfish_call, (char *)&call);
/* RHBZ#802389: If the command is quit, close the handle right
* away. Note that the main while loop will exit preventing
@@ -318,7 +323,7 @@ rc_listen (void)
/* Send the reply. */
xdrstdio_create (&xdr2, fp, XDR_ENCODE);
- (void) xdr_guestfish_reply (&xdr2, &reply);
+ (void)xdr_guestfish_reply (&xdr2, &reply);
xdr_destroy (&xdr2);
/* Exit on error? */
@@ -329,15 +334,16 @@ rc_listen (void)
}
error:
- xdr_destroy (&xdr); /* NB. This doesn't close 'fp'. */
- fclose (fp); /* Closes the underlying socket 's'. */
+ xdr_destroy (&xdr); /* NB. This doesn't close 'fp'. */
+ fclose (fp); /* Closes the underlying socket 's'. */
}
}
unlink (sockpath);
close (sock);
- /* This returns to 'fish.c', where it jumps to global cleanups and exits. */
+ /* This returns to 'fish.c', where it jumps to global cleanups and exits.
+ */
}
/* Remote control client. */
@@ -357,37 +363,42 @@ rc_remote (int pid, const char *cmd, size_t argc, char *argv[],
memset (&reply, 0, sizeof reply);
/* This is fine as long as we never try to xdr_free this struct. */
- hello.vers = (char *) PACKAGE_VERSION;
+ hello.vers = (char *)PACKAGE_VERSION;
/* Check the other end is still running. */
if (kill (pid, 0) == -1) {
- fprintf (stderr, _("guestfish: remote: looks like the server is not
running\n"));
+ fprintf (
+ stderr,
+ _("guestfish: remote: looks like the server is not running\n"));
return -1;
}
create_sockpath (pid, sockpath, sizeof sockpath, &addr);
- sock = socket (AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0);
+ sock = socket (AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
if (sock == -1) {
perror ("socket");
return -1;
}
- if (connect (sock, (struct sockaddr *) &addr, sizeof addr) == -1) {
+ if (connect (sock, (struct sockaddr *)&addr, sizeof addr) == -1) {
perror (sockpath);
- fprintf (stderr, _("guestfish: remote: looks like the server is not
running\n"));
+ fprintf (
+ stderr,
+ _("guestfish: remote: looks like the server is not running\n"));
close (sock);
return -1;
}
- send_stdout(sock);
+ send_stdout (sock);
/* Send the greeting. */
fp = fdopen (sock, "r+");
xdrstdio_create (&xdr, fp, XDR_ENCODE);
if (!xdr_guestfish_hello (&xdr, &hello)) {
- fprintf (stderr, _("guestfish: protocol error: could not send initial greeting
to server\n"));
+ fprintf (stderr, _("guestfish: protocol error: could not send initial "
+ "greeting to server\n"));
xdr_destroy (&xdr);
fclose (fp);
return -1;
@@ -396,12 +407,13 @@ rc_remote (int pid, const char *cmd, size_t argc, char *argv[],
/* Send the command. The server supports reading multiple commands
* per connection, but this code only ever sends one command.
*/
- call.cmd = (char *) cmd;
+ call.cmd = (char *)cmd;
call.args.args_len = argc;
call.args.args_val = argv;
call.exit_on_error = exit_on_error;
if (!xdr_guestfish_call (&xdr, &call)) {
- fprintf (stderr, _("guestfish: protocol error: could not send initial greeting
to server\n"));
+ fprintf (stderr, _("guestfish: protocol error: could not send initial "
+ "greeting to server\n"));
xdr_destroy (&xdr);
fclose (fp);
return -1;
@@ -412,7 +424,10 @@ rc_remote (int pid, const char *cmd, size_t argc, char *argv[],
xdrstdio_create (&xdr, fp, XDR_DECODE);
if (!xdr_guestfish_reply (&xdr, &reply)) {
- fprintf (stderr, _("guestfish: protocol error: could not decode reply from
server\n"));
+ fprintf (
+ stderr,
+ _ (
+ "guestfish: protocol error: could not decode reply from server\n"));
xdr_destroy (&xdr);
fclose (fp);
return -1;
diff --git a/fish/reopen.c b/fish/reopen.c
index ffe5509..1672586 100644
--- a/fish/reopen.c
+++ b/fish/reopen.c
@@ -49,7 +49,8 @@ run_reopen (const char *cmd, size_t argc, char *argv[])
*/
g2 = guestfs_create ();
if (g2 == NULL) {
- fprintf (stderr, _("reopen: guestfs_create: failed to create handle\n"));
+ fprintf (stderr,
+ _("reopen: guestfs_create: failed to create handle\n"));
return -1;
}
diff --git a/fish/setenv.c b/fish/setenv.c
index 5c6c08f..9031a72 100644
--- a/fish/setenv.c
+++ b/fish/setenv.c
@@ -32,7 +32,8 @@ run_setenv (const char *cmd, size_t argc, char *argv[])
const char *value;
if (argc != 2) {
- fprintf (stderr, _("use '%s VAR value' to set an environment
variable\n"),
+ fprintf (stderr,
+ _("use '%s VAR value' to set an environment variable\n"),
cmd);
return -1;
}
diff --git a/fish/supported.c b/fish/supported.c
index f54aee1..a218802 100644
--- a/fish/supported.c
+++ b/fish/supported.c
@@ -53,7 +53,7 @@ run_supported (const char *cmd, size_t argc, char *argv[])
int r = guestfs_available (g, gg);
const char *str = r == 0 ? _("yes") : _("no");
- printf ("%*s %s\n", (int) len, groups[i], str);
+ printf ("%*s %s\n", (int)len, groups[i], str);
}
/* Restore error handler. */
diff --git a/fish/tilde.c b/fish/tilde.c
index 0d7dfa2..7e1276f 100644
--- a/fish/tilde.c
+++ b/fish/tilde.c
@@ -43,9 +43,9 @@ try_tilde_expansion (char *str)
assert (str[0] == '~');
/* Expand "~" to current user's home directory. */
- if (str[1] == '\0') /* ~ */
+ if (str[1] == '\0') /* ~ */
return expand_home (str, NULL);
- else if (str[1] == '/') /* ~/... */
+ else if (str[1] == '/') /* ~/... */
return expand_home (str, &str[1]);
/* Try expanding the part up to the following '\0' or '/' as a
@@ -54,7 +54,7 @@ try_tilde_expansion (char *str)
else {
const char *home, *rest;
size_t len = strcspn (&str[1], "/");
- rest = &str[1+len];
+ rest = &str[1 + len];
home = find_home_for_username (&str[1], len);
diff --git a/fish/time.c b/fish/time.c
index 3d1c7bc..acf9d9d 100644
--- a/fish/time.c
+++ b/fish/time.c
@@ -45,12 +45,11 @@ run_time (const char *cmd, size_t argc, char *argv[])
gettimeofday (&end_t, NULL);
- start_us = (int64_t) start_t.tv_sec * 1000000 + start_t.tv_usec;
- end_us = (int64_t) end_t.tv_sec * 1000000 + end_t.tv_usec;
+ start_us = (int64_t)start_t.tv_sec * 1000000 + start_t.tv_usec;
+ end_us = (int64_t)end_t.tv_sec * 1000000 + end_t.tv_usec;
elapsed_us = end_us - start_us;
- printf ("elapsed time: %d.%02d seconds\n",
- (int) (elapsed_us / 1000000),
- (int) ((elapsed_us / 10000) % 100));
+ printf ("elapsed time: %d.%02d seconds\n", (int)(elapsed_us / 1000000),
+ (int)((elapsed_us / 10000) % 100));
return 0;
}
diff --git a/fish/uri.c b/fish/uri.c
index 33e820c..570a7a4 100644
--- a/fish/uri.c
+++ b/fish/uri.c
@@ -34,7 +34,9 @@
#include "uri.h"
static int is_uri (const char *arg);
-static int parse (const char *arg, char **path_ret, char **protocol_ret, char
***server_ret, char **username_ret, char **password_ret);
+static int parse (const char *arg, char **path_ret, char **protocol_ret,
+ char ***server_ret, char **username_ret,
+ char **password_ret);
static char *query_get (xmlURIPtr uri, const char *search_name);
static int make_server (xmlURIPtr uri, const char *socket, char ***ret);
@@ -128,14 +130,18 @@ parse (const char *arg, char **path_ret, char **protocol_ret,
socket = query_get (uri, "socket");
if (uri->server && STRNEQ (uri->server, "") && socket)
{
- fprintf (stderr, _("%s: %s: cannot both a server name and a socket query
parameter\n"),
- guestfs_int_program_name, arg);
+ fprintf (
+ stderr,
+ _ (
+ "%s: %s: cannot both a server name and a socket query parameter\n"),
+ guestfs_int_program_name, arg);
return -1;
}
/* Is this needed? XXX
if (socket && socket[0] != '/') {
- fprintf (stderr, _("%s: --add %s: socket query parameter must be an absolute
path\n"),
+ fprintf (stderr, _("%s: --add %s: socket query parameter must be an
+ absolute path\n"),
guestfs_int_program_name, arg);
return -1;
}
@@ -157,8 +163,8 @@ parse (const char *arg, char **path_ret, char **protocol_ret,
if (uri->user && STRNEQ (uri->user, "")) {
char *p = strchr (uri->user, ':');
if (p != NULL) {
- if (STRNEQ (p+1, "")) {
- *password_ret = strdup (p+1);
+ if (STRNEQ (p + 1, "")) {
+ *password_ret = strdup (p + 1);
if (*password_ret == NULL) {
perror ("strdup: password");
free (*protocol_ret);
@@ -185,10 +191,8 @@ parse (const char *arg, char **path_ret, char **protocol_ret,
*/
path = uri->path;
if (path && path[0] == '/' &&
- (STREQ (uri->scheme, "gluster") ||
- STREQ (uri->scheme, "iscsi") ||
- STREQ (uri->scheme, "rbd") ||
- STREQ (uri->scheme, "sheepdog")))
+ (STREQ (uri->scheme, "gluster") || STREQ (uri->scheme,
"iscsi") ||
+ STREQ (uri->scheme, "rbd") || STREQ (uri->scheme,
"sheepdog")))
path++;
*path_ret = strdup (path ? path : "");
@@ -224,13 +228,14 @@ query_get (xmlURIPtr uri, const char *search_name)
/* Find the next separator, or end of the string. */
end = strchr (query, '&');
if (!end)
- end = strchr(query, ';');
+ end = strchr (query, ';');
if (!end)
end = query + strlen (query);
/* Find the first '=' character between here and end. */
- eq = strchr(query, '=');
- if (eq && eq >= end) eq = NULL;
+ eq = strchr (query, '=');
+ if (eq && eq >= end)
+ eq = NULL;
/* Empty section (eg. "&&"). */
if (end == query)
@@ -241,14 +246,16 @@ query_get (xmlURIPtr uri, const char *search_name)
*/
else if (!eq) {
name = xmlURIUnescapeString (query, end - query, NULL);
- if (!name) goto no_memory;
+ if (!name)
+ goto no_memory;
}
/* Or if we have "name=" here (works around annoying
* problem when calling xmlURIUnescapeString with len = 0).
*/
- else if (eq+1 == end) {
+ else if (eq + 1 == end) {
name = xmlURIUnescapeString (query, eq - query, NULL);
- if (!name) goto no_memory;
+ if (!name)
+ goto no_memory;
}
/* If the '=' character is at the beginning then we have
* "=value" and consistent with CGI.pm we _ignore_ this.
@@ -261,7 +268,7 @@ query_get (xmlURIPtr uri, const char *search_name)
name = xmlURIUnescapeString (query, eq - query, NULL);
if (!name)
goto no_memory;
- value = xmlURIUnescapeString (eq+1, end - (eq+1), NULL);
+ value = xmlURIUnescapeString (eq + 1, end - (eq + 1), NULL);
if (!value) {
goto no_memory;
}
@@ -288,7 +295,7 @@ query_get (xmlURIPtr uri, const char *search_name)
/* search_name not found */
return NULL;
- no_memory:
+no_memory:
perror ("malloc");
return NULL;
}
diff --git a/fish/uri.h b/fish/uri.h
index 9202a70..d0776df 100644
--- a/fish/uri.h
+++ b/fish/uri.h
@@ -22,11 +22,11 @@
#define FISH_URI_H
struct uri {
- char *path; /* disk path */
- char *protocol; /* protocol (eg. "file", "nbd") */
- char **server; /* server(s) - can be NULL */
- char *username; /* username - can be NULL */
- char *password; /* password - can be NULL */
+ char *path; /* disk path */
+ char *protocol; /* protocol (eg. "file", "nbd") */
+ char **server; /* server(s) - can be NULL */
+ char *username; /* username - can be NULL */
+ char *password; /* password - can be NULL */
};
/* Parse the '-a' option parameter 'arg', and place the result in
diff --git a/fish/windows.c b/fish/windows.c
index cb77507..e737a0a 100644
--- a/fish/windows.c
+++ b/fish/windows.c
@@ -49,7 +49,8 @@ is_windows (guestfs_h *g, const char *root)
}
char *
-windows_path (guestfs_h *g, const char *root, const char *path, int readonly)
+windows_path (guestfs_h *g, const char *root, const char *path,
+ int readonly)
{
char *ret;
size_t i;
@@ -98,13 +99,14 @@ mount_drive_letter (guestfs_h *g, char drive_letter, const char
*root,
CLEANUP_FREE_STRING_LIST char **drives =
guestfs_inspect_get_drive_mappings (g, root);
if (drives == NULL || drives[0] == NULL)
- error (EXIT_FAILURE, 0,
- _("to use Windows drive letters, this must be a Windows guest"));
+ error (
+ EXIT_FAILURE, 0,
+ _("to use Windows drive letters, this must be a Windows guest"));
device = NULL;
for (i = 0; drives[i] != NULL; i += 2) {
if (c_tolower (drives[i][0]) == drive_letter && drives[i][1] == '\0')
{
- device = drives[i+1];
+ device = drives[i + 1];
break;
}
}
diff --git a/format/format.c b/format/format.c
index 4aa31de..651f6de 100644
--- a/format/format.c
+++ b/format/format.c
@@ -88,9 +88,8 @@ usage (int status)
"For more information, see the manpage %s(1).\n"
"\n"
"%s\n\n"),
- guestfs_int_program_name, warning,
- guestfs_int_program_name, guestfs_int_program_name,
- warning);
+ guestfs_int_program_name, warning, guestfs_int_program_name,
+ guestfs_int_program_name, warning);
}
exit (status);
}
@@ -133,24 +132,27 @@ main (int argc, char *argv[])
for (;;) {
c = getopt_long (argc, argv, options, long_options, &option_index);
- if (c == -1) break;
+ if (c == -1)
+ break;
switch (c) {
- case 0: /* options which are long only */
+ case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "long-options"))
display_long_options (long_options);
else if (STREQ (long_options[option_index].name, "short-options"))
display_short_options (options);
else if (STREQ (long_options[option_index].name, "format")) {
OPTION_format;
- } else if (STREQ (long_options[option_index].name, "filesystem")) {
+ }
+ else if (STREQ (long_options[option_index].name, "filesystem")) {
if (STREQ (optarg, "none"))
filesystem = NULL;
else if (optarg[0] == '-') /* eg: --filesystem --lvm */
error (EXIT_FAILURE, 0, _("no filesystem was specified"));
else
filesystem = optarg;
- } else if (STREQ (long_options[option_index].name, "lvm")) {
+ }
+ else if (STREQ (long_options[option_index].name, "lvm")) {
if (vg || lv)
error (EXIT_FAILURE, 0,
_("--lvm option cannot be given multiple times"));
@@ -164,20 +166,23 @@ main (int argc, char *argv[])
vg = lv = NULL;
else
parse_vg_lv (optarg);
- } else if (STREQ (long_options[option_index].name, "partition")) {
+ }
+ else if (STREQ (long_options[option_index].name, "partition")) {
if (optarg == NULL)
partition = "DEFAULT";
else if (STREQ (optarg, "none"))
partition = NULL;
else
partition = optarg;
- } else if (STREQ (long_options[option_index].name, "wipe")) {
+ }
+ else if (STREQ (long_options[option_index].name, "wipe")) {
wipe = 1;
- } else if (STREQ (long_options[option_index].name, "label")) {
+ }
+ else if (STREQ (long_options[option_index].name, "label")) {
label = optarg;
- } else
- error (EXIT_FAILURE, 0,
- _("unknown long option: %s (%d)"),
+ }
+ else
+ error (EXIT_FAILURE, 0, _("unknown long option: %s (%d)"),
long_options[option_index].name, option_index);
break;
@@ -242,7 +247,7 @@ main (int argc, char *argv[])
exit (EXIT_FAILURE);
/* Test if the wipefs API is available. */
- have_wipefs = guestfs_feature_available (g, (char **) wipefs);
+ have_wipefs = guestfs_feature_available (g, (char **)wipefs);
/* Perform the format. */
retry = do_format ();
@@ -299,9 +304,10 @@ parse_vg_lv (const char *lvm)
if (!vg || !lv)
error (EXIT_FAILURE, errno, "strdup");
- } else
+ }
+ else
cannot_parse:
- error (EXIT_FAILURE, 0, _("cannot parse --lvm option (%s)"), lvm);
+ error (EXIT_FAILURE, 0, _("cannot parse --lvm option (%s)"), lvm);
if (strchr (vg, '/') || strchr (lv, '/'))
goto cannot_parse;
@@ -313,8 +319,7 @@ do_format (void)
{
size_t i;
- CLEANUP_FREE_STRING_LIST char **devices =
- guestfs_list_devices (g);
+ CLEANUP_FREE_STRING_LIST char **devices = guestfs_list_devices (g);
if (devices == NULL)
exit (EXIT_FAILURE);
@@ -356,12 +361,14 @@ do_format (void)
const char *ptype = partition;
int64_t dev_size;
- /* If partition has the magic value "DEFAULT", choose either MBR or
GPT.*/
+ /* If partition has the magic value "DEFAULT", choose either MBR or
+ * GPT.*/
if (STREQ (partition, "DEFAULT")) {
dev_size = guestfs_blockdev_getsize64 (g, devices[i]);
if (dev_size == -1)
exit (EXIT_FAILURE);
- ptype = dev_size < INT64_C(2)*1024*1024*1024*1024 ? "mbr" :
"gpt";
+ ptype = dev_size < INT64_C (2) * 1024 * 1024 * 1024 * 1024 ? "mbr"
+ : "gpt";
}
if (guestfs_part_disk (g, devices[i], ptype) == -1)
@@ -416,7 +423,7 @@ do_format (void)
}
if (filesystem) {
- struct guestfs_mkfs_opts_argv optargs = { .bitmask = 0 };
+ struct guestfs_mkfs_opts_argv optargs = {.bitmask = 0 };
if (label) {
optargs.label = label;
diff --git a/fuse/guestmount.c b/fuse/guestmount.c
index fc03a9c..3f222c2 100644
--- a/fuse/guestmount.c
+++ b/fuse/guestmount.c
@@ -53,8 +53,8 @@ static int write_pid_file (const char *pid_file, pid_t pid);
static void
fuse_opt_add_opt_escaped (char **opts, const char *opt)
{
- unsigned oldlen = *opts ? strlen(*opts) : 0;
- char *d = realloc (*opts, oldlen + 1 + strlen(opt) * 2 + 1);
+ unsigned oldlen = *opts ? strlen (*opts) : 0;
+ char *d = realloc (*opts, oldlen + 1 + strlen (opt) * 2 + 1);
if (!d)
error (EXIT_FAILURE, errno, "realloc");
@@ -88,7 +88,7 @@ fuse_help (void)
{
static struct fuse_operations null_operations;
const char *tmp_argv[] = { guestfs_int_program_name, "--help", NULL };
- fuse_main (2, (char **) tmp_argv, &null_operations, NULL);
+ fuse_main (2, (char **)tmp_argv, &null_operations, NULL);
exit (EXIT_SUCCESS);
}
@@ -99,38 +99,40 @@ usage (int status)
fprintf (stderr, _("Try `%s --help' for more information.\n"),
guestfs_int_program_name);
else {
- printf (_("%s: FUSE module for libguestfs\n"
- "%s lets you mount a virtual machine filesystem\n"
- "Copyright (C) 2009-2016 Red Hat Inc.\n"
- "Usage:\n"
- " %s [--options] mountpoint\n"
- "Options:\n"
- " -a|--add image Add image\n"
- " -c|--connect uri Specify libvirt URI for -d option\n"
- " --dir-cache-timeout Set readdir cache timeout (default 5
sec)\n"
- " -d|--domain guest Add disks from libvirt guest\n"
- " --echo-keys Don't turn off echo for
passphrases\n"
- " --fd=FD Write to pipe FD when mountpoint is
ready\n"
- " --format[=raw|..] Force disk format for -a option\n"
- " --fuse-help Display extra FUSE options\n"
- " -i|--inspector Automatically mount filesystems\n"
- " --help Display help message and exit\n"
- " --keys-from-stdin Read passphrases from stdin\n"
- " --live Connect to a live virtual machine\n"
- " -m|--mount dev[:mnt[:opts[:fstype]] Mount dev on mnt (if omitted,
/)\n"
- " --no-fork Don't daemonize\n"
- " -n|--no-sync Don't autosync\n"
- " -o|--option opt Pass extra option to FUSE\n"
- " --pid-file filename Write PID to filename\n"
- " -r|--ro Mount read-only\n"
- " --selinux Enable SELinux support\n"
- " -v|--verbose Verbose messages\n"
- " -V|--version Display version and exit\n"
- " -w|--rw Mount read-write\n"
- " -x|--trace Trace guestfs API calls\n"
- ),
- guestfs_int_program_name, guestfs_int_program_name,
- guestfs_int_program_name);
+ printf (
+ _ (
+ "%s: FUSE module for libguestfs\n"
+ "%s lets you mount a virtual machine filesystem\n"
+ "Copyright (C) 2009-2016 Red Hat Inc.\n"
+ "Usage:\n"
+ " %s [--options] mountpoint\n"
+ "Options:\n"
+ " -a|--add image Add image\n"
+ " -c|--connect uri Specify libvirt URI for -d option\n"
+ " --dir-cache-timeout Set readdir cache timeout (default 5 sec)\n"
+ " -d|--domain guest Add disks from libvirt guest\n"
+ " --echo-keys Don't turn off echo for passphrases\n"
+ " --fd=FD Write to pipe FD when mountpoint is ready\n"
+ " --format[=raw|..] Force disk format for -a option\n"
+ " --fuse-help Display extra FUSE options\n"
+ " -i|--inspector Automatically mount filesystems\n"
+ " --help Display help message and exit\n"
+ " --keys-from-stdin Read passphrases from stdin\n"
+ " --live Connect to a live virtual machine\n"
+ " -m|--mount dev[:mnt[:opts[:fstype]] Mount dev on mnt (if "
+ "omitted, /)\n"
+ " --no-fork Don't daemonize\n"
+ " -n|--no-sync Don't autosync\n"
+ " -o|--option opt Pass extra option to FUSE\n"
+ " --pid-file filename Write PID to filename\n"
+ " -r|--ro Mount read-only\n"
+ " --selinux Enable SELinux support\n"
+ " -v|--verbose Verbose messages\n"
+ " -V|--version Display version and exit\n"
+ " -w|--rw Mount read-write\n"
+ " -x|--trace Trace guestfs API calls\n"),
+ guestfs_int_program_name, guestfs_int_program_name,
+ guestfs_int_program_name);
}
exit (status);
}
@@ -212,10 +214,11 @@ main (int argc, char *argv[])
for (;;) {
c = getopt_long (argc, argv, options, long_options, &option_index);
- if (c == -1) break;
+ if (c == -1)
+ break;
switch (c) {
- case 0: /* options which are long only */
+ case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "long-options"))
display_long_options (long_options);
else if (STREQ (long_options[option_index].name, "short-options"))
@@ -227,25 +230,32 @@ main (int argc, char *argv[])
else if (STREQ (long_options[option_index].name, "selinux")) {
if (guestfs_set_selinux (g, 1) == -1)
exit (EXIT_FAILURE);
- } else if (STREQ (long_options[option_index].name, "format")) {
+ }
+ else if (STREQ (long_options[option_index].name, "format")) {
OPTION_format;
- } else if (STREQ (long_options[option_index].name, "keys-from-stdin")) {
+ }
+ else if (STREQ (long_options[option_index].name, "keys-from-stdin")) {
keys_from_stdin = 1;
- } else if (STREQ (long_options[option_index].name, "echo-keys")) {
+ }
+ else if (STREQ (long_options[option_index].name, "echo-keys")) {
echo_keys = 1;
- } else if (STREQ (long_options[option_index].name, "live")) {
+ }
+ else if (STREQ (long_options[option_index].name, "live")) {
live = 1;
- } else if (STREQ (long_options[option_index].name, "pid-file")) {
+ }
+ else if (STREQ (long_options[option_index].name, "pid-file")) {
pid_file = optarg;
- } else if (STREQ (long_options[option_index].name, "no-fork")) {
+ }
+ else if (STREQ (long_options[option_index].name, "no-fork")) {
do_fork = 0;
- } else if (STREQ (long_options[option_index].name, "fd")) {
+ }
+ else if (STREQ (long_options[option_index].name, "fd")) {
if (sscanf (optarg, "%d", &pipe_fd) != 1 || pipe_fd < 0)
error (EXIT_FAILURE, 0,
_("unable to parse --fd option value: %s"), optarg);
- } else
- error (EXIT_FAILURE, 0,
- _("unknown long option: %s (%d)"),
+ }
+ else
+ error (EXIT_FAILURE, 0, _("unknown long option: %s (%d)"),
long_options[option_index].name, option_index);
break;
@@ -312,17 +322,21 @@ main (int argc, char *argv[])
/* Check we have the right options. */
if (!live) {
if (!drvs || !(mps || inspector))
- error (EXIT_FAILURE, 0,
- _("must have at least one -a/-d and at least one -m/-i option"));
- } else {
+ error (
+ EXIT_FAILURE, 0,
+ _("must have at least one -a/-d and at least one -m/-i option"));
+ }
+ else {
size_t count_d = 0, count_other = 0;
struct drv *drv;
if (read_only)
- error (EXIT_FAILURE, 0, _("--live is not compatible with --ro option"));
+ error (EXIT_FAILURE, 0,
+ _("--live is not compatible with --ro option"));
if (inspector)
- error (EXIT_FAILURE, 0, _("--live is not compatible with -i option"));
+ error (EXIT_FAILURE, 0,
+ _("--live is not compatible with -i option"));
/* --live: make sure there was one -d option and no -a options */
for (drv = drvs; drv; drv = drv->next) {
@@ -337,11 +351,12 @@ main (int argc, char *argv[])
_("with --live, you must use exactly one -d option"));
if (count_other != 0)
- error (EXIT_FAILURE, 0, _("--live is not compatible with -a option"));
+ error (EXIT_FAILURE, 0,
+ _("--live is not compatible with -a option"));
}
/* We'd better have a mountpoint. */
- if (optind+1 != argc)
+ if (optind + 1 != argc)
error (EXIT_FAILURE, 0,
_("you must specify a mountpoint in the host filesystem"));
@@ -394,7 +409,7 @@ main (int argc, char *argv[])
if (pid == -1)
error (EXIT_FAILURE, errno, "fork");
- if (pid != 0) { /* parent */
+ if (pid != 0) { /* parent */
if (write_pid_file (pid_file, pid) == -1)
_exit (EXIT_FAILURE);
if (write_pipe_fd (pipe_fd) == -1)
diff --git a/fuse/guestunmount.c b/fuse/guestunmount.c
index dc9428c..6c06bfc 100644
--- a/fuse/guestunmount.c
+++ b/fuse/guestunmount.c
@@ -53,20 +53,20 @@ usage (int status)
fprintf (stderr, _("Try `%s --help' for more information.\n"),
guestfs_int_program_name);
else {
- printf (_("%s: clean up a mounted filesystem\n"
- "Copyright (C) 2013 Red Hat Inc.\n"
- "Usage:\n"
- " %s [--fd=FD] mountpoint\n"
- "Options:\n"
- " --fd=FD Pipe file descriptor to monitor\n"
- " --help Display help message and exit\n"
- " -q|--quiet Don't print fusermount errors\n"
- " --no-retry Don't retry fusermount\n"
- " --retry=N Retry fusermount N times (default: 5)\n"
- " -v|--verbose Verbose messages\n"
- " -V|--version Display version and exit\n"
- ),
- guestfs_int_program_name, guestfs_int_program_name);
+ printf (
+ _("%s: clean up a mounted filesystem\n"
+ "Copyright (C) 2013 Red Hat Inc.\n"
+ "Usage:\n"
+ " %s [--fd=FD] mountpoint\n"
+ "Options:\n"
+ " --fd=FD Pipe file descriptor to monitor\n"
+ " --help Display help message and exit\n"
+ " -q|--quiet Don't print fusermount errors\n"
+ " --no-retry Don't retry fusermount\n"
+ " --retry=N Retry fusermount N times (default: 5)\n"
+ " -v|--verbose Verbose messages\n"
+ " -V|--version Display version and exit\n"),
+ guestfs_int_program_name, guestfs_int_program_name);
}
exit (status);
}
@@ -78,14 +78,10 @@ main (int argc, char *argv[])
static const char *options = "qv?V";
static const struct option long_options[] = {
- { "fd", 1, 0, 0 },
- { "help", 0, 0, HELP_OPTION },
- { "quiet", 0, 0, 'q' },
- { "no-retry", 0, 0, 0 },
- { "retry", 1, 0, 0 },
- { "verbose", 0, 0, 'v' },
- { "version", 0, 0, 'V' },
- { 0, 0, 0, 0 }
+ { "fd", 1, 0, 0 }, { "help", 0, 0, HELP_OPTION },
+ { "quiet", 0, 0, 'q' }, { "no-retry", 0, 0, 0 },
+ { "retry", 1, 0, 0 }, { "verbose", 0, 0, 'v' },
+ { "version", 0, 0, 'V' }, { 0, 0, 0, 0 }
};
int c, fd = -1;
@@ -102,23 +98,28 @@ main (int argc, char *argv[])
for (;;) {
c = getopt_long (argc, argv, options, long_options, &option_index);
- if (c == -1) break;
+ if (c == -1)
+ break;
switch (c) {
- case 0: /* options which are long only */
+ case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "fd")) {
if (sscanf (optarg, "%d", &fd) != 1 || fd < 0)
- error (EXIT_FAILURE, 0, _("cannot parse fd option '%s'"),
optarg);
- } else if (STREQ (long_options[option_index].name, "no-retry")) {
+ error (EXIT_FAILURE, 0, _("cannot parse fd option '%s'"),
+ optarg);
+ }
+ else if (STREQ (long_options[option_index].name, "no-retry")) {
retries = 0;
- } else if (STREQ (long_options[option_index].name, "retry")) {
+ }
+ else if (STREQ (long_options[option_index].name, "retry")) {
if (sscanf (optarg, "%zu", &retries) != 1 || retries >= 64)
- error (EXIT_FAILURE, 0,
- _("cannot parse retries option or value is too large
'%s'"),
- optarg);
- } else
- error (EXIT_FAILURE, 0,
- _("unknown long option: %s (%d)"),
+ error (
+ EXIT_FAILURE, 0,
+ _("cannot parse retries option or value is too large
'%s'"),
+ optarg);
+ }
+ else
+ error (EXIT_FAILURE, 0, _("unknown long option: %s (%d)"),
long_options[option_index].name, option_index);
break;
@@ -143,7 +144,7 @@ main (int argc, char *argv[])
}
/* We'd better have a mountpoint. */
- if (optind+1 != argc)
+ if (optind + 1 != argc)
error (EXIT_FAILURE, 0,
_("you must specify a mountpoint in the host filesystem\n"));
@@ -178,7 +179,7 @@ main (int argc, char *argv[])
/* Unmount the filesystem. We may have to try a few times. */
for (i = 0; i <= retries; ++i) {
if (i > 0)
- sleep (1 << (i-1));
+ sleep (1 << (i - 1));
free (error_str);
error_str = NULL;
@@ -187,8 +188,7 @@ main (int argc, char *argv[])
goto done;
/* Did fusermount fail because the mountpoint is not mounted? */
- if (error_str &&
- strstr (error_str, "fusermount: entry for") != NULL) {
+ if (error_str && strstr (error_str, "fusermount: entry for") !=
NULL) {
goto not_mounted;
}
}
@@ -203,8 +203,8 @@ main (int argc, char *argv[])
exit (2);
- /* not mounted */
- not_mounted:
+/* not mounted */
+not_mounted:
if (!quiet)
fprintf (stderr, _("%s: %s is not mounted: %s\n"),
guestfs_int_program_name, mountpoint, error_str);
@@ -213,8 +213,8 @@ main (int argc, char *argv[])
exit (3);
- /* success */
- done:
+/* success */
+done:
exit (EXIT_SUCCESS);
}
@@ -238,7 +238,7 @@ do_fusermount (const char *mountpoint, char **error_rtn)
if (pid == -1)
error (EXIT_FAILURE, errno, "fork");
- if (pid == 0) { /* Child - run fusermount. */
+ if (pid == 0) { /* Child - run fusermount. */
close (fd[0]);
dup2 (fd[1], 1);
dup2 (fd[1], 2);
@@ -284,8 +284,8 @@ do_fusermount (const char *mountpoint, char **error_rtn)
if (buf) {
/* Remove any trailing \n from the error message. */
- while (len > 0 && buf[len-1] == '\n') {
- buf[len-1] = '\0';
+ while (len > 0 && buf[len - 1] == '\n') {
+ buf[len - 1] = '\0';
len--;
}
@@ -302,7 +302,7 @@ do_fusermount (const char *mountpoint, char **error_rtn)
fprintf (stderr, "%s\n", buf);
*error_rtn = buf;
- return 1; /* fusermount or exec failed */
+ return 1; /* fusermount or exec failed */
}
if (verbose)
@@ -310,7 +310,7 @@ do_fusermount (const char *mountpoint, char **error_rtn)
guestfs_int_program_name);
free (buf);
- return 0; /* fusermount successful */
+ return 0; /* fusermount successful */
}
/* Try running 'fuser' on the mountpoint. This is for information
@@ -325,7 +325,7 @@ do_fuser (const char *mountpoint)
if (pid == -1)
error (EXIT_FAILURE, errno, "fork");
- if (pid == 0) { /* Child - run fuser. */
+ if (pid == 0) { /* Child - run fuser. */
#ifdef __linux__
execlp (FUSER, "fuser", "-v", "-m", mountpoint, NULL);
#else
diff --git a/fuse/test-fuse.c b/fuse/test-fuse.c
index 35d75d5..deefee7 100644
--- a/fuse/test-fuse.c
+++ b/fuse/test-fuse.c
@@ -56,7 +56,7 @@
static guestfs_h *g;
-#define SIZE INT64_C(1024*1024*1024)
+#define SIZE INT64_C (1024 * 1024 * 1024)
/* NB: Must be a path that does not need quoting. */
static char mountpoint[] = "/tmp/testfuseXXXXXX";
@@ -102,12 +102,14 @@ main (int argc, char *argv[])
exit (EXIT_FAILURE);
/* Test features. */
- acl_available = guestfs_feature_available (g, (char **) acl_group);
- if (acl_available == -1) exit (EXIT_FAILURE);
+ acl_available = guestfs_feature_available (g, (char **)acl_group);
+ if (acl_available == -1)
+ exit (EXIT_FAILURE);
linuxxattrs_available =
- guestfs_feature_available (g, (char **) linuxxattrs_group);
- if (linuxxattrs_available == -1) exit (EXIT_FAILURE);
+ guestfs_feature_available (g, (char **)linuxxattrs_group);
+ if (linuxxattrs_available == -1)
+ exit (EXIT_FAILURE);
create_initial_filesystem ();
@@ -117,9 +119,8 @@ main (int argc, char *argv[])
/* Mount the filesystem on the host using FUSE. */
debug_calls = guestfs_get_trace (g);
- if (guestfs_mount_local (g, mountpoint,
- GUESTFS_MOUNT_LOCAL_DEBUGCALLS, debug_calls,
- -1) == -1)
+ if (guestfs_mount_local (g, mountpoint, GUESTFS_MOUNT_LOCAL_DEBUGCALLS,
+ debug_calls, -1) == -1)
exit (EXIT_FAILURE);
/* Fork to run the next part of the test. */
@@ -127,7 +128,7 @@ main (int argc, char *argv[])
if (pid == -1)
error (EXIT_FAILURE, errno, "fork");
- if (pid == 0) { /* Child. */
+ if (pid == 0) { /* Child. */
/* Move into the mountpoint for the tests. */
if (chdir (mountpoint) == -1) {
perror (mountpoint);
@@ -155,7 +156,8 @@ main (int argc, char *argv[])
fflush (stdout);
r = system (cmd);
if (!WIFEXITED (r) || WEXITSTATUS (r) != EXIT_SUCCESS)
- fprintf (stderr, "%s: warning: guestunmount command failed\n", argv[0]);
+ fprintf (stderr, "%s: warning: guestunmount command failed\n",
+ argv[0]);
_exit (res == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
@@ -184,7 +186,8 @@ main (int argc, char *argv[])
guestfs_close (g);
/* Did the child process fail? */
- exit (!WIFEXITED (r) || WEXITSTATUS (r) != 0 ? EXIT_FAILURE : EXIT_SUCCESS);
+ exit (!WIFEXITED (r) || WEXITSTATUS (r) != 0 ? EXIT_FAILURE
+ : EXIT_SUCCESS);
}
/* Create a filesystem with some initial content. */
@@ -197,9 +200,8 @@ create_initial_filesystem (void)
/* Use ext4 because it supports modern features. Use >= 256 byte
* inodes because these support nanosecond timestamps.
*/
- if (guestfs_mkfs_opts (g, "ext4", "/dev/sda1",
- GUESTFS_MKFS_OPTS_INODE, 256,
- -1) == -1)
+ if (guestfs_mkfs_opts (g, "ext4", "/dev/sda1",
GUESTFS_MKFS_OPTS_INODE,
+ 256, -1) == -1)
exit (EXIT_FAILURE);
if (guestfs_mount_options (g, "acl,user_xattr", "/dev/sda1",
"/") == -1)
@@ -218,7 +220,8 @@ create_initial_filesystem (void)
if (guestfs_touch (g, "/user_xattr") == -1)
exit (EXIT_FAILURE);
- if (guestfs_setxattr (g, "user.test", "hello123", 8,
"/user_xattr") == -1)
+ if (guestfs_setxattr (g, "user.test", "hello123", 8,
"/user_xattr") ==
+ -1)
exit (EXIT_FAILURE);
}
@@ -237,8 +240,8 @@ static int
test_fuse (void)
{
int stage = 0;
-#define STAGE(fs,...) \
- printf ("%02d: " fs "\n", ++stage, ##__VA_ARGS__); \
+#define STAGE(fs, ...) \
+ printf ("%02d: " fs "\n", ++stage, ##__VA_ARGS__); \
fflush (stdout)
FILE *fp;
char *line = NULL;
@@ -319,7 +322,8 @@ test_fuse (void)
return -1;
}
if (statbuf.st_size != 0) {
- fprintf (stderr, "'empty' has invalid size (%d)\n", (int)
statbuf.st_size);
+ fprintf (stderr, "'empty' has invalid size (%d)\n",
+ (int)statbuf.st_size);
return -1;
}
@@ -328,12 +332,13 @@ test_fuse (void)
return -1;
}
if ((statbuf.st_mode & 0777) != 0644) {
- fprintf (stderr, "'hello.txt' has invalid mode (%o)\n",
statbuf.st_mode);
+ fprintf (stderr, "'hello.txt' has invalid mode (%o)\n",
+ statbuf.st_mode);
return -1;
}
if (statbuf.st_size != 5) {
fprintf (stderr, "'hello.txt' has invalid size (%d)\n",
- (int) statbuf.st_size);
+ (int)statbuf.st_size);
return -1;
}
@@ -342,12 +347,13 @@ test_fuse (void)
return -1;
}
if ((statbuf.st_mode & 0777) != 0644) {
- fprintf (stderr, "'world.txt' has invalid mode (%o)\n",
statbuf.st_mode);
+ fprintf (stderr, "'world.txt' has invalid mode (%o)\n",
+ statbuf.st_mode);
return -1;
}
if (statbuf.st_size != 11) {
fprintf (stderr, "'world.txt' has invalid size (%d)\n",
- (int) statbuf.st_size);
+ (int)statbuf.st_size);
return -1;
}
@@ -403,7 +409,7 @@ test_fuse (void)
}
if (statbuf.st_nlink != 1) {
fprintf (stderr, "nlink of 'hello.txt' was %d (expected 1)\n",
- (int) statbuf.st_nlink);
+ (int)statbuf.st_nlink);
return -1;
}
@@ -418,7 +424,7 @@ test_fuse (void)
}
if (statbuf.st_nlink != 2) {
fprintf (stderr, "nlink of 'link' was %d (expected 2)\n",
- (int) statbuf.st_nlink);
+ (int)statbuf.st_nlink);
return -1;
}
@@ -428,7 +434,7 @@ test_fuse (void)
}
if (statbuf.st_nlink != 2) {
fprintf (stderr, "nlink of 'hello.txt' was %d (expected 2)\n",
- (int) statbuf.st_nlink);
+ (int)statbuf.st_nlink);
return -1;
}
@@ -542,7 +548,7 @@ test_fuse (void)
}
if (statbuf.st_size != u) {
fprintf (stderr, "unexpected size: was %u expected %u\n",
- (unsigned) statbuf.st_size, u);
+ (unsigned)statbuf.st_size, u);
return -1;
}
}
@@ -553,15 +559,16 @@ test_fuse (void)
STAGE ("checking utimes");
- fd = open ("timestamp", O_WRONLY|O_CREAT|O_TRUNC|O_NOCTTY|O_CLOEXEC, 0644);
+ fd = open ("timestamp",
+ O_WRONLY | O_CREAT | O_TRUNC | O_NOCTTY | O_CLOEXEC, 0644);
if (fd == -1) {
perror ("open: timestamp");
return -1;
}
close (fd);
- tv[0].tv_sec = 23; /* atime */
+ tv[0].tv_sec = 23; /* atime */
tv[0].tv_usec = 45;
- tv[1].tv_sec = 67; /* mtime */
+ tv[1].tv_sec = 67; /* mtime */
tv[1].tv_usec = 89;
if (utimes ("timestamp", tv) == -1) {
perror ("utimes: timestamp");
@@ -571,26 +578,25 @@ test_fuse (void)
perror ("fstat: timestamp");
return -1;
}
- if (statbuf.st_atime != 23 ||
- statbuf.st_atim.tv_nsec != 45000 ||
- statbuf.st_mtime != 67 ||
- statbuf.st_mtim.tv_nsec != 89000) {
+ if (statbuf.st_atime != 23 || statbuf.st_atim.tv_nsec != 45000 ||
+ statbuf.st_mtime != 67 || statbuf.st_mtim.tv_nsec != 89000) {
fprintf (stderr, "utimes did not set time (%d/%d/%d/%d)\n",
- (int) statbuf.st_atime, (int) statbuf.st_atim.tv_nsec,
- (int) statbuf.st_mtime, (int) statbuf.st_mtim.tv_nsec);
+ (int)statbuf.st_atime, (int)statbuf.st_atim.tv_nsec,
+ (int)statbuf.st_mtime, (int)statbuf.st_mtim.tv_nsec);
return -1;
}
STAGE ("checking utimens");
- fd = open ("timestamp", O_WRONLY|O_CREAT|O_TRUNC|O_NOCTTY|O_CLOEXEC, 0644);
+ fd = open ("timestamp",
+ O_WRONLY | O_CREAT | O_TRUNC | O_NOCTTY | O_CLOEXEC, 0644);
if (fd == -1) {
perror ("open: timestamp");
return -1;
}
- ts[0].tv_sec = 12; /* atime */
+ ts[0].tv_sec = 12; /* atime */
ts[0].tv_nsec = 34;
- ts[1].tv_sec = 56; /* mtime */
+ ts[1].tv_sec = 56; /* mtime */
ts[1].tv_nsec = 78;
if (futimens (fd, ts) == -1) {
perror ("futimens: timestamp");
@@ -602,13 +608,11 @@ test_fuse (void)
close (fd);
return -1;
}
- if (statbuf.st_atime != 12 ||
- statbuf.st_atim.tv_nsec != 34 ||
- statbuf.st_mtime != 56 ||
- statbuf.st_mtim.tv_nsec != 78) {
+ if (statbuf.st_atime != 12 || statbuf.st_atim.tv_nsec != 34 ||
+ statbuf.st_mtime != 56 || statbuf.st_mtim.tv_nsec != 78) {
fprintf (stderr, "utimens did not set time (%d/%d/%d/%d)\n",
- (int) statbuf.st_atime, (int) statbuf.st_atim.tv_nsec,
- (int) statbuf.st_mtime, (int) statbuf.st_mtim.tv_nsec);
+ (int)statbuf.st_atime, (int)statbuf.st_atim.tv_nsec,
+ (int)statbuf.st_mtime, (int)statbuf.st_mtim.tv_nsec);
close (fd);
return -1;
}
@@ -658,16 +662,19 @@ test_fuse (void)
STAGE ("checking POSIX ACL read operation");
acl = acl_get_file ("acl", ACL_TYPE_ACCESS);
- if (acl == (acl_t) NULL) {
+ if (acl == (acl_t)NULL) {
perror ("acl_get_file: acl");
return -1;
}
- acl_text = acl_to_any_text (acl, NULL, '\n', TEXT_SOME_EFFECTIVE |
TEXT_NUMERIC_IDS);
+ acl_text = acl_to_any_text (acl, NULL, '\n',
+ TEXT_SOME_EFFECTIVE | TEXT_NUMERIC_IDS);
if (acl_text == NULL) {
perror ("acl_to_any_text: acl");
return -1;
}
- if (STRNEQ (acl_text,
"user::rwx\nuser:500:r--\ngroup::rwx\nmask::rwx\nother::r-x")) {
+ if (STRNEQ (
+ acl_text,
+ "user::rwx\nuser:500:r--\ngroup::rwx\nmask::rwx\nother::r-x")) {
fprintf (stderr, "unexpected acl: %s\n", acl_text);
return -1;
}
@@ -686,7 +693,8 @@ test_fuse (void)
return -1;
}
if (r != 8 || memcmp (buf, "hello123", r) != 0) {
- fprintf (stderr, "user.test xattr on file user_xattr was incorrect\n");
+ fprintf (stderr,
+ "user.test xattr on file user_xattr was incorrect\n");
return -1;
}
}
diff --git a/fuse/test-guestmount-fd.c b/fuse/test-guestmount-fd.c
index 3889094..c1b2e84 100644
--- a/fuse/test-guestmount-fd.c
+++ b/fuse/test-guestmount-fd.c
@@ -82,16 +82,14 @@ main (int argc, char *argv[])
if (pid == -1)
error (EXIT_FAILURE, errno, "fork");
- if (pid == 0) { /* child - guestmount */
+ if (pid == 0) { /* child - guestmount */
char fd_str[64];
close (pipefd[0]);
snprintf (fd_str, sizeof fd_str, "%d", pipefd[1]);
- execlp (GUESTMOUNT_BINARY,
- "guestmount",
- "--fd", fd_str, "--no-fork",
+ execlp (GUESTMOUNT_BINARY, "guestmount", "--fd", fd_str,
"--no-fork",
"--ro", "-a", TEST_IMAGE, "-i", MOUNTPOINT,
NULL);
perror ("execlp");
_exit (EXIT_FAILURE);
@@ -116,7 +114,8 @@ main (int argc, char *argv[])
/* Check that the test image was mounted. */
if (access (TEST_FILE, R_OK) == -1) {
- fprintf (stderr, "%s: test failed because test image is not mounted and
ready.",
+ fprintf (stderr,
+ "%s: test failed because test image is not mounted and ready.",
guestfs_int_program_name);
ignore_value (rmdir (MOUNTPOINT));
exit (EXIT_FAILURE);
@@ -129,8 +128,8 @@ main (int argc, char *argv[])
fprintf (stderr, "%s: test failed: %s\n", guestfs_int_program_name,
guestfs_int_exit_status_to_string (r, GUESTUNMOUNT_BINARY,
- status_string,
- sizeof status_string));
+ status_string,
+ sizeof status_string));
ignore_value (rmdir (MOUNTPOINT));
exit (EXIT_FAILURE);
}
@@ -147,11 +146,10 @@ main (int argc, char *argv[])
if (!WIFEXITED (status) || WEXITSTATUS (status) != 0) {
char status_string[80];
- fprintf (stderr, "%s: test failed: %s\n",
- guestfs_int_program_name,
+ fprintf (stderr, "%s: test failed: %s\n", guestfs_int_program_name,
guestfs_int_exit_status_to_string (status, GUESTMOUNT_BINARY,
- status_string,
- sizeof status_string));
+ status_string,
+ sizeof status_string));
ignore_value (rmdir (MOUNTPOINT));
exit (EXIT_FAILURE);
}
diff --git a/fuse/test-guestunmount-fd.c b/fuse/test-guestunmount-fd.c
index ad7ff74..61ccb97 100644
--- a/fuse/test-guestunmount-fd.c
+++ b/fuse/test-guestunmount-fd.c
@@ -63,7 +63,7 @@ main (int argc, char *argv[])
if (pid == -1)
error (EXIT_FAILURE, errno, "fork");
- if (pid == 0) { /* child - guestunmount */
+ if (pid == 0) { /* child - guestunmount */
char fd_str[64];
close (pipefd[1]);
@@ -88,11 +88,9 @@ main (int argc, char *argv[])
if (r != 0) {
char status_string[80];
- error (EXIT_FAILURE, 0,
- "test failed: %s",
- guestfs_int_exit_status_to_string (r, "guestunmount",
- status_string,
- sizeof status_string));
+ error (EXIT_FAILURE, 0, "test failed: %s",
+ guestfs_int_exit_status_to_string (
+ r, "guestunmount", status_string, sizeof status_string));
}
/* Close the write side of the pipe. This should cause guestunmount
@@ -109,9 +107,8 @@ main (int argc, char *argv[])
error (EXIT_FAILURE, 0,
"test failed: guestunmount didn't return status code 3; %s",
- guestfs_int_exit_status_to_string (status, "guestunmount",
- status_string,
- sizeof status_string));
+ guestfs_int_exit_status_to_string (
+ status, "guestunmount", status_string, sizeof status_string));
}
exit (EXIT_SUCCESS);
diff --git a/inspector/inspector.c b/inspector/inspector.c
index 6d4694d..d3f9963 100644
--- a/inspector/inspector.c
+++ b/inspector/inspector.c
@@ -70,28 +70,29 @@ usage (int status)
fprintf (stderr, _("Try `%s --help' for more information.\n"),
guestfs_int_program_name);
else {
- printf (_("%s: display information about a virtual machine\n"
- "Copyright (C) 2010 Red Hat Inc.\n"
- "Usage:\n"
- " %s [--options] -d domname file [file ...]\n"
- " %s [--options] -a disk.img [-a disk.img ...] file [file
...]\n"
- "Options:\n"
- " -a|--add image Add image\n"
- " -c|--connect uri Specify libvirt URI for -d option\n"
- " -d|--domain guest Add disks from libvirt guest\n"
- " --echo-keys Don't turn off echo for
passphrases\n"
- " --format[=raw|..] Force disk format for -a option\n"
- " --help Display brief help\n"
- " --keys-from-stdin Read passphrases from stdin\n"
- " --no-applications Do not output the installed
applications\n"
- " --no-icon Do not output the guest icon\n"
- " -v|--verbose Verbose messages\n"
- " -V|--version Display version and exit\n"
- " -x Trace libguestfs API calls\n"
- " --xpath query Perform an XPath query\n"
- "For more information, see the manpage %s(1).\n"),
- guestfs_int_program_name, guestfs_int_program_name,
- guestfs_int_program_name, guestfs_int_program_name);
+ printf (
+ _("%s: display information about a virtual machine\n"
+ "Copyright (C) 2010 Red Hat Inc.\n"
+ "Usage:\n"
+ " %s [--options] -d domname file [file ...]\n"
+ " %s [--options] -a disk.img [-a disk.img ...] file [file ...]\n"
+ "Options:\n"
+ " -a|--add image Add image\n"
+ " -c|--connect uri Specify libvirt URI for -d option\n"
+ " -d|--domain guest Add disks from libvirt guest\n"
+ " --echo-keys Don't turn off echo for passphrases\n"
+ " --format[=raw|..] Force disk format for -a option\n"
+ " --help Display brief help\n"
+ " --keys-from-stdin Read passphrases from stdin\n"
+ " --no-applications Do not output the installed applications\n"
+ " --no-icon Do not output the guest icon\n"
+ " -v|--verbose Verbose messages\n"
+ " -V|--version Display version and exit\n"
+ " -x Trace libguestfs API calls\n"
+ " --xpath query Perform an XPath query\n"
+ "For more information, see the manpage %s(1).\n"),
+ guestfs_int_program_name, guestfs_int_program_name,
+ guestfs_int_program_name, guestfs_int_program_name);
}
exit (status);
}
@@ -136,29 +137,35 @@ main (int argc, char *argv[])
for (;;) {
c = getopt_long (argc, argv, options, long_options, &option_index);
- if (c == -1) break;
+ if (c == -1)
+ break;
switch (c) {
- case 0: /* options which are long only */
+ case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "long-options"))
display_long_options (long_options);
else if (STREQ (long_options[option_index].name, "short-options"))
display_short_options (options);
else if (STREQ (long_options[option_index].name, "keys-from-stdin")) {
keys_from_stdin = 1;
- } else if (STREQ (long_options[option_index].name, "echo-keys")) {
+ }
+ else if (STREQ (long_options[option_index].name, "echo-keys")) {
echo_keys = 1;
- } else if (STREQ (long_options[option_index].name, "format")) {
+ }
+ else if (STREQ (long_options[option_index].name, "format")) {
OPTION_format;
- } else if (STREQ (long_options[option_index].name, "xpath")) {
+ }
+ else if (STREQ (long_options[option_index].name, "xpath")) {
xpath = optarg;
- } else if (STREQ (long_options[option_index].name, "no-applications")) {
+ }
+ else if (STREQ (long_options[option_index].name, "no-applications")) {
inspect_apps = 0;
- } else if (STREQ (long_options[option_index].name, "no-icon")) {
+ }
+ else if (STREQ (long_options[option_index].name, "no-icon")) {
inspect_icon = 0;
- } else
- error (EXIT_FAILURE, 0,
- _("unknown long option: %s (%d)"),
+ }
+ else
+ error (EXIT_FAILURE, 0, _("unknown long option: %s (%d)"),
long_options[option_index].name, option_index);
break;
@@ -210,7 +217,8 @@ main (int argc, char *argv[])
error (EXIT_FAILURE, errno, "strdup");
drv->next = drvs;
drvs = drv;
- } else { /* simulate -d option */
+ }
+ else { /* simulate -d option */
drv = calloc (1, sizeof (struct drv));
if (!drv)
error (EXIT_FAILURE, errno, "calloc");
@@ -275,8 +283,16 @@ main (int argc, char *argv[])
{
CLEANUP_FREE_STRING_LIST char **roots = guestfs_inspect_os (g);
if (roots == NULL)
- error (EXIT_FAILURE, 0,
- _("no operating system could be detected inside this disk
image.\n\nThis may be because the file is not a disk image, or is not a virtual
machine\nimage, or because the OS type is not understood by libguestfs.\n\nNOTE for Red
Hat Enterprise Linux 6 users: for Windows guest support you must\ninstall the separate
libguestfs-winsupport package.\n\nIf you feel this is an error, please file a bug report
including as much\ninformation about the disk image as possible.\n"));
+ error (
+ EXIT_FAILURE, 0,
+ _("no operating system could be detected inside this disk "
+ "image.\n\nThis may be because the file is not a disk image, or "
+ "is not a virtual machine\nimage, or because the OS type is not "
+ "understood by libguestfs.\n\nNOTE for Red Hat Enterprise Linux "
+ "6 users: for Windows guest support you must\ninstall the "
+ "separate libguestfs-winsupport package.\n\nIf you feel this is "
+ "an error, please file a bug report including as "
+ "much\ninformation about the disk image as possible.\n"));
output (roots);
}
@@ -286,9 +302,10 @@ main (int argc, char *argv[])
exit (EXIT_SUCCESS);
}
-#define XMLERROR(code,e) do { \
+#define XMLERROR(code, e) \
+ do { \
if ((e) == (code)) \
- error (EXIT_FAILURE, errno, _("XML write error at \"%s\""),
#e); \
+ error (EXIT_FAILURE, errno, _("XML write error at \"%s\""),
#e); \
} while (0)
static void
@@ -319,7 +336,8 @@ output_roots (xmlTextWriterPtr xo, char **roots)
{
size_t i;
- XMLERROR (-1, xmlTextWriterStartElement (xo, BAD_CAST "operatingsystems"));
+ XMLERROR (-1,
+ xmlTextWriterStartElement (xo, BAD_CAST "operatingsystems"));
for (i = 0; roots[i] != NULL; ++i)
output_root (xo, roots[i]);
XMLERROR (-1, xmlTextWriterEndElement (xo));
@@ -339,67 +357,73 @@ output_root (xmlTextWriterPtr xo, char *root)
canonical_root = guestfs_canonical_device_name (g, root);
if (canonical_root == NULL)
exit (EXIT_FAILURE);
- XMLERROR (-1,
- xmlTextWriterWriteElement (xo, BAD_CAST "root", BAD_CAST
canonical_root));
+ XMLERROR (-1, xmlTextWriterWriteElement (xo, BAD_CAST "root",
+ BAD_CAST canonical_root));
free (canonical_root);
str = guestfs_inspect_get_type (g, root);
- if (!str) exit (EXIT_FAILURE);
+ if (!str)
+ exit (EXIT_FAILURE);
if (STRNEQ (str, "unknown"))
- XMLERROR (-1,
- xmlTextWriterWriteElement (xo, BAD_CAST "name", BAD_CAST str));
+ XMLERROR (
+ -1, xmlTextWriterWriteElement (xo, BAD_CAST "name", BAD_CAST str));
free (str);
str = guestfs_inspect_get_arch (g, root);
- if (!str) exit (EXIT_FAILURE);
+ if (!str)
+ exit (EXIT_FAILURE);
if (STRNEQ (str, "unknown"))
- XMLERROR (-1,
- xmlTextWriterWriteElement (xo, BAD_CAST "arch", BAD_CAST str));
+ XMLERROR (
+ -1, xmlTextWriterWriteElement (xo, BAD_CAST "arch", BAD_CAST str));
free (str);
str = guestfs_inspect_get_distro (g, root);
- if (!str) exit (EXIT_FAILURE);
+ if (!str)
+ exit (EXIT_FAILURE);
if (STRNEQ (str, "unknown"))
- XMLERROR (-1,
- xmlTextWriterWriteElement (xo, BAD_CAST "distro", BAD_CAST str));
+ XMLERROR (
+ -1, xmlTextWriterWriteElement (xo, BAD_CAST "distro", BAD_CAST str));
free (str);
str = guestfs_inspect_get_product_name (g, root);
- if (!str) exit (EXIT_FAILURE);
+ if (!str)
+ exit (EXIT_FAILURE);
if (STRNEQ (str, "unknown"))
- XMLERROR (-1,
- xmlTextWriterWriteElement (xo, BAD_CAST "product_name", BAD_CAST str));
+ XMLERROR (-1, xmlTextWriterWriteElement (xo, BAD_CAST "product_name",
+ BAD_CAST str));
free (str);
str = guestfs_inspect_get_product_variant (g, root);
- if (!str) exit (EXIT_FAILURE);
+ if (!str)
+ exit (EXIT_FAILURE);
if (STRNEQ (str, "unknown"))
- XMLERROR (-1,
- xmlTextWriterWriteElement (xo, BAD_CAST "product_variant", BAD_CAST
str));
+ XMLERROR (-1, xmlTextWriterWriteElement (xo, BAD_CAST "product_variant",
+ BAD_CAST str));
free (str);
i = guestfs_inspect_get_major_version (g, root);
snprintf (buf, sizeof buf, "%d", i);
- XMLERROR (-1,
- xmlTextWriterWriteElement (xo, BAD_CAST "major_version", BAD_CAST buf));
+ XMLERROR (-1, xmlTextWriterWriteElement (xo, BAD_CAST "major_version",
+ BAD_CAST buf));
i = guestfs_inspect_get_minor_version (g, root);
snprintf (buf, sizeof buf, "%d", i);
- XMLERROR (-1,
- xmlTextWriterWriteElement (xo, BAD_CAST "minor_version", BAD_CAST buf));
+ XMLERROR (-1, xmlTextWriterWriteElement (xo, BAD_CAST "minor_version",
+ BAD_CAST buf));
str = guestfs_inspect_get_package_format (g, root);
- if (!str) exit (EXIT_FAILURE);
+ if (!str)
+ exit (EXIT_FAILURE);
if (STRNEQ (str, "unknown"))
- XMLERROR (-1,
- xmlTextWriterWriteElement (xo, BAD_CAST "package_format", BAD_CAST
str));
+ XMLERROR (-1, xmlTextWriterWriteElement (xo, BAD_CAST "package_format",
+ BAD_CAST str));
free (str);
str = guestfs_inspect_get_package_management (g, root);
- if (!str) exit (EXIT_FAILURE);
+ if (!str)
+ exit (EXIT_FAILURE);
if (STRNEQ (str, "unknown"))
- XMLERROR (-1,
- xmlTextWriterWriteElement (xo, BAD_CAST "package_management",
- BAD_CAST str));
+ XMLERROR (-1, xmlTextWriterWriteElement (
+ xo, BAD_CAST "package_management", BAD_CAST str));
free (str);
/* inspect-get-windows-systemroot will fail with non-windows guests,
@@ -409,52 +433,48 @@ output_root (xmlTextWriterPtr xo, char *root)
guestfs_push_error_handler (g, NULL, NULL);
str = guestfs_inspect_get_windows_systemroot (g, root);
if (str)
- XMLERROR (-1,
- xmlTextWriterWriteElement (xo, BAD_CAST "windows_systemroot",
- BAD_CAST str));
+ XMLERROR (-1, xmlTextWriterWriteElement (
+ xo, BAD_CAST "windows_systemroot", BAD_CAST str));
free (str);
str = guestfs_inspect_get_windows_current_control_set (g, root);
if (str)
- XMLERROR (-1,
- xmlTextWriterWriteElement (xo, BAD_CAST
"windows_current_control_set",
- BAD_CAST str));
+ XMLERROR (-1, xmlTextWriterWriteElement (xo, BAD_CAST
+ "windows_current_control_set",
+ BAD_CAST str));
free (str);
guestfs_pop_error_handler (g);
str = guestfs_inspect_get_hostname (g, root);
- if (!str) exit (EXIT_FAILURE);
+ if (!str)
+ exit (EXIT_FAILURE);
if (STRNEQ (str, "unknown"))
- XMLERROR (-1,
- xmlTextWriterWriteElement (xo, BAD_CAST "hostname",
- BAD_CAST str));
+ XMLERROR (-1, xmlTextWriterWriteElement (xo, BAD_CAST "hostname",
+ BAD_CAST str));
free (str);
str = guestfs_inspect_get_format (g, root);
- if (!str) exit (EXIT_FAILURE);
+ if (!str)
+ exit (EXIT_FAILURE);
if (STRNEQ (str, "unknown"))
- XMLERROR (-1,
- xmlTextWriterWriteElement (xo, BAD_CAST "format",
- BAD_CAST str));
+ XMLERROR (
+ -1, xmlTextWriterWriteElement (xo, BAD_CAST "format", BAD_CAST str));
free (str);
r = guestfs_inspect_is_live (g, root);
if (r > 0) {
- XMLERROR (-1,
- xmlTextWriterStartElement (xo, BAD_CAST "live"));
+ XMLERROR (-1, xmlTextWriterStartElement (xo, BAD_CAST "live"));
XMLERROR (-1, xmlTextWriterEndElement (xo));
}
r = guestfs_inspect_is_netinst (g, root);
if (r > 0) {
- XMLERROR (-1,
- xmlTextWriterStartElement (xo, BAD_CAST "netinst"));
+ XMLERROR (-1, xmlTextWriterStartElement (xo, BAD_CAST "netinst"));
XMLERROR (-1, xmlTextWriterEndElement (xo));
}
r = guestfs_inspect_is_multipart (g, root);
if (r > 0) {
- XMLERROR (-1,
- xmlTextWriterStartElement (xo, BAD_CAST "multipart"));
+ XMLERROR (-1, xmlTextWriterStartElement (xo, BAD_CAST "multipart"));
XMLERROR (-1, xmlTextWriterEndElement (xo));
}
@@ -477,10 +497,10 @@ output_root (xmlTextWriterPtr xo, char *root)
/* Don't return favicon. RHEL 7 and Fedora have crappy 16x16
* favicons in the base distro.
*/
- str = guestfs_inspect_get_icon (g, root, &size,
- GUESTFS_INSPECT_GET_ICON_FAVICON, 0,
- -1);
- if (!str) exit (EXIT_FAILURE);
+ str = guestfs_inspect_get_icon (
+ g, root, &size, GUESTFS_INSPECT_GET_ICON_FAVICON, 0, -1);
+ if (!str)
+ exit (EXIT_FAILURE);
if (size > 0) {
XMLERROR (-1, xmlTextWriterStartElement (xo, BAD_CAST "icon"));
XMLERROR (-1, xmlTextWriterWriteBase64 (xo, str, 0, size));
@@ -503,8 +523,8 @@ output_root (xmlTextWriterPtr xo, char *root)
static int
compare_keys (const void *p1, const void *p2)
{
- const char *key1 = * (char * const *) p1;
- const char *key2 = * (char * const *) p2;
+ const char *key1 = *(char *const *)p1;
+ const char *key2 = *(char *const *)p2;
return strcmp (key1, key2);
}
@@ -512,8 +532,8 @@ compare_keys (const void *p1, const void *p2)
static int
compare_keys_nocase (const void *p1, const void *p2)
{
- const char *key1 = * (char * const *) p1;
- const char *key2 = * (char * const *) p2;
+ const char *key1 = *(char *const *)p1;
+ const char *key2 = *(char *const *)p2;
return strcasecmp (key1, key2);
}
@@ -521,8 +541,8 @@ compare_keys_nocase (const void *p1, const void *p2)
static int
compare_keys_len (const void *p1, const void *p2)
{
- const char *key1 = * (char * const *) p1;
- const char *key2 = * (char * const *) p2;
+ const char *key1 = *(char *const *)p1;
+ const char *key2 = *(char *const *)p2;
int c;
c = strlen (key1) - strlen (key2);
@@ -546,22 +566,20 @@ output_mountpoints (xmlTextWriterPtr xo, char *root)
* output is stable.
*/
qsort (mountpoints, guestfs_int_count_strings (mountpoints) / 2,
- 2 * sizeof (char *),
- compare_keys_len);
+ 2 * sizeof (char *), compare_keys_len);
XMLERROR (-1, xmlTextWriterStartElement (xo, BAD_CAST "mountpoints"));
for (i = 0; mountpoints[i] != NULL; i += 2) {
- CLEANUP_FREE char *p = guestfs_canonical_device_name (g, mountpoints[i+1]);
+ CLEANUP_FREE char *p =
+ guestfs_canonical_device_name (g, mountpoints[i + 1]);
if (!p)
exit (EXIT_FAILURE);
- XMLERROR (-1,
- xmlTextWriterStartElement (xo, BAD_CAST "mountpoint"));
+ XMLERROR (-1, xmlTextWriterStartElement (xo, BAD_CAST "mountpoint"));
XMLERROR (-1,
xmlTextWriterWriteAttribute (xo, BAD_CAST "dev", BAD_CAST p));
- XMLERROR (-1,
- xmlTextWriterWriteString (xo, BAD_CAST mountpoints[i]));
+ XMLERROR (-1, xmlTextWriterWriteString (xo, BAD_CAST mountpoints[i]));
XMLERROR (-1, xmlTextWriterEndElement (xo));
}
@@ -580,8 +598,8 @@ output_filesystems (xmlTextWriterPtr xo, char *root)
exit (EXIT_FAILURE);
/* Sort by name so the output is stable. */
- qsort (filesystems, guestfs_int_count_strings (filesystems), sizeof (char *),
- compare_keys);
+ qsort (filesystems, guestfs_int_count_strings (filesystems),
+ sizeof (char *), compare_keys);
XMLERROR (-1, xmlTextWriterStartElement (xo, BAD_CAST "filesystems"));
@@ -591,31 +609,28 @@ output_filesystems (xmlTextWriterPtr xo, char *root)
exit (EXIT_FAILURE);
XMLERROR (-1, xmlTextWriterStartElement (xo, BAD_CAST "filesystem"));
- XMLERROR (-1,
- xmlTextWriterWriteAttribute (xo, BAD_CAST "dev", BAD_CAST str));
+ XMLERROR (
+ -1, xmlTextWriterWriteAttribute (xo, BAD_CAST "dev", BAD_CAST str));
free (str);
guestfs_push_error_handler (g, NULL, NULL);
str = guestfs_vfs_type (g, filesystems[i]);
if (str && str[0])
- XMLERROR (-1,
- xmlTextWriterWriteElement (xo, BAD_CAST "type",
- BAD_CAST str));
+ XMLERROR (
+ -1, xmlTextWriterWriteElement (xo, BAD_CAST "type", BAD_CAST str));
free (str);
str = guestfs_vfs_label (g, filesystems[i]);
if (str && str[0])
- XMLERROR (-1,
- xmlTextWriterWriteElement (xo, BAD_CAST "label",
- BAD_CAST str));
+ XMLERROR (
+ -1, xmlTextWriterWriteElement (xo, BAD_CAST "label", BAD_CAST str));
free (str);
str = guestfs_vfs_uuid (g, filesystems[i]);
if (str && str[0])
- XMLERROR (-1,
- xmlTextWriterWriteElement (xo, BAD_CAST "uuid",
- BAD_CAST str));
+ XMLERROR (
+ -1, xmlTextWriterWriteElement (xo, BAD_CAST "uuid", BAD_CAST str));
free (str);
guestfs_pop_error_handler (g);
@@ -643,24 +658,20 @@ output_drive_mappings (xmlTextWriterPtr xo, char *root)
return;
/* Sort by key. */
- qsort (drive_mappings,
- guestfs_int_count_strings (drive_mappings) / 2, 2 * sizeof (char *),
- compare_keys_nocase);
+ qsort (drive_mappings, guestfs_int_count_strings (drive_mappings) / 2,
+ 2 * sizeof (char *), compare_keys_nocase);
XMLERROR (-1, xmlTextWriterStartElement (xo, BAD_CAST "drive_mappings"));
for (i = 0; drive_mappings[i] != NULL; i += 2) {
- str = guestfs_canonical_device_name (g, drive_mappings[i+1]);
+ str = guestfs_canonical_device_name (g, drive_mappings[i + 1]);
if (!str)
exit (EXIT_FAILURE);
- XMLERROR (-1,
- xmlTextWriterStartElement (xo, BAD_CAST "drive_mapping"));
- XMLERROR (-1,
- xmlTextWriterWriteAttribute (xo, BAD_CAST "name",
- BAD_CAST drive_mappings[i]));
- XMLERROR (-1,
- xmlTextWriterWriteString (xo, BAD_CAST str));
+ XMLERROR (-1, xmlTextWriterStartElement (xo, BAD_CAST "drive_mapping"));
+ XMLERROR (-1, xmlTextWriterWriteAttribute (xo, BAD_CAST "name",
+ BAD_CAST drive_mappings[i]));
+ XMLERROR (-1, xmlTextWriterWriteString (xo, BAD_CAST str));
XMLERROR (-1, xmlTextWriterEndElement (xo));
free (str);
@@ -688,60 +699,59 @@ output_applications (xmlTextWriterPtr xo, char *root)
XMLERROR (-1, xmlTextWriterStartElement (xo, BAD_CAST "application"));
assert (apps->val[i].app2_name && apps->val[i].app2_name[0]);
- XMLERROR (-1,
- xmlTextWriterWriteElement (xo, BAD_CAST "name",
- BAD_CAST apps->val[i].app2_name));
+ XMLERROR (-1, xmlTextWriterWriteElement (
+ xo, BAD_CAST "name", BAD_CAST apps->val[i].app2_name));
if (apps->val[i].app2_display_name &&
apps->val[i].app2_display_name[0])
- XMLERROR (-1,
- xmlTextWriterWriteElement (xo, BAD_CAST "display_name",
- BAD_CAST apps->val[i].app2_display_name));
+ XMLERROR (-1, xmlTextWriterWriteElement (
+ xo, BAD_CAST "display_name",
+ BAD_CAST apps->val[i].app2_display_name));
if (apps->val[i].app2_epoch != 0) {
char buf[32];
snprintf (buf, sizeof buf, "%d", apps->val[i].app2_epoch);
- XMLERROR (-1,
- xmlTextWriterWriteElement (xo, BAD_CAST "epoch", BAD_CAST buf));
+ XMLERROR (
+ -1, xmlTextWriterWriteElement (xo, BAD_CAST "epoch", BAD_CAST buf));
}
if (apps->val[i].app2_version && apps->val[i].app2_version[0])
- XMLERROR (-1,
- xmlTextWriterWriteElement (xo, BAD_CAST "version",
- BAD_CAST apps->val[i].app2_version));
+ XMLERROR (
+ -1, xmlTextWriterWriteElement (xo, BAD_CAST "version",
+ BAD_CAST apps->val[i].app2_version));
if (apps->val[i].app2_release && apps->val[i].app2_release[0])
- XMLERROR (-1,
- xmlTextWriterWriteElement (xo, BAD_CAST "release",
- BAD_CAST apps->val[i].app2_release));
+ XMLERROR (
+ -1, xmlTextWriterWriteElement (xo, BAD_CAST "release",
+ BAD_CAST apps->val[i].app2_release));
if (apps->val[i].app2_arch && apps->val[i].app2_arch[0])
- XMLERROR (-1,
- xmlTextWriterWriteElement (xo, BAD_CAST "arch",
- BAD_CAST apps->val[i].app2_arch));
+ XMLERROR (
+ -1, xmlTextWriterWriteElement (xo, BAD_CAST "arch",
+ BAD_CAST apps->val[i].app2_arch));
if (apps->val[i].app2_install_path &&
apps->val[i].app2_install_path[0])
- XMLERROR (-1,
- xmlTextWriterWriteElement (xo, BAD_CAST "install_path",
- BAD_CAST apps->val[i].app2_install_path));
+ XMLERROR (-1, xmlTextWriterWriteElement (
+ xo, BAD_CAST "install_path",
+ BAD_CAST apps->val[i].app2_install_path));
if (apps->val[i].app2_publisher && apps->val[i].app2_publisher[0])
- XMLERROR (-1,
- xmlTextWriterWriteElement (xo, BAD_CAST "publisher",
- BAD_CAST apps->val[i].app2_publisher));
+ XMLERROR (-1, xmlTextWriterWriteElement (
+ xo, BAD_CAST "publisher",
+ BAD_CAST apps->val[i].app2_publisher));
if (apps->val[i].app2_url && apps->val[i].app2_url[0])
- XMLERROR (-1,
- xmlTextWriterWriteElement (xo, BAD_CAST "url",
- BAD_CAST apps->val[i].app2_url));
- if (apps->val[i].app2_source_package &&
apps->val[i].app2_source_package[0])
- XMLERROR (-1,
- xmlTextWriterWriteElement (xo, BAD_CAST "source_package",
- BAD_CAST apps->val[i].app2_source_package));
+ XMLERROR (-1, xmlTextWriterWriteElement (
+ xo, BAD_CAST "url", BAD_CAST apps->val[i].app2_url));
+ if (apps->val[i].app2_source_package &&
+ apps->val[i].app2_source_package[0])
+ XMLERROR (-1, xmlTextWriterWriteElement (
+ xo, BAD_CAST "source_package",
+ BAD_CAST apps->val[i].app2_source_package));
if (apps->val[i].app2_summary && apps->val[i].app2_summary[0])
- XMLERROR (-1,
- xmlTextWriterWriteElement (xo, BAD_CAST "summary",
- BAD_CAST apps->val[i].app2_summary));
+ XMLERROR (
+ -1, xmlTextWriterWriteElement (xo, BAD_CAST "summary",
+ BAD_CAST apps->val[i].app2_summary));
if (apps->val[i].app2_description && apps->val[i].app2_description[0])
- XMLERROR (-1,
- xmlTextWriterWriteElement (xo, BAD_CAST "description",
- BAD_CAST apps->val[i].app2_description));
+ XMLERROR (-1, xmlTextWriterWriteElement (
+ xo, BAD_CAST "description",
+ BAD_CAST apps->val[i].app2_description));
XMLERROR (-1, xmlTextWriterEndElement (xo));
}
@@ -780,12 +790,12 @@ do_xpath (const char *query)
if (nodes == NULL)
break;
- saveCtx = xmlSaveToFd (STDOUT_FILENO, NULL,
- XML_SAVE_NO_DECL | XML_SAVE_FORMAT);
+ saveCtx =
+ xmlSaveToFd (STDOUT_FILENO, NULL, XML_SAVE_NO_DECL | XML_SAVE_FORMAT);
if (saveCtx == NULL)
error (EXIT_FAILURE, 0, _("xmlSaveToFd failed"));
- for (i = 0; i < (size_t) nodes->nodeNr; ++i) {
+ for (i = 0; i < (size_t)nodes->nodeNr; ++i) {
CLEANUP_XMLFREEDOC xmlDocPtr wrdoc = xmlNewDoc (BAD_CAST "1.0");
if (wrdoc == NULL)
error (EXIT_FAILURE, 0, _("xmlNewDoc failed"));
@@ -804,10 +814,10 @@ do_xpath (const char *query)
break;
case XPATH_STRING:
- r = (char *) xpathObj->stringval;
+ r = (char *)xpathObj->stringval;
printf ("%s", r);
i = strlen (r);
- if (i > 0 && r[i-1] != '\n')
+ if (i > 0 && r[i - 1] != '\n')
printf ("\n");
break;
@@ -820,7 +830,7 @@ do_xpath (const char *query)
case XPATH_USERS:
case XPATH_XSLT_TREE:
default:
- r = (char *) xmlXPathCastToString (xpathObj);
+ r = (char *)xmlXPathCastToString (xpathObj);
printf ("%s\n", r);
free (r);
}
diff --git a/make-fs/make-fs.c b/make-fs/make-fs.c
index 42e7e82..3bdcc9c 100644
--- a/make-fs/make-fs.c
+++ b/make-fs/make-fs.c
@@ -47,25 +47,19 @@ int live;
int read_only;
int verbose;
-static const char *format = "raw", *label = NULL,
- *partition = NULL, *size_str = NULL, *type = "ext2";
+static const char *format = "raw", *label = NULL, *partition = NULL,
+ *size_str = NULL, *type = "ext2";
enum { HELP_OPTION = CHAR_MAX + 1 };
static const char *options = "F:s:t:Vvx";
static const struct option long_options[] = {
{ "debug", 0, 0, 'v' }, /* for compat with Perl tool */
- { "floppy", 0, 0, 0 },
- { "format", 1, 0, 'F' },
- { "help", 0, 0, HELP_OPTION },
- { "label", 1, 0, 0 },
- { "long-options", 0, 0, 0 },
- { "partition", 2, 0, 0 },
- { "short-options", 0, 0, 0 },
- { "size", 1, 0, 's' },
- { "type", 1, 0, 't' },
- { "verbose", 0, 0, 'v' },
- { "version", 0, 0, 'V' },
- { 0, 0, 0, 0 }
+ { "floppy", 0, 0, 0 }, { "format", 1, 0, 'F' },
+ { "help", 0, 0, HELP_OPTION }, { "label", 1, 0, 0 },
+ { "long-options", 0, 0, 0 }, { "partition", 2, 0, 0 },
+ { "short-options", 0, 0, 0 }, { "size", 1, 0, 's' },
+ { "type", 1, 0, 't' }, { "verbose", 0, 0,
'v' },
+ { "version", 0, 0, 'V' }, { 0, 0, 0, 0 }
};
static void __attribute__((noreturn))
@@ -118,10 +112,11 @@ main (int argc, char *argv[])
for (;;) {
c = getopt_long (argc, argv, options, long_options, &option_index);
- if (c == -1) break;
+ if (c == -1)
+ break;
switch (c) {
- case 0: /* options which are long only */
+ case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "long-options")) {
display_long_options (long_options);
}
@@ -141,9 +136,9 @@ main (int argc, char *argv[])
partition = "mbr";
else
partition = optarg;
- } else
- error (EXIT_FAILURE, 0,
- _("unknown long option: %s (%d)"),
+ }
+ else
+ error (EXIT_FAILURE, 0, _("unknown long option: %s (%d)"),
long_options[option_index].name, option_index);
break;
@@ -180,13 +175,14 @@ main (int argc, char *argv[])
}
if (optind + 2 != argc) {
- fprintf (stderr,
- _("%s: missing input and output arguments on the command
line\n"),
- guestfs_int_program_name);
+ fprintf (
+ stderr,
+ _("%s: missing input and output arguments on the command line\n"),
+ guestfs_int_program_name);
usage (EXIT_FAILURE);
}
- if (do_make_fs (argv[optind], argv[optind+1]) == -1)
+ if (do_make_fs (argv[optind], argv[optind + 1]) == -1)
exit (EXIT_FAILURE);
exit (EXIT_SUCCESS);
@@ -198,10 +194,11 @@ check_ntfs_available (void)
const char *ntfs_features[] = { "ntfs3g", "ntfsprogs", NULL };
if (STREQ (type, "ntfs") &&
- guestfs_feature_available (g, (char **) ntfs_features) == 0) {
- fprintf (stderr,
- _("%s: NTFS support was disabled when libguestfs was
compiled\n"),
- guestfs_int_program_name);
+ guestfs_feature_available (g, (char **)ntfs_features) == 0) {
+ fprintf (
+ stderr,
+ _("%s: NTFS support was disabled when libguestfs was compiled\n"),
+ guestfs_int_program_name);
return -1;
}
@@ -215,7 +212,8 @@ print_stats (guestfs_h *g, const char *before_or_after)
if (!verbose)
return;
- CLEANUP_FREE_STATVFS struct guestfs_statvfs *stats = guestfs_statvfs (g,
"/");
+ CLEANUP_FREE_STATVFS struct guestfs_statvfs *stats =
+ guestfs_statvfs (g, "/");
if (stats) {
fprintf (stderr, "%s uploading:\n", before_or_after);
fprintf (stderr, " bsize = %" PRIi64 "\n", stats->bsize);
@@ -258,7 +256,7 @@ exec_command (char **argv, const char *file)
}
/* Child process. */
- fd = open (file, O_WRONLY|O_NOCTTY);
+ fd = open (file, O_WRONLY | O_NOCTTY);
if (fd == -1) {
perror (file);
_exit (EXIT_FAILURE);
@@ -425,7 +423,7 @@ estimate_input (const char *input, uint64_t *estimate_rtn, char
**ifmt_rtn)
argv[4] = input;
argv[5] = NULL;
- if (exec_command ((char **) argv, tmpfile) == -1)
+ if (exec_command ((char **)argv, tmpfile) == -1)
return -1;
fp = fopen (tmpfile, "r");
@@ -439,7 +437,8 @@ estimate_input (const char *input, uint64_t *estimate_rtn, char
**ifmt_rtn)
}
if (sscanf (line, "%" SCNu64, estimate_rtn) != 1) {
- fprintf (stderr, _("%s: cannot parse the output of 'du' command:
%s\n"),
+ fprintf (stderr,
+ _("%s: cannot parse the output of 'du' command: %s\n"),
guestfs_int_program_name, line);
return -1;
}
@@ -450,7 +449,7 @@ estimate_input (const char *input, uint64_t *estimate_rtn, char
**ifmt_rtn)
argv[2] = input;
argv[3] = NULL;
- if (exec_command ((char **) argv, tmpfile) == -1)
+ if (exec_command ((char **)argv, tmpfile) == -1)
return -1;
fp = fopen (tmpfile, "r");
@@ -464,8 +463,8 @@ estimate_input (const char *input, uint64_t *estimate_rtn, char
**ifmt_rtn)
}
len = strlen (line);
- if (len > 0 && line[len-1] == '\n')
- line[len-1] = '\0';
+ if (len > 0 && line[len - 1] == '\n')
+ line[len - 1] = '\0';
*ifmt_rtn = strdup (line);
if (*ifmt_rtn == NULL) {
@@ -474,7 +473,8 @@ estimate_input (const char *input, uint64_t *estimate_rtn, char
**ifmt_rtn)
}
if (strstr (line, "tar archive") == NULL) {
- fprintf (stderr, _("%s: %s: input is not a directory, tar archive or
compressed tar archive\n"),
+ fprintf (stderr, _("%s: %s: input is not a directory, tar archive "
+ "or compressed tar archive\n"),
guestfs_int_program_name, input);
return -1;
}
@@ -505,13 +505,14 @@ estimate_input (const char *input, uint64_t *estimate_rtn, char
**ifmt_rtn)
argv[3] = NULL;
}
else {
- fprintf (stderr, _("%s: %s: unknown compressed input format (%s)\n"),
+ fprintf (stderr,
+ _("%s: %s: unknown compressed input format (%s)\n"),
guestfs_int_program_name, input, line);
return -1;
}
*estimate_rtn = 0;
- if (exec_command_count_output ((char **) argv, estimate_rtn) == -1)
+ if (exec_command_count_output ((char **)argv, estimate_rtn) == -1)
return -1;
}
else {
@@ -534,8 +535,8 @@ estimate_input (const char *input, uint64_t *estimate_rtn, char
**ifmt_rtn)
* the PID is returned so that callers can wait on it.
*/
static int
-prepare_input (const char *input, const char *ifmt,
- char **ifile_rtn, int *fd_rtn, pid_t *pid_rtn)
+prepare_input (const char *input, const char *ifmt, char **ifile_rtn,
+ int *fd_rtn, pid_t *pid_rtn)
{
const char *argv[7];
@@ -551,7 +552,7 @@ prepare_input (const char *input, const char *ifmt,
argv[5] = ".";
argv[6] = NULL;
- if (bg_command ((char **) argv, fd_rtn, pid_rtn) == -1)
+ if (bg_command ((char **)argv, fd_rtn, pid_rtn) == -1)
return -1;
if (asprintf (ifile_rtn, "/dev/fd/%d", *fd_rtn) == -1) {
@@ -589,7 +590,7 @@ prepare_input (const char *input, const char *ifmt,
/* Shouldn't happen - see estimate_input above. */
abort ();
- if (bg_command ((char **) argv, fd_rtn, pid_rtn) == -1)
+ if (bg_command ((char **)argv, fd_rtn, pid_rtn) == -1)
return -1;
if (asprintf (ifile_rtn, "/dev/fd/%d", *fd_rtn) == -1) {
@@ -627,9 +628,9 @@ parse_size (const char *str, uint64_t estimate, uint64_t *size_rtn)
xerr = xstrtoull (str, NULL, 0, &size, "0kKMGTPEZY");
if (xerr != LONGINT_OK) {
- fprintf (stderr,
- _("%s: %s: invalid size parameter '%s' (%s returned
%u)\n"),
- guestfs_int_program_name, "parse_size", str,
"xstrtoull", xerr);
+ fprintf (
+ stderr, _("%s: %s: invalid size parameter '%s' (%s returned
%u)\n"),
+ guestfs_int_program_name, "parse_size", str, "xstrtoull",
xerr);
return -1;
}
@@ -669,11 +670,11 @@ do_make_fs (const char *input, const char *output_str)
if (verbose) {
fprintf (stderr, "input format = %s\n", ifmt);
fprintf (stderr, "estimate = %" PRIu64 " bytes "
- "(%" PRIu64 " 1K blocks, %" PRIu64 " 4K
blocks)\n",
+ "(%" PRIu64 " 1K blocks, %" PRIu64 " 4K
blocks)\n",
estimate, estimate / 1024, estimate / 4096);
}
- estimate += 256 * 1024; /* For superblocks &c. */
+ estimate += 256 * 1024; /* For superblocks &c. */
if (STRPREFIX (type, "ext") && type[3] >= '3') {
/* For ext3+, add some more for the journal. */
@@ -698,9 +699,8 @@ do_make_fs (const char *input, const char *output_str)
/* Calculate the output size. */
if (size_str == NULL)
size = estimate;
- else
- if (parse_size (size_str, estimate, &size) == -1)
- return -1;
+ else if (parse_size (size_str, estimate, &size) == -1)
+ return -1;
/* Create the output disk. */
optargs.bitmask = 0;
@@ -711,9 +711,8 @@ do_make_fs (const char *input, const char *output_str)
if (guestfs_disk_create_argv (g, output, format, size, &optargs) == -1)
return -1;
- if (guestfs_add_drive_opts (g, output,
- GUESTFS_ADD_DRIVE_OPTS_FORMAT, format,
- -1) == -1)
+ if (guestfs_add_drive_opts (g, output, GUESTFS_ADD_DRIVE_OPTS_FORMAT,
+ format, -1) == -1)
return -1;
if (guestfs_launch (g) == -1)
@@ -740,7 +739,8 @@ do_make_fs (const char *input, const char *output_str)
*/
if (STREQ (partition, "mbr") || STREQ (partition, "msdos")) {
if (STREQ (type, "msdos"))
- /* According to Wikipedia. However I have not actually tried this. */
+ /* According to Wikipedia. However I have not actually tried this.
+ */
mbr_id = 0x1;
else if (STREQ (type, "vfat") || STREQ (type, "fat"))
mbr_id = 0xb;
@@ -763,7 +763,7 @@ do_make_fs (const char *input, const char *output_str)
/* Create the filesystem. */
if (STRNEQ (type, "btrfs")) {
int r;
- struct guestfs_mkfs_opts_argv optargs = { .bitmask = 0 };
+ struct guestfs_mkfs_opts_argv optargs = {.bitmask = 0 };
if (label) {
optargs.label = label;
@@ -776,10 +776,12 @@ do_make_fs (const char *input, const char *output_str)
if (r == -1) {
/* Provide more guidance in the error message (RHBZ#823883). */
- fprintf (stderr, "%s: 'mkfs' (create filesystem) operation failed:
%s\n",
+ fprintf (stderr,
+ "%s: 'mkfs' (create filesystem) operation failed:
%s\n",
guestfs_int_program_name, guestfs_last_error (g));
if (STREQ (type, "fat"))
- fprintf (stderr, "Instead of 'fat', try 'vfat' (long
filenames) or 'msdos' (short filenames).\n");
+ fprintf (stderr, "Instead of 'fat', try 'vfat' (long
filenames) or "
+ "'msdos' (short filenames).\n");
else
fprintf (stderr, "Is '%s' a correct filesystem type?\n",
type);
@@ -788,17 +790,18 @@ do_make_fs (const char *input, const char *output_str)
}
else {
const char *devs[] = { dev, NULL };
- struct guestfs_mkfs_btrfs_argv optargs = { .bitmask = 0 };
+ struct guestfs_mkfs_btrfs_argv optargs = {.bitmask = 0 };
optargs.datatype = "single";
optargs.metadata = "single";
- optargs.bitmask |= GUESTFS_MKFS_BTRFS_DATATYPE_BITMASK |
GUESTFS_MKFS_BTRFS_METADATA_BITMASK;
+ optargs.bitmask |= GUESTFS_MKFS_BTRFS_DATATYPE_BITMASK |
+ GUESTFS_MKFS_BTRFS_METADATA_BITMASK;
if (label) {
optargs.label = label;
optargs.bitmask |= GUESTFS_MKFS_BTRFS_LABEL_BITMASK;
}
- if (guestfs_mkfs_btrfs_argv (g, (char **) devs, &optargs) == -1)
+ if (guestfs_mkfs_btrfs_argv (g, (char **)devs, &optargs) == -1)
return -1;
}
@@ -834,7 +837,8 @@ do_make_fs (const char *input, const char *output_str)
return -1;
}
if (!WIFEXITED (status) || WEXITSTATUS (status) != 0) {
- fprintf (stderr, _("%s: subprocess failed\n"),
guestfs_int_program_name);
+ fprintf (stderr, _("%s: subprocess failed\n"),
+ guestfs_int_program_name);
return -1;
}
}
diff --git a/mllib/fsync-c.c b/mllib/fsync-c.c
index 72e74ef..2104f18 100644
--- a/mllib/fsync-c.c
+++ b/mllib/fsync-c.c
@@ -32,8 +32,8 @@
#ifdef HAVE_CAML_UNIXSUPPORT_H
#include <caml/unixsupport.h>
#else
-#define Nothing ((value) 0)
-extern void unix_error (int errcode, char * cmdname, value arg) Noreturn;
+#define Nothing ((value)0)
+extern void unix_error (int errcode, char *cmdname, value arg) Noreturn;
#endif
/* OCaml doesn't bind any *sync* calls. */
@@ -69,16 +69,16 @@ guestfs_int_mllib_fsync_file (value filenamev)
/* Note to do fsync you have to open for write. */
fd = open (filename, O_RDWR);
if (fd == -1)
- unix_error (errno, (char *) "open", filenamev);
+ unix_error (errno, (char *)"open", filenamev);
if (fsync (fd) == -1) {
err = errno;
close (fd);
- unix_error (err, (char *) "fsync", filenamev);
+ unix_error (err, (char *)"fsync", filenamev);
}
if (close (fd) == -1)
- unix_error (errno, (char *) "close", filenamev);
+ unix_error (errno, (char *)"close", filenamev);
CAMLreturn (Val_unit);
}
diff --git a/mllib/mkdtemp-c.c b/mllib/mkdtemp-c.c
index a31e3a7..b99f3ad 100644
--- a/mllib/mkdtemp-c.c
+++ b/mllib/mkdtemp-c.c
@@ -30,8 +30,8 @@
#ifdef HAVE_CAML_UNIXSUPPORT_H
#include <caml/unixsupport.h>
#else
-#define Nothing ((value) 0)
-extern void unix_error (int errcode, char * cmdname, value arg) Noreturn;
+#define Nothing ((value)0)
+extern void unix_error (int errcode, char *cmdname, value arg) Noreturn;
#endif
#pragma GCC diagnostic ignored "-Wmissing-prototypes"
@@ -45,11 +45,11 @@ guestfs_int_mllib_mkdtemp (value val_pattern)
pattern = strdup (String_val (val_pattern));
if (pattern == NULL)
- unix_error (errno, (char *) "strdup", val_pattern);
+ unix_error (errno, (char *)"strdup", val_pattern);
ret = mkdtemp (pattern);
if (ret == NULL)
- unix_error (errno, (char *) "mkdtemp", val_pattern);
+ unix_error (errno, (char *)"mkdtemp", val_pattern);
rv = caml_copy_string (ret);
free (pattern);
diff --git a/mllib/progress-c.c b/mllib/progress-c.c
index 8e5efd3..113885b 100644
--- a/mllib/progress-c.c
+++ b/mllib/progress-c.c
@@ -35,7 +35,7 @@
#pragma GCC diagnostic ignored "-Wmissing-prototypes"
-#define Bar_val(v) (*((struct progress_bar **)Data_custom_val(v)))
+#define Bar_val(v) (*((struct progress_bar **)Data_custom_val (v)))
static void
progress_bar_finalize (value barv)
@@ -47,7 +47,7 @@ progress_bar_finalize (value barv)
}
static struct custom_operations progress_bar_custom_operations = {
- (char *) "progress_bar_custom_operations",
+ (char *)"progress_bar_custom_operations",
progress_bar_finalize,
custom_compare_default,
custom_hash_default,
@@ -95,8 +95,8 @@ guestfs_int_mllib_progress_bar_reset (value barv)
/* NB: "noalloc" function. */
value
-guestfs_int_mllib_progress_bar_set (value barv,
- value positionv, value totalv)
+guestfs_int_mllib_progress_bar_set (value barv, value positionv,
+ value totalv)
{
struct progress_bar *bar = Bar_val (barv);
uint64_t position = Int64_val (positionv);
diff --git a/mllib/uri-c.c b/mllib/uri-c.c
index f3af817..5f52787 100644
--- a/mllib/uri-c.c
+++ b/mllib/uri-c.c
@@ -63,7 +63,7 @@ guestfs_int_mllib_parse_uri (value argv /* arg value, not an array! */)
/* server : string array option */
if (uri.server) {
- ssv = caml_copy_string_array ((const char **) uri.server);
+ ssv = caml_copy_string_array ((const char **)uri.server);
guestfs_int_free_string_list (uri.server);
ov = caml_alloc (1, 0);
Store_field (ov, 0, ssv);
diff --git a/ocaml/guestfs-c.c b/ocaml/guestfs-c.c
index edb4646..aef86e5 100644
--- a/ocaml/guestfs-c.c
+++ b/ocaml/guestfs-c.c
@@ -38,28 +38,35 @@
#ifdef HAVE_CAML_UNIXSUPPORT_H
#include <caml/unixsupport.h>
#else
-#define Nothing ((value) 0)
-extern void unix_error (int errcode, char * cmdname, value arg) Noreturn;
+#define Nothing ((value)0)
+extern void unix_error (int errcode, char *cmdname, value arg) Noreturn;
#endif
#include "guestfs-c.h"
static value **get_all_event_callbacks (guestfs_h *g, size_t *len_rtn);
-static void event_callback_wrapper (guestfs_h *g, void *data, uint64_t event, int
event_handle, int flags, const char *buf, size_t buf_len, const uint64_t *array, size_t
array_len);
+static void event_callback_wrapper (guestfs_h *g, void *data,
+ uint64_t event, int event_handle,
+ int flags, const char *buf,
+ size_t buf_len, const uint64_t *array,
+ size_t array_len);
/* This macro was added in OCaml 3.10. Backport for earlier versions. */
#ifndef CAMLreturnT
-#define CAMLreturnT(type, result) do{ \
- type caml__temp_result = (result); \
- caml_local_roots = caml__frame; \
- return (caml__temp_result); \
- }while(0)
+#define CAMLreturnT(type, result) \
+ do { \
+ type caml__temp_result = (result); \
+ caml_local_roots = caml__frame; \
+ return (caml__temp_result); \
+ } while (0)
#endif
/* These prototypes are solely to quiet gcc warning. */
-value guestfs_int_ocaml_create (value environmentv, value close_on_exitv, value unitv);
+value guestfs_int_ocaml_create (value environmentv, value close_on_exitv,
+ value unitv);
value guestfs_int_ocaml_close (value gv);
-value guestfs_int_ocaml_set_event_callback (value gv, value closure, value events);
+value guestfs_int_ocaml_set_event_callback (value gv, value closure,
+ value events);
value guestfs_int_ocaml_delete_event_callback (value gv, value eh);
value guestfs_int_ocaml_event_to_string (value events);
value guestfs_int_ocaml_last_errno (value gv);
@@ -94,7 +101,7 @@ guestfs_finalize (value gv)
}
static struct custom_operations guestfs_custom_operations = {
- (char *) "guestfs_custom_operations",
+ (char *)"guestfs_custom_operations",
guestfs_finalize,
custom_compare_default,
custom_hash_default,
@@ -108,8 +115,8 @@ Val_guestfs (guestfs_h *g)
CAMLparam0 ();
CAMLlocal1 (rv);
- rv = caml_alloc_custom (&guestfs_custom_operations,
- sizeof (guestfs_h *), 0, 1);
+ rv = caml_alloc_custom (&guestfs_custom_operations, sizeof (guestfs_h *),
+ 0, 1);
Guestfs_val (rv) = g;
CAMLreturn (rv);
@@ -145,15 +152,15 @@ guestfs_int_ocaml_raise_closed (const char *func)
/* Guestfs.create */
value
-guestfs_int_ocaml_create (value environmentv, value close_on_exitv, value unitv)
+guestfs_int_ocaml_create (value environmentv, value close_on_exitv,
+ value unitv)
{
CAMLparam3 (environmentv, close_on_exitv, unitv);
CAMLlocal1 (gv);
unsigned flags = 0;
guestfs_h *g;
- if (environmentv != Val_int (0) &&
- !Bool_val (Field (environmentv, 0)))
+ if (environmentv != Val_int (0) && !Bool_val (Field (environmentv, 0)))
flags |= GUESTFS_CREATE_NO_ENVIRONMENT;
if (close_on_exitv != Val_int (0) &&
@@ -194,10 +201,12 @@ guestfs_int_ocaml_strings_val (guestfs_h *g, value sv)
size_t i;
r = malloc (sizeof (char *) * (Wosize_val (sv) + 1));
- if (r == NULL) caml_raise_out_of_memory ();
+ if (r == NULL)
+ caml_raise_out_of_memory ();
for (i = 0; i < Wosize_val (sv); ++i) {
r[i] = strdup (String_val (Field (sv, i)));
- if (r[i] == NULL) caml_raise_out_of_memory ();
+ if (r[i] == NULL)
+ caml_raise_out_of_memory ();
}
r[i] = NULL;
@@ -210,7 +219,7 @@ event_bitmask_of_event_list (value events)
uint64_t r = 0;
while (events != Val_int (0)) {
- r |= UINT64_C(1) << Int_val (Field (events, 0));
+ r |= UINT64_C (1) << Int_val (Field (events, 0));
events = Field (events, 1);
}
@@ -231,11 +240,12 @@ guestfs_int_ocaml_set_event_callback (value gv, value closure, value
events)
event_bitmask = event_bitmask_of_event_list (events);
value *root = malloc (sizeof *root);
- if (root == NULL) caml_raise_out_of_memory ();
+ if (root == NULL)
+ caml_raise_out_of_memory ();
*root = closure;
- eh = guestfs_set_event_callback (g, event_callback_wrapper,
- event_bitmask, 0, root);
+ eh = guestfs_set_event_callback (g, event_callback_wrapper, event_bitmask,
+ 0, root);
if (eh == -1) {
free (root);
@@ -286,7 +296,7 @@ guestfs_int_ocaml_event_to_string (value events)
r = guestfs_event_to_string (event_bitmask);
if (r == NULL)
- unix_error (errno, (char *) "Guestfs.event_to_string", Nothing);
+ unix_error (errno, (char *)"Guestfs.event_to_string", Nothing);
rv = caml_copy_string (r);
free (r);
@@ -312,7 +322,8 @@ get_all_event_callbacks (guestfs_h *g, size_t *len_rtn)
/* Copy them into the return array. */
r = malloc (sizeof (value *) * (*len_rtn));
- if (r == NULL) caml_raise_out_of_memory ();
+ if (r == NULL)
+ caml_raise_out_of_memory ();
i = 0;
root = guestfs_first_private (g, &key);
@@ -340,13 +351,10 @@ event_bitmask_to_event (uint64_t event)
}
static void
-event_callback_wrapper_locked (guestfs_h *g,
- void *data,
- uint64_t event,
- int event_handle,
- int flags,
- const char *buf, size_t buf_len,
- const uint64_t *array, size_t array_len)
+event_callback_wrapper_locked (guestfs_h *g, void *data, uint64_t event,
+ int event_handle, int flags, const char *buf,
+ size_t buf_len, const uint64_t *array,
+ size_t array_len)
{
CAMLparam0 ();
CAMLlocal4 (evv, ehv, bufv, arrayv);
@@ -369,7 +377,7 @@ event_callback_wrapper_locked (guestfs_h *g,
value args[4] = { evv, ehv, bufv, arrayv };
- rv = caml_callbackN_exn (*(value*)data, 4, args);
+ rv = caml_callbackN_exn (*(value *)data, 4, args);
/* Callbacks shouldn't throw exceptions. There's not much we can do
* except to print it.
@@ -383,21 +391,18 @@ event_callback_wrapper_locked (guestfs_h *g,
}
static void
-event_callback_wrapper (guestfs_h *g,
- void *data,
- uint64_t event,
- int event_handle,
- int flags,
- const char *buf, size_t buf_len,
- const uint64_t *array, size_t array_len)
+event_callback_wrapper (guestfs_h *g, void *data, uint64_t event,
+ int event_handle, int flags, const char *buf,
+ size_t buf_len, const uint64_t *array,
+ size_t array_len)
{
/* Ensure we are holding the GC lock before any GC operations are
* possible. (RHBZ#725824)
*/
caml_leave_blocking_section ();
- event_callback_wrapper_locked (g, data, event, event_handle, flags,
- buf, buf_len, array, array_len);
+ event_callback_wrapper_locked (g, data, event, event_handle, flags, buf,
+ buf_len, array, array_len);
caml_enter_blocking_section ();
}
diff --git a/ocaml/guestfs-c.h b/ocaml/guestfs-c.h
index b99aceb..f12f154 100644
--- a/ocaml/guestfs-c.h
+++ b/ocaml/guestfs-c.h
@@ -21,11 +21,10 @@
#include "guestfs-internal-frontend.h"
-#define Guestfs_val(v) (*((guestfs_h **)Data_custom_val(v)))
-extern void guestfs_int_ocaml_raise_error (guestfs_h *g, const char *func)
- Noreturn;
-extern void guestfs_int_ocaml_raise_closed (const char *func)
- Noreturn;
+#define Guestfs_val(v) (*((guestfs_h **)Data_custom_val (v)))
+extern void guestfs_int_ocaml_raise_error (guestfs_h *g,
+ const char *func) Noreturn;
+extern void guestfs_int_ocaml_raise_closed (const char *func) Noreturn;
extern char **guestfs_int_ocaml_strings_val (guestfs_h *g, value sv);
#endif /* GUESTFS_OCAML_C_H */
diff --git a/p2v/about-authors.c b/p2v/about-authors.c
index 005dc87..6956d34 100644
--- a/p2v/about-authors.c
+++ b/p2v/about-authors.c
@@ -22,12 +22,10 @@
/* The list of authors of virt-p2v and virt-v2v, for the About dialog. */
-const char *authors[] = {
- "Matthew Booth",
- "John Eckersberg",
- "Richard W.M. Jones",
- "Mike Latimer",
- "Pino Toscano",
- "Tingting Zheng",
- NULL
-};
+const char *authors[] = { "Matthew Booth",
+ "John Eckersberg",
+ "Richard W.M. Jones",
+ "Mike Latimer",
+ "Pino Toscano",
+ "Tingting Zheng",
+ NULL };
diff --git a/p2v/about-license.c b/p2v/about-license.c
index e8c9412..433c3fa 100644
--- a/p2v/about-license.c
+++ b/p2v/about-license.c
@@ -35,4 +35,5 @@ const char *gplv2plus =
"\n"
"You should have received a copy of the GNU General Public License\n"
"along with this program; if not, write to the Free Software\n"
- "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA.\n";
+ "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA "
+ "02110-1301 USA.\n";
diff --git a/p2v/config.c b/p2v/config.c
index 9c0d76f..3569a99 100644
--- a/p2v/config.c
+++ b/p2v/config.c
@@ -116,8 +116,8 @@ print_config (struct config *config, FILE *fp)
size_t i;
fprintf (fp, "local version . %s\n", PACKAGE_VERSION);
- fprintf (fp, "remote version . %d.%d.%d\n",
- v2v_major, v2v_minor, v2v_release);
+ fprintf (fp, "remote version . %d.%d.%d\n", v2v_major, v2v_minor,
+ v2v_release);
fprintf (fp, "remote debugging %s\n",
config->verbose ? "true" : "false");
fprintf (fp, "conversion server %s\n",
@@ -126,11 +126,11 @@ print_config (struct config *config, FILE *fp)
fprintf (fp, "username . . . . %s\n",
config->username ? config->username : "none");
fprintf (fp, "password . . . . %s\n",
- config->password && strlen (config->password) > 0 ?
"***" : "none");
+ config->password && strlen (config->password) > 0 ?
"***"
+ : "none");
fprintf (fp, "identity URL . . %s\n",
config->identity_url ? config->identity_url : "none");
- fprintf (fp, "sudo . . . . . . %s\n",
- config->sudo ? "true" : "false");
+ fprintf (fp, "sudo . . . . . . %s\n", config->sudo ? "true" :
"false");
fprintf (fp, "guest name . . . %s\n",
config->guestname ? config->guestname : "none");
fprintf (fp, "vcpus . . . . . %d\n", config->vcpus);
@@ -138,7 +138,7 @@ print_config (struct config *config, FILE *fp)
fprintf (fp, "flags . . . . . %s%s%s\n",
config->flags & FLAG_ACPI ? " acpi" : "",
config->flags & FLAG_APIC ? " apic" : "",
- config->flags & FLAG_PAE ? " pae" : "");
+ config->flags & FLAG_PAE ? " pae" : "");
fprintf (fp, "disks . . . . . ");
if (config->disks != NULL) {
for (i = 0; config->disks[i] != NULL; ++i)
@@ -167,10 +167,17 @@ print_config (struct config *config, FILE *fp)
config->output ? config->output : "none");
fprintf (fp, "output alloc . . ");
switch (config->output_allocation) {
- case OUTPUT_ALLOCATION_NONE: fprintf (fp, "none"); break;
- case OUTPUT_ALLOCATION_SPARSE: fprintf (fp, "sparse"); break;
- case OUTPUT_ALLOCATION_PREALLOCATED: fprintf (fp, "preallocated"); break;
- default: fprintf (fp, "unknown? (%d)", config->output_allocation);
+ case OUTPUT_ALLOCATION_NONE:
+ fprintf (fp, "none");
+ break;
+ case OUTPUT_ALLOCATION_SPARSE:
+ fprintf (fp, "sparse");
+ break;
+ case OUTPUT_ALLOCATION_PREALLOCATED:
+ fprintf (fp, "preallocated");
+ break;
+ default:
+ fprintf (fp, "unknown? (%d)", config->output_allocation);
}
fprintf (fp, "\n");
fprintf (fp, "output conn . . %s\n",
diff --git a/p2v/conversion.c b/p2v/conversion.c
index 103073e..a06b130 100644
--- a/p2v/conversion.c
+++ b/p2v/conversion.c
@@ -73,10 +73,10 @@ xmlBufferDetach (xmlBufferPtr buf)
/* Data per NBD connection / physical disk. */
struct data_conn {
- mexp_h *h; /* miniexpect handle to ssh */
- pid_t nbd_pid; /* qemu pid */
- int nbd_local_port; /* local NBD port on physical machine */
- int nbd_remote_port; /* remote NBD port on conversion server */
+ mexp_h *h; /* miniexpect handle to ssh */
+ pid_t nbd_pid; /* qemu pid */
+ int nbd_local_port; /* local NBD port on physical machine */
+ int nbd_remote_port; /* remote NBD port on conversion server */
};
static int send_quoted (mexp_h *, const char *s);
@@ -84,12 +84,13 @@ static pid_t start_qemu_nbd (int nbd_local_port, const char *device);
static int wait_qemu_nbd (int nbd_local_port, int timeout_seconds);
static void cleanup_data_conns (struct data_conn *data_conns, size_t nr);
static char *generate_libvirt_xml (struct config *, struct data_conn *);
-static const char *map_interface_to_network (struct config *, const char *interface);
+static const char *map_interface_to_network (struct config *,
+ const char *interface);
static char *conversion_error;
static void set_conversion_error (const char *fs, ...)
- __attribute__((format(printf,1,2)));
+ __attribute__((format (printf, 1, 2)));
static void
set_conversion_error (const char *fs, ...)
@@ -171,7 +172,8 @@ start_conversion (struct config *config,
time_t now;
struct tm tm;
mexp_h *control_h = NULL;
- char dmesg_cmd[] = "dmesg > /tmp/dmesg.XXXXXX", *dmesg_file =
&dmesg_cmd[8];
+ char dmesg_cmd[] = "dmesg > /tmp/dmesg.XXXXXX",
+ *dmesg_file = &dmesg_cmd[8];
CLEANUP_FREE char *dmesg = NULL;
int fd, r;
@@ -200,20 +202,21 @@ start_conversion (struct config *config,
if (notify_ui) {
CLEANUP_FREE char *msg;
- if (asprintf (&msg,
- _("Opening data connection for %s ..."),
+ if (asprintf (&msg, _("Opening data connection for %s ..."),
config->disks[i]) == -1)
error (EXIT_FAILURE, errno, "asprintf");
notify_ui (NOTIFY_STATUS, msg);
}
- data_conns[i].h = open_data_connection (config,
- &data_conns[i].nbd_local_port,
- &data_conns[i].nbd_remote_port);
+ data_conns[i].h =
+ open_data_connection (config, &data_conns[i].nbd_local_port,
+ &data_conns[i].nbd_remote_port);
if (data_conns[i].h == NULL) {
const char *err = get_ssh_error ();
- set_conversion_error ("could not open data connection over SSH to the
conversion server: %s", err);
+ set_conversion_error ("could not open data connection over SSH to "
+ "the conversion server: %s",
+ err);
goto out;
}
@@ -232,10 +235,11 @@ start_conversion (struct config *config,
}
#if DEBUG_STDERR
- fprintf (stderr,
- "%s: data connection for %s: SSH remote port %d, local port
%d\n",
- guestfs_int_program_name, device,
- data_conns[i].nbd_remote_port, data_conns[i].nbd_local_port);
+ fprintf (
+ stderr,
+ "%s: data connection for %s: SSH remote port %d, local port %d\n",
+ guestfs_int_program_name, device, data_conns[i].nbd_remote_port,
+ data_conns[i].nbd_local_port);
#endif
/* Start qemu-nbd listening on the given port number. */
@@ -259,15 +263,14 @@ start_conversion (struct config *config,
*/
time (&now);
gmtime_r (&now, &tm);
- if (asprintf (&remote_dir,
- "/tmp/virt-p2v-%04d%02d%02d-XXXXXXXX",
+ if (asprintf (&remote_dir, "/tmp/virt-p2v-%04d%02d%02d-XXXXXXXX",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday) == -1) {
perror ("asprintf");
cleanup_data_conns (data_conns, nr_disks);
exit (EXIT_FAILURE);
}
len = strlen (remote_dir);
- guestfs_int_random_string (&remote_dir[len-8], 8);
+ guestfs_int_random_string (&remote_dir[len - 8], 8);
if (notify_ui)
notify_ui (NOTIFY_LOG_DIR, remote_dir);
@@ -277,7 +280,8 @@ start_conversion (struct config *config,
goto out;
#if DEBUG_STDERR
- fprintf (stderr, "%s: libvirt XML:\n%s", guestfs_int_program_name,
libvirt_xml);
+ fprintf (stderr, "%s: libvirt XML:\n%s", guestfs_int_program_name,
+ libvirt_xml);
#endif
/* Get the output from the 'dmesg' command. We will store this
@@ -300,17 +304,20 @@ start_conversion (struct config *config,
}
ignore_value (read_whole_file (dmesg_file, &dmesg, NULL));
- skip_dmesg:
+skip_dmesg:
/* Open the control connection and start conversion */
if (notify_ui)
notify_ui (NOTIFY_STATUS, _("Setting up the control connection ..."));
- control_h = start_remote_connection (config, remote_dir, libvirt_xml, dmesg);
+ control_h =
+ start_remote_connection (config, remote_dir, libvirt_xml, dmesg);
if (control_h == NULL) {
const char *err = get_ssh_error ();
- set_conversion_error ("could not open control connection over SSH to the
conversion server: %s", err);
+ set_conversion_error ("could not open control connection over SSH to "
+ "the conversion server: %s",
+ err);
goto out;
}
@@ -328,7 +335,7 @@ start_conversion (struct config *config,
set_conversion_error ("mexp_printf: virt-v2v command: %m");
goto out;
}
- if (config->output) { /* -o */
+ if (config->output) { /* -o */
if (mexp_printf (control_h, " -o ") == -1)
goto printf_fail;
if (send_quoted (control_h, config->output) == -1)
@@ -349,7 +356,7 @@ start_conversion (struct config *config,
default:
abort ();
}
- if (config->output_format) { /* -of */
+ if (config->output_format) { /* -of */
if (mexp_printf (control_h, " -of ") == -1)
goto printf_fail;
if (send_quoted (control_h, config->output_format) == -1)
@@ -389,12 +396,12 @@ start_conversion (struct config *config,
if (r == -1) {
/* See comment about this in miniexpect.c. */
if (errno == EIO)
- break; /* EOF */
+ break; /* EOF */
set_conversion_error ("read: %m");
goto out;
}
if (r == 0)
- break; /* EOF */
+ break; /* EOF */
buf[r] = '\0';
if (notify_ui)
notify_ui (NOTIFY_REMOTE_MESSAGE, buf);
@@ -411,14 +418,13 @@ start_conversion (struct config *config,
notify_ui (NOTIFY_STATUS, _("Control connection closed by remote."));
ret = 0;
- out:
+out:
if (control_h) {
if ((status = mexp_close (control_h)) == -1) {
set_conversion_error ("mexp_close: %m");
ret = -1;
- } else if (ret == 0 &&
- WIFEXITED (status) &&
- WEXITSTATUS (status) != 0) {
+ }
+ else if (ret == 0 && WIFEXITED (status) && WEXITSTATUS (status) != 0)
{
set_conversion_error ("virt-v2v exited with status %d",
WEXITSTATUS (status));
ret = -1;
@@ -478,19 +484,17 @@ start_qemu_nbd (int port, const char *device)
return 0;
}
- if (pid == 0) { /* Child. */
+ if (pid == 0) { /* Child. */
close (0);
open ("/dev/null", O_RDONLY);
- execlp ("qemu-nbd",
- "qemu-nbd",
- "-r", /* readonly (vital!) */
- "-p", port_str, /* listening port */
- "-t", /* persistent */
- "-f", "raw", /* force raw format */
- "-b", "localhost", /* listen only on loopback interface
*/
- "--cache=unsafe", /* use unsafe caching for speed */
- device, /* a device like /dev/sda */
+ execlp ("qemu-nbd", "qemu-nbd", "-r", /* readonly
(vital!) */
+ "-p", port_str, /* listening port */
+ "-t", /* persistent */
+ "-f", "raw", /* force raw format */
+ "-b", "localhost", /* listen only on loopback interface
*/
+ "--cache=unsafe", /* use unsafe caching for speed */
+ device, /* a device like /dev/sda */
NULL);
perror ("qemu-nbd");
_exit (EXIT_FAILURE);
@@ -507,7 +511,8 @@ start_qemu_nbd (int port, const char *device)
static int bind_source_port (int sockfd, int family, int source_port);
static int
-connect_with_source_port (const char *hostname, int dest_port, int source_port)
+connect_with_source_port (const char *hostname, int dest_port,
+ int source_port)
{
struct addrinfo hints;
struct addrinfo *results, *rp;
@@ -518,15 +523,15 @@ connect_with_source_port (const char *hostname, int dest_port, int
source_port)
snprintf (dest_port_str, sizeof dest_port_str, "%d", dest_port);
memset (&hints, 0, sizeof hints);
- hints.ai_family = AF_UNSPEC; /* allow IPv4 or IPv6 */
+ hints.ai_family = AF_UNSPEC; /* allow IPv4 or IPv6 */
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_NUMERICSERV; /* numeric dest port number */
hints.ai_protocol = 0; /* any protocol */
r = getaddrinfo (hostname, dest_port_str, &hints, &results);
if (r != 0) {
- set_conversion_error ("getaddrinfo: %s/%s: %s",
- hostname, dest_port_str, gai_strerror (r));
+ set_conversion_error ("getaddrinfo: %s/%s: %s", hostname, dest_port_str,
+ gai_strerror (r));
return -1;
}
@@ -540,8 +545,8 @@ connect_with_source_port (const char *hostname, int dest_port, int
source_port)
* that is in TIME_WAIT from a prior run. Handle that gracefully
* with SO_REUSEADDR.
*/
- if (setsockopt (sockfd, SOL_SOCKET, SO_REUSEADDR,
- &reuseaddr, sizeof reuseaddr) == -1)
+ if (setsockopt (sockfd, SOL_SOCKET, SO_REUSEADDR, &reuseaddr,
+ sizeof reuseaddr) == -1)
perror ("warning: setsockopt");
/* Need to bind the source port. */
@@ -602,7 +607,7 @@ bind_source_port (int sockfd, int family, int source_port)
freeaddrinfo (results);
return -1;
- bound:
+bound:
freeaddrinfo (results);
return 0;
}
@@ -613,8 +618,8 @@ wait_qemu_nbd (int nbd_local_port, int timeout_seconds)
int sockfd = -1;
int result = -1;
time_t start_t, now_t;
- struct timespec half_sec = { .tv_sec = 0, .tv_nsec = 500000000 };
- struct timeval timeout = { .tv_usec = 0 };
+ struct timespec half_sec = {.tv_sec = 0, .tv_nsec = 500000000 };
+ struct timeval timeout = {.tv_usec = 0 };
char magic[8]; /* NBDMAGIC */
size_t bytes_read = 0;
ssize_t recvd;
@@ -636,7 +641,7 @@ wait_qemu_nbd (int nbd_local_port, int timeout_seconds)
*
https://bugzilla.redhat.com/show_bug.cgi?id=1167774#c9
*/
sockfd = connect_with_source_port ("localhost", nbd_local_port,
- nbd_local_port+1);
+ nbd_local_port + 1);
if (sockfd >= 0)
break;
@@ -665,7 +670,7 @@ wait_qemu_nbd (int nbd_local_port, int timeout_seconds)
}
result = 0;
- cleanup:
+cleanup:
close (sockfd);
return result;
@@ -696,61 +701,66 @@ cleanup_data_conns (struct data_conn *data_conns, size_t nr)
/* Macros "inspired" by src/launch-libvirt.c */
/* <element */
-#define start_element(element) \
- if (xmlTextWriterStartElement (xo, BAD_CAST (element)) == -1) { \
- set_conversion_error ("xmlTextWriterStartElement: %m"); \
- return NULL; \
- } \
+#define start_element(element) \
+ if (xmlTextWriterStartElement (xo, BAD_CAST (element)) == -1) { \
+ set_conversion_error ("xmlTextWriterStartElement: %m"); \
+ return NULL; \
+ } \
do
/* finish current </element> */
-#define end_element() \
- while (0); \
- do { \
- if (xmlTextWriterEndElement (xo) == -1) { \
- set_conversion_error ("xmlTextWriterEndElement: %m"); \
- return NULL; \
- } \
+#define end_element() \
+ while (0) \
+ ; \
+ do { \
+ if (xmlTextWriterEndElement (xo) == -1) { \
+ set_conversion_error ("xmlTextWriterEndElement: %m"); \
+ return NULL; \
+ } \
} while (0)
/* <element/> */
-#define empty_element(element) \
- do { start_element(element) {} end_element (); } while (0)
+#define empty_element(element) \
+ do { \
+ start_element (element) {} \
+ end_element (); \
+ } while (0)
/* key=value attribute of the current element. */
-#define attribute(key,value) \
- if (xmlTextWriterWriteAttribute (xo, BAD_CAST (key), BAD_CAST (value)) == -1) { \
- set_conversion_error ("xmlTextWriterWriteAttribute: %m"); \
- return NULL; \
+#define attribute(key, value) \
+ if (xmlTextWriterWriteAttribute (xo, BAD_CAST (key), \
+ BAD_CAST (value)) == -1) { \
+ set_conversion_error ("xmlTextWriterWriteAttribute: %m"); \
+ return NULL; \
}
/* key=value, but value is a printf-style format string. */
-#define attribute_format(key,fs,...) \
- if (xmlTextWriterWriteFormatAttribute (xo, BAD_CAST (key), \
- fs, ##__VA_ARGS__) == -1) { \
- set_conversion_error ("xmlTextWriterWriteFormatAttribute: %m"); \
- return NULL; \
+#define attribute_format(key, fs, ...) \
+ if (xmlTextWriterWriteFormatAttribute (xo, BAD_CAST (key), fs, \
+ ##__VA_ARGS__) == -1) { \
+ set_conversion_error ("xmlTextWriterWriteFormatAttribute: %m"); \
+ return NULL; \
}
/* A string, eg. within an element. */
-#define string(str) \
- if (xmlTextWriterWriteString (xo, BAD_CAST (str)) == -1) { \
- set_conversion_error ("xmlTextWriterWriteString: %m"); \
- return NULL; \
+#define string(str) \
+ if (xmlTextWriterWriteString (xo, BAD_CAST (str)) == -1) { \
+ set_conversion_error ("xmlTextWriterWriteString: %m"); \
+ return NULL; \
}
/* A string, using printf-style formatting. */
-#define string_format(fs,...) \
- if (xmlTextWriterWriteFormatString (xo, fs, ##__VA_ARGS__) == -1) { \
- set_conversion_error ("xmlTextWriterWriteFormatString: %m"); \
- return NULL; \
+#define string_format(fs, ...) \
+ if (xmlTextWriterWriteFormatString (xo, fs, ##__VA_ARGS__) == -1) { \
+ set_conversion_error ("xmlTextWriterWriteFormatString: %m"); \
+ return NULL; \
}
/* An XML comment. */
-#define comment(str) \
- if (xmlTextWriterWriteComment (xo, BAD_CAST (str)) == -1) { \
- set_conversion_error ("xmlTextWriterWriteComment: %m"); \
- return NULL; \
+#define comment(str) \
+ if (xmlTextWriterWriteComment (xo, BAD_CAST (str)) == -1) { \
+ set_conversion_error ("xmlTextWriterWriteComment: %m"); \
+ return NULL; \
}
/* Write the libvirt XML for this physical machine. Note this is not
@@ -796,53 +806,66 @@ generate_libvirt_xml (struct config *config, struct data_conn
*data_conns)
memkb = config->memory / 1024;
- comment
- (" NOTE!\n"
- "\n"
- " This libvirt XML is generated by the virt-p2v front end, in\n"
- " order to communicate with the backend virt-v2v process running\n"
- " on the conversion server. It is a minimal description of the\n"
- " physical machine. If the target of the conversion is libvirt,\n"
- " then virt-v2v will generate the real target libvirt XML, which\n"
- " has only a little to do with the XML in this file.\n"
- "\n"
- " TL;DR: Don't try to load this XML into libvirt. ");
+ comment (
+ " NOTE!\n"
+ "\n"
+ " This libvirt XML is generated by the virt-p2v front end, in\n"
+ " order to communicate with the backend virt-v2v process running\n"
+ " on the conversion server. It is a minimal description of the\n"
+ " physical machine. If the target of the conversion is libvirt,\n"
+ " then virt-v2v will generate the real target libvirt XML, which\n"
+ " has only a little to do with the XML in this file.\n"
+ "\n"
+ " TL;DR: Don't try to load this XML into libvirt. ");
- start_element ("domain") {
+ start_element ("domain")
+ {
attribute ("type", "physical");
- start_element ("name") {
- string (config->guestname);
- } end_element ();
+ start_element ("name") { string (config->guestname); }
+ end_element ();
- start_element ("memory") {
+ start_element ("memory")
+ {
attribute ("unit", "KiB");
string_format ("%" PRIu64, memkb);
- } end_element ();
+ }
+ end_element ();
- start_element ("currentMemory") {
+ start_element ("currentMemory")
+ {
attribute ("unit", "KiB");
string_format ("%" PRIu64, memkb);
- } end_element ();
+ }
+ end_element ();
- start_element ("vcpu") {
- string_format ("%d", config->vcpus);
- } end_element ();
+ start_element ("vcpu") { string_format ("%d", config->vcpus);
}
+ end_element ();
- start_element ("os") {
- start_element ("type") {
+ start_element ("os")
+ {
+ start_element ("type")
+ {
attribute ("arch", host_cpu);
string ("hvm");
- } end_element ();
- } end_element ();
+ }
+ end_element ();
+ }
+ end_element ();
- start_element ("features") {
- if (config->flags & FLAG_ACPI) empty_element ("acpi");
- if (config->flags & FLAG_APIC) empty_element ("apic");
- if (config->flags & FLAG_PAE) empty_element ("pae");
- } end_element ();
+ start_element ("features")
+ {
+ if (config->flags & FLAG_ACPI)
+ empty_element ("acpi");
+ if (config->flags & FLAG_APIC)
+ empty_element ("apic");
+ if (config->flags & FLAG_PAE)
+ empty_element ("pae");
+ }
+ end_element ();
- start_element ("devices") {
+ start_element ("devices")
+ {
for (i = 0; config->disks[i] != NULL; ++i) {
char target_dev[64];
@@ -851,47 +874,65 @@ generate_libvirt_xml (struct config *config, struct data_conn
*data_conns)
target_sd:
memcpy (target_dev, "sd", 2);
guestfs_int_drive_name (i, &target_dev[2]);
- } else {
+ }
+ else {
if (strlen (config->disks[i]) <= sizeof (target_dev) - 1)
strcpy (target_dev, config->disks[i]);
else
goto target_sd;
}
- start_element ("disk") {
+ start_element ("disk")
+ {
attribute ("type", "network");
attribute ("device", "disk");
- start_element ("driver") {
+ start_element ("driver")
+ {
attribute ("name", "qemu");
attribute ("type", "raw");
- } end_element ();
- start_element ("source") {
+ }
+ end_element ();
+ start_element ("source")
+ {
attribute ("protocol", "nbd");
- start_element ("host") {
+ start_element ("host")
+ {
attribute ("name", "localhost");
- attribute_format ("port", "%d",
data_conns[i].nbd_remote_port);
- } end_element ();
- } end_element ();
- start_element ("target") {
+ attribute_format ("port", "%d",
+ data_conns[i].nbd_remote_port);
+ }
+ end_element ();
+ }
+ end_element ();
+ start_element ("target")
+ {
attribute ("dev", target_dev);
/* XXX Need to set bus to "ide" or "scsi" here. */
- } end_element ();
- } end_element ();
+ }
+ end_element ();
+ }
+ end_element ();
}
if (config->removable) {
for (i = 0; config->removable[i] != NULL; ++i) {
- start_element ("disk") {
+ start_element ("disk")
+ {
attribute ("type", "network");
attribute ("device", "cdrom");
- start_element ("driver") {
+ start_element ("driver")
+ {
attribute ("name", "qemu");
attribute ("type", "raw");
- } end_element ();
- start_element ("target") {
+ }
+ end_element ();
+ start_element ("target")
+ {
attribute ("dev", config->removable[i]);
- } end_element ();
- } end_element ();
+ }
+ end_element ();
+ }
+ end_element ();
}
}
@@ -910,36 +951,41 @@ generate_libvirt_xml (struct config *config, struct data_conn
*data_conns)
if (g_file_get_contents (mac_filename, &mac, NULL, NULL)) {
size_t len = strlen (mac);
- if (len > 0 && mac[len-1] == '\n')
- mac[len-1] = '\0';
+ if (len > 0 && mac[len - 1] == '\n')
+ mac[len - 1] = '\0';
}
- start_element ("interface") {
+ start_element ("interface")
+ {
attribute ("type", "network");
- start_element ("source") {
+ start_element ("source")
+ {
attribute ("network", target_network);
- } end_element ();
- start_element ("target") {
+ }
+ end_element ();
+ start_element ("target")
+ {
attribute ("dev", config->interfaces[i]);
- } end_element ();
+ }
+ end_element ();
if (mac) {
- start_element ("mac") {
- attribute ("address", mac);
- } end_element ();
+ start_element ("mac") { attribute ("address", mac); }
+ end_element ();
}
- } end_element ();
+ }
+ end_element ();
}
}
-
- } end_element (); /* </devices> */
-
- } end_element (); /* </domain> */
+ }
+ end_element (); /* </devices> */
+ }
+ end_element (); /* </domain> */
if (xmlTextWriterEndDocument (xo) == -1) {
set_conversion_error ("xmlTextWriterEndDocument: %m");
return NULL;
}
- ret = (char *) xmlBufferDetach (xb); /* caller frees */
+ ret = (char *)xmlBufferDetach (xb); /* caller frees */
if (ret == NULL) {
set_conversion_error ("xmlBufferDetach: %m");
return NULL;
@@ -972,7 +1018,7 @@ map_interface_to_network (struct config *config, const char
*interface)
len = strlen (interface);
if (STRPREFIX (config->network_map[i], interface) &&
config->network_map[i][len] == ':')
- return &config->network_map[i][len+1];
+ return &config->network_map[i][len + 1];
}
/* No mapping found. */
diff --git a/p2v/gui.c b/p2v/gui.c
index 625c6eb..ae4917f 100644
--- a/p2v/gui.c
+++ b/p2v/gui.c
@@ -33,7 +33,8 @@
#include <pthread.h>
-#pragma GCC diagnostic ignored "-Wstrict-prototypes" /* error in <gtk.h>
*/
+#pragma GCC diagnostic ignored "-Wstrict-prototypes" /* error in <gtk.h>
\
+ */
#include <gtk/gtk.h>
#include "ignore-value.h"
@@ -52,25 +53,19 @@ static void show_running_dialog (void);
static void set_info_label (void);
/* The connection dialog. */
-static GtkWidget *conn_dlg,
- *server_entry, *port_entry,
- *username_entry, *password_entry, *identity_entry, *sudo_button,
- *spinner_hbox, *spinner, *spinner_message, *next_button;
+static GtkWidget *conn_dlg, *server_entry, *port_entry, *username_entry,
+ *password_entry, *identity_entry, *sudo_button, *spinner_hbox, *spinner,
+ *spinner_message, *next_button;
/* The conversion dialog. */
-static GtkWidget *conv_dlg,
- *guestname_entry, *vcpus_entry, *memory_entry,
- *vcpus_warning, *memory_warning, *target_warning_label,
- *o_combo, *oc_entry, *os_entry, *of_entry, *oa_combo,
- *info_label,
- *debug_button,
- *disks_list, *removable_list, *interfaces_list,
- *start_button;
+static GtkWidget *conv_dlg, *guestname_entry, *vcpus_entry, *memory_entry,
+ *vcpus_warning, *memory_warning, *target_warning_label, *o_combo,
+ *oc_entry, *os_entry, *of_entry, *oa_combo, *info_label, *debug_button,
+ *disks_list, *removable_list, *interfaces_list, *start_button;
/* The running dialog which is displayed when virt-v2v is running. */
-static GtkWidget *run_dlg,
- *v2v_output_sw, *v2v_output, *log_label, *status_label,
- *cancel_button, *reboot_button;
+static GtkWidget *run_dlg, *v2v_output_sw, *v2v_output, *log_label,
+ *status_label, *cancel_button, *reboot_button;
/* The entry point from the main program.
* Note that gtk_init etc have already been called in main.
@@ -120,48 +115,49 @@ create_connection_dialog (struct config *config)
gtk_window_set_resizable (GTK_WINDOW (conn_dlg), FALSE);
/* The main dialog area. */
- intro = gtk_label_new (_("Connect to a virt-v2v conversion server over
SSH:"));
+ intro =
+ gtk_label_new (_("Connect to a virt-v2v conversion server over SSH:"));
gtk_label_set_line_wrap (GTK_LABEL (intro), TRUE);
gtk_misc_set_padding (GTK_MISC (intro), 10, 10);
table = gtk_table_new (7, 2, FALSE);
server_label = gtk_label_new (_("Conversion server:"));
gtk_misc_set_alignment (GTK_MISC (server_label), 1., 0.5);
- gtk_table_attach (GTK_TABLE (table), server_label,
- 0, 1, 0, 1, GTK_FILL, GTK_FILL, 4, 4);
+ gtk_table_attach (GTK_TABLE (table), server_label, 0, 1, 0, 1, GTK_FILL,
+ GTK_FILL, 4, 4);
server_entry = gtk_entry_new ();
if (config->server != NULL)
gtk_entry_set_text (GTK_ENTRY (server_entry), config->server);
- gtk_table_attach (GTK_TABLE (table), server_entry,
- 1, 2, 0, 1, GTK_FILL, GTK_FILL, 4, 4);
+ gtk_table_attach (GTK_TABLE (table), server_entry, 1, 2, 0, 1, GTK_FILL,
+ GTK_FILL, 4, 4);
port_label = gtk_label_new (_("SSH port:"));
gtk_misc_set_alignment (GTK_MISC (port_label), 1., 0.5);
- gtk_table_attach (GTK_TABLE (table), port_label,
- 0, 1, 1, 2, GTK_FILL, GTK_FILL, 4, 4);
+ gtk_table_attach (GTK_TABLE (table), port_label, 0, 1, 1, 2, GTK_FILL,
+ GTK_FILL, 4, 4);
port_entry = gtk_entry_new ();
gtk_entry_set_width_chars (GTK_ENTRY (port_entry), 6);
snprintf (port_str, sizeof port_str, "%d", config->port);
gtk_entry_set_text (GTK_ENTRY (port_entry), port_str);
- gtk_table_attach (GTK_TABLE (table), port_entry,
- 1, 2, 1, 2, GTK_FILL, GTK_FILL, 4, 4);
+ gtk_table_attach (GTK_TABLE (table), port_entry, 1, 2, 1, 2, GTK_FILL,
+ GTK_FILL, 4, 4);
username_label = gtk_label_new (_("User name:"));
gtk_misc_set_alignment (GTK_MISC (username_label), 1., 0.5);
- gtk_table_attach (GTK_TABLE (table), username_label,
- 0, 1, 2, 3, GTK_FILL, GTK_FILL, 4, 4);
+ gtk_table_attach (GTK_TABLE (table), username_label, 0, 1, 2, 3, GTK_FILL,
+ GTK_FILL, 4, 4);
username_entry = gtk_entry_new ();
if (config->username != NULL)
gtk_entry_set_text (GTK_ENTRY (username_entry), config->username);
else
gtk_entry_set_text (GTK_ENTRY (username_entry), "root");
- gtk_table_attach (GTK_TABLE (table), username_entry,
- 1, 2, 2, 3, GTK_FILL, GTK_FILL, 4, 4);
+ gtk_table_attach (GTK_TABLE (table), username_entry, 1, 2, 2, 3, GTK_FILL,
+ GTK_FILL, 4, 4);
password_label = gtk_label_new (_("Password:"));
gtk_misc_set_alignment (GTK_MISC (password_label), 1., 0.5);
- gtk_table_attach (GTK_TABLE (table), password_label,
- 0, 1, 3, 4, GTK_FILL, GTK_FILL, 4, 4);
+ gtk_table_attach (GTK_TABLE (table), password_label, 0, 1, 3, 4, GTK_FILL,
+ GTK_FILL, 4, 4);
password_entry = gtk_entry_new ();
gtk_entry_set_visibility (GTK_ENTRY (password_entry), FALSE);
#ifdef GTK_INPUT_PURPOSE_PASSWORD
@@ -170,32 +166,33 @@ create_connection_dialog (struct config *config)
#endif
if (config->password != NULL)
gtk_entry_set_text (GTK_ENTRY (password_entry), config->password);
- gtk_table_attach (GTK_TABLE (table), password_entry,
- 1, 2, 3, 4, GTK_FILL, GTK_FILL, 4, 4);
+ gtk_table_attach (GTK_TABLE (table), password_entry, 1, 2, 3, 4, GTK_FILL,
+ GTK_FILL, 4, 4);
identity_label = gtk_label_new (_("SSH Identity URL:"));
gtk_misc_set_alignment (GTK_MISC (identity_label), 1., 0.5);
- gtk_table_attach (GTK_TABLE (table), identity_label,
- 0, 1, 4, 5, GTK_FILL, GTK_FILL, 4, 4);
+ gtk_table_attach (GTK_TABLE (table), identity_label, 0, 1, 4, 5, GTK_FILL,
+ GTK_FILL, 4, 4);
identity_entry = gtk_entry_new ();
if (config->identity_url != NULL)
gtk_entry_set_text (GTK_ENTRY (identity_entry), config->identity_url);
- gtk_table_attach (GTK_TABLE (table), identity_entry,
- 1, 2, 4, 5, GTK_FILL, GTK_FILL, 4, 4);
+ gtk_table_attach (GTK_TABLE (table), identity_entry, 1, 2, 4, 5, GTK_FILL,
+ GTK_FILL, 4, 4);
identity_tip_label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (identity_tip_label),
- _("<i>If using password authentication, leave the SSH
Identity URL blank</i>"));
+ _("<i>If using password authentication, leave the
"
+ "SSH Identity URL blank</i>"));
gtk_label_set_line_wrap (GTK_LABEL (identity_tip_label), TRUE);
- gtk_table_attach (GTK_TABLE (table), identity_tip_label,
- 1, 2, 5, 6, GTK_FILL, GTK_FILL, 4, 4);
+ gtk_table_attach (GTK_TABLE (table), identity_tip_label, 1, 2, 5, 6,
+ GTK_FILL, GTK_FILL, 4, 4);
sudo_button =
gtk_check_button_new_with_label (_("Use sudo when running virt-v2v"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (sudo_button),
config->sudo);
- gtk_table_attach (GTK_TABLE (table), sudo_button,
- 1, 2, 6, 7, GTK_FILL, GTK_FILL, 4, 4);
+ gtk_table_attach (GTK_TABLE (table), sudo_button, 1, 2, 6, 7, GTK_FILL,
+ GTK_FILL, 4, 4);
test_hbox = gtk_hbox_new (FALSE, 0);
test = gtk_button_new_with_label (_("Test connection"));
@@ -207,25 +204,25 @@ create_connection_dialog (struct config *config)
spinner_message = gtk_label_new (NULL);
gtk_label_set_line_wrap (GTK_LABEL (spinner_message), TRUE);
gtk_misc_set_padding (GTK_MISC (spinner_message), 10, 10);
- gtk_box_pack_start (GTK_BOX (spinner_hbox), spinner_message, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (spinner_hbox), spinner_message, TRUE, TRUE,
+ 0);
- gtk_box_pack_start (GTK_BOX (GTK_DIALOG (conn_dlg)->vbox),
- intro, TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (GTK_DIALOG (conn_dlg)->vbox),
- table, TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (GTK_DIALOG (conn_dlg)->vbox),
- test_hbox, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (GTK_DIALOG (conn_dlg)->vbox),
- spinner_hbox, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (conn_dlg)->vbox), intro, TRUE,
+ TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (conn_dlg)->vbox), table, TRUE,
+ TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (conn_dlg)->vbox), test_hbox,
+ FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (conn_dlg)->vbox), spinner_hbox,
+ TRUE, TRUE, 0);
/* Buttons. */
- gtk_dialog_add_buttons (GTK_DIALOG (conn_dlg),
- _("Configure network ..."), 1,
- _("About virt-p2v " PACKAGE_VERSION "
..."), 2,
- _("Next"), 3,
- NULL);
+ gtk_dialog_add_buttons (
+ GTK_DIALOG (conn_dlg), _("Configure network ..."), 1,
+ _("About virt-p2v " PACKAGE_VERSION " ..."), 2,
_("Next"), 3, NULL);
- next_button = gtk_dialog_get_widget_for_response (GTK_DIALOG (conn_dlg), 3);
+ next_button =
+ gtk_dialog_get_widget_for_response (GTK_DIALOG (conn_dlg), 3);
gtk_widget_set_sensitive (next_button, FALSE);
configure_network =
@@ -282,23 +279,27 @@ test_connection_clicked (GtkWidget *w, gpointer data)
errors++;
}
port_str = gtk_entry_get_text (GTK_ENTRY (port_entry));
- if (sscanf (port_str, "%d", &config->port) != 1 ||
- config->port <= 0 || config->port >= 65536) {
- gtk_label_set_text (GTK_LABEL (spinner_message),
- _("error: Invalid port number. If in doubt, use
\"22\"."));
+ if (sscanf (port_str, "%d", &config->port) != 1 || config->port
<= 0 ||
+ config->port >= 65536) {
+ gtk_label_set_text (
+ GTK_LABEL (spinner_message),
+ _("error: Invalid port number. If in doubt, use \"22\"."));
gtk_widget_grab_focus (port_entry);
errors++;
}
free (config->username);
- config->username = strdup (gtk_entry_get_text (GTK_ENTRY (username_entry)));
+ config->username =
+ strdup (gtk_entry_get_text (GTK_ENTRY (username_entry)));
if (STREQ (config->username, "")) {
- gtk_label_set_text (GTK_LABEL (spinner_message),
- _("error: No user name. If in doubt, use
\"root\"."));
+ gtk_label_set_text (
+ GTK_LABEL (spinner_message),
+ _("error: No user name. If in doubt, use \"root\"."));
gtk_widget_grab_focus (username_entry);
errors++;
}
free (config->password);
- config->password = strdup (gtk_entry_get_text (GTK_ENTRY (password_entry)));
+ config->password =
+ strdup (gtk_entry_get_text (GTK_ENTRY (password_entry)));
free (config->identity_url);
identity_str = gtk_entry_get_text (GTK_ENTRY (identity_entry));
@@ -308,7 +309,8 @@ test_connection_clicked (GtkWidget *w, gpointer data)
config->identity_url = NULL;
config->identity_file_needs_update = 1;
- config->sudo = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (sudo_button));
+ config->sudo =
+ gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (sudo_button));
if (errors)
return;
@@ -339,8 +341,9 @@ test_connection_thread (void *data)
int r;
gdk_threads_enter ();
- gtk_label_set_text (GTK_LABEL (spinner_message),
- _("Testing the connection to the conversion server
..."));
+ gtk_label_set_text (
+ GTK_LABEL (spinner_message),
+ _("Testing the connection to the conversion server ..."));
gtk_spinner_start (GTK_SPINNER (spinner));
gdk_threads_leave ();
@@ -361,9 +364,10 @@ test_connection_thread (void *data)
}
else {
/* Connection is good. */
- gtk_label_set_text (GTK_LABEL (spinner_message),
- _("Connected to the conversion server.\n"
- "Press the \"Next\" button to configure the
conversion process."));
+ gtk_label_set_text (
+ GTK_LABEL (spinner_message),
+ _("Connected to the conversion server.\n"
+ "Press the \"Next\" button to configure the conversion
process."));
/* Enable the Next button. */
gtk_widget_set_sensitive (next_button, TRUE);
gtk_widget_grab_focus (next_button);
@@ -386,15 +390,12 @@ configure_network_button_clicked (GtkWidget *w, gpointer data)
static void
about_button_clicked (GtkWidget *w, gpointer data)
{
- gtk_show_about_dialog (GTK_WINDOW (conn_dlg),
- "program-name", guestfs_int_program_name,
- "version", PACKAGE_VERSION " (" host_cpu
")",
- "copyright", "\u00A9 2009-2016 Red Hat
Inc.",
- "comments", "Convert a physical machine to use
KVM",
- "license", gplv2plus,
- "website", "http://libguestfs.org/",
- "authors", authors,
- NULL);
+ gtk_show_about_dialog (
+ GTK_WINDOW (conn_dlg), "program-name", guestfs_int_program_name,
+ "version", PACKAGE_VERSION " (" host_cpu ")",
"copyright",
+ "\u00A9 2009-2016 Red Hat Inc.", "comments",
+ "Convert a physical machine to use KVM", "license", gplv2plus,
+ "website", "http://libguestfs.org/", "authors",
authors, NULL);
}
/* The connection dialog Next button has been clicked. */
@@ -411,9 +412,13 @@ connection_next_clicked (GtkWidget *w, gpointer data)
static void populate_disks (GtkTreeView *disks_list);
static void populate_removable (GtkTreeView *removable_list);
static void populate_interfaces (GtkTreeView *interfaces_list);
-static void toggled (GtkCellRendererToggle *cell, gchar *path_str, gpointer data);
-static void network_edited_callback (GtkCellRendererToggle *cell, gchar *path_str, gchar
*new_text, gpointer data);
-static gboolean maybe_identify_click (GtkWidget *interfaces_list, GdkEventButton *event,
gpointer data);
+static void toggled (GtkCellRendererToggle *cell, gchar *path_str,
+ gpointer data);
+static void network_edited_callback (GtkCellRendererToggle *cell,
+ gchar *path_str, gchar *new_text,
+ gpointer data);
+static gboolean maybe_identify_click (GtkWidget *interfaces_list,
+ GdkEventButton *event, gpointer data);
static void set_disks_from_ui (struct config *);
static void set_removable_from_ui (struct config *);
static void set_interfaces_from_ui (struct config *);
@@ -483,42 +488,42 @@ create_conversion_dialog (struct config *config)
target_tbl = gtk_table_new (3, 3, FALSE);
guestname_label = gtk_label_new (_("Name:"));
gtk_misc_set_alignment (GTK_MISC (guestname_label), 1., 0.5);
- gtk_table_attach (GTK_TABLE (target_tbl), guestname_label,
- 0, 1, 0, 1, GTK_FILL, GTK_FILL, 1, 1);
+ gtk_table_attach (GTK_TABLE (target_tbl), guestname_label, 0, 1, 0, 1,
+ GTK_FILL, GTK_FILL, 1, 1);
guestname_entry = gtk_entry_new ();
if (config->guestname != NULL)
gtk_entry_set_text (GTK_ENTRY (guestname_entry), config->guestname);
- gtk_table_attach (GTK_TABLE (target_tbl), guestname_entry,
- 1, 2, 0, 1, GTK_FILL, GTK_FILL, 1, 1);
+ gtk_table_attach (GTK_TABLE (target_tbl), guestname_entry, 1, 2, 0, 1,
+ GTK_FILL, GTK_FILL, 1, 1);
vcpus_label = gtk_label_new (_("# vCPUs:"));
gtk_misc_set_alignment (GTK_MISC (vcpus_label), 1., 0.5);
- gtk_table_attach (GTK_TABLE (target_tbl), vcpus_label,
- 0, 1, 1, 2, GTK_FILL, GTK_FILL, 1, 1);
+ gtk_table_attach (GTK_TABLE (target_tbl), vcpus_label, 0, 1, 1, 2,
+ GTK_FILL, GTK_FILL, 1, 1);
vcpus_entry = gtk_entry_new ();
snprintf (vcpus_str, sizeof vcpus_str, "%d", config->vcpus);
gtk_entry_set_text (GTK_ENTRY (vcpus_entry), vcpus_str);
- gtk_table_attach (GTK_TABLE (target_tbl), vcpus_entry,
- 1, 2, 1, 2, GTK_FILL, GTK_FILL, 1, 1);
+ gtk_table_attach (GTK_TABLE (target_tbl), vcpus_entry, 1, 2, 1, 2,
+ GTK_FILL, GTK_FILL, 1, 1);
vcpus_warning = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING,
GTK_ICON_SIZE_BUTTON);
- gtk_table_attach (GTK_TABLE (target_tbl), vcpus_warning,
- 2, 3, 1, 2, 0, 0, 1, 1);
+ gtk_table_attach (GTK_TABLE (target_tbl), vcpus_warning, 2, 3, 1, 2, 0, 0,
+ 1, 1);
memory_label = gtk_label_new (_("Memory (MB):"));
gtk_misc_set_alignment (GTK_MISC (memory_label), 1., 0.5);
- gtk_table_attach (GTK_TABLE (target_tbl), memory_label,
- 0, 1, 2, 3, GTK_FILL, GTK_FILL, 1, 1);
+ gtk_table_attach (GTK_TABLE (target_tbl), memory_label, 0, 1, 2, 3,
+ GTK_FILL, GTK_FILL, 1, 1);
memory_entry = gtk_entry_new ();
snprintf (memory_str, sizeof memory_str, "%" PRIu64,
config->memory / 1024 / 1024);
gtk_entry_set_text (GTK_ENTRY (memory_entry), memory_str);
- gtk_table_attach (GTK_TABLE (target_tbl), memory_entry,
- 1, 2, 2, 3, GTK_FILL, GTK_FILL, 1, 1);
+ gtk_table_attach (GTK_TABLE (target_tbl), memory_entry, 1, 2, 2, 3,
+ GTK_FILL, GTK_FILL, 1, 1);
memory_warning = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING,
GTK_ICON_SIZE_BUTTON);
- gtk_table_attach (GTK_TABLE (target_tbl), memory_warning,
- 2, 3, 2, 3, 0, 0, 1, 1);
+ gtk_table_attach (GTK_TABLE (target_tbl), memory_warning, 2, 3, 2, 3, 0,
+ 0, 1, 1);
gtk_box_pack_start (GTK_BOX (target_vbox), target_tbl, TRUE, TRUE, 0);
@@ -527,7 +532,8 @@ create_conversion_dialog (struct config *config)
gtk_label_set_line_wrap_mode (GTK_LABEL (target_warning_label),
PANGO_WRAP_WORD);
gtk_widget_set_size_request (target_warning_label, -1, 7 * 16);
- gtk_box_pack_end (GTK_BOX (target_vbox), target_warning_label, TRUE, TRUE, 0);
+ gtk_box_pack_end (GTK_BOX (target_vbox), target_warning_label, TRUE, TRUE,
+ 0);
gtk_container_add (GTK_CONTAINER (target_frame), target_vbox);
@@ -539,54 +545,70 @@ create_conversion_dialog (struct config *config)
output_tbl = gtk_table_new (5, 2, FALSE);
o_label = gtk_label_new (_("Output to (-o):"));
gtk_misc_set_alignment (GTK_MISC (o_label), 1., 0.5);
- gtk_table_attach (GTK_TABLE (output_tbl), o_label,
- 0, 1, 0, 1, GTK_FILL, GTK_FILL, 1, 1);
+ gtk_table_attach (GTK_TABLE (output_tbl), o_label, 0, 1, 0, 1, GTK_FILL,
+ GTK_FILL, 1, 1);
o_combo = gtk_combo_box_text_new ();
- gtk_widget_set_tooltip_markup (o_combo, _("<b>libvirt</b> means send
the converted guest to libvirt-managed KVM on the conversion server.
<b>local</b> means put it in a directory on the conversion server.
<b>rhev</b> means write it to RHEV-M/oVirt. <b>glance</b> means
write it to OpenStack Glance. See the virt-v2v(1) manual page for more information about
output options."));
+ gtk_widget_set_tooltip_markup (
+ o_combo,
+ _("<b>libvirt</b> means send the converted guest to libvirt-managed
"
+ "KVM on the conversion server. <b>local</b> means put it in a
"
+ "directory on the conversion server. <b>rhev</b> means write it
to "
+ "RHEV-M/oVirt. <b>glance</b> means write it to OpenStack Glance.
"
+ "See the virt-v2v(1) manual page for more information about output "
+ "options."));
repopulate_output_combo (config);
- gtk_table_attach (GTK_TABLE (output_tbl), o_combo,
- 1, 2, 0, 1, GTK_FILL, GTK_FILL, 1, 1);
+ gtk_table_attach (GTK_TABLE (output_tbl), o_combo, 1, 2, 0, 1, GTK_FILL,
+ GTK_FILL, 1, 1);
oc_label = gtk_label_new (_("Output conn. (-oc):"));
gtk_misc_set_alignment (GTK_MISC (oc_label), 1., 0.5);
- gtk_table_attach (GTK_TABLE (output_tbl), oc_label,
- 0, 1, 1, 2, GTK_FILL, GTK_FILL, 1, 1);
+ gtk_table_attach (GTK_TABLE (output_tbl), oc_label, 0, 1, 1, 2, GTK_FILL,
+ GTK_FILL, 1, 1);
oc_entry = gtk_entry_new ();
- gtk_widget_set_tooltip_markup (oc_entry, _("For <b>libvirt</b> only,
the libvirt connection URI, or leave blank to add the guest to the default libvirt
instance on the conversion server. For others, leave this field blank."));
+ gtk_widget_set_tooltip_markup (
+ oc_entry,
+ _("For <b>libvirt</b> only, the libvirt connection URI, or leave
"
+ "blank to add the guest to the default libvirt instance on the "
+ "conversion server. For others, leave this field blank."));
if (config->output_connection != NULL)
gtk_entry_set_text (GTK_ENTRY (oc_entry), config->output_connection);
- gtk_table_attach (GTK_TABLE (output_tbl), oc_entry,
- 1, 2, 1, 2, GTK_FILL, GTK_FILL, 1, 1);
+ gtk_table_attach (GTK_TABLE (output_tbl), oc_entry, 1, 2, 1, 2, GTK_FILL,
+ GTK_FILL, 1, 1);
os_label = gtk_label_new (_("Output storage (-os):"));
gtk_misc_set_alignment (GTK_MISC (os_label), 1., 0.5);
- gtk_table_attach (GTK_TABLE (output_tbl), os_label,
- 0, 1, 2, 3, GTK_FILL, GTK_FILL, 1, 1);
+ gtk_table_attach (GTK_TABLE (output_tbl), os_label, 0, 1, 2, 3, GTK_FILL,
+ GTK_FILL, 1, 1);
os_entry = gtk_entry_new ();
- gtk_widget_set_tooltip_markup (os_entry, _("For <b>local</b>, put the
directory name on the conversion server. For <b>rhev</b>, put the Export
Storage Domain (server:/mountpoint). For others, leave this field blank."));
+ gtk_widget_set_tooltip_markup (
+ os_entry,
+ _("For <b>local</b>, put the directory name on the conversion
server. "
+ " For <b>rhev</b>, put the Export Storage Domain "
+ "(server:/mountpoint). For others, leave this field blank."));
if (config->output_storage != NULL)
gtk_entry_set_text (GTK_ENTRY (os_entry), config->output_storage);
- gtk_table_attach (GTK_TABLE (output_tbl), os_entry,
- 1, 2, 2, 3, GTK_FILL, GTK_FILL, 1, 1);
+ gtk_table_attach (GTK_TABLE (output_tbl), os_entry, 1, 2, 2, 3, GTK_FILL,
+ GTK_FILL, 1, 1);
of_label = gtk_label_new (_("Output format (-of):"));
gtk_misc_set_alignment (GTK_MISC (of_label), 1., 0.5);
- gtk_table_attach (GTK_TABLE (output_tbl), of_label,
- 0, 1, 3, 4, GTK_FILL, GTK_FILL, 1, 1);
+ gtk_table_attach (GTK_TABLE (output_tbl), of_label, 0, 1, 3, 4, GTK_FILL,
+ GTK_FILL, 1, 1);
of_entry = gtk_entry_new ();
- gtk_widget_set_tooltip_markup (of_entry, _("The output disk format, typically
<b>raw</b> or <b>qcow2</b>. If blank, defaults to
<b>raw</b>."));
+ gtk_widget_set_tooltip_markup (
+ of_entry, _("The output disk format, typically <b>raw</b> or "
+ "<b>qcow2</b>. If blank, defaults to
<b>raw</b>."));
if (config->output_format != NULL)
gtk_entry_set_text (GTK_ENTRY (of_entry), config->output_format);
- gtk_table_attach (GTK_TABLE (output_tbl), of_entry,
- 1, 2, 3, 4, GTK_FILL, GTK_FILL, 1, 1);
+ gtk_table_attach (GTK_TABLE (output_tbl), of_entry, 1, 2, 3, 4, GTK_FILL,
+ GTK_FILL, 1, 1);
oa_label = gtk_label_new (_("Output allocation (-oa):"));
gtk_misc_set_alignment (GTK_MISC (oa_label), 1., 0.5);
- gtk_table_attach (GTK_TABLE (output_tbl), oa_label,
- 0, 1, 4, 5, GTK_FILL, GTK_FILL, 1, 1);
+ gtk_table_attach (GTK_TABLE (output_tbl), oa_label, 0, 1, 4, 5, GTK_FILL,
+ GTK_FILL, 1, 1);
oa_combo = gtk_combo_box_text_new ();
- gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (oa_combo),
- "sparse");
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (oa_combo), "sparse");
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (oa_combo),
"preallocated");
switch (config->output_allocation) {
@@ -597,12 +619,12 @@ create_conversion_dialog (struct config *config)
gtk_combo_box_set_active (GTK_COMBO_BOX (oa_combo), 0);
break;
}
- gtk_table_attach (GTK_TABLE (output_tbl), oa_combo,
- 1, 2, 4, 5, GTK_FILL, GTK_FILL, 1, 1);
+ gtk_table_attach (GTK_TABLE (output_tbl), oa_combo, 1, 2, 4, 5, GTK_FILL,
+ GTK_FILL, 1, 1);
- debug_button =
- gtk_check_button_new_with_label (_("Enable server-side debugging\n"
- "(This is saved in /tmp on the conversion
server)"));
+ debug_button = gtk_check_button_new_with_label (
+ _("Enable server-side debugging\n"
+ "(This is saved in /tmp on the conversion server)"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (debug_button),
config->verbose);
@@ -652,10 +674,12 @@ create_conversion_dialog (struct config *config)
/* See maybe_identify_click below for what we're doing. */
g_signal_connect (interfaces_list, "button-press-event",
G_CALLBACK (maybe_identify_click), NULL);
- gtk_widget_set_tooltip_markup (interfaces_list, _("Left click on an interface name
to flash the light on the physical interface."));
+ gtk_widget_set_tooltip_markup (
+ interfaces_list, _("Left click on an interface name to flash the "
+ "light on the physical interface."));
populate_interfaces (GTK_TREE_VIEW (interfaces_list));
- gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (interfaces_sw),
- interfaces_list);
+ gtk_scrolled_window_add_with_viewport (
+ GTK_SCROLLED_WINDOW (interfaces_sw), interfaces_list);
gtk_container_add (GTK_CONTAINER (interfaces_frame), interfaces_sw);
/* Pack the top level dialog. */
@@ -665,20 +689,20 @@ create_conversion_dialog (struct config *config)
gtk_box_pack_start (GTK_BOX (right_vbox), disks_frame, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (right_vbox), removable_frame, TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (right_vbox), interfaces_frame, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (right_vbox), interfaces_frame, TRUE, TRUE,
+ 0);
gtk_box_pack_start (GTK_BOX (hbox), left_vbox, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (hbox), right_vbox, TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (GTK_DIALOG (conv_dlg)->vbox),
- hbox, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (conv_dlg)->vbox), hbox, TRUE,
+ TRUE, 0);
/* Buttons. */
- gtk_dialog_add_buttons (GTK_DIALOG (conv_dlg),
- _("Back"), 1,
- _("Start conversion"), 2,
- NULL);
+ gtk_dialog_add_buttons (GTK_DIALOG (conv_dlg), _("Back"), 1,
+ _("Start conversion"), 2, NULL);
back = gtk_dialog_get_widget_for_response (GTK_DIALOG (conv_dlg), 1);
- start_button = gtk_dialog_get_widget_for_response (GTK_DIALOG (conv_dlg), 2);
+ start_button =
+ gtk_dialog_get_widget_for_response (GTK_DIALOG (conv_dlg), 2);
/* Signals. */
g_signal_connect_swapped (G_OBJECT (conv_dlg), "destroy",
@@ -719,9 +743,8 @@ set_info_label (void)
if (!v2v_major)
r = asprintf (&text, _("virt-p2v (client) %s"), PACKAGE_VERSION);
else
- r = asprintf (&text,
- _("virt-p2v (client) %s\n"
- "virt-v2v (conversion server) %d.%d.%d"),
+ r = asprintf (&text, _("virt-p2v (client) %s\n"
+ "virt-v2v (conversion server) %d.%d.%d"),
PACKAGE_VERSION, v2v_major, v2v_minor, v2v_release);
if (r == -1) {
perror ("asprintf");
@@ -742,7 +765,8 @@ repopulate_output_combo (struct config *config)
if (config && config->output)
output = strdup (config->output);
else
- output = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (o_combo));
+ output =
+ gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (o_combo));
/* Remove existing rows in o_combo. */
model = gtk_combo_box_get_model (GTK_COMBO_BOX (o_combo));
@@ -752,7 +776,8 @@ repopulate_output_combo (struct config *config)
* a standard set of drivers.
*/
if (output_drivers == NULL) {
- gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (o_combo), "libvirt");
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (o_combo),
+ "libvirt");
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (o_combo), "local");
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (o_combo), "rhev");
if (output == NULL || STREQ (output, "libvirt"))
@@ -781,14 +806,14 @@ static void
populate_disks (GtkTreeView *disks_list)
{
GtkListStore *disks_store;
- GtkCellRenderer *disks_col_convert, *disks_col_device,
- *disks_col_size, *disks_col_model;
+ GtkCellRenderer *disks_col_convert, *disks_col_device, *disks_col_size,
+ *disks_col_model;
GtkTreeIter iter;
size_t i;
- disks_store = gtk_list_store_new (NUM_DISKS_COLS,
- G_TYPE_BOOLEAN, G_TYPE_STRING,
- G_TYPE_STRING, G_TYPE_STRING);
+ disks_store =
+ gtk_list_store_new (NUM_DISKS_COLS, G_TYPE_BOOLEAN, G_TYPE_STRING,
+ G_TYPE_STRING, G_TYPE_STRING);
if (all_disks != NULL) {
for (i = 0; all_disks[i] != NULL; ++i) {
CLEANUP_FREE char *size_filename = NULL;
@@ -798,12 +823,12 @@ populate_disks (GtkTreeView *disks_list)
CLEANUP_FREE char *model = NULL;
uint64_t size;
- if (asprintf (&size_filename, "/sys/block/%s/size",
- all_disks[i]) == -1)
+ if (asprintf (&size_filename, "/sys/block/%s/size", all_disks[i]) ==
+ -1)
error (EXIT_FAILURE, errno, "asprintf");
if (g_file_get_contents (size_filename, &size_str, NULL, NULL) &&
sscanf (size_str, "%" SCNu64, &size) == 1) {
- size /= 2*1024*1024; /* size from kernel is given in sectors? */
+ size /= 2 * 1024 * 1024; /* size from kernel is given in sectors? */
if (asprintf (&size_gb, "%" PRIu64, size) == -1)
error (EXIT_FAILURE, errno, "asprintf");
}
@@ -814,55 +839,40 @@ populate_disks (GtkTreeView *disks_list)
if (g_file_get_contents (model_filename, &model, NULL, NULL)) {
/* Need to chomp trailing \n from the content. */
size_t len = strlen (model);
- if (len > 0 && model[len-1] == '\n')
- model[len-1] = '\0';
- } else {
+ if (len > 0 && model[len - 1] == '\n')
+ model[len - 1] = '\0';
+ }
+ else {
model = strdup ("");
}
gtk_list_store_append (disks_store, &iter);
- gtk_list_store_set (disks_store, &iter,
- DISKS_COL_CONVERT, TRUE,
- DISKS_COL_DEVICE, all_disks[i],
- DISKS_COL_SIZE, size_gb,
- DISKS_COL_MODEL, model,
- -1);
+ gtk_list_store_set (disks_store, &iter, DISKS_COL_CONVERT, TRUE,
+ DISKS_COL_DEVICE, all_disks[i], DISKS_COL_SIZE,
+ size_gb, DISKS_COL_MODEL, model, -1);
}
}
- gtk_tree_view_set_model (disks_list,
- GTK_TREE_MODEL (disks_store));
+ gtk_tree_view_set_model (disks_list, GTK_TREE_MODEL (disks_store));
gtk_tree_view_set_headers_visible (disks_list, TRUE);
disks_col_convert = gtk_cell_renderer_toggle_new ();
- gtk_tree_view_insert_column_with_attributes (disks_list,
- -1,
- _("Convert"),
- disks_col_convert,
- "active", DISKS_COL_CONVERT,
- NULL);
+ gtk_tree_view_insert_column_with_attributes (
+ disks_list, -1, _("Convert"), disks_col_convert, "active",
+ DISKS_COL_CONVERT, NULL);
disks_col_device = gtk_cell_renderer_text_new ();
- gtk_tree_view_insert_column_with_attributes (disks_list,
- -1,
- _("Device"),
- disks_col_device,
- "text", DISKS_COL_DEVICE,
- NULL);
+ gtk_tree_view_insert_column_with_attributes (disks_list, -1, _("Device"),
+ disks_col_device, "text",
+ DISKS_COL_DEVICE, NULL);
disks_col_size = gtk_cell_renderer_text_new ();
- gtk_tree_view_insert_column_with_attributes (disks_list,
- -1,
- _("Size (GB)"),
- disks_col_size,
- "text", DISKS_COL_SIZE,
- NULL);
+ gtk_tree_view_insert_column_with_attributes (
+ disks_list, -1, _("Size (GB)"), disks_col_size, "text",
DISKS_COL_SIZE,
+ NULL);
disks_col_model = gtk_cell_renderer_text_new ();
- gtk_tree_view_insert_column_with_attributes (disks_list,
- -1,
- _("Model"),
- disks_col_model,
- "text", DISKS_COL_MODEL,
- NULL);
+ gtk_tree_view_insert_column_with_attributes (disks_list, -1, _("Model"),
+ disks_col_model, "text",
+ DISKS_COL_MODEL, NULL);
- g_signal_connect (disks_col_convert, "toggled",
- G_CALLBACK (toggled), disks_store);
+ g_signal_connect (disks_col_convert, "toggled", G_CALLBACK (toggled),
+ disks_store);
}
static void
@@ -873,37 +883,29 @@ populate_removable (GtkTreeView *removable_list)
GtkTreeIter iter;
size_t i;
- removable_store = gtk_list_store_new (NUM_REMOVABLE_COLS,
- G_TYPE_BOOLEAN, G_TYPE_STRING);
+ removable_store =
+ gtk_list_store_new (NUM_REMOVABLE_COLS, G_TYPE_BOOLEAN, G_TYPE_STRING);
if (all_removable != NULL) {
for (i = 0; all_removable[i] != NULL; ++i) {
gtk_list_store_append (removable_store, &iter);
- gtk_list_store_set (removable_store, &iter,
- REMOVABLE_COL_CONVERT, TRUE,
- REMOVABLE_COL_DEVICE, all_removable[i],
- -1);
+ gtk_list_store_set (removable_store, &iter, REMOVABLE_COL_CONVERT,
+ TRUE, REMOVABLE_COL_DEVICE, all_removable[i], -1);
}
}
gtk_tree_view_set_model (removable_list,
GTK_TREE_MODEL (removable_store));
gtk_tree_view_set_headers_visible (removable_list, TRUE);
removable_col_convert = gtk_cell_renderer_toggle_new ();
- gtk_tree_view_insert_column_with_attributes (removable_list,
- -1,
- _("Convert"),
- removable_col_convert,
- "active",
REMOVABLE_COL_CONVERT,
- NULL);
+ gtk_tree_view_insert_column_with_attributes (
+ removable_list, -1, _("Convert"), removable_col_convert,
"active",
+ REMOVABLE_COL_CONVERT, NULL);
removable_col_device = gtk_cell_renderer_text_new ();
- gtk_tree_view_insert_column_with_attributes (removable_list,
- -1,
- _("Device"),
- removable_col_device,
- "text", REMOVABLE_COL_DEVICE,
- NULL);
+ gtk_tree_view_insert_column_with_attributes (
+ removable_list, -1, _("Device"), removable_col_device, "text",
+ REMOVABLE_COL_DEVICE, NULL);
- g_signal_connect (removable_col_convert, "toggled",
- G_CALLBACK (toggled), removable_store);
+ g_signal_connect (removable_col_convert, "toggled", G_CALLBACK (toggled),
+ removable_store);
}
static void
@@ -915,9 +917,8 @@ populate_interfaces (GtkTreeView *interfaces_list)
GtkTreeIter iter;
size_t i;
- interfaces_store = gtk_list_store_new (NUM_INTERFACES_COLS,
- G_TYPE_BOOLEAN, G_TYPE_STRING,
- G_TYPE_STRING);
+ interfaces_store = gtk_list_store_new (
+ NUM_INTERFACES_COLS, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_STRING);
if (all_interfaces) {
for (i = 0; all_interfaces[i] != NULL; ++i) {
const char *if_name = all_interfaces[i];
@@ -931,10 +932,10 @@ populate_interfaces (GtkTreeView *interfaces_list)
"%s\n"
"%s"
"</small>\n"
- "<small><u><span
foreground=\"blue\">Identify
interface</span></u></small>",
- if_name,
- if_addr ? : _("Unknown"),
- if_vendor ? : _("Unknown")) == -1)
+ "<small><u><span
foreground=\"blue\">Identify "
+ "interface</span></u></small>",
+ if_name, if_addr ?: _("Unknown"),
+ if_vendor ?: _("Unknown")) == -1)
error (EXIT_FAILURE, errno, "asprintf");
gtk_list_store_append (interfaces_store, &iter);
@@ -945,40 +946,30 @@ populate_interfaces (GtkTreeView *interfaces_list)
*/
INTERFACES_COL_CONVERT, i == 0,
INTERFACES_COL_DEVICE, device_descr,
- INTERFACES_COL_NETWORK, "default",
- -1);
+ INTERFACES_COL_NETWORK, "default", -1);
}
}
gtk_tree_view_set_model (interfaces_list,
GTK_TREE_MODEL (interfaces_store));
gtk_tree_view_set_headers_visible (interfaces_list, TRUE);
interfaces_col_convert = gtk_cell_renderer_toggle_new ();
- gtk_tree_view_insert_column_with_attributes (interfaces_list,
- -1,
- _("Convert"),
- interfaces_col_convert,
- "active",
INTERFACES_COL_CONVERT,
- NULL);
+ gtk_tree_view_insert_column_with_attributes (
+ interfaces_list, -1, _("Convert"), interfaces_col_convert,
"active",
+ INTERFACES_COL_CONVERT, NULL);
gtk_cell_renderer_set_alignment (interfaces_col_convert, 0.5, 0.0);
interfaces_col_device = gtk_cell_renderer_text_new ();
- gtk_tree_view_insert_column_with_attributes (interfaces_list,
- -1,
- _("Device"),
- interfaces_col_device,
- "markup",
INTERFACES_COL_DEVICE,
- NULL);
+ gtk_tree_view_insert_column_with_attributes (
+ interfaces_list, -1, _("Device"), interfaces_col_device,
"markup",
+ INTERFACES_COL_DEVICE, NULL);
gtk_cell_renderer_set_alignment (interfaces_col_device, 0.5, 0.0);
interfaces_col_network = gtk_cell_renderer_text_new ();
- gtk_tree_view_insert_column_with_attributes (interfaces_list,
- -1,
- _("Connect to virtual
network"),
- interfaces_col_network,
- "text", INTERFACES_COL_NETWORK,
- NULL);
+ gtk_tree_view_insert_column_with_attributes (
+ interfaces_list, -1, _("Connect to virtual network"),
+ interfaces_col_network, "text", INTERFACES_COL_NETWORK, NULL);
gtk_cell_renderer_set_alignment (interfaces_col_network, 0.5, 0.0);
- g_signal_connect (interfaces_col_convert, "toggled",
- G_CALLBACK (toggled), interfaces_store);
+ g_signal_connect (interfaces_col_convert, "toggled", G_CALLBACK (toggled),
+ interfaces_store);
g_object_set (interfaces_col_network, "editable", TRUE, NULL);
g_signal_connect (interfaces_col_network, "edited",
@@ -996,7 +987,8 @@ toggled (GtkCellRendererToggle *cell, gchar *path_str, gpointer data)
gtk_tree_model_get_iter (model, &iter, path);
gtk_tree_model_get (model, &iter, 0 /* CONVERT */, &v, -1);
v ^= 1;
- gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0 /* CONVERT */, v, -1);
+ gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0 /* CONVERT */, v,
+ -1);
gtk_tree_path_free (path);
}
@@ -1014,8 +1006,8 @@ network_edited_callback (GtkCellRendererToggle *cell, gchar
*path_str,
path = gtk_tree_path_new_from_string (path_str);
gtk_tree_model_get_iter (model, &iter, path);
- gtk_list_store_set (GTK_LIST_STORE (model), &iter,
- INTERFACES_COL_NETWORK, new_text, -1);
+ gtk_list_store_set (GTK_LIST_STORE (model), &iter, INTERFACES_COL_NETWORK,
+ new_text, -1);
gtk_tree_path_free (path);
}
@@ -1030,7 +1022,7 @@ static gboolean
maybe_identify_click (GtkWidget *interfaces_list, GdkEventButton *event,
gpointer data)
{
- gboolean ret = FALSE; /* Did we handle this event? */
+ gboolean ret = FALSE; /* Did we handle this event? */
/* Single left click only. */
if (event->type == GDK_BUTTON_PRESS && event->button == 1) {
@@ -1038,14 +1030,14 @@ maybe_identify_click (GtkWidget *interfaces_list, GdkEventButton
*event,
GtkTreeViewColumn *column;
if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (interfaces_list),
- event->x, event->y,
- &path, &column, NULL, NULL)) {
+ event->x, event->y, &path, &column,
+ NULL, NULL)) {
GList *cols;
gint column_index;
/* Get column index. */
cols = gtk_tree_view_get_columns (GTK_TREE_VIEW (interfaces_list));
- column_index = g_list_index (cols, (gpointer) column);
+ column_index = g_list_index (cols, (gpointer)column);
g_list_free (cols);
if (column_index == INTERFACES_COL_DEVICE) {
@@ -1069,7 +1061,7 @@ maybe_identify_click (GtkWidget *interfaces_list, GdkEventButton
*event,
free (cmd);
- ret = TRUE; /* We handled this event. */
+ ret = TRUE; /* We handled this event. */
}
gtk_tree_path_free (path);
@@ -1156,9 +1148,8 @@ set_network_map_from_ui (struct config *config)
model = gtk_tree_view_get_model (list);
guestfs_int_free_string_list (config->network_map);
- config->network_map =
- malloc ((1 + guestfs_int_count_strings (all_interfaces))
- * sizeof (char *));
+ config->network_map = malloc (
+ (1 + guestfs_int_count_strings (all_interfaces)) * sizeof (char *));
if (config->network_map == NULL)
error (EXIT_FAILURE, errno, "malloc");
i = j = 0;
@@ -1168,8 +1159,8 @@ set_network_map_from_ui (struct config *config)
gtk_tree_model_get (model, &iter, INTERFACES_COL_NETWORK, &s, -1);
if (s) {
assert (all_interfaces[i] != NULL);
- if (asprintf (&config->network_map[j], "%s:%s",
- all_interfaces[i], s) == -1)
+ if (asprintf (&config->network_map[j], "%s:%s",
all_interfaces[i],
+ s) == -1)
error (EXIT_FAILURE, errno, "asprintf");
++j;
}
@@ -1197,11 +1188,11 @@ conversion_back_clicked (GtkWidget *w, gpointer data)
* range. (RHBZ#823758). See also:
*
https://access.redhat.com/articles/rhel-kvm-limits
*/
-#define MAX_SUPPORTED_VCPUS 160
+#define MAX_SUPPORTED_VCPUS 160
#define MAX_SUPPORTED_MEMORY_MB (UINT64_C (4000 * 1024))
static char *concat_warning (char *warning, const char *fs, ...)
- __attribute__((format (printf,2,3)));
+ __attribute__((format (printf, 2, 3)));
static char *
concat_warning (char *warning, const char *fs, ...)
@@ -1215,11 +1206,11 @@ concat_warning (char *warning, const char *fs, ...)
warning = strdup ("");
if (warning == NULL)
malloc_fail:
- error (EXIT_FAILURE, errno, "malloc");
+ error (EXIT_FAILURE, errno, "malloc");
}
len = strlen (warning);
- if (len > 0 && warning[len-1] != '\n' && fs[0] !=
'\n') {
+ if (len > 0 && warning[len - 1] != '\n' && fs[0] !=
'\n') {
warning = concat_warning (warning, "\n");
len = strlen (warning);
}
@@ -1227,11 +1218,13 @@ concat_warning (char *warning, const char *fs, ...)
va_start (args, fs);
r = vasprintf (&msg, fs, args);
va_end (args);
- if (r == -1) goto malloc_fail;
+ if (r == -1)
+ goto malloc_fail;
len2 = strlen (msg);
warning = realloc (warning, len + len2 + 1);
- if (warning == NULL) goto malloc_fail;
+ if (warning == NULL)
+ goto malloc_fail;
memcpy (&warning[len], msg, len2 + 1);
free (msg);
@@ -1251,9 +1244,10 @@ vcpus_or_memory_check_callback (GtkWidget *w, gpointer data)
if (vcpus > MAX_SUPPORTED_VCPUS) {
gtk_widget_show (vcpus_warning);
- warning = concat_warning (warning,
- _("Number of virtual CPUs is larger than what is
supported for KVM (max: %d)."),
- MAX_SUPPORTED_VCPUS);
+ warning =
+ concat_warning (warning, _("Number of virtual CPUs is larger than "
+ "what is supported for KVM (max: %d)."),
+ MAX_SUPPORTED_VCPUS);
}
else
gtk_widget_hide (vcpus_warning);
@@ -1261,16 +1255,19 @@ vcpus_or_memory_check_callback (GtkWidget *w, gpointer data)
if (memory > MAX_SUPPORTED_MEMORY_MB * 1024 * 1024) {
gtk_widget_show (memory_warning);
- warning = concat_warning (warning,
- _("Memory size is larger than what is supported for
KVM (max: %" PRIu64 ")."),
- MAX_SUPPORTED_MEMORY_MB);
+ warning =
+ concat_warning (warning, _("Memory size is larger than what is "
+ "supported for KVM (max: %" PRIu64
")."),
+ MAX_SUPPORTED_MEMORY_MB);
}
else
gtk_widget_hide (memory_warning);
if (warning != NULL) {
- warning = concat_warning (warning,
- _("If you ignore this warning, conversion can still
succeed, but the guest may not work or may not be supported on the target."));
+ warning = concat_warning (
+ warning,
+ _("If you ignore this warning, conversion can still succeed, but "
+ "the guest may not work or may not be supported on the target."));
gtk_label_set_text (GTK_LABEL (target_warning_label), warning);
}
else
@@ -1313,7 +1310,8 @@ static void add_v2v_output_2 (const char *msg, size_t len);
static void *start_conversion_thread (void *data);
static void cancel_conversion_clicked (GtkWidget *w, gpointer data);
static void reboot_clicked (GtkWidget *w, gpointer data);
-static gboolean close_running_dialog (GtkWidget *w, GdkEvent *event, gpointer data);
+static gboolean close_running_dialog (GtkWidget *w, GdkEvent *event,
+ gpointer data);
static void
create_running_dialog (void)
@@ -1340,21 +1338,21 @@ create_running_dialog (void)
gtk_container_add (GTK_CONTAINER (v2v_output_sw), v2v_output);
- gtk_box_pack_start (GTK_BOX (GTK_DIALOG (run_dlg)->vbox),
- v2v_output_sw, TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (GTK_DIALOG (run_dlg)->vbox),
- log_label, TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (GTK_DIALOG (run_dlg)->vbox),
- status_label, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (run_dlg)->vbox), v2v_output_sw,
+ TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (run_dlg)->vbox), log_label, TRUE,
+ TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (run_dlg)->vbox), status_label,
+ TRUE, TRUE, 0);
/* Buttons. */
- gtk_dialog_add_buttons (GTK_DIALOG (run_dlg),
- _("Cancel conversion"), 1,
- _("Reboot"), 2,
- NULL);
- cancel_button = gtk_dialog_get_widget_for_response (GTK_DIALOG (run_dlg), 1);
+ gtk_dialog_add_buttons (GTK_DIALOG (run_dlg), _("Cancel conversion"), 1,
+ _("Reboot"), 2, NULL);
+ cancel_button =
+ gtk_dialog_get_widget_for_response (GTK_DIALOG (run_dlg), 1);
gtk_widget_set_sensitive (cancel_button, FALSE);
- reboot_button = gtk_dialog_get_widget_for_response (GTK_DIALOG (run_dlg), 2);
+ reboot_button =
+ gtk_dialog_get_widget_for_response (GTK_DIALOG (run_dlg), 2);
gtk_widget_set_sensitive (reboot_button, FALSE);
/* Signals. */
@@ -1386,11 +1384,10 @@ set_log_dir (const char *remote_dir)
{
CLEANUP_FREE char *msg;
- if (asprintf (&msg,
- _("Log files and debug information "
- "is saved to this directory "
- "on the conversion server:\n"
- "%s"),
+ if (asprintf (&msg, _("Log files and debug information "
+ "is saved to this directory "
+ "on the conversion server:\n"
+ "%s"),
remote_dir ? remote_dir : "") == -1)
error (EXIT_FAILURE, errno, "asprintf");
@@ -1421,14 +1418,14 @@ add_v2v_output (const char *msg)
for (p0 = p = msg; *p; ++p) {
linelen++;
if (*p == '\n' || linelen > 1024) {
- add_v2v_output_2 (p0, p-p0+1);
+ add_v2v_output_2 (p0, p - p0 + 1);
if (*p != '\n')
add_v2v_output_2 ("\n", 1);
linelen = 0;
- p0 = p+1;
+ p0 = p + 1;
}
}
- add_v2v_output_2 (p0, p-p0);
+ add_v2v_output_2 (p0, p - p0);
}
static void
@@ -1444,8 +1441,8 @@ add_v2v_output_2 (const char *msg, size_t len)
/* Scroll to the end of the buffer. */
gtk_text_buffer_get_end_iter (buf, &iter);
- gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (v2v_output), &iter,
- 0, FALSE, 0., 1.);
+ gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (v2v_output), &iter, 0, FALSE,
+ 0., 1.);
}
/* User clicked the Start conversion button. */
@@ -1463,13 +1460,13 @@ start_conversion_clicked (GtkWidget *w, gpointer data)
/* Unpack dialog fields and check them. */
free (config->guestname);
- config->guestname = strdup (gtk_entry_get_text (GTK_ENTRY (guestname_entry)));
+ config->guestname =
+ strdup (gtk_entry_get_text (GTK_ENTRY (guestname_entry)));
if (STREQ (config->guestname, "")) {
dlg = gtk_message_dialog_new (GTK_WINDOW (conv_dlg),
GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
+ GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
_("The guest \"Name\" field is
empty."));
gtk_window_set_title (GTK_WINDOW (dlg), _("Error"));
gtk_dialog_run (GTK_DIALOG (dlg));
@@ -1488,13 +1485,13 @@ start_conversion_clicked (GtkWidget *w, gpointer data)
set_disks_from_ui (config);
/* The list of disks must be non-empty. */
- if (config->disks == NULL || guestfs_int_count_strings (config->disks) == 0) {
- dlg = gtk_message_dialog_new (GTK_WINDOW (conv_dlg),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- _("No disks were selected for conversion.\n"
- "At least one fixed hard disk must be
selected.\n"));
+ if (config->disks == NULL ||
+ guestfs_int_count_strings (config->disks) == 0) {
+ dlg = gtk_message_dialog_new (
+ GTK_WINDOW (conv_dlg), GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
+ _("No disks were selected for conversion.\n"
+ "At least one fixed hard disk must be selected.\n"));
gtk_window_set_title (GTK_WINDOW (dlg), _("Error"));
gtk_dialog_run (GTK_DIALOG (dlg));
gtk_widget_destroy (dlg);
@@ -1575,11 +1572,9 @@ start_conversion_thread (void *data)
if (r == -1) {
const char *err = get_conversion_error ();
- dlg = gtk_message_dialog_new (GTK_WINDOW (run_dlg),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- _("Conversion failed: %s"), err);
+ dlg = gtk_message_dialog_new (
+ GTK_WINDOW (run_dlg), GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Conversion failed: %s"), err);
gtk_window_set_title (GTK_WINDOW (dlg), _("Conversion failed"));
gtk_dialog_run (GTK_DIALOG (dlg));
gtk_widget_destroy (dlg);
@@ -1587,10 +1582,10 @@ start_conversion_thread (void *data)
else {
dlg = gtk_message_dialog_new (GTK_WINDOW (run_dlg),
GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_INFO,
- GTK_BUTTONS_OK,
+ GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
_("The conversion was successful."));
- gtk_window_set_title (GTK_WINDOW (dlg), _("Conversion was successful"));
+ gtk_window_set_title (GTK_WINDOW (dlg),
+ _("Conversion was successful"));
gtk_dialog_run (GTK_DIALOG (dlg));
gtk_widget_destroy (dlg);
}
diff --git a/p2v/kernel-cmdline.c b/p2v/kernel-cmdline.c
index ee4c0e9..f99f004 100644
--- a/p2v/kernel-cmdline.c
+++ b/p2v/kernel-cmdline.c
@@ -46,15 +46,15 @@ add_null (char ***argv, size_t *lenp)
*argv = realloc (*argv, *lenp * sizeof (char *));
if (*argv == NULL)
error (EXIT_FAILURE, errno, "realloc");
- (*argv)[(*lenp)-1] = NULL;
+ (*argv)[(*lenp) - 1] = NULL;
}
static void
add_string (char ***argv, size_t *lenp, const char *str, size_t len)
{
add_null (argv, lenp);
- (*argv)[(*lenp)-1] = strndup (str, len);
- if ((*argv)[(*lenp)-1] == NULL)
+ (*argv)[(*lenp) - 1] = strndup (str, len);
+ if ((*argv)[(*lenp) - 1] == NULL)
error (EXIT_FAILURE, errno, "strndup");
}
@@ -64,41 +64,36 @@ parse_cmdline_string (const char *cmdline)
char **ret = NULL;
size_t len = 0;
const char *p, *key = NULL, *value = NULL;
- enum {
- KEY_START = 0,
- KEY,
- VALUE_START,
- VALUE,
- VALUE_QUOTED
- } state = 0;
+ enum { KEY_START = 0, KEY, VALUE_START, VALUE, VALUE_QUOTED } state = 0;
for (p = cmdline; *p; p++) {
switch (state) {
- case KEY_START: /* looking for the start of a key */
- if (*p == ' ') continue;
+ case KEY_START: /* looking for the start of a key */
+ if (*p == ' ')
+ continue;
key = p;
state = KEY;
break;
- case KEY: /* reading key */
+ case KEY: /* reading key */
if (*p == ' ') {
- add_string (&ret, &len, key, p-key);
+ add_string (&ret, &len, key, p - key);
add_string (&ret, &len, "", 0);
state = KEY_START;
}
else if (*p == '=') {
- add_string (&ret, &len, key, p-key);
+ add_string (&ret, &len, key, p - key);
state = VALUE_START;
}
break;
- case VALUE_START: /* looking for the start of a value */
+ case VALUE_START: /* looking for the start of a value */
if (*p == ' ') {
add_string (&ret, &len, "", 0);
state = KEY_START;
}
else if (*p == '"') {
- value = p+1;
+ value = p + 1;
state = VALUE_QUOTED;
}
else {
@@ -107,16 +102,16 @@ parse_cmdline_string (const char *cmdline)
}
break;
- case VALUE: /* reading unquoted value */
+ case VALUE: /* reading unquoted value */
if (*p == ' ') {
- add_string (&ret, &len, value, p-value);
+ add_string (&ret, &len, value, p - value);
state = KEY_START;
}
break;
- case VALUE_QUOTED: /* reading quoted value */
+ case VALUE_QUOTED: /* reading quoted value */
if (*p == '"') {
- add_string (&ret, &len, value, p-value);
+ add_string (&ret, &len, value, p - value);
state = KEY_START;
}
break;
@@ -124,21 +119,24 @@ parse_cmdline_string (const char *cmdline)
}
switch (state) {
- case KEY_START: break;
- case KEY: /* key followed by end of string */
- add_string (&ret, &len, key, p-key);
+ case KEY_START:
+ break;
+ case KEY: /* key followed by end of string */
+ add_string (&ret, &len, key, p - key);
add_string (&ret, &len, "", 0);
break;
- case VALUE_START: /* key= followed by end of string */
+ case VALUE_START: /* key= followed by end of string */
add_string (&ret, &len, "", 0);
break;
- case VALUE: /* key=value followed by end of string */
- add_string (&ret, &len, value, p-value);
+ case VALUE: /* key=value followed by end of string */
+ add_string (&ret, &len, value, p - value);
break;
- case VALUE_QUOTED: /* unterminated key="value" */
- fprintf (stderr, "%s: warning: unterminated quoted string on kernel command
line\n",
- guestfs_int_program_name);
- add_string (&ret, &len, value, p-value);
+ case VALUE_QUOTED: /* unterminated key="value" */
+ fprintf (
+ stderr,
+ "%s: warning: unterminated quoted string on kernel command line\n",
+ guestfs_int_program_name);
+ add_string (&ret, &len, value, p - value);
}
add_null (&ret, &len);
@@ -169,8 +167,8 @@ parse_proc_cmdline (void)
*/
len = strlen (cmdline);
- if (len >= 1 && cmdline[len-1] == '\n')
- cmdline[len-1] = '\0';
+ if (len >= 1 && cmdline[len - 1] == '\n')
+ cmdline[len - 1] = '\0';
return parse_cmdline_string (cmdline);
}
@@ -182,7 +180,7 @@ get_cmdline_key (char **argv, const char *key)
for (i = 0; argv[i] != NULL; i += 2) {
if (STREQ (argv[i], key))
- return argv[i+1];
+ return argv[i + 1];
}
/* Not found. */
diff --git a/p2v/kernel.c b/p2v/kernel.c
index fb52785..662d63f 100644
--- a/p2v/kernel.c
+++ b/p2v/kernel.c
@@ -36,10 +36,12 @@
#include "p2v.h"
static void notify_ui_callback (int type, const char *data);
-static void run_command (int verbose, const char *stage, const char *command);
+static void run_command (int verbose, const char *stage,
+ const char *command);
void
-kernel_configuration (struct config *config, char **cmdline, int cmdline_source)
+kernel_configuration (struct config *config, char **cmdline,
+ int cmdline_source)
{
const char *p;
@@ -118,15 +120,16 @@ kernel_configuration (struct config *config, char **cmdline, int
cmdline_source)
error (EXIT_FAILURE, 0,
"cannot parse p2v.memory from kernel command line");
config->memory *= 1024;
- if (mem_code == 'M' || mem_code == 'm'
- || mem_code == 'G' || mem_code == 'g')
+ if (mem_code == 'M' || mem_code == 'm' || mem_code == 'G' ||
+ mem_code == 'g')
config->memory *= 1024;
if (mem_code == 'G' || mem_code == 'g')
config->memory *= 1024;
- if (mem_code != 'M' && mem_code != 'm'
- && mem_code != 'G' && mem_code != 'g')
- error (EXIT_FAILURE, 0,
- "p2v.memory on kernel command line must be followed by 'G' or
'M'");
+ if (mem_code != 'M' && mem_code != 'm' && mem_code !=
'G' &&
+ mem_code != 'g')
+ error (
+ EXIT_FAILURE, 0,
+ "p2v.memory on kernel command line must be followed by 'G' or
'M'");
}
p = get_cmdline_key (cmdline, "p2v.disks");
@@ -200,7 +203,8 @@ kernel_configuration (struct config *config, char **cmdline, int
cmdline_source)
config->output_storage = strdup (p);
}
- /* Undocumented command line tool used for testing command line parsing. */
+ /* Undocumented command line tool used for testing command line parsing.
+ */
p = get_cmdline_key (cmdline, "p2v.dump_config_and_exit");
if (p) {
print_config (config, stdout);
@@ -208,10 +212,12 @@ kernel_configuration (struct config *config, char **cmdline, int
cmdline_source)
}
/* Some disks must have been specified for conversion. */
- if (config->disks == NULL || guestfs_int_count_strings (config->disks) == 0)
+ if (config->disks == NULL ||
+ guestfs_int_count_strings (config->disks) == 0)
error (EXIT_FAILURE, 0,
"no non-removable disks were discovered on this machine.\n"
- "virt-p2v looked in /sys/block and in p2v.disks on the kernel command
line.\n"
+ "virt-p2v looked in /sys/block and in p2v.disks on the kernel "
+ "command line.\n"
"This is a fatal error and virt-p2v cannot continue.");
/* Perform the conversion in text mode. */
@@ -242,7 +248,8 @@ notify_ui_callback (int type, const char *data)
{
switch (type) {
case NOTIFY_LOG_DIR:
- printf ("%s: remote log directory location: %s\n",
guestfs_int_program_name, data);
+ printf ("%s: remote log directory location: %s\n",
+ guestfs_int_program_name, data);
break;
case NOTIFY_REMOTE_MESSAGE:
@@ -276,6 +283,6 @@ run_command (int verbose, const char *stage, const char *command)
if (r == -1)
error (EXIT_FAILURE, errno, "system: %s", command);
if ((WIFEXITED (r) && WEXITSTATUS (r) != 0) || !WIFEXITED (r))
- error (EXIT_FAILURE, 0,
- "%s: unexpected failure of external command", stage);
+ error (EXIT_FAILURE, 0, "%s: unexpected failure of external command",
+ stage);
}
diff --git a/p2v/main.c b/p2v/main.c
index 34cbd4d..3469459 100644
--- a/p2v/main.c
+++ b/p2v/main.c
@@ -33,7 +33,8 @@
#include <sys/types.h>
#include <sys/stat.h>
-#pragma GCC diagnostic ignored "-Wstrict-prototypes" /* error in <gtk.h>
*/
+#pragma GCC diagnostic ignored "-Wstrict-prototypes" /* error in <gtk.h>
\
+ */
#include <gtk/gtk.h>
#include "p2v.h"
@@ -49,15 +50,13 @@ static int cpuinfo_flags (void);
enum { HELP_OPTION = CHAR_MAX + 1 };
static const char *options = "Vv";
-static const struct option long_options[] = {
- { "help", 0, 0, HELP_OPTION },
- { "cmdline", 1, 0, 0 },
- { "long-options", 0, 0, 0 },
- { "short-options", 0, 0, 0 },
- { "verbose", 0, 0, 'v' },
- { "version", 0, 0, 'V' },
- { 0, 0, 0, 0 }
-};
+static const struct option long_options[] = { { "help", 0, 0, HELP_OPTION },
+ { "cmdline", 1, 0, 0 },
+ { "long-options", 0, 0, 0 },
+ { "short-options", 0, 0, 0 },
+ { "verbose", 0, 0, 'v'
},
+ { "version", 0, 0, 'V'
},
+ { 0, 0, 0, 0 } };
static void __attribute__((noreturn))
usage (int status)
@@ -66,18 +65,19 @@ usage (int status)
fprintf (stderr, _("Try `%s --help' for more information.\n"),
guestfs_int_program_name);
else {
- printf (_("%s: Convert a physical machine to use KVM\n"
- "Copyright (C) 2009-2016 Red Hat Inc.\n"
- "Usage:\n"
- " %s [--options]\n"
- "Options:\n"
- " --help Display brief help\n"
- " --cmdline=CMDLINE Used to debug command line parsing\n"
- " -v|--verbose Verbose messages\n"
- " -V|--version Display version and exit\n"
- "For more information, see the manpage %s(1).\n"),
- guestfs_int_program_name, guestfs_int_program_name,
- guestfs_int_program_name);
+ printf (
+ _("%s: Convert a physical machine to use KVM\n"
+ "Copyright (C) 2009-2016 Red Hat Inc.\n"
+ "Usage:\n"
+ " %s [--options]\n"
+ "Options:\n"
+ " --help Display brief help\n"
+ " --cmdline=CMDLINE Used to debug command line parsing\n"
+ " -v|--verbose Verbose messages\n"
+ " -V|--version Display version and exit\n"
+ "For more information, see the manpage %s(1).\n"),
+ guestfs_int_program_name, guestfs_int_program_name,
+ guestfs_int_program_name);
}
exit (status);
}
@@ -98,7 +98,8 @@ static void
display_long_options (const struct option *long_options)
{
while (long_options->name) {
- if (STRNEQ (long_options->name, "long-options") && STRNEQ
(long_options->name, "short-options"))
+ if (STRNEQ (long_options->name, "long-options") &&
+ STRNEQ (long_options->name, "short-options"))
printf ("--%s\n", long_options->name);
long_options++;
}
@@ -119,7 +120,7 @@ main (int argc, char *argv[])
bindtextdomain (PACKAGE, LOCALEBASEDIR);
textdomain (PACKAGE);
-#if ! GLIB_CHECK_VERSION(2,32,0)
+#if !GLIB_CHECK_VERSION(2, 32, 0)
/* In glib2 < 2.32 you had to call g_thread_init(). In later glib2
* that is not required and should not be called.
*/
@@ -132,10 +133,11 @@ main (int argc, char *argv[])
for (;;) {
c = getopt_long (argc, argv, options, long_options, &option_index);
- if (c == -1) break;
+ if (c == -1)
+ break;
switch (c) {
- case 0: /* options which are long only */
+ case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "long-options")) {
display_long_options (long_options);
}
@@ -147,8 +149,7 @@ main (int argc, char *argv[])
cmdline_source = CMDLINE_SOURCE_COMMAND_LINE;
}
else
- error (EXIT_FAILURE, 0,
- _("unknown long option: %s (%d)"),
+ error (EXIT_FAILURE, 0, _("unknown long option: %s (%d)"),
long_options[option_index].name, option_index);
break;
@@ -157,9 +158,8 @@ main (int argc, char *argv[])
break;
case 'V':
- printf ("%s %s%s\n",
- guestfs_int_program_name,
- PACKAGE_VERSION, PACKAGE_VERSION_EXTRA);
+ printf ("%s %s%s\n", guestfs_int_program_name, PACKAGE_VERSION,
+ PACKAGE_VERSION_EXTRA);
exit (EXIT_SUCCESS);
case HELP_OPTION:
@@ -198,9 +198,11 @@ main (int argc, char *argv[])
else {
gui:
if (!gui_possible)
- error (EXIT_FAILURE, 0,
- _("gtk_init_check returned false, indicating that\n"
- "a GUI is not possible on this host. Check X11, $DISPLAY
etc."));
+ error (
+ EXIT_FAILURE, 0,
+ _ (
+ "gtk_init_check returned false, indicating that\n"
+ "a GUI is not possible on this host. Check X11, $DISPLAY etc."));
gui_application (config);
}
@@ -227,7 +229,8 @@ set_config_defaults (struct config *config)
/* Generate a simple random name. */
if (guestfs_int_random_string (hostname, 8) == -1)
error (EXIT_FAILURE, errno, "/dev/random");
- } else {
+ }
+ else {
char *p;
/* If the hostname is an FQDN, truncate before the first dot. */
@@ -256,7 +259,7 @@ set_config_defaults (struct config *config)
else
config->memory = i;
- i = sysconf (_SC_PAGESIZE);
+ i = sysconf (_SC_PAGESIZE);
if (i == -1) {
perror ("sysconf: _SC_PAGESIZE");
config->memory *= 4096;
@@ -303,8 +306,8 @@ set_config_defaults (struct config *config)
static int
compare (const void *vp1, const void *vp2)
{
- char * const *p1 = (char * const *) vp1;
- char * const *p2 = (char * const *) vp2;
+ char *const *p1 = (char *const *)vp1;
+ char *const *p2 = (char *const *)vp2;
return strcmp (*p1, *p2);
}
@@ -320,8 +323,8 @@ partition_parent (dev_t part_dev)
unsigned parent_major, parent_minor;
if (asprintf (&path, "/sys/dev/block/%ju:%ju/../dev",
- (uintmax_t) major (part_dev),
- (uintmax_t) minor (part_dev)) == -1)
+ (uintmax_t)major (part_dev),
+ (uintmax_t)minor (part_dev)) == -1)
error (EXIT_FAILURE, errno, "asprintf");
fp = fopen (path, "r");
@@ -394,12 +397,11 @@ find_all_disks (void)
for (;;) {
errno = 0;
d = readdir (dir);
- if (!d) break;
+ if (!d)
+ break;
- if (STRPREFIX (d->d_name, "cciss!") ||
- STRPREFIX (d->d_name, "hd") ||
- STRPREFIX (d->d_name, "sd") ||
- STRPREFIX (d->d_name, "ubd") ||
+ if (STRPREFIX (d->d_name, "cciss!") || STRPREFIX (d->d_name,
"hd") ||
+ STRPREFIX (d->d_name, "sd") || STRPREFIX (d->d_name,
"ubd") ||
STRPREFIX (d->d_name, "vd")) {
char *p;
@@ -412,21 +414,22 @@ find_all_disks (void)
if (!all_disks)
error (EXIT_FAILURE, errno, "realloc");
- all_disks[nr_disks-1] = strdup (d->d_name);
+ all_disks[nr_disks - 1] = strdup (d->d_name);
/* cciss device /dev/cciss/c0d0 will be /sys/block/cciss!c0d0 */
- p = strchr (all_disks[nr_disks-1], '!');
- if (p) *p = '/';
+ p = strchr (all_disks[nr_disks - 1], '!');
+ if (p)
+ *p = '/';
all_disks[nr_disks] = NULL;
}
else if (STRPREFIX (d->d_name, "sr")) {
nr_removable++;
- all_removable = realloc (all_removable,
- sizeof (char *) * (nr_removable + 1));
+ all_removable =
+ realloc (all_removable, sizeof (char *) * (nr_removable + 1));
if (!all_removable)
error (EXIT_FAILURE, errno, "realloc");
- all_removable[nr_removable-1] = strdup (d->d_name);
+ all_removable[nr_removable - 1] = strdup (d->d_name);
all_removable[nr_removable] = NULL;
}
}
@@ -462,23 +465,22 @@ find_all_interfaces (void)
for (;;) {
errno = 0;
d = readdir (dir);
- if (!d) break;
+ if (!d)
+ break;
/* For systemd predictable names, see:
*
http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-ne...
* biosdevname is also a possibility here.
* Ignore PPP, SLIP, WWAN, bridges, etc.
*/
- if (STRPREFIX (d->d_name, "em") ||
- STRPREFIX (d->d_name, "en") ||
- STRPREFIX (d->d_name, "eth") ||
- STRPREFIX (d->d_name, "wl")) {
+ if (STRPREFIX (d->d_name, "em") || STRPREFIX (d->d_name,
"en") ||
+ STRPREFIX (d->d_name, "eth") || STRPREFIX (d->d_name,
"wl")) {
nr_interfaces++;
all_interfaces =
realloc (all_interfaces, sizeof (char *) * (nr_interfaces + 1));
if (!all_interfaces)
error (EXIT_FAILURE, errno, "realloc");
- all_interfaces[nr_interfaces-1] = strdup (d->d_name);
+ all_interfaces[nr_interfaces - 1] = strdup (d->d_name);
all_interfaces[nr_interfaces] = NULL;
}
}
@@ -509,11 +511,11 @@ cpuinfo_flags (void)
/* Get the flags, one per line. */
cmd = "< /proc/cpuinfo "
#if defined(__arm__)
- "grep ^Features"
+ "grep ^Features"
#else
- "grep ^flags"
+ "grep ^flags"
#endif
- " | awk '{ for (i = 3; i <= NF; ++i) { print $i }; exit }'";
+ " | awk '{ for (i = 3; i <= NF; ++i) { print $i }; exit
}'";
fp = popen (cmd, "re");
if (fp == NULL) {
@@ -522,8 +524,8 @@ cpuinfo_flags (void)
}
while (errno = 0, (len = getline (&flag, &buflen, fp)) != -1) {
- if (len > 0 && flag[len-1] == '\n')
- flag[len-1] = '\0';
+ if (len > 0 && flag[len - 1] == '\n')
+ flag[len - 1] = '\0';
if (STREQ (flag, "acpi"))
ret |= FLAG_ACPI;
diff --git a/p2v/miniexpect.c b/p2v/miniexpect.c
index e1a184c..7b563b8 100644
--- a/p2v/miniexpect.c
+++ b/p2v/miniexpect.c
@@ -106,19 +106,19 @@ mexp_spawnl (const char *file, const char *arg, ...)
argv = malloc (sizeof (char *));
if (argv == NULL)
return NULL;
- argv[0] = (char *) arg;
+ argv[0] = (char *)arg;
va_start (args, arg);
for (i = 1; arg != NULL; ++i) {
arg = va_arg (args, const char *);
- new_argv = realloc (argv, sizeof (char *) * (i+1));
+ new_argv = realloc (argv, sizeof (char *) * (i + 1));
if (new_argv == NULL) {
free (argv);
va_end (args);
return NULL;
}
argv = new_argv;
- argv[i] = (char *) arg;
+ argv[i] = (char *)arg;
}
h = mexp_spawnv (file, argv);
@@ -136,7 +136,7 @@ mexp_spawnv (const char *file, char **argv)
char slave[1024];
pid_t pid = 0;
- fd = posix_openpt (O_RDWR|O_NOCTTY);
+ fd = posix_openpt (O_RDWR | O_NOCTTY);
if (fd == -1)
goto error;
@@ -159,7 +159,7 @@ mexp_spawnv (const char *file, char **argv)
if (pid == -1)
goto error;
- if (pid == 0) { /* Child. */
+ if (pid == 0) { /* Child. */
struct termios terminal_settings;
int slave_fd;
@@ -200,7 +200,7 @@ mexp_spawnv (const char *file, char **argv)
h->pid = pid;
return h;
- error:
+error:
err = errno;
if (fd >= 0)
close (fd);
@@ -213,7 +213,8 @@ mexp_spawnv (const char *file, char **argv)
}
enum mexp_status
-mexp_expect (mexp_h *h, const mexp_regexp *regexps, int *ovector, int ovecsize)
+mexp_expect (mexp_h *h, const mexp_regexp *regexps, int *ovector,
+ int ovecsize)
{
time_t start_t, now_t;
int timeout;
@@ -226,11 +227,13 @@ mexp_expect (mexp_h *h, const mexp_regexp *regexps, int *ovector,
int ovecsize)
if (h->next_match == -1) {
/* Fully clear the buffer, then read. */
clear_buffer (h);
- } else {
+ }
+ else {
/* See the comment in the manual about h->next_match. We have
* some data remaining in the buffer, so begin by matching that.
*/
- memmove (&h->buffer[0], &h->buffer[h->next_match], h->len -
h->next_match);
+ memmove (&h->buffer[0], &h->buffer[h->next_match],
+ h->len - h->next_match);
h->len -= h->next_match;
h->buffer[h->len] = '\0';
h->next_match = -1;
@@ -311,10 +314,8 @@ mexp_expect (mexp_h *h, const mexp_regexp *regexps, int *ovector, int
ovecsize)
for (i = 0; regexps[i].r > 0; ++i) {
int options = regexps[i].options | PCRE_PARTIAL_SOFT;
- r = pcre_exec (regexps[i].re, regexps[i].extra,
- h->buffer, (int)h->len, 0,
- options,
- ovector, ovecsize);
+ r = pcre_exec (regexps[i].re, regexps[i].extra, h->buffer,
+ (int)h->len, 0, options, ovector, ovecsize);
h->pcre_error = r;
if (r >= 0) {
diff --git a/p2v/miniexpect.h b/p2v/miniexpect.h
index 192d180..ae990ff 100644
--- a/p2v/miniexpect.h
+++ b/p2v/miniexpect.h
@@ -80,16 +80,16 @@ struct mexp_regexp {
typedef struct mexp_regexp mexp_regexp;
enum mexp_status {
- MEXP_EOF = 0,
- MEXP_ERROR = -1,
+ MEXP_EOF = 0,
+ MEXP_ERROR = -1,
MEXP_PCRE_ERROR = -2,
- MEXP_TIMEOUT = -3,
+ MEXP_TIMEOUT = -3,
};
-extern int mexp_expect (mexp_h *h, const mexp_regexp *regexps,
- int *ovector, int ovecsize);
+extern int mexp_expect (mexp_h *h, const mexp_regexp *regexps, int *ovector,
+ int ovecsize);
extern int mexp_printf (mexp_h *h, const char *fs, ...)
- __attribute__((format(printf,2,3)));
+ __attribute__((format (printf, 2, 3)));
#endif /* MINIEXPECT_H_ */
diff --git a/p2v/p2v.h b/p2v/p2v.h
index 0123da8..663fc02 100644
--- a/p2v/p2v.h
+++ b/p2v/p2v.h
@@ -100,24 +100,31 @@ extern const char *get_cmdline_key (char **cmdline, const char
*key);
#define CMDLINE_SOURCE_PROC_CMDLINE 2 /* /proc/cmdline */
/* kernel.c */
-extern void kernel_configuration (struct config *, char **cmdline, int cmdline_source);
+extern void kernel_configuration (struct config *, char **cmdline,
+ int cmdline_source);
/* gui.c */
extern void gui_application (struct config *);
/* conversion.c */
-extern int start_conversion (struct config *, void (*notify_ui) (int type, const char
*data));
-#define NOTIFY_LOG_DIR 1 /* location of remote log directory */
-#define NOTIFY_REMOTE_MESSAGE 2 /* log message from remote virt-v2v */
-#define NOTIFY_STATUS 3 /* stage in conversion process */
+extern int start_conversion (struct config *,
+ void (*notify_ui) (int type,
+ const char *data));
+#define NOTIFY_LOG_DIR 1 /* location of remote log directory */
+#define NOTIFY_REMOTE_MESSAGE 2 /* log message from remote virt-v2v */
+#define NOTIFY_STATUS 3 /* stage in conversion process */
extern const char *get_conversion_error (void);
extern void cancel_conversion (void);
extern int conversion_is_running (void);
/* ssh.c */
extern int test_connection (struct config *);
-extern mexp_h *open_data_connection (struct config *, int *local_port, int
*remote_port);
-extern mexp_h *start_remote_connection (struct config *, const char *remote_dir, const
char *libvirt_xml, const char *dmesg);
+extern mexp_h *open_data_connection (struct config *, int *local_port,
+ int *remote_port);
+extern mexp_h *start_remote_connection (struct config *,
+ const char *remote_dir,
+ const char *libvirt_xml,
+ const char *dmesg);
extern const char *get_ssh_error (void);
/* utils.c */
@@ -126,7 +133,8 @@ extern char *get_if_vendor (const char *if_name, int truncate);
extern void wait_network_online (const struct config *);
/* whole-file.c */
-extern int read_whole_file (const char *filename, char **data_r, size_t *size_r);
+extern int read_whole_file (const char *filename, char **data_r,
+ size_t *size_r);
/* virt-v2v version and features (read from remote). */
extern int v2v_major;
diff --git a/p2v/ssh.c b/p2v/ssh.c
index 7158e70..0a41e7b 100644
--- a/p2v/ssh.c
+++ b/p2v/ssh.c
@@ -66,7 +66,7 @@ char **output_drivers = NULL;
static char *ssh_error;
static void set_ssh_error (const char *fs, ...)
- __attribute__((format(printf,1,2)));
+ __attribute__((format (printf, 1, 2)));
static void
set_ssh_error (const char *fs, ...)
@@ -111,30 +111,30 @@ compile_regexps (void)
int offset;
int p;
- /* These regexps are always used for partial matching. In pcre < 8
- * there were limitations on the regexps possible for partial
- * matching, so fail if that is true here. In pcre >= 8, all
- * regexps can be used in a partial match.
- */
-#define CHECK_PARTIAL_OK(pattern, re) \
- do { \
- pcre_fullinfo ((re), NULL, PCRE_INFO_OKPARTIAL, &p); \
- if (p != 1) { \
- fprintf (stderr, "%s: %s:%d: internal error: pattern '%s' cannot be
used for partial matching\n", \
- guestfs_int_program_name, \
- __FILE__, __LINE__, (pattern)); \
- abort (); \
- } \
+/* These regexps are always used for partial matching. In pcre < 8
+ * there were limitations on the regexps possible for partial
+ * matching, so fail if that is true here. In pcre >= 8, all
+ * regexps can be used in a partial match.
+ */
+#define CHECK_PARTIAL_OK(pattern, re) \
+ do { \
+ pcre_fullinfo ((re), NULL, PCRE_INFO_OKPARTIAL, &p); \
+ if (p != 1) { \
+ fprintf (stderr, "%s: %s:%d: internal error: pattern '%s' cannot
" \
+ "be used for partial matching\n", \
+ guestfs_int_program_name, __FILE__, __LINE__, (pattern)); \
+ abort (); \
+ } \
} while (0)
-#define COMPILE(re,pattern,options) \
- do { \
- re = pcre_compile ((pattern), (options), &err, &offset, NULL); \
- if (re == NULL) { \
- ignore_value (write (2, err, strlen (err))); \
- abort (); \
- } \
- CHECK_PARTIAL_OK ((pattern), re); \
+#define COMPILE(re, pattern, options) \
+ do { \
+ re = pcre_compile ((pattern), (options), &err, &offset, NULL); \
+ if (re == NULL) { \
+ ignore_value (write (2, err, strlen (err))); \
+ abort (); \
+ } \
+ CHECK_PARTIAL_OK ((pattern), re); \
} while (0)
COMPILE (password_re, "assword", 0);
@@ -142,10 +142,10 @@ compile_regexps (void)
* start_ssh function below.
*/
COMPILE (prompt_re,
- "###((?:[0123456789abcdefghijklmnopqrstuvwxyz]){8})### ", 0);
+ "###((?:[0123456789abcdefghijklmnopqrstuvwxyz]){8})### ", 0);
COMPILE (version_re,
"virt-v2v ([1-9](?:\\d)*)\\.([1-9](?:\\d)*)\\.(0|[1-9](?:\\d)*)",
- 0);
+ 0);
COMPILE (feature_libguestfs_rewrite_re, "libguestfs-rewrite", 0);
COMPILE (feature_input_re, "input:((?:\\w)*)", 0);
COMPILE (feature_output_re, "output:((?:\\w)*)", 0);
@@ -185,21 +185,34 @@ curl_download (const char *url, const char *local_file)
len = strlen (url);
for (i = 0; i < len; ++i) {
switch (url[i]) {
- case '\\': fprintf (fp, "\\\\"); break;
- case '"': fprintf (fp, "\\\""); break;
- case '\t': fprintf (fp, "\\t"); break;
- case '\n': fprintf (fp, "\\n"); break;
- case '\r': fprintf (fp, "\\r"); break;
- case '\v': fprintf (fp, "\\v"); break;
- default: fputc (url[i], fp);
+ case '\\':
+ fprintf (fp, "\\\\");
+ break;
+ case '"':
+ fprintf (fp, "\\\"");
+ break;
+ case '\t':
+ fprintf (fp, "\\t");
+ break;
+ case '\n':
+ fprintf (fp, "\\n");
+ break;
+ case '\r':
+ fprintf (fp, "\\r");
+ break;
+ case '\v':
+ fprintf (fp, "\\v");
+ break;
+ default:
+ fputc (url[i], fp);
}
}
fprintf (fp, "\"\n");
fclose (fp);
/* Run curl to download the URL to a file. */
- if (asprintf (&curl_cmd, "curl -f -o %s -K %s",
- local_file, curl_config_file) == -1)
+ if (asprintf (&curl_cmd, "curl -f -o %s -K %s", local_file,
+ curl_config_file) == -1)
error (EXIT_FAILURE, errno, "asprintf");
r = system (curl_cmd);
@@ -230,8 +243,7 @@ cache_ssh_identity (struct config *config)
int fd;
/* If it doesn't need downloading, return. */
- if (config->identity_url == NULL ||
- !config->identity_file_needs_update)
+ if (config->identity_url == NULL || !config->identity_file_needs_update)
return 0;
/* Generate a random filename. */
@@ -291,12 +303,12 @@ start_ssh (struct config *config, char **extra_args, int
wait_prompt)
j = 0;
args[j++] = "ssh";
- args[j++] = "-p"; /* Port. */
+ args[j++] = "-p"; /* Port. */
snprintf (port_str, sizeof port_str, "%d", config->port);
args[j++] = port_str;
- args[j++] = "-l"; /* Username. */
+ args[j++] = "-l"; /* Username. */
args[j++] = config->username ? config->username : "root";
- args[j++] = "-o"; /* Host key will always be novel. */
+ args[j++] = "-o"; /* Host key will always be novel. */
args[j++] = "StrictHostKeyChecking=no";
if (using_password_auth) {
/* Only use password authentication. */
@@ -314,23 +326,21 @@ start_ssh (struct config *config, char **extra_args, int
wait_prompt)
for (i = 0; extra_args[i] != NULL; ++i)
args[j++] = extra_args[i];
}
- args[j++] = config->server; /* Conversion server. */
+ args[j++] = config->server; /* Conversion server. */
args[j++] = NULL;
assert (j == nr_args);
- h = mexp_spawnv ("ssh", (char **) args);
+ h = mexp_spawnv ("ssh", (char **)args);
if (h == NULL)
return NULL;
- if (using_password_auth &&
- config->password && strlen (config->password) > 0) {
+ if (using_password_auth && config->password &&
+ strlen (config->password) > 0) {
/* Wait for the password prompt. */
- switch (mexp_expect (h,
- (mexp_regexp[]) {
- { 100, .re = password_re },
- { 0 }
- }, ovector, ovecsize)) {
- case 100: /* Got password prompt. */
+ switch (
+ mexp_expect (h, (mexp_regexp[]){ { 100, .re = password_re }, { 0 } },
+ ovector, ovecsize)) {
+ case 100: /* Got password prompt. */
if (mexp_printf (h, "%s\n", config->password) == -1) {
set_ssh_error ("mexp_printf: %m");
mexp_close (h);
@@ -393,18 +403,17 @@ start_ssh (struct config *config, char **extra_args, int
wait_prompt)
return NULL;
}
- /* Wait for the prompt. */
+ /* Wait for the prompt. */
wait_again:
- switch (mexp_expect (h,
- (mexp_regexp[]) {
- { 100, .re = password_re },
- { 101, .re = prompt_re },
- { 0 }
- }, ovector, ovecsize)) {
- case 100: /* Got password prompt unexpectedly. */
+ switch (mexp_expect (h, (mexp_regexp[]){ { 100, .re = password_re },
+ { 101, .re = prompt_re },
+ { 0 } },
+ ovector, ovecsize)) {
+ case 100: /* Got password prompt unexpectedly. */
if (mexp_printf (h, "%s\n", config->password) == -1) {
mexp_close (h);
- set_ssh_error ("unexpected password prompt: probably the password supplied
is wrong");
+ set_ssh_error ("unexpected password prompt: probably the password "
+ "supplied is wrong");
return NULL;
}
break;
@@ -413,8 +422,8 @@ start_ssh (struct config *config, char **extra_args, int wait_prompt)
/* Got a prompt. However it might be an earlier prompt. If it
* doesn't match the PS1 string we sent, then repeat the expect.
*/
- r = pcre_get_substring (h->buffer, ovector,
- mexp_get_pcre_error (h), 1, &matched);
+ r = pcre_get_substring (h->buffer, ovector, mexp_get_pcre_error (h),
+ 1, &matched);
if (r < 0)
error (EXIT_FAILURE, 0, "PCRE error reading substring (%d)", r);
r = STREQ (magic, matched);
@@ -447,10 +456,11 @@ start_ssh (struct config *config, char **extra_args, int
wait_prompt)
}
mexp_close (h);
- set_ssh_error ("failed to synchronize with remote shell after 60 seconds");
+ set_ssh_error (
+ "failed to synchronize with remote shell after 60 seconds");
return NULL;
- got_prompt:
+got_prompt:
mexp_set_timeout_ms (h, saved_timeout);
return h;
@@ -464,7 +474,8 @@ int
test_connection (struct config *config)
{
mexp_h *h;
- CLEANUP_FREE char *major_str = NULL, *minor_str = NULL, *release_str = NULL;
+ CLEANUP_FREE char *major_str = NULL, *minor_str = NULL,
+ *release_str = NULL;
int feature_libguestfs_rewrite = 0;
int status;
const int ovecsize = 12;
@@ -479,11 +490,11 @@ test_connection (struct config *config)
*/
v2v_major = v2v_minor = v2v_release = 0;
- /* Send 'virt-v2v --version' command and hope we get back a version string.
+ /* Send 'virt-v2v --version' command and hope we get back a version
+ * string.
* Note old virt-v2v did not understand -V option.
*/
- if (mexp_printf (h,
- "%svirt-v2v --version\n",
+ if (mexp_printf (h, "%svirt-v2v --version\n",
config->sudo ? "sudo " : "") == -1) {
set_ssh_error ("mexp_printf: %m");
mexp_close (h);
@@ -491,16 +502,15 @@ test_connection (struct config *config)
}
for (;;) {
- switch (mexp_expect (h,
- (mexp_regexp[]) {
- { 100, .re = version_re },
- { 101, .re = prompt_re },
- { 0 }
- }, ovector, ovecsize)) {
- case 100: /* Got version string. */
- major_str = strndup (&h->buffer[ovector[2]], ovector[3]-ovector[2]);
- minor_str = strndup (&h->buffer[ovector[4]], ovector[5]-ovector[4]);
- release_str = strndup (&h->buffer[ovector[6]], ovector[7]-ovector[6]);
+ switch (mexp_expect (h, (mexp_regexp[]){ { 100, .re = version_re },
+ { 101, .re = prompt_re },
+ { 0 } },
+ ovector, ovecsize)) {
+ case 100: /* Got version string. */
+ major_str = strndup (&h->buffer[ovector[2]], ovector[3] - ovector[2]);
+ minor_str = strndup (&h->buffer[ovector[4]], ovector[5] - ovector[4]);
+ release_str =
+ strndup (&h->buffer[ovector[6]], ovector[7] - ovector[6]);
sscanf (major_str, "%d", &v2v_major);
sscanf (minor_str, "%d", &v2v_minor);
sscanf (release_str, "%d", &v2v_release);
@@ -518,12 +528,13 @@ test_connection (struct config *config)
}
break;
- case 101: /* Got the prompt. */
+ case 101: /* Got the prompt. */
goto end_of_version;
case MEXP_EOF:
mexp_close (h);
- set_ssh_error ("unexpected end of file waiting virt-v2v --version
output");
+ set_ssh_error (
+ "unexpected end of file waiting virt-v2v --version output");
return -1;
case MEXP_TIMEOUT:
@@ -542,7 +553,7 @@ test_connection (struct config *config)
return -1;
}
}
- end_of_version:
+end_of_version:
/* Got the prompt but no version number. */
if (v2v_major == 0) {
@@ -556,7 +567,8 @@ test_connection (struct config *config)
if (v2v_major != 1) {
mexp_close (h);
set_ssh_error ("virt-v2v major version is not 1 (major = %d), "
- "this version of virt-p2v is not compatible", v2v_major);
+ "this version of virt-p2v is not compatible",
+ v2v_major);
return -1;
}
@@ -569,7 +581,8 @@ test_connection (struct config *config)
mexp_close (h);
set_ssh_error ("virt-v2v version is < 1.28 (major = %d, minor = %d), "
"you must upgrade to virt-v2v >= 1.28 on "
- "the conversion server", v2v_major, v2v_minor);
+ "the conversion server",
+ v2v_major, v2v_minor);
return -1;
}
@@ -589,36 +602,36 @@ test_connection (struct config *config)
}
for (;;) {
- switch (mexp_expect (h,
- (mexp_regexp[]) {
- { 100, .re = feature_libguestfs_rewrite_re },
- { 101, .re = feature_input_re },
- { 102, .re = feature_output_re },
- { 103, .re = prompt_re },
- { 0 }
- }, ovector, ovecsize)) {
- case 100: /* libguestfs-rewrite. */
+ switch (mexp_expect (
+ h, (mexp_regexp[]){ { 100, .re = feature_libguestfs_rewrite_re },
+ { 101, .re = feature_input_re },
+ { 102, .re = feature_output_re },
+ { 103, .re = prompt_re },
+ { 0 } },
+ ovector, ovecsize)) {
+ case 100: /* libguestfs-rewrite. */
feature_libguestfs_rewrite = 1;
break;
case 101:
/* input:<driver-name> corresponds to an -i option in virt-v2v. */
add_input_driver (&h->buffer[ovector[2]],
- (size_t) (ovector[3]-ovector[2]));
+ (size_t) (ovector[3] - ovector[2]));
break;
case 102:
/* output:<driver-name> corresponds to an -o option in virt-v2v. */
add_output_driver (&h->buffer[ovector[2]],
- (size_t) (ovector[3]-ovector[2]));
+ (size_t) (ovector[3] - ovector[2]));
break;
- case 103: /* Got prompt, so end of output. */
+ case 103: /* Got prompt, so end of output. */
goto end_of_machine_readable;
case MEXP_EOF:
mexp_close (h);
- set_ssh_error ("unexpected end of file waiting virt-v2v --machine-readable
output");
+ set_ssh_error ("unexpected end of file waiting virt-v2v "
+ "--machine-readable output");
return -1;
case MEXP_TIMEOUT:
@@ -637,7 +650,7 @@ test_connection (struct config *config)
return -1;
}
}
- end_of_machine_readable:
+end_of_machine_readable:
if (!feature_libguestfs_rewrite) {
mexp_close (h);
@@ -680,7 +693,8 @@ test_connection (struct config *config)
if (WIFSIGNALED (status) && WTERMSIG (status) == SIGHUP)
return 0; /* not an error */
if (!WIFEXITED (status) || WEXITSTATUS (status) != 0) {
- set_ssh_error ("unexpected close status from ssh subprocess (%d)",
status);
+ set_ssh_error ("unexpected close status from ssh subprocess (%d)",
+ status);
return -1;
}
return 0;
@@ -698,18 +712,18 @@ add_option (const char *type, char ***drivers, const char *name,
size_t len)
n++;
- *drivers = realloc (*drivers, (n+1) * sizeof (char *));
+ *drivers = realloc (*drivers, (n + 1) * sizeof (char *));
if (*drivers == NULL)
error (EXIT_FAILURE, errno, "malloc");
- (*drivers)[n-1] = strndup (name, len);
- if ((*drivers)[n-1] == NULL)
+ (*drivers)[n - 1] = strndup (name, len);
+ if ((*drivers)[n - 1] == NULL)
error (EXIT_FAILURE, errno, "strndup");
(*drivers)[n] = NULL;
#if DEBUG_STDERR
fprintf (stderr, "%s: remote virt-v2v supports %s driver %s\n",
- guestfs_int_program_name, type, (*drivers)[n-1]);
+ guestfs_int_program_name, type, (*drivers)[n - 1]);
#endif
}
@@ -731,34 +745,30 @@ add_output_driver (const char *name, size_t len)
static int nbd_local_port = 50123;
mexp_h *
-open_data_connection (struct config *config, int *local_port, int *remote_port)
+open_data_connection (struct config *config, int *local_port,
+ int *remote_port)
{
mexp_h *h;
char remote_arg[32];
- const char *extra_args[] = {
- "-R", remote_arg,
- "-N",
- NULL
- };
+ const char *extra_args[] = { "-R", remote_arg, "-N", NULL };
CLEANUP_FREE char *port_str = NULL;
const int ovecsize = 12;
int ovector[ovecsize];
- snprintf (remote_arg, sizeof remote_arg, "0:localhost:%d", nbd_local_port);
+ snprintf (remote_arg, sizeof remote_arg, "0:localhost:%d",
+ nbd_local_port);
*local_port = nbd_local_port;
nbd_local_port++;
- h = start_ssh (config, (char **) extra_args, 0);
+ h = start_ssh (config, (char **)extra_args, 0);
if (h == NULL)
return NULL;
switch (mexp_expect (h,
- (mexp_regexp[]) {
- { 100, .re = portfwd_re },
- { 0 }
- }, ovector, ovecsize)) {
- case 100: /* Ephemeral port. */
- port_str = strndup (&h->buffer[ovector[2]], ovector[3]-ovector[2]);
+ (mexp_regexp[]){ { 100, .re = portfwd_re }, { 0 } },
+ ovector, ovecsize)) {
+ case 100: /* Ephemeral port. */
+ port_str = strndup (&h->buffer[ovector[2]], ovector[3] - ovector[2]);
if (port_str == NULL) {
set_ssh_error ("not enough memory for strndup");
mexp_close (h);
@@ -803,11 +813,9 @@ wait_for_prompt (mexp_h *h)
int ovector[ovecsize];
switch (mexp_expect (h,
- (mexp_regexp[]) {
- { 100, .re = prompt_re },
- { 0 }
- }, ovector, ovecsize)) {
- case 100: /* Got the prompt. */
+ (mexp_regexp[]){ { 100, .re = prompt_re }, { 0 } },
+ ovector, ovecsize)) {
+ case 100: /* Got the prompt. */
return 0;
case MEXP_EOF:
@@ -831,9 +839,8 @@ wait_for_prompt (mexp_h *h)
}
mexp_h *
-start_remote_connection (struct config *config,
- const char *remote_dir, const char *libvirt_xml,
- const char *dmesg)
+start_remote_connection (struct config *config, const char *remote_dir,
+ const char *libvirt_xml, const char *dmesg)
{
mexp_h *h;
char magic[9];
@@ -856,9 +863,10 @@ start_remote_connection (struct config *config,
if (wait_for_prompt (h) == -1)
goto error;
- /* Write some useful config information to files in the remote directory. */
- if (mexp_printf (h, "echo '%s' > %s/name\n",
- config->guestname, remote_dir) == -1) {
+ /* Write some useful config information to files in the remote directory.
+ */
+ if (mexp_printf (h, "echo '%s' > %s/name\n",
config->guestname,
+ remote_dir) == -1) {
set_ssh_error ("mexp_printf: %m");
goto error;
}
@@ -875,13 +883,10 @@ start_remote_connection (struct config *config,
goto error;
/* Upload the guest libvirt XML to the remote directory. */
- if (mexp_printf (h,
- "cat > '%s/physical.xml' <<
'__%s__'\n"
- "%s"
- "__%s__\n",
- remote_dir, magic,
- libvirt_xml,
- magic) == -1) {
+ if (mexp_printf (h, "cat > '%s/physical.xml' <<
'__%s__'\n"
+ "%s"
+ "__%s__\n",
+ remote_dir, magic, libvirt_xml, magic) == -1) {
set_ssh_error ("mexp_printf: %m");
goto error;
}
@@ -891,14 +896,11 @@ start_remote_connection (struct config *config,
if (dmesg != NULL) {
/* Upload the physical host dmesg to the remote directory. */
- if (mexp_printf (h,
- "cat > '%s/dmesg' << '__%s__'\n"
- "%s"
- "\n"
- "__%s__\n",
- remote_dir, magic,
- dmesg,
- magic) == -1) {
+ if (mexp_printf (h, "cat > '%s/dmesg' <<
'__%s__'\n"
+ "%s"
+ "\n"
+ "__%s__\n",
+ remote_dir, magic, dmesg, magic) == -1) {
set_ssh_error ("mexp_printf: %m");
goto error;
}
@@ -909,7 +911,7 @@ start_remote_connection (struct config *config,
return h;
- error:
+error:
mexp_close (h);
return NULL;
}
diff --git a/p2v/utils.c b/p2v/utils.c
index 183e406..cf064a9 100644
--- a/p2v/utils.c
+++ b/p2v/utils.c
@@ -32,7 +32,7 @@
#include "p2v.h"
-#define CHOMP(line,len) \
+#define CHOMP(line, len) \
do { \
if ((len) > 0 && (line)[(len)-1] == '\n') { \
(line)[(len)-1] = '\0'; \
@@ -121,7 +121,7 @@ get_if_vendor (const char *if_name, int truncate)
n--;
}
- memmove (&line[0], &line[i], n+1 /* copy trailing \0 */);
+ memmove (&line[0], &line[i], n + 1 /* copy trailing \0 */);
/* Truncate? */
if (truncate > 0 && n > truncate)
diff --git a/p2v/whole-file.c b/p2v/whole-file.c
index 90df716..d56018a 100644
--- a/p2v/whole-file.c
+++ b/p2v/whole-file.c
@@ -40,7 +40,7 @@ read_whole_file (const char *filename, char **data_r, size_t *size_r)
ssize_t r;
struct stat statbuf;
- fd = open (filename, O_RDONLY|O_CLOEXEC);
+ fd = open (filename, O_RDONLY | O_CLOEXEC);
if (fd == -1) {
fprintf (stderr, "open: %s: %m\n", filename);
return -1;
diff --git a/python/guestfs-py-byhand.c b/python/guestfs-py-byhand.c
index b200dc6..973bf5a 100644
--- a/python/guestfs-py-byhand.c
+++ b/python/guestfs-py-byhand.c
@@ -42,7 +42,7 @@ guestfs_int_py_create (PyObject *self, PyObject *args)
guestfs_h *g;
unsigned flags;
- if (!PyArg_ParseTuple (args, (char *) "I:guestfs_create", &flags))
+ if (!PyArg_ParseTuple (args, (char *)"I:guestfs_create", &flags))
return NULL;
g = guestfs_create_flags (flags);
if (g == NULL) {
@@ -66,7 +66,7 @@ guestfs_int_py_close (PyObject *self, PyObject *args)
size_t i, len;
PyObject **callbacks;
- if (!PyArg_ParseTuple (args, (char *) "O:guestfs_close", &py_g))
+ if (!PyArg_ParseTuple (args, (char *)"O:guestfs_close", &py_g))
return NULL;
g = get_handle (py_g);
@@ -94,13 +94,9 @@ guestfs_int_py_close (PyObject *self, PyObject *args)
/*
http://docs.python.org/release/2.5.2/ext/callingPython.html */
static void
-guestfs_int_py_event_callback_wrapper (guestfs_h *g,
- void *callback,
- uint64_t event,
- int event_handle,
- int flags,
- const char *buf, size_t buf_len,
- const uint64_t *array, size_t array_len)
+guestfs_int_py_event_callback_wrapper (
+ guestfs_h *g, void *callback, uint64_t event, int event_handle, int flags,
+ const char *buf, size_t buf_len, const uint64_t *array, size_t array_len)
{
PyGILState_STATE py_save = PyGILState_UNLOCKED;
PyObject *py_callback = callback;
@@ -117,9 +113,8 @@ guestfs_int_py_event_callback_wrapper (guestfs_h *g,
}
/* XXX As with Perl we don't pass the guestfs_h handle here. */
- args = Py_BuildValue ("(Kis#O)",
- (unsigned PY_LONG_LONG) event, event_handle,
- buf, buf_len, py_array);
+ args = Py_BuildValue ("(Kis#O)", (unsigned PY_LONG_LONG)event,
+ event_handle, buf, buf_len, py_array);
if (PyEval_ThreadsInitialized ())
py_save = PyGILState_Ensure ();
@@ -149,14 +144,13 @@ guestfs_int_py_set_event_callback (PyObject *self, PyObject *args)
PyObject *py_eh;
char key[64];
- if (!PyArg_ParseTuple (args, (char *) "OOK:guestfs_set_event_callback",
+ if (!PyArg_ParseTuple (args, (char *)"OOK:guestfs_set_event_callback",
&py_g, &py_callback, &events))
return NULL;
if (!PyCallable_Check (py_callback)) {
- PyErr_SetString (PyExc_TypeError,
- "callback parameter is not callable "
- "(eg. lambda or function)");
+ PyErr_SetString (PyExc_TypeError, "callback parameter is not callable "
+ "(eg. lambda or function)");
return NULL;
}
@@ -179,7 +173,7 @@ guestfs_int_py_set_event_callback (PyObject *self, PyObject *args)
snprintf (key, sizeof key, "_python_event_%d", eh);
guestfs_set_private (g, key, py_callback);
- py_eh = PyLong_FromLong ((long) eh);
+ py_eh = PyLong_FromLong ((long)eh);
return py_eh;
}
@@ -192,7 +186,7 @@ guestfs_int_py_delete_event_callback (PyObject *self, PyObject *args)
PyObject *py_callback;
char key[64];
- if (!PyArg_ParseTuple (args, (char *) "Oi:guestfs_delete_event_callback",
+ if (!PyArg_ParseTuple (args, (char *)"Oi:guestfs_delete_event_callback",
&py_g, &eh))
return NULL;
g = get_handle (py_g);
@@ -216,7 +210,7 @@ guestfs_int_py_event_to_string (PyObject *self, PyObject *args)
char *str;
PyObject *py_r;
- if (!PyArg_ParseTuple (args, (char *) "K", &events))
+ if (!PyArg_ParseTuple (args, (char *)"K", &events))
return NULL;
str = guestfs_event_to_string (events);
diff --git a/python/guestfs-py.h b/python/guestfs-py.h
index da5f483..54fcfbd 100644
--- a/python/guestfs-py.h
+++ b/python/guestfs-py.h
@@ -30,8 +30,7 @@ typedef int Py_ssize_t;
#ifndef HAVE_PYCAPSULE_NEW
typedef struct {
- PyObject_HEAD
- guestfs_h *g;
+ PyObject_HEAD guestfs_h *g;
} Pyguestfs_Object;
#endif
@@ -41,9 +40,9 @@ get_handle (PyObject *obj)
assert (obj);
assert (obj != Py_None);
#ifndef HAVE_PYCAPSULE_NEW
- return ((Pyguestfs_Object *) obj)->g;
+ return ((Pyguestfs_Object *)obj)->g;
#else
- return (guestfs_h*) PyCapsule_GetPointer(obj, "guestfs_h");
+ return (guestfs_h *)PyCapsule_GetPointer (obj, "guestfs_h");
#endif
}
@@ -52,17 +51,20 @@ put_handle (guestfs_h *g)
{
assert (g);
#ifndef HAVE_PYCAPSULE_NEW
- return
- PyCObject_FromVoidPtrAndDesc ((void *) g, (char *) "guestfs_h", NULL);
+ return PyCObject_FromVoidPtrAndDesc ((void *)g, (char *)"guestfs_h",
+ NULL);
#else
- return PyCapsule_New ((void *) g, "guestfs_h", NULL);
+ return PyCapsule_New ((void *)g, "guestfs_h", NULL);
#endif
}
extern PyObject *guestfs_int_py_create (PyObject *self, PyObject *args);
extern PyObject *guestfs_int_py_close (PyObject *self, PyObject *args);
-extern PyObject *guestfs_int_py_set_event_callback (PyObject *self, PyObject *args);
-extern PyObject *guestfs_int_py_delete_event_callback (PyObject *self, PyObject *args);
-extern PyObject *guestfs_int_py_event_to_string (PyObject *self, PyObject *args);
+extern PyObject *guestfs_int_py_set_event_callback (PyObject *self,
+ PyObject *args);
+extern PyObject *guestfs_int_py_delete_event_callback (PyObject *self,
+ PyObject *args);
+extern PyObject *guestfs_int_py_event_to_string (PyObject *self,
+ PyObject *args);
#endif /* guestfs_py_h */
diff --git a/rescue/rescue.c b/rescue/rescue.c
index c46c775..8fd917b 100644
--- a/rescue/rescue.c
+++ b/rescue/rescue.c
@@ -57,32 +57,33 @@ usage (int status)
fprintf (stderr, _("Try `%s --help' for more information.\n"),
guestfs_int_program_name);
else {
- printf (_("%s: Run a rescue shell on a virtual machine\n"
- "Copyright (C) 2009-2016 Red Hat Inc.\n"
- "Usage:\n"
- " %s [--options] -d domname\n"
- " %s [--options] -a disk.img [-a disk.img ...]\n"
- "Options:\n"
- " -a|--add image Add image\n"
- " --append kernelopts Append kernel options\n"
- " -c|--connect uri Specify libvirt URI for -d option\n"
- " -d|--domain guest Add disks from libvirt guest\n"
- " --format[=raw|..] Force disk format for -a option\n"
- " --help Display brief help\n"
- " -m|--memsize MB Set memory size in megabytes\n"
- " --network Enable network\n"
- " -r|--ro Access read-only\n"
- " --scratch[=N] Add scratch disk(s)\n"
- " --selinux Enable SELinux\n"
- " --smp N Enable SMP with N >= 2 virtual
CPUs\n"
- " --suggest Suggest mount commands for this guest\n"
- " -v|--verbose Verbose messages\n"
- " -V|--version Display version and exit\n"
- " -w|--rw Mount read-write\n"
- " -x Trace libguestfs API calls\n"
- "For more information, see the manpage %s(1).\n"),
- guestfs_int_program_name, guestfs_int_program_name,
- guestfs_int_program_name, guestfs_int_program_name);
+ printf (
+ _("%s: Run a rescue shell on a virtual machine\n"
+ "Copyright (C) 2009-2016 Red Hat Inc.\n"
+ "Usage:\n"
+ " %s [--options] -d domname\n"
+ " %s [--options] -a disk.img [-a disk.img ...]\n"
+ "Options:\n"
+ " -a|--add image Add image\n"
+ " --append kernelopts Append kernel options\n"
+ " -c|--connect uri Specify libvirt URI for -d option\n"
+ " -d|--domain guest Add disks from libvirt guest\n"
+ " --format[=raw|..] Force disk format for -a option\n"
+ " --help Display brief help\n"
+ " -m|--memsize MB Set memory size in megabytes\n"
+ " --network Enable network\n"
+ " -r|--ro Access read-only\n"
+ " --scratch[=N] Add scratch disk(s)\n"
+ " --selinux Enable SELinux\n"
+ " --smp N Enable SMP with N >= 2 virtual CPUs\n"
+ " --suggest Suggest mount commands for this guest\n"
+ " -v|--verbose Verbose messages\n"
+ " -V|--version Display version and exit\n"
+ " -w|--rw Mount read-write\n"
+ " -x Trace libguestfs API calls\n"
+ "For more information, see the manpage %s(1).\n"),
+ guestfs_int_program_name, guestfs_int_program_name,
+ guestfs_int_program_name, guestfs_int_program_name);
}
exit (status);
}
@@ -138,10 +139,11 @@ main (int argc, char *argv[])
for (;;) {
c = getopt_long (argc, argv, options, long_options, &option_index);
- if (c == -1) break;
+ if (c == -1)
+ break;
switch (c) {
- case 0: /* options which are long only */
+ case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "long-options"))
display_long_options (long_options);
else if (STREQ (long_options[option_index].name, "short-options"))
@@ -149,22 +151,28 @@ main (int argc, char *argv[])
else if (STREQ (long_options[option_index].name, "selinux")) {
if (guestfs_set_selinux (g, 1) == -1)
exit (EXIT_FAILURE);
- } else if (STREQ (long_options[option_index].name, "append")) {
+ }
+ else if (STREQ (long_options[option_index].name, "append")) {
append = optarg;
- } else if (STREQ (long_options[option_index].name, "network")) {
+ }
+ else if (STREQ (long_options[option_index].name, "network")) {
network = 1;
- } else if (STREQ (long_options[option_index].name, "format")) {
+ }
+ else if (STREQ (long_options[option_index].name, "format")) {
OPTION_format;
- } else if (STREQ (long_options[option_index].name, "smp")) {
+ }
+ else if (STREQ (long_options[option_index].name, "smp")) {
if (sscanf (optarg, "%d", &smp) != 1)
error (EXIT_FAILURE, 0,
_("could not parse --smp parameter '%s'"), optarg);
if (smp < 1)
- error (EXIT_FAILURE, 0,
- _("--smp parameter '%s' should be >= 1"), optarg);
- } else if (STREQ (long_options[option_index].name, "suggest")) {
+ error (EXIT_FAILURE, 0, _("--smp parameter '%s' should be >=
1"),
+ optarg);
+ }
+ else if (STREQ (long_options[option_index].name, "suggest")) {
suggest = 1;
- } else if (STREQ (long_options[option_index].name, "scratch")) {
+ }
+ else if (STREQ (long_options[option_index].name, "scratch")) {
if (!optarg || STREQ (optarg, ""))
add_scratch_disks (1, &drvs);
else {
@@ -177,9 +185,9 @@ main (int argc, char *argv[])
_("--scratch parameter '%s' should be >= 1"),
optarg);
add_scratch_disks (n, &drvs);
}
- } else
- error (EXIT_FAILURE, 0,
- _("unknown long option: %s (%d)"),
+ }
+ else
+ error (EXIT_FAILURE, 0, _("unknown long option: %s (%d)"),
long_options[option_index].name, option_index);
break;
@@ -197,8 +205,8 @@ main (int argc, char *argv[])
case 'm':
if (sscanf (optarg, "%d", &memsize) != 1)
- error (EXIT_FAILURE, 0,
- _("could not parse memory size '%s'"), optarg);
+ error (EXIT_FAILURE, 0, _("could not parse memory size '%s'"),
+ optarg);
break;
case 'r':
@@ -245,7 +253,8 @@ main (int argc, char *argv[])
error (EXIT_FAILURE, errno, "strdup");
drv->next = drvs;
drvs = drv;
- } else { /* simulate -d option */
+ }
+ else { /* simulate -d option */
drv = calloc (1, sizeof (struct drv));
if (!drv)
error (EXIT_FAILURE, errno, "calloc");
@@ -294,10 +303,11 @@ main (int argc, char *argv[])
*/
CLEANUP_FREE char *backend = guestfs_get_backend (g);
if (backend) {
- if (STREQ (backend, "libvirt") ||
- STRPREFIX (backend, "libvirt:")) {
- fprintf (stderr, _("%s: warning: virt-rescue doesn't work with the
libvirt backend\n"
- "at the moment. As a workaround, forcing backend =
'direct'.\n"),
+ if (STREQ (backend, "libvirt") || STRPREFIX (backend,
"libvirt:")) {
+ fprintf (stderr, _("%s: warning: virt-rescue doesn't work with "
+ "the libvirt backend\n"
+ "at the moment. As a workaround, forcing "
+ "backend = 'direct'.\n"),
guestfs_int_program_name);
if (guestfs_set_backend (g, "direct") == -1)
exit (EXIT_FAILURE);
@@ -320,9 +330,8 @@ main (int argc, char *argv[])
/* Kernel command line must include guestfs_rescue=1 (see
* appliance/init) as well as other options.
*/
- CLEANUP_FREE char *append_full = xasprintf ("guestfs_rescue=1%s%s",
- append ? " " : "",
- append ? append : "");
+ CLEANUP_FREE char *append_full = xasprintf (
+ "guestfs_rescue=1%s%s", append ? " " : "", append ?
append : "");
if (guestfs_set_append (g, append_full) == -1)
exit (EXIT_FAILURE);
}
@@ -354,8 +363,8 @@ static void suggest_filesystems (void);
static int
compare_keys_len (const void *p1, const void *p2)
{
- const char *key1 = * (char * const *) p1;
- const char *key2 = * (char * const *) p2;
+ const char *key1 = *(char *const *)p1;
+ const char *key2 = *(char *const *)p2;
return strlen (key1) - strlen (key2);
}
@@ -396,8 +405,10 @@ do_suggestion (struct drv *drvs)
return;
}
- printf (_("This disk contains one or more operating systems. You can use these
mount\n"
- "commands in virt-rescue (at the ><rescue> prompt) to mount the
filesystems.\n\n"));
+ printf (_("This disk contains one or more operating systems. You can "
+ "use these mount\n"
+ "commands in virt-rescue (at the ><rescue> prompt) to mount
"
+ "the filesystems.\n\n"));
for (i = 0; roots[i] != NULL; ++i) {
CLEANUP_FREE_STRING_LIST char **mps = NULL;
@@ -414,9 +425,8 @@ do_suggestion (struct drv *drvs)
printf (_("# %s is the root of a %s operating system\n"
"# type: %s, distro: %s, version: %d.%d\n"
"# %s\n\n"),
- roots[i], type ? : "unknown",
- type ? : "unknown", distro ? : "unknown", major, minor,
- product_name ? : "");
+ roots[i], type ?: "unknown", type ?: "unknown",
+ distro ?: "unknown", major, minor, product_name ?: "");
mps = guestfs_inspect_get_mountpoints (g, roots[i]);
if (mps == NULL)
@@ -429,7 +439,7 @@ do_suggestion (struct drv *drvs)
compare_keys_len);
for (j = 0; mps[j] != NULL; j += 2)
- printf ("mount %s /sysroot%s\n", mps[j+1], mps[j]);
+ printf ("mount %s /sysroot%s\n", mps[j + 1], mps[j]);
/* If it's Linux, print the bind-mounts and a chroot command. */
if (type && STREQ (type, "linux")) {
@@ -458,33 +468,38 @@ suggest_filesystems (void)
if (fses == NULL)
exit (EXIT_FAILURE);
- /* Count how many are not swap or unknown. Possibly we should try
- * mounting to see which are mountable, but that has a high
- * probability of breaking.
- */
+/* Count how many are not swap or unknown. Possibly we should try
+ * mounting to see which are mountable, but that has a high
+ * probability of breaking.
+ */
#define TEST_MOUNTABLE(fs) STRNEQ ((fs), "swap") && STRNEQ ((fs),
"unknown")
count = 0;
for (i = 0; fses[i] != NULL; i += 2) {
- if (TEST_MOUNTABLE (fses[i+1]))
+ if (TEST_MOUNTABLE (fses[i + 1]))
count++;
}
if (count == 0) {
- printf (_("This disk contains no mountable filesystems that we
recognize.\n\n"
- "However you can still use virt-rescue on the disk image, to try to
mount\n"
- "filesystems that are not recognized by libguestfs, or to create
partitions,\n"
- "logical volumes and filesystems on a blank disk.\n"));
+ printf (_ (
+ "This disk contains no mountable filesystems that we recognize.\n\n"
+ "However you can still use virt-rescue on the disk image, to try to "
+ "mount\n"
+ "filesystems that are not recognized by libguestfs, or to create "
+ "partitions,\n"
+ "logical volumes and filesystems on a blank disk.\n"));
return;
}
- printf (_("This disk contains one or more filesystems, but we don't recognize
any\n"
- "operating system. You can use these mount commands in virt-rescue (at
the\n"
+ printf (_("This disk contains one or more filesystems, but we don't "
+ "recognize any\n"
+ "operating system. You can use these mount commands in "
+ "virt-rescue (at the\n"
"><rescue> prompt) to mount these filesystems.\n\n"));
for (i = 0; fses[i] != NULL; i += 2) {
- printf (_("# %s has type '%s'\n"), fses[i], fses[i+1]);
+ printf (_("# %s has type '%s'\n"), fses[i], fses[i + 1]);
- if (TEST_MOUNTABLE (fses[i+1]))
+ if (TEST_MOUNTABLE (fses[i + 1]))
printf ("mount %s /sysroot\n", fses[i]);
printf ("\n");
diff --git a/sparsify/statvfs-c.c b/sparsify/statvfs-c.c
index 76bff0b..9431d8b 100644
--- a/sparsify/statvfs-c.c
+++ b/sparsify/statvfs-c.c
@@ -43,7 +43,7 @@ virt_sparsify_statvfs_free_space (value pathv)
caml_failwith ("statvfs");
}
- free_space = (int64_t) buf.f_bsize * buf.f_bavail;
+ free_space = (int64_t)buf.f_bsize * buf.f_bavail;
rv = caml_copy_int64 (free_space);
CAMLreturn (rv);
diff --git a/src/actions-support.c b/src/actions-support.c
index baf375f..6956f1e 100644
--- a/src/actions-support.c
+++ b/src/actions-support.c
@@ -30,25 +30,26 @@
/* Check the return message from a call for validity. */
int
guestfs_int_check_reply_header (guestfs_h *g,
- const struct guestfs_message_header *hdr,
- unsigned int proc_nr, unsigned int serial)
+ const struct guestfs_message_header *hdr,
+ unsigned int proc_nr, unsigned int serial)
{
if (hdr->prog != GUESTFS_PROGRAM) {
error (g, "wrong program (%u/%d)", hdr->prog, GUESTFS_PROGRAM);
return -1;
}
if (hdr->vers != GUESTFS_PROTOCOL_VERSION) {
- error (g, "wrong protocol version (%u/%d)",
- hdr->vers, GUESTFS_PROTOCOL_VERSION);
+ error (g, "wrong protocol version (%u/%d)", hdr->vers,
+ GUESTFS_PROTOCOL_VERSION);
return -1;
}
if (hdr->direction != GUESTFS_DIRECTION_REPLY) {
- error (g, "unexpected message direction (%d/%d)",
- (int) hdr->direction, GUESTFS_DIRECTION_REPLY);
+ error (g, "unexpected message direction (%d/%d)", (int)hdr->direction,
+ GUESTFS_DIRECTION_REPLY);
return -1;
}
if (hdr->proc != proc_nr) {
- error (g, "unexpected procedure number (%d/%u)", (int) hdr->proc,
proc_nr);
+ error (g, "unexpected procedure number (%d/%u)", (int)hdr->proc,
+ proc_nr);
return -1;
}
if (hdr->serial != serial) {
@@ -64,7 +65,8 @@ int
guestfs_int_check_appliance_up (guestfs_h *g, const char *caller)
{
if (g->state == CONFIG || g->state == LAUNCHING) {
- error (g, "%s: call launch before using this function\n(in guestfish, don't
forget to use the 'run' command)",
+ error (g, "%s: call launch before using this function\n(in guestfish, "
+ "don't forget to use the 'run' command)",
caller);
return -1;
}
@@ -95,7 +97,8 @@ guestfs_int_trace_send_line (guestfs_h *g, struct trace_buffer *tb)
if (tb->opened) {
fclose (tb->fp);
tb->fp = NULL;
- guestfs_int_call_callbacks_message (g, GUESTFS_EVENT_TRACE, tb->buf, tb->len);
+ guestfs_int_call_callbacks_message (g, GUESTFS_EVENT_TRACE, tb->buf,
+ tb->len);
free (tb->buf);
tb->buf = NULL;
}
diff --git a/src/alloc.c b/src/alloc.c
index d6f70c2..4fce06a 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -30,7 +30,8 @@ void *
guestfs_int_safe_malloc (guestfs_h *g, size_t nbytes)
{
void *ptr = malloc (nbytes);
- if (nbytes > 0 && !ptr) g->abort_cb ();
+ if (nbytes > 0 && !ptr)
+ g->abort_cb ();
return ptr;
}
@@ -46,10 +47,11 @@ guestfs_int_safe_malloc (guestfs_h *g, size_t nbytes)
sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for
exactly-SIZE_MAX allocations on such hosts; this avoids a test and
branch when S is known to be 1. */
-# define xalloc_oversized(n, s) \
+#define xalloc_oversized(n, s) \
((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n))
-/* Technically we should add an autoconf test for this, testing for the desired
+/* Technically we should add an autoconf test for this, testing for the
+ desired
functionality, like what's done in gnulib, but for now, this is fine. */
#if defined(__GLIBC__)
#define HAVE_GNU_CALLOC (__GLIBC__ >= 2)
@@ -68,8 +70,8 @@ guestfs_int_safe_calloc (guestfs_h *g, size_t n, size_t s)
proper overflow checks. But omit overflow and size-zero tests if
HAVE_GNU_CALLOC, since GNU calloc catches overflow and never
returns NULL if successful. */
- if ((! HAVE_GNU_CALLOC && xalloc_oversized (n, s))
- || (! (p = calloc (n, s)) && (HAVE_GNU_CALLOC || n != 0)))
+ if ((!HAVE_GNU_CALLOC && xalloc_oversized (n, s)) ||
+ (!(p = calloc (n, s)) && (HAVE_GNU_CALLOC || n != 0)))
g->abort_cb ();
return p;
}
@@ -78,7 +80,8 @@ void *
guestfs_int_safe_realloc (guestfs_h *g, void *ptr, size_t nbytes)
{
void *p = realloc (ptr, nbytes);
- if (nbytes > 0 && !p) g->abort_cb ();
+ if (nbytes > 0 && !p)
+ g->abort_cb ();
return p;
}
@@ -86,7 +89,8 @@ char *
guestfs_int_safe_strdup (guestfs_h *g, const char *str)
{
char *s = strdup (str);
- if (!s) g->abort_cb ();
+ if (!s)
+ g->abort_cb ();
return s;
}
@@ -94,7 +98,8 @@ char *
guestfs_int_safe_strndup (guestfs_h *g, const char *str, size_t n)
{
char *s = strndup (str, n);
- if (!s) g->abort_cb ();
+ if (!s)
+ g->abort_cb ();
return s;
}
@@ -102,7 +107,8 @@ void *
guestfs_int_safe_memdup (guestfs_h *g, const void *ptr, size_t size)
{
void *p = malloc (size);
- if (!p) g->abort_cb ();
+ if (!p)
+ g->abort_cb ();
memcpy (p, ptr, size);
return p;
}
diff --git a/src/appliance.c b/src/appliance.c
index 864761f..ab85b09 100644
--- a/src/appliance.c
+++ b/src/appliance.c
@@ -37,15 +37,28 @@
static const char *kernel_name = "vmlinuz." host_cpu;
static const char *initrd_name = "initramfs." host_cpu ".img";
-static int build_appliance (guestfs_h *g, char **kernel, char **initrd, char
**appliance);
-static int find_path (guestfs_h *g, int (*pred) (guestfs_h *g, const char *pelem, void
*data), void *data, char **pelem);
-static int dir_contains_file (guestfs_h *g, const char *dir, const char *file);
+static int build_appliance (guestfs_h *g, char **kernel, char **initrd,
+ char **appliance);
+static int find_path (guestfs_h *g,
+ int (*pred) (guestfs_h *g, const char *pelem,
+ void *data),
+ void *data, char **pelem);
+static int dir_contains_file (guestfs_h *g, const char *dir,
+ const char *file);
static int dir_contains_files (guestfs_h *g, const char *dir, ...);
-static int contains_old_style_appliance (guestfs_h *g, const char *path, void *data);
-static int contains_fixed_appliance (guestfs_h *g, const char *path, void *data);
-static int contains_supermin_appliance (guestfs_h *g, const char *path, void *data);
-static int build_supermin_appliance (guestfs_h *g, const char *supermin_path, uid_t uid,
char **kernel, char **initrd, char **appliance);
-static int run_supermin_build (guestfs_h *g, const char *lockfile, const char
*appliancedir, const char *supermin_path);
+static int contains_old_style_appliance (guestfs_h *g, const char *path,
+ void *data);
+static int contains_fixed_appliance (guestfs_h *g, const char *path,
+ void *data);
+static int contains_supermin_appliance (guestfs_h *g, const char *path,
+ void *data);
+static int build_supermin_appliance (guestfs_h *g,
+ const char *supermin_path, uid_t uid,
+ char **kernel, char **initrd,
+ char **appliance);
+static int run_supermin_build (guestfs_h *g, const char *lockfile,
+ const char *appliancedir,
+ const char *supermin_path);
/* Locate or build the appliance.
*
@@ -91,10 +104,8 @@ static int run_supermin_build (guestfs_h *g, const char *lockfile,
const char *a
* subdirectory.
*/
int
-guestfs_int_build_appliance (guestfs_h *g,
- char **kernel_rtn,
- char **initrd_rtn,
- char **appliance_rtn)
+guestfs_int_build_appliance (guestfs_h *g, char **kernel_rtn,
+ char **initrd_rtn, char **appliance_rtn)
{
char *kernel = NULL, *initrd = NULL, *appliance = NULL;
@@ -111,9 +122,7 @@ guestfs_int_build_appliance (guestfs_h *g,
}
static int
-build_appliance (guestfs_h *g,
- char **kernel,
- char **initrd,
+build_appliance (guestfs_h *g, char **kernel, char **initrd,
char **appliance)
{
int r;
@@ -128,8 +137,8 @@ build_appliance (guestfs_h *g,
if (r == 1)
/* Step (2): build supermin appliance. */
- return build_supermin_appliance (g, supermin_path, uid,
- kernel, initrd, appliance);
+ return build_supermin_appliance (g, supermin_path, uid, kernel, initrd,
+ appliance);
/* Step (3). */
r = find_path (g, contains_fixed_appliance, NULL, &path);
@@ -162,7 +171,8 @@ build_appliance (guestfs_h *g,
return 0;
}
- error (g, _("cannot find any suitable libguestfs supermin, fixed or old-style
appliance on LIBGUESTFS_PATH (search path: %s)"),
+ error (g, _("cannot find any suitable libguestfs supermin, fixed or "
+ "old-style appliance on LIBGUESTFS_PATH (search path: %s)"),
g->path);
return -1;
}
@@ -176,9 +186,8 @@ contains_old_style_appliance (guestfs_h *g, const char *path, void
*data)
static int
contains_fixed_appliance (guestfs_h *g, const char *path, void *data)
{
- return dir_contains_files (g, path,
- "README.fixed",
- "kernel", "initrd", "root",
NULL);
+ return dir_contains_files (g, path, "README.fixed", "kernel",
"initrd",
+ "root", NULL);
}
static int
@@ -194,17 +203,16 @@ contains_supermin_appliance (guestfs_h *g, const char *path, void
*data)
* -1 = error (aborts launch)
*/
static int
-build_supermin_appliance (guestfs_h *g,
- const char *supermin_path,
- uid_t uid,
- char **kernel, char **initrd,
+build_supermin_appliance (guestfs_h *g, const char *supermin_path,
+ uid_t uid, char **kernel, char **initrd,
char **appliance)
{
CLEANUP_FREE char *tmpdir = guestfs_get_cachedir (g);
- CLEANUP_FREE char *cachedir = NULL, *lockfile = NULL, *appliancedir = NULL;
+ CLEANUP_FREE char *cachedir = NULL, *lockfile = NULL,
+ *appliancedir = NULL;
struct stat statbuf;
- cachedir = safe_asprintf (g, "%s/.guestfs-%ju", tmpdir, (uintmax_t) uid);
+ cachedir = safe_asprintf (g, "%s/.guestfs-%ju", tmpdir, (uintmax_t)uid);
lockfile = safe_asprintf (g, "%s/lock", cachedir);
appliancedir = safe_asprintf (g, "%s/appliance.d", cachedir);
@@ -218,21 +226,23 @@ build_supermin_appliance (guestfs_h *g,
return 0;
if (statbuf.st_uid != uid) {
error (g, _("security: cached appliance %s is not owned by UID %ju"),
- cachedir, (uintmax_t) uid);
+ cachedir, (uintmax_t)uid);
return -1;
}
if (!S_ISDIR (statbuf.st_mode)) {
- error (g, _("security: cached appliance %s is not a directory (mode %o)"),
+ error (g,
+ _("security: cached appliance %s is not a directory (mode %o)"),
cachedir, statbuf.st_mode);
return -1;
}
if ((statbuf.st_mode & 0022) != 0) {
- error (g, _("security: cached appliance %s is writable by group or other (mode
%o)"),
+ error (g, _("security: cached appliance %s is writable by group or "
+ "other (mode %o)"),
cachedir, statbuf.st_mode);
return -1;
}
- (void) utimes (cachedir, NULL);
+ (void)utimes (cachedir, NULL);
debug (g, "begin building supermin appliance");
/* Build the appliance if it needs to be built. */
@@ -249,8 +259,8 @@ build_supermin_appliance (guestfs_h *g,
*appliance = safe_asprintf (g, "%s/root", appliancedir);
/* Touch the files so they don't get deleted (as they are in /var/tmp). */
- (void) utimes (*kernel, NULL);
- (void) utimes (*initrd, NULL);
+ (void)utimes (*kernel, NULL);
+ (void)utimes (*initrd, NULL);
/* Checking backend != "uml" is a big hack. UML encodes the mtime
* of the original backing file (in this case, the appliance) in the
@@ -265,7 +275,7 @@ build_supermin_appliance (guestfs_h *g,
* XXX
*/
if (STRNEQ (g->backend, "uml"))
- (void) utimes (*appliance, NULL);
+ (void)utimes (*appliance, NULL);
return 0;
}
@@ -274,14 +284,12 @@ build_supermin_appliance (guestfs_h *g,
* appliance.
*/
static int
-run_supermin_build (guestfs_h *g,
- const char *lockfile,
- const char *appliancedir,
- const char *supermin_path)
+run_supermin_build (guestfs_h *g, const char *lockfile,
+ const char *appliancedir, const char *supermin_path)
{
CLEANUP_CMD_CLOSE struct command *cmd = guestfs_int_new_command (g);
int r;
-#if 0 /* not supported in supermin 5 yet XXX */
+#if 0 /* not supported in supermin 5 yet XXX */
uid_t uid = getuid ();
uid_t euid = geteuid ();
gid_t gid = getgid ();
@@ -339,8 +347,7 @@ run_supermin_build (guestfs_h *g,
static int
find_path (guestfs_h *g,
int (*pred) (guestfs_h *g, const char *pelem, void *data),
- void *data,
- char **pelem_ret)
+ void *data, char **pelem_ret)
{
size_t len;
int r;
@@ -365,7 +372,7 @@ find_path (guestfs_h *g,
return -1;
}
- if (r != 0) /* predicate matched */
+ if (r != 0) /* predicate matched */
return 1;
free (*pelem_ret);
@@ -435,10 +442,11 @@ guestfs_int_get_uefi (guestfs_h *g, char **code, char **vars)
for (i = 0; guestfs_int_aavmf_firmware[i] != NULL; i += 2) {
const char *codefile = guestfs_int_aavmf_firmware[i];
- const char *varsfile = guestfs_int_aavmf_firmware[i+1];
+ const char *varsfile = guestfs_int_aavmf_firmware[i + 1];
if (access (codefile, R_OK) == 0 && access (varsfile, R_OK) == 0) {
- CLEANUP_CMD_CLOSE struct command *copycmd = guestfs_int_new_command (g);
+ CLEANUP_CMD_CLOSE struct command *copycmd =
+ guestfs_int_new_command (g);
char *varst;
int r;
diff --git a/src/available.c b/src/available.c
index ae0bd84..cef3eda 100644
--- a/src/available.c
+++ b/src/available.c
@@ -43,11 +43,10 @@ find_or_cache_feature (guestfs_h *g, const char *group)
res = guestfs_internal_feature_available (g, group);
if (res < 0)
- return 0; /* internal_feature_available sent an error. */
+ return 0; /* internal_feature_available sent an error. */
- g->features =
- safe_realloc (g, g->features,
- (g->nr_features+1) * sizeof (struct cached_feature));
+ g->features = safe_realloc (
+ g, g->features, (g->nr_features + 1) * sizeof (struct cached_feature));
f = &g->features[g->nr_features];
++g->nr_features;
f->group = safe_strdup (g, group);
@@ -71,7 +70,8 @@ guestfs_impl_available (guestfs_h *g, char *const *groups)
if (f->result == 2) {
error (g, _("%s: unknown group"), group);
return -1;
- } else if (f->result == 1) {
+ }
+ else if (f->result == 1) {
error (g, _("%s: group not available"), group);
return -1;
}
@@ -95,7 +95,8 @@ guestfs_impl_feature_available (guestfs_h *g, char *const *groups)
if (f->result == 2) {
error (g, _("%s: unknown group"), group);
return -1;
- } else if (f->result == 1) {
+ }
+ else if (f->result == 1) {
return 0;
}
}
diff --git a/src/canonical-name.c b/src/canonical-name.c
index 8b5f493..8541176 100644
--- a/src/canonical-name.c
+++ b/src/canonical-name.c
@@ -34,9 +34,9 @@ guestfs_impl_canonical_device_name (guestfs_h *g, const char *device)
/* /dev/hd etc. */
if (STRPREFIX (device, "/dev/") &&
- strchr (device+5, '/') == NULL && /* not an LV name */
- ((len = strcspn (device+5, "d")) > 0 && len <= 2)) {
- ret = safe_asprintf (g, "/dev/sd%s", &device[5+len+1]);
+ strchr (device + 5, '/') == NULL && /* not an LV name */
+ ((len = strcspn (device + 5, "d")) > 0 && len <= 2)) {
+ ret = safe_asprintf (g, "/dev/sd%s", &device[5 + len + 1]);
}
else if (STRPREFIX (device, "/dev/mapper/") ||
STRPREFIX (device, "/dev/dm-")) {
@@ -48,5 +48,5 @@ guestfs_impl_canonical_device_name (guestfs_h *g, const char *device)
else
ret = safe_strdup (g, device);
- return ret; /* caller frees */
+ return ret; /* caller frees */
}
diff --git a/src/cleanup.c b/src/cleanup.c
index 71c26ec..6a89f74 100644
--- a/src/cleanup.c
+++ b/src/cleanup.c
@@ -40,7 +40,7 @@
void
guestfs_int_cleanup_free (void *ptr)
{
- free (* (void **) ptr);
+ free (*(void **)ptr);
}
void
@@ -52,7 +52,7 @@ guestfs_int_cleanup_free_string_list (char ***ptr)
void
guestfs_int_cleanup_hash_free (void *ptr)
{
- Hash_table *h = * (Hash_table **) ptr;
+ Hash_table *h = *(Hash_table **)ptr;
if (h)
hash_free (h);
@@ -72,7 +72,7 @@ guestfs_int_cleanup_unlink_free (char **ptr)
void
guestfs_int_cleanup_xmlBufferFree (void *ptr)
{
- xmlBufferPtr xb = * (xmlBufferPtr *) ptr;
+ xmlBufferPtr xb = *(xmlBufferPtr *)ptr;
if (xb)
xmlBufferFree (xb);
@@ -81,7 +81,7 @@ guestfs_int_cleanup_xmlBufferFree (void *ptr)
void
guestfs_int_cleanup_xmlFreeDoc (void *ptr)
{
- xmlDocPtr doc = * (xmlDocPtr *) ptr;
+ xmlDocPtr doc = *(xmlDocPtr *)ptr;
if (doc)
xmlFreeDoc (doc);
@@ -90,7 +90,7 @@ guestfs_int_cleanup_xmlFreeDoc (void *ptr)
void
guestfs_int_cleanup_xmlFreeURI (void *ptr)
{
- xmlURIPtr uri = * (xmlURIPtr *) ptr;
+ xmlURIPtr uri = *(xmlURIPtr *)ptr;
if (uri)
xmlFreeURI (uri);
@@ -99,7 +99,7 @@ guestfs_int_cleanup_xmlFreeURI (void *ptr)
void
guestfs_int_cleanup_xmlFreeTextWriter (void *ptr)
{
- xmlTextWriterPtr xo = * (xmlTextWriterPtr *) ptr;
+ xmlTextWriterPtr xo = *(xmlTextWriterPtr *)ptr;
if (xo)
xmlFreeTextWriter (xo);
@@ -108,7 +108,7 @@ guestfs_int_cleanup_xmlFreeTextWriter (void *ptr)
void
guestfs_int_cleanup_xmlXPathFreeContext (void *ptr)
{
- xmlXPathContextPtr ctx = * (xmlXPathContextPtr *) ptr;
+ xmlXPathContextPtr ctx = *(xmlXPathContextPtr *)ptr;
if (ctx)
xmlXPathFreeContext (ctx);
@@ -117,7 +117,7 @@ guestfs_int_cleanup_xmlXPathFreeContext (void *ptr)
void
guestfs_int_cleanup_xmlXPathFreeObject (void *ptr)
{
- xmlXPathObjectPtr obj = * (xmlXPathObjectPtr *) ptr;
+ xmlXPathObjectPtr obj = *(xmlXPathObjectPtr *)ptr;
if (obj)
xmlXPathFreeObject (obj);
@@ -126,7 +126,7 @@ guestfs_int_cleanup_xmlXPathFreeObject (void *ptr)
void
guestfs_int_cleanup_fclose (void *ptr)
{
- FILE *f = * (FILE **) ptr;
+ FILE *f = *(FILE **)ptr;
if (f)
fclose (f);
@@ -135,7 +135,7 @@ guestfs_int_cleanup_fclose (void *ptr)
void
guestfs_int_cleanup_pclose (void *ptr)
{
- FILE *f = * (FILE **) ptr;
+ FILE *f = *(FILE **)ptr;
if (f)
pclose (f);
diff --git a/src/command.c b/src/command.c
index 866847d..9e4c18d 100644
--- a/src/command.c
+++ b/src/command.c
@@ -95,10 +95,13 @@ enum command_style {
struct command;
-static void add_line_buffer (struct command *cmd, const char *buf, size_t len);
+static void add_line_buffer (struct command *cmd, const char *buf,
+ size_t len);
static void close_line_buffer (struct command *cmd);
-static void add_unbuffered (struct command *cmd, const char *buf, size_t len);
-static void add_whole_buffer (struct command *cmd, const char *buf, size_t len);
+static void add_unbuffered (struct command *cmd, const char *buf,
+ size_t len);
+static void add_whole_buffer (struct command *cmd, const char *buf,
+ size_t len);
static void close_whole_buffer (struct command *cmd);
struct buffering {
@@ -114,12 +117,12 @@ struct child_rlimits {
long limit;
};
-struct command
-{
+struct command {
guestfs_h *g;
enum command_style style;
- union {
+ union
+ {
/* COMMAND_STYLE_EXECV */
struct stringsbuf argv;
/* COMMAND_STYLE_SYSTEM */
@@ -226,7 +229,8 @@ add_string (struct command *cmd, const char *str, size_t len)
cmd->string.alloc = 256;
else
cmd->string.alloc += MAX (cmd->string.alloc, len);
- cmd->string.str = safe_realloc (cmd->g, cmd->string.str,
cmd->string.alloc);
+ cmd->string.str =
+ safe_realloc (cmd->g, cmd->string.str, cmd->string.alloc);
}
memcpy (&cmd->string.str[cmd->string.len], str, len);
@@ -249,10 +253,7 @@ guestfs_int_cmd_add_string_quoted (struct command *cmd, const char
*str)
add_string (cmd, "\"", 1);
for (; *str; str++) {
- if (*str == '$' ||
- *str == '`' ||
- *str == '\\' ||
- *str == '"')
+ if (*str == '$' || *str == '`' || *str == '\\' || *str ==
'"')
add_string (cmd, "\\", 1);
add_string (cmd, str, 1);
}
@@ -348,7 +349,8 @@ guestfs_int_cmd_set_child_callback (struct command *cmd,
* consume lots of space or time.
*/
void
-guestfs_int_cmd_set_child_rlimit (struct command *cmd, int resource, long limit)
+guestfs_int_cmd_set_child_rlimit (struct command *cmd, int resource,
+ long limit)
{
struct child_rlimits *p;
@@ -359,7 +361,6 @@ guestfs_int_cmd_set_child_rlimit (struct command *cmd, int resource,
long limit)
cmd->child_rlimits = p;
}
-
/* Finish off the command by either NULL-terminating the argv array or
* adding a terminating \0 to the string, or die with an internal
* error if no command has been added.
@@ -389,12 +390,12 @@ debug_command (struct command *cmd)
switch (cmd->style) {
case COMMAND_STYLE_EXECV:
debug (cmd->g, "command: run: %s", cmd->argv.argv[0]);
- last = cmd->argv.size-1; /* omit final NULL pointer */
+ last = cmd->argv.size - 1; /* omit final NULL pointer */
for (i = 1; i < last; ++i) {
- if (i < last-1 &&
- cmd->argv.argv[i][0] == '-' && cmd->argv.argv[i+1][0] !=
'-') {
- debug (cmd->g, "command: run: \\ %s %s",
- cmd->argv.argv[i], cmd->argv.argv[i+1]);
+ if (i < last - 1 && cmd->argv.argv[i][0] == '-' &&
+ cmd->argv.argv[i + 1][0] != '-') {
+ debug (cmd->g, "command: run: \\ %s %s", cmd->argv.argv[i],
+ cmd->argv.argv[i + 1]);
i++;
}
else
@@ -419,7 +420,8 @@ run_command (struct command *cmd)
int errorfd[2] = { -1, -1 };
int outfd[2] = { -1, -1 };
- /* Set up a pipe to capture command output and send it to the error log. */
+ /* Set up a pipe to capture command output and send it to the error log.
+ */
if (cmd->capture_errors) {
if (pipe2 (errorfd, O_CLOEXEC) == -1) {
perrorf (cmd->g, "pipe2");
@@ -479,9 +481,9 @@ run_command (struct command *cmd)
dup2 (1, 2);
run_child (cmd);
- /*NOTREACHED*/
+/*NOTREACHED*/
- error:
+error:
if (errorfd[0] >= 0)
close (errorfd[0]);
if (errorfd[1] >= 0)
@@ -525,7 +527,7 @@ run_child (struct command *cmd)
if (max_fd == -1)
max_fd = 1024;
if (max_fd > 65536)
- max_fd = 65536; /* bound the amount of work we do here */
+ max_fd = 65536; /* bound the amount of work we do here */
for (fd = 3; fd < max_fd; ++fd)
close (fd);
}
@@ -533,7 +535,8 @@ run_child (struct command *cmd)
/* Clean up the environment. */
setenv ("LC_ALL", "C", 1);
- /* Set the umask for all subcommands to something sensible (RHBZ#610880). */
+ /* Set the umask for all subcommands to something sensible (RHBZ#610880).
+ */
umask (022);
if (cmd->child_callback) {
@@ -542,8 +545,7 @@ run_child (struct command *cmd)
}
#ifdef HAVE_SETRLIMIT
- for (child_rlimit = cmd->child_rlimits;
- child_rlimit != NULL;
+ for (child_rlimit = cmd->child_rlimits; child_rlimit != NULL;
child_rlimit = child_rlimit->next) {
rlimit.rlim_cur = rlimit.rlim_max = child_rlimit->limit;
if (setrlimit (child_rlimit->resource, &rlimit) == -1) {
@@ -585,9 +587,8 @@ run_child (struct command *cmd)
if (WIFEXITED (r))
_exit (WEXITSTATUS (r));
fprintf (stderr, "%s\n",
- guestfs_int_exit_status_to_string (r, cmd->string.str,
- status_string,
- sizeof status_string));
+ guestfs_int_exit_status_to_string (
+ r, cmd->string.str, status_string, sizeof status_string));
_exit (EXIT_FAILURE);
case COMMAND_STYLE_NOT_SELECTED:
@@ -626,7 +627,7 @@ loop (struct command *cmd)
while (nr_fds > 0) {
rset2 = rset;
- r = select (maxfd+1, &rset2, NULL, NULL, NULL);
+ r = select (maxfd + 1, &rset2, NULL, NULL, NULL);
if (r == -1) {
if (errno == EINTR || errno == EAGAIN)
continue;
@@ -754,9 +755,12 @@ guestfs_int_cmd_pipe_run (struct command *cmd, const char *mode)
assert (!cmd->stdout_callback);
assert (!cmd->stderr_to_stdout);
- if (STREQ (mode, "r")) r_mode = 1;
- else if (STREQ (mode, "w")) r_mode = 0;
- else abort ();
+ if (STREQ (mode, "r"))
+ r_mode = 1;
+ else if (STREQ (mode, "w"))
+ r_mode = 0;
+ else
+ abort ();
if (pipe2 (fd, O_CLOEXEC) == -1) {
perrorf (cmd->g, "pipe2");
@@ -770,10 +774,10 @@ guestfs_int_cmd_pipe_run (struct command *cmd, const char *mode)
if (guestfs_int_lazy_make_tmpdir (cmd->g) == -1)
goto error;
- cmd->error_file =
- safe_asprintf (cmd->g, "%s/cmderr.%d", cmd->g->tmpdir,
++cmd->g->unique);
+ cmd->error_file = safe_asprintf (cmd->g, "%s/cmderr.%d",
cmd->g->tmpdir,
+ ++cmd->g->unique);
errfd = open (cmd->error_file,
- O_WRONLY|O_CREAT|O_NOCTTY|O_TRUNC|O_CLOEXEC, 0600);
+ O_WRONLY | O_CREAT | O_NOCTTY | O_TRUNC | O_CLOEXEC, 0600);
if (errfd == -1) {
perrorf (cmd->g, "open: %s", cmd->error_file);
goto error;
@@ -818,9 +822,9 @@ guestfs_int_cmd_pipe_run (struct command *cmd, const char *mode)
}
run_child (cmd);
- /*NOTREACHED*/
+/*NOTREACHED*/
- error:
+error:
if (errfd >= 0)
close (errfd);
if (fd[0] >= 0)
@@ -853,13 +857,14 @@ guestfs_int_cmd_get_pipe_errors (struct command *cmd)
assert (cmd->error_file != NULL);
- if (guestfs_int_read_whole_file (cmd->g, cmd->error_file, &ret, NULL) == -1)
+ if (guestfs_int_read_whole_file (cmd->g, cmd->error_file, &ret, NULL) ==
+ -1)
return NULL;
/* If the file ends with \n characters, trim them. */
len = strlen (ret);
- while (len > 0 && ret[len-1] == '\n') {
- ret[len-1] = '\0';
+ while (len > 0 && ret[len - 1] == '\n') {
+ ret[len - 1] = '\0';
len--;
}
@@ -930,15 +935,15 @@ process_line_buffer (struct command *cmd, int closed)
while (cmd->outbuf.len > 0) {
/* Length of the next line. */
p = strchr (cmd->outbuf.buffer, '\n');
- if (p != NULL) { /* Got a whole line. */
+ if (p != NULL) { /* Got a whole line. */
len = p - cmd->outbuf.buffer;
newlen = cmd->outbuf.len - len - 1;
}
- else if (closed) { /* Consume rest of input even if no \n found. */
+ else if (closed) { /* Consume rest of input even if no \n found. */
len = cmd->outbuf.len;
newlen = 0;
}
- else /* Need to wait for more input. */
+ else /* Need to wait for more input. */
break;
/* Call the callback with the next line. */
@@ -966,8 +971,8 @@ add_line_buffer (struct command *cmd, const char *buf, size_t len)
*/
oldlen = cmd->outbuf.len;
cmd->outbuf.len += len;
- cmd->outbuf.buffer = safe_realloc (g, cmd->outbuf.buffer,
- cmd->outbuf.len + 1 /* for \0 */);
+ cmd->outbuf.buffer =
+ safe_realloc (g, cmd->outbuf.buffer, cmd->outbuf.len + 1 /* for \0 */);
memcpy (cmd->outbuf.buffer + oldlen, buf, len);
cmd->outbuf.buffer[cmd->outbuf.len] = '\0';
@@ -995,13 +1000,14 @@ add_whole_buffer (struct command *cmd, const char *buf, size_t
len)
/* Append the new content to the end of the current buffer. */
oldlen = cmd->outbuf.len;
cmd->outbuf.len += len;
- cmd->outbuf.buffer = safe_realloc (g, cmd->outbuf.buffer, cmd->outbuf.len);
+ cmd->outbuf.buffer =
+ safe_realloc (g, cmd->outbuf.buffer, cmd->outbuf.len);
memcpy (cmd->outbuf.buffer + oldlen, buf, len);
}
static void
close_whole_buffer (struct command *cmd)
{
- cmd->stdout_callback (cmd->g, cmd->stdout_data,
- cmd->outbuf.buffer, cmd->outbuf.len);
+ cmd->stdout_callback (cmd->g, cmd->stdout_data, cmd->outbuf.buffer,
+ cmd->outbuf.len);
}
diff --git a/src/conn-socket.c b/src/conn-socket.c
index 633946c..c415d38 100644
--- a/src/conn-socket.c
+++ b/src/conn-socket.c
@@ -28,7 +28,7 @@
#include <errno.h>
#include <poll.h>
#include <sys/stat.h>
-#include <sys/socket.h> /* accept4 */
+#include <sys/socket.h> /* accept4 */
#include <sys/types.h>
#include <assert.h>
#include <libintl.h>
@@ -41,8 +41,8 @@
struct connection_socket {
const struct connection_ops *ops;
- int console_sock; /* Appliance console (for debug info). */
- int daemon_sock; /* Daemon communications socket. */
+ int console_sock; /* Appliance console (for debug info). */
+ int daemon_sock; /* Daemon communications socket. */
/* Socket for accepting a connection from the daemon. Only used
* before and during accept_connection.
@@ -50,12 +50,13 @@ struct connection_socket {
int daemon_accept_sock;
};
-static int handle_log_message (guestfs_h *g, struct connection_socket *conn);
+static int handle_log_message (guestfs_h *g,
+ struct connection_socket *conn);
static int
accept_connection (guestfs_h *g, struct connection *connv)
{
- struct connection_socket *conn = (struct connection_socket *) connv;
+ struct connection_socket *conn = (struct connection_socket *)connv;
int sock = -1;
time_t start_t, now_t;
int timeout_ms;
@@ -94,7 +95,7 @@ accept_connection (guestfs_h *g, struct connection *connv)
return -1;
}
- if (r == 0) { /* timeout reached */
+ if (r == 0) { /* timeout reached */
guestfs_int_launch_timeout (g);
return -1;
}
@@ -138,7 +139,7 @@ static ssize_t
read_data (guestfs_h *g, struct connection *connv, void *bufv, size_t len)
{
char *buf = bufv;
- struct connection_socket *conn = (struct connection_socket *) connv;
+ struct connection_socket *conn = (struct connection_socket *)connv;
size_t original_len = len;
if (conn->daemon_sock == -1) {
@@ -212,7 +213,7 @@ read_data (guestfs_h *g, struct connection *connv, void *bufv, size_t
len)
static int
can_read_data (guestfs_h *g, struct connection *connv)
{
- struct connection_socket *conn = (struct connection_socket *) connv;
+ struct connection_socket *conn = (struct connection_socket *)connv;
struct pollfd fd;
int r;
@@ -225,7 +226,7 @@ can_read_data (guestfs_h *g, struct connection *connv)
fd.events = POLLIN;
fd.revents = 0;
- again:
+again:
r = poll (&fd, 1, 0);
if (r == -1) {
if (errno == EINTR || errno == EAGAIN)
@@ -238,11 +239,11 @@ can_read_data (guestfs_h *g, struct connection *connv)
}
static ssize_t
-write_data (guestfs_h *g, struct connection *connv,
- const void *bufv, size_t len)
+write_data (guestfs_h *g, struct connection *connv, const void *bufv,
+ size_t len)
{
const char *buf = bufv;
- struct connection_socket *conn = (struct connection_socket *) connv;
+ struct connection_socket *conn = (struct connection_socket *)connv;
size_t original_len = len;
if (conn->daemon_sock == -1) {
@@ -311,8 +312,7 @@ write_data (guestfs_h *g, struct connection *connv,
* -1 = error
*/
static int
-handle_log_message (guestfs_h *g,
- struct connection_socket *conn)
+handle_log_message (guestfs_h *g, struct connection_socket *conn)
{
CLEANUP_FREE char *buf = safe_malloc (g, BUFSIZ);
ssize_t n;
@@ -361,8 +361,8 @@ handle_log_message (guestfs_h *g,
* We can't even be sure that console_sock is a socket or that
* it's writable.
*/
- ignore_value (write (conn->console_sock, dsr_reply,
- sizeof dsr_reply - 1));
+ ignore_value (
+ write (conn->console_sock, dsr_reply, sizeof dsr_reply - 1));
/* Additionally, because of a bug in sgabios, it will still pause
* unless you write at least 14 bytes, so we have to pad the
* reply. We can't pad with NULs since sgabios's input routine
@@ -382,7 +382,7 @@ handle_log_message (guestfs_h *g,
static void
free_conn_socket (guestfs_h *g, struct connection *connv)
{
- struct connection_socket *conn = (struct connection_socket *) connv;
+ struct connection_socket *conn = (struct connection_socket *)connv;
if (conn->console_sock >= 0)
close (conn->console_sock);
@@ -412,9 +412,8 @@ static struct connection_ops ops = {
* free_connection.
*/
struct connection *
-guestfs_int_new_conn_socket_listening (guestfs_h *g,
- int daemon_accept_sock,
- int console_sock)
+guestfs_int_new_conn_socket_listening (guestfs_h *g, int daemon_accept_sock,
+ int console_sock)
{
struct connection_socket *conn;
@@ -442,7 +441,7 @@ guestfs_int_new_conn_socket_listening (guestfs_h *g,
conn->daemon_sock = -1;
conn->daemon_accept_sock = daemon_accept_sock;
- return (struct connection *) conn;
+ return (struct connection *)conn;
}
/* Create a new socket connection, connected.
@@ -451,9 +450,8 @@ guestfs_int_new_conn_socket_listening (guestfs_h *g,
* and promises not to call accept_connection.
*/
struct connection *
-guestfs_int_new_conn_socket_connected (guestfs_h *g,
- int daemon_sock,
- int console_sock)
+guestfs_int_new_conn_socket_connected (guestfs_h *g, int daemon_sock,
+ int console_sock)
{
struct connection_socket *conn;
@@ -481,5 +479,5 @@ guestfs_int_new_conn_socket_connected (guestfs_h *g,
conn->daemon_sock = daemon_sock;
conn->daemon_accept_sock = -1;
- return (struct connection *) conn;
+ return (struct connection *)conn;
}
diff --git a/src/copy-in-out.c b/src/copy-in-out.c
index 50831be..2a445bc 100644
--- a/src/copy-in-out.c
+++ b/src/copy-in-out.c
@@ -32,11 +32,13 @@
#include "guestfs-internal.h"
#include "guestfs-internal-actions.h"
-static int split_path (guestfs_h *g, char *buf, size_t buf_size, const char *path, const
char **dirname, const char **basename);
+static int split_path (guestfs_h *g, char *buf, size_t buf_size,
+ const char *path, const char **dirname,
+ const char **basename);
int
-guestfs_impl_copy_in (guestfs_h *g,
- const char *localpath, const char *remotedir)
+guestfs_impl_copy_in (guestfs_h *g, const char *localpath,
+ const char *remotedir)
{
CLEANUP_CMD_CLOSE struct command *cmd = guestfs_int_new_command (g);
int fd;
@@ -48,7 +50,8 @@ guestfs_impl_copy_in (guestfs_h *g,
struct stat statbuf;
if (stat (localpath, &statbuf) == -1) {
- error (g, _("source '%s' does not exist (or cannot be read)"),
localpath);
+ error (g, _("source '%s' does not exist (or cannot be read)"),
+ localpath);
return -1;
}
@@ -110,7 +113,7 @@ struct copy_out_child_data {
static int
child_setup (guestfs_h *g, void *data)
{
- struct copy_out_child_data d = *(struct copy_out_child_data *) data;
+ struct copy_out_child_data d = *(struct copy_out_child_data *)data;
if (chdir (d.localdir) == -1) {
perror (d.localdir);
@@ -131,14 +134,13 @@ child_setup (guestfs_h *g, void *data)
}
int
-guestfs_impl_copy_out (guestfs_h *g,
- const char *remotepath, const char *localdir)
+guestfs_impl_copy_out (guestfs_h *g, const char *remotepath,
+ const char *localdir)
{
struct stat statbuf;
int r;
- if (stat (localdir, &statbuf) == -1 ||
- ! (S_ISDIR (statbuf.st_mode))) {
+ if (stat (localdir, &statbuf) == -1 || !(S_ISDIR (statbuf.st_mode))) {
error (g, _("target '%s' is not a directory"), localdir);
return -1;
}
@@ -150,7 +152,7 @@ guestfs_impl_copy_out (guestfs_h *g,
if (r == -1)
return -1;
- if (r == 1) { /* is file */
+ if (r == 1) { /* is file */
CLEANUP_FREE char *filename = NULL;
size_t buf_len = strlen (remotepath) + 1;
CLEANUP_FREE char *buf = safe_malloc (g, buf_len);
@@ -165,7 +167,8 @@ guestfs_impl_copy_out (guestfs_h *g,
}
if (guestfs_download (g, remotepath, filename) == -1)
return -1;
- } else { /* not a regular file */
+ }
+ else { /* not a regular file */
CLEANUP_CMD_CLOSE struct command *cmd = guestfs_int_new_command (g);
struct copy_out_child_data data;
char fdbuf[64];
@@ -237,34 +240,45 @@ guestfs_impl_copy_out (guestfs_h *g,
* (eg. path == "/") then this can return dirname as NULL.
*/
static int
-split_path (guestfs_h *g, char *buf, size_t buf_size,
- const char *path, const char **dirname, const char **basename)
+split_path (guestfs_h *g, char *buf, size_t buf_size, const char *path,
+ const char **dirname, const char **basename)
{
size_t len = strlen (path);
if (len == 0 || len > buf_size - 1) {
- error (g, _("error: argument is zero length or longer than maximum
permitted"));
+ error (
+ g,
+ _ (
+ "error: argument is zero length or longer than maximum permitted"));
return -1;
}
strcpy (buf, path);
- if (len >= 2 && buf[len-1] == '/') {
- buf[len-1] = '\0';
+ if (len >= 2 && buf[len - 1] == '/') {
+ buf[len - 1] = '\0';
len--;
}
char *p = strrchr (buf, '/');
- if (p && p > buf) { /* "foo/bar" */
+ if (p && p > buf) { /* "foo/bar" */
*p = '\0';
p++;
- if (dirname) *dirname = buf;
- if (basename) *basename = p;
- } else if (p && p == buf) { /* "/foo" */
- if (dirname) *dirname = "/";
- if (basename) *basename = buf+1;
- } else {
- if (dirname) *dirname = NULL;
- if (basename) *basename = buf;
+ if (dirname)
+ *dirname = buf;
+ if (basename)
+ *basename = p;
+ }
+ else if (p && p == buf) { /* "/foo" */
+ if (dirname)
+ *dirname = "/";
+ if (basename)
+ *basename = buf + 1;
+ }
+ else {
+ if (dirname)
+ *dirname = NULL;
+ if (basename)
+ *basename = buf;
}
return 0;
diff --git a/src/create.c b/src/create.c
index 355e814..462b3d4 100644
--- a/src/create.c
+++ b/src/create.c
@@ -40,19 +40,25 @@
#include "guestfs-internal.h"
#include "guestfs-internal-actions.h"
-static int disk_create_raw (guestfs_h *g, const char *filename, int64_t size, const
struct guestfs_disk_create_argv *optargs);
-static int disk_create_qcow2 (guestfs_h *g, const char *filename, int64_t size, const
char *backingfile, const struct guestfs_disk_create_argv *optargs);
+static int disk_create_raw (guestfs_h *g, const char *filename,
+ int64_t size,
+ const struct guestfs_disk_create_argv *optargs);
+static int
+disk_create_qcow2 (guestfs_h *g, const char *filename, int64_t size,
+ const char *backingfile,
+ const struct guestfs_disk_create_argv *optargs);
static char *qemu_escape_param (guestfs_h *g, const char *param);
int
guestfs_impl_disk_create (guestfs_h *g, const char *filename,
- const char *format, int64_t size,
- const struct guestfs_disk_create_argv *optargs)
+ const char *format, int64_t size,
+ const struct guestfs_disk_create_argv *optargs)
{
const char *backingfile;
- backingfile = optargs->bitmask & GUESTFS_DISK_CREATE_BACKINGFILE_BITMASK ?
- optargs->backingfile : NULL;
+ backingfile = optargs->bitmask & GUESTFS_DISK_CREATE_BACKINGFILE_BITMASK
+ ? optargs->backingfile
+ : NULL;
/* Ensure size is valid. */
if (backingfile) {
@@ -60,7 +66,8 @@ guestfs_impl_disk_create (guestfs_h *g, const char *filename,
error (g, _("if using a backing file, size must be passed as -1"));
return -1;
}
- } else {
+ }
+ else {
/* XXX Actually size == 0 could be valid, although not useful and
* it causes qemu to break.
*/
@@ -100,13 +107,13 @@ disk_create_raw_block (guestfs_h *g, const char *filename)
{
int fd;
- fd = open (filename, O_WRONLY|O_NOCTTY|O_CLOEXEC, 0666);
+ fd = open (filename, O_WRONLY | O_NOCTTY | O_CLOEXEC, 0666);
if (fd == -1) {
perrorf (g, _("cannot open block device: %s"), filename);
return -1;
}
- /* Just discard blocks, if possible. However don't try too hard. */
+/* Just discard blocks, if possible. However don't try too hard. */
#if defined(BLKGETSIZE64) && defined(BLKDISCARD)
uint64_t size;
uint64_t range[2];
@@ -171,13 +178,14 @@ disk_create_raw (guestfs_h *g, const char *filename, int64_t size,
return disk_create_raw_block (g, filename);
}
- fd = open (filename, O_WRONLY|O_CREAT|O_NOCTTY|O_TRUNC|O_CLOEXEC, 0666);
+ fd = open (filename, O_WRONLY | O_CREAT | O_NOCTTY | O_TRUNC | O_CLOEXEC,
+ 0666);
if (fd == -1) {
perrorf (g, _("cannot create raw file: %s"), filename);
return -1;
}
- if (!allocated) { /* Sparse file. */
+ if (!allocated) { /* Sparse file. */
if (ftruncate (fd, size) == -1) {
perrorf (g, _("%s: truncate"), filename);
close (fd);
@@ -185,7 +193,7 @@ disk_create_raw (guestfs_h *g, const char *filename, int64_t size,
return -1;
}
}
- else { /* Allocated file. */
+ else { /* Allocated file. */
#ifdef HAVE_POSIX_FALLOCATE
int err;
@@ -198,7 +206,8 @@ disk_create_raw (guestfs_h *g, const char *filename, int64_t size,
return -1;
}
#else
- /* Slow emulation of posix_fallocate on platforms which don't have it. */
+ /* Slow emulation of posix_fallocate on platforms which don't have it.
+ */
char buffer[BUFSIZ];
size_t remaining = size;
size_t n;
@@ -229,7 +238,8 @@ disk_create_raw (guestfs_h *g, const char *filename, int64_t size,
return 0;
}
-/*
http://graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2 */
+/*
http://graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2
+ */
static int
is_power_of_2 (unsigned v)
{
@@ -265,8 +275,7 @@ disk_create_qcow2 (guestfs_h *g, const char *orig_filename, int64_t
size,
/* Conservative whitelist. This can be extended with other
* valid formats as required.
*/
- if (STRNEQ (backingformat, "raw") &&
- STRNEQ (backingformat, "qcow2") &&
+ if (STRNEQ (backingformat, "raw") && STRNEQ (backingformat,
"qcow2") &&
STRNEQ (backingformat, "vmdk")) {
error (g, _("invalid value for backingformat parameter '%s'"),
backingformat);
@@ -280,7 +289,9 @@ disk_create_qcow2 (guestfs_h *g, const char *orig_filename, int64_t
size,
else if (STREQ (optargs->preallocation, "metadata"))
preallocation = "metadata";
else if (STREQ (optargs->preallocation, "full"))
- /* Ugh:
https://lists.gnu.org/archive/html/qemu-devel/2014-08/msg03863.html */
+ /* Ugh:
+ *
https://lists.gnu.org/archive/html/qemu-devel/2014-08/msg03863.html
+ */
preallocation = "falloc";
else {
error (g, _("invalid value for preallocation parameter '%s'"),
@@ -298,7 +309,7 @@ disk_create_qcow2 (guestfs_h *g, const char *orig_filename, int64_t
size,
if (optargs->bitmask & GUESTFS_DISK_CREATE_CLUSTERSIZE_BITMASK) {
clustersize = optargs->clustersize;
if (clustersize < 512 || clustersize > 2097152 ||
- !is_power_of_2 ((unsigned) clustersize)) {
+ !is_power_of_2 ((unsigned)clustersize)) {
error (g, _("invalid value for clustersize parameter '%d'"),
clustersize);
return -1;
@@ -319,7 +330,8 @@ disk_create_qcow2 (guestfs_h *g, const char *orig_filename, int64_t
size,
if (backingformat)
guestfs_int_add_sprintf (g, &optionsv, "backing_fmt=%s",
backingformat);
if (preallocation)
- guestfs_int_add_sprintf (g, &optionsv, "preallocation=%s",
preallocation);
+ guestfs_int_add_sprintf (g, &optionsv, "preallocation=%s",
+ preallocation);
if (compat)
guestfs_int_add_sprintf (g, &optionsv, "compat=%s", compat);
if (clustersize >= 0)
@@ -327,7 +339,8 @@ disk_create_qcow2 (guestfs_h *g, const char *orig_filename, int64_t
size,
guestfs_int_end_stringsbuf (g, &optionsv);
if (optionsv.size > 1) {
- CLEANUP_FREE char *options = guestfs_int_join_strings (",",
optionsv.argv);
+ CLEANUP_FREE char *options =
+ guestfs_int_join_strings (",", optionsv.argv);
guestfs_int_cmd_add_arg (cmd, "-o");
guestfs_int_cmd_add_arg (cmd, options);
}
@@ -353,7 +366,7 @@ qemu_escape_param (guestfs_h *g, const char *param)
size_t i, len = strlen (param);
char *p, *ret;
- ret = p = safe_malloc (g, len*2 + 1); /* max length of escaped name*/
+ ret = p = safe_malloc (g, len * 2 + 1); /* max length of escaped name*/
for (i = 0; i < len; ++i) {
*p++ = param[i];
if (param[i] == ',')
diff --git a/src/dbdump.c b/src/dbdump.c
index 7c17ce6..572a5ae 100644
--- a/src/dbdump.c
+++ b/src/dbdump.c
@@ -33,16 +33,22 @@
#if defined(DB_DUMP)
-static void read_db_dump_line (guestfs_h *g, void *datav, const char *line, size_t len);
-static unsigned char *convert_hex_to_binary (guestfs_h *g, const char *hex, size_t
hexlen, size_t *binlen_rtn);
+static void read_db_dump_line (guestfs_h *g, void *datav, const char *line,
+ size_t len);
+static unsigned char *convert_hex_to_binary (guestfs_h *g, const char *hex,
+ size_t hexlen,
+ size_t *binlen_rtn);
struct cb_data {
guestfs_int_db_dump_callback callback;
void *opaque;
- enum { reading_header,
- reading_key, reading_value,
- reading_finished,
- reading_failed } state;
+ enum {
+ reading_header,
+ reading_key,
+ reading_value,
+ reading_finished,
+ reading_failed
+ } state;
unsigned char *key;
size_t keylen;
};
@@ -52,9 +58,8 @@ struct cb_data {
* database format.
*/
int
-guestfs_int_read_db_dump (guestfs_h *g,
- const char *dumpfile, void *opaque,
- guestfs_int_db_dump_callback callback)
+guestfs_int_read_db_dump (guestfs_h *g, const char *dumpfile, void *opaque,
+ guestfs_int_db_dump_callback callback)
{
struct cb_data data;
CLEANUP_CMD_CLOSE struct command *cmd = guestfs_int_new_command (g);
@@ -103,11 +108,11 @@ read_db_dump_line (guestfs_h *g, void *datav, const char *line,
size_t len)
data->state = reading_key;
return;
- /* Read the key, value pairs using a state machine. They are
- * prefixed with a space and printed as hex strings, so convert
- * those strings to binary. Pass the strings up to the callback
- * function.
- */
+ /* Read the key, value pairs using a state machine. They are
+ * prefixed with a space and printed as hex strings, so convert
+ * those strings to binary. Pass the strings up to the callback
+ * function.
+ */
case reading_key:
if (STRPREFIX (line, "DATA=END")) {
data->state = reading_finished;
@@ -115,12 +120,13 @@ read_db_dump_line (guestfs_h *g, void *datav, const char *line,
size_t len)
}
if (len < 1 || line[0] != ' ') {
- debug (g, _("unexpected line from db_dump command, no space prefix"));
+ debug (g,
+ _("unexpected line from db_dump command, no space prefix"));
data->state = reading_failed;
return;
}
- data->key = convert_hex_to_binary (g, &line[1], len-1, &data->keylen);
+ data->key = convert_hex_to_binary (g, &line[1], len - 1,
&data->keylen);
if (data->key == NULL) {
data->state = reading_failed;
return;
@@ -134,19 +140,20 @@ read_db_dump_line (guestfs_h *g, void *datav, const char *line,
size_t len)
size_t valuelen;
if (len < 1 || line[0] != ' ') {
- debug (g, _("unexpected line from db_dump command, no space prefix"));
+ debug (g,
+ _("unexpected line from db_dump command, no space prefix"));
data->state = reading_failed;
return;
}
- value = convert_hex_to_binary (g, &line[1], len-1, &valuelen);
+ value = convert_hex_to_binary (g, &line[1], len - 1, &valuelen);
if (value == NULL) {
data->state = reading_failed;
return;
}
- if (data->callback (g, data->key, data->keylen,
- value, valuelen, data->opaque) == -1) {
+ if (data->callback (g, data->key, data->keylen, value, valuelen,
+ data->opaque) == -1) {
data->state = reading_failed;
return;
}
@@ -166,13 +173,13 @@ convert_hex_octet (const char *h)
int r;
switch (h[0]) {
- case 'a'...'f':
+ case 'a' ... 'f':
r = (h[0] - 'a' + 10) << 4;
break;
- case 'A'...'F':
+ case 'A' ... 'F':
r = (h[0] - 'A' + 10) << 4;
break;
- case '0'...'9':
+ case '0' ... '9':
r = (h[0] - '0') << 4;
break;
default:
@@ -180,13 +187,13 @@ convert_hex_octet (const char *h)
}
switch (h[1]) {
- case 'a'...'f':
+ case 'a' ... 'f':
r |= h[1] - 'a' + 10;
break;
- case 'A'...'F':
+ case 'A' ... 'F':
r |= h[1] - 'A' + 10;
break;
- case '0'...'9':
+ case '0' ... '9':
r |= h[1] - '0';
break;
default:
@@ -205,18 +212,19 @@ convert_hex_to_binary (guestfs_h *g, const char *hex, size_t
hexlen,
size_t i, o;
int b;
- if (hexlen > 0 && hex[hexlen-1] == '\n')
+ if (hexlen > 0 && hex[hexlen - 1] == '\n')
hexlen--;
binlen = hexlen / 2;
bin = safe_malloc (g, binlen);
- for (i = o = 0; i+1 < hexlen && o < binlen; i += 2, ++o) {
+ for (i = o = 0; i + 1 < hexlen && o < binlen; i += 2, ++o) {
b = convert_hex_octet (&hex[i]);
if (b >= 0)
bin[o] = b;
else {
- error (g, _("unexpected non-hex digits in output of db_dump command"));
+ error (g,
+ _("unexpected non-hex digits in output of db_dump command"));
free (bin);
return NULL;
}
diff --git a/src/drives.c b/src/drives.c
index 385cf04..3015758 100644
--- a/src/drives.c
+++ b/src/drives.c
@@ -46,7 +46,7 @@ struct drive_create_data {
enum drive_protocol protocol;
struct drive_server *servers;
size_t nr_servers;
- const char *exportname; /* File name or path to the resource. */
+ const char *exportname; /* File name or path to the resource. */
const char *username;
const char *secret;
bool readonly;
@@ -94,8 +94,7 @@ create_overlay (guestfs_h *g, struct drive *drv)
/* Create and free the 'drive' struct. */
static struct drive *
-create_drive_file (guestfs_h *g,
- const struct drive_create_data *data)
+create_drive_file (guestfs_h *g, const struct drive_create_data *data)
{
struct drive *drv = safe_calloc (g, 1, sizeof *drv);
@@ -106,8 +105,10 @@ create_drive_file (guestfs_h *g,
drv->readonly = data->readonly;
drv->iface = data->iface ? safe_strdup (g, data->iface) : NULL;
drv->name = data->name ? safe_strdup (g, data->name) : NULL;
- drv->disk_label = data->disk_label ? safe_strdup (g, data->disk_label) :
NULL;
- drv->cachemode = data->cachemode ? safe_strdup (g, data->cachemode) : NULL;
+ drv->disk_label =
+ data->disk_label ? safe_strdup (g, data->disk_label) : NULL;
+ drv->cachemode =
+ data->cachemode ? safe_strdup (g, data->cachemode) : NULL;
drv->discard = data->discard;
drv->copyonread = data->copyonread;
@@ -116,7 +117,8 @@ create_drive_file (guestfs_h *g,
/* Don't double-free the servers in free_drive_struct, since
* they are owned by the caller along this error path.
*/
- drv->src.servers = NULL; drv->src.nr_servers = 0;
+ drv->src.servers = NULL;
+ drv->src.nr_servers = 0;
free_drive_struct (drv);
return NULL;
}
@@ -126,8 +128,7 @@ create_drive_file (guestfs_h *g,
}
static struct drive *
-create_drive_non_file (guestfs_h *g,
- const struct drive_create_data *data)
+create_drive_non_file (guestfs_h *g, const struct drive_create_data *data)
{
struct drive *drv = safe_calloc (g, 1, sizeof *drv);
@@ -135,15 +136,18 @@ create_drive_non_file (guestfs_h *g,
drv->src.servers = data->servers;
drv->src.nr_servers = data->nr_servers;
drv->src.u.exportname = safe_strdup (g, data->exportname);
- drv->src.username = data->username ? safe_strdup (g, data->username) : NULL;
+ drv->src.username =
+ data->username ? safe_strdup (g, data->username) : NULL;
drv->src.secret = data->secret ? safe_strdup (g, data->secret) : NULL;
drv->src.format = data->format ? safe_strdup (g, data->format) : NULL;
drv->readonly = data->readonly;
drv->iface = data->iface ? safe_strdup (g, data->iface) : NULL;
drv->name = data->name ? safe_strdup (g, data->name) : NULL;
- drv->disk_label = data->disk_label ? safe_strdup (g, data->disk_label) :
NULL;
- drv->cachemode = data->cachemode ? safe_strdup (g, data->cachemode) : NULL;
+ drv->disk_label =
+ data->disk_label ? safe_strdup (g, data->disk_label) : NULL;
+ drv->cachemode =
+ data->cachemode ? safe_strdup (g, data->cachemode) : NULL;
drv->discard = data->discard;
drv->copyonread = data->copyonread;
@@ -152,7 +156,8 @@ create_drive_non_file (guestfs_h *g,
/* Don't double-free the servers in free_drive_struct, since
* they are owned by the caller along this error path.
*/
- drv->src.servers = NULL; drv->src.nr_servers = 0;
+ drv->src.servers = NULL;
+ drv->src.nr_servers = 0;
free_drive_struct (drv);
return NULL;
}
@@ -162,8 +167,7 @@ create_drive_non_file (guestfs_h *g,
}
static struct drive *
-create_drive_curl (guestfs_h *g,
- const struct drive_create_data *data)
+create_drive_curl (guestfs_h *g, const struct drive_create_data *data)
{
if (data->nr_servers != 1) {
error (g, _("curl: you must specify exactly one server"));
@@ -190,15 +194,16 @@ create_drive_curl (guestfs_h *g,
}
static struct drive *
-create_drive_gluster (guestfs_h *g,
- const struct drive_create_data *data)
+create_drive_gluster (guestfs_h *g, const struct drive_create_data *data)
{
if (data->username != NULL) {
- error (g, _("gluster: you cannot specify a username with this protocol"));
+ error (g,
+ _("gluster: you cannot specify a username with this protocol"));
return NULL;
}
if (data->secret != NULL) {
- error (g, _("gluster: you cannot specify a secret with this protocol"));
+ error (g,
+ _("gluster: you cannot specify a secret with this protocol"));
return NULL;
}
@@ -208,7 +213,9 @@ create_drive_gluster (guestfs_h *g,
}
if (STREQ (data->exportname, "")) {
- error (g, _("gluster: volume name parameter should not be an empty
string"));
+ error (
+ g,
+ _("gluster: volume name parameter should not be an empty string"));
return NULL;
}
@@ -233,8 +240,7 @@ nbd_port (void)
}
static struct drive *
-create_drive_nbd (guestfs_h *g,
- const struct drive_create_data *data)
+create_drive_nbd (guestfs_h *g, const struct drive_create_data *data)
{
if (data->username != NULL) {
error (g, _("nbd: you cannot specify a username with this protocol"));
@@ -257,8 +263,7 @@ create_drive_nbd (guestfs_h *g,
}
static struct drive *
-create_drive_rbd (guestfs_h *g,
- const struct drive_create_data *data)
+create_drive_rbd (guestfs_h *g, const struct drive_create_data *data)
{
size_t i;
@@ -275,7 +280,8 @@ create_drive_rbd (guestfs_h *g,
}
if (STREQ (data->exportname, "")) {
- error (g, _("rbd: image name parameter should not be an empty string"));
+ error (g,
+ _("rbd: image name parameter should not be an empty string"));
return NULL;
}
@@ -288,17 +294,18 @@ create_drive_rbd (guestfs_h *g,
}
static struct drive *
-create_drive_sheepdog (guestfs_h *g,
- const struct drive_create_data *data)
+create_drive_sheepdog (guestfs_h *g, const struct drive_create_data *data)
{
size_t i;
if (data->username != NULL) {
- error (g, _("sheepdog: you cannot specify a username with this
protocol"));
+ error (
+ g, _("sheepdog: you cannot specify a username with this protocol"));
return NULL;
}
if (data->secret != NULL) {
- error (g, _("sheepdog: you cannot specify a secret with this protocol"));
+ error (g,
+ _("sheepdog: you cannot specify a secret with this protocol"));
return NULL;
}
@@ -315,7 +322,8 @@ create_drive_sheepdog (guestfs_h *g,
}
if (STREQ (data->exportname, "")) {
- error (g, _("sheepdog: volume parameter should not be an empty string"));
+ error (g,
+ _("sheepdog: volume parameter should not be an empty string"));
return NULL;
}
@@ -328,8 +336,7 @@ create_drive_sheepdog (guestfs_h *g,
}
static struct drive *
-create_drive_ssh (guestfs_h *g,
- const struct drive_create_data *data)
+create_drive_ssh (guestfs_h *g, const struct drive_create_data *data)
{
if (data->nr_servers != 1) {
error (g, _("ssh: you must specify exactly one server"));
@@ -361,8 +368,7 @@ create_drive_ssh (guestfs_h *g,
}
static struct drive *
-create_drive_iscsi (guestfs_h *g,
- const struct drive_create_data *data)
+create_drive_iscsi (guestfs_h *g, const struct drive_create_data *data)
{
if (data->nr_servers != 1) {
error (g, _("iscsi: you must specify exactly one server"));
@@ -397,8 +403,7 @@ create_drive_iscsi (guestfs_h *g,
* a null drive.
*/
static struct drive *
-create_drive_dev_null (guestfs_h *g,
- struct drive_create_data *data)
+create_drive_dev_null (guestfs_h *g, struct drive_create_data *data)
{
CLEANUP_FREE char *tmpfile = NULL;
@@ -430,8 +435,11 @@ create_drive_dev_null (guestfs_h *g,
static struct drive *
create_drive_dummy (guestfs_h *g)
{
- /* A special drive struct that is used as a dummy slot for the appliance. */
- struct drive_create_data data = { 0, };
+ /* A special drive struct that is used as a dummy slot for the appliance.
+ */
+ struct drive_create_data data = {
+ 0,
+ };
data.exportname = "";
return create_drive_file (g, &data);
}
@@ -465,18 +473,30 @@ const char *
guestfs_int_drive_protocol_to_string (enum drive_protocol protocol)
{
switch (protocol) {
- case drive_protocol_file: return "file";
- case drive_protocol_ftp: return "ftp";
- case drive_protocol_ftps: return "ftps";
- case drive_protocol_gluster: return "gluster";
- case drive_protocol_http: return "http";
- case drive_protocol_https: return "https";
- case drive_protocol_iscsi: return "iscsi";
- case drive_protocol_nbd: return "nbd";
- case drive_protocol_rbd: return "rbd";
- case drive_protocol_sheepdog: return "sheepdog";
- case drive_protocol_ssh: return "ssh";
- case drive_protocol_tftp: return "tftp";
+ case drive_protocol_file:
+ return "file";
+ case drive_protocol_ftp:
+ return "ftp";
+ case drive_protocol_ftps:
+ return "ftps";
+ case drive_protocol_gluster:
+ return "gluster";
+ case drive_protocol_http:
+ return "http";
+ case drive_protocol_https:
+ return "https";
+ case drive_protocol_iscsi:
+ return "iscsi";
+ case drive_protocol_nbd:
+ return "nbd";
+ case drive_protocol_rbd:
+ return "rbd";
+ case drive_protocol_sheepdog:
+ return "sheepdog";
+ case drive_protocol_ssh:
+ return "ssh";
+ case drive_protocol_tftp:
+ return "tftp";
}
abort ();
}
@@ -487,24 +507,19 @@ guestfs_int_drive_protocol_to_string (enum drive_protocol protocol)
static char *
drive_to_string (guestfs_h *g, const struct drive *drv)
{
- return safe_asprintf
- (g, "%s%s%s%s protocol=%s%s%s%s%s%s%s%s%s%s%s",
- drv->src.u.path,
- drv->readonly ? " readonly" : "",
- drv->src.format ? " format=" : "",
- drv->src.format ? : "",
- guestfs_int_drive_protocol_to_string (drv->src.protocol),
- drv->iface ? " iface=" : "",
- drv->iface ? : "",
- drv->name ? " name=" : "",
- drv->name ? : "",
- drv->disk_label ? " label=" : "",
- drv->disk_label ? : "",
- drv->cachemode ? " cache=" : "",
- drv->cachemode ? : "",
- drv->discard == discard_disable ? "" :
- drv->discard == discard_enable ? " discard=enable" : "
discard=besteffort",
- drv->copyonread ? " copyonread" : "");
+ return safe_asprintf (
+ g, "%s%s%s%s protocol=%s%s%s%s%s%s%s%s%s%s%s", drv->src.u.path,
+ drv->readonly ? " readonly" : "", drv->src.format ? "
format=" : "",
+ drv->src.format ?: "",
+ guestfs_int_drive_protocol_to_string (drv->src.protocol),
+ drv->iface ? " iface=" : "", drv->iface ?: "",
+ drv->name ? " name=" : "", drv->name ?: "",
+ drv->disk_label ? " label=" : "", drv->disk_label ?:
"",
+ drv->cachemode ? " cache=" : "", drv->cachemode ?:
"",
+ drv->discard == discard_disable ? "" : drv->discard ==
discard_enable
+ ? " discard=enable"
+ : " discard=besteffort",
+ drv->copyonread ? " copyonread" : "");
}
/* Add struct drive to the g->drives vector at the given index. */
@@ -514,7 +529,7 @@ add_drive_to_handle_at (guestfs_h *g, struct drive *d, size_t
drv_index)
if (drv_index >= g->nr_drives) {
g->drives = safe_realloc (g, g->drives,
sizeof (struct drive *) * (drv_index + 1));
- while (g->nr_drives < drv_index+1) {
+ while (g->nr_drives < drv_index + 1) {
g->drives[g->nr_drives] = NULL;
g->nr_drives++;
}
@@ -549,9 +564,7 @@ guestfs_int_free_drives (guestfs_h *g)
struct drive *drv;
size_t i;
- ITER_DRIVES (g, i, drv) {
- free_drive_struct (drv);
- }
+ ITER_DRIVES (g, i, drv) { free_drive_struct (drv); }
free (g->drives);
@@ -610,8 +623,8 @@ valid_hostname (const char *str)
while (len > 0) {
char c = *str++;
len--;
- if (!c_isalnum (c) &&
- c != '-' && c != '.' && c != ':'
&& c != '[' && c != ']')
+ if (!c_isalnum (c) && c != '-' && c != '.' &&
c != ':' && c != '[' &&
+ c != ']')
return 0;
}
return 1;
@@ -627,7 +640,8 @@ valid_port (int port)
}
static int
-parse_one_server (guestfs_h *g, const char *server, struct drive_server *ret)
+parse_one_server (guestfs_h *g, const char *server,
+ struct drive_server *ret)
{
char *hostname;
char *port_str;
@@ -653,11 +667,11 @@ parse_one_server (guestfs_h *g, const char *server, struct
drive_server *ret)
return -1;
}
ret->transport = drive_transport_unix;
- ret->u.socket = safe_strdup (g, server+5);
+ ret->u.socket = safe_strdup (g, server + 5);
ret->port = 0;
return 0;
}
- skip_unix:
+skip_unix:
if (match2 (g, server, re_hostname_port, &hostname, &port_str)) {
if (sscanf (port_str, "%d", &port) != 1 || !valid_port (port)) {
@@ -718,8 +732,9 @@ parse_servers (guestfs_h *g, char *const *strs,
}
int
-guestfs_impl_add_drive_opts (guestfs_h *g, const char *filename,
- const struct guestfs_add_drive_opts_argv *optargs)
+guestfs_impl_add_drive_opts (
+ guestfs_h *g, const char *filename,
+ const struct guestfs_add_drive_opts_argv *optargs)
{
struct drive_create_data data;
const char *protocol;
@@ -731,17 +746,23 @@ guestfs_impl_add_drive_opts (guestfs_h *g, const char *filename,
data.exportname = filename;
data.readonly = optargs->bitmask & GUESTFS_ADD_DRIVE_OPTS_READONLY_BITMASK
- ? optargs->readonly : false;
+ ? optargs->readonly
+ : false;
data.format = optargs->bitmask & GUESTFS_ADD_DRIVE_OPTS_FORMAT_BITMASK
- ? optargs->format : NULL;
+ ? optargs->format
+ : NULL;
data.iface = optargs->bitmask & GUESTFS_ADD_DRIVE_OPTS_IFACE_BITMASK
- ? optargs->iface : NULL;
+ ? optargs->iface
+ : NULL;
data.name = optargs->bitmask & GUESTFS_ADD_DRIVE_OPTS_NAME_BITMASK
- ? optargs->name : NULL;
+ ? optargs->name
+ : NULL;
data.disk_label = optargs->bitmask & GUESTFS_ADD_DRIVE_OPTS_LABEL_BITMASK
- ? optargs->label : NULL;
+ ? optargs->label
+ : NULL;
protocol = optargs->bitmask & GUESTFS_ADD_DRIVE_OPTS_PROTOCOL_BITMASK
- ? optargs->protocol : "file";
+ ? optargs->protocol
+ : "file";
if (optargs->bitmask & GUESTFS_ADD_DRIVE_OPTS_SERVER_BITMASK) {
ssize_t r = parse_servers (g, optargs->server, &data.servers);
if (r == -1)
@@ -749,11 +770,15 @@ guestfs_impl_add_drive_opts (guestfs_h *g, const char *filename,
data.nr_servers = r;
}
data.username = optargs->bitmask & GUESTFS_ADD_DRIVE_OPTS_USERNAME_BITMASK
- ? optargs->username : NULL;
+ ? optargs->username
+ : NULL;
data.secret = optargs->bitmask & GUESTFS_ADD_DRIVE_OPTS_SECRET_BITMASK
- ? optargs->secret : NULL;
- data.cachemode = optargs->bitmask & GUESTFS_ADD_DRIVE_OPTS_CACHEMODE_BITMASK
- ? optargs->cachemode : NULL;
+ ? optargs->secret
+ : NULL;
+ data.cachemode =
+ optargs->bitmask & GUESTFS_ADD_DRIVE_OPTS_CACHEMODE_BITMASK
+ ? optargs->cachemode
+ : NULL;
if (optargs->bitmask & GUESTFS_ADD_DRIVE_OPTS_DISCARD_BITMASK) {
if (STREQ (optargs->discard, "disable"))
@@ -763,7 +788,10 @@ guestfs_impl_add_drive_opts (guestfs_h *g, const char *filename,
else if (STREQ (optargs->discard, "besteffort"))
data.discard = discard_besteffort;
else {
- error (g, _("discard parameter must be 'disable', 'enable' or
'besteffort'"));
+ error (
+ g,
+ _ (
+ "discard parameter must be 'disable', 'enable' or
'besteffort'"));
free_drive_servers (data.servers, data.nr_servers);
return -1;
}
@@ -773,7 +801,8 @@ guestfs_impl_add_drive_opts (guestfs_h *g, const char *filename,
data.copyonread =
optargs->bitmask & GUESTFS_ADD_DRIVE_OPTS_COPYONREAD_BITMASK
- ? optargs->copyonread : false;
+ ? optargs->copyonread
+ : false;
if (data.readonly && data.discard == discard_enable) {
error (g, _("discard support cannot be enabled on read-only drives"));
@@ -783,24 +812,28 @@ guestfs_impl_add_drive_opts (guestfs_h *g, const char *filename,
if (data.format && !valid_format_iface (data.format)) {
error (g, _("%s parameter is empty or contains disallowed characters"),
- "format");
+ "format");
free_drive_servers (data.servers, data.nr_servers);
return -1;
}
if (data.iface && !valid_format_iface (data.iface)) {
error (g, _("%s parameter is empty or contains disallowed characters"),
- "iface");
+ "iface");
free_drive_servers (data.servers, data.nr_servers);
return -1;
}
if (data.disk_label && !valid_disk_label (data.disk_label)) {
- error (g, _("label parameter is empty, too long, or contains disallowed
characters"));
+ error (g, _("label parameter is empty, too long, or contains "
+ "disallowed characters"));
free_drive_servers (data.servers, data.nr_servers);
return -1;
}
if (data.cachemode &&
- !(STREQ (data.cachemode, "writeback") || STREQ (data.cachemode,
"unsafe"))) {
- error (g, _("cachemode parameter must be 'writeback' (default) or
'unsafe'"));
+ !(STREQ (data.cachemode, "writeback") ||
+ STREQ (data.cachemode, "unsafe"))) {
+ error (
+ g,
+ _("cachemode parameter must be 'writeback' (default) or
'unsafe'"));
free_drive_servers (data.servers, data.nr_servers);
return -1;
}
@@ -897,7 +930,8 @@ guestfs_impl_add_drive_opts (guestfs_h *g, const char *filename,
/* ... else, hotplugging case. */
if (!g->backend_ops->hot_add_drive) {
- error (g, _("the current backend does not support hotplugging drives"));
+ error (g,
+ _("the current backend does not support hotplugging drives"));
free_drive_struct (drv);
return -1;
}
@@ -915,8 +949,8 @@ guestfs_impl_add_drive_opts (guestfs_h *g, const char *filename,
drv_index = i;
/* Hot-add the drive. */
- if (g->backend_ops->hot_add_drive (g, g->backend_data,
- drv, drv_index) == -1) {
+ if (g->backend_ops->hot_add_drive (g, g->backend_data, drv, drv_index) ==
+ -1) {
free_drive_struct (drv);
return -1;
}
@@ -935,8 +969,7 @@ int
guestfs_impl_add_drive_ro (guestfs_h *g, const char *filename)
{
const struct guestfs_add_drive_opts_argv optargs = {
- .bitmask = GUESTFS_ADD_DRIVE_OPTS_READONLY_BITMASK,
- .readonly = true,
+ .bitmask = GUESTFS_ADD_DRIVE_OPTS_READONLY_BITMASK, .readonly = true,
};
return guestfs_add_drive_opts_argv (g, filename, &optargs);
@@ -944,11 +977,10 @@ guestfs_impl_add_drive_ro (guestfs_h *g, const char *filename)
int
guestfs_impl_add_drive_with_if (guestfs_h *g, const char *filename,
- const char *iface)
+ const char *iface)
{
const struct guestfs_add_drive_opts_argv optargs = {
- .bitmask = GUESTFS_ADD_DRIVE_OPTS_IFACE_BITMASK,
- .iface = iface,
+ .bitmask = GUESTFS_ADD_DRIVE_OPTS_IFACE_BITMASK, .iface = iface,
};
return guestfs_add_drive_opts_argv (g, filename, &optargs);
@@ -956,11 +988,11 @@ guestfs_impl_add_drive_with_if (guestfs_h *g, const char *filename,
int
guestfs_impl_add_drive_ro_with_if (guestfs_h *g, const char *filename,
- const char *iface)
+ const char *iface)
{
const struct guestfs_add_drive_opts_argv optargs = {
- .bitmask = GUESTFS_ADD_DRIVE_OPTS_IFACE_BITMASK
- | GUESTFS_ADD_DRIVE_OPTS_READONLY_BITMASK,
+ .bitmask = GUESTFS_ADD_DRIVE_OPTS_IFACE_BITMASK |
+ GUESTFS_ADD_DRIVE_OPTS_READONLY_BITMASK,
.iface = iface,
.readonly = true,
};
@@ -969,10 +1001,11 @@ guestfs_impl_add_drive_ro_with_if (guestfs_h *g, const char
*filename,
}
int
-guestfs_impl_add_drive_scratch (guestfs_h *g, int64_t size,
- const struct guestfs_add_drive_scratch_argv *optargs)
+guestfs_impl_add_drive_scratch (
+ guestfs_h *g, int64_t size,
+ const struct guestfs_add_drive_scratch_argv *optargs)
{
- struct guestfs_add_drive_opts_argv add_drive_optargs = { .bitmask = 0 };
+ struct guestfs_add_drive_opts_argv add_drive_optargs = {.bitmask = 0 };
CLEANUP_FREE char *filename = NULL;
/* Some parameters we always set. */
@@ -1026,26 +1059,28 @@ guestfs_impl_remove_drive (guestfs_h *g, const char *label)
size_t i;
struct drive *drv;
- ITER_DRIVES (g, i, drv) {
+ ITER_DRIVES (g, i, drv)
+ {
if (drv->disk_label && STREQ (label, drv->disk_label))
goto found;
}
error (g, _("disk with label '%s' not found"), label);
return -1;
- found:
- if (g->state == CONFIG) { /* Not hotplugging. */
+found:
+ if (g->state == CONFIG) { /* Not hotplugging. */
free_drive_struct (drv);
g->nr_drives--;
for (; i < g->nr_drives; ++i)
- g->drives[i] = g->drives[i+1];
+ g->drives[i] = g->drives[i + 1];
return 0;
}
- else { /* Hotplugging. */
+ else { /* Hotplugging. */
if (!g->backend_ops->hot_remove_drive) {
- error (g, _("the current backend does not support hotplugging drives"));
+ error (g,
+ _("the current backend does not support hotplugging drives"));
return -1;
}
@@ -1057,7 +1092,7 @@ guestfs_impl_remove_drive (guestfs_h *g, const char *label)
free_drive_struct (drv);
g->drives[i] = NULL;
- if (i == g->nr_drives-1)
+ if (i == g->nr_drives - 1)
g->nr_drives--;
if (guestfs_internal_hot_remove_drive (g, label) == -1)
@@ -1096,13 +1131,14 @@ guestfs_impl_debug_drives (guestfs_h *g)
DECLARE_STRINGSBUF (ret);
struct drive *drv;
- ITER_DRIVES (g, i, drv) {
+ ITER_DRIVES (g, i, drv)
+ {
guestfs_int_add_string_nodup (g, &ret, drive_to_string (g, drv));
}
guestfs_int_end_stringsbuf (g, &ret);
- return ret.argv; /* caller frees */
+ return ret.argv; /* caller frees */
}
static void
diff --git a/src/errors.c b/src/errors.c
index c85aed5..32c42aa 100644
--- a/src/errors.c
+++ b/src/errors.c
@@ -65,7 +65,8 @@ guestfs_int_warning (guestfs_h *g, const char *fs, ...)
len = vasprintf (&msg, fs, args);
va_end (args);
- if (len < 0) return;
+ if (len < 0)
+ return;
guestfs_int_call_callbacks_message (g, GUESTFS_EVENT_WARNING, msg, len);
}
@@ -89,7 +90,8 @@ guestfs_int_debug (guestfs_h *g, const char *fs, ...)
len = vasprintf (&msg, fs, args);
va_end (args);
- if (len < 0) return;
+ if (len < 0)
+ return;
guestfs_int_call_callbacks_message (g, GUESTFS_EVENT_LIBRARY, msg, len);
}
@@ -109,7 +111,8 @@ guestfs_int_trace (guestfs_h *g, const char *fs, ...)
len = vasprintf (&msg, fs, args);
va_end (args);
- if (len < 0) return;
+ if (len < 0)
+ return;
guestfs_int_call_callbacks_message (g, GUESTFS_EVENT_TRACE, msg, len);
}
@@ -125,13 +128,15 @@ guestfs_int_error_errno (guestfs_h *g, int errnum, const char *fs,
...)
err = vasprintf (&msg, fs, args);
va_end (args);
- if (err < 0) return;
+ if (err < 0)
+ return;
/* set_last_error first so that the callback can access the error
* message and errno through the handle if it wishes.
*/
set_last_error (g, errnum, msg);
- if (g->error_cb) g->error_cb (g, g->error_cb_data, msg);
+ if (g->error_cb)
+ g->error_cb (g, g->error_cb_data, msg);
}
void
@@ -147,7 +152,8 @@ guestfs_int_perrorf (guestfs_h *g, const char *fs, ...)
err = vasprintf (&msg, fs, args);
va_end (args);
- if (err < 0) return;
+ if (err < 0)
+ return;
strerror_r (errnum, buf, sizeof buf);
@@ -159,7 +165,8 @@ guestfs_int_perrorf (guestfs_h *g, const char *fs, ...)
* message and errno through the handle if it wishes.
*/
set_last_error (g, errnum, msg);
- if (g->error_cb) g->error_cb (g, g->error_cb_data, msg);
+ if (g->error_cb)
+ g->error_cb (g, g->error_cb_data, msg);
}
void
@@ -175,8 +182,8 @@ guestfs_get_out_of_memory_handler (guestfs_h *g)
}
void
-guestfs_set_error_handler (guestfs_h *g,
- guestfs_error_handler_cb cb, void *data)
+guestfs_set_error_handler (guestfs_h *g, guestfs_error_handler_cb cb,
+ void *data)
{
g->error_cb = cb;
g->error_cb_data = data;
@@ -185,13 +192,14 @@ guestfs_set_error_handler (guestfs_h *g,
guestfs_error_handler_cb
guestfs_get_error_handler (guestfs_h *g, void **data_rtn)
{
- if (data_rtn) *data_rtn = g->error_cb_data;
+ if (data_rtn)
+ *data_rtn = g->error_cb_data;
return g->error_cb;
}
void
-guestfs_push_error_handler (guestfs_h *g,
- guestfs_error_handler_cb cb, void *data)
+guestfs_push_error_handler (guestfs_h *g, guestfs_error_handler_cb cb,
+ void *data)
{
struct error_cb_stack *old_stack;
@@ -253,14 +261,13 @@ guestfs_int_print_BufferIn (FILE *out, const char *buf, size_t
buf_size)
if (c_isprint (buf[i]))
fputc (buf[i], out);
else
- fprintf (out, "\\x%02x", (unsigned char) buf[i]);
+ fprintf (out, "\\x%02x", (unsigned char)buf[i]);
}
fputc ('"', out);
if (orig_size > buf_size)
- fprintf (out,
- _("<truncated, original size %zu bytes>"), orig_size);
+ fprintf (out, _("<truncated, original size %zu bytes>"), orig_size);
}
void
@@ -271,12 +278,13 @@ guestfs_int_print_BufferOut (FILE *out, const char *buf, size_t
buf_size)
/* Some standard error messages for common failures. */
-#define DEBUG_ADVICE \
- "Do:\n" \
- " export LIBGUESTFS_DEBUG=1 LIBGUESTFS_TRACE=1\n" \
- "and run the command again. For further information, read:\n" \
- "
http://libguestfs.org/guestfs-faq.1.html#debugging-libguestfs\n" \
- "You can also run 'libguestfs-test-tool' and post the *complete*
output\n" \
+#define DEBUG_ADVICE \
+ "Do:\n" \
+ " export LIBGUESTFS_DEBUG=1 LIBGUESTFS_TRACE=1\n" \
+ "and run the command again. For further information, read:\n" \
+ "
http://libguestfs.org/guestfs-faq.1.html#debugging-libguestfs\n" \
+ "You can also run 'libguestfs-test-tool' and post the *complete* "
\
+ "output\n" \
"into a bug report or message to the libguestfs mailing list."
/* Launch failed. Since this is the most common error seen by people
@@ -290,10 +298,9 @@ guestfs_int_launch_failed_error (guestfs_h *g)
if (g->verbose)
error (g, _("guestfs_launch failed, see earlier error messages"));
else
- error (g, _(
- "guestfs_launch failed.\n"
- "This usually means the libguestfs appliance failed to start or crashed.\n"
- DEBUG_ADVICE));
+ error (g, _("guestfs_launch failed.\n"
+ "This usually means the libguestfs appliance failed to "
+ "start or crashed.\n" DEBUG_ADVICE));
}
/* As above, but for crashes that occur after launch. */
@@ -301,12 +308,12 @@ void
guestfs_int_unexpected_close_error (guestfs_h *g)
{
if (g->verbose)
- error (g, _("appliance closed the connection unexpectedly, see earlier error
messages"));
+ error (g, _("appliance closed the connection unexpectedly, see "
+ "earlier error messages"));
else
- error (g, _(
- "appliance closed the connection unexpectedly.\n"
- "This usually means the libguestfs appliance crashed.\n"
- DEBUG_ADVICE));
+ error (g, _("appliance closed the connection unexpectedly.\n"
+ "This usually means the libguestfs appliance "
+ "crashed.\n" DEBUG_ADVICE));
}
/* As above, but for appliance kernel hanging. */
@@ -316,16 +323,16 @@ guestfs_int_launch_timeout (guestfs_h *g)
if (g->verbose)
error (g, _("appliance launch timed out, see earlier error messages"));
else
- error (g, _(
- "appliance launch timed out.\n"
- "This usually means the kernel or appliance hung during launch.\n"
- DEBUG_ADVICE));
+ error (g, _("appliance launch timed out.\n"
+ "This usually means the kernel or appliance hung during "
+ "launch.\n" DEBUG_ADVICE));
}
/* External command failed. */
void
guestfs_int_external_command_failed (guestfs_h *g, int status,
- const char *cmd_name, const char *extra)
+ const char *cmd_name,
+ const char *extra)
{
size_t len = 80 + strlen (cmd_name);
CLEANUP_FREE char *status_string = safe_malloc (g, len);
@@ -336,19 +343,19 @@ guestfs_int_external_command_failed (guestfs_h *g, int status,
if (!extra)
error (g, _("%s, see debug messages above"), status_string);
else
- error (g, _("%s: %s: %s, see debug messages above"),
- cmd_name, extra, status_string);
+ error (g, _("%s: %s: %s, see debug messages above"), cmd_name, extra,
+ status_string);
}
else {
if (!extra)
error (g, _("%s.\n"
- "To see full error messages you may need to enable debugging.\n"
- DEBUG_ADVICE),
+ "To see full error messages you may need to enable "
+ "debugging.\n" DEBUG_ADVICE),
status_string);
else
error (g, _("%s: %s: %s.\n"
- "To see full error messages you may need to enable debugging.\n"
- DEBUG_ADVICE),
+ "To see full error messages you may need to enable "
+ "debugging.\n" DEBUG_ADVICE),
cmd_name, extra, status_string);
}
}
diff --git a/src/events.c b/src/events.c
index 2d065b8..789bd14 100644
--- a/src/events.c
+++ b/src/events.c
@@ -29,11 +29,8 @@
#include "guestfs-internal.h"
int
-guestfs_set_event_callback (guestfs_h *g,
- guestfs_event_callback cb,
- uint64_t event_bitmask,
- int flags,
- void *opaque)
+guestfs_set_event_callback (guestfs_h *g, guestfs_event_callback cb,
+ uint64_t event_bitmask, int flags, void *opaque)
{
int event_handle;
@@ -52,10 +49,9 @@ guestfs_set_event_callback (guestfs_h *g,
return -1;
}
- event_handle = (int) g->nr_events;
+ event_handle = (int)g->nr_events;
g->events =
- safe_realloc (g, g->events,
- (g->nr_events+1) * sizeof (struct event));
+ safe_realloc (g, g->events, (g->nr_events + 1) * sizeof (struct event));
g->nr_events++;
g->events[event_handle].event_bitmask = event_bitmask;
@@ -69,7 +65,7 @@ guestfs_set_event_callback (guestfs_h *g,
void
guestfs_delete_event_callback (guestfs_h *g, int event_handle)
{
- if (event_handle < 0 || event_handle >= (int) g->nr_events)
+ if (event_handle < 0 || event_handle >= (int)g->nr_events)
return;
/* Set the event_bitmask to 0, which will ensure that this callback
@@ -83,7 +79,7 @@ guestfs_delete_event_callback (guestfs_h *g, int event_handle)
* problem that this structure is not well-suited to handling large
* numbers of event handlers.
*/
- if ((unsigned) event_handle == g->nr_events-1)
+ if ((unsigned)event_handle == g->nr_events - 1)
g->nr_events--;
}
@@ -96,7 +92,8 @@ guestfs_int_call_callbacks_void (guestfs_h *g, uint64_t event)
for (i = 0; i < g->nr_events; ++i)
if ((g->events[i].event_bitmask & event) != 0)
- g->events[i].cb (g, g->events[i].opaque, event, i, 0, NULL, 0, NULL, 0);
+ g->events[i].cb (g, g->events[i].opaque, event, i, 0, NULL, 0, NULL,
+ 0);
/* All events with payload type void are discarded if no callback
* was registered.
@@ -105,14 +102,14 @@ guestfs_int_call_callbacks_void (guestfs_h *g, uint64_t event)
void
guestfs_int_call_callbacks_message (guestfs_h *g, uint64_t event,
- const char *buf, size_t buf_len)
+ const char *buf, size_t buf_len)
{
size_t i, count = 0;
for (i = 0; i < g->nr_events; ++i)
if ((g->events[i].event_bitmask & event) != 0) {
- g->events[i].cb (g, g->events[i].opaque, event, i, 0,
- buf, buf_len, NULL, 0);
+ g->events[i].cb (g, g->events[i].opaque, event, i, 0, buf, buf_len,
+ NULL, 0);
count++;
}
@@ -124,12 +121,9 @@ guestfs_int_call_callbacks_message (guestfs_h *g, uint64_t event,
if (count > 0)
return;
- if ((event == GUESTFS_EVENT_APPLIANCE ||
- event == GUESTFS_EVENT_LIBRARY ||
- event == GUESTFS_EVENT_WARNING ||
- event == GUESTFS_EVENT_TRACE) &&
- (g->verbose ||
- event == GUESTFS_EVENT_WARNING ||
+ if ((event == GUESTFS_EVENT_APPLIANCE || event == GUESTFS_EVENT_LIBRARY ||
+ event == GUESTFS_EVENT_WARNING || event == GUESTFS_EVENT_TRACE) &&
+ (g->verbose || event == GUESTFS_EVENT_WARNING ||
event == GUESTFS_EVENT_TRACE)) {
bool from_appliance = event == GUESTFS_EVENT_APPLIANCE;
size_t i0;
@@ -154,51 +148,68 @@ guestfs_int_call_callbacks_message (guestfs_h *g, uint64_t event,
}
}
- /* Special or non-printing characters in the buffer must be
- * escaped (RHBZ#731744). The buffer can contain any 8 bit
- * character, even \0.
- *
- * Handling of \n and \r characters is complex:
- *
- * Case 1: Messages from the appliance: These messages already
- * contain \n and \r characters at logical positions, so we just
- * echo those out directly.
- *
- * Case 2: Messages from other sources: These messages should NOT
- * contain \n or \r. If they do, it is escaped. However we also
- * need to print a real end of line after these messages.
- *
- * RHBZ#802109: Because stderr is usually not buffered, avoid
- * single 'putc' calls (which translate to a 1 byte write), and
- * try to send longest possible strings in single fwrite calls
- * (thanks to Jim Meyering for the basic approach).
- */
-#define NO_ESCAPING(c) \
- (c_isprint ((c)) || (from_appliance && ((c) == '\n' || (c) ==
'\r')))
+/* Special or non-printing characters in the buffer must be
+ * escaped (RHBZ#731744). The buffer can contain any 8 bit
+ * character, even \0.
+ *
+ * Handling of \n and \r characters is complex:
+ *
+ * Case 1: Messages from the appliance: These messages already
+ * contain \n and \r characters at logical positions, so we just
+ * echo those out directly.
+ *
+ * Case 2: Messages from other sources: These messages should NOT
+ * contain \n or \r. If they do, it is escaped. However we also
+ * need to print a real end of line after these messages.
+ *
+ * RHBZ#802109: Because stderr is usually not buffered, avoid
+ * single 'putc' calls (which translate to a 1 byte write), and
+ * try to send longest possible strings in single fwrite calls
+ * (thanks to Jim Meyering for the basic approach).
+ */
+#define NO_ESCAPING(c) \
+ (c_isprint ((c)) || (from_appliance && ((c) == '\n' || (c) ==
'\r')))
for (i = 0; i < buf_len; ++i) {
if (NO_ESCAPING (buf[i])) {
i0 = i;
while (i < buf_len && NO_ESCAPING (buf[i]))
++i;
- fwrite (&buf[i0], 1, i-i0, stderr);
+ fwrite (&buf[i0], 1, i - i0, stderr);
/* Adjust i so that next time around the loop, the next
* non-printing character will be displayed.
*/
if (i < buf_len)
--i;
- } else {
+ }
+ else {
switch (buf[i]) {
- case '\0': fputs ("\\0", stderr); break;
- case '\a': fputs ("\\a", stderr); break;
- case '\b': fputs ("\\b", stderr); break;
- case '\f': fputs ("\\f", stderr); break;
- case '\n': fputs ("\\n", stderr); break;
- case '\r': fputs ("\\r", stderr); break;
- case '\t': fputs ("\\t", stderr); break;
- case '\v': fputs ("\\v", stderr); break;
+ case '\0':
+ fputs ("\\0", stderr);
+ break;
+ case '\a':
+ fputs ("\\a", stderr);
+ break;
+ case '\b':
+ fputs ("\\b", stderr);
+ break;
+ case '\f':
+ fputs ("\\f", stderr);
+ break;
+ case '\n':
+ fputs ("\\n", stderr);
+ break;
+ case '\r':
+ fputs ("\\r", stderr);
+ break;
+ case '\t':
+ fputs ("\\t", stderr);
+ break;
+ case '\v':
+ fputs ("\\v", stderr);
+ break;
default:
- fprintf (stderr, "\\x%x", (unsigned char) buf[i]);
+ fprintf (stderr, "\\x%x", (unsigned char)buf[i]);
}
}
}
@@ -210,14 +221,14 @@ guestfs_int_call_callbacks_message (guestfs_h *g, uint64_t event,
void
guestfs_int_call_callbacks_array (guestfs_h *g, uint64_t event,
- const uint64_t *array, size_t array_len)
+ const uint64_t *array, size_t array_len)
{
size_t i;
for (i = 0; i < g->nr_events; ++i)
if ((g->events[i].event_bitmask & event) != 0)
- g->events[i].cb (g, g->events[i].opaque, event, i, 0,
- NULL, 0, array, array_len);
+ g->events[i].cb (g, g->events[i].opaque, event, i, 0, NULL, 0, array,
+ array_len);
/* All events with payload type array are discarded if no callback
* was registered.
@@ -233,10 +244,8 @@ guestfs_int_call_callbacks_array (guestfs_h *g, uint64_t event,
*/
static void
-replace_old_style_event_callback (guestfs_h *g,
- guestfs_event_callback cb,
- uint64_t event_bitmask,
- void *opaque,
+replace_old_style_event_callback (guestfs_h *g, guestfs_event_callback cb,
+ uint64_t event_bitmask, void *opaque,
void *opaque2)
{
size_t i;
@@ -264,11 +273,10 @@ replace_old_style_event_callback (guestfs_h *g,
/* i == g->nr_events */
g->events =
- safe_realloc (g, g->events,
- (g->nr_events+1) * sizeof (struct event));
+ safe_realloc (g, g->events, (g->nr_events + 1) * sizeof (struct event));
g->nr_events++;
- replace:
+replace:
g->events[i].event_bitmask = event_bitmask;
g->events[i].cb = cb;
g->events[i].opaque = opaque;
@@ -276,39 +284,33 @@ replace_old_style_event_callback (guestfs_h *g,
}
static void
-log_message_callback_wrapper (guestfs_h *g,
- void *opaque,
- uint64_t event,
- int event_handle,
- int flags,
- const char *buf, size_t buf_len,
- const uint64_t *array, size_t array_len)
+log_message_callback_wrapper (guestfs_h *g, void *opaque, uint64_t event,
+ int event_handle, int flags, const char *buf,
+ size_t buf_len, const uint64_t *array,
+ size_t array_len)
{
guestfs_log_message_cb cb = g->events[event_handle].opaque2;
/* Note that the old callback declared the message buffer as
* (char *, int). I sure hope message buffers aren't too large
* and that callers aren't writing to them. XXX
*/
- cb (g, opaque, (char *) buf, (int) buf_len);
+ cb (g, opaque, (char *)buf, (int)buf_len);
}
void
-guestfs_set_log_message_callback (guestfs_h *g,
- guestfs_log_message_cb cb, void *opaque)
+guestfs_set_log_message_callback (guestfs_h *g, guestfs_log_message_cb cb,
+ void *opaque)
{
replace_old_style_event_callback (g, log_message_callback_wrapper,
- GUESTFS_EVENT_APPLIANCE,
- opaque, cb);
+ GUESTFS_EVENT_APPLIANCE, opaque, cb);
}
static void
-subprocess_quit_callback_wrapper (guestfs_h *g,
- void *opaque,
- uint64_t event,
- int event_handle,
- int flags,
- const char *buf, size_t buf_len,
- const uint64_t *array, size_t array_len)
+subprocess_quit_callback_wrapper (guestfs_h *g, void *opaque,
+ uint64_t event, int event_handle,
+ int flags, const char *buf,
+ size_t buf_len, const uint64_t *array,
+ size_t array_len)
{
guestfs_subprocess_quit_cb cb = g->events[event_handle].opaque2;
cb (g, opaque);
@@ -316,76 +318,64 @@ subprocess_quit_callback_wrapper (guestfs_h *g,
void
guestfs_set_subprocess_quit_callback (guestfs_h *g,
- guestfs_subprocess_quit_cb cb, void *opaque)
+ guestfs_subprocess_quit_cb cb,
+ void *opaque)
{
replace_old_style_event_callback (g, subprocess_quit_callback_wrapper,
- GUESTFS_EVENT_SUBPROCESS_QUIT,
- opaque, cb);
+ GUESTFS_EVENT_SUBPROCESS_QUIT, opaque,
+ cb);
}
static void
-launch_done_callback_wrapper (guestfs_h *g,
- void *opaque,
- uint64_t event,
- int event_handle,
- int flags,
- const char *buf, size_t buf_len,
- const uint64_t *array, size_t array_len)
+launch_done_callback_wrapper (guestfs_h *g, void *opaque, uint64_t event,
+ int event_handle, int flags, const char *buf,
+ size_t buf_len, const uint64_t *array,
+ size_t array_len)
{
guestfs_launch_done_cb cb = g->events[event_handle].opaque2;
cb (g, opaque);
}
void
-guestfs_set_launch_done_callback (guestfs_h *g,
- guestfs_launch_done_cb cb, void *opaque)
+guestfs_set_launch_done_callback (guestfs_h *g, guestfs_launch_done_cb cb,
+ void *opaque)
{
replace_old_style_event_callback (g, launch_done_callback_wrapper,
- GUESTFS_EVENT_LAUNCH_DONE,
- opaque, cb);
+ GUESTFS_EVENT_LAUNCH_DONE, opaque, cb);
}
static void
-close_callback_wrapper (guestfs_h *g,
- void *opaque,
- uint64_t event,
- int event_handle,
- int flags,
- const char *buf, size_t buf_len,
- const uint64_t *array, size_t array_len)
+close_callback_wrapper (guestfs_h *g, void *opaque, uint64_t event,
+ int event_handle, int flags, const char *buf,
+ size_t buf_len, const uint64_t *array,
+ size_t array_len)
{
guestfs_close_cb cb = g->events[event_handle].opaque2;
cb (g, opaque);
}
void
-guestfs_set_close_callback (guestfs_h *g,
- guestfs_close_cb cb, void *opaque)
+guestfs_set_close_callback (guestfs_h *g, guestfs_close_cb cb, void *opaque)
{
replace_old_style_event_callback (g, close_callback_wrapper,
- GUESTFS_EVENT_CLOSE,
- opaque, cb);
+ GUESTFS_EVENT_CLOSE, opaque, cb);
}
static void
-progress_callback_wrapper (guestfs_h *g,
- void *opaque,
- uint64_t event,
- int event_handle,
- int flags,
- const char *buf, size_t buf_len,
- const uint64_t *array, size_t array_len)
+progress_callback_wrapper (guestfs_h *g, void *opaque, uint64_t event,
+ int event_handle, int flags, const char *buf,
+ size_t buf_len, const uint64_t *array,
+ size_t array_len)
{
guestfs_progress_cb cb = g->events[event_handle].opaque2;
assert (array_len >= 4);
- cb (g, opaque, (int) array[0], (int) array[1], array[2], array[3]);
+ cb (g, opaque, (int)array[0], (int)array[1], array[2], array[3]);
}
void
-guestfs_set_progress_callback (guestfs_h *g,
- guestfs_progress_cb cb, void *opaque)
+guestfs_set_progress_callback (guestfs_h *g, guestfs_progress_cb cb,
+ void *opaque)
{
replace_old_style_event_callback (g, progress_callback_wrapper,
- GUESTFS_EVENT_PROGRESS,
- opaque, cb);
+ GUESTFS_EVENT_PROGRESS, opaque, cb);
}
diff --git a/src/file.c b/src/file.c
index d57c4e1..b8377a3 100644
--- a/src/file.c
+++ b/src/file.c
@@ -36,8 +36,8 @@
static int
compare (const void *vp1, const void *vp2)
{
- char * const *p1 = (char * const *) vp1;
- char * const *p2 = (char * const *) vp2;
+ char *const *p1 = (char *const *)vp1;
+ char *const *p2 = (char *const *)vp2;
return strcmp (*p1, *p2);
}
@@ -52,11 +52,12 @@ sort_strings (char **argv, size_t len)
* then it is updated with the pointer to the list of remaining names.
*/
static char **
-take_strings (guestfs_h *g, char *const *names, size_t n, char *const **lastp)
+take_strings (guestfs_h *g, char *const *names, size_t n,
+ char *const **lastp)
{
size_t i;
- char **ret = safe_malloc (g, (n+1) * sizeof (char *));
+ char **ret = safe_malloc (g, (n + 1) * sizeof (char *));
for (i = 0; names[i] != NULL && i < n; ++i)
ret[i] = names[i];
@@ -94,7 +95,7 @@ guestfs_impl_read_file (guestfs_h *g, const char *path, size_t *size_r)
if (guestfs_download (g, path, tmpfile) == -1)
goto err;
- fd = open (tmpfile, O_RDONLY|O_CLOEXEC);
+ fd = open (tmpfile, O_RDONLY | O_CLOEXEC);
if (fd == -1) {
perrorf (g, "open: %s", tmpfile);
goto err;
@@ -106,7 +107,8 @@ guestfs_impl_read_file (guestfs_h *g, const char *path, size_t
*size_r)
goto err;
}
- /* Don't use safe_malloc, because we want to return an errno to the caller. */
+ /* Don't use safe_malloc, because we want to return an errno to the
+ * caller. */
size = statbuf.st_size;
ret = malloc (size + 1);
if (!ret) {
@@ -132,7 +134,7 @@ guestfs_impl_read_file (guestfs_h *g, const char *path, size_t
*size_r)
*size_r = size;
return ret;
- err:
+err:
free (ret);
if (fd >= 0)
close (fd);
@@ -160,7 +162,7 @@ guestfs_impl_read_lines (guestfs_h *g, const char *file)
for (i = 0; i < size; ++i)
if (buf[i] == '\n')
count++;
- if (size > 0 && buf[size-1] != '\n')
+ if (size > 0 && buf[size - 1] != '\n')
count++;
ret = malloc ((count + 1) * sizeof (char *));
@@ -175,8 +177,8 @@ guestfs_impl_read_lines (guestfs_h *g, const char *file)
for (i = 0; i < size; ++i) {
if (buf[i] == '\n') {
buf[i] = '\0';
- if (i+1 < size)
- ret[count++] = &buf[i+1];
+ if (i + 1 < size)
+ ret[count++] = &buf[i + 1];
}
}
}
@@ -192,13 +194,13 @@ guestfs_impl_read_lines (guestfs_h *g, const char *file)
goto err;
}
len = strlen (ret[i]);
- if (len > 0 && ret[i][len-1] == '\r')
- ret[i][len-1] = '\0';
+ if (len > 0 && ret[i][len - 1] == '\r')
+ ret[i][len - 1] = '\0';
}
return ret;
- err:
+err:
free (ret);
return NULL;
}
@@ -221,7 +223,7 @@ guestfs_impl_find (guestfs_h *g, const char *directory)
if (guestfs_find0 (g, directory, tmpfile) == -1)
goto err;
- fd = open (tmpfile, O_RDONLY|O_CLOEXEC);
+ fd = open (tmpfile, O_RDONLY | O_CLOEXEC);
if (fd == -1) {
perrorf (g, "open: %s", tmpfile);
goto err;
@@ -233,7 +235,8 @@ guestfs_impl_find (guestfs_h *g, const char *directory)
goto err;
}
- /* Don't use safe_malloc, because we want to return an errno to the caller. */
+ /* Don't use safe_malloc, because we want to return an errno to the
+ * caller. */
size = statbuf.st_size;
buf = malloc (size);
if (!buf) {
@@ -272,7 +275,7 @@ guestfs_impl_find (guestfs_h *g, const char *directory)
ret[count++] = buf;
for (i = 0; i < size; ++i) {
if (buf[i] == '\0')
- ret[count++] = &buf[i+1];
+ ret[count++] = &buf[i + 1];
}
ret[--count] = NULL;
@@ -291,9 +294,9 @@ guestfs_impl_find (guestfs_h *g, const char *directory)
sort_strings (ret, count);
- return ret; /* caller frees */
+ return ret; /* caller frees */
- err:
+err:
free (ret);
if (fd >= 0)
close (fd);
@@ -301,9 +304,8 @@ guestfs_impl_find (guestfs_h *g, const char *directory)
}
static int
-write_or_append (guestfs_h *g, const char *path,
- const char *content, size_t size,
- int append)
+write_or_append (guestfs_h *g, const char *path, const char *content,
+ size_t size, int append)
{
CLEANUP_UNLINK_FREE char *tmpfile = NULL;
int fd = -1;
@@ -312,10 +314,10 @@ write_or_append (guestfs_h *g, const char *path,
/* If the content is small enough, use guestfs_internal_write{,_append}
* since that call is more efficient.
*/
- if (size <= 2*1024*1024)
- return
- (!append ? guestfs_internal_write : guestfs_internal_write_append)
- (g, path, content, size);
+ if (size <= 2 * 1024 * 1024)
+ return (!append
+ ? guestfs_internal_write
+ : guestfs_internal_write_append) (g, path, content, size);
if (guestfs_int_lazy_make_tmpdir (g) == -1)
goto err;
@@ -323,7 +325,7 @@ write_or_append (guestfs_h *g, const char *path,
/* Write the content out to a temporary file. */
tmpfile = safe_asprintf (g, "%s/write%d", g->tmpdir, ++g->unique);
- fd = open (tmpfile, O_WRONLY|O_CREAT|O_NOCTTY|O_CLOEXEC, 0600);
+ fd = open (tmpfile, O_WRONLY | O_CREAT | O_NOCTTY | O_CLOEXEC, 0600);
if (fd == -1) {
perrorf (g, "open: %s", tmpfile);
goto err;
@@ -355,22 +357,22 @@ write_or_append (guestfs_h *g, const char *path,
return 0;
- err:
+err:
if (fd >= 0)
close (fd);
return -1;
}
int
-guestfs_impl_write (guestfs_h *g, const char *path,
- const char *content, size_t size)
+guestfs_impl_write (guestfs_h *g, const char *path, const char *content,
+ size_t size)
{
return write_or_append (g, path, content, size, 0);
}
int
guestfs_impl_write_append (guestfs_h *g, const char *path,
- const char *content, size_t size)
+ const char *content, size_t size)
{
return write_or_append (g, path, content, size, 1);
}
@@ -378,7 +380,7 @@ guestfs_impl_write_append (guestfs_h *g, const char *path,
#define LSTATNSLIST_MAX 1000
struct guestfs_statns_list *
-guestfs_impl_lstatnslist (guestfs_h *g, const char *dir, char * const*names)
+guestfs_impl_lstatnslist (guestfs_h *g, const char *dir, char *const *names)
{
size_t len = guestfs_int_count_strings (names);
size_t old_len;
@@ -394,7 +396,8 @@ guestfs_impl_lstatnslist (guestfs_h *g, const char *dir, char *
const*names)
/* Note we don't need to free up the strings because take_strings
* does not do a deep copy.
*/
- CLEANUP_FREE char **first = take_strings (g, names, LSTATNSLIST_MAX, &names);
+ CLEANUP_FREE char **first =
+ take_strings (g, names, LSTATNSLIST_MAX, &names);
len = len <= LSTATNSLIST_MAX ? 0 : len - LSTATNSLIST_MAX;
@@ -408,8 +411,8 @@ guestfs_impl_lstatnslist (guestfs_h *g, const char *dir, char *
const*names)
/* Append stats to ret. */
old_len = ret->len;
ret->len += stats->len;
- ret->val = safe_realloc (g, ret->val,
- ret->len * sizeof (struct guestfs_statns));
+ ret->val =
+ safe_realloc (g, ret->val, ret->len * sizeof (struct guestfs_statns));
memcpy (&ret->val[old_len], stats->val,
stats->len * sizeof (struct guestfs_statns));
}
@@ -436,7 +439,8 @@ guestfs_impl_lxattrlist (guestfs_h *g, const char *dir, char *const
*names)
/* Note we don't need to free up the strings because take_strings
* does not do a deep copy.
*/
- CLEANUP_FREE char **first = take_strings (g, names, LXATTRLIST_MAX, &names);
+ CLEANUP_FREE char **first =
+ take_strings (g, names, LXATTRLIST_MAX, &names);
len = len <= LXATTRLIST_MAX ? 0 : len - LXATTRLIST_MAX;
xattrs = guestfs_internal_lxattrlist (g, dir, first);
@@ -449,13 +453,14 @@ guestfs_impl_lxattrlist (guestfs_h *g, const char *dir, char *const
*names)
/* Append xattrs to ret. */
old_len = ret->len;
ret->len += xattrs->len;
- ret->val = safe_realloc (g, ret->val,
- ret->len * sizeof (struct guestfs_xattr));
+ ret->val =
+ safe_realloc (g, ret->val, ret->len * sizeof (struct guestfs_xattr));
for (i = 0; i < xattrs->len; ++i, ++old_len) {
/* We have to make a deep copy of the attribute name and value.
*/
ret->val[old_len].attrname = safe_strdup (g, xattrs->val[i].attrname);
- ret->val[old_len].attrval = safe_malloc (g, xattrs->val[i].attrval_len);
+ ret->val[old_len].attrval =
+ safe_malloc (g, xattrs->val[i].attrval_len);
ret->val[old_len].attrval_len = xattrs->val[i].attrval_len;
memcpy (ret->val[old_len].attrval, xattrs->val[i].attrval,
xattrs->val[i].attrval_len);
@@ -468,7 +473,8 @@ guestfs_impl_lxattrlist (guestfs_h *g, const char *dir, char *const
*names)
#define READLINK_MAX 1000
char **
-guestfs_impl_readlinklist (guestfs_h *g, const char *dir, char *const *names)
+guestfs_impl_readlinklist (guestfs_h *g, const char *dir,
+ char *const *names)
{
size_t len = guestfs_int_count_strings (names);
size_t old_len, ret_len = 0;
@@ -480,7 +486,8 @@ guestfs_impl_readlinklist (guestfs_h *g, const char *dir, char *const
*names)
* deep copy.
*/
CLEANUP_FREE char **links = NULL;
- CLEANUP_FREE char **first = take_strings (g, names, READLINK_MAX, &names);
+ CLEANUP_FREE char **first =
+ take_strings (g, names, READLINK_MAX, &names);
len = len <= READLINK_MAX ? 0 : len - READLINK_MAX;
links = guestfs_internal_readlinklist (g, dir, first);
@@ -495,11 +502,11 @@ guestfs_impl_readlinklist (guestfs_h *g, const char *dir, char
*const *names)
old_len = ret_len;
ret_len += guestfs_int_count_strings (links);
ret = safe_realloc (g, ret, ret_len * sizeof (char *));
- memcpy (&ret[old_len], links, (ret_len-old_len) * sizeof (char *));
+ memcpy (&ret[old_len], links, (ret_len - old_len) * sizeof (char *));
}
/* NULL-terminate the list. */
- ret = safe_realloc (g, ret, (ret_len+1) * sizeof (char *));
+ ret = safe_realloc (g, ret, (ret_len + 1) * sizeof (char *));
ret[ret_len] = NULL;
return ret;
@@ -523,7 +530,7 @@ guestfs_impl_ls (guestfs_h *g, const char *directory)
if (guestfs_ls0 (g, directory, tmpfile) == -1)
goto err;
- fd = open (tmpfile, O_RDONLY|O_CLOEXEC);
+ fd = open (tmpfile, O_RDONLY | O_CLOEXEC);
if (fd == -1) {
perrorf (g, "open: %s", tmpfile);
goto err;
@@ -535,7 +542,8 @@ guestfs_impl_ls (guestfs_h *g, const char *directory)
goto err;
}
- /* Don't use safe_malloc, because we want to return an errno to the caller. */
+ /* Don't use safe_malloc, because we want to return an errno to the
+ * caller. */
size = statbuf.st_size;
buf = malloc (size);
if (!buf) {
@@ -573,7 +581,7 @@ guestfs_impl_ls (guestfs_h *g, const char *directory)
ret[count++] = buf;
for (i = 0; i < size; ++i) {
if (buf[i] == '\0')
- ret[count++] = &buf[i+1];
+ ret[count++] = &buf[i + 1];
}
ret[--count] = NULL;
@@ -592,9 +600,9 @@ guestfs_impl_ls (guestfs_h *g, const char *directory)
sort_strings (ret, count);
- return ret; /* caller frees */
+ return ret; /* caller frees */
- err:
+err:
free (ret);
if (fd >= 0)
close (fd);
@@ -631,7 +639,7 @@ guestfs_impl_stat (guestfs_h *g, const char *path)
ret = safe_malloc (g, sizeof *ret);
statns_to_old_stat (r, ret);
- return ret; /* caller frees */
+ return ret; /* caller frees */
}
struct guestfs_stat *
@@ -646,11 +654,11 @@ guestfs_impl_lstat (guestfs_h *g, const char *path)
ret = safe_malloc (g, sizeof *ret);
statns_to_old_stat (r, ret);
- return ret; /* caller frees */
+ return ret; /* caller frees */
}
struct guestfs_stat_list *
-guestfs_impl_lstatlist (guestfs_h *g, const char *dir, char * const*names)
+guestfs_impl_lstatlist (guestfs_h *g, const char *dir, char *const *names)
{
CLEANUP_FREE_STATNS_LIST struct guestfs_statns_list *r;
struct guestfs_stat_list *ret;
diff --git a/src/filearch.c b/src/filearch.c
index 5985b73..5edab77 100644
--- a/src/filearch.c
+++ b/src/filearch.c
@@ -39,31 +39,34 @@
#if defined(HAVE_LIBMAGIC)
-# ifdef HAVE_ATTRIBUTE_CLEANUP
-# define CLEANUP_MAGIC_T_FREE __attribute__((cleanup(cleanup_magic_t_free)))
+#ifdef HAVE_ATTRIBUTE_CLEANUP
+#define CLEANUP_MAGIC_T_FREE \
+ __attribute__((cleanup (cleanup_magic_t_free)))
static void
cleanup_magic_t_free (void *ptr)
{
- magic_t m = *(magic_t *) ptr;
+ magic_t m = *(magic_t *)ptr;
if (m)
magic_close (m);
}
-# else
-# define CLEANUP_MAGIC_T_FREE
-# endif
+#else
+#define CLEANUP_MAGIC_T_FREE
+#endif
-COMPILE_REGEXP (re_file_elf,
- "ELF.*(MSB|LSB).*(?:executable|shared object|relocatable),
(.+?),", 0)
+COMPILE_REGEXP (
+ re_file_elf,
+ "ELF.*(MSB|LSB).*(?:executable|shared object|relocatable), (.+?),", 0)
COMPILE_REGEXP (re_elf_ppc64, ".*64.*PowerPC", 0)
/* Convert output from 'file' command on ELF files to the canonical
* architecture string. Caller must free the result.
*/
static char *
-canonical_elf_arch (guestfs_h *g, const char *endianness, const char *elf_arch)
+canonical_elf_arch (guestfs_h *g, const char *endianness,
+ const char *elf_arch)
{
const char *r;
char *ret;
@@ -164,15 +167,9 @@ magic_for_file (guestfs_h *g, const char *filename, bool
*loading_ok,
/* Download and uncompress the cpio file to find binaries within. */
static const char *initrd_binaries[] = {
- "bin/ls",
- "bin/rm",
- "bin/modprobe",
- "sbin/modprobe",
- "bin/sh",
- "bin/bash",
- "bin/dash",
- "bin/nash",
- NULL
+ "bin/ls", "bin/rm", "bin/modprobe",
+ "sbin/modprobe", "bin/sh", "bin/bash",
+ "bin/dash", "bin/nash", NULL
};
static char *
@@ -202,8 +199,8 @@ cpio_arch (guestfs_h *g, const char *file, const char *path)
/* Security: Refuse to download initrd if it is huge. */
size = guestfs_filesize (g, path);
if (size == -1 || size > 100000000) {
- error (g, _("size of %s unreasonable (%" PRIi64 " bytes)"),
- path, size);
+ error (g, _("size of %s unreasonable (%" PRIi64 " bytes)"),
path,
+ size);
goto out;
}
@@ -218,7 +215,7 @@ cpio_arch (guestfs_h *g, const char *file, const char *path)
/* Construct a command to extract named binaries from the initrd file. */
guestfs_int_cmd_add_string_unquoted (cmd, "cd ");
- guestfs_int_cmd_add_string_quoted (cmd, dir);
+ guestfs_int_cmd_add_string_quoted (cmd, dir);
guestfs_int_cmd_add_string_unquoted (cmd, " && ");
guestfs_int_cmd_add_string_unquoted (cmd, method);
guestfs_int_cmd_add_string_unquoted (cmd, " initrd | cpio --quiet -id");
@@ -247,9 +244,11 @@ cpio_arch (guestfs_h *g, const char *file, const char *path)
goto out;
}
}
- error (g, "file_architecture: could not determine architecture of cpio
archive");
+ error (
+ g,
+ "file_architecture: could not determine architecture of cpio archive");
- out:
+out:
guestfs_int_recursive_remove_dir (g, dir);
return ret;
@@ -274,8 +273,8 @@ compressed_file_arch (guestfs_h *g, const char *path, const char
*method)
/* Security: Refuse to download file if it is huge. */
size = guestfs_filesize (g, path);
if (size == -1 || size > 10000000) {
- error (g, _("size of %s unreasonable (%" PRIi64 " bytes)"),
- path, size);
+ error (g, _("size of %s unreasonable (%" PRIi64 " bytes)"),
path,
+ size);
goto out;
}
@@ -307,9 +306,10 @@ compressed_file_arch (guestfs_h *g, const char *path, const char
*method)
ret = magic_for_file (g, tempfile_extracted, NULL, &matched);
if (!matched)
- error (g, "file_architecture: could not determine architecture of compressed
file");
+ error (g, "file_architecture: could not determine architecture of "
+ "compressed file");
- out:
+out:
guestfs_int_recursive_remove_dir (g, dir);
return ret;
@@ -345,21 +345,23 @@ guestfs_impl_file_architecture (guestfs_h *g, const char *path)
else
error (g, "file_architecture: unknown architecture: %s", path);
- return ret; /* caller frees */
+ return ret; /* caller frees */
}
#else /* no libmagic at compile time */
/* XXX Should be an optgroup. */
-#define NOT_IMPL(r) \
- error (g, _("file-architecture API not available since this version of libguestfs
was compiled without the libmagic library")); \
+#define NOT_IMPL(r) \
+ error (g, \
+ _("file-architecture API not available since this version of " \
+ "libguestfs was compiled without the libmagic library")); \
return r
char *
guestfs_impl_file_architecture (guestfs_h *g, const char *path)
{
- NOT_IMPL(NULL);
+ NOT_IMPL (NULL);
}
#endif /* no libmagic at compile time */
diff --git a/src/fuse.c b/src/fuse.c
index cb8274f..f3202e6 100644
--- a/src/fuse.c
+++ b/src/fuse.c
@@ -55,39 +55,43 @@ static int init_dir_caches (guestfs_h *);
static void free_dir_caches (guestfs_h *);
static void dir_cache_remove_all_expired (guestfs_h *, time_t now);
static void dir_cache_invalidate (guestfs_h *, const char *path);
-static int lsc_insert (guestfs_h *, const char *path, const char *name, time_t now,
struct stat const *statbuf);
-static int xac_insert (guestfs_h *, const char *path, const char *name, time_t now,
struct guestfs_xattr_list *xattrs);
-static int rlc_insert (guestfs_h *, const char *path, const char *name, time_t now, char
*link);
+static int lsc_insert (guestfs_h *, const char *path, const char *name,
+ time_t now, struct stat const *statbuf);
+static int xac_insert (guestfs_h *, const char *path, const char *name,
+ time_t now, struct guestfs_xattr_list *xattrs);
+static int rlc_insert (guestfs_h *, const char *path, const char *name,
+ time_t now, char *link);
static const struct stat *lsc_lookup (guestfs_h *, const char *pathname);
-static const struct guestfs_xattr_list *xac_lookup (guestfs_h *, const char *pathname);
+static const struct guestfs_xattr_list *xac_lookup (guestfs_h *,
+ const char *pathname);
static const char *rlc_lookup (guestfs_h *, const char *pathname);
/* This lock protects access to g->localmountpoint. */
gl_lock_define_initialized (static, mount_local_lock);
-#define DECL_G() guestfs_h *g = fuse_get_context()->private_data
-#define DEBUG_CALL(fs,...) \
- if (g->ml_debug_calls) { \
- debug (g, \
- "%s: %s (" fs ")", \
- g->localmountpoint, __func__, ## __VA_ARGS__); \
+#define DECL_G() guestfs_h *g = fuse_get_context ()->private_data
+#define DEBUG_CALL(fs, ...) \
+ if (g->ml_debug_calls) { \
+ debug (g, "%s: %s (" fs ")", g->localmountpoint, __func__, \
+ ##__VA_ARGS__); \
}
-#define RETURN_ERRNO \
- do { \
- int ret_errno = guestfs_last_errno (g); \
- \
- /* 0 doesn't mean "no error". It means the errno was not \
- * captured. Therefore we have to substitute an errno here. \
- */ \
- if (ret_errno == 0) \
- ret_errno = EINVAL; \
- \
- return -ret_errno; \
+#define RETURN_ERRNO \
+ do { \
+ int ret_errno = guestfs_last_errno (g); \
+ \
+ /* 0 doesn't mean "no error". It means the errno was not \
+ * captured. Therefore we have to substitute an errno here. \
+ */ \
+ if (ret_errno == 0) \
+ ret_errno = EINVAL; \
+ \
+ return -ret_errno; \
} while (0)
static struct guestfs_xattr_list *
-copy_xattr_list (guestfs_h *g, const struct guestfs_xattr *first, size_t num)
+copy_xattr_list (guestfs_h *g, const struct guestfs_xattr *first,
+ size_t num)
{
struct guestfs_xattr_list *xattrs;
size_t i;
@@ -125,7 +129,7 @@ mount_local_readdir (const char *path, void *buf, fuse_fill_dir_t
filler,
char **names;
CLEANUP_FREE_DIRENT_LIST struct guestfs_dirent_list *ents = NULL;
DECL_G ();
- DEBUG_CALL ("%s, %p, %ld", path, buf, (long) offset);
+ DEBUG_CALL ("%s, %p, %ld", path, buf, (long)offset);
time (&now);
@@ -141,16 +145,31 @@ mount_local_readdir (const char *path, void *buf, fuse_fill_dir_t
filler,
stat.st_ino = ents->val[i].ino;
switch (ents->val[i].ftyp) {
- case 'b': stat.st_mode = S_IFBLK; break;
- case 'c': stat.st_mode = S_IFCHR; break;
- case 'd': stat.st_mode = S_IFDIR; break;
- case 'f': stat.st_mode = S_IFIFO; break;
- case 'l': stat.st_mode = S_IFLNK; break;
- case 'r': stat.st_mode = S_IFREG; break;
- case 's': stat.st_mode = S_IFSOCK; break;
+ case 'b':
+ stat.st_mode = S_IFBLK;
+ break;
+ case 'c':
+ stat.st_mode = S_IFCHR;
+ break;
+ case 'd':
+ stat.st_mode = S_IFDIR;
+ break;
+ case 'f':
+ stat.st_mode = S_IFIFO;
+ break;
+ case 'l':
+ stat.st_mode = S_IFLNK;
+ break;
+ case 'r':
+ stat.st_mode = S_IFREG;
+ break;
+ case 's':
+ stat.st_mode = S_IFSOCK;
+ break;
case 'u':
case '?':
- default: stat.st_mode = 0;
+ default:
+ stat.st_mode = 0;
}
/* Copied from the example, which also ignores 'offset'. I'm
@@ -221,7 +240,8 @@ mount_local_readdir (const char *path, void *buf, fuse_fill_dir_t
filler,
++i;
first = &xattrs->val[i];
num = 0;
- for (; i < xattrs->len && strlen (xattrs->val[i].attrname)
> 0; ++i)
+ for (; i < xattrs->len && strlen (xattrs->val[i].attrname)
> 0;
+ ++i)
num++;
copy = copy_xattr_list (g, first, num);
@@ -243,7 +263,7 @@ mount_local_readdir (const char *path, void *buf, fuse_fill_dir_t
filler,
/* which is why we have to free links[i] here. */
free (links[i]);
}
- free (links); /* free the array, not the strings */
+ free (links); /* free the array, not the strings */
}
free (names);
@@ -327,37 +347,36 @@ mount_local_access (const char *path, int mask)
*/
if (fuse->uid != 0) {
if (mask & R_OK)
- ok = ok &&
- ( fuse->uid == statbuf.st_uid ? statbuf.st_mode & S_IRUSR
- : fuse->gid == statbuf.st_gid ? statbuf.st_mode & S_IRGRP
- : statbuf.st_mode & S_IROTH);
+ ok =
+ ok && (fuse->uid == statbuf.st_uid
+ ? statbuf.st_mode & S_IRUSR
+ : fuse->gid == statbuf.st_gid ? statbuf.st_mode & S_IRGRP
+ : statbuf.st_mode & S_IROTH);
if (mask & W_OK)
- ok = ok &&
- ( fuse->uid == statbuf.st_uid ? statbuf.st_mode & S_IWUSR
- : fuse->gid == statbuf.st_gid ? statbuf.st_mode & S_IWGRP
- : statbuf.st_mode & S_IWOTH);
+ ok =
+ ok && (fuse->uid == statbuf.st_uid
+ ? statbuf.st_mode & S_IWUSR
+ : fuse->gid == statbuf.st_gid ? statbuf.st_mode & S_IWGRP
+ : statbuf.st_mode & S_IWOTH);
if (mask & X_OK)
- ok = ok &&
- ( fuse->uid == statbuf.st_uid ? statbuf.st_mode & S_IXUSR
- : fuse->gid == statbuf.st_gid ? statbuf.st_mode & S_IXGRP
- : statbuf.st_mode & S_IXOTH);
+ ok =
+ ok && (fuse->uid == statbuf.st_uid
+ ? statbuf.st_mode & S_IXUSR
+ : fuse->gid == statbuf.st_gid ? statbuf.st_mode & S_IXGRP
+ : statbuf.st_mode & S_IXOTH);
}
debug (g, "%s: "
- "testing access mask%s%s%s%s: "
- "caller UID:GID = %ju:%ju, "
- "file UID:GID = %ju:%ju, "
- "file mode = %o, "
- "result = %s",
- path,
- mask & R_OK ? " R_OK" : "",
- mask & W_OK ? " W_OK" : "",
- mask & X_OK ? " X_OK" : "",
- mask == 0 ? " 0" : "",
- (uintmax_t) fuse->uid, (uintmax_t) fuse->gid,
- (uintmax_t) statbuf.st_uid, (uintmax_t) statbuf.st_gid,
- statbuf.st_mode,
- ok ? "OK" : "EACCESS");
+ "testing access mask%s%s%s%s: "
+ "caller UID:GID = %ju:%ju, "
+ "file UID:GID = %ju:%ju, "
+ "file mode = %o, "
+ "result = %s",
+ path, mask & R_OK ? " R_OK" : "", mask & W_OK ?
" W_OK" : "",
+ mask & X_OK ? " X_OK" : "", mask == 0 ? " 0" :
"",
+ (uintmax_t)fuse->uid, (uintmax_t)fuse->gid,
+ (uintmax_t)statbuf.st_uid, (uintmax_t)statbuf.st_gid,
+ statbuf.st_mode, ok ? "OK" : "EACCESS");
return ok ? 0 : -EACCES;
}
@@ -390,7 +409,7 @@ mount_local_readlink (const char *path, char *buf, size_t size)
buf[len] = '\0';
if (free_it) {
- char *tmp = (char *) r;
+ char *tmp = (char *)r;
free (tmp);
}
@@ -402,9 +421,10 @@ mount_local_mknod (const char *path, mode_t mode, dev_t rdev)
{
int r;
DECL_G ();
- DEBUG_CALL ("%s, 0%o, 0x%jx", path, mode, (uintmax_t) rdev);
+ DEBUG_CALL ("%s, 0%o, 0x%jx", path, mode, (uintmax_t)rdev);
- if (g->ml_read_only) return -EROFS;
+ if (g->ml_read_only)
+ return -EROFS;
dir_cache_invalidate (g, path);
@@ -422,7 +442,8 @@ mount_local_mkdir (const char *path, mode_t mode)
DECL_G ();
DEBUG_CALL ("%s, 0%o", path, mode);
- if (g->ml_read_only) return -EROFS;
+ if (g->ml_read_only)
+ return -EROFS;
dir_cache_invalidate (g, path);
@@ -440,7 +461,8 @@ mount_local_unlink (const char *path)
DECL_G ();
DEBUG_CALL ("%s", path);
- if (g->ml_read_only) return -EROFS;
+ if (g->ml_read_only)
+ return -EROFS;
dir_cache_invalidate (g, path);
@@ -458,7 +480,8 @@ mount_local_rmdir (const char *path)
DECL_G ();
DEBUG_CALL ("%s", path);
- if (g->ml_read_only) return -EROFS;
+ if (g->ml_read_only)
+ return -EROFS;
dir_cache_invalidate (g, path);
@@ -476,7 +499,8 @@ mount_local_symlink (const char *from, const char *to)
DECL_G ();
DEBUG_CALL ("%s, %s", from, to);
- if (g->ml_read_only) return -EROFS;
+ if (g->ml_read_only)
+ return -EROFS;
dir_cache_invalidate (g, to);
@@ -494,7 +518,8 @@ mount_local_rename (const char *from, const char *to)
DECL_G ();
DEBUG_CALL ("%s, %s", from, to);
- if (g->ml_read_only) return -EROFS;
+ if (g->ml_read_only)
+ return -EROFS;
dir_cache_invalidate (g, from);
dir_cache_invalidate (g, to);
@@ -513,7 +538,8 @@ mount_local_link (const char *from, const char *to)
DECL_G ();
DEBUG_CALL ("%s, %s", from, to);
- if (g->ml_read_only) return -EROFS;
+ if (g->ml_read_only)
+ return -EROFS;
dir_cache_invalidate (g, from);
dir_cache_invalidate (g, to);
@@ -532,7 +558,8 @@ mount_local_chmod (const char *path, mode_t mode)
DECL_G ();
DEBUG_CALL ("%s, 0%o", path, mode);
- if (g->ml_read_only) return -EROFS;
+ if (g->ml_read_only)
+ return -EROFS;
dir_cache_invalidate (g, path);
@@ -548,9 +575,10 @@ mount_local_chown (const char *path, uid_t uid, gid_t gid)
{
int r;
DECL_G ();
- DEBUG_CALL ("%s, %ju, %ju", path, (uintmax_t) uid, (uintmax_t) gid);
+ DEBUG_CALL ("%s, %ju, %ju", path, (uintmax_t)uid, (uintmax_t)gid);
- if (g->ml_read_only) return -EROFS;
+ if (g->ml_read_only)
+ return -EROFS;
dir_cache_invalidate (g, path);
@@ -566,9 +594,10 @@ mount_local_truncate (const char *path, off_t size)
{
int r;
DECL_G ();
- DEBUG_CALL ("%s, %ld", path, (long) size);
+ DEBUG_CALL ("%s, %ld", path, (long)size);
- if (g->ml_read_only) return -EROFS;
+ if (g->ml_read_only)
+ return -EROFS;
dir_cache_invalidate (g, path);
@@ -586,10 +615,11 @@ mount_local_utimens (const char *path, const struct timespec ts[2])
time_t atsecs, mtsecs;
long atnsecs, mtnsecs;
DECL_G ();
- DEBUG_CALL ("%s, [{ %ld, %ld }, { %ld, %ld }]",
- path, ts[0].tv_sec, ts[0].tv_nsec, ts[1].tv_sec, ts[1].tv_nsec);
+ DEBUG_CALL ("%s, [{ %ld, %ld }, { %ld, %ld }]", path, ts[0].tv_sec,
+ ts[0].tv_nsec, ts[1].tv_sec, ts[1].tv_nsec);
- if (g->ml_read_only) return -EROFS;
+ if (g->ml_read_only)
+ return -EROFS;
dir_cache_invalidate (g, path);
@@ -630,7 +660,7 @@ mount_local_open (const char *path, struct fuse_file_info *fi)
{
int flags = fi->flags & O_ACCMODE;
DECL_G ();
- DEBUG_CALL ("%s, 0%o", path, (unsigned) fi->flags);
+ DEBUG_CALL ("%s, 0%o", path, (unsigned)fi->flags);
if (g->ml_read_only && flags != O_RDONLY)
return -EROFS;
@@ -646,7 +676,7 @@ mount_local_read (const char *path, char *buf, size_t size, off_t
offset,
size_t rsize;
const size_t limit = 2 * 1024 * 1024;
DECL_G ();
- DEBUG_CALL ("%s, %p, %zu, %ld", path, buf, size, (long) offset);
+ DEBUG_CALL ("%s, %p, %zu, %ld", path, buf, size, (long)offset);
/* The guestfs protocol limits size to somewhere over 2MB. We just
* reduce the requested size here accordingly and push the problem
@@ -678,9 +708,10 @@ mount_local_write (const char *path, const char *buf, size_t size,
const size_t limit = 2 * 1024 * 1024;
int r;
DECL_G ();
- DEBUG_CALL ("%s, %p, %zu, %ld", path, buf, size, (long) offset);
+ DEBUG_CALL ("%s, %p, %zu, %ld", path, buf, size, (long)offset);
- if (g->ml_read_only) return -EROFS;
+ if (g->ml_read_only)
+ return -EROFS;
dir_cache_invalidate (g, path);
@@ -751,13 +782,14 @@ mount_local_fsync (const char *path, int isdatasync,
static int
mount_local_setxattr (const char *path, const char *name, const char *value,
- size_t size, int flags)
+ size_t size, int flags)
{
int r;
DECL_G ();
DEBUG_CALL ("%s, %s, %p, %zu", path, name, value, size);
- if (g->ml_read_only) return -EROFS;
+ if (g->ml_read_only)
+ return -EROFS;
dir_cache_invalidate (g, path);
@@ -798,7 +830,7 @@ mount_local_getxattr (const char *path, const char *name, char
*value,
break;
}
- if (i == xattrs->len) { /* not found */
+ if (i == xattrs->len) { /* not found */
r = -ENOATTR;
goto out;
}
@@ -824,9 +856,9 @@ mount_local_getxattr (const char *path, const char *name, char
*value,
}
memcpy (value, xattrs->val[i].attrval, sz);
- out:
+out:
if (free_attrs)
- guestfs_free_xattr_list ((struct guestfs_xattr_list *) xattrs);
+ guestfs_free_xattr_list ((struct guestfs_xattr_list *)xattrs);
return r;
}
@@ -878,27 +910,29 @@ mount_local_listxattr (const char *path, char *list, size_t size)
size -= len;
list += len;
r += len;
- } else {
+ }
+ else {
r = -ERANGE;
break;
}
}
- out:
+out:
if (free_attrs)
- guestfs_free_xattr_list ((struct guestfs_xattr_list *) xattrs);
+ guestfs_free_xattr_list ((struct guestfs_xattr_list *)xattrs);
return r;
}
static int
-mount_local_removexattr(const char *path, const char *name)
+mount_local_removexattr (const char *path, const char *name)
{
int r;
DECL_G ();
DEBUG_CALL ("%s, %s", path, name);
- if (g->ml_read_only) return -EROFS;
+ if (g->ml_read_only)
+ return -EROFS;
dir_cache_invalidate (g, path);
@@ -910,7 +944,7 @@ mount_local_removexattr(const char *path, const char *name)
}
static int
-mount_local_flush(const char *path, struct fuse_file_info *fi)
+mount_local_flush (const char *path, struct fuse_file_info *fi)
{
DECL_G ();
DEBUG_CALL ("%s", path);
@@ -924,37 +958,37 @@ mount_local_flush(const char *path, struct fuse_file_info *fi)
}
static struct fuse_operations mount_local_operations = {
- .getattr = mount_local_getattr,
- .access = mount_local_access,
- .readlink = mount_local_readlink,
- .readdir = mount_local_readdir,
- .mknod = mount_local_mknod,
- .mkdir = mount_local_mkdir,
- .symlink = mount_local_symlink,
- .unlink = mount_local_unlink,
- .rmdir = mount_local_rmdir,
- .rename = mount_local_rename,
- .link = mount_local_link,
- .chmod = mount_local_chmod,
- .chown = mount_local_chown,
- .truncate = mount_local_truncate,
- .utimens = mount_local_utimens,
- .open = mount_local_open,
- .read = mount_local_read,
- .write = mount_local_write,
- .statfs = mount_local_statfs,
- .release = mount_local_release,
- .fsync = mount_local_fsync,
- .setxattr = mount_local_setxattr,
- .getxattr = mount_local_getxattr,
- .listxattr = mount_local_listxattr,
- .removexattr = mount_local_removexattr,
- .flush = mount_local_flush,
+ .getattr = mount_local_getattr,
+ .access = mount_local_access,
+ .readlink = mount_local_readlink,
+ .readdir = mount_local_readdir,
+ .mknod = mount_local_mknod,
+ .mkdir = mount_local_mkdir,
+ .symlink = mount_local_symlink,
+ .unlink = mount_local_unlink,
+ .rmdir = mount_local_rmdir,
+ .rename = mount_local_rename,
+ .link = mount_local_link,
+ .chmod = mount_local_chmod,
+ .chown = mount_local_chown,
+ .truncate = mount_local_truncate,
+ .utimens = mount_local_utimens,
+ .open = mount_local_open,
+ .read = mount_local_read,
+ .write = mount_local_write,
+ .statfs = mount_local_statfs,
+ .release = mount_local_release,
+ .fsync = mount_local_fsync,
+ .setxattr = mount_local_setxattr,
+ .getxattr = mount_local_getxattr,
+ .listxattr = mount_local_listxattr,
+ .removexattr = mount_local_removexattr,
+ .flush = mount_local_flush,
};
int
guestfs_impl_mount_local (guestfs_h *g, const char *localmountpoint,
- const struct guestfs_mount_local_argv *optargs)
+ const struct guestfs_mount_local_argv *optargs)
{
const char *t;
struct fuse_args args = FUSE_ARGS_INIT (0, NULL);
@@ -1022,9 +1056,8 @@ guestfs_impl_mount_local (guestfs_h *g, const char
*localmountpoint,
debug (g, "%s: fuse_new", __func__);
/* Create the FUSE handle. */
- g->fuse = fuse_new (ch, &args,
- &mount_local_operations, sizeof mount_local_operations,
- g);
+ g->fuse = fuse_new (ch, &args, &mount_local_operations,
+ sizeof mount_local_operations, g);
if (!g->fuse) {
perrorf (g, _("fuse_new: %s"), localmountpoint);
fuse_unmount (localmountpoint, ch);
@@ -1066,7 +1099,9 @@ guestfs_impl_mount_local_run (guestfs_h *g)
r = guestfs_exists (g, "/");
guestfs_pop_error_handler (g);
if (r == -1) {
- error (g, _("you must call 'guestfs_mount' first to mount a filesystem
on '/'.\nNote: '%s' is still mounted. Use 'guestunmount %s' to
clean up."),
+ error (g, _("you must call 'guestfs_mount' first to mount a "
+ "filesystem on '/'.\nNote: '%s' is still mounted.
Use "
+ "'guestunmount %s' to clean up."),
g->localmountpoint, g->localmountpoint);
return -1;
}
@@ -1095,14 +1130,14 @@ void
guestfs_int_free_fuse (guestfs_h *g)
{
if (g->fuse)
- fuse_destroy (g->fuse); /* also closes the channel */
+ fuse_destroy (g->fuse); /* also closes the channel */
g->fuse = NULL;
free_dir_caches (g);
}
int
guestfs_impl_umount_local (guestfs_h *g,
- const struct guestfs_umount_local_argv *optargs)
+ const struct guestfs_umount_local_argv *optargs)
{
const char *retry;
int r;
@@ -1170,21 +1205,21 @@ guestfs_impl_umount_local (guestfs_h *g,
*/
struct entry_common {
- char *pathname; /* full path to the file */
- time_t timeout; /* when this entry expires */
+ char *pathname; /* full path to the file */
+ time_t timeout; /* when this entry expires */
};
-struct lsc_entry { /* lstat cache entry */
+struct lsc_entry { /* lstat cache entry */
struct entry_common c;
- struct stat statbuf; /* statbuf */
+ struct stat statbuf; /* statbuf */
};
-struct xac_entry { /* xattr cache entry */
+struct xac_entry { /* xattr cache entry */
struct entry_common c;
struct guestfs_xattr_list *xattrs;
};
-struct rlc_entry { /* readlink cache entry */
+struct rlc_entry { /* readlink cache entry */
struct entry_common c;
char *link;
};
@@ -1311,8 +1346,8 @@ dir_cache_remove_all_expired (guestfs_h *g, time_t now)
}
static int
-gen_replace (guestfs_h *g, Hash_table *ht,
- struct entry_common *new_entry, Hash_data_freer freer)
+gen_replace (guestfs_h *g, Hash_table *ht, struct entry_common *new_entry,
+ Hash_data_freer freer)
{
struct entry_common *old_entry;
@@ -1331,8 +1366,7 @@ gen_replace (guestfs_h *g, Hash_table *ht,
}
static int
-lsc_insert (guestfs_h *g,
- const char *path, const char *name, time_t now,
+lsc_insert (guestfs_h *g, const char *path, const char *name, time_t now,
struct stat const *statbuf)
{
struct lsc_entry *entry;
@@ -1360,12 +1394,11 @@ lsc_insert (guestfs_h *g,
entry->c.timeout = now + g->ml_dir_cache_timeout;
- return gen_replace (g, g->lsc_ht, (struct entry_common *) entry, lsc_free);
+ return gen_replace (g, g->lsc_ht, (struct entry_common *)entry, lsc_free);
}
static int
-xac_insert (guestfs_h *g,
- const char *path, const char *name, time_t now,
+xac_insert (guestfs_h *g, const char *path, const char *name, time_t now,
struct guestfs_xattr_list *xattrs)
{
struct xac_entry *entry;
@@ -1393,12 +1426,11 @@ xac_insert (guestfs_h *g,
entry->c.timeout = now + g->ml_dir_cache_timeout;
- return gen_replace (g, g->xac_ht, (struct entry_common *) entry, xac_free);
+ return gen_replace (g, g->xac_ht, (struct entry_common *)entry, xac_free);
}
static int
-rlc_insert (guestfs_h *g,
- const char *path, const char *name, time_t now,
+rlc_insert (guestfs_h *g, const char *path, const char *name, time_t now,
char *link)
{
struct rlc_entry *entry;
@@ -1426,13 +1458,13 @@ rlc_insert (guestfs_h *g,
entry->c.timeout = now + g->ml_dir_cache_timeout;
- return gen_replace (g, g->rlc_ht, (struct entry_common *) entry, rlc_free);
+ return gen_replace (g, g->rlc_ht, (struct entry_common *)entry, rlc_free);
}
static const struct stat *
lsc_lookup (guestfs_h *g, const char *pathname)
{
- const struct entry_common key = { .pathname = (char *) pathname };
+ const struct entry_common key = {.pathname = (char *)pathname };
struct lsc_entry *entry;
time_t now;
@@ -1448,7 +1480,7 @@ lsc_lookup (guestfs_h *g, const char *pathname)
static const struct guestfs_xattr_list *
xac_lookup (guestfs_h *g, const char *pathname)
{
- const struct entry_common key = { .pathname = (char *) pathname };
+ const struct entry_common key = {.pathname = (char *)pathname };
struct xac_entry *entry;
time_t now;
@@ -1464,7 +1496,7 @@ xac_lookup (guestfs_h *g, const char *pathname)
static const char *
rlc_lookup (guestfs_h *g, const char *pathname)
{
- const struct entry_common key = { .pathname = (char *) pathname };
+ const struct entry_common key = {.pathname = (char *)pathname };
struct rlc_entry *entry;
time_t now;
@@ -1480,7 +1512,7 @@ rlc_lookup (guestfs_h *g, const char *pathname)
static void
gen_remove (Hash_table *ht, const char *pathname, Hash_data_freer freer)
{
- const struct entry_common key = { .pathname = (char *) pathname };
+ const struct entry_common key = {.pathname = (char *)pathname };
struct entry_common *entry;
entry = hash_delete (ht, &key);
@@ -1498,14 +1530,14 @@ dir_cache_invalidate (guestfs_h *g, const char *path)
#else /* !HAVE_FUSE */
-#define FUSE_NOT_SUPPORTED() \
- NOT_SUPPORTED (g, -1, _("FUSE is not supported in this build of " \
- "libguestfs because libfuse was not found " \
+#define FUSE_NOT_SUPPORTED() \
+ NOT_SUPPORTED (g, -1, _("FUSE is not supported in this build of " \
+ "libguestfs because libfuse was not found " \
"when libguestfs was compiled"))
int
guestfs_impl_mount_local (guestfs_h *g, const char *localmountpoint,
- const struct guestfs_mount_local_argv *optargs)
+ const struct guestfs_mount_local_argv *optargs)
{
FUSE_NOT_SUPPORTED ();
}
@@ -1518,7 +1550,7 @@ guestfs_impl_mount_local_run (guestfs_h *g)
int
guestfs_impl_umount_local (guestfs_h *g,
- const struct guestfs_umount_local_argv *optargs)
+ const struct guestfs_umount_local_argv *optargs)
{
FUSE_NOT_SUPPORTED ();
}
diff --git a/src/guestfs-internal-all.h b/src/guestfs-internal-all.h
index af30e58..146c834 100644
--- a/src/guestfs-internal-all.h
+++ b/src/guestfs-internal-all.h
@@ -25,40 +25,43 @@
/* This is also defined in <guestfs.h>, so don't redefine it. */
#if defined(__GNUC__) && !defined(GUESTFS_GCC_VERSION)
-# define GUESTFS_GCC_VERSION \
- (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
+#define GUESTFS_GCC_VERSION \
+ (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#endif
-#if !defined(__attribute__) && defined(__GNUC__) && GUESTFS_GCC_VERSION
< 20800 /* gcc < 2.8 */
-# define __attribute__(x) /* empty */
+#if !defined(__attribute__) && defined(__GNUC__) && \
+ GUESTFS_GCC_VERSION < 20800 /* gcc < 2.8 */
+#define __attribute__(x) /* empty */
#endif
#ifndef ATTRIBUTE_UNUSED
-# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
+#define ATTRIBUTE_UNUSED __attribute__((__unused__))
#endif
-#define STREQ(a,b) (strcmp((a),(b)) == 0)
-#define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0)
-#define STRNEQ(a,b) (strcmp((a),(b)) != 0)
-#define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0)
-#define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0)
-#define STRCASEEQLEN(a,b,n) (strncasecmp((a),(b),(n)) == 0)
-#define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0)
-#define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0)
-#define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0)
-#define STRCASEPREFIX(a,b) (strncasecmp((a),(b),strlen((b))) == 0)
-#define STRSUFFIX(a,b) (strlen((a)) >= strlen((b)) &&
STREQ((a)+strlen((a))-strlen((b)),(b)))
+#define STREQ(a, b) (strcmp ((a), (b)) == 0)
+#define STRCASEEQ(a, b) (strcasecmp ((a), (b)) == 0)
+#define STRNEQ(a, b) (strcmp ((a), (b)) != 0)
+#define STRCASENEQ(a, b) (strcasecmp ((a), (b)) != 0)
+#define STREQLEN(a, b, n) (strncmp ((a), (b), (n)) == 0)
+#define STRCASEEQLEN(a, b, n) (strncasecmp ((a), (b), (n)) == 0)
+#define STRNEQLEN(a, b, n) (strncmp ((a), (b), (n)) != 0)
+#define STRCASENEQLEN(a, b, n) (strncasecmp ((a), (b), (n)) != 0)
+#define STRPREFIX(a, b) (strncmp ((a), (b), strlen ((b))) == 0)
+#define STRCASEPREFIX(a, b) (strncasecmp ((a), (b), strlen ((b))) == 0)
+#define STRSUFFIX(a, b) \
+ (strlen ((a)) >= strlen ((b)) && \
+ STREQ ((a) + strlen ((a)) - strlen ((b)), (b)))
#ifndef SOCK_CLOEXEC
#define SOCK_CLOEXEC 0
#endif
#ifndef MAX
-#define MAX(a,b) ((a)>(b)?(a):(b))
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif
#ifndef MIN
-#define MIN(a,b) ((a)<(b)?(a):(b))
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
#ifdef __APPLE__
@@ -68,28 +71,23 @@
/* Macro which compiles the regexp once when the program/library is
* loaded, and frees it when the library is unloaded.
*/
-#define COMPILE_REGEXP(name,pattern,options) \
+#define COMPILE_REGEXP(name, pattern, options) \
static void compile_regexp_##name (void) __attribute__((constructor)); \
- static void free_regexp_##name (void) __attribute__((destructor)); \
- static pcre *name; \
- \
- static void \
- compile_regexp_##name (void) \
- { \
- const char *err; \
- int offset; \
- name = pcre_compile ((pattern), (options), &err, &offset, NULL); \
- if (name == NULL) { \
- ignore_value (write (2, err, strlen (err))); \
- abort (); \
- } \
- } \
- \
- static void \
- free_regexp_##name (void) \
- { \
- pcre_free (name); \
- }
+ static void free_regexp_##name (void) __attribute__((destructor)); \
+ static pcre *name; \
+ \
+ static void compile_regexp_##name (void) \
+ { \
+ const char *err; \
+ int offset; \
+ name = pcre_compile ((pattern), (options), &err, &offset, NULL); \
+ if (name == NULL) { \
+ ignore_value (write (2, err, strlen (err))); \
+ abort (); \
+ } \
+ } \
+ \
+ static void free_regexp_##name (void) { pcre_free (name); }
/* The type field of a parsed mountable.
*
@@ -98,9 +96,9 @@
*/
typedef enum {
- MOUNTABLE_DEVICE, /* A bare device */
- MOUNTABLE_BTRFSVOL, /* A btrfs subvolume: device + volume */
- MOUNTABLE_PATH /* An already mounted path: device = path */
+ MOUNTABLE_DEVICE, /* A bare device */
+ MOUNTABLE_BTRFSVOL, /* A btrfs subvolume: device + volume */
+ MOUNTABLE_PATH /* An already mounted path: device = path */
} mountable_type_t;
#endif /* GUESTFS_INTERNAL_ALL_H_ */
diff --git a/src/guestfs-internal-frontend.h b/src/guestfs-internal-frontend.h
index 7f10906..428a7c6 100644
--- a/src/guestfs-internal-frontend.h
+++ b/src/guestfs-internal-frontend.h
@@ -32,31 +32,33 @@
#include "guestfs-internal-all.h"
-#define _(str) dgettext(PACKAGE, (str))
-#define N_(str) dgettext(PACKAGE, (str))
+#define _(str) dgettext (PACKAGE, (str))
+#define N_(str) dgettext (PACKAGE, (str))
#ifdef HAVE_ATTRIBUTE_CLEANUP
-#define CLEANUP_FREE __attribute__((cleanup(guestfs_int_cleanup_free)))
-#define CLEANUP_FREE_STRING_LIST \
- __attribute__((cleanup(guestfs_int_cleanup_free_string_list)))
-#define CLEANUP_HASH_FREE \
- __attribute__((cleanup(guestfs_int_cleanup_hash_free)))
-#define CLEANUP_UNLINK_FREE \
- __attribute__((cleanup(guestfs_int_cleanup_unlink_free)))
-#define CLEANUP_XMLBUFFERFREE \
- __attribute__((cleanup(guestfs_int_cleanup_xmlBufferFree)))
-#define CLEANUP_XMLFREEDOC \
- __attribute__((cleanup(guestfs_int_cleanup_xmlFreeDoc)))
-#define CLEANUP_XMLFREEURI \
- __attribute__((cleanup(guestfs_int_cleanup_xmlFreeURI)))
-#define CLEANUP_XMLFREETEXTWRITER \
- __attribute__((cleanup(guestfs_int_cleanup_xmlFreeTextWriter)))
-#define CLEANUP_XMLXPATHFREECONTEXT \
- __attribute__((cleanup(guestfs_int_cleanup_xmlXPathFreeContext)))
-#define CLEANUP_XMLXPATHFREEOBJECT \
- __attribute__((cleanup(guestfs_int_cleanup_xmlXPathFreeObject)))
-#define CLEANUP_FCLOSE __attribute__((cleanup(guestfs_int_cleanup_fclose)))
-#define CLEANUP_PCLOSE __attribute__((cleanup(guestfs_int_cleanup_pclose)))
+#define CLEANUP_FREE __attribute__((cleanup (guestfs_int_cleanup_free)))
+#define CLEANUP_FREE_STRING_LIST \
+ __attribute__ ((cleanup (guestfs_int_cleanup_free_string_list)))
+#define CLEANUP_HASH_FREE \
+ __attribute__((cleanup (guestfs_int_cleanup_hash_free)))
+#define CLEANUP_UNLINK_FREE \
+ __attribute__((cleanup (guestfs_int_cleanup_unlink_free)))
+#define CLEANUP_XMLBUFFERFREE \
+ __attribute__((cleanup (guestfs_int_cleanup_xmlBufferFree)))
+#define CLEANUP_XMLFREEDOC \
+ __attribute__((cleanup (guestfs_int_cleanup_xmlFreeDoc)))
+#define CLEANUP_XMLFREEURI \
+ __attribute__((cleanup (guestfs_int_cleanup_xmlFreeURI)))
+#define CLEANUP_XMLFREETEXTWRITER \
+ __attribute__((cleanup (guestfs_int_cleanup_xmlFreeTextWriter)))
+#define CLEANUP_XMLXPATHFREECONTEXT \
+ __attribute__((cleanup (guestfs_int_cleanup_xmlXPathFreeContext)))
+#define CLEANUP_XMLXPATHFREEOBJECT \
+ __attribute__((cleanup (guestfs_int_cleanup_xmlXPathFreeObject)))
+#define CLEANUP_FCLOSE \
+ __attribute__((cleanup (guestfs_int_cleanup_fclose)))
+#define CLEANUP_PCLOSE \
+ __attribute__((cleanup (guestfs_int_cleanup_pclose)))
#else
#define CLEANUP_FREE
#define CLEANUP_FREE_STRING_LIST
@@ -79,7 +81,10 @@ extern char *guestfs_int_concat_strings (char *const *);
extern char **guestfs_int_copy_string_list (char *const *);
extern char *guestfs_int_join_strings (const char *sep, char *const *);
extern char **guestfs_int_split_string (char sep, const char *);
-extern char *guestfs_int_exit_status_to_string (int status, const char *cmd_name, char
*buffer, size_t buflen);
+extern char *guestfs_int_exit_status_to_string (int status,
+ const char *cmd_name,
+ char *buffer,
+ size_t buflen);
extern int guestfs_int_random_string (char *ret, size_t len);
extern char *guestfs_int_drive_name (size_t index, char *ret);
extern ssize_t guestfs_int_drive_index (const char *);
@@ -113,36 +118,38 @@ extern void guestfs_int_cleanup_pclose (void *ptr);
* that want to use 'guestfs_int_program_name'.
*/
#if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME == 1
-# define guestfs_int_program_name program_invocation_short_name
+#define guestfs_int_program_name program_invocation_short_name
#elif HAVE_GETPROGNAME
-# define guestfs_int_program_name getprogname()
+#define guestfs_int_program_name getprogname ()
#else
-# define guestfs_int_program_name "libguestfs"
+#define guestfs_int_program_name "libguestfs"
#endif
/* Close all file descriptors matching the condition. */
-#define close_file_descriptors(cond) do { \
- int max_fd = sysconf (_SC_OPEN_MAX); \
- int fd; \
- if (max_fd == -1) \
- max_fd = 1024; \
- if (max_fd > 65536) \
- max_fd = 65536; /* bound the amount of work we do here */ \
- for (fd = 0; fd < max_fd; ++fd) { \
- if (cond) \
- close (fd); \
- } \
+#define close_file_descriptors(cond) \
+ do { \
+ int max_fd = sysconf (_SC_OPEN_MAX); \
+ int fd; \
+ if (max_fd == -1) \
+ max_fd = 1024; \
+ if (max_fd > 65536) \
+ max_fd = 65536; /* bound the amount of work we do here */ \
+ for (fd = 0; fd < max_fd; ++fd) { \
+ if (cond) \
+ close (fd); \
+ } \
} while (0)
/* Not all language bindings know how to deal with Pointer arguments.
* Those that don't will use this macro which complains noisily and
* returns NULL.
*/
-#define POINTER_NOT_IMPLEMENTED(type) \
- ( \
- fprintf (stderr, "*** WARNING: this language binding does not support conversion
of Pointer(%s), so the current function will always fail. Patches to fix this should be
sent to the libguestfs upstream mailing list.\n", \
- type), \
- NULL \
-)
+#define POINTER_NOT_IMPLEMENTED(type) \
+ (fprintf (stderr, "*** WARNING: this language binding does not support " \
+ "conversion of Pointer(%s), so the current function " \
+ "will always fail. Patches to fix this should be " \
+ "sent to the libguestfs upstream mailing list.\n", \
+ type), \
+ NULL)
#endif /* GUESTFS_INTERNAL_FRONTEND_H_ */
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index 61f384c..4a859d0 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -21,7 +21,7 @@
#include <stdbool.h>
-#include <rpc/types.h> /* Needed on libc's different than glibc. */
+#include <rpc/types.h> /* Needed on libc's different than glibc. */
#include <rpc/xdr.h>
#include <pcre.h>
@@ -34,9 +34,9 @@
#define MIN_LIBVIRT_MAJOR 0
#define MIN_LIBVIRT_MINOR 10
#define MIN_LIBVIRT_MICRO 2 /* XXX patches in > 2 already */
-#define MIN_LIBVIRT_VERSION (MIN_LIBVIRT_MAJOR * 1000000 + \
- MIN_LIBVIRT_MINOR * 1000 + \
- MIN_LIBVIRT_MICRO)
+#define MIN_LIBVIRT_VERSION \
+ (MIN_LIBVIRT_MAJOR * 1000000 + MIN_LIBVIRT_MINOR * 1000 + \
+ MIN_LIBVIRT_MICRO)
#ifdef HAVE_LIBVIRT
#include <libvirt/libvirt.h>
@@ -52,15 +52,14 @@
#if ENABLE_PROBES
#include <sys/sdt.h>
/* NB: The 'name' parameter is a literal identifier, NOT a string! */
-#define TRACE0(name) DTRACE_PROBE(guestfs, name)
-#define TRACE1(name, arg1) \
- DTRACE_PROBE(guestfs, name, (arg1))
+#define TRACE0(name) DTRACE_PROBE (guestfs, name)
+#define TRACE1(name, arg1) DTRACE_PROBE (guestfs, name, (arg1))
#define TRACE2(name, arg1, arg2) \
- DTRACE_PROBE(guestfs, name, (arg1), (arg2))
+ DTRACE_PROBE (guestfs, name, (arg1), (arg2))
#define TRACE3(name, arg1, arg2, arg3) \
- DTRACE_PROBE(guestfs, name, (arg1), (arg2), (arg3))
+ DTRACE_PROBE (guestfs, name, (arg1), (arg2), (arg3))
#define TRACE4(name, arg1, arg2, arg3, arg4) \
- DTRACE_PROBE(guestfs, name, (arg1), (arg2), (arg3), (arg4))
+ DTRACE_PROBE (guestfs, name, (arg1), (arg2), (arg3), (arg4))
#else /* !ENABLE_PROBES */
#define TRACE0(name)
#define TRACE1(name, arg1)
@@ -77,8 +76,8 @@
* creating device nodes.
*/
#ifdef __powerpc__
-# define DEFAULT_MEMSIZE 768
-# define MIN_MEMSIZE 256
+#define DEFAULT_MEMSIZE 768
+#define MIN_MEMSIZE 256
#endif
/* Kernel 3.19 is unable to uncompress the initramfs on aarch64 unless
@@ -87,16 +86,16 @@
* common on aarch64, treat this like the ppc case above.
*/
#ifdef __aarch64__
-# define DEFAULT_MEMSIZE 768
-# define MIN_MEMSIZE 256
+#define DEFAULT_MEMSIZE 768
+#define MIN_MEMSIZE 256
#endif
/* The default and minimum memory size for most users. */
#ifndef DEFAULT_MEMSIZE
-# define DEFAULT_MEMSIZE 500
+#define DEFAULT_MEMSIZE 500
#endif
#ifndef MIN_MEMSIZE
-# define MIN_MEMSIZE 128
+#define MIN_MEMSIZE 128
#endif
/* Timeout waiting for appliance to come up (seconds).
@@ -105,7 +104,7 @@
* configurable. Also it interacts with libguestfs-test-tool -t
* option.
*/
-#define APPLIANCE_TIMEOUT (20*60) /* 20 mins */
+#define APPLIANCE_TIMEOUT (20 * 60) /* 20 mins */
/* Some limits on what the inspection code will read, for safety. */
@@ -121,15 +120,15 @@
* create a lot of metadata so we really need to be careful about
* those.
*/
-#define MAX_SMALL_FILE_SIZE (2 * 1000 * 1000)
-#define MAX_AUGEAS_FILE_SIZE (100 * 1000)
+#define MAX_SMALL_FILE_SIZE (2 * 1000 * 1000)
+#define MAX_AUGEAS_FILE_SIZE (100 * 1000)
/* Maximum RPM or dpkg database we will download to /tmp. RPM
* 'Packages' database can get very large: 70 MB is roughly the
* standard size for a new Fedora install, and after lots of package
* installation/removal I have seen well over 100 MB databases.
*/
-#define MAX_PKG_DB_SIZE (300 * 1000 * 1000)
+#define MAX_PKG_DB_SIZE (300 * 1000 * 1000)
/* Maximum size of Windows explorer.exe. 2.6MB on Windows 7. */
#define MAX_WINDOWS_EXPLORER_SIZE (4 * 1000 * 1000)
@@ -138,15 +137,15 @@
* hardware with PCI.
*/
#if !defined(__arm__) && !defined(__aarch64__)
-#define VIRTIO_BLK "virtio-blk-pci"
-#define VIRTIO_SCSI "virtio-scsi-pci"
+#define VIRTIO_BLK "virtio-blk-pci"
+#define VIRTIO_SCSI "virtio-scsi-pci"
#define VIRTIO_SERIAL "virtio-serial-pci"
-#define VIRTIO_NET "virtio-net-pci"
+#define VIRTIO_NET "virtio-net-pci"
#else /* ARM */
-#define VIRTIO_BLK "virtio-blk-device"
-#define VIRTIO_SCSI "virtio-scsi-device"
+#define VIRTIO_BLK "virtio-blk-device"
+#define VIRTIO_SCSI "virtio-scsi-device"
#define VIRTIO_SERIAL "virtio-serial-device"
-#define VIRTIO_NET "virtio-net-device"
+#define VIRTIO_NET "virtio-net-device"
#endif /* ARM */
/* Machine types. */
@@ -163,8 +162,7 @@
/* Guestfs handle and associated structures. */
/* State. */
-enum state { CONFIG = 0, LAUNCHING = 1, READY = 2,
- NO_HANDLE = 0xebadebad };
+enum state { CONFIG = 0, LAUNCHING = 1, READY = 2, NO_HANDLE = 0xebadebad };
/* Event. */
struct event {
@@ -195,9 +193,9 @@ enum drive_protocol {
};
enum drive_transport {
- drive_transport_none = 0, /* no transport specified */
- drive_transport_tcp, /* +tcp */
- drive_transport_unix, /* +unix */
+ drive_transport_none = 0, /* no transport specified */
+ drive_transport_tcp, /* +tcp */
+ drive_transport_unix, /* +unix */
/* XXX In theory gluster+rdma could be supported here, but
* I have no idea what gluster+rdma URLs would look like.
*/
@@ -207,12 +205,13 @@ struct drive_server {
enum drive_transport transport;
/* This field is always non-NULL. */
- union {
- char *hostname; /* hostname or IP address as a string */
- char *socket; /* Unix domain socket */
+ union
+ {
+ char *hostname; /* hostname or IP address as a string */
+ char *socket; /* Unix domain socket */
} u;
- int port; /* port number */
+ int port; /* port number */
};
struct drive_source {
@@ -222,9 +221,10 @@ struct drive_source {
char *format;
/* This field is always non-NULL. It may be an empty string. */
- union {
- char *path; /* path to file (file) */
- char *exportname; /* name of export (nbd) */
+ union
+ {
+ char *path; /* path to file (file) */
+ char *exportname; /* name of export (nbd) */
} u;
/* For network transports, zero or more servers can be specified here.
@@ -276,7 +276,7 @@ struct hv_param {
struct hv_param *next;
char *hv_param;
- char *hv_value; /* May be NULL. */
+ char *hv_value; /* May be NULL. */
};
/* Backend operations. */
@@ -305,8 +305,10 @@ struct backend_ops {
int (*max_disks) (guestfs_h *g, void *data);
/* Hotplugging drives. */
- int (*hot_add_drive) (guestfs_h *g, void *data, struct drive *drv, size_t drv_index);
- int (*hot_remove_drive) (guestfs_h *g, void *data, struct drive *drv, size_t
drv_index);
+ int (*hot_add_drive) (guestfs_h *g, void *data, struct drive *drv,
+ size_t drv_index);
+ int (*hot_remove_drive) (guestfs_h *g, void *data, struct drive *drv,
+ size_t drv_index);
};
/* Connection module. A 'connection' represents the appliance console
@@ -322,7 +324,8 @@ struct connection {
};
struct connection_ops {
- /* Close everything and free the connection struct and any internal data. */
+ /* Close everything and free the connection struct and any internal data.
+ */
void (*free_connection) (guestfs_h *g, struct connection *);
/* Accept the connection (back to us) from the daemon.
@@ -343,10 +346,13 @@ struct connection_ops {
* return 0 to mean that the appliance closed the connection or
* otherwise went away. -1 means there's an error.
*/
- ssize_t (*read_data) (guestfs_h *g, struct connection *, void *buf, size_t len);
- ssize_t (*write_data) (guestfs_h *g, struct connection *, const void *buf, size_t
len);
+ ssize_t (*read_data) (guestfs_h *g, struct connection *, void *buf,
+ size_t len);
+ ssize_t (*write_data) (guestfs_h *g, struct connection *, const void *buf,
+ size_t len);
- /* Test if data is available to read on the daemon socket, without blocking.
+ /* Test if data is available to read on the daemon socket, without
+ * blocking.
* Returns: 1 = yes, 0 = no, -1 = error
*/
int (*can_read_data) (guestfs_h *g, struct connection *);
@@ -354,9 +360,9 @@ struct connection_ops {
/* Stack of old error handlers. */
struct error_cb_stack {
- struct error_cb_stack *next;
+ struct error_cb_stack *next;
guestfs_error_handler_cb error_cb;
- void * error_cb_data;
+ void *error_cb_data;
};
/* Cached queried features. */
@@ -366,33 +372,32 @@ struct cached_feature {
};
/* The libguestfs handle. */
-struct guestfs_h
-{
- struct guestfs_h *next; /* Linked list of open handles. */
- enum state state; /* See the state machine diagram in guestfs(3)*/
+struct guestfs_h {
+ struct guestfs_h *next; /* Linked list of open handles. */
+ enum state state; /* See the state machine diagram in guestfs(3)*/
/**** Configuration of the handle. ****/
- bool verbose; /* Debugging. */
- bool trace; /* Trace calls. */
- bool autosync; /* Autosync. */
- bool direct_mode; /* Direct mode. */
- bool recovery_proc; /* Create a recovery process. */
- bool enable_network; /* Enable the network. */
- bool selinux; /* selinux enabled? */
- bool pgroup; /* Create process group for children? */
- bool close_on_exit; /* Is this handle on the atexit list? */
+ bool verbose; /* Debugging. */
+ bool trace; /* Trace calls. */
+ bool autosync; /* Autosync. */
+ bool direct_mode; /* Direct mode. */
+ bool recovery_proc; /* Create a recovery process. */
+ bool enable_network; /* Enable the network. */
+ bool selinux; /* selinux enabled? */
+ bool pgroup; /* Create process group for children? */
+ bool close_on_exit; /* Is this handle on the atexit list? */
- int smp; /* If > 1, -smp flag passed to hv. */
- int memsize; /* Size of RAM (megabytes). */
+ int smp; /* If > 1, -smp flag passed to hv. */
+ int memsize; /* Size of RAM (megabytes). */
- char *path; /* Path to the appliance. */
- char *hv; /* Hypervisor (HV) binary. */
- char *append; /* Append to kernel command line. */
+ char *path; /* Path to the appliance. */
+ char *hv; /* Hypervisor (HV) binary. */
+ char *append; /* Append to kernel command line. */
- struct hv_param *hv_params; /* Extra hv parameters. */
+ struct hv_param *hv_params; /* Extra hv parameters. */
- char *program; /* Program name. */
- char *identifier; /* Handle identifier. */
+ char *program; /* Program name. */
+ char *identifier; /* Handle identifier. */
/* Array of drives added by add-drive* APIs.
*
@@ -414,20 +419,20 @@ struct guestfs_h
struct drive **drives;
size_t nr_drives;
-#define ITER_DRIVES(g,i,drv) \
- for (i = 0; i < (g)->nr_drives; ++i) \
+#define ITER_DRIVES(g, i, drv) \
+ for (i = 0; i < (g)->nr_drives; ++i) \
if (((drv) = (g)->drives[i]) != NULL)
/* Backend. NB: Use guestfs_int_set_backend to change the backend. */
- char *backend; /* The full string, always non-NULL. */
- char *backend_arg; /* Pointer to the argument part. */
+ char *backend; /* The full string, always non-NULL. */
+ char *backend_arg; /* Pointer to the argument part. */
const struct backend_ops *backend_ops;
- void *backend_data; /* Per-handle data. */
- char **backend_settings; /* Backend settings (can be NULL). */
+ void *backend_data; /* Per-handle data. */
+ char **backend_settings; /* Backend settings (can be NULL). */
/**** Runtime information. ****/
- char *last_error; /* Last error on handle. */
- int last_errnum; /* errno, or 0 if there was no errno */
+ char *last_error; /* Last error on handle. */
+ int last_errnum; /* errno, or 0 if there was no errno */
/* Temporary and cache directories. */
/* The actual temporary directory - this is not created with the
@@ -436,18 +441,19 @@ struct guestfs_h
char *tmpdir;
char *sockdir;
/* Environment variables that affect tmpdir/cachedir/sockdir locations. */
- char *env_tmpdir; /* $TMPDIR (NULL if not set) */
- char *env_runtimedir; /* $XDG_RUNTIME_DIR (NULL if not set)*/
- char *int_tmpdir; /* $LIBGUESTFS_TMPDIR or guestfs_set_tmpdir or NULL */
- char *int_cachedir; /* $LIBGUESTFS_CACHEDIR or guestfs_set_cachedir or NULL */
+ char *env_tmpdir; /* $TMPDIR (NULL if not set) */
+ char *env_runtimedir; /* $XDG_RUNTIME_DIR (NULL if not set)*/
+ char *int_tmpdir; /* $LIBGUESTFS_TMPDIR or guestfs_set_tmpdir or NULL */
+ char *
+ int_cachedir; /* $LIBGUESTFS_CACHEDIR or guestfs_set_cachedir or NULL */
/* Error handler, plus stack of old error handlers. */
- guestfs_error_handler_cb error_cb;
- void * error_cb_data;
- struct error_cb_stack *error_cb_stack;
+ guestfs_error_handler_cb error_cb;
+ void *error_cb_data;
+ struct error_cb_stack *error_cb_stack;
/* Out of memory error handler. */
- guestfs_abort_cb abort_cb;
+ guestfs_abort_cb abort_cb;
/* Events. */
struct event *events;
@@ -468,7 +474,7 @@ struct guestfs_h
*/
int user_cancel;
- struct timeval launch_t; /* The time that we called guestfs_launch. */
+ struct timeval launch_t; /* The time that we called guestfs_launch. */
/* Used by bindtests. */
FILE *test_fp;
@@ -480,7 +486,7 @@ struct guestfs_h
int unique;
/*** Protocol. ***/
- struct connection *conn; /* Connection to appliance. */
+ struct connection *conn; /* Connection to appliance. */
int msg_next_serial;
#if HAVE_FUSE
@@ -490,11 +496,11 @@ struct guestfs_h
int ml_dir_cache_timeout; /* Directory cache timeout. */
Hash_table *lsc_ht, *xac_ht, *rlc_ht; /* Directory cache. */
int ml_read_only; /* If mounted read-only. */
- int ml_debug_calls; /* Extra debug info on each FUSE call. */
+ int ml_debug_calls; /* Extra debug info on each FUSE call. */
#endif
#ifdef HAVE_LIBVIRT_BACKEND
- /* Used by src/libvirt-auth.c. */
+/* Used by src/libvirt-auth.c. */
#define NR_CREDENTIAL_TYPES 9
unsigned int nr_supported_credentials;
int supported_credentials[NR_CREDENTIAL_TYPES];
@@ -624,19 +630,24 @@ struct guestfs_message_error;
struct guestfs_progress;
/* handle.c */
-extern int guestfs_int_get_backend_setting_bool (guestfs_h *g, const char *name);
+extern int guestfs_int_get_backend_setting_bool (guestfs_h *g,
+ const char *name);
/* alloc.c */
extern void *guestfs_int_safe_malloc (guestfs_h *g, size_t nbytes);
extern void *guestfs_int_safe_calloc (guestfs_h *g, size_t n, size_t s);
extern char *guestfs_int_safe_strdup (guestfs_h *g, const char *str);
-extern void *guestfs_int_safe_memdup (guestfs_h *g, const void *ptr, size_t size);
-extern void *guestfs_int_safe_realloc (guestfs_h *g, void *ptr, size_t nbytes);
+extern void *guestfs_int_safe_memdup (guestfs_h *g, const void *ptr,
+ size_t size);
+extern void *guestfs_int_safe_realloc (guestfs_h *g, void *ptr,
+ size_t nbytes);
extern char *guestfs_int_safe_strdup (guestfs_h *g, const char *str);
-extern char *guestfs_int_safe_strndup (guestfs_h *g, const char *str, size_t n);
-extern void *guestfs_int_safe_memdup (guestfs_h *g, const void *ptr, size_t size);
+extern char *guestfs_int_safe_strndup (guestfs_h *g, const char *str,
+ size_t n);
+extern void *guestfs_int_safe_memdup (guestfs_h *g, const void *ptr,
+ size_t size);
extern char *guestfs_int_safe_asprintf (guestfs_h *g, const char *fs, ...)
- __attribute__((format (printf,2,3)));
+ __attribute__((format (printf, 2, 3)));
#define safe_calloc guestfs_int_safe_calloc
#define safe_malloc guestfs_int_safe_malloc
@@ -649,38 +660,45 @@ extern char *guestfs_int_safe_asprintf (guestfs_h *g, const char
*fs, ...)
/* errors.c */
extern void guestfs_int_init_error_handler (guestfs_h *g);
-extern void guestfs_int_error_errno (guestfs_h *g, int errnum, const char *fs, ...)
- __attribute__((format (printf,3,4)));
+extern void guestfs_int_error_errno (guestfs_h *g, int errnum,
+ const char *fs, ...)
+ __attribute__((format (printf, 3, 4)));
extern void guestfs_int_perrorf (guestfs_h *g, const char *fs, ...)
- __attribute__((format (printf,2,3)));
+ __attribute__((format (printf, 2, 3)));
extern void guestfs_int_warning (guestfs_h *g, const char *fs, ...)
- __attribute__((format (printf,2,3)));
+ __attribute__((format (printf, 2, 3)));
extern void guestfs_int_debug (guestfs_h *g, const char *fs, ...)
- __attribute__((format (printf,2,3)));
+ __attribute__((format (printf, 2, 3)));
extern void guestfs_int_trace (guestfs_h *g, const char *fs, ...)
- __attribute__((format (printf,2,3)));
+ __attribute__((format (printf, 2, 3)));
-extern void guestfs_int_print_BufferIn (FILE *out, const char *buf, size_t buf_size);
-extern void guestfs_int_print_BufferOut (FILE *out, const char *buf, size_t buf_size);
+extern void guestfs_int_print_BufferIn (FILE *out, const char *buf,
+ size_t buf_size);
+extern void guestfs_int_print_BufferOut (FILE *out, const char *buf,
+ size_t buf_size);
-#define error(g,...) guestfs_int_error_errno((g),0,__VA_ARGS__)
+#define error(g, ...) guestfs_int_error_errno ((g), 0, __VA_ARGS__)
#define perrorf guestfs_int_perrorf
-#define warning(g,...) guestfs_int_warning((g),__VA_ARGS__)
-#define debug(g,...) \
- do { if ((g)->verbose) guestfs_int_debug ((g),__VA_ARGS__); } while (0)
+#define warning(g, ...) guestfs_int_warning ((g), __VA_ARGS__)
+#define debug(g, ...) \
+ do { \
+ if ((g)->verbose) \
+ guestfs_int_debug ((g), __VA_ARGS__); \
+ } while (0)
-#define NOT_SUPPORTED(g,errcode,...) \
+#define NOT_SUPPORTED(g, errcode, ...) \
do { \
- guestfs_int_error_errno ((g), ENOTSUP, __VA_ARGS__); \
+ guestfs_int_error_errno ((g), ENOTSUP, __VA_ARGS__); \
return (errcode); \
- } \
- while (0)
+ } while (0)
extern void guestfs_int_launch_failed_error (guestfs_h *g);
extern void guestfs_int_unexpected_close_error (guestfs_h *g);
extern void guestfs_int_launch_timeout (guestfs_h *g);
-extern void guestfs_int_external_command_failed (guestfs_h *g, int status, const char
*cmd_name, const char *extra);
+extern void guestfs_int_external_command_failed (guestfs_h *g, int status,
+ const char *cmd_name,
+ const char *extra);
/* actions-support.c */
struct trace_buffer {
@@ -690,18 +708,33 @@ struct trace_buffer {
bool opened;
};
-extern int guestfs_int_check_reply_header (guestfs_h *g, const struct
guestfs_message_header *hdr, unsigned int proc_nr, unsigned int serial);
-extern int guestfs_int_check_appliance_up (guestfs_h *g, const char *caller);
+extern int
+guestfs_int_check_reply_header (guestfs_h *g,
+ const struct guestfs_message_header *hdr,
+ unsigned int proc_nr, unsigned int serial);
+extern int guestfs_int_check_appliance_up (guestfs_h *g,
+ const char *caller);
extern void guestfs_int_trace_open (struct trace_buffer *tb);
-extern void guestfs_int_trace_send_line (guestfs_h *g, struct trace_buffer *tb);
+extern void guestfs_int_trace_send_line (guestfs_h *g,
+ struct trace_buffer *tb);
/* match.c */
-extern int guestfs_int_match (guestfs_h *g, const char *str, const pcre *re);
-extern char *guestfs_int_match1 (guestfs_h *g, const char *str, const pcre *re);
-extern int guestfs_int_match2 (guestfs_h *g, const char *str, const pcre *re, char
**ret1, char **ret2);
-extern int guestfs_int_match3 (guestfs_h *g, const char *str, const pcre *re, char
**ret1, char **ret2, char **ret3);
-extern int guestfs_int_match4 (guestfs_h *g, const char *str, const pcre *re, char
**ret1, char **ret2, char **ret3, char **ret4);
-extern int guestfs_int_match6 (guestfs_h *g, const char *str, const pcre *re, char
**ret1, char **ret2, char **ret3, char **ret4, char **ret5, char **ret6);
+extern int guestfs_int_match (guestfs_h *g, const char *str,
+ const pcre *re);
+extern char *guestfs_int_match1 (guestfs_h *g, const char *str,
+ const pcre *re);
+extern int guestfs_int_match2 (guestfs_h *g, const char *str,
+ const pcre *re, char **ret1, char **ret2);
+extern int guestfs_int_match3 (guestfs_h *g, const char *str,
+ const pcre *re, char **ret1, char **ret2,
+ char **ret3);
+extern int guestfs_int_match4 (guestfs_h *g, const char *str,
+ const pcre *re, char **ret1, char **ret2,
+ char **ret3, char **ret4);
+extern int guestfs_int_match6 (guestfs_h *g, const char *str,
+ const pcre *re, char **ret1, char **ret2,
+ char **ret3, char **ret4, char **ret5,
+ char **ret6);
#define match guestfs_int_match
#define match1 guestfs_int_match1
@@ -717,117 +750,185 @@ struct stringsbuf {
size_t alloc;
};
#define DECLARE_STRINGSBUF(v) \
- struct stringsbuf (v) = { .argv = NULL, .size = 0, .alloc = 0 }
+ struct stringsbuf (v) = {.argv = NULL, .size = 0, .alloc = 0 }
-extern void guestfs_int_add_string_nodup (guestfs_h *g, struct stringsbuf *sb, char
*str);
-extern void guestfs_int_add_string (guestfs_h *g, struct stringsbuf *sb, const char
*str);
-extern void guestfs_int_add_sprintf (guestfs_h *g, struct stringsbuf *sb, const char *fs,
...)
- __attribute__((format (printf,3,4)));
-extern void guestfs_int_end_stringsbuf (guestfs_h *g, struct stringsbuf *sb);
+extern void guestfs_int_add_string_nodup (guestfs_h *g,
+ struct stringsbuf *sb, char *str);
+extern void guestfs_int_add_string (guestfs_h *g, struct stringsbuf *sb,
+ const char *str);
+extern void guestfs_int_add_sprintf (guestfs_h *g, struct stringsbuf *sb,
+ const char *fs, ...)
+ __attribute__((format (printf, 3, 4)));
+extern void guestfs_int_end_stringsbuf (guestfs_h *g,
+ struct stringsbuf *sb);
extern void guestfs_int_free_stringsbuf (struct stringsbuf *sb);
#ifdef HAVE_ATTRIBUTE_CLEANUP
-#define CLEANUP_FREE_STRINGSBUF
__attribute__((cleanup(guestfs_int_cleanup_free_stringsbuf)))
+#define CLEANUP_FREE_STRINGSBUF \
+ __attribute__((cleanup (guestfs_int_cleanup_free_stringsbuf)))
#else
#define CLEANUP_FREE_STRINGSBUF
#endif
extern void guestfs_int_cleanup_free_stringsbuf (struct stringsbuf *sb);
/* proto.c */
-extern int guestfs_int_send (guestfs_h *g, int proc_nr, uint64_t progress_hint, uint64_t
optargs_bitmask, xdrproc_t xdrp, char *args);
-extern int guestfs_int_recv (guestfs_h *g, const char *fn, struct guestfs_message_header
*hdr, struct guestfs_message_error *err, xdrproc_t xdrp, char *ret);
+extern int guestfs_int_send (guestfs_h *g, int proc_nr,
+ uint64_t progress_hint,
+ uint64_t optargs_bitmask, xdrproc_t xdrp,
+ char *args);
+extern int guestfs_int_recv (guestfs_h *g, const char *fn,
+ struct guestfs_message_header *hdr,
+ struct guestfs_message_error *err,
+ xdrproc_t xdrp, char *ret);
extern int guestfs_int_recv_discard (guestfs_h *g, const char *fn);
extern int guestfs_int_send_file (guestfs_h *g, const char *filename);
extern int guestfs_int_recv_file (guestfs_h *g, const char *filename);
-extern int guestfs_int_recv_from_daemon (guestfs_h *g, uint32_t *size_rtn, void
**buf_rtn);
-extern void guestfs_int_progress_message_callback (guestfs_h *g, const struct
guestfs_progress *message);
-extern void guestfs_int_log_message_callback (guestfs_h *g, const char *buf, size_t
len);
+extern int guestfs_int_recv_from_daemon (guestfs_h *g, uint32_t *size_rtn,
+ void **buf_rtn);
+extern void guestfs_int_progress_message_callback (
+ guestfs_h *g, const struct guestfs_progress *message);
+extern void guestfs_int_log_message_callback (guestfs_h *g, const char *buf,
+ size_t len);
/* conn-socket.c */
-extern struct connection *guestfs_int_new_conn_socket_listening (guestfs_h *g, int
daemon_accept_sock, int console_sock);
-extern struct connection *guestfs_int_new_conn_socket_connected (guestfs_h *g, int
daemon_sock, int console_sock);
+extern struct connection *
+guestfs_int_new_conn_socket_listening (guestfs_h *g, int daemon_accept_sock,
+ int console_sock);
+extern struct connection *
+guestfs_int_new_conn_socket_connected (guestfs_h *g, int daemon_sock,
+ int console_sock);
/* events.c */
extern void guestfs_int_call_callbacks_void (guestfs_h *g, uint64_t event);
-extern void guestfs_int_call_callbacks_message (guestfs_h *g, uint64_t event, const char
*buf, size_t buf_len);
-extern void guestfs_int_call_callbacks_array (guestfs_h *g, uint64_t event, const
uint64_t *array, size_t array_len);
+extern void guestfs_int_call_callbacks_message (guestfs_h *g,
+ uint64_t event,
+ const char *buf,
+ size_t buf_len);
+extern void guestfs_int_call_callbacks_array (guestfs_h *g, uint64_t event,
+ const uint64_t *array,
+ size_t array_len);
/* tmpdirs.c */
extern int guestfs_int_set_env_tmpdir (guestfs_h *g, const char *tmpdir);
-extern int guestfs_int_set_env_runtimedir (guestfs_h *g, const char *runtimedir);
+extern int guestfs_int_set_env_runtimedir (guestfs_h *g,
+ const char *runtimedir);
extern int guestfs_int_lazy_make_tmpdir (guestfs_h *g);
extern int guestfs_int_lazy_make_sockdir (guestfs_h *g);
extern void guestfs_int_remove_tmpdir (guestfs_h *g);
extern void guestfs_int_remove_sockdir (guestfs_h *g);
-extern void guestfs_int_recursive_remove_dir (guestfs_h *g, const char *dir);
+extern void guestfs_int_recursive_remove_dir (guestfs_h *g,
+ const char *dir);
/* whole-file.c */
-extern int guestfs_int_read_whole_file (guestfs_h *g, const char *filename, char
**data_r, size_t *size_r);
+extern int guestfs_int_read_whole_file (guestfs_h *g, const char *filename,
+ char **data_r, size_t *size_r);
/* drives.c */
extern size_t guestfs_int_checkpoint_drives (guestfs_h *g);
extern void guestfs_int_rollback_drives (guestfs_h *g, size_t);
extern void guestfs_int_add_dummy_appliance_drive (guestfs_h *g);
extern void guestfs_int_free_drives (guestfs_h *g);
-extern const char *guestfs_int_drive_protocol_to_string (enum drive_protocol protocol);
+extern const char *
+guestfs_int_drive_protocol_to_string (enum drive_protocol protocol);
/* appliance.c */
-extern int guestfs_int_build_appliance (guestfs_h *g, char **kernel, char **initrd, char
**appliance);
+extern int guestfs_int_build_appliance (guestfs_h *g, char **kernel,
+ char **initrd, char **appliance);
extern int guestfs_int_get_uefi (guestfs_h *g, char **code, char **vars);
/* launch.c */
-extern int64_t guestfs_int_timeval_diff (const struct timeval *x, const struct timeval
*y);
+extern int64_t guestfs_int_timeval_diff (const struct timeval *x,
+ const struct timeval *y);
extern void guestfs_int_launch_send_progress (guestfs_h *g, int perdozen);
-extern char *guestfs_int_appliance_command_line (guestfs_h *g, const char *appliance_dev,
int flags);
+extern char *guestfs_int_appliance_command_line (guestfs_h *g,
+ const char *appliance_dev,
+ int flags);
#define APPLIANCE_COMMAND_LINE_IS_TCG 1
const char *guestfs_int_get_cpu_model (int kvm);
-int guestfs_int_create_socketname (guestfs_h *g, const char *filename, char
(*sockname)[UNIX_PATH_MAX]);
-extern void guestfs_int_register_backend (const char *name, const struct backend_ops *);
+int guestfs_int_create_socketname (guestfs_h *g, const char *filename,
+ char (*sockname)[UNIX_PATH_MAX]);
+extern void guestfs_int_register_backend (const char *name,
+ const struct backend_ops *);
extern int guestfs_int_set_backend (guestfs_h *g, const char *method);
/* inspect.c */
extern void guestfs_int_free_inspect_info (guestfs_h *g);
-extern char *guestfs_int_download_to_tmp (guestfs_h *g, struct inspect_fs *fs, const char
*filename, const char *basename, uint64_t max_size);
-extern struct inspect_fs *guestfs_int_search_for_root (guestfs_h *g, const char *root);
+extern char *guestfs_int_download_to_tmp (guestfs_h *g,
+ struct inspect_fs *fs,
+ const char *filename,
+ const char *basename,
+ uint64_t max_size);
+extern struct inspect_fs *guestfs_int_search_for_root (guestfs_h *g,
+ const char *root);
extern int guestfs_int_is_partition (guestfs_h *g, const char *partition);
/* inspect-fs.c */
extern int guestfs_int_is_file_nocase (guestfs_h *g, const char *);
extern int guestfs_int_is_dir_nocase (guestfs_h *g, const char *);
extern int guestfs_int_check_for_filesystem_on (guestfs_h *g,
- const char *mountable);
+ const char *mountable);
extern int guestfs_int_parse_unsigned_int (guestfs_h *g, const char *str);
-extern int guestfs_int_parse_unsigned_int_ignore_trailing (guestfs_h *g, const char
*str);
-extern int guestfs_int_parse_major_minor (guestfs_h *g, struct inspect_fs *fs);
-extern char *guestfs_int_first_line_of_file (guestfs_h *g, const char *filename);
-extern int guestfs_int_first_egrep_of_file (guestfs_h *g, const char *filename, const
char *eregex, int iflag, char **ret);
-extern void guestfs_int_check_package_format (guestfs_h *g, struct inspect_fs *fs);
-extern void guestfs_int_check_package_management (guestfs_h *g, struct inspect_fs *fs);
-extern void guestfs_int_merge_fs_inspections (guestfs_h *g, struct inspect_fs *dst,
struct inspect_fs *src);
+extern int guestfs_int_parse_unsigned_int_ignore_trailing (guestfs_h *g,
+ const char *str);
+extern int guestfs_int_parse_major_minor (guestfs_h *g,
+ struct inspect_fs *fs);
+extern char *guestfs_int_first_line_of_file (guestfs_h *g,
+ const char *filename);
+extern int guestfs_int_first_egrep_of_file (guestfs_h *g,
+ const char *filename,
+ const char *eregex, int iflag,
+ char **ret);
+extern void guestfs_int_check_package_format (guestfs_h *g,
+ struct inspect_fs *fs);
+extern void guestfs_int_check_package_management (guestfs_h *g,
+ struct inspect_fs *fs);
+extern void guestfs_int_merge_fs_inspections (guestfs_h *g,
+ struct inspect_fs *dst,
+ struct inspect_fs *src);
/* inspect-fs-unix.c */
-extern int guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs);
-extern int guestfs_int_check_freebsd_root (guestfs_h *g, struct inspect_fs *fs);
-extern int guestfs_int_check_netbsd_root (guestfs_h *g, struct inspect_fs *fs);
-extern int guestfs_int_check_openbsd_root (guestfs_h *g, struct inspect_fs *fs);
-extern int guestfs_int_check_hurd_root (guestfs_h *g, struct inspect_fs *fs);
-extern int guestfs_int_check_minix_root (guestfs_h *g, struct inspect_fs *fs);
-extern int guestfs_int_check_coreos_root (guestfs_h *g, struct inspect_fs *fs);
-extern int guestfs_int_check_coreos_usr (guestfs_h *g, struct inspect_fs *fs);
+extern int guestfs_int_check_linux_root (guestfs_h *g,
+ struct inspect_fs *fs);
+extern int guestfs_int_check_freebsd_root (guestfs_h *g,
+ struct inspect_fs *fs);
+extern int guestfs_int_check_netbsd_root (guestfs_h *g,
+ struct inspect_fs *fs);
+extern int guestfs_int_check_openbsd_root (guestfs_h *g,
+ struct inspect_fs *fs);
+extern int guestfs_int_check_hurd_root (guestfs_h *g,
+ struct inspect_fs *fs);
+extern int guestfs_int_check_minix_root (guestfs_h *g,
+ struct inspect_fs *fs);
+extern int guestfs_int_check_coreos_root (guestfs_h *g,
+ struct inspect_fs *fs);
+extern int guestfs_int_check_coreos_usr (guestfs_h *g,
+ struct inspect_fs *fs);
/* inspect-fs-windows.c */
-extern char *guestfs_int_case_sensitive_path_silently (guestfs_h *g, const char *);
-extern char * guestfs_int_get_windows_systemroot (guestfs_h *g);
-extern int guestfs_int_check_windows_root (guestfs_h *g, struct inspect_fs *fs, char
*windows_systemroot);
+extern char *guestfs_int_case_sensitive_path_silently (guestfs_h *g,
+ const char *);
+extern char *guestfs_int_get_windows_systemroot (guestfs_h *g);
+extern int guestfs_int_check_windows_root (guestfs_h *g,
+ struct inspect_fs *fs,
+ char *windows_systemroot);
/* inspect-fs-cd.c */
-extern int guestfs_int_check_installer_root (guestfs_h *g, struct inspect_fs *fs);
-extern int guestfs_int_check_installer_iso (guestfs_h *g, struct inspect_fs *fs, const
char *device);
+extern int guestfs_int_check_installer_root (guestfs_h *g,
+ struct inspect_fs *fs);
+extern int guestfs_int_check_installer_iso (guestfs_h *g,
+ struct inspect_fs *fs,
+ const char *device);
/* dbdump.c */
-typedef int (*guestfs_int_db_dump_callback) (guestfs_h *g, const unsigned char *key,
size_t keylen, const unsigned char *value, size_t valuelen, void *opaque);
-extern int guestfs_int_read_db_dump (guestfs_h *g, const char *dumpfile, void *opaque,
guestfs_int_db_dump_callback callback);
+typedef int (*guestfs_int_db_dump_callback) (guestfs_h *g,
+ const unsigned char *key,
+ size_t keylen,
+ const unsigned char *value,
+ size_t valuelen, void *opaque);
+extern int guestfs_int_read_db_dump (guestfs_h *g, const char *dumpfile,
+ void *opaque,
+ guestfs_int_db_dump_callback callback);
/* lpj.c */
extern int guestfs_int_get_lpj (guestfs_h *g);
@@ -839,7 +940,9 @@ extern void guestfs_int_free_fuse (guestfs_h *g);
/* libvirt-auth.c */
#ifdef HAVE_LIBVIRT
-extern virConnectPtr guestfs_int_open_libvirt_connection (guestfs_h *g, const char *uri,
unsigned int flags);
+extern virConnectPtr
+guestfs_int_open_libvirt_connection (guestfs_h *g, const char *uri,
+ unsigned int flags);
#endif
/* osinfo.c */
@@ -866,27 +969,38 @@ struct osinfo {
pcre *re_publisher_id;
pcre *re_application_id;
};
-extern int guestfs_int_osinfo_map (guestfs_h *g, const struct guestfs_isoinfo *isoinfo,
const struct osinfo **osinfo_ret);
+extern int guestfs_int_osinfo_map (guestfs_h *g,
+ const struct guestfs_isoinfo *isoinfo,
+ const struct osinfo **osinfo_ret);
/* command.c */
struct command;
-typedef void (*cmd_stdout_callback) (guestfs_h *g, void *data, const char *line, size_t
len);
+typedef void (*cmd_stdout_callback) (guestfs_h *g, void *data,
+ const char *line, size_t len);
typedef int (*cmd_child_callback) (guestfs_h *g, void *data);
extern struct command *guestfs_int_new_command (guestfs_h *g);
extern void guestfs_int_cmd_add_arg (struct command *, const char *arg);
-extern void guestfs_int_cmd_add_arg_format (struct command *, const char *fs, ...)
- __attribute__((format (printf,2,3)));
-extern void guestfs_int_cmd_add_string_unquoted (struct command *, const char *str);
-extern void guestfs_int_cmd_add_string_quoted (struct command *, const char *str);
-extern void guestfs_int_cmd_set_stdout_callback (struct command *, cmd_stdout_callback
stdout_callback, void *data, unsigned flags);
-#define CMD_STDOUT_FLAG_LINE_BUFFER 0
-#define CMD_STDOUT_FLAG_UNBUFFERED 1
-#define CMD_STDOUT_FLAG_WHOLE_BUFFER 2
+extern void guestfs_int_cmd_add_arg_format (struct command *,
+ const char *fs, ...)
+ __attribute__((format (printf, 2, 3)));
+extern void guestfs_int_cmd_add_string_unquoted (struct command *,
+ const char *str);
+extern void guestfs_int_cmd_add_string_quoted (struct command *,
+ const char *str);
+extern void
+guestfs_int_cmd_set_stdout_callback (struct command *,
+ cmd_stdout_callback stdout_callback,
+ void *data, unsigned flags);
+#define CMD_STDOUT_FLAG_LINE_BUFFER 0
+#define CMD_STDOUT_FLAG_UNBUFFERED 1
+#define CMD_STDOUT_FLAG_WHOLE_BUFFER 2
extern void guestfs_int_cmd_set_stderr_to_stdout (struct command *);
-extern void guestfs_int_cmd_set_child_rlimit (struct command *, int resource, long
limit);
+extern void guestfs_int_cmd_set_child_rlimit (struct command *,
+ int resource, long limit);
extern void guestfs_int_cmd_clear_capture_errors (struct command *);
extern void guestfs_int_cmd_clear_close_files (struct command *);
-extern void guestfs_int_cmd_set_child_callback (struct command *, cmd_child_callback
child_callback, void *data);
+extern void guestfs_int_cmd_set_child_callback (
+ struct command *, cmd_child_callback child_callback, void *data);
extern int guestfs_int_cmd_run (struct command *);
extern void guestfs_int_cmd_close (struct command *);
extern int guestfs_int_cmd_pipe_run (struct command *cmd, const char *mode);
@@ -894,15 +1008,19 @@ extern int guestfs_int_cmd_pipe_wait (struct command *cmd);
extern char *guestfs_int_cmd_get_pipe_errors (struct command *cmd);
#ifdef HAVE_ATTRIBUTE_CLEANUP
-#define CLEANUP_CMD_CLOSE __attribute__((cleanup(guestfs_int_cleanup_cmd_close)))
+#define CLEANUP_CMD_CLOSE \
+ __attribute__((cleanup (guestfs_int_cleanup_cmd_close)))
#else
#define CLEANUP_CMD_CLOSE
#endif
extern void guestfs_int_cleanup_cmd_close (struct command **);
/* launch-direct.c */
-extern char *guestfs_int_drive_source_qemu_param (guestfs_h *g, const struct drive_source
*src);
-extern bool guestfs_int_discard_possible (guestfs_h *g, struct drive *drv, unsigned long
qemu_version);
+extern char *
+guestfs_int_drive_source_qemu_param (guestfs_h *g,
+ const struct drive_source *src);
+extern bool guestfs_int_discard_possible (guestfs_h *g, struct drive *drv,
+ unsigned long qemu_version);
/* launch-*.c constructors */
void guestfs_int_init_direct_backend (void) __attribute__((constructor));
diff --git a/src/guid.c b/src/guid.c
index a69f5ec..76e358a 100644
--- a/src/guid.c
+++ b/src/guid.c
@@ -28,7 +28,8 @@
#include "guestfs-internal.h"
/* Check whether a string supposed to contain a GUID actually contains it.
- * It can recognize strings either as '{21EC2020-3AEA-1069-A2DD-08002B30309D}'
+ * It can recognize strings either as
+ * '{21EC2020-3AEA-1069-A2DD-08002B30309D}'
* or '21EC2020-3AEA-1069-A2DD-08002B30309D'.
*/
int
@@ -40,7 +41,7 @@ guestfs_int_validate_guid (const char *str)
case 36:
break;
case 38:
- if (str[0] == '{' && str[len -1] == '}') {
+ if (str[0] == '{' && str[len - 1] == '}') {
++str;
len -= 2;
break;
diff --git a/src/handle.c b/src/handle.c
index 25d3c99..afe30b8 100644
--- a/src/handle.c
+++ b/src/handle.c
@@ -77,7 +77,8 @@ guestfs_create_flags (unsigned flags, ...)
guestfs_h *g;
g = calloc (1, sizeof (*g));
- if (!g) return NULL;
+ if (!g)
+ return NULL;
g->state = CONFIG;
@@ -100,7 +101,8 @@ guestfs_create_flags (unsigned flags, ...)
g->smp = 1;
g->path = strdup (GUESTFS_DEFAULT_PATH);
- if (!g->path) goto error;
+ if (!g->path)
+ goto error;
#ifdef QEMU
g->hv = strdup (QEMU);
@@ -111,9 +113,10 @@ guestfs_create_flags (unsigned flags, ...)
*/
g->hv = strdup ("false");
#endif
- if (!g->hv) goto error;
+ if (!g->hv)
+ goto error;
- /* Get program name. */
+/* Get program name. */
#if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME == 1
if (STRPREFIX (program_invocation_short_name, "lt-"))
/* Remove libtool (lt-*) prefix from short name. */
@@ -123,13 +126,16 @@ guestfs_create_flags (unsigned flags, ...)
#else
g->program = strdup ("");
#endif
- if (!g->program) goto error;
+ if (!g->program)
+ goto error;
g->identifier = strdup ("");
- if (!g->identifier) goto error;
+ if (!g->identifier)
+ goto error;
if (guestfs_int_set_backend (g, DEFAULT_BACKEND) == -1) {
- warning (g, _("libguestfs was built with an invalid default backend, using
'direct' instead"));
+ warning (g, _("libguestfs was built with an invalid default backend, "
+ "using 'direct' instead"));
if (guestfs_int_set_backend (g, "direct") == -1) {
warning (g, _("'direct' backend does not work"));
goto error;
@@ -153,12 +159,12 @@ guestfs_create_flags (unsigned flags, ...)
gl_lock_unlock (handles_lock);
}
- debug (g, "create: flags = %u, handle = %p, program = %s",
- flags, g, g->program);
+ debug (g, "create: flags = %u, handle = %p, program = %s", flags, g,
+ g->program);
return g;
- error:
+error:
guestfs_int_free_string_list (g->backend_settings);
free (g->backend);
free (g->identifier);
@@ -262,7 +268,8 @@ parse_environment (guestfs_h *g,
str = do_getenv (data, "LIBGUESTFS_BACKEND_SETTINGS");
if (str) {
- CLEANUP_FREE_STRING_LIST char **settings = guestfs_int_split_string (':',
str);
+ CLEANUP_FREE_STRING_LIST char **settings =
+ guestfs_int_split_string (':', str);
if (settings == NULL) {
perrorf (g, "split_string: malloc");
@@ -295,18 +302,18 @@ guestfs_impl_parse_environment (guestfs_h *g)
static char *
getenv_from_strings (const void *stringsv, const char *name)
{
- char **strings = (char **) stringsv;
+ char **strings = (char **)stringsv;
size_t len = strlen (name);
size_t i;
for (i = 0; strings[i] != NULL; ++i)
if (STRPREFIX (strings[i], name) && strings[i][len] == '=')
- return &strings[i][len+1];
+ return &strings[i][len + 1];
return NULL;
}
int
-guestfs_impl_parse_environment_list (guestfs_h *g, char * const *strings)
+guestfs_impl_parse_environment_list (guestfs_h *g, char *const *strings)
{
return parse_environment (g, getenv_from_strings, strings);
}
@@ -319,7 +326,8 @@ guestfs_close (guestfs_h *g)
if (g->state == NO_HANDLE) {
/* Not safe to call ANY callbacks here, so ... */
- fprintf (stderr, _("guestfs_close: called twice on the same handle\n"));
+ fprintf (stderr,
+ _("guestfs_close: called twice on the same handle\n"));
return;
}
@@ -335,11 +343,11 @@ guestfs_close (guestfs_h *g)
if (g->trace) {
const char trace_msg[] = "close";
- guestfs_int_call_callbacks_message (g, GUESTFS_EVENT_TRACE,
- trace_msg, strlen (trace_msg));
+ guestfs_int_call_callbacks_message (g, GUESTFS_EVENT_TRACE, trace_msg,
+ strlen (trace_msg));
}
- debug (g, "closing guestfs handle %p (state %d)", g, (int) g->state);
+ debug (g, "closing guestfs handle %p (state %d)", g, (int)g->state);
if (g->state != CONFIG)
shutdown_backend (g, 0);
@@ -404,7 +412,7 @@ guestfs_close (guestfs_h *g)
int64_t
guestfs_impl_c_pointer (guestfs_h *g)
{
- return (int64_t) g;
+ return (int64_t)g;
}
#pragma GCC diagnostic pop
@@ -463,7 +471,8 @@ shutdown_backend (guestfs_h *g, int check_for_errors)
static void
close_handles (void)
{
- while (handles) guestfs_close (handles);
+ while (handles)
+ guestfs_close (handles);
}
int
@@ -498,9 +507,8 @@ guestfs_impl_set_path (guestfs_h *g, const char *path)
free (g->path);
g->path = NULL;
- g->path =
- path == NULL ?
- safe_strdup (g, GUESTFS_DEFAULT_PATH) : safe_strdup (g, path);
+ g->path = path == NULL ? safe_strdup (g, GUESTFS_DEFAULT_PATH)
+ : safe_strdup (g, path);
return 0;
}
@@ -523,7 +531,8 @@ guestfs_impl_set_qemu (guestfs_h *g, const char *qemu)
#ifdef QEMU
new_hv = safe_strdup (g, QEMU);
#else
- error (g, _("configured --without-qemu so calling guestfs_set_qemu with qemu ==
NULL is an error"));
+ error (g, _("configured --without-qemu so calling guestfs_set_qemu "
+ "with qemu == NULL is an error"));
return -1;
#endif
}
@@ -576,7 +585,8 @@ int
guestfs_impl_set_memsize (guestfs_h *g, int memsize)
{
if (memsize < MIN_MEMSIZE) {
- error (g, _("too small value for memsize (must be at least %d)"),
MIN_MEMSIZE);
+ error (g, _("too small value for memsize (must be at least %d)"),
+ MIN_MEMSIZE);
return -1;
}
g->memsize = memsize;
@@ -693,7 +703,8 @@ guestfs_impl_set_identifier (guestfs_h *g, const char *identifier)
char c = identifier[i];
if (!c_isalnum (c) && c != '_' && c != '-') {
- error (g, _("identifier must contain only alphanumeric characters, underscore
or minus sign"));
+ error (g, _("identifier must contain only alphanumeric characters, "
+ "underscore or minus sign"));
return -1;
}
}
@@ -776,7 +787,7 @@ guestfs_impl_get_backend_settings (guestfs_h *g)
return NULL;
}
- return ret; /* caller frees */
+ return ret; /* caller frees */
}
char *
@@ -795,10 +806,10 @@ guestfs_impl_get_backend_setting (guestfs_h *g, const char *name)
return safe_strdup (g, "1");
/* "name=...", return value */
if (STRPREFIX (settings[i], name) && settings[i][namelen] == '=')
- return safe_strdup (g, &settings[i][namelen+1]);
+ return safe_strdup (g, &settings[i][namelen + 1]);
}
- not_found:
+not_found:
guestfs_int_error_errno (g, ESRCH, _("setting not found"));
return NULL;
}
@@ -820,9 +831,10 @@ guestfs_impl_clear_backend_setting (guestfs_h *g, const char *name)
count++;
free (settings[i]);
- /* We move all the following strings down one place, including the NULL. */
+ /* We move all the following strings down one place, including the
+ * NULL. */
for (j = i; settings[j] != NULL; ++j)
- settings[j] = settings[j+1];
+ settings[j] = settings[j + 1];
i--;
}
@@ -832,7 +844,8 @@ guestfs_impl_clear_backend_setting (guestfs_h *g, const char *name)
}
int
-guestfs_impl_set_backend_setting (guestfs_h *g, const char *name, const char *value)
+guestfs_impl_set_backend_setting (guestfs_h *g, const char *name,
+ const char *value)
{
char *new_setting;
size_t len;
@@ -850,7 +863,7 @@ guestfs_impl_set_backend_setting (guestfs_h *g, const char *name,
const char *va
}
g->backend_settings =
- safe_realloc (g, g->backend_settings, (len+2) * sizeof (char *));
+ safe_realloc (g, g->backend_settings, (len + 2) * sizeof (char *));
g->backend_settings[len++] = new_setting;
g->backend_settings[len++] = NULL;
@@ -902,10 +915,12 @@ guestfs_impl_set_smp (guestfs_h *g, int v)
if (v > 255) {
error (g, "unsupported number of smp vcpus: %d", v);
return -1;
- } else if (v >= 1) {
+ }
+ else if (v >= 1) {
g->smp = v;
return 0;
- } else {
+ }
+ else {
error (g, "invalid smp parameter: %d", v);
return -1;
}
diff --git a/src/info.c b/src/info.c
index 9791730..320ec3d 100644
--- a/src/info.c
+++ b/src/info.c
@@ -45,12 +45,13 @@
#include "guestfs-internal-actions.h"
#ifdef HAVE_ATTRIBUTE_CLEANUP
-#define CLEANUP_YAJL_TREE_FREE __attribute__((cleanup(cleanup_yajl_tree_free)))
+#define CLEANUP_YAJL_TREE_FREE \
+ __attribute__((cleanup (cleanup_yajl_tree_free)))
static void
cleanup_yajl_tree_free (void *ptr)
{
- yajl_tree_free (* (yajl_val *) ptr);
+ yajl_tree_free (*(yajl_val *)ptr);
}
#else
@@ -69,14 +70,14 @@ guestfs_impl_disk_format (guestfs_h *g, const char *filename)
if (tree == NULL)
return NULL;
- if (! YAJL_IS_OBJECT (tree))
+ if (!YAJL_IS_OBJECT (tree))
goto bad_type;
- len = YAJL_GET_OBJECT(tree)->len;
+ len = YAJL_GET_OBJECT (tree)->len;
for (i = 0; i < len; ++i) {
- if (STREQ (YAJL_GET_OBJECT(tree)->keys[i], "format")) {
+ if (STREQ (YAJL_GET_OBJECT (tree)->keys[i], "format")) {
const char *str;
- yajl_val node = YAJL_GET_OBJECT(tree)->values[i];
+ yajl_val node = YAJL_GET_OBJECT (tree)->values[i];
if (YAJL_IS_NULL (node))
goto bad_type;
str = YAJL_GET_STRING (node);
@@ -86,7 +87,7 @@ guestfs_impl_disk_format (guestfs_h *g, const char *filename)
}
}
- bad_type:
+bad_type:
error (g, _("qemu-img info: JSON output did not contain 'format'
key"));
return NULL;
}
@@ -100,27 +101,29 @@ guestfs_impl_disk_virtual_size (guestfs_h *g, const char *filename)
if (tree == NULL)
return -1;
- if (! YAJL_IS_OBJECT (tree))
+ if (!YAJL_IS_OBJECT (tree))
goto bad_type;
- len = YAJL_GET_OBJECT(tree)->len;
+ len = YAJL_GET_OBJECT (tree)->len;
for (i = 0; i < len; ++i) {
- if (STREQ (YAJL_GET_OBJECT(tree)->keys[i], "virtual-size")) {
- yajl_val node = YAJL_GET_OBJECT(tree)->values[i];
+ if (STREQ (YAJL_GET_OBJECT (tree)->keys[i], "virtual-size")) {
+ yajl_val node = YAJL_GET_OBJECT (tree)->values[i];
if (YAJL_IS_NULL (node))
goto bad_type;
- if (! YAJL_IS_NUMBER (node))
+ if (!YAJL_IS_NUMBER (node))
goto bad_type;
- if (! YAJL_IS_INTEGER (node)) {
- error (g, _("qemu-img info: 'virtual-size' is not representable as a
64 bit integer"));
+ if (!YAJL_IS_INTEGER (node)) {
+ error (g, _("qemu-img info: 'virtual-size' is not representable
"
+ "as a 64 bit integer"));
return -1;
}
return YAJL_GET_INTEGER (node);
}
}
- bad_type:
- error (g, _("qemu-img info: JSON output did not contain 'virtual-size'
key"));
+bad_type:
+ error (
+ g, _("qemu-img info: JSON output did not contain 'virtual-size'
key"));
return -1;
}
@@ -133,13 +136,13 @@ guestfs_impl_disk_has_backing_file (guestfs_h *g, const char
*filename)
if (tree == NULL)
return -1;
- if (! YAJL_IS_OBJECT (tree))
+ if (!YAJL_IS_OBJECT (tree))
goto bad_type;
- len = YAJL_GET_OBJECT(tree)->len;
+ len = YAJL_GET_OBJECT (tree)->len;
for (i = 0; i < len; ++i) {
- if (STREQ (YAJL_GET_OBJECT(tree)->keys[i], "backing-filename")) {
- yajl_val node = YAJL_GET_OBJECT(tree)->values[i];
+ if (STREQ (YAJL_GET_OBJECT (tree)->keys[i], "backing-filename")) {
+ yajl_val node = YAJL_GET_OBJECT (tree)->values[i];
/* Work on the assumption that if this field is null, it means
* no backing file, rather than being an error.
*/
@@ -151,7 +154,7 @@ guestfs_impl_disk_has_backing_file (guestfs_h *g, const char
*filename)
return 0; /* no backing-filename key means no backing file */
- bad_type:
+bad_type:
error (g, _("qemu-img info: JSON output was not an object"));
return -1;
}
@@ -159,8 +162,9 @@ guestfs_impl_disk_has_backing_file (guestfs_h *g, const char
*filename)
/* Run 'qemu-img info --output json filename', and parse the output
* as JSON, returning a JSON tree and handling errors.
*/
-static void parse_json (guestfs_h *g, void *treevp, const char *input, size_t len);
-#define PARSE_JSON_NO_OUTPUT ((void *) -1)
+static void parse_json (guestfs_h *g, void *treevp, const char *input,
+ size_t len);
+#define PARSE_JSON_NO_OUTPUT ((void *)-1)
static yajl_val
get_json_output (guestfs_h *g, const char *filename)
@@ -209,15 +213,16 @@ get_json_output (guestfs_h *g, const char *filename)
}
if (tree == NULL)
- return NULL; /* parse_json callback already set an error */
+ return NULL; /* parse_json callback already set an error */
if (tree == PARSE_JSON_NO_OUTPUT) {
/* If this ever happened, it would indicate a bug in 'qemu-img info'. */
- error (g, _("qemu-img info command produced no output, but didn't return an
error status code"));
+ error (g, _("qemu-img info command produced no output, but didn't "
+ "return an error status code"));
return NULL;
}
- return tree; /* caller must call yajl_tree_free (tree) */
+ return tree; /* caller must call yajl_tree_free (tree) */
}
/* Parse the JSON document printed by qemu-img info --output json. */
diff --git a/src/inspect-apps.c b/src/inspect-apps.c
index e53d87c..e56d321 100644
--- a/src/inspect-apps.c
+++ b/src/inspect-apps.c
@@ -33,11 +33,11 @@
#if defined __APPLE__ && defined __MACH__
/* Define/include necessary items on MacOS X */
#include <machine/endian.h>
-#define __BIG_ENDIAN BIG_ENDIAN
-#define __LITTLE_ENDIAN LITTLE_ENDIAN
-#define __BYTE_ORDER BYTE_ORDER
+#define __BIG_ENDIAN BIG_ENDIAN
+#define __LITTLE_ENDIAN LITTLE_ENDIAN
+#define __BYTE_ORDER BYTE_ORDER
#include <libkern/OSByteOrder.h>
-#define __bswap_32 OSSwapConstInt32
+#define __bswap_32 OSSwapConstInt32
#endif /* __APPLE__ */
#include "guestfs.h"
@@ -45,13 +45,23 @@
#include "guestfs-internal-actions.h"
#ifdef DB_DUMP
-static struct guestfs_application2_list *list_applications_rpm (guestfs_h *g, struct
inspect_fs *fs);
+static struct guestfs_application2_list *
+list_applications_rpm (guestfs_h *g, struct inspect_fs *fs);
#endif
-static struct guestfs_application2_list *list_applications_deb (guestfs_h *g, struct
inspect_fs *fs);
-static struct guestfs_application2_list *list_applications_pacman (guestfs_h *g, struct
inspect_fs *fs);
-static struct guestfs_application2_list *list_applications_apk (guestfs_h *g, struct
inspect_fs *fs);
-static struct guestfs_application2_list *list_applications_windows (guestfs_h *g, struct
inspect_fs *fs);
-static void add_application (guestfs_h *g, struct guestfs_application2_list *, const char
*name, const char *display_name, int32_t epoch, const char *version, const char *release,
const char *arch, const char *install_path, const char *publisher, const char *url, const
char *description);
+static struct guestfs_application2_list *
+list_applications_deb (guestfs_h *g, struct inspect_fs *fs);
+static struct guestfs_application2_list *
+list_applications_pacman (guestfs_h *g, struct inspect_fs *fs);
+static struct guestfs_application2_list *
+list_applications_apk (guestfs_h *g, struct inspect_fs *fs);
+static struct guestfs_application2_list *
+list_applications_windows (guestfs_h *g, struct inspect_fs *fs);
+static void
+add_application (guestfs_h *g, struct guestfs_application2_list *,
+ const char *name, const char *display_name, int32_t epoch,
+ const char *version, const char *release, const char *arch,
+ const char *install_path, const char *publisher,
+ const char *url, const char *description);
static void sort_applications (struct guestfs_application2_list *);
/* The deprecated guestfs_inspect_list_applications call, which is now
@@ -72,8 +82,7 @@ guestfs_impl_inspect_list_applications (guestfs_h *g, const char *root)
/* Translate the structures from the new format to the old format. */
ret = safe_malloc (g, sizeof (struct guestfs_application_list));
ret->len = r->len;
- ret->val =
- safe_malloc (g, sizeof (struct guestfs_application) * r->len);
+ ret->val = safe_malloc (g, sizeof (struct guestfs_application) * r->len);
for (i = 0; i < r->len; ++i) {
ret->val[i].app_name = r->val[i].app2_name;
ret->val[i].app_display_name = r->val[i].app2_display_name;
@@ -95,7 +104,7 @@ guestfs_impl_inspect_list_applications (guestfs_h *g, const char
*root)
free (r->val[i].app2_spare3);
free (r->val[i].app2_spare4);
}
- free (r->val); /* Must not free the other strings. */
+ free (r->val); /* Must not free the other strings. */
free (r);
return ret;
@@ -135,10 +144,10 @@ guestfs_impl_inspect_list_applications2 (guestfs_h *g, const char
*root)
break;
case OS_PACKAGE_FORMAT_PACMAN:
- ret = list_applications_pacman (g, fs);
- if (ret == NULL)
- return NULL;
- break;
+ ret = list_applications_pacman (g, fs);
+ if (ret == NULL)
+ return NULL;
+ break;
case OS_PACKAGE_FORMAT_APK:
ret = list_applications_apk (g, fs);
@@ -149,8 +158,7 @@ guestfs_impl_inspect_list_applications2 (guestfs_h *g, const char
*root)
case OS_PACKAGE_FORMAT_EBUILD:
case OS_PACKAGE_FORMAT_PISI:
case OS_PACKAGE_FORMAT_PKGSRC:
- case OS_PACKAGE_FORMAT_UNKNOWN:
- ; /* nothing */
+ case OS_PACKAGE_FORMAT_UNKNOWN:; /* nothing */
}
break;
@@ -165,8 +173,7 @@ guestfs_impl_inspect_list_applications2 (guestfs_h *g, const char
*root)
case OS_TYPE_NETBSD:
case OS_TYPE_DOS:
case OS_TYPE_OPENBSD:
- case OS_TYPE_UNKNOWN:
- ; /* nothing */
+ case OS_TYPE_UNKNOWN:; /* nothing */
}
}
@@ -217,10 +224,8 @@ compare_links (const void *av, const void *bv)
}
static int
-read_rpm_name (guestfs_h *g,
- const unsigned char *key, size_t keylen,
- const unsigned char *value, size_t valuelen,
- void *listv)
+read_rpm_name (guestfs_h *g, const unsigned char *key, size_t keylen,
+ const unsigned char *value, size_t valuelen, void *listv)
{
struct rpm_names_list *list = listv;
const unsigned char *link_p;
@@ -236,7 +241,7 @@ read_rpm_name (guestfs_h *g,
* entry. Add an entry onto list for all installed instances.
*/
for (link_p = value; link_p < value + valuelen; link_p += 8) {
- name = safe_strndup (g, (const char *) key, keylen);
+ name = safe_strndup (g, (const char *)key, keylen);
list->names = safe_realloc (g, list->names,
(list->len + 1) * sizeof (struct rpm_name));
@@ -254,8 +259,8 @@ read_rpm_name (guestfs_h *g,
/* tag constants, see rpmtag.h in RPM for complete list */
#define RPMTAG_VERSION 1001
#define RPMTAG_RELEASE 1002
-#define RPMTAG_EPOCH 1003
-#define RPMTAG_ARCH 1022
+#define RPMTAG_EPOCH 1003
+#define RPMTAG_ARCH 1022
static char *
get_rpm_header_tag (guestfs_h *g, const unsigned char *header_start,
@@ -279,7 +284,7 @@ get_rpm_header_tag (guestfs_h *g, const unsigned char *header_start,
if (header_len < 24)
return NULL;
- num_fields = be32toh (*(uint32_t *) header_start);
+ num_fields = be32toh (*(uint32_t *)header_start);
store = header_start + 8 + (16 * num_fields);
/* The first byte *after* the buffer. If you are here, you've gone
@@ -287,8 +292,8 @@ get_rpm_header_tag (guestfs_h *g, const unsigned char *header_start,
header_end = header_start + header_len;
while (cursor < store && cursor <= header_end - 16) {
- if (be32toh (*(uint32_t *) cursor) == tag) {
- offset = be32toh(*(uint32_t *) (cursor + 8));
+ if (be32toh (*(uint32_t *)cursor) == tag) {
+ offset = be32toh (*(uint32_t *)(cursor + 8));
if (store + offset >= header_end)
return NULL;
@@ -296,11 +301,11 @@ get_rpm_header_tag (guestfs_h *g, const unsigned char
*header_start,
switch (type) {
case 's':
- return safe_strndup (g, (const char *) (store + offset), max_len);
+ return safe_strndup (g, (const char *)(store + offset), max_len);
case 'i':
memset (iv, 0, sizeof iv);
- memcpy (iv, (void *) (store + offset),
+ memcpy (iv, (void *)(store + offset),
max_len > sizeof iv ? sizeof iv : max_len);
return safe_memdup (g, iv, sizeof iv);
@@ -320,15 +325,13 @@ struct read_package_data {
};
static int
-read_package (guestfs_h *g,
- const unsigned char *key, size_t keylen,
- const unsigned char *value, size_t valuelen,
- void *datav)
+read_package (guestfs_h *g, const unsigned char *key, size_t keylen,
+ const unsigned char *value, size_t valuelen, void *datav)
{
struct read_package_data *data = datav;
struct rpm_name nkey, *entry;
- CLEANUP_FREE char *version = NULL, *release = NULL,
- *epoch_str = NULL, *arch = NULL;
+ CLEANUP_FREE char *version = NULL, *release = NULL, *epoch_str = NULL,
+ *arch = NULL;
int32_t epoch;
/* This function reads one (key, value) pair from the Packages
@@ -347,7 +350,7 @@ read_package (guestfs_h *g,
entry = bsearch (&nkey, data->list->names, data->list->len,
sizeof (struct rpm_name), compare_links);
if (!entry)
- return 0; /* Not found - ignore it. */
+ return 0; /* Not found - ignore it. */
/* We found a matching link entry, so that gives us the application
* name (entry->name). Now we can get other data for this
@@ -361,14 +364,14 @@ read_package (guestfs_h *g,
/* The epoch is stored as big-endian integer. */
if (epoch_str)
- epoch = be32toh (*(int32_t *) epoch_str);
+ epoch = be32toh (*(int32_t *)epoch_str);
else
epoch = 0;
/* Add the application and what we know. */
if (version && release)
- add_application (g, data->apps, entry->name, "", epoch, version,
release,
- arch ? arch : "", "", "",
"", "");
+ add_application (g, data->apps, entry->name, "", epoch, version,
+ release, arch ? arch : "", "", "",
"", "");
return 0;
}
@@ -379,19 +382,17 @@ static struct guestfs_application2_list *
list_applications_rpm (guestfs_h *g, struct inspect_fs *fs)
{
CLEANUP_FREE char *Name = NULL, *Packages = NULL;
- struct rpm_names_list list = { .names = NULL, .len = 0 };
+ struct rpm_names_list list = {.names = NULL, .len = 0 };
struct guestfs_application2_list *apps = NULL;
struct read_package_data data;
- Name = guestfs_int_download_to_tmp (g, fs,
- "/var/lib/rpm/Name", "rpm_Name",
- MAX_PKG_DB_SIZE);
+ Name = guestfs_int_download_to_tmp (g, fs, "/var/lib/rpm/Name",
+ "rpm_Name", MAX_PKG_DB_SIZE);
if (Name == NULL)
goto error;
- Packages = guestfs_int_download_to_tmp (g, fs,
- "/var/lib/rpm/Packages", "rpm_Packages",
- MAX_PKG_DB_SIZE);
+ Packages = guestfs_int_download_to_tmp (g, fs, "/var/lib/rpm/Packages",
+ "rpm_Packages", MAX_PKG_DB_SIZE);
if (Packages == NULL)
goto error;
@@ -417,7 +418,7 @@ list_applications_rpm (guestfs_h *g, struct inspect_fs *fs)
return apps;
- error:
+error:
free_rpm_names_list (&list);
guestfs_free_application2_list (apps);
@@ -435,11 +436,12 @@ list_applications_deb (guestfs_h *g, struct inspect_fs *fs)
char line[1024];
size_t len;
int32_t epoch = 0;
- CLEANUP_FREE char *name = NULL, *version = NULL, *release = NULL, *arch = NULL;
+ CLEANUP_FREE char *name = NULL, *version = NULL, *release = NULL,
+ *arch = NULL;
int installed_flag = 0;
- status = guestfs_int_download_to_tmp (g, fs, "/var/lib/dpkg/status",
"status",
- MAX_PKG_DB_SIZE);
+ status = guestfs_int_download_to_tmp (g, fs, "/var/lib/dpkg/status",
+ "status", MAX_PKG_DB_SIZE);
if (status == NULL)
return NULL;
@@ -463,8 +465,8 @@ list_applications_deb (guestfs_h *g, struct inspect_fs *fs)
*/
while (fgets (line, sizeof line, fp) != NULL) {
len = strlen (line);
- if (len > 0 && line[len-1] == '\n') {
- line[len-1] = '\0';
+ if (len > 0 && line[len - 1] == '\n') {
+ line[len - 1] = '\0';
len--;
}
@@ -482,8 +484,10 @@ list_applications_deb (guestfs_h *g, struct inspect_fs *fs)
p1 = strchr (&line[9], ':');
if (p1) {
*p1++ = '\0';
- epoch = guestfs_int_parse_unsigned_int (g, &line[9]); /* -1 on error */
- } else {
+ epoch =
+ guestfs_int_parse_unsigned_int (g, &line[9]); /* -1 on error */
+ }
+ else {
p1 = &line[9];
epoch = 0;
}
@@ -491,7 +495,8 @@ list_applications_deb (guestfs_h *g, struct inspect_fs *fs)
if (p2) {
*p2++ = '\0';
release = safe_strdup (g, p2);
- } else {
+ }
+ else {
release = NULL;
}
version = safe_strdup (g, p1);
@@ -502,8 +507,8 @@ list_applications_deb (guestfs_h *g, struct inspect_fs *fs)
}
else if (STREQ (line, "")) {
if (installed_flag && name && version && (epoch >= 0))
- add_application (g, apps, name, "", epoch, version, release ? :
"",
- arch ? : "", "", "", "",
"");
+ add_application (g, apps, name, "", epoch, version, release ?:
"",
+ arch ?: "", "", "", "",
"");
free (name);
free (version);
free (release);
@@ -520,7 +525,7 @@ list_applications_deb (guestfs_h *g, struct inspect_fs *fs)
ret = apps;
- out:
+out:
if (ret == NULL)
guestfs_free_application2_list (apps);
/*
@@ -544,7 +549,8 @@ list_applications_pacman (guestfs_h *g, struct inspect_fs *fs)
CLEANUP_FREE char *arch = NULL, *url = NULL;
char **key = NULL, *rel = NULL, *ver = NULL, *p;
int32_t epoch;
- const size_t path_len = strlen ("/var/lib/pacman/local/") + strlen
("/desc");
+ const size_t path_len =
+ strlen ("/var/lib/pacman/local/") + strlen ("/desc");
local_db = guestfs_readdir (g, "/var/lib/pacman/local");
if (local_db == NULL)
@@ -558,17 +564,20 @@ list_applications_pacman (guestfs_h *g, struct inspect_fs *fs)
for (i = 0; i < local_db->len; i++) {
curr = &local_db->val[i];
- if (curr->ftyp != 'd' || STREQ (curr->name, ".") || STREQ
(curr->name, ".."))
+ if (curr->ftyp != 'd' || STREQ (curr->name, ".") ||
+ STREQ (curr->name, ".."))
continue;
free (fname);
fname = safe_malloc (g, strlen (curr->name) + path_len + 1);
sprintf (fname, "/var/lib/pacman/local/%s/desc", curr->name);
free (desc_file);
- desc_file = guestfs_int_download_to_tmp (g, fs, fname, curr->name, 8192);
+ desc_file =
+ guestfs_int_download_to_tmp (g, fs, fname, curr->name, 8192);
/* The desc files are small (4K). If the desc file does not exist or is
- * larger than the 8K limit we've used, the database is probably corrupted,
+ * larger than the 8K limit we've used, the database is probably
+ * corrupted,
* but we'll continue with the next package anyway.
*/
if (desc_file == NULL)
@@ -580,8 +589,8 @@ list_applications_pacman (guestfs_h *g, struct inspect_fs *fs)
goto out;
}
- while ((len = getline(&line, &allocsize, fp)) != -1) {
- if (len > 0 && line[len-1] == '\n') {
+ while ((len = getline (&line, &allocsize, fp)) != -1) {
+ if (len > 0 && line[len - 1] == '\n') {
line[--len] = '\0';
}
@@ -619,7 +628,8 @@ list_applications_pacman (guestfs_h *g, struct inspect_fs *fs)
*p = '\0';
epoch = guestfs_int_parse_unsigned_int (g, version); /* -1 on error */
ver = p + 1;
- } else {
+ }
+ else {
epoch = 0;
ver = version;
}
@@ -628,12 +638,13 @@ list_applications_pacman (guestfs_h *g, struct inspect_fs *fs)
if (p) {
*p = '\0';
rel = p + 1;
- } else /* release is a mandatory field */
+ }
+ else /* release is a mandatory field */
goto after_add_application;
if ((epoch >= 0) && (ver[0] != '\0') && (rel[0] !=
'\0'))
add_application (g, apps, name, "", epoch, ver, rel, arch, "",
"",
- url ? : "", desc ? : "");
+ url ?: "", desc ?: "");
after_add_application:
key = NULL;
@@ -649,12 +660,11 @@ list_applications_pacman (guestfs_h *g, struct inspect_fs *fs)
perrorf (g, "fclose: %s", desc_file);
goto out;
}
-
}
ret = apps;
- out:
+out:
if (ret == NULL)
guestfs_free_application2_list (apps);
@@ -670,8 +680,8 @@ list_applications_apk (guestfs_h *g, struct inspect_fs *fs)
size_t allocsize = 0;
ssize_t len;
int32_t epoch = 0;
- CLEANUP_FREE char *name = NULL, *version = NULL, *release = NULL, *arch = NULL,
- *url = NULL, *description = NULL;
+ CLEANUP_FREE char *name = NULL, *version = NULL, *release = NULL,
+ *arch = NULL, *url = NULL, *description = NULL;
installed = guestfs_int_download_to_tmp (g, fs, "/lib/apk/db/installed",
"installed", MAX_PKG_DB_SIZE);
@@ -693,8 +703,8 @@ list_applications_apk (guestfs_h *g, struct inspect_fs *fs)
* a blank line. Each package line is <character>:<field>.
*/
while ((len = getline (&line, &allocsize, fp)) != -1) {
- if (len > 0 && line[len-1] == '\n') {
- line[len-1] = '\0';
+ if (len > 0 && line[len - 1] == '\n') {
+ line[len - 1] = '\0';
--len;
}
@@ -706,8 +716,8 @@ list_applications_apk (guestfs_h *g, struct inspect_fs *fs)
switch (line[0]) {
case '\0':
if (name && version && (epoch >= 0))
- add_application (g, apps, name, "", epoch, version, release ? :
"",
- arch ? : "", "", "", url ? :
"", description ? : "");
+ add_application (g, apps, name, "", epoch, version, release ?:
"",
+ arch ?: "", "", "", url ?:
"", description ?: "");
free (name);
free (version);
free (release);
@@ -739,8 +749,10 @@ list_applications_apk (guestfs_h *g, struct inspect_fs *fs)
p1 = strchr (&line[2], ':');
if (p1) {
*p1++ = '\0';
- epoch = guestfs_int_parse_unsigned_int (g, &line[2]); /* -1 on error */
- } else {
+ epoch =
+ guestfs_int_parse_unsigned_int (g, &line[2]); /* -1 on error */
+ }
+ else {
p1 = &line[2];
epoch = 0;
}
@@ -751,7 +763,8 @@ list_applications_apk (guestfs_h *g, struct inspect_fs *fs)
if (p2[0] == 'r')
++p2;
release = safe_strdup (g, p2);
- } else {
+ }
+ else {
release = NULL;
}
version = safe_strdup (g, p1);
@@ -766,7 +779,7 @@ list_applications_apk (guestfs_h *g, struct inspect_fs *fs)
ret = apps;
- out:
+out:
if (ret == NULL)
guestfs_free_application2_list (apps);
/*
@@ -776,13 +789,16 @@ list_applications_apk (guestfs_h *g, struct inspect_fs *fs)
return ret;
}
-static void list_applications_windows_from_path (guestfs_h *g, struct
guestfs_application2_list *apps, const char **path, size_t path_len);
+static void
+list_applications_windows_from_path (guestfs_h *g,
+ struct guestfs_application2_list *apps,
+ const char **path, size_t path_len);
static struct guestfs_application2_list *
list_applications_windows (guestfs_h *g, struct inspect_fs *fs)
{
- CLEANUP_FREE char *software =
- safe_asprintf (g, "%s/system32/config/software",
fs->windows_systemroot);
+ CLEANUP_FREE char *software = safe_asprintf (
+ g, "%s/system32/config/software", fs->windows_systemroot);
CLEANUP_FREE char *software_path;
struct guestfs_application2_list *ret = NULL;
@@ -790,8 +806,8 @@ list_applications_windows (guestfs_h *g, struct inspect_fs *fs)
if (!software_path)
return NULL;
- if (guestfs_hivex_open (g, software_path,
- GUESTFS_HIVEX_OPEN_VERBOSE, g->verbose, -1) == -1)
+ if (guestfs_hivex_open (g, software_path, GUESTFS_HIVEX_OPEN_VERBOSE,
+ g->verbose, -1) == -1)
return NULL;
/* Allocate apps list. */
@@ -800,18 +816,18 @@ list_applications_windows (guestfs_h *g, struct inspect_fs *fs)
ret->val = NULL;
/* Ordinary native applications. */
- const char *hivepath[] =
- { "Microsoft", "Windows", "CurrentVersion",
"Uninstall" };
- list_applications_windows_from_path (g, ret, hivepath,
- sizeof hivepath / sizeof hivepath[0]);
+ const char *hivepath[] = { "Microsoft", "Windows",
"CurrentVersion",
+ "Uninstall" };
+ list_applications_windows_from_path (
+ g, ret, hivepath, sizeof hivepath / sizeof hivepath[0]);
/* 32-bit emulated Windows apps running on the WOW64 emulator.
*
http://support.microsoft.com/kb/896459 (RHBZ#692545).
*/
- const char *hivepath2[] =
- { "WOW6432node", "Microsoft", "Windows",
"CurrentVersion", "Uninstall" };
- list_applications_windows_from_path (g, ret, hivepath2,
- sizeof hivepath2 / sizeof hivepath2[0]);
+ const char *hivepath2[] = { "WOW6432node", "Microsoft",
"Windows",
+ "CurrentVersion", "Uninstall" };
+ list_applications_windows_from_path (
+ g, ret, hivepath2, sizeof hivepath2 / sizeof hivepath2[0]);
guestfs_hivex_close (g);
return ret;
@@ -822,7 +838,8 @@ list_applications_windows_from_path (guestfs_h *g,
struct guestfs_application2_list *apps,
const char **path, size_t path_len)
{
- CLEANUP_FREE_HIVEX_NODE_LIST struct guestfs_hivex_node_list *children = NULL;
+ CLEANUP_FREE_HIVEX_NODE_LIST struct guestfs_hivex_node_list *children =
+ NULL;
int64_t node;
size_t i;
@@ -846,7 +863,8 @@ list_applications_windows_from_path (guestfs_h *g,
int64_t child = children->val[i].hivex_node_h;
int64_t value;
CLEANUP_FREE char *name = NULL, *display_name = NULL, *version = NULL,
- *install_path = NULL, *publisher = NULL, *url = NULL, *comments = NULL;
+ *install_path = NULL, *publisher = NULL, *url = NULL,
+ *comments = NULL;
/* Use the node name as a proxy for the package name in Linux. The
* display name is not language-independent, so it cannot be used.
@@ -875,13 +893,9 @@ list_applications_windows_from_path (guestfs_h *g,
if (value)
comments = guestfs_hivex_value_utf8 (g, value);
- add_application (g, apps, name, display_name, 0,
- version ? : "",
- "", "",
- install_path ? : "",
- publisher ? : "",
- url ? : "",
- comments ? : "");
+ add_application (g, apps, name, display_name, 0, version ?: "",
"",
+ "", install_path ?: "", publisher ?:
"", url ?: "",
+ comments ?: "");
}
}
}
@@ -891,35 +905,36 @@ static void
add_application (guestfs_h *g, struct guestfs_application2_list *apps,
const char *name, const char *display_name, int32_t epoch,
const char *version, const char *release, const char *arch,
- const char *install_path,
- const char *publisher, const char *url,
- const char *description)
+ const char *install_path, const char *publisher,
+ const char *url, const char *description)
{
apps->len++;
- apps->val = safe_realloc (g, apps->val,
- apps->len * sizeof (struct guestfs_application2));
- apps->val[apps->len-1].app2_name = safe_strdup (g, name);
- apps->val[apps->len-1].app2_display_name = safe_strdup (g, display_name);
- apps->val[apps->len-1].app2_epoch = epoch;
- apps->val[apps->len-1].app2_version = safe_strdup (g, version);
- apps->val[apps->len-1].app2_release = safe_strdup (g, release);
- apps->val[apps->len-1].app2_arch = safe_strdup (g, arch);
- apps->val[apps->len-1].app2_install_path = safe_strdup (g, install_path);
+ apps->val = safe_realloc (
+ g, apps->val, apps->len * sizeof (struct guestfs_application2));
+ apps->val[apps->len - 1].app2_name = safe_strdup (g, name);
+ apps->val[apps->len - 1].app2_display_name =
+ safe_strdup (g, display_name);
+ apps->val[apps->len - 1].app2_epoch = epoch;
+ apps->val[apps->len - 1].app2_version = safe_strdup (g, version);
+ apps->val[apps->len - 1].app2_release = safe_strdup (g, release);
+ apps->val[apps->len - 1].app2_arch = safe_strdup (g, arch);
+ apps->val[apps->len - 1].app2_install_path =
+ safe_strdup (g, install_path);
/* XXX Translated path is not implemented yet. */
- apps->val[apps->len-1].app2_trans_path = safe_strdup (g, "");
- apps->val[apps->len-1].app2_publisher = safe_strdup (g, publisher);
- apps->val[apps->len-1].app2_url = safe_strdup (g, url);
+ apps->val[apps->len - 1].app2_trans_path = safe_strdup (g, "");
+ apps->val[apps->len - 1].app2_publisher = safe_strdup (g, publisher);
+ apps->val[apps->len - 1].app2_url = safe_strdup (g, url);
/* XXX The next two are not yet implemented for any package
* format, but we could easily support them for rpm and deb.
*/
- apps->val[apps->len-1].app2_source_package = safe_strdup (g, "");
- apps->val[apps->len-1].app2_summary = safe_strdup (g, "");
- apps->val[apps->len-1].app2_description = safe_strdup (g, description);
+ apps->val[apps->len - 1].app2_source_package = safe_strdup (g, "");
+ apps->val[apps->len - 1].app2_summary = safe_strdup (g, "");
+ apps->val[apps->len - 1].app2_description = safe_strdup (g, description);
/* XXX Reserved for future use. */
- apps->val[apps->len-1].app2_spare1 = safe_strdup (g, "");
- apps->val[apps->len-1].app2_spare2 = safe_strdup (g, "");
- apps->val[apps->len-1].app2_spare3 = safe_strdup (g, "");
- apps->val[apps->len-1].app2_spare4 = safe_strdup (g, "");
+ apps->val[apps->len - 1].app2_spare1 = safe_strdup (g, "");
+ apps->val[apps->len - 1].app2_spare2 = safe_strdup (g, "");
+ apps->val[apps->len - 1].app2_spare3 = safe_strdup (g, "");
+ apps->val[apps->len - 1].app2_spare4 = safe_strdup (g, "");
}
/* Sort applications by name before returning the list. */
diff --git a/src/inspect-fs-cd.c b/src/inspect-fs-cd.c
index b008f58..0c56662 100644
--- a/src/inspect-fs-cd.c
+++ b/src/inspect-fs-cd.c
@@ -55,7 +55,7 @@ check_debian_installer_root (guestfs_h *g, struct inspect_fs *fs)
else if (STRPREFIX (fs->product_name, "Debian"))
fs->distro = OS_DISTRO_DEBIAN;
- (void) guestfs_int_parse_major_minor (g, fs);
+ (void)guestfs_int_parse_major_minor (g, fs);
if (guestfs_is_file (g, "/.disk/cd_type") > 0) {
CLEANUP_FREE char *cd_type =
@@ -68,8 +68,7 @@ check_debian_installer_root (guestfs_h *g, struct inspect_fs *fs)
fs->is_multipart_disk = 0;
fs->is_netinst_disk = 0;
}
- else if (STRPREFIX (cd_type, "dvd") ||
- STRPREFIX (cd_type, "full_cd")) {
+ else if (STRPREFIX (cd_type, "dvd") || STRPREFIX (cd_type,
"full_cd")) {
fs->is_multipart_disk = 1;
fs->is_netinst_disk = 0;
}
@@ -181,8 +180,8 @@ check_fedora_installer_root (guestfs_h *g, struct inspect_fs *fs)
fs->type = OS_TYPE_LINUX;
- r = guestfs_int_first_egrep_of_file (g, "/.treeinfo",
- "^family = Fedora$", 0, &str);
+ r = guestfs_int_first_egrep_of_file (g, "/.treeinfo", "^family =
Fedora$",
+ 0, &str);
if (r == -1)
return -1;
if (r > 0) {
@@ -190,9 +189,8 @@ check_fedora_installer_root (guestfs_h *g, struct inspect_fs *fs)
free (str);
}
- r = guestfs_int_first_egrep_of_file (g, "/.treeinfo",
- "^family = Red Hat Enterprise Linux$",
- 0, &str);
+ r = guestfs_int_first_egrep_of_file (
+ g, "/.treeinfo", "^family = Red Hat Enterprise Linux$", 0,
&str);
if (r == -1)
return -1;
if (r > 0) {
@@ -200,9 +198,8 @@ check_fedora_installer_root (guestfs_h *g, struct inspect_fs *fs)
free (str);
}
- r = guestfs_int_first_egrep_of_file (g, "/.treeinfo",
- "^family = Oracle Linux Server$",
- 0, &str);
+ r = guestfs_int_first_egrep_of_file (
+ g, "/.treeinfo", "^family = Oracle Linux Server$", 0, &str);
if (r == -1)
return -1;
if (r > 0) {
@@ -212,19 +209,20 @@ check_fedora_installer_root (guestfs_h *g, struct inspect_fs *fs)
/* XXX should do major.minor before this */
r = guestfs_int_first_egrep_of_file (g, "/.treeinfo",
- "^version = [[:digit:]]+", 0, &str);
+ "^version = [[:digit:]]+", 0,
&str);
if (r == -1)
return -1;
if (r > 0) {
v = find_value (str);
- fs->major_version = guestfs_int_parse_unsigned_int_ignore_trailing (g, v);
+ fs->major_version =
+ guestfs_int_parse_unsigned_int_ignore_trailing (g, v);
free (str);
if (fs->major_version == -1)
return -1;
}
r = guestfs_int_first_egrep_of_file (g, "/.treeinfo",
- "^arch = [-_[:alnum:]]+$", 0, &str);
+ "^arch = [-_[:alnum:]]+$", 0,
&str);
if (r == -1)
return -1;
if (r > 0) {
@@ -234,7 +232,7 @@ check_fedora_installer_root (guestfs_h *g, struct inspect_fs *fs)
}
r = guestfs_int_first_egrep_of_file (g, "/.treeinfo",
- "^discnum = [[:digit:]]+$", 0, &str);
+ "^discnum = [[:digit:]]+$", 0,
&str);
if (r == -1)
return -1;
if (r > 0) {
@@ -245,8 +243,8 @@ check_fedora_installer_root (guestfs_h *g, struct inspect_fs *fs)
return -1;
}
- r = guestfs_int_first_egrep_of_file (g, "/.treeinfo",
- "^totaldiscs = [[:digit:]]+$", 0, &str);
+ r = guestfs_int_first_egrep_of_file (
+ g, "/.treeinfo", "^totaldiscs = [[:digit:]]+$", 0, &str);
if (r == -1)
return -1;
if (r > 0) {
@@ -279,9 +277,9 @@ check_isolinux_installer_root (guestfs_h *g, struct inspect_fs *fs)
fs->type = OS_TYPE_LINUX;
- r = guestfs_int_first_egrep_of_file (g, "/isolinux/isolinux.cfg",
- "^menu title Welcome to Fedora [[:digit:]]+",
- 0, &str);
+ r = guestfs_int_first_egrep_of_file (
+ g, "/isolinux/isolinux.cfg",
+ "^menu title Welcome to Fedora [[:digit:]]+", 0, &str);
if (r == -1)
return -1;
if (r > 0) {
@@ -294,9 +292,10 @@ check_isolinux_installer_root (guestfs_h *g, struct inspect_fs *fs)
}
/* XXX parse major.minor */
- r = guestfs_int_first_egrep_of_file (g, "/isolinux/isolinux.cfg",
- "^menu title Welcome to Red Hat Enterprise Linux [[:digit:]]+",
- 0, &str);
+ r = guestfs_int_first_egrep_of_file (
+ g, "/isolinux/isolinux.cfg",
+ "^menu title Welcome to Red Hat Enterprise Linux [[:digit:]]+", 0,
+ &str);
if (r == -1)
return -1;
if (r > 0) {
@@ -309,9 +308,9 @@ check_isolinux_installer_root (guestfs_h *g, struct inspect_fs *fs)
}
/* XXX parse major.minor */
- r = guestfs_int_first_egrep_of_file (g, "/isolinux/isolinux.cfg",
- "^menu title Welcome to RHEL[[:digit:]]+",
- 0, &str);
+ r = guestfs_int_first_egrep_of_file (
+ g, "/isolinux/isolinux.cfg", "^menu title Welcome to
RHEL[[:digit:]]+",
+ 0, &str);
if (r == -1)
return -1;
if (r > 0) {
@@ -324,9 +323,9 @@ check_isolinux_installer_root (guestfs_h *g, struct inspect_fs *fs)
}
/* XXX parse major.minor */
- r = guestfs_int_first_egrep_of_file (g, "/isolinux/isolinux.cfg",
- "^menu title Welcome to Oracle Linux Server [[:digit:]]+",
- 0, &str);
+ r = guestfs_int_first_egrep_of_file (
+ g, "/isolinux/isolinux.cfg",
+ "^menu title Welcome to Oracle Linux Server [[:digit:]]+", 0, &str);
if (r == -1)
return -1;
if (r > 0) {
@@ -350,16 +349,16 @@ static void
trim_cr (char *str)
{
size_t n = strlen (str);
- if (n > 0 && str[n-1] == '\r')
- str[n-1] = '\0';
+ if (n > 0 && str[n - 1] == '\r')
+ str[n - 1] = '\0';
}
static void
trim_quot (char *str)
{
size_t n = strlen (str);
- if (n > 0 && str[n-1] == '"')
- str[n-1] = '\0';
+ if (n > 0 && str[n - 1] == '"')
+ str[n - 1] = '\0';
}
static int
@@ -373,41 +372,43 @@ check_w2k3_installer_root (guestfs_h *g, struct inspect_fs *fs,
fs->type = OS_TYPE_WINDOWS;
fs->distro = OS_DISTRO_WINDOWS;
- r = guestfs_int_first_egrep_of_file (g, txtsetup,
- "^productname[[:space:]]*=[[:space:]]*\"", 1, &str);
+ r = guestfs_int_first_egrep_of_file (
+ g, txtsetup, "^productname[[:space:]]*=[[:space:]]*\"", 1, &str);
if (r == -1)
return -1;
if (r > 0) {
trim_cr (str);
trim_quot (str);
v = find_value (str);
- fs->product_name = safe_strdup (g, v+1);
+ fs->product_name = safe_strdup (g, v + 1);
free (str);
}
- r = guestfs_int_first_egrep_of_file (g, txtsetup,
- "^majorversion[[:space:]]*=[[:space:]]*[[:digit:]]+",
- 1, &str);
+ r = guestfs_int_first_egrep_of_file (
+ g, txtsetup, "^majorversion[[:space:]]*=[[:space:]]*[[:digit:]]+", 1,
+ &str);
if (r == -1)
return -1;
if (r > 0) {
trim_cr (str);
v = find_value (str);
- fs->major_version = guestfs_int_parse_unsigned_int_ignore_trailing (g, v);
+ fs->major_version =
+ guestfs_int_parse_unsigned_int_ignore_trailing (g, v);
free (str);
if (fs->major_version == -1)
return -1;
}
- r = guestfs_int_first_egrep_of_file (g, txtsetup,
- "^minorversion[[:space:]]*=[[:space:]]*[[:digit:]]+",
- 1, &str);
+ r = guestfs_int_first_egrep_of_file (
+ g, txtsetup, "^minorversion[[:space:]]*=[[:space:]]*[[:digit:]]+", 1,
+ &str);
if (r == -1)
return -1;
if (r > 0) {
trim_cr (str);
v = find_value (str);
- fs->minor_version = guestfs_int_parse_unsigned_int_ignore_trailing (g, v);
+ fs->minor_version =
+ guestfs_int_parse_unsigned_int_ignore_trailing (g, v);
free (str);
if (fs->minor_version == -1)
return -1;
@@ -417,9 +418,8 @@ check_w2k3_installer_root (guestfs_h *g, struct inspect_fs *fs,
* installation by default, although not necessarily the one that
* the user will finally choose.
*/
- r = guestfs_int_first_egrep_of_file (g, txtsetup,
- "^defaultpath[[:space:]]*=[[:space:]]*",
- 1, &str);
+ r = guestfs_int_first_egrep_of_file (
+ g, txtsetup, "^defaultpath[[:space:]]*=[[:space:]]*", 1, &str);
if (r == -1)
return -1;
if (r > 0) {
@@ -505,7 +505,7 @@ guestfs_int_check_installer_root (guestfs_h *g, struct inspect_fs
*fs)
*/
int
guestfs_int_check_installer_iso (guestfs_h *g, struct inspect_fs *fs,
- const char *device)
+ const char *device)
{
CLEANUP_FREE_ISOINFO struct guestfs_isoinfo *isoinfo = NULL;
const struct osinfo *osinfo;
@@ -518,9 +518,9 @@ guestfs_int_check_installer_iso (guestfs_h *g, struct inspect_fs *fs,
return 0;
r = guestfs_int_osinfo_map (g, isoinfo, &osinfo);
- if (r == -1) /* Fatal error. */
+ if (r == -1) /* Fatal error. */
return -1;
- if (r == 0) /* Could not locate any matching ISO. */
+ if (r == 0) /* Could not locate any matching ISO. */
return 0;
/* Otherwise we matched an ISO, so fill in the fs fields. */
diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c
index dab4370..e24b05d 100644
--- a/src/inspect-fs-unix.c
+++ b/src/inspect-fs-unix.c
@@ -51,8 +51,7 @@ COMPILE_REGEXP (re_scientific_linux_no_minor,
"Scientific Linux.*release (\\d+)", 0)
COMPILE_REGEXP (re_oracle_linux_old,
"Oracle Linux.*release (\\d+).*Update (\\d+)", 0)
-COMPILE_REGEXP (re_oracle_linux,
- "Oracle Linux.*release (\\d+)\\.(\\d+)", 0)
+COMPILE_REGEXP (re_oracle_linux, "Oracle Linux.*release (\\d+)\\.(\\d+)", 0)
COMPILE_REGEXP (re_oracle_linux_no_minor, "Oracle Linux.*release (\\d+)", 0)
COMPILE_REGEXP (re_major_minor, "(\\d+)\\.(\\d+)", 0)
COMPILE_REGEXP (re_xdev, "^/dev/(h|s|v|xv)d([a-z]+)(\\d*)$", 0)
@@ -75,7 +74,9 @@ COMPILE_REGEXP (re_openbsd, "^OpenBSD
(\\d+|\\?)\\.(\\d+|\\?)", 0)
COMPILE_REGEXP (re_openbsd_duid, "^[0-9a-f]{16}\\.[a-z]", 0)
COMPILE_REGEXP (re_openbsd_dev, "^/dev/(s|w)d([0-9])([a-z])$", 0)
COMPILE_REGEXP (re_netbsd_dev, "^/dev/(l|s)d([0-9])([a-z])$", 0)
-COMPILE_REGEXP (re_altlinux, "
(?:(\\d+)(?:\\.(\\d+)(?:[\\.\\d]+)?)?)\\s+\\((?:[^)]+)\\)$", 0)
+COMPILE_REGEXP (
+ re_altlinux,
+ " (?:(\\d+)(?:\\.(\\d+)(?:[\\.\\d]+)?)?)\\s+\\((?:[^)]+)\\)$", 0)
COMPILE_REGEXP (re_frugalware, "Frugalware (\\d+)\\.(\\d+)", 0)
static void check_architecture (guestfs_h *g, struct inspect_fs *fs);
@@ -88,7 +89,10 @@ static void add_fstab_entry (guestfs_h *g, struct inspect_fs *fs,
static char *resolve_fstab_device (guestfs_h *g, const char *spec,
Hash_table *md_map,
enum inspect_os_type os_type);
-static int inspect_with_augeas (guestfs_h *g, struct inspect_fs *fs, const char
**configfiles, int (*f) (guestfs_h *, struct inspect_fs *));
+static int inspect_with_augeas (guestfs_h *g, struct inspect_fs *fs,
+ const char **configfiles,
+ int (*f) (guestfs_h *,
+ struct inspect_fs *));
/* Hash structure for uuid->path lookups */
typedef struct md_uuid {
@@ -96,11 +100,11 @@ typedef struct md_uuid {
char *path;
} md_uuid;
-static size_t uuid_hash(const void *x, size_t table_size);
-static bool uuid_cmp(const void *x, const void *y);
-static void md_uuid_free(void *x);
+static size_t uuid_hash (const void *x, size_t table_size);
+static bool uuid_cmp (const void *x, const void *y);
+static void md_uuid_free (void *x);
-static int parse_uuid(const char *str, uint32_t *uuid);
+static int parse_uuid (const char *str, uint32_t *uuid);
/* Hash structure for path(mdadm)->path(appliance) lookup */
typedef struct {
@@ -108,12 +112,12 @@ typedef struct {
char *app;
} mdadm_app;
-static size_t mdadm_app_hash(const void *x, size_t table_size);
-static bool mdadm_app_cmp(const void *x, const void *y);
-static void mdadm_app_free(void *x);
+static size_t mdadm_app_hash (const void *x, size_t table_size);
+static bool mdadm_app_cmp (const void *x, const void *y);
+static void mdadm_app_free (void *x);
static ssize_t map_app_md_devices (guestfs_h *g, Hash_table **map);
-static int map_md_devices(guestfs_h *g, Hash_table **map);
+static int map_md_devices (guestfs_h *g, Hash_table **map);
/* Set fs->product_name to the first line of the release file. */
static int
@@ -126,7 +130,8 @@ parse_release_file (guestfs_h *g, struct inspect_fs *fs,
if (STREQ (fs->product_name, "")) {
free (fs->product_name);
fs->product_name = NULL;
- error (g, _("release file %s is empty or malformed"), release_filename);
+ error (g, _("release file %s is empty or malformed"),
+ release_filename);
return -1;
}
return 0;
@@ -181,12 +186,12 @@ parse_os_release (guestfs_h *g, struct inspect_fs *fs, const char
*filename)
++value;
value_len = strlen (line) - (value - line);
- if (value_len > 1 && value[0] == '"' &&
value[value_len-1] == '"') {
+ if (value_len > 1 && value[0] == '"' &&
value[value_len - 1] == '"') {
++value;
value_len -= 2;
}
-#define VALUE_IS(a) STREQLEN(value, a, value_len)
+#define VALUE_IS(a) STREQLEN (value, a, value_len)
if (STRPREFIX (line, "ID=")) {
if (VALUE_IS ("alpine"))
distro = OS_DISTRO_ALPINE_LINUX;
@@ -216,10 +221,12 @@ parse_os_release (guestfs_h *g, struct inspect_fs *fs, const char
*filename)
distro = OS_DISTRO_SLES;
else if (VALUE_IS ("ubuntu"))
distro = OS_DISTRO_UBUNTU;
- } else if (STRPREFIX (line, "PRETTY_NAME=")) {
+ }
+ else if (STRPREFIX (line, "PRETTY_NAME=")) {
free (product_name);
product_name = safe_strndup (g, value, value_len);
- } else if (STRPREFIX (line, "VERSION_ID=")) {
+ }
+ else if (STRPREFIX (line, "VERSION_ID=")) {
char *major, *minor;
if (match2 (g, value, re_major_minor, &major, &minor)) {
major_version = guestfs_int_parse_unsigned_int (g, major);
@@ -232,9 +239,10 @@ parse_os_release (guestfs_h *g, struct inspect_fs *fs, const char
*filename)
free (minor);
if (minor_version == -1)
return -1;
- } else {
+ }
+ else {
CLEANUP_FREE char *buf =
- safe_asprintf (g, "%.*s", (int) value_len, value);
+ safe_asprintf (g, "%.*s", (int)value_len, value);
major_version = guestfs_int_parse_unsigned_int (g, buf);
/* Handle cases where VERSION_ID is not a number. */
if (major_version != -1)
@@ -293,14 +301,16 @@ parse_os_release (guestfs_h *g, struct inspect_fs *fs, const char
*filename)
* DISTRIB_DESCRIPTION="Mandriva Linux 2010.1"
* Mandriva also has a normal release file called /etc/mandriva-release.
*
- * CoreOS has a /etc/lsb-release link to /usr/share/coreos/lsb-release containing:
+ * CoreOS has a /etc/lsb-release link to /usr/share/coreos/lsb-release
+ * containing:
* DISTRIB_ID=CoreOS
* DISTRIB_RELEASE=647.0.0
* DISTRIB_CODENAME="Red Dog"
* DISTRIB_DESCRIPTION="CoreOS 647.0.0"
*/
static int
-parse_lsb_release (guestfs_h *g, struct inspect_fs *fs, const char *filename)
+parse_lsb_release (guestfs_h *g, struct inspect_fs *fs,
+ const char *filename)
{
int64_t size;
CLEANUP_FREE_STRING_LIST char **lines = NULL;
@@ -325,13 +335,11 @@ parse_lsb_release (guestfs_h *g, struct inspect_fs *fs, const char
*filename)
return -1;
for (i = 0; lines[i] != NULL; ++i) {
- if (fs->distro == 0 &&
- STREQ (lines[i], "DISTRIB_ID=Ubuntu")) {
+ if (fs->distro == 0 && STREQ (lines[i], "DISTRIB_ID=Ubuntu")) {
fs->distro = OS_DISTRO_UBUNTU;
r = 1;
}
- else if (fs->distro == 0 &&
- STREQ (lines[i], "DISTRIB_ID=LinuxMint")) {
+ else if (fs->distro == 0 && STREQ (lines[i],
"DISTRIB_ID=LinuxMint")) {
fs->distro = OS_DISTRO_LINUX_MINT;
r = 1;
}
@@ -340,13 +348,11 @@ parse_lsb_release (guestfs_h *g, struct inspect_fs *fs, const char
*filename)
fs->distro = OS_DISTRO_MANDRIVA;
r = 1;
}
- else if (fs->distro == 0 &&
- STREQ (lines[i], "DISTRIB_ID=\"Mageia\"")) {
+ else if (fs->distro == 0 && STREQ (lines[i],
"DISTRIB_ID=\"Mageia\"")) {
fs->distro = OS_DISTRO_MAGEIA;
r = 1;
}
- else if (fs->distro == 0 &&
- STREQ (lines[i], "DISTRIB_ID=CoreOS")) {
+ else if (fs->distro == 0 && STREQ (lines[i],
"DISTRIB_ID=CoreOS")) {
fs->distro = OS_DISTRO_COREOS;
r = 1;
}
@@ -387,7 +393,8 @@ parse_lsb_release (guestfs_h *g, struct inspect_fs *fs, const char
*filename)
}
static int
-parse_suse_release (guestfs_h *g, struct inspect_fs *fs, const char *filename)
+parse_suse_release (guestfs_h *g, struct inspect_fs *fs,
+ const char *filename)
{
int64_t size;
char *major, *minor;
@@ -417,8 +424,10 @@ parse_suse_release (guestfs_h *g, struct inspect_fs *fs, const char
*filename)
/* First line is dist release name */
fs->product_name = safe_strdup (g, lines[0]);
- /* Match SLES first because openSuSE regex overlaps some SLES release strings */
- if (match (g, fs->product_name, re_sles) || match (g, fs->product_name, re_nld))
{
+ /* Match SLES first because openSuSE regex overlaps some SLES release
+ * strings */
+ if (match (g, fs->product_name, re_sles) ||
+ match (g, fs->product_name, re_nld)) {
fs->distro = OS_DISTRO_SLES;
/* Second line contains version string */
@@ -461,7 +470,7 @@ parse_suse_release (guestfs_h *g, struct inspect_fs *fs, const char
*filename)
r = 0;
- out:
+out:
return r;
}
@@ -479,20 +488,22 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
fs->type = OS_TYPE_LINUX;
if (guestfs_is_file_opts (g, "/etc/os-release",
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1,
+ -1) > 0) {
r = parse_os_release (g, fs, "/etc/os-release");
- if (r == -1) /* error */
+ if (r == -1) /* error */
return -1;
- if (r == 1) /* ok - detected the release from this file */
+ if (r == 1) /* ok - detected the release from this file */
goto skip_release_checks;
}
if (guestfs_is_file_opts (g, "/etc/lsb-release",
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1,
+ -1) > 0) {
r = parse_lsb_release (g, fs, "/etc/lsb-release");
- if (r == -1) /* error */
+ if (r == -1) /* error */
return -1;
- if (r == 1) /* ok - detected the release from this file */
+ if (r == 1) /* ok - detected the release from this file */
goto skip_release_checks;
}
@@ -500,7 +511,8 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
* checks need to be performed before the Red-Hat one.
*/
if (guestfs_is_file_opts (g, "/etc/oracle-release",
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1,
+ -1) > 0) {
fs->distro = OS_DISTRO_ORACLE_LINUX;
@@ -519,7 +531,9 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
free (minor);
if (fs->minor_version == -1)
return -1;
- } else if ((major = match1 (g, fs->product_name, re_oracle_linux_no_minor)) !=
NULL) {
+ }
+ else if ((major = match1 (g, fs->product_name,
+ re_oracle_linux_no_minor)) != NULL) {
fs->major_version = guestfs_int_parse_unsigned_int (g, major);
free (major);
if (fs->major_version == -1)
@@ -528,14 +542,15 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
}
}
else if (guestfs_is_file_opts (g, "/etc/centos-release",
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1,
+ -1) > 0) {
fs->distro = OS_DISTRO_CENTOS;
if (parse_release_file (g, fs, "/etc/centos-release") == -1)
return -1;
if (match2 (g, fs->product_name, re_centos_old, &major, &minor) ||
- match2 (g, fs->product_name, re_centos, &major, &minor)) {
+ match2 (g, fs->product_name, re_centos, &major, &minor)) {
fs->major_version = guestfs_int_parse_unsigned_int (g, major);
free (major);
if (fs->major_version == -1) {
@@ -547,7 +562,8 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
if (fs->minor_version == -1)
return -1;
}
- else if ((major = match1 (g, fs->product_name, re_centos_no_minor)) != NULL) {
+ else if ((major = match1 (g, fs->product_name, re_centos_no_minor)) !=
+ NULL) {
fs->major_version = guestfs_int_parse_unsigned_int (g, major);
free (major);
if (fs->major_version == -1)
@@ -556,7 +572,8 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
}
}
else if (guestfs_is_file_opts (g, "/etc/altlinux-release",
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1,
+ -1) > 0) {
fs->distro = OS_DISTRO_ALTLINUX;
if (parse_release_file (g, fs, "/etc/altlinux-release") == -1)
@@ -576,8 +593,10 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
}
}
else if (guestfs_is_file_opts (g, "/etc/redhat-release",
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
- fs->distro = OS_DISTRO_REDHAT_BASED; /* Something generic Red Hat-like. */
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1,
+ -1) > 0) {
+ fs->distro =
+ OS_DISTRO_REDHAT_BASED; /* Something generic Red Hat-like. */
if (parse_release_file (g, fs, "/etc/redhat-release") == -1)
return -1;
@@ -603,7 +622,8 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
if (fs->minor_version == -1)
return -1;
}
- else if ((major = match1 (g, fs->product_name, re_rhel_no_minor)) != NULL) {
+ else if ((major = match1 (g, fs->product_name, re_rhel_no_minor)) !=
+ NULL) {
fs->distro = OS_DISTRO_RHEL;
fs->major_version = guestfs_int_parse_unsigned_int (g, major);
free (major);
@@ -625,7 +645,8 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
if (fs->minor_version == -1)
return -1;
}
- else if ((major = match1 (g, fs->product_name, re_centos_no_minor)) != NULL) {
+ else if ((major = match1 (g, fs->product_name, re_centos_no_minor)) !=
+ NULL) {
fs->distro = OS_DISTRO_CENTOS;
fs->major_version = guestfs_int_parse_unsigned_int (g, major);
free (major);
@@ -633,8 +654,10 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
return -1;
fs->minor_version = 0;
}
- else if (match2 (g, fs->product_name, re_scientific_linux_old, &major,
&minor) ||
- match2 (g, fs->product_name, re_scientific_linux, &major,
&minor)) {
+ else if (match2 (g, fs->product_name, re_scientific_linux_old, &major,
+ &minor) ||
+ match2 (g, fs->product_name, re_scientific_linux, &major,
+ &minor)) {
fs->distro = OS_DISTRO_SCIENTIFIC_LINUX;
fs->major_version = guestfs_int_parse_unsigned_int (g, major);
free (major);
@@ -647,7 +670,8 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
if (fs->minor_version == -1)
return -1;
}
- else if ((major = match1 (g, fs->product_name, re_scientific_linux_no_minor)) !=
NULL) {
+ else if ((major = match1 (g, fs->product_name,
+ re_scientific_linux_no_minor)) != NULL) {
fs->distro = OS_DISTRO_SCIENTIFIC_LINUX;
fs->major_version = guestfs_int_parse_unsigned_int (g, major);
free (major);
@@ -657,7 +681,8 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
}
}
else if (guestfs_is_file_opts (g, "/etc/debian_version",
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1,
+ -1) > 0) {
fs->distro = OS_DISTRO_DEBIAN;
if (parse_release_file (g, fs, "/etc/debian_version") == -1)
@@ -667,7 +692,8 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
return -1;
}
else if (guestfs_is_file_opts (g, "/etc/pardus-release",
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1,
+ -1) > 0) {
fs->distro = OS_DISTRO_PARDUS;
if (parse_release_file (g, fs, "/etc/pardus-release") == -1)
@@ -677,7 +703,8 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
return -1;
}
else if (guestfs_is_file_opts (g, "/etc/arch-release",
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1,
+ -1) > 0) {
fs->distro = OS_DISTRO_ARCHLINUX;
/* /etc/arch-release file is empty and I can't see a way to
@@ -685,7 +712,8 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
*/
}
else if (guestfs_is_file_opts (g, "/etc/gentoo-release",
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1,
+ -1) > 0) {
fs->distro = OS_DISTRO_GENTOO;
if (parse_release_file (g, fs, "/etc/gentoo-release") == -1)
@@ -695,7 +723,8 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
return -1;
}
else if (guestfs_is_file_opts (g, "/etc/meego-release",
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1,
+ -1) > 0) {
fs->distro = OS_DISTRO_MEEGO;
if (parse_release_file (g, fs, "/etc/meego-release") == -1)
@@ -705,7 +734,8 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
return -1;
}
else if (guestfs_is_file_opts (g, "/etc/slackware-version",
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1,
+ -1) > 0) {
fs->distro = OS_DISTRO_SLACKWARE;
if (parse_release_file (g, fs, "/etc/slackware-version") == -1)
@@ -715,7 +745,8 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
return -1;
}
else if (guestfs_is_file_opts (g, "/etc/ttylinux-target",
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1,
+ -1) > 0) {
fs->distro = OS_DISTRO_TTYLINUX;
if (parse_release_file (g, fs, "/etc/ttylinux-target") == -1)
@@ -725,17 +756,18 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
return -1;
}
else if (guestfs_is_file_opts (g, "/etc/SuSE-release",
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1,
+ -1) > 0) {
fs->distro = OS_DISTRO_SUSE_BASED;
if (parse_suse_release (g, fs, "/etc/SuSE-release") == -1)
return -1;
-
}
/* CirrOS versions providing a own version file.
*/
else if (guestfs_is_file_opts (g, "/etc/cirros/version",
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1,
+ -1) > 0) {
fs->distro = OS_DISTRO_CIRROS;
if (parse_release_file (g, fs, "/etc/cirros/version") == -1)
@@ -748,9 +780,11 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
* toolkit. It is used by specific distros such as Cirros.
*/
else if (guestfs_is_file_opts (g, "/etc/br-version",
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1,
+ -1) > 0) {
if (guestfs_is_file_opts (g, "/usr/share/cirros/logo",
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0)
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1,
+ -1) > 0)
fs->distro = OS_DISTRO_CIRROS;
else
fs->distro = OS_DISTRO_BUILDROOT;
@@ -763,7 +797,8 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
return -1;
}
else if (guestfs_is_file_opts (g, "/etc/alpine-release",
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1,
+ -1) > 0) {
fs->distro = OS_DISTRO_ALPINE_LINUX;
if (parse_release_file (g, fs, "/etc/alpine-release") == -1)
@@ -773,7 +808,8 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
return -1;
}
else if (guestfs_is_file_opts (g, "/etc/frugalware-release",
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1,
+ -1) > 0) {
fs->distro = OS_DISTRO_FRUGALWARE;
if (parse_release_file (g, fs, "/etc/frugalware-release") == -1)
@@ -793,7 +829,7 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
}
}
- skip_release_checks:;
+skip_release_checks:;
/* Determine the architecture. */
check_architecture (g, fs);
@@ -826,8 +862,8 @@ guestfs_int_check_freebsd_root (guestfs_h *g, struct inspect_fs *fs)
* we'll use that anyway.
*/
- if (guestfs_is_file_opts (g, "/etc/motd",
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ if (guestfs_is_file_opts (
+ g, "/etc/motd", GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
if (parse_release_file (g, fs, "/etc/motd") == -1)
return -1;
@@ -838,7 +874,8 @@ guestfs_int_check_freebsd_root (guestfs_h *g, struct inspect_fs *fs)
/* Determine the architecture. */
check_architecture (g, fs);
- /* We already know /etc/fstab exists because it's part of the test above. */
+ /* We already know /etc/fstab exists because it's part of the test above.
+ */
const char *configfiles[] = { "/etc/fstab", NULL };
if (inspect_with_augeas (g, fs, configfiles, check_fstab) == -1)
return -1;
@@ -856,7 +893,8 @@ guestfs_int_check_netbsd_root (guestfs_h *g, struct inspect_fs *fs)
{
if (guestfs_is_file_opts (g, "/etc/release",
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1,
+ -1) > 0) {
char *major, *minor;
if (parse_release_file (g, fs, "/etc/release") == -1)
return -1;
@@ -875,14 +913,16 @@ guestfs_int_check_netbsd_root (guestfs_h *g, struct inspect_fs *fs)
if (fs->minor_version == -1)
return -1;
}
- } else {
+ }
+ else {
return -1;
}
/* Determine the architecture. */
check_architecture (g, fs);
- /* We already know /etc/fstab exists because it's part of the test above. */
+ /* We already know /etc/fstab exists because it's part of the test above.
+ */
const char *configfiles[] = { "/etc/fstab", NULL };
if (inspect_with_augeas (g, fs, configfiles, check_fstab) == -1)
return -1;
@@ -898,8 +938,8 @@ guestfs_int_check_netbsd_root (guestfs_h *g, struct inspect_fs *fs)
int
guestfs_int_check_openbsd_root (guestfs_h *g, struct inspect_fs *fs)
{
- if (guestfs_is_file_opts (g, "/etc/motd",
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ if (guestfs_is_file_opts (
+ g, "/etc/motd", GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
CLEANUP_FREE char *major = NULL, *minor = NULL;
/* The first line of this file gets automatically updated at boot. */
@@ -924,14 +964,16 @@ guestfs_int_check_openbsd_root (guestfs_h *g, struct inspect_fs
*fs)
return -1;
}
}
- } else {
+ }
+ else {
return -1;
}
/* Determine the architecture. */
check_architecture (g, fs);
- /* We already know /etc/fstab exists because it's part of the test above. */
+ /* We already know /etc/fstab exists because it's part of the test above.
+ */
const char *configfiles[] = { "/etc/fstab", NULL };
if (inspect_with_augeas (g, fs, configfiles, check_fstab) == -1)
return -1;
@@ -952,7 +994,8 @@ guestfs_int_check_hurd_root (guestfs_h *g, struct inspect_fs *fs)
fs->type = OS_TYPE_HURD;
if (guestfs_is_file_opts (g, "/etc/debian_version",
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1,
+ -1) > 0) {
fs->distro = OS_DISTRO_DEBIAN;
if (parse_release_file (g, fs, "/etc/debian_version") == -1)
@@ -989,7 +1032,8 @@ guestfs_int_check_minix_root (guestfs_h *g, struct inspect_fs *fs)
fs->type = OS_TYPE_MINIX;
if (guestfs_is_file_opts (g, "/etc/version",
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1,
+ -1) > 0) {
char *major, *minor;
if (parse_release_file (g, fs, "/etc/version") == -1)
return -1;
@@ -1006,7 +1050,8 @@ guestfs_int_check_minix_root (guestfs_h *g, struct inspect_fs *fs)
if (fs->minor_version == -1)
return -1;
}
- } else {
+ }
+ else {
return -1;
}
@@ -1059,22 +1104,24 @@ guestfs_int_check_coreos_usr (guestfs_h *g, struct inspect_fs
*fs)
fs->distro = OS_DISTRO_COREOS;
if (guestfs_is_file_opts (g, "/lib/os-release",
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1,
+ -1) > 0) {
r = parse_os_release (g, fs, "/lib/os-release");
- if (r == -1) /* error */
+ if (r == -1) /* error */
return -1;
- if (r == 1) /* ok - detected the release from this file */
+ if (r == 1) /* ok - detected the release from this file */
goto skip_release_checks;
}
if (guestfs_is_file_opts (g, "/share/coreos/lsb-release",
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1,
+ -1) > 0) {
r = parse_lsb_release (g, fs, "/share/coreos/lsb-release");
- if (r == -1) /* error */
+ if (r == -1) /* error */
return -1;
}
- skip_release_checks:;
+skip_release_checks:;
/* Determine the architecture. */
check_architecture (g, fs);
@@ -1090,8 +1137,8 @@ guestfs_int_check_coreos_usr (guestfs_h *g, struct inspect_fs *fs)
static void
check_architecture (guestfs_h *g, struct inspect_fs *fs)
{
- const char *binaries[] =
- { "/bin/bash", "/bin/ls", "/bin/echo",
"/bin/rm", "/bin/sh" };
+ const char *binaries[] = { "/bin/bash", "/bin/ls",
"/bin/echo", "/bin/rm",
+ "/bin/sh" };
size_t i;
char *arch = NULL;
@@ -1100,8 +1147,8 @@ check_architecture (guestfs_h *g, struct inspect_fs *fs)
* relative ones (which can be resolved within the same partition),
* then we can check the architecture of their target.
*/
- if (guestfs_is_file_opts (g, binaries[i],
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ if (guestfs_is_file_opts (
+ g, binaries[i], GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
CLEANUP_FREE char *resolved = NULL;
/* Ignore errors from realpath and file_architecture calls. */
@@ -1163,8 +1210,8 @@ check_hostname_unix (guestfs_h *g, struct inspect_fs *fs)
if (!fs->hostname && guestfs_is_file (g,
"/etc/sysconfig/network")) {
const char *configfiles[] = { "/etc/sysconfig/network", NULL };
- if (inspect_with_augeas (g, fs, configfiles,
- check_hostname_redhat) == -1)
+ if (inspect_with_augeas (g, fs, configfiles, check_hostname_redhat) ==
+ -1)
return -1;
}
break;
@@ -1194,7 +1241,8 @@ check_hostname_unix (guestfs_h *g, struct inspect_fs *fs)
case OS_TYPE_MINIX:
if (guestfs_is_file (g, "/etc/hostname.file")) {
- fs->hostname = guestfs_int_first_line_of_file (g,
"/etc/hostname.file");
+ fs->hostname =
+ guestfs_int_first_line_of_file (g, "/etc/hostname.file");
if (fs->hostname == NULL)
return -1;
if (STREQ (fs->hostname, "")) {
@@ -1274,7 +1322,8 @@ check_hostname_freebsd (guestfs_h *g, struct inspect_fs *fs)
size_t len = strlen (lines[i]) - 10 - 1;
fs->hostname = safe_strndup (g, &lines[i][10], len);
break;
- } else if (STRPREFIX (lines[i], "hostname=")) {
+ }
+ else if (STRPREFIX (lines[i], "hostname=")) {
size_t len = strlen (lines[i]) - 9;
fs->hostname = safe_strndup (g, &lines[i][9], len);
break;
@@ -1292,14 +1341,16 @@ check_fstab (guestfs_h *g, struct inspect_fs *fs)
char augpath[256];
CLEANUP_HASH_FREE Hash_table *md_map = NULL;
bool is_bsd = (fs->type == OS_TYPE_FREEBSD ||
- fs->type == OS_TYPE_NETBSD ||
- fs->type == OS_TYPE_OPENBSD);
+ fs->type == OS_TYPE_NETBSD || fs->type == OS_TYPE_OPENBSD);
- /* Generate a map of MD device paths listed in /etc/mdadm.conf to MD device
+ /* Generate a map of MD device paths listed in /etc/mdadm.conf to MD
+ * device
* paths in the guestfs appliance */
- if (map_md_devices (g, &md_map) == -1) return -1;
+ if (map_md_devices (g, &md_map) == -1)
+ return -1;
- entries = guestfs_aug_match (g, "/files/etc/fstab/*[label() !=
'#comment']");
+ entries =
+ guestfs_aug_match (g, "/files/etc/fstab/*[label() !=
'#comment']");
if (entries == NULL)
return -1;
@@ -1320,8 +1371,7 @@ check_fstab (guestfs_h *g, struct inspect_fs *fs)
* discs.
*/
if ((STRPREFIX (spec, "/dev/fd") && c_isdigit (spec[7])) ||
- STREQ (spec, "/dev/floppy") ||
- STREQ (spec, "/dev/cdrom") ||
+ STREQ (spec, "/dev/floppy") || STREQ (spec, "/dev/cdrom") ||
STRPREFIX (spec, "/dev/iso9660/"))
continue;
@@ -1331,14 +1381,10 @@ check_fstab (guestfs_h *g, struct inspect_fs *fs)
return -1;
/* Ignore certain mountpoints. */
- if (STRPREFIX (mp, "/dev/") ||
- STREQ (mp, "/dev") ||
- STRPREFIX (mp, "/media/") ||
- STRPREFIX (mp, "/proc/") ||
- STREQ (mp, "/proc") ||
- STRPREFIX (mp, "/selinux/") ||
- STREQ (mp, "/selinux") ||
- STRPREFIX (mp, "/sys/") ||
+ if (STRPREFIX (mp, "/dev/") || STREQ (mp, "/dev") ||
+ STRPREFIX (mp, "/media/") || STRPREFIX (mp, "/proc/") ||
+ STREQ (mp, "/proc") || STRPREFIX (mp, "/selinux/") ||
+ STREQ (mp, "/selinux") || STRPREFIX (mp, "/sys/") ||
STREQ (mp, "/sys"))
continue;
@@ -1358,7 +1404,8 @@ check_fstab (guestfs_h *g, struct inspect_fs *fs)
/* Resolve guest block device names. */
mountable = resolve_fstab_device (g, spec, md_map, fs->type);
else if (match (g, spec, re_openbsd_duid)) {
- /* In OpenBSD's fstab you can specify partitions on a disk by appending a
+ /* In OpenBSD's fstab you can specify partitions on a disk by
+ * appending a
* period and a partition letter to a Disklable Unique Identifier. The
* DUID is a 16 hex digit field found in the OpenBSD's altered BSD
* disklabel. For more info see here:
@@ -1370,7 +1417,7 @@ check_fstab (guestfs_h *g, struct inspect_fs *fs)
/* We cannot peep into disklables, we can only assume that this is the
* first disk.
*/
- snprintf(device, 10, "%s%c", "/dev/sd0", part);
+ snprintf (device, 10, "%s%c", "/dev/sd0", part);
mountable = resolve_fstab_device (g, device, md_map, fs->type);
}
@@ -1382,18 +1429,21 @@ check_fstab (guestfs_h *g, struct inspect_fs *fs)
snprintf (augpath, sizeof augpath, "%s/vfstype", *entry);
vfstype = guestfs_aug_get (g, augpath);
- if (vfstype == NULL) return -1;
+ if (vfstype == NULL)
+ return -1;
if (STREQ (vfstype, "btrfs")) {
char **opt;
snprintf (augpath, sizeof augpath, "%s/opt", *entry);
CLEANUP_FREE_STRING_LIST char **opts = guestfs_aug_match (g, augpath);
- if (opts == NULL) return -1;
+ if (opts == NULL)
+ return -1;
for (opt = opts; *opt; opt++) {
CLEANUP_FREE char *optname = guestfs_aug_get (g, augpath);
- if (optname == NULL) return -1;
+ if (optname == NULL)
+ return -1;
if (STREQ (optname, "subvol")) {
CLEANUP_FREE char *subvol = NULL;
@@ -1401,7 +1451,8 @@ check_fstab (guestfs_h *g, struct inspect_fs *fs)
snprintf (augpath, sizeof augpath, "%s/value", *opt);
subvol = guestfs_aug_get (g, augpath);
- if (subvol == NULL) return -1;
+ if (subvol == NULL)
+ return -1;
new = safe_asprintf (g, "btrfsvol:%s/%s", mountable, subvol);
free (mountable);
@@ -1425,8 +1476,8 @@ check_fstab (guestfs_h *g, struct inspect_fs *fs)
* 'mp' is the mount point, which could also be 'swap' or
'none'.
*/
static void
-add_fstab_entry (guestfs_h *g, struct inspect_fs *fs,
- const char *mountable, const char *mountpoint)
+add_fstab_entry (guestfs_h *g, struct inspect_fs *fs, const char *mountable,
+ const char *mountpoint)
{
/* Add this to the fstab entry in 'fs'.
* Note these are further filtered by guestfs_inspect_get_mountpoints
@@ -1440,16 +1491,17 @@ add_fstab_entry (guestfs_h *g, struct inspect_fs *fs,
fs->fstab = p;
fs->nr_fstab = n;
- /* These are owned by the handle and freed by guestfs_int_free_inspect_info. */
- fs->fstab[n-1].mountable = safe_strdup (g, mountable);
- fs->fstab[n-1].mountpoint = safe_strdup (g, mountpoint);
+ /* These are owned by the handle and freed by
+ * guestfs_int_free_inspect_info. */
+ fs->fstab[n - 1].mountable = safe_strdup (g, mountable);
+ fs->fstab[n - 1].mountpoint = safe_strdup (g, mountpoint);
debug (g, "fstab: mountable=%s mountpoint=%s", mountable, mountpoint);
}
/* Compute a uuid hash as a simple xor of of its 4 32bit components */
static size_t
-uuid_hash(const void *x, size_t table_size)
+uuid_hash (const void *x, size_t table_size)
{
const md_uuid *a = x;
size_t h, i;
@@ -1463,25 +1515,26 @@ uuid_hash(const void *x, size_t table_size)
}
static bool
-uuid_cmp(const void *x, const void *y)
+uuid_cmp (const void *x, const void *y)
{
const md_uuid *a = x;
const md_uuid *b = y;
size_t i;
for (i = 0; i < 1; i++) {
- if (a->uuid[i] != b->uuid[i]) return 0;
+ if (a->uuid[i] != b->uuid[i])
+ return 0;
}
return 1;
}
static void
-md_uuid_free(void *x)
+md_uuid_free (void *x)
{
md_uuid *a = x;
- free(a->path);
- free(a);
+ free (a->path);
+ free (a);
}
/* Taken from parse_uuid in mdadm */
@@ -1514,7 +1567,8 @@ parse_uuid (const char *str, uint32_t *uuid)
}
hit++;
}
- if (hit == 32) return 0;
+ if (hit == 32)
+ return 0;
return -1;
}
@@ -1528,20 +1582,24 @@ map_app_md_devices (guestfs_h *g, Hash_table **map)
char **md;
/* A hash mapping uuids to md device names */
- *map = hash_initialize(16, NULL, uuid_hash, uuid_cmp, md_uuid_free);
- if (*map == NULL) g->abort_cb();
+ *map = hash_initialize (16, NULL, uuid_hash, uuid_cmp, md_uuid_free);
+ if (*map == NULL)
+ g->abort_cb ();
- mds = guestfs_list_md_devices(g);
- if (mds == NULL) goto error;
+ mds = guestfs_list_md_devices (g);
+ if (mds == NULL)
+ goto error;
for (md = mds; *md != NULL; md++) {
char **i;
CLEANUP_FREE_STRING_LIST char **detail = guestfs_md_detail (g, *md);
- if (detail == NULL) goto error;
+ if (detail == NULL)
+ goto error;
/* Iterate over keys until we find uuid */
for (i = detail; *i != NULL; i += 2) {
- if (STREQ(*i, "uuid")) break;
+ if (STREQ (*i, "uuid"))
+ break;
}
/* We found it */
@@ -1551,52 +1609,54 @@ map_app_md_devices (guestfs_h *g, Hash_table **map)
/* Next item is the uuid value */
i++;
- entry = safe_malloc(g, sizeof(md_uuid));
- entry->path = safe_strdup(g, *md);
+ entry = safe_malloc (g, sizeof (md_uuid));
+ entry->path = safe_strdup (g, *md);
- if (parse_uuid(*i, entry->uuid) == -1) {
+ if (parse_uuid (*i, entry->uuid) == -1) {
/* Invalid UUID is weird, but not fatal. */
- debug(g, "inspect-os: guestfs_md_detail returned invalid "
- "uuid for %s: %s", *md, *i);
- md_uuid_free(entry);
+ debug (g, "inspect-os: guestfs_md_detail returned invalid "
+ "uuid for %s: %s",
+ *md, *i);
+ md_uuid_free (entry);
continue;
}
const void *matched = NULL;
- switch (hash_insert_if_absent(*map, entry, &matched)) {
+ switch (hash_insert_if_absent (*map, entry, &matched)) {
case -1:
- g->abort_cb();
+ g->abort_cb ();
case 0:
- /* Duplicate uuid in for md device is weird, but not fatal. */
- debug(g, "inspect-os: md devices %s and %s have the same uuid",
- ((md_uuid *)matched)->path, entry->path);
- md_uuid_free(entry);
- break;
+ /* Duplicate uuid in for md device is weird, but not fatal. */
+ debug (g, "inspect-os: md devices %s and %s have the same uuid",
+ ((md_uuid *)matched)->path, entry->path);
+ md_uuid_free (entry);
+ break;
default:
- n++;
+ n++;
}
}
}
return n;
- error:
- hash_free (*map); *map = NULL;
+error:
+ hash_free (*map);
+ *map = NULL;
return -1;
}
static size_t
-mdadm_app_hash(const void *x, size_t table_size)
+mdadm_app_hash (const void *x, size_t table_size)
{
const mdadm_app *a = x;
- return hash_pjw(a->mdadm, table_size);
+ return hash_pjw (a->mdadm, table_size);
}
static bool
-mdadm_app_cmp(const void *x, const void *y)
+mdadm_app_cmp (const void *x, const void *y)
{
const mdadm_app *a = x;
const mdadm_app *b = y;
@@ -1605,18 +1665,18 @@ mdadm_app_cmp(const void *x, const void *y)
}
static void
-mdadm_app_free(void *x)
+mdadm_app_free (void *x)
{
mdadm_app *a = x;
- free(a->mdadm);
- free(a->app);
- free(a);
+ free (a->mdadm);
+ free (a->app);
+ free (a);
}
/* Get a map of md device names in mdadm.conf to their device names in the
* appliance */
static int
-map_md_devices(guestfs_h *g, Hash_table **map)
+map_md_devices (guestfs_h *g, Hash_table **map)
{
CLEANUP_HASH_FREE Hash_table *app_map = NULL;
CLEANUP_FREE_STRING_LIST char **matches = NULL;
@@ -1626,32 +1686,38 @@ map_md_devices(guestfs_h *g, Hash_table **map)
/* Get a map of md device uuids to their device names in the appliance */
n_app_md_devices = map_app_md_devices (g, &app_map);
- if (n_app_md_devices == -1) goto error;
+ if (n_app_md_devices == -1)
+ goto error;
/* Nothing to do if there are no md devices */
if (n_app_md_devices == 0)
return 0;
/* Get all arrays listed in mdadm.conf */
- matches = guestfs_aug_match(g, "/files/etc/mdadm.conf/array");
- if (!matches) goto error;
+ matches = guestfs_aug_match (g, "/files/etc/mdadm.conf/array");
+ if (!matches)
+ goto error;
- /* Log a debug message if we've got md devices, but nothing in mdadm.conf */
+ /* Log a debug message if we've got md devices, but nothing in mdadm.conf
+ */
if (matches[0] == NULL) {
- debug(g, "Appliance has MD devices, but augeas returned no array matches "
- "in mdadm.conf");
+ debug (g,
+ "Appliance has MD devices, but augeas returned no array matches "
+ "in mdadm.conf");
return 0;
}
- *map = hash_initialize(16, NULL, mdadm_app_hash, mdadm_app_cmp,
- mdadm_app_free);
- if (!*map) g->abort_cb();
+ *map = hash_initialize (16, NULL, mdadm_app_hash, mdadm_app_cmp,
+ mdadm_app_free);
+ if (!*map)
+ g->abort_cb ();
for (char **m = matches; *m != NULL; m++) {
/* Get device name and uuid for each array */
CLEANUP_FREE char *dev_path = safe_asprintf (g, "%s/devicename", *m);
char *dev = guestfs_aug_get (g, dev_path);
- if (!dev) goto error;
+ if (!dev)
+ goto error;
CLEANUP_FREE char *uuid_path = safe_asprintf (g, "%s/uuid", *m);
CLEANUP_FREE char *uuid = guestfs_aug_get (g, uuid_path);
@@ -1664,41 +1730,43 @@ map_md_devices(guestfs_h *g, Hash_table **map)
* uuid->appliance device map */
md_uuid mdadm;
mdadm.path = dev;
- if (parse_uuid(uuid, mdadm.uuid) == -1) {
+ if (parse_uuid (uuid, mdadm.uuid) == -1) {
/* Invalid uuid. Weird, but not fatal. */
- debug(g, "inspect-os: mdadm.conf contains invalid uuid for %s: %s",
- dev, uuid);
+ debug (g, "inspect-os: mdadm.conf contains invalid uuid for %s: %s",
+ dev, uuid);
free (dev);
continue;
}
/* If there's a corresponding uuid in the appliance, create a new
* entry in the transitive map */
- md_uuid *app = hash_lookup(app_map, &mdadm);
+ md_uuid *app = hash_lookup (app_map, &mdadm);
if (app) {
- mdadm_app *entry = safe_malloc(g, sizeof(mdadm_app));
+ mdadm_app *entry = safe_malloc (g, sizeof (mdadm_app));
entry->mdadm = dev;
- entry->app = safe_strdup(g, app->path);
+ entry->app = safe_strdup (g, app->path);
- switch (hash_insert_if_absent(*map, entry, NULL)) {
+ switch (hash_insert_if_absent (*map, entry, NULL)) {
case -1:
- g->abort_cb();
+ g->abort_cb ();
case 0:
- /* Duplicate uuid in for md device is weird, but not fatal. */
- debug(g, "inspect-os: mdadm.conf contains multiple entries for %s",
- app->path);
- mdadm_app_free(entry);
- continue;
+ /* Duplicate uuid in for md device is weird, but not fatal. */
+ debug (g, "inspect-os: mdadm.conf contains multiple entries for %s",
+ app->path);
+ mdadm_app_free (entry);
+ continue;
}
- } else
+ }
+ else
free (dev);
}
return 0;
- error:
- if (*map) hash_free (*map);
+error:
+ if (*map)
+ hash_free (*map);
return -1;
}
@@ -1725,7 +1793,8 @@ resolve_fstab_device_xdev (guestfs_h *g, const char *type, const
char *disk,
/* Check any hints we were passed for a non-heuristic mapping */
name = safe_asprintf (g, "%sd%s", type, disk);
- ITER_DRIVES (g, i, drv) {
+ ITER_DRIVES (g, i, drv)
+ {
if (drv->name && STREQ (drv->name, name)) {
device = safe_asprintf (g, "%s%s", devices[i], part);
if (!guestfs_int_is_partition (g, device)) {
@@ -1746,11 +1815,13 @@ resolve_fstab_device_xdev (guestfs_h *g, const char *type, const
char *disk,
/* Calculate the numerical index of the disk */
i = disk[0] - 'a';
for (p = disk + 1; *p != '\0'; p++) {
- i += 1; i *= 26;
+ i += 1;
+ i *= 26;
i += *p - 'a';
}
- /* Check the index makes sense wrt the number of disks the appliance has.
+ /* Check the index makes sense wrt the number of disks the appliance
+ * has.
* If it does, map it to an appliance disk.
*/
if (i < count) {
@@ -1767,8 +1838,8 @@ resolve_fstab_device_xdev (guestfs_h *g, const char *type, const
char *disk,
}
static int
-resolve_fstab_device_cciss (guestfs_h *g, const char *disk, const char *part,
- char **device_ret)
+resolve_fstab_device_cciss (guestfs_h *g, const char *disk,
+ const char *part, char **device_ret)
{
char *device;
CLEANUP_FREE_STRING_LIST char **devices = NULL;
@@ -1784,7 +1855,8 @@ resolve_fstab_device_cciss (guestfs_h *g, const char *disk, const
char *part,
return -1;
/* Check any hints we were passed for a non-heuristic mapping */
- ITER_DRIVES (g, i, drv) {
+ ITER_DRIVES (g, i, drv)
+ {
if (drv->name && STREQ (drv->name, disk)) {
if (part) {
device = safe_asprintf (g, "%s%s", devices[i], part);
@@ -1889,14 +1961,16 @@ resolve_fstab_device (guestfs_h *g, const char *spec, Hash_table
*md_map,
entry.mdadm = disk;
mdadm_app *app = hash_lookup (md_map, &entry);
- if (app) device = safe_strdup (g, app->app);
+ if (app)
+ device = safe_strdup (g, app->app);
free (disk);
}
else if (match3 (g, spec, re_freebsd_gpt, &type, &disk, &part)) {
/* If the FreeBSD disk contains GPT partitions, the translation to Linux
* device names is straight forward. Partitions on a virtio disk are
- * prefixed with vtbd. IDE hard drives used to be prefixed with ad and now
+ * prefixed with vtbd. IDE hard drives used to be prefixed with ad and
+ * now
* are with ada.
*/
int disk_i = guestfs_int_parse_unsigned_int (g, disk);
@@ -1924,12 +1998,13 @@ resolve_fstab_device (guestfs_h *g, const char *spec, Hash_table
*md_map,
free (part);
if (part_i > 2)
- /* Partition 'c' has the size of the enclosing slice. Not mapped under
Linux. */
+ /* Partition 'c' has the size of the enclosing slice. Not mapped under
+ * Linux. */
part_i -= 1;
- if (disk_i != -1 && disk_i <= 26 &&
- slice_i > 0 && slice_i <= 1 /* > 4 .. see comment above */
&&
- part_i >= 0 && part_i < 25) {
+ if (disk_i != -1 && disk_i <= 26 && slice_i > 0 &&
+ slice_i <= 1 /* > 4 .. see comment above */ && part_i >= 0
&&
+ part_i < 25) {
device = safe_asprintf (g, "/dev/sd%c%d", disk_i + 'a', part_i +
5);
}
}
@@ -1942,7 +2017,8 @@ resolve_fstab_device (guestfs_h *g, const char *spec, Hash_table
*md_map,
free (part);
if (part_i > 3)
- /* Partition 'c' is the disklabel partition and 'd' the hard disk
itself.
+ /* Partition 'c' is the disklabel partition and 'd' the hard disk
+ * itself.
* Not mapped under Linux.
*/
part_i -= 2;
@@ -1995,7 +2071,8 @@ resolve_fstab_device (guestfs_h *g, const char *spec, Hash_table
*md_map,
return device;
}
-static char *make_augeas_path_expression (guestfs_h *g, const char **configfiles);
+static char *make_augeas_path_expression (guestfs_h *g,
+ const char **configfiles);
/* Call 'f' with Augeas opened and having parsed 'configfiles' (these
* files must exist). As a security measure, this bails if any file
@@ -2017,7 +2094,8 @@ inspect_with_augeas (guestfs_h *g, struct inspect_fs *fs,
/* Security: Refuse to do this if a config file is too large. */
for (i = 0; configfiles[i] != NULL; ++i) {
if (guestfs_is_file_opts (g, configfiles[i],
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) == 0)
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1,
+ -1) == 0)
continue;
size = guestfs_filesize (g, configfiles[i]);
@@ -2031,7 +2109,8 @@ inspect_with_augeas (guestfs_h *g, struct inspect_fs *fs,
}
}
- if (guestfs_aug_init (g, "/", 16|32 /* AUG_SAVE_NOOP|AUG_NO_LOAD */) == -1)
+ if (guestfs_aug_init (g, "/", 16 | 32 /* AUG_SAVE_NOOP|AUG_NO_LOAD */) ==
+ -1)
return -1;
r = -1;
@@ -2072,11 +2151,8 @@ inspect_with_augeas (guestfs_h *g, struct inspect_fs *fs,
CLEANUP_FREE char *charp = guestfs_aug_get (g, charpath);
guestfs_pop_error_handler (g);
- error (g, _("%s:%s:%s: augeas parse failure: %s"),
- configfiles[i],
- line ? : "<none>",
- charp ? : "<none>",
- message ? : "<none>");
+ error (g, _("%s:%s:%s: augeas parse failure: %s"), configfiles[i],
+ line ?: "<none>", charp ?: "<none>",
message ?: "<none>");
goto out;
}
}
@@ -2084,7 +2160,7 @@ inspect_with_augeas (guestfs_h *g, struct inspect_fs *fs,
r = f (g, fs);
- out:
+out:
guestfs_aug_close (g);
return r;
@@ -2100,12 +2176,13 @@ make_augeas_path_expression (guestfs_h *g, const char
**configfiles)
CLEANUP_FREE char *subexpr = NULL;
char *ret;
- nr_files = guestfs_int_count_strings ((char **) configfiles);
+ nr_files = guestfs_int_count_strings ((char **)configfiles);
subexprs = safe_malloc (g, sizeof (char *) * (nr_files + 1));
for (i = 0; i < nr_files; ++i) {
subexprs[i] = /* v NB trailing '/' after filename */
- safe_asprintf (g, "\"%s/\" !~ regexp('^') + glob(incl) +
regexp('/.*')",
+ safe_asprintf (g,
+ "\"%s/\" !~ regexp('^') + glob(incl) +
regexp('/.*')",
configfiles[i]);
}
subexprs[nr_files] = NULL;
diff --git a/src/inspect-fs-windows.c b/src/inspect-fs-windows.c
index 3ac9107..012e21e 100644
--- a/src/inspect-fs-windows.c
+++ b/src/inspect-fs-windows.c
@@ -36,8 +36,8 @@
#if defined __APPLE__ && defined __MACH__
#include <libkern/OSByteOrder.h>
-#define le32toh(x) OSSwapLittleToHostInt32(x)
-#define le64toh(x) OSSwapLittleToHostInt64(x)
+#define le32toh(x) OSSwapLittleToHostInt32 (x)
+#define le64toh(x) OSSwapLittleToHostInt64 (x)
#endif
#include <pcre.h>
@@ -51,15 +51,20 @@
COMPILE_REGEXP (re_windows_version, "^(\\d+)\\.(\\d+)", 0)
COMPILE_REGEXP (re_boot_ini_os_header, "^\\[operating systems\\]\\s*$", 0)
-COMPILE_REGEXP (re_boot_ini_os,
-
"^(multi|scsi)\\((\\d+)\\)disk\\((\\d+)\\)rdisk\\((\\d+)\\)partition\\((\\d+)\\)([^=]+)=",
0)
+COMPILE_REGEXP (re_boot_ini_os, "^(multi|scsi)\\((\\d+)\\)disk\\((\\d+)\\)"
+ "rdisk\\((\\d+)\\)partition\\((\\d+)\\)([^="
+ "]+)=",
+ 0)
static int check_windows_arch (guestfs_h *g, struct inspect_fs *fs);
-static int check_windows_software_registry (guestfs_h *g, struct inspect_fs *fs);
-static int check_windows_system_registry (guestfs_h *g, struct inspect_fs *fs);
+static int check_windows_software_registry (guestfs_h *g,
+ struct inspect_fs *fs);
+static int check_windows_system_registry (guestfs_h *g,
+ struct inspect_fs *fs);
static char *map_registry_disk_blob (guestfs_h *g, const void *blob);
static char *map_registry_disk_blob_gpt (guestfs_h *g, const void *blob);
-static char *extract_guid_from_registry_blob (guestfs_h *g, const void *blob);
+static char *extract_guid_from_registry_blob (guestfs_h *g,
+ const void *blob);
/* XXX Handling of boot.ini in the Perl version was pretty broken. It
* essentially didn't do anything for modern Windows guests.
@@ -104,8 +109,8 @@ char *
guestfs_int_get_windows_systemroot (guestfs_h *g)
{
/* Check a predefined list of common windows system root locations */
- static const char *systemroots[] =
- { "/windows", "/winnt", "/win32", "/win",
"/reactos", NULL };
+ static const char *systemroots[] = { "/windows", "/winnt",
"/win32",
+ "/win", "/reactos", NULL
};
for (size_t i = 0; i < sizeof systemroots / sizeof systemroots[0]; ++i) {
char *systemroot =
@@ -117,7 +122,8 @@ guestfs_int_get_windows_systemroot (guestfs_h *g)
debug (g, "windows %%SYSTEMROOT%% = %s", systemroot);
return systemroot;
- } else {
+ }
+ else {
free (systemroot);
}
}
@@ -154,51 +160,53 @@ guestfs_int_get_windows_systemroot (guestfs_h *g)
/* See
http://support.microsoft.com/kb/102873 for a discussion
* of what this line means */
- if (match6 (g, line, re_boot_ini_os, &controller_type,
- &controller, &disk, &rdisk, &partition, &path))
- {
- /* The Windows system root may be on any disk. However, there
- * are currently (at least) 2 practical problems preventing us
- * from locating it on another disk:
- *
- * 1. We don't have enough metadata about the disks we were
- * given to know if what controller they were on and what
- * index they had.
- *
- * 2. The way inspection of filesystems currently works, we
- * can't mark another filesystem, which we may have already
- * inspected, to be inspected for a specific Windows system
- * root.
- *
- * Solving 1 properly would require a new API at a minimum. We
- * might be able to fudge something practical without this,
- * though, e.g. by looking at the <partition>th partition of
- * every disk for the specific windows root.
- *
- * Solving 2 would probably require a significant refactoring
- * of the way filesystems are inspected. We should probably do
- * this some time.
- *
- * For the moment, we ignore all partition information and
- * assume the system root is on the current partition. In
- * practice, this will normally be correct.
- */
+ if (match6 (g, line, re_boot_ini_os, &controller_type, &controller,
+ &disk, &rdisk, &partition, &path)) {
+ /* The Windows system root may be on any disk. However, there
+ * are currently (at least) 2 practical problems preventing us
+ * from locating it on another disk:
+ *
+ * 1. We don't have enough metadata about the disks we were
+ * given to know if what controller they were on and what
+ * index they had.
+ *
+ * 2. The way inspection of filesystems currently works, we
+ * can't mark another filesystem, which we may have already
+ * inspected, to be inspected for a specific Windows system
+ * root.
+ *
+ * Solving 1 properly would require a new API at a minimum. We
+ * might be able to fudge something practical without this,
+ * though, e.g. by looking at the <partition>th partition of
+ * every disk for the specific windows root.
+ *
+ * Solving 2 would probably require a significant refactoring
+ * of the way filesystems are inspected. We should probably do
+ * this some time.
+ *
+ * For the moment, we ignore all partition information and
+ * assume the system root is on the current partition. In
+ * practice, this will normally be correct.
+ */
- /* Swap backslashes for forward slashes in the system root
- * path */
- for (char *j = path; *j != '\0'; j++) {
- if (*j == '\\') *j = '/';
- }
+ /* Swap backslashes for forward slashes in the system root
+ * path */
+ for (char *j = path; *j != '\0'; j++) {
+ if (*j == '\\')
+ *j = '/';
+ }
- char *systemroot = guestfs_int_case_sensitive_path_silently (g, path);
- if (systemroot && is_systemroot (g, systemroot)) {
- debug (g, "windows %%SYSTEMROOT%% = %s", systemroot);
+ char *systemroot =
+ guestfs_int_case_sensitive_path_silently (g, path);
+ if (systemroot && is_systemroot (g, systemroot)) {
+ debug (g, "windows %%SYSTEMROOT%% = %s", systemroot);
- return systemroot;
- } else {
- free (systemroot);
- }
- }
+ return systemroot;
+ }
+ else {
+ free (systemroot);
+ }
+ }
}
}
@@ -207,7 +215,7 @@ guestfs_int_get_windows_systemroot (guestfs_h *g)
int
guestfs_int_check_windows_root (guestfs_h *g, struct inspect_fs *fs,
- char *const systemroot)
+ char *const systemroot)
{
fs->type = OS_TYPE_WINDOWS;
fs->distro = OS_DISTRO_WINDOWS;
@@ -235,8 +243,10 @@ check_windows_arch (guestfs_h *g, struct inspect_fs *fs)
CLEANUP_FREE char *cmd_exe =
safe_asprintf (g, "%s/system32/cmd.exe", fs->windows_systemroot);
- /* Should exist because of previous check above in get_windows_systemroot. */
- CLEANUP_FREE char *cmd_exe_path = guestfs_case_sensitive_path (g, cmd_exe);
+ /* Should exist because of previous check above in get_windows_systemroot.
+ */
+ CLEANUP_FREE char *cmd_exe_path =
+ guestfs_case_sensitive_path (g, cmd_exe);
if (!cmd_exe_path)
return -1;
@@ -244,7 +254,7 @@ check_windows_arch (guestfs_h *g, struct inspect_fs *fs)
if (!arch)
return -1;
- fs->arch = arch; /* freed by guestfs_int_free_inspect_info */
+ fs->arch = arch; /* freed by guestfs_int_free_inspect_info */
return 0;
}
@@ -259,10 +269,11 @@ check_windows_software_registry (guestfs_h *g, struct inspect_fs
*fs)
int ret = -1;
int r;
- CLEANUP_FREE char *software =
- safe_asprintf (g, "%s/system32/config/software",
fs->windows_systemroot);
+ CLEANUP_FREE char *software = safe_asprintf (
+ g, "%s/system32/config/software", fs->windows_systemroot);
- CLEANUP_FREE char *software_path = guestfs_case_sensitive_path (g, software);
+ CLEANUP_FREE char *software_path =
+ guestfs_case_sensitive_path (g, software);
if (!software_path)
return -1;
@@ -276,14 +287,14 @@ check_windows_software_registry (guestfs_h *g, struct inspect_fs
*fs)
return 0;
int64_t node;
- const char *hivepath[] =
- { "Microsoft", "Windows NT", "CurrentVersion" };
+ const char *hivepath[] = { "Microsoft", "Windows NT",
"CurrentVersion" };
size_t i;
- CLEANUP_FREE_HIVEX_VALUE_LIST struct guestfs_hivex_value_list *values = NULL;
+ CLEANUP_FREE_HIVEX_VALUE_LIST struct guestfs_hivex_value_list *values =
+ NULL;
bool ignore_currentversion = false;
- if (guestfs_hivex_open (g, software_path,
- GUESTFS_HIVEX_OPEN_VERBOSE, g->verbose, -1) == -1)
+ if (guestfs_hivex_open (g, software_path, GUESTFS_HIVEX_OPEN_VERBOSE,
+ g->verbose, -1) == -1)
return -1;
node = guestfs_hivex_root (g);
@@ -294,7 +305,8 @@ check_windows_software_registry (guestfs_h *g, struct inspect_fs *fs)
goto out;
if (node == 0) {
- perrorf (g, "hivex: cannot locate HKLM\\SOFTWARE\\Microsoft\\Windows
NT\\CurrentVersion");
+ perrorf (g, "hivex: cannot locate HKLM\\SOFTWARE\\Microsoft\\Windows "
+ "NT\\CurrentVersion");
goto out;
}
@@ -314,7 +326,8 @@ check_windows_software_registry (guestfs_h *g, struct inspect_fs *fs)
else if (STRCASEEQ (key, "CurrentMajorVersionNumber")) {
size_t vsize;
int64_t vtype = guestfs_hivex_value_type (g, value);
- CLEANUP_FREE char *vbuf = guestfs_hivex_value_value (g, value, &vsize);
+ CLEANUP_FREE char *vbuf =
+ guestfs_hivex_value_value (g, value, &vsize);
if (vbuf == NULL)
goto out;
@@ -332,7 +345,8 @@ check_windows_software_registry (guestfs_h *g, struct inspect_fs *fs)
else if (STRCASEEQ (key, "CurrentMinorVersionNumber")) {
size_t vsize;
int64_t vtype = guestfs_hivex_value_type (g, value);
- CLEANUP_FREE char *vbuf = guestfs_hivex_value_value (g, value, &vsize);
+ CLEANUP_FREE char *vbuf =
+ guestfs_hivex_value_value (g, value, &vsize);
if (vbuf == NULL)
goto out;
@@ -374,7 +388,7 @@ check_windows_software_registry (guestfs_h *g, struct inspect_fs *fs)
ret = 0;
- out:
+out:
guestfs_hivex_close (g);
return ret;
@@ -387,8 +401,7 @@ check_windows_system_registry (guestfs_h *g, struct inspect_fs *fs)
static const char gpt_prefix[] = "DMIO:ID:";
CLEANUP_FREE char *system =
- safe_asprintf (g, "%s/system32/config/system",
- fs->windows_systemroot);
+ safe_asprintf (g, "%s/system32/config/system", fs->windows_systemroot);
CLEANUP_FREE char *system_path = guestfs_case_sensitive_path (g, system);
if (!system_path)
@@ -405,17 +418,19 @@ check_windows_system_registry (guestfs_h *g, struct inspect_fs *fs)
int ret = -1;
int64_t root, node, value;
- CLEANUP_FREE_HIVEX_VALUE_LIST struct guestfs_hivex_value_list *values = NULL;
- CLEANUP_FREE_HIVEX_VALUE_LIST struct guestfs_hivex_value_list *values2 = NULL;
+ CLEANUP_FREE_HIVEX_VALUE_LIST struct guestfs_hivex_value_list *values =
+ NULL;
+ CLEANUP_FREE_HIVEX_VALUE_LIST struct guestfs_hivex_value_list *values2 =
+ NULL;
int32_t dword;
size_t i, count;
CLEANUP_FREE void *buf = NULL;
size_t buflen;
- const char *hivepath[] =
- { NULL /* current control set */, "Services", "Tcpip",
"Parameters" };
+ const char *hivepath[] = { NULL /* current control set */, "Services",
+ "Tcpip", "Parameters" };
- if (guestfs_hivex_open (g, system_path,
- GUESTFS_HIVEX_OPEN_VERBOSE, g->verbose, -1) == -1)
+ if (guestfs_hivex_open (g, system_path, GUESTFS_HIVEX_OPEN_VERBOSE,
+ g->verbose, -1) == -1)
goto out;
root = guestfs_hivex_root (g);
@@ -448,7 +463,8 @@ check_windows_system_registry (guestfs_h *g, struct inspect_fs *fs)
goto out;
}
dword = le32toh (*(int32_t *)buf);
- fs->windows_current_control_set = safe_asprintf (g, "ControlSet%03d",
dword);
+ fs->windows_current_control_set =
+ safe_asprintf (g, "ControlSet%03d", dword);
/* Get the drive mappings.
* This page explains the contents of HKLM\System\MountedDevices:
@@ -473,20 +489,20 @@ check_windows_system_registry (guestfs_h *g, struct inspect_fs *fs)
guestfs_hivex_value_key (g, values->val[i].hivex_value_h);
if (key == NULL)
goto out;
- if (STRCASEEQLEN (key, "\\DosDevices\\", 12) &&
- c_isalpha (key[12]) && key[13] == ':')
+ if (STRCASEEQLEN (key, "\\DosDevices\\", 12) && c_isalpha (key[12])
&&
+ key[13] == ':')
count++;
}
- fs->drive_mappings = safe_calloc (g, 2*count + 1, sizeof (char *));
+ fs->drive_mappings = safe_calloc (g, 2 * count + 1, sizeof (char *));
for (i = count = 0; i < values->len; ++i) {
int64_t v = values->val[i].hivex_value_h;
CLEANUP_FREE char *key = guestfs_hivex_value_key (g, v);
if (key == NULL)
goto out;
- if (STRCASEEQLEN (key, "\\DosDevices\\", 12) &&
- c_isalpha (key[12]) && key[13] == ':') {
+ if (STRCASEEQLEN (key, "\\DosDevices\\", 12) && c_isalpha (key[12])
&&
+ key[13] == ':') {
/* Get the binary value. Is it a fixed disk? */
CLEANUP_FREE char *blob = NULL;
char *device;
@@ -512,12 +528,11 @@ check_windows_system_registry (guestfs_h *g, struct inspect_fs *fs)
}
}
- skip_drive_letter_mappings:;
+skip_drive_letter_mappings:;
/* Get the hostname. */
hivepath[0] = fs->windows_current_control_set;
for (node = root, i = 0;
- node > 0 && i < sizeof hivepath / sizeof hivepath[0];
- ++i) {
+ node > 0 && i < sizeof hivepath / sizeof hivepath[0]; ++i) {
node = guestfs_hivex_node_get_child (g, node, hivepath[i]);
}
@@ -525,8 +540,10 @@ check_windows_system_registry (guestfs_h *g, struct inspect_fs *fs)
goto out;
if (node == 0) {
- perrorf (g, "hivex: cannot locate
HKLM\\SYSTEM\\%s\\Services\\Tcpip\\Parameters",
- fs->windows_current_control_set);
+ perrorf (
+ g,
+ "hivex: cannot locate HKLM\\SYSTEM\\%s\\Services\\Tcpip\\Parameters",
+ fs->windows_current_control_set);
goto out;
}
@@ -550,7 +567,7 @@ check_windows_system_registry (guestfs_h *g, struct inspect_fs *fs)
ret = 0;
- out:
+out:
guestfs_hivex_close (g);
return ret;
@@ -566,7 +583,8 @@ static char *
map_registry_disk_blob (guestfs_h *g, const void *blob)
{
CLEANUP_FREE_STRING_LIST char **devices = NULL;
- CLEANUP_FREE_PARTITION_LIST struct guestfs_partition_list *partitions = NULL;
+ CLEANUP_FREE_PARTITION_LIST struct guestfs_partition_list *partitions =
+ NULL;
size_t i, j, len;
uint64_t part_offset;
@@ -590,12 +608,12 @@ map_registry_disk_blob (guestfs_h *g, const void *blob)
}
return NULL;
- found_disk:
+found_disk:
/* Next 8 bytes are the offset of the partition in bytes(!) given as
* a 64 bit little endian number. Luckily it's easy to get the
* partition byte offset from guestfs_part_list.
*/
- memcpy (&part_offset, (char *) blob + 4, sizeof (part_offset));
+ memcpy (&part_offset, (char *)blob + 4, sizeof (part_offset));
part_offset = le64toh (part_offset);
partitions = guestfs_part_list (g, devices[i]);
@@ -608,7 +626,7 @@ map_registry_disk_blob (guestfs_h *g, const void *blob)
}
return NULL;
- found_partition:
+found_partition:
/* Construct the full device name. */
return safe_asprintf (g, "%s%d", devices[i],
partitions->val[j].part_num);
}
@@ -676,7 +694,7 @@ extract_guid_from_registry_blob (guestfs_h *g, const void *blob)
uint64_t data4;
/* get the GUID bytes from blob (skip 8 byte "DMIO:ID:" prefix) */
- memcpy (&guid_bytes, (char *) blob + 8, sizeof (guid_bytes));
+ memcpy (&guid_bytes, (char *)blob + 8, sizeof (guid_bytes));
/* copy relevant sections from blob to respective ints */
memcpy (&data1, guid_bytes, sizeof (data1));
@@ -690,9 +708,10 @@ extract_guid_from_registry_blob (guestfs_h *g, const void *blob)
data3 = le16toh (data3);
data4 = be64toh (data4);
- return safe_asprintf (g,
- "%08" PRIX32 "-%04" PRIX16 "-%04" PRIX16
"-%04" PRIX64 "-%012" PRIX64,
- data1, data2, data3, data4 >> 48, data4 & 0xffffffffffff);
+ return safe_asprintf (g, "%08" PRIX32 "-%04" PRIX16
"-%04" PRIX16
+ "-%04" PRIX64 "-%012" PRIX64,
+ data1, data2, data3, data4 >> 48,
+ data4 & 0xffffffffffff);
}
/* NB: This function DOES NOT test for the existence of the file. It
@@ -741,7 +760,7 @@ static char *
utf16_to_utf8 (/* const */ char *input, size_t len)
{
iconv_t ic = iconv_open ("UTF-8", "UTF-16LE");
- if (ic == (iconv_t) -1)
+ if (ic == (iconv_t)-1)
return NULL;
/* iconv(3) has an insane interface ... */
@@ -749,7 +768,7 @@ utf16_to_utf8 (/* const */ char *input, size_t len)
/* Mostly UTF-8 will be smaller, so this is a good initial guess. */
size_t outalloc = len;
- again:;
+again:;
size_t inlen = len;
size_t outlen = outalloc;
char *out = malloc (outlen + 1);
@@ -762,8 +781,8 @@ utf16_to_utf8 (/* const */ char *input, size_t len)
char *inp = input;
char *outp = out;
- size_t r = iconv (ic, (ICONV_CONST char **) &inp, &inlen, &outp,
&outlen);
- if (r == (size_t) -1) {
+ size_t r = iconv (ic, (ICONV_CONST char **)&inp, &inlen, &outp,
&outlen);
+ if (r == (size_t)-1) {
if (errno == E2BIG) {
int err = errno;
size_t prev = outalloc;
diff --git a/src/inspect-fs.c b/src/inspect-fs.c
index 0714ae1..9b5fa2a 100644
--- a/src/inspect-fs.c
+++ b/src/inspect-fs.c
@@ -42,8 +42,10 @@ static int check_filesystem (guestfs_h *g, const char *mountable,
const struct guestfs_internal_mountable *m,
int whole_device);
static void extend_fses (guestfs_h *g);
-static int get_partition_context (guestfs_h *g, const char *partition, int *partnum_ret,
int *nr_partitions_ret);
-static int is_symlink_to (guestfs_h *g, const char *file, const char *wanted_target);
+static int get_partition_context (guestfs_h *g, const char *partition,
+ int *partnum_ret, int *nr_partitions_ret);
+static int is_symlink_to (guestfs_h *g, const char *file,
+ const char *wanted_target);
/* Find out if 'device' contains a filesystem. If it does, add
* another entry in g->fses.
@@ -54,7 +56,8 @@ guestfs_int_check_for_filesystem_on (guestfs_h *g, const char
*mountable)
CLEANUP_FREE char *vfs_type = NULL;
int is_swap, r;
struct inspect_fs *fs;
- CLEANUP_FREE_INTERNAL_MOUNTABLE struct guestfs_internal_mountable *m = NULL;
+ CLEANUP_FREE_INTERNAL_MOUNTABLE struct guestfs_internal_mountable *m =
+ NULL;
int whole_device = 0;
/* Get vfs-type in order to check if it's a Linux(?) swap device.
@@ -66,12 +69,12 @@ guestfs_int_check_for_filesystem_on (guestfs_h *g, const char
*mountable)
guestfs_pop_error_handler (g);
is_swap = vfs_type && STREQ (vfs_type, "swap");
- debug (g, "check_for_filesystem_on: %s (%s)",
- mountable, vfs_type ? vfs_type : "failed to get vfs type");
+ debug (g, "check_for_filesystem_on: %s (%s)", mountable,
+ vfs_type ? vfs_type : "failed to get vfs type");
if (is_swap) {
extend_fses (g);
- fs = &g->fses[g->nr_fses-1];
+ fs = &g->fses[g->nr_fses - 1];
fs->mountable = safe_strdup (g, mountable);
return 0;
}
@@ -90,14 +93,14 @@ guestfs_int_check_for_filesystem_on (guestfs_h *g, const char
*mountable)
if (whole_device) {
extend_fses (g);
- fs = &g->fses[g->nr_fses-1];
+ fs = &g->fses[g->nr_fses - 1];
r = guestfs_int_check_installer_iso (g, fs, m->im_device);
- if (r == -1) { /* Fatal error. */
+ if (r == -1) { /* Fatal error. */
g->nr_fses--;
return -1;
}
- if (r > 0) /* Found something. */
+ if (r > 0) /* Found something. */
return 0;
/* Didn't find anything. Fall through ... */
@@ -112,7 +115,8 @@ guestfs_int_check_for_filesystem_on (guestfs_h *g, const char
*mountable)
if (r == -1)
/* while NetBSD and OpenBSD use another variant labeled 44bsd */
r = guestfs_mount_vfs (g, "ro,ufstype=44bsd", "ufs", mountable,
"/");
- } else {
+ }
+ else {
r = guestfs_mount_ro (g, mountable, "/");
}
guestfs_pop_error_handler (g);
@@ -142,16 +146,17 @@ check_filesystem (guestfs_h *g, const char *mountable,
if (!whole_device && m->im_type == MOUNTABLE_DEVICE &&
guestfs_int_is_partition (g, m->im_device)) {
- if (get_partition_context (g, m->im_device,
- &partnum, &nr_partitions) == -1)
+ if (get_partition_context (g, m->im_device, &partnum, &nr_partitions) ==
+ -1)
return -1;
}
- struct inspect_fs *fs = &g->fses[g->nr_fses-1];
+ struct inspect_fs *fs = &g->fses[g->nr_fses - 1];
fs->mountable = safe_strdup (g, mountable);
- /* Optimize some of the tests by avoiding multiple tests of the same thing. */
+ /* Optimize some of the tests by avoiding multiple tests of the same
+ * thing. */
int is_dir_etc = guestfs_is_dir (g, "/etc") > 0;
int is_dir_bin = guestfs_is_dir (g, "/bin") > 0;
int is_dir_share = guestfs_is_dir (g, "/share") > 0;
@@ -162,8 +167,7 @@ check_filesystem (guestfs_h *g, const char *mountable,
guestfs_is_file (g, "/grub2/grub.cfg") > 0)
;
/* FreeBSD root? */
- else if (is_dir_etc &&
- is_dir_bin &&
+ else if (is_dir_etc && is_dir_bin &&
guestfs_is_file (g, "/etc/freebsd-update.conf") > 0 &&
guestfs_is_file (g, "/etc/fstab") > 0) {
fs->is_root = 1;
@@ -172,9 +176,7 @@ check_filesystem (guestfs_h *g, const char *mountable,
return -1;
}
/* NetBSD root? */
- else if (is_dir_etc &&
- is_dir_bin &&
- guestfs_is_file (g, "/netbsd") > 0 &&
+ else if (is_dir_etc && is_dir_bin && guestfs_is_file (g,
"/netbsd") > 0 &&
guestfs_is_file (g, "/etc/fstab") > 0 &&
guestfs_is_file (g, "/etc/release") > 0) {
fs->is_root = 1;
@@ -183,9 +185,7 @@ check_filesystem (guestfs_h *g, const char *mountable,
return -1;
}
/* OpenBSD root? */
- else if (is_dir_etc &&
- is_dir_bin &&
- guestfs_is_file (g, "/bsd") > 0 &&
+ else if (is_dir_etc && is_dir_bin && guestfs_is_file (g,
"/bsd") > 0 &&
guestfs_is_file (g, "/etc/fstab") > 0 &&
guestfs_is_file (g, "/etc/motd") > 0) {
fs->is_root = 1;
@@ -203,8 +203,7 @@ check_filesystem (guestfs_h *g, const char *mountable,
return -1;
}
/* Minix root? */
- else if (is_dir_etc &&
- is_dir_bin &&
+ else if (is_dir_etc && is_dir_bin &&
guestfs_is_file (g, "/service/vm") > 0 &&
guestfs_is_file (g, "/etc/fstab") > 0 &&
guestfs_is_file (g, "/etc/version") > 0) {
@@ -215,8 +214,7 @@ check_filesystem (guestfs_h *g, const char *mountable,
}
/* Linux root? */
else if (is_dir_etc &&
- (is_dir_bin ||
- is_symlink_to (g, "/bin", "usr/bin") > 0) &&
+ (is_dir_bin || is_symlink_to (g, "/bin", "usr/bin") >
0) &&
guestfs_is_file (g, "/etc/fstab") > 0) {
fs->is_root = 1;
fs->format = OS_FORMAT_INSTALLED;
@@ -224,8 +222,7 @@ check_filesystem (guestfs_h *g, const char *mountable,
return -1;
}
/* CoreOS root? */
- else if (is_dir_etc &&
- guestfs_is_dir (g, "/root") > 0 &&
+ else if (is_dir_etc && guestfs_is_dir (g, "/root") > 0 &&
guestfs_is_dir (g, "/home") > 0 &&
guestfs_is_dir (g, "/usr") > 0 &&
guestfs_is_file (g, "/etc/coreos/update.conf") > 0) {
@@ -235,23 +232,17 @@ check_filesystem (guestfs_h *g, const char *mountable,
return -1;
}
/* Linux /usr/local? */
- else if (is_dir_etc &&
- is_dir_bin &&
- is_dir_share &&
+ else if (is_dir_etc && is_dir_bin && is_dir_share &&
guestfs_is_dir (g, "/local") == 0 &&
guestfs_is_file (g, "/etc/fstab") == 0)
;
/* Linux /usr? */
- else if (is_dir_etc &&
- is_dir_bin &&
- is_dir_share &&
+ else if (is_dir_etc && is_dir_bin && is_dir_share &&
guestfs_is_dir (g, "/local") > 0 &&
guestfs_is_file (g, "/etc/fstab") == 0)
;
/* CoreOS /usr? */
- else if (is_dir_bin &&
- is_dir_share &&
- guestfs_is_dir (g, "/local") > 0 &&
+ else if (is_dir_bin && is_dir_share && guestfs_is_dir (g,
"/local") > 0 &&
guestfs_is_dir (g, "/share/coreos") > 0) {
if (guestfs_int_check_coreos_usr (g, fs) == -1)
return -1;
@@ -262,15 +253,16 @@ check_filesystem (guestfs_h *g, const char *mountable,
guestfs_is_dir (g, "/spool") > 0)
;
/* Windows root? */
- else if ((windows_systemroot = guestfs_int_get_windows_systemroot (g)) != NULL)
- {
- fs->is_root = 1;
- fs->format = OS_FORMAT_INSTALLED;
- if (guestfs_int_check_windows_root (g, fs, windows_systemroot) == -1)
- return -1;
- }
+ else if ((windows_systemroot = guestfs_int_get_windows_systemroot (g)) !=
+ NULL) {
+ fs->is_root = 1;
+ fs->format = OS_FORMAT_INSTALLED;
+ if (guestfs_int_check_windows_root (g, fs, windows_systemroot) == -1)
+ return -1;
+ }
/* Windows volume with installed applications (but not root)? */
- else if (guestfs_int_is_dir_nocase (g, "/System Volume Information") > 0
&&
+ else if (guestfs_int_is_dir_nocase (g, "/System Volume Information") >
+ 0 &&
guestfs_int_is_dir_nocase (g, "/Program Files") > 0)
;
/* Windows volume (but not root)? */
@@ -333,7 +325,7 @@ extend_fses (guestfs_h *g)
g->fses = p;
g->nr_fses = n;
- memset (&g->fses[n-1], 0, sizeof (struct inspect_fs));
+ memset (&g->fses[n - 1], 0, sizeof (struct inspect_fs));
}
/* Given a partition (eg. /dev/sda2) then return the partition number
@@ -345,7 +337,8 @@ get_partition_context (guestfs_h *g, const char *partition,
{
int partnum, nr_partitions;
CLEANUP_FREE char *device = NULL;
- CLEANUP_FREE_PARTITION_LIST struct guestfs_partition_list *partitions = NULL;
+ CLEANUP_FREE_PARTITION_LIST struct guestfs_partition_list *partitions =
+ NULL;
partnum = guestfs_part_to_partnum (g, partition);
if (partnum == -1)
@@ -423,7 +416,8 @@ guestfs_int_parse_unsigned_int (guestfs_h *g, const char *str)
/* Like parse_unsigned_int, but ignore trailing stuff. */
int
-guestfs_int_parse_unsigned_int_ignore_trailing (guestfs_h *g, const char *str)
+guestfs_int_parse_unsigned_int_ignore_trailing (guestfs_h *g,
+ const char *str)
{
long ret;
int r = xstrtol (str, NULL, 10, &ret, NULL);
@@ -529,7 +523,8 @@ guestfs_int_check_package_management (guestfs_h *g, struct inspect_fs
*fs)
/* If Fedora >= 22 and dnf is installed, say "dnf". */
if (fs->major_version >= 22 &&
guestfs_is_file_opts (g, "/usr/bin/dnf",
- GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0)
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1,
+ -1) > 0)
fs->package_management = OS_PACKAGE_MANAGEMENT_DNF;
else
fs->package_management = OS_PACKAGE_MANAGEMENT_YUM;
@@ -632,7 +627,7 @@ guestfs_int_first_line_of_file (guestfs_h *g, const char *filename)
}
/* lines[1] should be NULL because of '1' argument above ... */
- ret = lines[0]; /* caller frees */
+ ret = lines[0]; /* caller frees */
free (lines);
@@ -648,7 +643,7 @@ guestfs_int_first_line_of_file (guestfs_h *g, const char *filename)
*/
int
guestfs_int_first_egrep_of_file (guestfs_h *g, const char *filename,
- const char *eregex, int iflag, char **ret)
+ const char *eregex, int iflag, char **ret)
{
char **lines;
int64_t size;
@@ -682,7 +677,7 @@ guestfs_int_first_egrep_of_file (guestfs_h *g, const char *filename,
return 0;
}
- *ret = lines[0]; /* caller frees */
+ *ret = lines[0]; /* caller frees */
/* free up any other matches and the array itself */
for (i = 1; lines[i] != NULL; ++i)
@@ -692,16 +687,18 @@ guestfs_int_first_egrep_of_file (guestfs_h *g, const char
*filename,
return 1;
}
-/* Merge the missing OS inspection information found on the src inspect_fs into
+/* Merge the missing OS inspection information found on the src inspect_fs
+ * into
* the ones of the dst inspect_fs. This function is useful if the inspection
* information for an OS are gathered by inspecting multiple filesystems.
*/
void
-guestfs_int_merge_fs_inspections (guestfs_h *g, struct inspect_fs *dst, struct inspect_fs
*src)
+guestfs_int_merge_fs_inspections (guestfs_h *g, struct inspect_fs *dst,
+ struct inspect_fs *src)
{
size_t n, i, old;
struct inspect_fstab_entry *fstab = NULL;
- char ** mappings = NULL;
+ char **mappings = NULL;
if (dst->type == 0)
dst->type = src->type;
@@ -721,7 +718,7 @@ guestfs_int_merge_fs_inspections (guestfs_h *g, struct inspect_fs
*dst, struct i
}
if (dst->product_variant == NULL) {
- dst->product_variant= src->product_variant;
+ dst->product_variant = src->product_variant;
src->product_variant = NULL;
}
@@ -755,7 +752,8 @@ guestfs_int_merge_fs_inspections (guestfs_h *g, struct inspect_fs
*dst, struct i
/* Adopt the drive mappings of src */
dst->drive_mappings = src->drive_mappings;
src->drive_mappings = NULL;
- } else {
+ }
+ else {
n = 0;
for (; dst->drive_mappings[n] != NULL; n++)
;
@@ -764,7 +762,8 @@ guestfs_int_merge_fs_inspections (guestfs_h *g, struct inspect_fs
*dst, struct i
;
/* Merge the src mappings to dst */
- mappings = safe_realloc (g, dst->drive_mappings,(n + 1) * sizeof (char *));
+ mappings =
+ safe_realloc (g, dst->drive_mappings, (n + 1) * sizeof (char *));
for (i = old; i < n; i++)
mappings[i] = src->drive_mappings[i - old];
@@ -772,20 +771,21 @@ guestfs_int_merge_fs_inspections (guestfs_h *g, struct inspect_fs
*dst, struct i
mappings[n] = NULL;
dst->drive_mappings = mappings;
- free(src->drive_mappings);
+ free (src->drive_mappings);
src->drive_mappings = NULL;
}
}
if (src->nr_fstab > 0) {
n = dst->nr_fstab + src->nr_fstab;
- fstab = safe_realloc (g, dst->fstab, n * sizeof (struct inspect_fstab_entry));
+ fstab =
+ safe_realloc (g, dst->fstab, n * sizeof (struct inspect_fstab_entry));
for (i = 0; i < src->nr_fstab; i++) {
fstab[dst->nr_fstab + i].mountable = src->fstab[i].mountable;
fstab[dst->nr_fstab + i].mountpoint = src->fstab[i].mountpoint;
}
- free(src->fstab);
+ free (src->fstab);
src->fstab = NULL;
src->nr_fstab = 0;
diff --git a/src/inspect-icon.c b/src/inspect-icon.c
index 5c5169e..44f98e2 100644
--- a/src/inspect-icon.c
+++ b/src/inspect-icon.c
@@ -29,10 +29,10 @@
#include "guestfs-internal-actions.h"
/* External tools are required for some icon types. Check we have them. */
-#if defined(PBMTEXT) && defined (PNMTOPNG)
+#if defined(PBMTEXT) && defined(PNMTOPNG)
#define CAN_DO_CIRROS 1
#endif
-#if defined(WRESTOOL) && defined(BMPTOPNM) && defined(PNMTOPNG)
&& \
+#if defined(WRESTOOL) && defined(BMPTOPNM) && defined(PNMTOPNG)
&& \
defined(PAMCUT)
#define CAN_DO_WINDOWS 1
#endif
@@ -51,22 +51,31 @@
* An icon was found. 'ret' points to the icon buffer, and *size_r
* is the size.
*/
-static char *icon_favicon (guestfs_h *g, struct inspect_fs *fs, size_t *size_r);
-static char *icon_fedora (guestfs_h *g, struct inspect_fs *fs, size_t *size_r);
-static char *icon_rhel (guestfs_h *g, struct inspect_fs *fs, size_t *size_r);
-static char *icon_debian (guestfs_h *g, struct inspect_fs *fs, size_t *size_r);
-static char *icon_ubuntu (guestfs_h *g, struct inspect_fs *fs, size_t *size_r);
-static char *icon_mageia (guestfs_h *g, struct inspect_fs *fs, size_t *size_r);
-static char *icon_opensuse (guestfs_h *g, struct inspect_fs *fs, size_t *size_r);
+static char *icon_favicon (guestfs_h *g, struct inspect_fs *fs,
+ size_t *size_r);
+static char *icon_fedora (guestfs_h *g, struct inspect_fs *fs,
+ size_t *size_r);
+static char *icon_rhel (guestfs_h *g, struct inspect_fs *fs,
+ size_t *size_r);
+static char *icon_debian (guestfs_h *g, struct inspect_fs *fs,
+ size_t *size_r);
+static char *icon_ubuntu (guestfs_h *g, struct inspect_fs *fs,
+ size_t *size_r);
+static char *icon_mageia (guestfs_h *g, struct inspect_fs *fs,
+ size_t *size_r);
+static char *icon_opensuse (guestfs_h *g, struct inspect_fs *fs,
+ size_t *size_r);
#if CAN_DO_CIRROS
-static char *icon_cirros (guestfs_h *g, struct inspect_fs *fs, size_t *size_r);
+static char *icon_cirros (guestfs_h *g, struct inspect_fs *fs,
+ size_t *size_r);
#endif
#if CAN_DO_WINDOWS
-static char *icon_windows (guestfs_h *g, struct inspect_fs *fs, size_t *size_r);
+static char *icon_windows (guestfs_h *g, struct inspect_fs *fs,
+ size_t *size_r);
#endif
/* Dummy static object. */
-static char *NOT_FOUND = (char *) "not_found";
+static char *NOT_FOUND = (char *)"not_found";
/* For the unexpected legal consequences of this function, see:
*
http://lists.fedoraproject.org/pipermail/legal/2011-April/001615.html
@@ -77,8 +86,9 @@ static char *NOT_FOUND = (char *) "not_found";
* Check optargs for the optional argument.
*/
char *
-guestfs_impl_inspect_get_icon (guestfs_h *g, const char *root, size_t *size_r,
- const struct guestfs_inspect_get_icon_argv *optargs)
+guestfs_impl_inspect_get_icon (
+ guestfs_h *g, const char *root, size_t *size_r,
+ const struct guestfs_inspect_get_icon_argv *optargs)
{
struct inspect_fs *fs;
char *r = NOT_FOUND;
@@ -90,13 +100,14 @@ guestfs_impl_inspect_get_icon (guestfs_h *g, const char *root, size_t
*size_r,
return NULL;
/* Get optargs, or defaults. */
- favicon =
- optargs->bitmask & GUESTFS_INSPECT_GET_ICON_FAVICON_BITMASK ?
- optargs->favicon : 1;
+ favicon = optargs->bitmask & GUESTFS_INSPECT_GET_ICON_FAVICON_BITMASK
+ ? optargs->favicon
+ : 1;
highquality =
- optargs->bitmask & GUESTFS_INSPECT_GET_ICON_HIGHQUALITY_BITMASK ?
- optargs->highquality : 0;
+ optargs->bitmask & GUESTFS_INSPECT_GET_ICON_HIGHQUALITY_BITMASK
+ ? optargs->highquality
+ : 0;
/* Favicons are never high quality, so ... */
if (highquality)
@@ -158,7 +169,7 @@ guestfs_impl_inspect_get_icon (guestfs_h *g, const char *root, size_t
*size_r,
#endif
break;
- /* These are just to keep gcc warnings happy. */
+ /* These are just to keep gcc warnings happy. */
case OS_DISTRO_ARCHLINUX:
case OS_DISTRO_BUILDROOT:
case OS_DISTRO_COREOS:
@@ -178,8 +189,7 @@ guestfs_impl_inspect_get_icon (guestfs_h *g, const char *root, size_t
*size_r,
case OS_DISTRO_ALTLINUX:
case OS_DISTRO_FRUGALWARE:
case OS_DISTRO_PLD_LINUX:
- case OS_DISTRO_UNKNOWN:
- ; /* nothing */
+ case OS_DISTRO_UNKNOWN:; /* nothing */
}
break;
@@ -198,8 +208,7 @@ guestfs_impl_inspect_get_icon (guestfs_h *g, const char *root, size_t
*size_r,
case OS_TYPE_DOS:
case OS_TYPE_OPENBSD:
case OS_TYPE_MINIX:
- case OS_TYPE_UNKNOWN:
- ; /* nothing */
+ case OS_TYPE_UNKNOWN:; /* nothing */
}
if (r == NOT_FOUND) {
@@ -296,7 +305,8 @@ icon_favicon (guestfs_h *g, struct inspect_fs *fs, size_t *size_r)
/* Return FEDORA_ICON. I checked that this exists on at least Fedora 6
* through 16.
*/
-#define FEDORA_ICON "/usr/share/icons/hicolor/96x96/apps/fedora-logo-icon.png"
+#define FEDORA_ICON \
+ "/usr/share/icons/hicolor/96x96/apps/fedora-logo-icon.png"
static char *
icon_fedora (guestfs_h *g, struct inspect_fs *fs, size_t *size_r)
@@ -402,9 +412,9 @@ icon_cirros (guestfs_h *g, struct inspect_fs *fs, size_t *size_r)
pngfile = safe_asprintf (g, "%s/cirros.png", g->tmpdir);
guestfs_int_cmd_add_string_unquoted (cmd, PBMTEXT " < ");
- guestfs_int_cmd_add_string_quoted (cmd, local);
+ guestfs_int_cmd_add_string_quoted (cmd, local);
guestfs_int_cmd_add_string_unquoted (cmd, " | " PNMTOPNG " >
");
- guestfs_int_cmd_add_string_quoted (cmd, pngfile);
+ guestfs_int_cmd_add_string_quoted (cmd, pngfile);
r = guestfs_int_cmd_run (cmd);
if (r == -1)
return NOT_FOUND;
@@ -462,19 +472,19 @@ icon_windows_xp (guestfs_h *g, struct inspect_fs *fs, size_t
*size_r)
if (r == 0)
return NOT_FOUND;
- filename_downloaded = guestfs_int_download_to_tmp (g, fs, filename_case,
- "explorer.exe",
- MAX_WINDOWS_EXPLORER_SIZE);
+ filename_downloaded = guestfs_int_download_to_tmp (
+ g, fs, filename_case, "explorer.exe", MAX_WINDOWS_EXPLORER_SIZE);
if (filename_downloaded == NULL)
return NOT_FOUND;
pngfile = safe_asprintf (g, "%s/windows-xp-icon.png", g->tmpdir);
- guestfs_int_cmd_add_string_unquoted (cmd, WRESTOOL " -x --type=2 --name=143
");
- guestfs_int_cmd_add_string_quoted (cmd, filename_downloaded);
guestfs_int_cmd_add_string_unquoted (cmd,
- " | " BMPTOPNM " | " PNMTOPNG " > ");
- guestfs_int_cmd_add_string_quoted (cmd, pngfile);
+ WRESTOOL " -x --type=2 --name=143 ");
+ guestfs_int_cmd_add_string_quoted (cmd, filename_downloaded);
+ guestfs_int_cmd_add_string_unquoted (cmd,
+ " | " BMPTOPNM " | " PNMTOPNG
" > ");
+ guestfs_int_cmd_add_string_quoted (cmd, pngfile);
r = guestfs_int_cmd_run (cmd);
if (r == -1)
return NULL;
@@ -512,21 +522,19 @@ icon_windows_7 (guestfs_h *g, struct inspect_fs *fs, size_t
*size_r)
if (r == 0)
return NOT_FOUND;
- filename_downloaded = guestfs_int_download_to_tmp (g, fs, filename_case,
- "explorer.exe",
- MAX_WINDOWS_EXPLORER_SIZE);
+ filename_downloaded = guestfs_int_download_to_tmp (
+ g, fs, filename_case, "explorer.exe", MAX_WINDOWS_EXPLORER_SIZE);
if (filename_downloaded == NULL)
return NOT_FOUND;
pngfile = safe_asprintf (g, "%s/windows-7-icon.png", g->tmpdir);
- guestfs_int_cmd_add_string_unquoted (cmd, WRESTOOL " -x --type=2 --name=6801
");
- guestfs_int_cmd_add_string_quoted (cmd, filename_downloaded);
- guestfs_int_cmd_add_string_unquoted (cmd,
- " | " BMPTOPNM " | "
- PAMCUT " -bottom 54 | "
- PNMTOPNG " > ");
- guestfs_int_cmd_add_string_quoted (cmd, pngfile);
+ guestfs_int_cmd_add_string_unquoted (cmd, WRESTOOL
+ " -x --type=2 --name=6801 ");
+ guestfs_int_cmd_add_string_quoted (cmd, filename_downloaded);
+ guestfs_int_cmd_add_string_unquoted (
+ cmd, " | " BMPTOPNM " | " PAMCUT " -bottom 54 | "
PNMTOPNG " > ");
+ guestfs_int_cmd_add_string_quoted (cmd, pngfile);
r = guestfs_int_cmd_run (cmd);
if (r == -1)
return NULL;
@@ -552,8 +560,8 @@ icon_windows_8 (guestfs_h *g, struct inspect_fs *fs, size_t *size_r)
int r;
char *ret;
- filename_case = guestfs_int_case_sensitive_path_silently
- (g, "/ProgramData/Microsoft/Windows Live/WLive48x48.png");
+ filename_case = guestfs_int_case_sensitive_path_silently (
+ g, "/ProgramData/Microsoft/Windows Live/WLive48x48.png");
if (filename_case == NULL)
return NOT_FOUND; /* Not an error since a parent dir might not exist. */
@@ -565,12 +573,13 @@ icon_windows_8 (guestfs_h *g, struct inspect_fs *fs, size_t
*size_r)
if (r == 0)
return NOT_FOUND;
- filename_downloaded = guestfs_int_download_to_tmp (g, fs, filename_case,
- "wlive48x48.png", 8192);
+ filename_downloaded = guestfs_int_download_to_tmp (
+ g, fs, filename_case, "wlive48x48.png", 8192);
if (filename_downloaded == NULL)
return NOT_FOUND;
- if (guestfs_int_read_whole_file (g, filename_downloaded, &ret, size_r) == -1)
+ if (guestfs_int_read_whole_file (g, filename_downloaded, &ret, size_r) ==
+ -1)
return NULL;
return ret;
@@ -595,7 +604,8 @@ icon_windows (guestfs_h *g, struct inspect_fs *fs, size_t *size_r)
return icon_windows_8 (g, fs, size_r);
/* Not (yet) a supported version of Windows. */
- else return NOT_FOUND;
+ else
+ return NOT_FOUND;
}
#endif /* CAN_DO_WINDOWS */
diff --git a/src/inspect.c b/src/inspect.c
index 497794e..d5f1833 100644
--- a/src/inspect.c
+++ b/src/inspect.c
@@ -60,7 +60,8 @@ guestfs_impl_inspect_os (guestfs_h *g)
*/
fses = guestfs_list_filesystems (g);
- if (fses == NULL) return NULL;
+ if (fses == NULL)
+ return NULL;
for (fs = fses; *fs; fs += 2) {
if (guestfs_int_check_for_filesystem_on (g, *fs)) {
@@ -124,14 +125,15 @@ collect_coreos_inspection_info (guestfs_h *g)
* partition is empty and it gets filled up when an update is performed.
* Then, when the system reboots, the boot loader is instructed to boot
* from the passive partition. If both partitions are valid, we cannot
- * determine which the active and which the passive is, unless we peep into
- * the boot loader. As a workaround, we check the OS versions and pick the
+ * determine which the active and which the passive is, unless we peep
+ * into
+ * the boot loader. As a workaround, we check the OS versions and pick
+ * the
* one with the higher version as active.
*/
- if (usr &&
- (usr->major_version > fs->major_version ||
- (usr->major_version == fs->major_version &&
- usr->minor_version > fs->minor_version)))
+ if (usr && (usr->major_version > fs->major_version ||
+ (usr->major_version == fs->major_version &&
+ usr->minor_version > fs->minor_version)))
continue;
usr = fs;
@@ -157,10 +159,8 @@ check_for_duplicated_bsd_root (guestfs_h *g)
bool is_bsd;
struct inspect_fs *fs = &g->fses[i];
- is_bsd =
- fs->type == OS_TYPE_FREEBSD ||
- fs->type == OS_TYPE_NETBSD ||
- fs->type == OS_TYPE_OPENBSD;
+ is_bsd = fs->type == OS_TYPE_FREEBSD || fs->type == OS_TYPE_NETBSD ||
+ fs->type == OS_TYPE_OPENBSD;
if (fs->is_root && is_bsd &&
match (g, fs->mountable, re_primary_partition)) {
@@ -180,8 +180,8 @@ check_for_duplicated_bsd_root (guestfs_h *g)
static int
compare_strings (const void *vp1, const void *vp2)
{
- const char *s1 = * (char * const *) vp1;
- const char *s2 = * (char * const *) vp2;
+ const char *s1 = *(char *const *)vp1;
+ const char *s2 = *(char *const *)vp2;
return strcmp (s1, s2);
}
@@ -201,7 +201,7 @@ guestfs_impl_inspect_get_roots (guestfs_h *g)
}
guestfs_int_end_stringsbuf (g, &ret);
- qsort (ret.argv, ret.size-1, sizeof (char *), compare_strings);
+ qsort (ret.argv, ret.size - 1, sizeof (char *), compare_strings);
return ret.argv;
}
@@ -216,15 +216,33 @@ guestfs_impl_inspect_get_type (guestfs_h *g, const char *root)
return NULL;
switch (fs->type) {
- case OS_TYPE_DOS: ret = safe_strdup (g, "dos"); break;
- case OS_TYPE_FREEBSD: ret = safe_strdup (g, "freebsd"); break;
- case OS_TYPE_HURD: ret = safe_strdup (g, "hurd"); break;
- case OS_TYPE_LINUX: ret = safe_strdup (g, "linux"); break;
- case OS_TYPE_MINIX: ret = safe_strdup (g, "minix"); break;
- case OS_TYPE_NETBSD: ret = safe_strdup (g, "netbsd"); break;
- case OS_TYPE_OPENBSD: ret = safe_strdup (g, "openbsd"); break;
- case OS_TYPE_WINDOWS: ret = safe_strdup (g, "windows"); break;
- case OS_TYPE_UNKNOWN: ret = safe_strdup (g, "unknown"); break;
+ case OS_TYPE_DOS:
+ ret = safe_strdup (g, "dos");
+ break;
+ case OS_TYPE_FREEBSD:
+ ret = safe_strdup (g, "freebsd");
+ break;
+ case OS_TYPE_HURD:
+ ret = safe_strdup (g, "hurd");
+ break;
+ case OS_TYPE_LINUX:
+ ret = safe_strdup (g, "linux");
+ break;
+ case OS_TYPE_MINIX:
+ ret = safe_strdup (g, "minix");
+ break;
+ case OS_TYPE_NETBSD:
+ ret = safe_strdup (g, "netbsd");
+ break;
+ case OS_TYPE_OPENBSD:
+ ret = safe_strdup (g, "openbsd");
+ break;
+ case OS_TYPE_WINDOWS:
+ ret = safe_strdup (g, "windows");
+ break;
+ case OS_TYPE_UNKNOWN:
+ ret = safe_strdup (g, "unknown");
+ break;
}
if (ret == NULL)
@@ -240,7 +258,7 @@ guestfs_impl_inspect_get_arch (guestfs_h *g, const char *root)
if (!fs)
return NULL;
- return safe_strdup (g, fs->arch ? : "unknown");
+ return safe_strdup (g, fs->arch ?: "unknown");
}
char *
@@ -253,39 +271,105 @@ guestfs_impl_inspect_get_distro (guestfs_h *g, const char *root)
return NULL;
switch (fs->distro) {
- case OS_DISTRO_ALPINE_LINUX: ret = safe_strdup (g, "alpinelinux"); break;
- case OS_DISTRO_ALTLINUX: ret = safe_strdup (g, "altlinux"); break;
- case OS_DISTRO_ARCHLINUX: ret = safe_strdup (g, "archlinux"); break;
- case OS_DISTRO_BUILDROOT: ret = safe_strdup (g, "buildroot"); break;
- case OS_DISTRO_CENTOS: ret = safe_strdup (g, "centos"); break;
- case OS_DISTRO_CIRROS: ret = safe_strdup (g, "cirros"); break;
- case OS_DISTRO_COREOS: ret = safe_strdup (g, "coreos"); break;
- case OS_DISTRO_DEBIAN: ret = safe_strdup (g, "debian"); break;
- case OS_DISTRO_FEDORA: ret = safe_strdup (g, "fedora"); break;
- case OS_DISTRO_FREEBSD: ret = safe_strdup (g, "freebsd"); break;
- case OS_DISTRO_FREEDOS: ret = safe_strdup (g, "freedos"); break;
- case OS_DISTRO_FRUGALWARE: ret = safe_strdup (g, "frugalware"); break;
- case OS_DISTRO_GENTOO: ret = safe_strdup (g, "gentoo"); break;
- case OS_DISTRO_LINUX_MINT: ret = safe_strdup (g, "linuxmint"); break;
- case OS_DISTRO_MAGEIA: ret = safe_strdup (g, "mageia"); break;
- case OS_DISTRO_MANDRIVA: ret = safe_strdup (g, "mandriva"); break;
- case OS_DISTRO_MEEGO: ret = safe_strdup (g, "meego"); break;
- case OS_DISTRO_NETBSD: ret = safe_strdup (g, "netbsd"); break;
- case OS_DISTRO_OPENBSD: ret = safe_strdup (g, "openbsd"); break;
- case OS_DISTRO_OPENSUSE: ret = safe_strdup (g, "opensuse"); break;
- case OS_DISTRO_ORACLE_LINUX: ret = safe_strdup (g, "oraclelinux"); break;
- case OS_DISTRO_PARDUS: ret = safe_strdup (g, "pardus"); break;
- case OS_DISTRO_PLD_LINUX: ret = safe_strdup (g, "pldlinux"); break;
- case OS_DISTRO_REDHAT_BASED: ret = safe_strdup (g, "redhat-based"); break;
- case OS_DISTRO_RHEL: ret = safe_strdup (g, "rhel"); break;
- case OS_DISTRO_SCIENTIFIC_LINUX: ret = safe_strdup (g, "scientificlinux");
break;
- case OS_DISTRO_SLACKWARE: ret = safe_strdup (g, "slackware"); break;
- case OS_DISTRO_SLES: ret = safe_strdup (g, "sles"); break;
- case OS_DISTRO_SUSE_BASED: ret = safe_strdup (g, "suse-based"); break;
- case OS_DISTRO_TTYLINUX: ret = safe_strdup (g, "ttylinux"); break;
- case OS_DISTRO_WINDOWS: ret = safe_strdup (g, "windows"); break;
- case OS_DISTRO_UBUNTU: ret = safe_strdup (g, "ubuntu"); break;
- case OS_DISTRO_UNKNOWN: ret = safe_strdup (g, "unknown"); break;
+ case OS_DISTRO_ALPINE_LINUX:
+ ret = safe_strdup (g, "alpinelinux");
+ break;
+ case OS_DISTRO_ALTLINUX:
+ ret = safe_strdup (g, "altlinux");
+ break;
+ case OS_DISTRO_ARCHLINUX:
+ ret = safe_strdup (g, "archlinux");
+ break;
+ case OS_DISTRO_BUILDROOT:
+ ret = safe_strdup (g, "buildroot");
+ break;
+ case OS_DISTRO_CENTOS:
+ ret = safe_strdup (g, "centos");
+ break;
+ case OS_DISTRO_CIRROS:
+ ret = safe_strdup (g, "cirros");
+ break;
+ case OS_DISTRO_COREOS:
+ ret = safe_strdup (g, "coreos");
+ break;
+ case OS_DISTRO_DEBIAN:
+ ret = safe_strdup (g, "debian");
+ break;
+ case OS_DISTRO_FEDORA:
+ ret = safe_strdup (g, "fedora");
+ break;
+ case OS_DISTRO_FREEBSD:
+ ret = safe_strdup (g, "freebsd");
+ break;
+ case OS_DISTRO_FREEDOS:
+ ret = safe_strdup (g, "freedos");
+ break;
+ case OS_DISTRO_FRUGALWARE:
+ ret = safe_strdup (g, "frugalware");
+ break;
+ case OS_DISTRO_GENTOO:
+ ret = safe_strdup (g, "gentoo");
+ break;
+ case OS_DISTRO_LINUX_MINT:
+ ret = safe_strdup (g, "linuxmint");
+ break;
+ case OS_DISTRO_MAGEIA:
+ ret = safe_strdup (g, "mageia");
+ break;
+ case OS_DISTRO_MANDRIVA:
+ ret = safe_strdup (g, "mandriva");
+ break;
+ case OS_DISTRO_MEEGO:
+ ret = safe_strdup (g, "meego");
+ break;
+ case OS_DISTRO_NETBSD:
+ ret = safe_strdup (g, "netbsd");
+ break;
+ case OS_DISTRO_OPENBSD:
+ ret = safe_strdup (g, "openbsd");
+ break;
+ case OS_DISTRO_OPENSUSE:
+ ret = safe_strdup (g, "opensuse");
+ break;
+ case OS_DISTRO_ORACLE_LINUX:
+ ret = safe_strdup (g, "oraclelinux");
+ break;
+ case OS_DISTRO_PARDUS:
+ ret = safe_strdup (g, "pardus");
+ break;
+ case OS_DISTRO_PLD_LINUX:
+ ret = safe_strdup (g, "pldlinux");
+ break;
+ case OS_DISTRO_REDHAT_BASED:
+ ret = safe_strdup (g, "redhat-based");
+ break;
+ case OS_DISTRO_RHEL:
+ ret = safe_strdup (g, "rhel");
+ break;
+ case OS_DISTRO_SCIENTIFIC_LINUX:
+ ret = safe_strdup (g, "scientificlinux");
+ break;
+ case OS_DISTRO_SLACKWARE:
+ ret = safe_strdup (g, "slackware");
+ break;
+ case OS_DISTRO_SLES:
+ ret = safe_strdup (g, "sles");
+ break;
+ case OS_DISTRO_SUSE_BASED:
+ ret = safe_strdup (g, "suse-based");
+ break;
+ case OS_DISTRO_TTYLINUX:
+ ret = safe_strdup (g, "ttylinux");
+ break;
+ case OS_DISTRO_WINDOWS:
+ ret = safe_strdup (g, "windows");
+ break;
+ case OS_DISTRO_UBUNTU:
+ ret = safe_strdup (g, "ubuntu");
+ break;
+ case OS_DISTRO_UNKNOWN:
+ ret = safe_strdup (g, "unknown");
+ break;
}
if (ret == NULL)
@@ -321,7 +405,7 @@ guestfs_impl_inspect_get_product_name (guestfs_h *g, const char
*root)
if (!fs)
return NULL;
- return safe_strdup (g, fs->product_name ? : "unknown");
+ return safe_strdup (g, fs->product_name ?: "unknown");
}
char *
@@ -331,7 +415,7 @@ guestfs_impl_inspect_get_product_variant (guestfs_h *g, const char
*root)
if (!fs)
return NULL;
- return safe_strdup (g, fs->product_variant ? : "unknown");
+ return safe_strdup (g, fs->product_variant ?: "unknown");
}
char *
@@ -342,7 +426,8 @@ guestfs_impl_inspect_get_windows_systemroot (guestfs_h *g, const char
*root)
return NULL;
if (!fs->windows_systemroot) {
- error (g, _("not a Windows guest, or systemroot could not be
determined"));
+ error (
+ g, _("not a Windows guest, or systemroot could not be determined"));
return NULL;
}
@@ -351,14 +436,15 @@ guestfs_impl_inspect_get_windows_systemroot (guestfs_h *g, const
char *root)
char *
guestfs_impl_inspect_get_windows_current_control_set (guestfs_h *g,
- const char *root)
+ const char *root)
{
struct inspect_fs *fs = guestfs_int_search_for_root (g, root);
if (!fs)
return NULL;
if (!fs->windows_current_control_set) {
- error (g, _("not a Windows guest, or CurrentControlSet could not be
determined"));
+ error (g, _("not a Windows guest, or CurrentControlSet could not be "
+ "determined"));
return NULL;
}
@@ -374,9 +460,15 @@ guestfs_impl_inspect_get_format (guestfs_h *g, const char *root)
return NULL;
switch (fs->format) {
- case OS_FORMAT_INSTALLED: ret = safe_strdup (g, "installed"); break;
- case OS_FORMAT_INSTALLER: ret = safe_strdup (g, "installer"); break;
- case OS_FORMAT_UNKNOWN: ret = safe_strdup (g, "unknown"); break;
+ case OS_FORMAT_INSTALLED:
+ ret = safe_strdup (g, "installed");
+ break;
+ case OS_FORMAT_INSTALLER:
+ ret = safe_strdup (g, "installer");
+ break;
+ case OS_FORMAT_UNKNOWN:
+ ret = safe_strdup (g, "unknown");
+ break;
}
if (ret == NULL)
@@ -440,7 +532,7 @@ guestfs_impl_inspect_get_mountpoints (guestfs_h *g, const char *root)
}
/* Hashtables have 2N+1 entries. */
- ret = calloc (2*count+1, sizeof (char *));
+ ret = calloc (2 * count + 1, sizeof (char *));
if (ret == NULL) {
perrorf (g, "calloc");
return NULL;
@@ -457,8 +549,8 @@ guestfs_impl_inspect_get_mountpoints (guestfs_h *g, const char *root)
count = 0;
for (i = 0; i < nr; ++i)
if (CRITERION (fs, i)) {
- ret[2*count] = safe_strdup (g, fs->fstab[i].mountpoint);
- ret[2*count+1] = safe_strdup (g, fs->fstab[i].mountable);
+ ret[2 * count] = safe_strdup (g, fs->fstab[i].mountpoint);
+ ret[2 * count + 1] = safe_strdup (g, fs->fstab[i].mountable);
count++;
}
#undef CRITERION
@@ -477,7 +569,7 @@ guestfs_impl_inspect_get_filesystems (guestfs_h *g, const char *root)
return NULL;
nr = fs->nr_fstab;
- ret = calloc (nr == 0 ? 2 : nr+1, sizeof (char *));
+ ret = calloc (nr == 0 ? 2 : nr + 1, sizeof (char *));
if (ret == NULL) {
perrorf (g, "calloc");
return NULL;
@@ -525,13 +617,27 @@ guestfs_impl_inspect_get_package_format (guestfs_h *g, const char
*root)
return NULL;
switch (fs->package_format) {
- case OS_PACKAGE_FORMAT_RPM: ret = safe_strdup (g, "rpm"); break;
- case OS_PACKAGE_FORMAT_DEB: ret = safe_strdup (g, "deb"); break;
- case OS_PACKAGE_FORMAT_PACMAN: ret = safe_strdup (g, "pacman"); break;
- case OS_PACKAGE_FORMAT_EBUILD: ret = safe_strdup (g, "ebuild"); break;
- case OS_PACKAGE_FORMAT_PISI: ret = safe_strdup (g, "pisi"); break;
- case OS_PACKAGE_FORMAT_PKGSRC: ret = safe_strdup (g, "pkgsrc"); break;
- case OS_PACKAGE_FORMAT_APK: ret = safe_strdup (g, "apk"); break;
+ case OS_PACKAGE_FORMAT_RPM:
+ ret = safe_strdup (g, "rpm");
+ break;
+ case OS_PACKAGE_FORMAT_DEB:
+ ret = safe_strdup (g, "deb");
+ break;
+ case OS_PACKAGE_FORMAT_PACMAN:
+ ret = safe_strdup (g, "pacman");
+ break;
+ case OS_PACKAGE_FORMAT_EBUILD:
+ ret = safe_strdup (g, "ebuild");
+ break;
+ case OS_PACKAGE_FORMAT_PISI:
+ ret = safe_strdup (g, "pisi");
+ break;
+ case OS_PACKAGE_FORMAT_PKGSRC:
+ ret = safe_strdup (g, "pkgsrc");
+ break;
+ case OS_PACKAGE_FORMAT_APK:
+ ret = safe_strdup (g, "apk");
+ break;
case OS_PACKAGE_FORMAT_UNKNOWN:
ret = safe_strdup (g, "unknown");
break;
@@ -552,16 +658,36 @@ guestfs_impl_inspect_get_package_management (guestfs_h *g, const
char *root)
return NULL;
switch (fs->package_management) {
- case OS_PACKAGE_MANAGEMENT_APK: ret = safe_strdup (g, "apk"); break;
- case OS_PACKAGE_MANAGEMENT_APT: ret = safe_strdup (g, "apt"); break;
- case OS_PACKAGE_MANAGEMENT_DNF: ret = safe_strdup (g, "dnf"); break;
- case OS_PACKAGE_MANAGEMENT_PACMAN: ret = safe_strdup (g, "pacman"); break;
- case OS_PACKAGE_MANAGEMENT_PISI: ret = safe_strdup (g, "pisi"); break;
- case OS_PACKAGE_MANAGEMENT_PORTAGE: ret = safe_strdup (g, "portage"); break;
- case OS_PACKAGE_MANAGEMENT_UP2DATE: ret = safe_strdup (g, "up2date"); break;
- case OS_PACKAGE_MANAGEMENT_URPMI: ret = safe_strdup (g, "urpmi"); break;
- case OS_PACKAGE_MANAGEMENT_YUM: ret = safe_strdup (g, "yum"); break;
- case OS_PACKAGE_MANAGEMENT_ZYPPER: ret = safe_strdup (g, "zypper"); break;
+ case OS_PACKAGE_MANAGEMENT_APK:
+ ret = safe_strdup (g, "apk");
+ break;
+ case OS_PACKAGE_MANAGEMENT_APT:
+ ret = safe_strdup (g, "apt");
+ break;
+ case OS_PACKAGE_MANAGEMENT_DNF:
+ ret = safe_strdup (g, "dnf");
+ break;
+ case OS_PACKAGE_MANAGEMENT_PACMAN:
+ ret = safe_strdup (g, "pacman");
+ break;
+ case OS_PACKAGE_MANAGEMENT_PISI:
+ ret = safe_strdup (g, "pisi");
+ break;
+ case OS_PACKAGE_MANAGEMENT_PORTAGE:
+ ret = safe_strdup (g, "portage");
+ break;
+ case OS_PACKAGE_MANAGEMENT_UP2DATE:
+ ret = safe_strdup (g, "up2date");
+ break;
+ case OS_PACKAGE_MANAGEMENT_URPMI:
+ ret = safe_strdup (g, "urpmi");
+ break;
+ case OS_PACKAGE_MANAGEMENT_YUM:
+ ret = safe_strdup (g, "yum");
+ break;
+ case OS_PACKAGE_MANAGEMENT_ZYPPER:
+ ret = safe_strdup (g, "zypper");
+ break;
case OS_PACKAGE_MANAGEMENT_UNKNOWN:
ret = safe_strdup (g, "unknown");
break;
@@ -580,7 +706,7 @@ guestfs_impl_inspect_get_hostname (guestfs_h *g, const char *root)
if (!fs)
return NULL;
- return safe_strdup (g, fs->hostname ? : "unknown");
+ return safe_strdup (g, fs->hostname ?: "unknown");
}
void
@@ -624,8 +750,8 @@ guestfs_int_free_inspect_info (guestfs_h *g)
*/
char *
guestfs_int_download_to_tmp (guestfs_h *g, struct inspect_fs *fs,
- const char *filename,
- const char *basename, uint64_t max_size)
+ const char *filename, const char *basename,
+ uint64_t max_size)
{
char *r;
int fd;
@@ -649,13 +775,13 @@ guestfs_int_download_to_tmp (guestfs_h *g, struct inspect_fs *fs,
if (size == -1)
/* guestfs_filesize failed and has already set error in handle */
goto error;
- if ((uint64_t) size > max_size) {
+ if ((uint64_t)size > max_size) {
error (g, _("size of %s is unreasonably large (%" PRIi64 "
bytes)"),
filename, size);
goto error;
}
- fd = open (r, O_WRONLY|O_CREAT|O_TRUNC|O_NOCTTY|O_CLOEXEC, 0600);
+ fd = open (r, O_WRONLY | O_CREAT | O_TRUNC | O_NOCTTY | O_CLOEXEC, 0600);
if (fd == -1) {
perrorf (g, "open: %s", r);
goto error;
@@ -677,7 +803,7 @@ guestfs_int_download_to_tmp (guestfs_h *g, struct inspect_fs *fs,
return r;
- error:
+error:
free (r);
return NULL;
}
@@ -698,7 +824,8 @@ guestfs_int_search_for_root (guestfs_h *g, const char *root)
return fs;
}
- error (g, _("%s: root device not found: only call this function with a root device
previously returned by guestfs_inspect_os"),
+ error (g, _("%s: root device not found: only call this function with a "
+ "root device previously returned by guestfs_inspect_os"),
root);
return NULL;
}
diff --git a/src/journal.c b/src/journal.c
index 22b81de..bdd4839 100644
--- a/src/journal.c
+++ b/src/journal.c
@@ -36,7 +36,7 @@
#if defined __APPLE__ && defined __MACH__
#include <libkern/OSByteOrder.h>
-#define be64toh(x) OSSwapBigToHostInt64(x)
+#define be64toh(x) OSSwapBigToHostInt64 (x)
#endif
#include "full-read.h"
@@ -73,7 +73,7 @@ guestfs_impl_journal_get (guestfs_h *g)
if (guestfs_internal_journal_get (g, tmpfile) == -1)
goto err;
- fd = open (tmpfile, O_RDONLY|O_CLOEXEC);
+ fd = open (tmpfile, O_RDONLY | O_CLOEXEC);
if (fd == -1) {
perrorf (g, "open: %s", tmpfile);
goto err;
@@ -87,13 +87,13 @@ guestfs_impl_journal_get (guestfs_h *g)
/* Don't use safe_malloc. Want to return an errno to the caller. */
size = statbuf.st_size;
- buf = malloc (size+1);
+ buf = malloc (size + 1);
if (!buf) {
perrorf (g, "malloc: %zu bytes", size);
goto err;
}
eobuf = &buf[size];
- *eobuf = '\0'; /* Makes strchr etc safe. */
+ *eobuf = '\0'; /* Makes strchr etc safe. */
if (full_read (fd, buf, size) != size) {
perrorf (g, "full-read: %s: %zu bytes", tmpfile, size);
@@ -116,44 +116,48 @@ guestfs_impl_journal_get (guestfs_h *g)
* 64 bit length field followed by N bytes of 'field=data' binary
* data.
*/
- for (i = 0; i < size; ) {
- if (i+8 > size) {
+ for (i = 0; i < size;) {
+ if (i + 8 > size) {
error (g, "invalid data from guestfs_internal_journal_get: "
- "truncated: "
- "size=%zu, i=%zu", size, i);
+ "truncated: "
+ "size=%zu, i=%zu",
+ size, i);
goto err;
}
- memcpy(&len, &buf[i], sizeof(len));
+ memcpy (&len, &buf[i], sizeof (len));
len = be64toh (len);
i += 8;
- eofield = &buf[i+len];
+ eofield = &buf[i + len];
if (eofield > eobuf) {
error (g, "invalid data from guestfs_internal_journal_get: "
- "length field is too large: "
- "size=%zu, i=%zu, len=%" PRIu64, size, i, len);
+ "length field is too large: "
+ "size=%zu, i=%zu, len=%" PRIu64,
+ size, i, len);
goto err;
}
p = strchr (&buf[i], '=');
if (!p || p >= eofield) {
error (g, "invalid data from guestfs_internal_journal_get: "
- "no '=' found separating field name and data: "
- "size=%zu, i=%zu, p=%p", size, i, p);
+ "no '=' found separating field name and data: "
+ "size=%zu, i=%zu, p=%p",
+ size, i, p);
goto err;
}
*p = '\0';
j++;
- ret->val = safe_realloc (g, ret->val, j * sizeof (struct guestfs_xattr));
- ret->val[j-1].attrname = safe_strdup (g, &buf[i]);
- ret->val[j-1].attrval_len = eofield - (p+1);
- ret->val[j-1].attrval = safe_memdup (g, p+1, eofield - (p+1));
+ ret->val =
+ safe_realloc (g, ret->val, j * sizeof (struct guestfs_xattr));
+ ret->val[j - 1].attrname = safe_strdup (g, &buf[i]);
+ ret->val[j - 1].attrval_len = eofield - (p + 1);
+ ret->val[j - 1].attrval = safe_memdup (g, p + 1, eofield - (p + 1));
ret->len = j;
i += len;
}
- return ret; /* caller frees */
+ return ret; /* caller frees */
- err:
+err:
guestfs_free_xattr_list (ret);
if (fd >= 0)
close (fd);
diff --git a/src/launch-direct.c b/src/launch-direct.c
index 322737d..306b694 100644
--- a/src/launch-direct.c
+++ b/src/launch-direct.c
@@ -50,16 +50,16 @@ COMPILE_REGEXP (re_major_minor, "(\\d+)\\.(\\d+)", 0)
/* Per-handle data. */
struct backend_direct_data {
- pid_t pid; /* Qemu PID. */
- pid_t recoverypid; /* Recovery process PID. */
+ pid_t pid; /* Qemu PID. */
+ pid_t recoverypid; /* Recovery process PID. */
- char *qemu_help; /* Output of qemu -help. */
- char *qemu_devices; /* Output of qemu -device ? */
+ char *qemu_help; /* Output of qemu -help. */
+ char *qemu_devices; /* Output of qemu -device ? */
/* qemu version (0, 0 if unable to parse). */
int qemu_version_major, qemu_version_minor;
- int virtio_scsi; /* See function qemu_supports_virtio_scsi */
+ int virtio_scsi; /* See function qemu_supports_virtio_scsi */
char guestfsd_sock[UNIX_PATH_MAX]; /* Path to daemon socket. */
};
@@ -67,9 +67,12 @@ struct backend_direct_data {
static int is_openable (guestfs_h *g, const char *path, int flags);
static char *make_appliance_dev (guestfs_h *g, int virtio_scsi);
static void print_qemu_command_line (guestfs_h *g, char **argv);
-static int qemu_supports (guestfs_h *g, struct backend_direct_data *, const char
*option);
-static int qemu_supports_device (guestfs_h *g, struct backend_direct_data *, const char
*device_name);
-static int qemu_supports_virtio_scsi (guestfs_h *g, struct backend_direct_data *);
+static int qemu_supports (guestfs_h *g, struct backend_direct_data *,
+ const char *option);
+static int qemu_supports_device (guestfs_h *g, struct backend_direct_data *,
+ const char *device_name);
+static int qemu_supports_virtio_scsi (guestfs_h *g,
+ struct backend_direct_data *);
static char *qemu_escape_param (guestfs_h *g, const char *param);
static char *
@@ -120,7 +123,7 @@ add_cmdline_shell_unquoted (guestfs_h *g, struct stringsbuf *sb,
while (*options) {
quote = *options;
if (quote == '\'' || quote == '"')
- startp = options+1;
+ startp = options + 1;
else {
startp = options;
quote = ' ';
@@ -129,9 +132,10 @@ add_cmdline_shell_unquoted (guestfs_h *g, struct stringsbuf *sb,
endp = strchr (options, quote);
if (endp == NULL) {
if (quote != ' ') {
- fprintf (stderr,
- _("unclosed quote character (%c) in command line near: %s"),
- quote, options);
+ fprintf (
+ stderr,
+ _("unclosed quote character (%c) in command line near: %s"),
+ quote, options);
_exit (EXIT_FAILURE);
}
endp = options + strlen (options);
@@ -141,15 +145,16 @@ add_cmdline_shell_unquoted (guestfs_h *g, struct stringsbuf *sb,
if (endp[0] == '\0')
nextp = endp;
else
- nextp = endp+1;
+ nextp = endp + 1;
}
else {
if (!endp[1])
- nextp = endp+1;
+ nextp = endp + 1;
else if (endp[1] == ' ')
- nextp = endp+2;
+ nextp = endp + 2;
else {
- fprintf (stderr, _("cannot parse quoted string near: %s"), options);
+ fprintf (stderr, _("cannot parse quoted string near: %s"),
+ options);
_exit (EXIT_FAILURE);
}
}
@@ -157,7 +162,7 @@ add_cmdline_shell_unquoted (guestfs_h *g, struct stringsbuf *sb,
nextp++;
guestfs_int_add_string_nodup (g, sb,
- safe_strndup (g, startp, endp-startp));
+ safe_strndup (g, startp, endp - startp));
options = nextp;
}
@@ -189,7 +194,8 @@ debian_kvm_warning (guestfs_h *g)
if ((statbuf.st_mode & 0777) != 0660)
return;
- /* They might be running libguestfs as root or have chowned /dev/kvm, so: */
+ /* They might be running libguestfs as root or have chowned /dev/kvm, so:
+ */
if (geteuid () == statbuf.st_uid)
return;
@@ -206,7 +212,7 @@ debian_kvm_warning (guestfs_h *g)
warning (g, "getgroups: %m (ignored)");
return;
}
- for (i = 0; i < (size_t) ngroups; ++i) {
+ for (i = 0; i < (size_t)ngroups; ++i) {
if (groups[i] == kvm_group)
return;
}
@@ -215,12 +221,14 @@ debian_kvm_warning (guestfs_h *g)
/* No, so emit the warning. Note that \n characters cannot appear
* in warnings.
*/
- warning (g,
- _("current user is not a member of the KVM group (group ID %d). "
- "This user cannot access /dev/kvm, so libguestfs may run very slowly. "
- "It is recommended that you 'chmod 0666 /dev/kvm' or add the current
user "
- "to the KVM group (you might need to log out and log in again)."),
- (int) kvm_group);
+ warning (
+ g, _("current user is not a member of the KVM group (group ID %d). "
+ "This user cannot access /dev/kvm, so libguestfs may run very "
+ "slowly. "
+ "It is recommended that you 'chmod 0666 /dev/kvm' or add the
"
+ "current user "
+ "to the KVM group (you might need to log out and log in again)."),
+ (int)kvm_group);
#endif /* __linux__ */
}
@@ -262,7 +270,7 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
* which case the user would not get hardware virtualization,
* although at least shouldn't fail.
*/
- has_kvm = is_openable (g, "/dev/kvm", O_RDWR|O_CLOEXEC);
+ has_kvm = is_openable (g, "/dev/kvm", O_RDWR | O_CLOEXEC);
force_tcg = guestfs_int_get_backend_setting_bool (g, "force_tcg");
if (force_tcg == -1)
@@ -297,7 +305,7 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
&data->guestfsd_sock) == -1)
goto cleanup0;
- daemon_accept_sock = socket (AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0);
+ daemon_accept_sock = socket (AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
if (daemon_accept_sock == -1) {
perrorf (g, "socket");
goto cleanup0;
@@ -305,10 +313,10 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
addr.sun_family = AF_UNIX;
strncpy (addr.sun_path, data->guestfsd_sock, UNIX_PATH_MAX);
- addr.sun_path[UNIX_PATH_MAX-1] = '\0';
+ addr.sun_path[UNIX_PATH_MAX - 1] = '\0';
- if (bind (daemon_accept_sock, (struct sockaddr *) &addr,
- sizeof addr) == -1) {
+ if (bind (daemon_accept_sock, (struct sockaddr *)&addr, sizeof addr) ==
+ -1) {
perrorf (g, "bind");
goto cleanup0;
}
@@ -319,7 +327,7 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
}
if (!g->direct_mode) {
- if (socketpair (AF_LOCAL, SOCK_STREAM|SOCK_CLOEXEC, 0, sv) == -1) {
+ if (socketpair (AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0, sv) == -1) {
perrorf (g, "socketpair");
goto cleanup0;
}
@@ -327,15 +335,14 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
debug (g, "finished testing qemu features");
- /* Construct the qemu command line. We have to do this before
- * forking, because after fork we are not allowed to use
- * non-signal-safe functions such as malloc.
- */
-#define ADD_CMDLINE(str) \
- guestfs_int_add_string (g, &cmdline, (str))
-#define ADD_CMDLINE_STRING_NODUP(str) \
+/* Construct the qemu command line. We have to do this before
+ * forking, because after fork we are not allowed to use
+ * non-signal-safe functions such as malloc.
+ */
+#define ADD_CMDLINE(str) guestfs_int_add_string (g, &cmdline, (str))
+#define ADD_CMDLINE_STRING_NODUP(str) \
guestfs_int_add_string_nodup (g, &cmdline, (str))
-#define ADD_CMDLINE_PRINTF(fs,...) \
+#define ADD_CMDLINE_PRINTF(fs, ...) \
guestfs_int_add_sprintf (g, &cmdline, (fs), ##__VA_ARGS__)
ADD_CMDLINE (g->hv);
@@ -379,28 +386,29 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
if (guestfs_int_get_backend_setting_bool (g, "gdb") > 0) {
ADD_CMDLINE ("-S");
ADD_CMDLINE ("-s");
- warning (g, "qemu debugging is enabled, connect gdb to tcp::1234 to
begin");
+ warning (
+ g, "qemu debugging is enabled, connect gdb to tcp::1234 to begin");
}
ADD_CMDLINE ("-machine");
if (!force_tcg)
ADD_CMDLINE (
#ifdef MACHINE_TYPE
- MACHINE_TYPE ","
+ MACHINE_TYPE ","
#endif
#ifdef __aarch64__
- "gic-version=host,"
+ "gic-version=host,"
#endif
- "accel=kvm:tcg");
+ "accel=kvm:tcg");
else
ADD_CMDLINE (
#ifdef MACHINE_TYPE
- MACHINE_TYPE ","
+ MACHINE_TYPE ","
#endif
#ifdef __aarch64__
- "gic-version=host,"
+ "gic-version=host,"
#endif
- "accel=tcg");
+ "accel=tcg");
cpu_model = guestfs_int_get_cpu_model (has_kvm && !force_tcg);
if (cpu_model) {
@@ -472,12 +480,14 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
ADD_CMDLINE (VIRTIO_SCSI ",id=scsi");
}
- ITER_DRIVES (g, i, drv) {
+ ITER_DRIVES (g, i, drv)
+ {
CLEANUP_FREE char *file = NULL, *escaped_file = NULL, *param = NULL;
if (!drv->overlay) {
const char *discard_mode = "";
- int major = data->qemu_version_major, minor = data->qemu_version_minor;
+ int major = data->qemu_version_major,
+ minor = data->qemu_version_minor;
unsigned long qemu_version = major * 1000000 + minor * 1000;
switch (drv->discard) {
@@ -490,7 +500,7 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
case discard_enable:
if (!guestfs_int_discard_possible (g, drv, qemu_version))
goto cleanup0;
- /*FALLTHROUGH*/
+ /*FALLTHROUGH*/
case discard_besteffort:
/* I believe from reading the code that this is always safe as
* long as qemu >= 1.5.
@@ -507,28 +517,23 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
/* Make the first part of the -drive parameter, everything up to
* the if=... at the end.
*/
- param = safe_asprintf
- (g, "file=%s%s,cache=%s%s%s%s%s%s%s,id=hd%zu",
- escaped_file,
- drv->readonly ? ",snapshot=on" : "",
- drv->cachemode ? drv->cachemode : "writeback",
- discard_mode,
- drv->src.format ? ",format=" : "",
- drv->src.format ? drv->src.format : "",
- drv->disk_label ? ",serial=" : "",
- drv->disk_label ? drv->disk_label : "",
- drv->copyonread ? ",copy-on-read=on" : "",
- i);
+ param =
+ safe_asprintf (g, "file=%s%s,cache=%s%s%s%s%s%s%s,id=hd%zu",
+ escaped_file, drv->readonly ? ",snapshot=on" :
"",
+ drv->cachemode ? drv->cachemode : "writeback",
+ discard_mode, drv->src.format ? ",format=" :
"",
+ drv->src.format ? drv->src.format : "",
+ drv->disk_label ? ",serial=" : "",
+ drv->disk_label ? drv->disk_label : "",
+ drv->copyonread ? ",copy-on-read=on" : "",
i);
}
else {
/* Writable qcow2 overlay on top of read-only drive. */
escaped_file = qemu_escape_param (g, drv->overlay);
- param = safe_asprintf
- (g, "file=%s,cache=unsafe,format=qcow2%s%s,id=hd%zu",
- escaped_file,
- drv->disk_label ? ",serial=" : "",
- drv->disk_label ? drv->disk_label : "",
- i);
+ param =
+ safe_asprintf (g, "file=%s,cache=unsafe,format=qcow2%s%s,id=hd%zu",
+ escaped_file, drv->disk_label ? ",serial=" :
"",
+ drv->disk_label ? drv->disk_label : "", i);
}
/* If there's an explicit 'iface', use it. Otherwise default to
@@ -564,8 +569,8 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
/* Add the ext2 appliance drive (after all the drives). */
if (has_appliance_drive) {
ADD_CMDLINE ("-drive");
- ADD_CMDLINE_PRINTF
("file=%s,snapshot=on,id=appliance,cache=unsafe,if=none",
- appliance);
+ ADD_CMDLINE_PRINTF (
+ "file=%s,snapshot=on,id=appliance,cache=unsafe,if=none", appliance);
if (virtio_scsi) {
ADD_CMDLINE ("-device");
@@ -603,7 +608,8 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
ADD_CMDLINE ("-chardev");
ADD_CMDLINE_PRINTF ("socket,path=%s,id=channel0", data->guestfsd_sock);
ADD_CMDLINE ("-device");
- ADD_CMDLINE
("virtserialport,chardev=channel0,name=org.libguestfs.channel.0");
+ ADD_CMDLINE (
+ "virtserialport,chardev=channel0,name=org.libguestfs.channel.0");
/* Enable user networking. */
if (g->enable_network) {
@@ -617,16 +623,16 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
flags = 0;
if (!has_kvm || force_tcg)
flags |= APPLIANCE_COMMAND_LINE_IS_TCG;
- ADD_CMDLINE_STRING_NODUP (guestfs_int_appliance_command_line (g, appliance_dev,
- flags));
+ ADD_CMDLINE_STRING_NODUP (
+ guestfs_int_appliance_command_line (g, appliance_dev, flags));
- /* Note: custom command line parameters must come last so that
- * qemu -set parameters can modify previously added options.
- */
+/* Note: custom command line parameters must come last so that
+ * qemu -set parameters can modify previously added options.
+ */
- /* Add the extra options for the qemu command line specified
- * at configure time.
- */
+/* Add the extra options for the qemu command line specified
+ * at configure time.
+ */
#ifdef QEMU_OPTIONS
if (STRNEQ (QEMU_OPTIONS, ""))
add_cmdline_shell_unquoted (g, &cmdline, QEMU_OPTIONS);
@@ -652,7 +658,7 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
goto cleanup0;
}
- if (r == 0) { /* Child (qemu). */
+ if (r == 0) { /* Child (qemu). */
if (!g->direct_mode) {
/* Set up stdin, stdout, stderr. */
close (0);
@@ -702,7 +708,8 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
setpgid (0, 0);
setenv ("LC_ALL", "C", 1);
- setenv ("QEMU_AUDIO_DRV", "none", 1); /* Prevents qemu opening
/dev/dsp */
+ setenv ("QEMU_AUDIO_DRV", "none",
+ 1); /* Prevents qemu opening /dev/dsp */
TRACE0 (launch_run_qemu);
@@ -760,7 +767,8 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
* effectively polling. Is the cure worse than the disease?
*/
for (;;) {
- if (kill (qemu_pid, 0) == -1) /* qemu's gone away, we aren't needed */
+ if (kill (qemu_pid, 0) ==
+ -1) /* qemu's gone away, we aren't needed */
_exit (EXIT_SUCCESS);
if (kill (parent_pid, 0) == -1) {
/* Parent's gone away, qemu still around, so kill qemu. */
@@ -781,7 +789,7 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
/* Close the other end of the socketpair. */
close (sv[1]);
- console_sock = sv[0]; /* stdin of child */
+ console_sock = sv[0]; /* stdin of child */
sv[0] = -1;
}
@@ -790,8 +798,8 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
/* Wait for qemu to start and to connect back to us via
* virtio-serial and send the GUESTFS_LAUNCH_FLAG message.
*/
- g->conn =
- guestfs_int_new_conn_socket_listening (g, daemon_accept_sock, console_sock);
+ g->conn = guestfs_int_new_conn_socket_listening (g, daemon_accept_sock,
+ console_sock);
if (!g->conn)
goto cleanup1;
@@ -846,18 +854,22 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
return 0;
- cleanup1:
+cleanup1:
if (!g->direct_mode && sv[0] >= 0)
close (sv[0]);
- if (data->pid > 0) kill (data->pid, 9);
- if (data->recoverypid > 0) kill (data->recoverypid, 9);
- if (data->pid > 0) waitpid (data->pid, NULL, 0);
- if (data->recoverypid > 0) waitpid (data->recoverypid, NULL, 0);
+ if (data->pid > 0)
+ kill (data->pid, 9);
+ if (data->recoverypid > 0)
+ kill (data->recoverypid, 9);
+ if (data->pid > 0)
+ waitpid (data->pid, NULL, 0);
+ if (data->recoverypid > 0)
+ waitpid (data->recoverypid, NULL, 0);
data->pid = 0;
data->recoverypid = 0;
memset (&g->launch_t, 0, sizeof g->launch_t);
- cleanup0:
+cleanup0:
if (daemon_accept_sock >= 0)
close (daemon_accept_sock);
if (console_sock >= 0)
@@ -887,7 +899,8 @@ make_appliance_dev (guestfs_h *g, int virtio_scsi)
char dev[64] = "/dev/Xd";
/* Calculate the index of the drive. */
- ITER_DRIVES (g, i, drv) {
+ ITER_DRIVES (g, i, drv)
+ {
if (virtio_scsi) {
if (drv->iface == NULL || STREQ (drv->iface, "ide"))
index++;
@@ -901,7 +914,7 @@ make_appliance_dev (guestfs_h *g, int virtio_scsi)
dev[5] = virtio_scsi ? 's' : 'v';
guestfs_int_drive_name (index, &dev[7]);
- return safe_strdup (g, dev); /* Caller frees. */
+ return safe_strdup (g, dev); /* Caller frees. */
}
/* This is called from the forked subprocess just before qemu runs, so
@@ -923,22 +936,27 @@ print_qemu_command_line (guestfs_h *g, char **argv)
if (argv[i][0] == '-') /* -option starts a new line */
fprintf (stderr, " \\\n ");
- if (i > 0) fputc (' ', stderr);
+ if (i > 0)
+ fputc (' ', stderr);
/* Does it need shell quoting? This only deals with simple cases. */
needs_quote = strcspn (argv[i], " ") != strlen (argv[i]);
- if (needs_quote) fputc ('\'', stderr);
+ if (needs_quote)
+ fputc ('\'', stderr);
fprintf (stderr, "%s", argv[i]);
- if (needs_quote) fputc ('\'', stderr);
+ if (needs_quote)
+ fputc ('\'', stderr);
i++;
}
fputc ('\n', stderr);
}
-static void parse_qemu_version (guestfs_h *g, struct backend_direct_data *data);
-static void read_all (guestfs_h *g, void *retv, const char *buf, size_t len);
+static void parse_qemu_version (guestfs_h *g,
+ struct backend_direct_data *data);
+static void read_all (guestfs_h *g, void *retv, const char *buf,
+ size_t len);
/* Test qemu binary (or wrapper) runs, and do 'qemu -help' so we know
* the version of qemu what options this qemu supports.
@@ -960,7 +978,7 @@ test_qemu (guestfs_h *g, struct backend_direct_data *data)
guestfs_int_cmd_add_arg (cmd1, "none");
guestfs_int_cmd_add_arg (cmd1, "-help");
guestfs_int_cmd_set_stdout_callback (cmd1, read_all, &data->qemu_help,
- CMD_STDOUT_FLAG_WHOLE_BUFFER);
+ CMD_STDOUT_FLAG_WHOLE_BUFFER);
r = guestfs_int_cmd_run (cmd1);
if (r == -1 || !WIFEXITED (r) || WEXITSTATUS (r) != 0)
goto error;
@@ -975,20 +993,20 @@ test_qemu (guestfs_h *g, struct backend_direct_data *data)
#ifdef MACHINE_TYPE
MACHINE_TYPE ","
#endif
- "accel=kvm:tcg");
+ "accel=kvm:tcg");
guestfs_int_cmd_add_arg (cmd2, "-device");
guestfs_int_cmd_add_arg (cmd2, "?");
guestfs_int_cmd_clear_capture_errors (cmd2);
guestfs_int_cmd_set_stderr_to_stdout (cmd2);
guestfs_int_cmd_set_stdout_callback (cmd2, read_all, &data->qemu_devices,
- CMD_STDOUT_FLAG_WHOLE_BUFFER);
+ CMD_STDOUT_FLAG_WHOLE_BUFFER);
r = guestfs_int_cmd_run (cmd2);
if (r == -1 || !WIFEXITED (r) || WEXITSTATUS (r) != 0)
goto error;
return 0;
- error:
+error:
if (r == -1)
return -1;
@@ -1014,7 +1032,9 @@ parse_qemu_version (guestfs_h *g, struct backend_direct_data *data)
if (!match2 (g, data->qemu_help, re_major_minor, &major_s, &minor_s)) {
parse_failed:
- debug (g, "%s: failed to parse qemu version string from the first line of the
output of '%s -help'. When reporting this bug please include the -help
output.",
+ debug (g, "%s: failed to parse qemu version string from the first line "
+ "of the output of '%s -help'. When reporting this bug "
+ "please include the -help output.",
__func__, g->hv);
return;
}
@@ -1112,7 +1132,7 @@ qemu_supports_virtio_scsi (guestfs_h *g, struct backend_direct_data
*data)
if (!data->qemu_help) {
if (test_qemu (g, data) == -1)
- return 0; /* safe option? */
+ return 0; /* safe option? */
}
/* data->virtio_scsi has these values:
@@ -1147,7 +1167,7 @@ qemu_escape_param (guestfs_h *g, const char *param)
size_t i, len = strlen (param);
char *p, *ret;
- ret = p = safe_malloc (g, len*2 + 1); /* max length of escaped name*/
+ ret = p = safe_malloc (g, len * 2 + 1); /* max length of escaped name*/
for (i = 0; i < len; ++i) {
*p++ = param[i];
if (param[i] == ',')
@@ -1160,11 +1180,10 @@ qemu_escape_param (guestfs_h *g, const char *param)
static char *
make_uri (guestfs_h *g, const char *scheme, const char *user,
- const char *password,
- struct drive_server *server, const char *path)
+ const char *password, struct drive_server *server,
+ const char *path)
{
- xmlURI uri = { .scheme = (char *) scheme,
- .user = (char *) user };
+ xmlURI uri = {.scheme = (char *)scheme, .user = (char *)user };
CLEANUP_FREE char *query = NULL;
CLEANUP_FREE char *pathslash = NULL;
CLEANUP_FREE char *userauth = NULL;
@@ -1175,11 +1194,12 @@ make_uri (guestfs_h *g, const char *scheme, const char *user,
uri.path = pathslash;
}
else
- uri.path = (char *) path;
+ uri.path = (char *)path;
/* Rebuild user:password. */
if (user != NULL && password != NULL) {
- /* Keep the string in an own variable so it can be freed automatically. */
+ /* Keep the string in an own variable so it can be freed automatically.
+ */
userauth = safe_asprintf (g, "%s:%s", user, password);
uri.user = userauth;
}
@@ -1196,7 +1216,7 @@ make_uri (guestfs_h *g, const char *scheme, const char *user,
break;
}
- return (char *) xmlSaveUri (&uri);
+ return (char *)xmlSaveUri (&uri);
}
/* Useful function to format a drive + protocol for qemu. Also shared
@@ -1207,7 +1227,8 @@ make_uri (guestfs_h *g, const char *scheme, const char *user,
* part of a full -drive parameter (but not for qemu-img).
*/
char *
-guestfs_int_drive_source_qemu_param (guestfs_h *g, const struct drive_source *src)
+guestfs_int_drive_source_qemu_param (guestfs_h *g,
+ const struct drive_source *src)
{
char *path;
@@ -1229,8 +1250,8 @@ guestfs_int_drive_source_qemu_param (guestfs_h *g, const struct
drive_source *sr
return path;
case drive_protocol_ftp:
- return make_uri (g, "ftp", src->username, src->secret,
- &src->servers[0], src->u.exportname);
+ return make_uri (g, "ftp", src->username, src->secret,
&src->servers[0],
+ src->u.exportname);
case drive_protocol_ftps:
return make_uri (g, "ftps", src->username, src->secret,
@@ -1239,14 +1260,14 @@ guestfs_int_drive_source_qemu_param (guestfs_h *g, const struct
drive_source *sr
case drive_protocol_gluster:
switch (src->servers[0].transport) {
case drive_transport_none:
- return make_uri (g, "gluster", NULL, NULL,
- &src->servers[0], src->u.exportname);
+ return make_uri (g, "gluster", NULL, NULL, &src->servers[0],
+ src->u.exportname);
case drive_transport_tcp:
- return make_uri (g, "gluster+tcp", NULL, NULL,
- &src->servers[0], src->u.exportname);
+ return make_uri (g, "gluster+tcp", NULL, NULL, &src->servers[0],
+ src->u.exportname);
case drive_transport_unix:
- return make_uri (g, "gluster+unix", NULL, NULL,
- &src->servers[0], NULL);
+ return make_uri (g, "gluster+unix", NULL, NULL, &src->servers[0],
+ NULL);
}
case drive_protocol_http:
@@ -1264,22 +1285,20 @@ guestfs_int_drive_source_qemu_param (guestfs_h *g, const struct
drive_source *sr
char port_str[16];
char *ret;
- escaped_hostname =
- (char *) xmlURIEscapeStr(BAD_CAST src->servers[0].u.hostname,
- BAD_CAST "");
+ escaped_hostname = (char *)xmlURIEscapeStr (
+ BAD_CAST src->servers[0].u.hostname, BAD_CAST "");
/* The target string must keep slash as it is, as exportname contains
* "iqn/lun".
*/
escaped_target =
- (char *) xmlURIEscapeStr(BAD_CAST src->u.exportname, BAD_CAST "/");
+ (char *)xmlURIEscapeStr (BAD_CAST src->u.exportname, BAD_CAST "/");
if (src->username != NULL && src->secret != NULL)
userauth = safe_asprintf (g, "%s%%%s@", src->username,
src->secret);
if (src->servers[0].port != 0)
snprintf (port_str, sizeof port_str, ":%d", src->servers[0].port);
ret = safe_asprintf (g, "iscsi://%s%s%s/%s",
- userauth != NULL ? userauth : "",
- escaped_hostname,
+ userauth != NULL ? userauth : "", escaped_hostname,
src->servers[0].port != 0 ? port_str : "",
escaped_target);
@@ -1293,8 +1312,8 @@ guestfs_int_drive_source_qemu_param (guestfs_h *g, const struct
drive_source *sr
switch (src->servers[0].transport) {
case drive_transport_none:
case drive_transport_tcp:
- p = safe_asprintf (g, "nbd:%s:%d",
- src->servers[0].u.hostname, src->servers[0].port);
+ p = safe_asprintf (g, "nbd:%s:%d", src->servers[0].u.hostname,
+ src->servers[0].port);
break;
case drive_transport_unix:
p = safe_asprintf (g, "nbd:unix:%s", src->servers[0].u.socket);
@@ -1352,26 +1371,24 @@ guestfs_int_drive_source_qemu_param (guestfs_h *g, const struct
drive_source *sr
else
auth = ":auth_supported=none";
- return safe_asprintf (g, "rbd:%s%s%s%s%s%s",
- src->u.exportname,
+ return safe_asprintf (g, "rbd:%s%s%s%s%s%s", src->u.exportname,
src->nr_servers > 0 ? ":mon_host=" :
"",
src->nr_servers > 0 ? mon_host : "",
- username ? username : "",
- auth,
+ username ? username : "", auth,
secret ? secret : "");
}
case drive_protocol_sheepdog:
if (src->nr_servers == 0)
return safe_asprintf (g, "sheepdog:%s", src->u.exportname);
- else /* XXX How to pass multiple hosts? */
+ else /* XXX How to pass multiple hosts? */
return safe_asprintf (g, "sheepdog:%s:%d:%s",
- src->servers[0].u.hostname, src->servers[0].port,
- src->u.exportname);
+ src->servers[0].u.hostname,
+ src->servers[0].port, src->u.exportname);
case drive_protocol_ssh:
- return make_uri (g, "ssh", src->username, src->secret,
- &src->servers[0], src->u.exportname);
+ return make_uri (g, "ssh", src->username, src->secret,
&src->servers[0],
+ src->u.exportname);
case drive_protocol_tftp:
return make_uri (g, "tftp", src->username, src->secret,
@@ -1392,7 +1409,7 @@ guestfs_int_drive_source_qemu_param (guestfs_h *g, const struct
drive_source *sr
*/
bool
guestfs_int_discard_possible (guestfs_h *g, struct drive *drv,
- unsigned long qemu_version)
+ unsigned long qemu_version)
{
/* qemu >= 1.5. This was the first version that supported the
* discard option on -drive at all.
@@ -1404,18 +1421,16 @@ guestfs_int_discard_possible (guestfs_h *g, struct drive *drv,
bool qemu16 = qemu_version >= 1006000;
if (!qemu15)
- NOT_SUPPORTED (g, false,
- _("discard cannot be enabled on this drive: "
- "qemu < 1.5"));
+ NOT_SUPPORTED (g, false, _("discard cannot be enabled on this drive: "
+ "qemu < 1.5"));
/* If it's an overlay, discard is not possible (on the underlying
* file). This has probably been caught earlier since we already
* checked that the drive is !readonly. Nevertheless ...
*/
if (drv->overlay)
- NOT_SUPPORTED (g, false,
- _("discard cannot be enabled on this drive: "
- "the drive has a read-only overlay"));
+ NOT_SUPPORTED (g, false, _("discard cannot be enabled on this drive: "
+ "the drive has a read-only overlay"));
/* Look at the source format. */
if (drv->src.format == NULL) {
@@ -1425,7 +1440,7 @@ guestfs_int_discard_possible (guestfs_h *g, struct drive *drv,
"you have to specify the format of the file"));
}
else if (STREQ (drv->src.format, "raw"))
- /* OK */ ;
+ /* OK */;
else if (STREQ (drv->src.format, "qcow2")) {
if (!qemu16)
NOT_SUPPORTED (g, false,
@@ -1436,14 +1451,14 @@ guestfs_int_discard_possible (guestfs_h *g, struct drive *drv,
/* It's possible in future other formats will support discard, but
* currently (qemu 1.7) none of them do.
*/
- NOT_SUPPORTED (g, false,
- _("discard cannot be enabled on this drive: "
- "qemu does not support discard for '%s' format
files"),
- drv->src.format);
+ NOT_SUPPORTED (
+ g, false, _("discard cannot be enabled on this drive: "
+ "qemu does not support discard for '%s' format
files"),
+ drv->src.format);
}
switch (drv->src.protocol) {
- /* Protocols which support discard. */
+ /* Protocols which support discard. */
case drive_protocol_file:
case drive_protocol_gluster:
case drive_protocol_iscsi:
@@ -1452,17 +1467,17 @@ guestfs_int_discard_possible (guestfs_h *g, struct drive *drv,
case drive_protocol_sheepdog: /* XXX depends on server version */
break;
- /* Protocols which don't support discard. */
+ /* Protocols which don't support discard. */
case drive_protocol_ftp:
case drive_protocol_ftps:
case drive_protocol_http:
case drive_protocol_https:
case drive_protocol_ssh:
case drive_protocol_tftp:
- NOT_SUPPORTED (g, -1,
- _("discard cannot be enabled on this drive: "
- "protocol '%s' does not support discard"),
- guestfs_int_drive_protocol_to_string (drv->src.protocol));
+ NOT_SUPPORTED (
+ g, -1, _("discard cannot be enabled on this drive: "
+ "protocol '%s' does not support discard"),
+ guestfs_int_drive_protocol_to_string (drv->src.protocol));
}
return true;
@@ -1480,7 +1495,8 @@ shutdown_direct (guestfs_h *g, void *datav, int check_for_errors)
debug (g, "sending SIGTERM to process %d", data->pid);
kill (data->pid, SIGTERM);
}
- if (data->recoverypid > 0) kill (data->recoverypid, 9);
+ if (data->recoverypid > 0)
+ kill (data->recoverypid, 9);
/* Wait for subprocess(es) to exit. */
if (g->recovery_proc /* RHBZ#998482 */ && data->pid > 0) {
@@ -1493,7 +1509,8 @@ shutdown_direct (guestfs_h *g, void *datav, int check_for_errors)
ret = -1;
}
}
- if (data->recoverypid > 0) waitpid (data->recoverypid, NULL, 0);
+ if (data->recoverypid > 0)
+ waitpid (data->recoverypid, NULL, 0);
data->pid = data->recoverypid = 0;
@@ -1532,7 +1549,7 @@ max_disks_direct (guestfs_h *g, void *datav)
if (qemu_supports_virtio_scsi (g, data))
return 255;
else
- return 27; /* conservative estimate */
+ return 27; /* conservative estimate */
}
static struct backend_ops backend_direct_ops = {
diff --git a/src/launch-libvirt.c b/src/launch-libvirt.c
index 7331acc..bc0f7f2 100644
--- a/src/launch-libvirt.c
+++ b/src/launch-libvirt.c
@@ -31,7 +31,7 @@
#include <assert.h>
#include <string.h>
#include <libintl.h>
-#include <sys/un.h> /* sockaddr_un */
+#include <sys/un.h> /* sockaddr_un */
#ifdef HAVE_LIBVIRT
#include <libvirt/virterror.h>
@@ -53,10 +53,10 @@
/* Fixes for Mac OS X */
#ifndef SOCK_CLOEXEC
-# define SOCK_CLOEXEC O_CLOEXEC
+#define SOCK_CLOEXEC O_CLOEXEC
#endif
#ifndef SOCK_NONBLOCK
-# define SOCK_NONBLOCK O_NONBLOCK
+#define SOCK_NONBLOCK O_NONBLOCK
#endif
/* End of fixes for Mac OS X */
@@ -86,12 +86,13 @@ xmlBufferDetach (xmlBufferPtr buf)
#endif
#ifdef HAVE_ATTRIBUTE_CLEANUP
-#define CLEANUP_VIRSECRETFREE __attribute__((cleanup(cleanup_virSecretFree)))
+#define CLEANUP_VIRSECRETFREE \
+ __attribute__((cleanup (cleanup_virSecretFree)))
static void
cleanup_virSecretFree (void *ptr)
{
- virSecretPtr secret_obj = * (virSecretPtr *) ptr;
+ virSecretPtr secret_obj = *(virSecretPtr *)ptr;
if (secret_obj)
virSecretFree (secret_obj);
}
@@ -106,22 +107,22 @@ struct secret {
char uuid[VIR_UUID_STRING_BUFLEN];
};
-#define DOMAIN_NAME_LEN (8+16+1) /* "guestfs-" + random + \0 */
+#define DOMAIN_NAME_LEN (8 + 16 + 1) /* "guestfs-" + random + \0 */
/* Per-handle data. */
struct backend_libvirt_data {
- virConnectPtr conn; /* libvirt connection */
- virDomainPtr dom; /* libvirt domain */
+ virConnectPtr conn; /* libvirt connection */
+ virDomainPtr dom; /* libvirt domain */
char *selinux_label;
char *selinux_imagelabel;
bool selinux_norelabel_disks;
char *network_bridge;
- char name[DOMAIN_NAME_LEN]; /* random name */
- bool is_kvm; /* false = qemu, true = kvm (from capabilities)*/
- unsigned long qemu_version; /* qemu version (from libvirt) */
- struct secret *secrets; /* list of secrets */
+ char name[DOMAIN_NAME_LEN]; /* random name */
+ bool is_kvm; /* false = qemu, true = kvm (from capabilities)*/
+ unsigned long qemu_version; /* qemu version (from libvirt) */
+ struct secret *secrets; /* list of secrets */
size_t nr_secrets;
- char *uefi_code; /* UEFI (firmware) code and variables. */
+ char *uefi_code; /* UEFI (firmware) code and variables. */
char *uefi_vars;
char guestfsd_path[UNIX_PATH_MAX]; /* paths to sockets */
char console_path[UNIX_PATH_MAX];
@@ -132,24 +133,36 @@ struct backend_libvirt_data {
*/
struct libvirt_xml_params {
struct backend_libvirt_data *data;
- char *kernel; /* paths to kernel and initrd */
+ char *kernel; /* paths to kernel and initrd */
char *initrd;
- char *appliance_overlay; /* path to qcow2 overlay backed by appliance */
- char appliance_dev[64]; /* appliance device name */
- size_t appliance_index; /* index of appliance */
- bool enable_svirt; /* false if we decided to disable sVirt */
- bool current_proc_is_root; /* true = euid is root */
+ char *appliance_overlay; /* path to qcow2 overlay backed by appliance */
+ char appliance_dev[64]; /* appliance device name */
+ size_t appliance_index; /* index of appliance */
+ bool enable_svirt; /* false if we decided to disable sVirt */
+ bool current_proc_is_root; /* true = euid is root */
};
-static int parse_capabilities (guestfs_h *g, const char *capabilities_xml, struct
backend_libvirt_data *data);
-static int add_secret (guestfs_h *g, virConnectPtr conn, struct backend_libvirt_data
*data, const struct drive *drv);
-static int find_secret (guestfs_h *g, const struct backend_libvirt_data *data, const
struct drive *drv, const char **type, const char **uuid);
-static int have_secret (guestfs_h *g, const struct backend_libvirt_data *data, const
struct drive *drv);
-static xmlChar *construct_libvirt_xml (guestfs_h *g, const struct libvirt_xml_params
*params);
+static int parse_capabilities (guestfs_h *g, const char *capabilities_xml,
+ struct backend_libvirt_data *data);
+static int add_secret (guestfs_h *g, virConnectPtr conn,
+ struct backend_libvirt_data *data,
+ const struct drive *drv);
+static int find_secret (guestfs_h *g,
+ const struct backend_libvirt_data *data,
+ const struct drive *drv, const char **type,
+ const char **uuid);
+static int have_secret (guestfs_h *g,
+ const struct backend_libvirt_data *data,
+ const struct drive *drv);
+static xmlChar *
+construct_libvirt_xml (guestfs_h *g,
+ const struct libvirt_xml_params *params);
static void debug_appliance_permissions (guestfs_h *g);
static void debug_socket_permissions (guestfs_h *g);
-static void libvirt_error (guestfs_h *g, const char *fs, ...) __attribute__((format
(printf,2,3)));
-static void libvirt_debug (guestfs_h *g, const char *fs, ...) __attribute__((format
(printf,2,3)));
+static void libvirt_error (guestfs_h *g, const char *fs, ...)
+ __attribute__((format (printf, 2, 3)));
+static void libvirt_debug (guestfs_h *g, const char *fs, ...)
+ __attribute__((format (printf, 2, 3)));
static int is_custom_hv (guestfs_h *g);
static int is_blk (const char *path);
static void ignore_errors (void *ignore, virErrorPtr ignore2);
@@ -158,7 +171,8 @@ static void clear_socket_create_context (guestfs_h *g);
static int check_bridge_exists (guestfs_h *g, const char *brname);
#if HAVE_LIBSELINUX
-static void selinux_warning (guestfs_h *g, const char *func, const char *selinux_op,
const char *data);
+static void selinux_warning (guestfs_h *g, const char *func,
+ const char *selinux_op, const char *data);
#endif
static char *
@@ -216,10 +230,10 @@ create_cow_overlay_libvirt (guestfs_h *g, void *datav, struct drive
*drv)
guestfs_pop_error_handler (g);
if (data->selinux_imagelabel) {
- debug (g, "setting SELinux label on %s to %s",
- overlay, data->selinux_imagelabel);
+ debug (g, "setting SELinux label on %s to %s", overlay,
+ data->selinux_imagelabel);
if (setfilecon (overlay,
- (security_context_t) data->selinux_imagelabel) == -1)
+ (security_context_t)data->selinux_imagelabel) == -1)
selinux_warning (g, __func__, "setfilecon", overlay);
}
#endif
@@ -240,10 +254,7 @@ launch_libvirt (guestfs_h *g, void *datav, const char *libvirt_uri)
virDomainPtr dom = NULL;
CLEANUP_FREE char *capabilities_xml = NULL;
struct libvirt_xml_params params = {
- .data = data,
- .kernel = NULL,
- .initrd = NULL,
- .appliance_overlay = NULL,
+ .data = data, .kernel = NULL, .initrd = NULL, .appliance_overlay = NULL,
};
CLEANUP_FREE xmlChar *xml = NULL;
CLEANUP_FREE char *appliance = NULL;
@@ -258,13 +269,13 @@ launch_libvirt (guestfs_h *g, void *datav, const char *libvirt_uri)
/* XXX: It should be possible to make this work. */
if (g->direct_mode) {
- error (g, _("direct mode flag is not supported yet for libvirt backend"));
+ error (g,
+ _("direct mode flag is not supported yet for libvirt backend"));
return -1;
}
virGetVersion (&version, NULL, NULL);
- debug (g, "libvirt version = %lu (%lu.%lu.%lu)",
- version,
+ debug (g, "libvirt version = %lu (%lu.%lu.%lu)", version,
version / 1000000UL, version / 1000UL % 1000UL, version % 1000UL);
if (version < MIN_LIBVIRT_VERSION) {
error (g, _("you must have libvirt >= %d.%d.%d "
@@ -289,12 +300,13 @@ launch_libvirt (guestfs_h *g, void *datav, const char *libvirt_uri)
debug (g, "connect to libvirt");
/* Decode the URI string. */
- if (!libvirt_uri) { /* "libvirt" */
+ if (!libvirt_uri) { /* "libvirt" */
if (!params.current_proc_is_root)
libvirt_uri = "qemu:///session";
else
libvirt_uri = "qemu:///system";
- } else if (STREQ (libvirt_uri, "null")) { /* libvirt:null */
+ }
+ else if (STREQ (libvirt_uri, "null")) { /* libvirt:null */
libvirt_uri = NULL;
} /* else nothing */
@@ -302,7 +314,7 @@ launch_libvirt (guestfs_h *g, void *datav, const char *libvirt_uri)
conn = guestfs_int_open_libvirt_connection (g, libvirt_uri, 0);
if (!conn) {
libvirt_error (g, _("could not connect to libvirt (URI = %s)"),
- libvirt_uri ? : "NULL");
+ libvirt_uri ?: "NULL");
goto cleanup;
}
@@ -315,8 +327,7 @@ launch_libvirt (guestfs_h *g, void *datav, const char *libvirt_uri)
/* Get hypervisor (hopefully qemu) version. */
if (virConnectGetVersion (conn, &data->qemu_version) == 0) {
debug (g, "qemu version (reported by libvirt) = %lu (%lu.%lu.%lu)",
- data->qemu_version,
- data->qemu_version / 1000000UL,
+ data->qemu_version, data->qemu_version / 1000000UL,
data->qemu_version / 1000UL % 1000UL,
data->qemu_version % 1000UL);
}
@@ -354,8 +365,8 @@ launch_libvirt (guestfs_h *g, void *datav, const char *libvirt_uri)
free (data->selinux_imagelabel);
data->selinux_imagelabel =
guestfs_get_backend_setting (g, "internal_libvirt_imagelabel");
- data->selinux_norelabel_disks =
- guestfs_int_get_backend_setting_bool (g,
"internal_libvirt_norelabel_disks");
+ data->selinux_norelabel_disks = guestfs_int_get_backend_setting_bool (
+ g, "internal_libvirt_norelabel_disks");
if (g->enable_network) {
data->network_bridge =
guestfs_get_backend_setting (g, "network_bridge");
@@ -364,7 +375,8 @@ launch_libvirt (guestfs_h *g, void *datav, const char *libvirt_uri)
}
guestfs_pop_error_handler (g);
- if (g->enable_network && check_bridge_exists (g, data->network_bridge) ==
-1)
+ if (g->enable_network &&
+ check_bridge_exists (g, data->network_bridge) == -1)
goto cleanup;
/* Locate and/or build the appliance. */
@@ -397,7 +409,7 @@ launch_libvirt (guestfs_h *g, void *datav, const char *libvirt_uri)
set_socket_create_context (g);
- daemon_accept_sock = socket (AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0);
+ daemon_accept_sock = socket (AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
if (daemon_accept_sock == -1) {
perrorf (g, "socket");
goto cleanup;
@@ -406,8 +418,8 @@ launch_libvirt (guestfs_h *g, void *datav, const char *libvirt_uri)
addr.sun_family = AF_UNIX;
memcpy (addr.sun_path, data->guestfsd_path, UNIX_PATH_MAX);
- if (bind (daemon_accept_sock, (struct sockaddr *) &addr,
- sizeof addr) == -1) {
+ if (bind (daemon_accept_sock, (struct sockaddr *)&addr, sizeof addr) ==
+ -1) {
perrorf (g, "bind");
goto cleanup;
}
@@ -422,7 +434,7 @@ launch_libvirt (guestfs_h *g, void *datav, const char *libvirt_uri)
&data->console_path) == -1)
goto cleanup;
- console_sock = socket (AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0);
+ console_sock = socket (AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
if (console_sock == -1) {
perrorf (g, "socket");
goto cleanup;
@@ -431,7 +443,7 @@ launch_libvirt (guestfs_h *g, void *datav, const char *libvirt_uri)
addr.sun_family = AF_UNIX;
memcpy (addr.sun_path, data->console_path, UNIX_PATH_MAX);
- if (bind (console_sock, (struct sockaddr *) &addr, sizeof addr) == -1) {
+ if (bind (console_sock, (struct sockaddr *)&addr, sizeof addr) == -1) {
perrorf (g, "bind");
goto cleanup;
}
@@ -486,14 +498,16 @@ launch_libvirt (guestfs_h *g, void *datav, const char *libvirt_uri)
perrorf (g, "chown: %s", data->console_path);
goto cleanup;
}
- } else
+ }
+ else
debug (g, "cannot find group 'qemu'");
}
/* Store any secrets in libvirtd, keeping a mapping from the secret
* to its UUID.
*/
- ITER_DRIVES (g, i, drv) {
+ ITER_DRIVES (g, i, drv)
+ {
if (add_secret (g, conn, data, drv) == -1)
goto cleanup;
}
@@ -504,7 +518,7 @@ launch_libvirt (guestfs_h *g, void *datav, const char *libvirt_uri)
params.appliance_index = g->nr_drives;
strcpy (params.appliance_dev, "/dev/sd");
guestfs_int_drive_name (params.appliance_index, ¶ms.appliance_dev[7]);
- params.enable_svirt = ! is_custom_hv (g);
+ params.enable_svirt = !is_custom_hv (g);
xml = construct_libvirt_xml (g, ¶ms);
if (!xml)
@@ -519,22 +533,23 @@ launch_libvirt (guestfs_h *g, void *datav, const char *libvirt_uri)
/* Launch the libvirt guest. */
debug (g, "launch libvirt guest");
- dom = virDomainCreateXML (conn, (char *) xml, VIR_DOMAIN_START_AUTODESTROY);
+ dom =
+ virDomainCreateXML (conn, (char *)xml, VIR_DOMAIN_START_AUTODESTROY);
if (!dom) {
- libvirt_error (g, _(
- "could not create appliance through libvirt.\n"
- "\n"
- "Try running qemu directly without libvirt using this environment
variable:\n"
- "export LIBGUESTFS_BACKEND=direct\n"
- "\n"
- "Original error from libvirt"));
+ libvirt_error (g, _("could not create appliance through libvirt.\n"
+ "\n"
+ "Try running qemu directly without libvirt using "
+ "this environment variable:\n"
+ "export LIBGUESTFS_BACKEND=direct\n"
+ "\n"
+ "Original error from libvirt"));
goto cleanup;
}
g->state = LAUNCHING;
/* Wait for console socket to be opened (by qemu). */
- r = accept4 (console_sock, NULL, NULL, SOCK_NONBLOCK|SOCK_CLOEXEC);
+ r = accept4 (console_sock, NULL, NULL, SOCK_NONBLOCK | SOCK_CLOEXEC);
if (r == -1) {
perrorf (g, "accept");
goto cleanup;
@@ -545,13 +560,13 @@ launch_libvirt (guestfs_h *g, void *datav, const char *libvirt_uri)
close (r);
goto cleanup;
}
- console_sock = r; /* This is the accepted console socket. */
+ console_sock = r; /* This is the accepted console socket. */
/* Wait for libvirt domain to start and to connect back to us via
* virtio-serial and send the GUESTFS_LAUNCH_FLAG message.
*/
- g->conn =
- guestfs_int_new_conn_socket_listening (g, daemon_accept_sock, console_sock);
+ g->conn = guestfs_int_new_conn_socket_listening (g, daemon_accept_sock,
+ console_sock);
if (!g->conn)
goto cleanup;
@@ -613,7 +628,7 @@ launch_libvirt (guestfs_h *g, void *datav, const char *libvirt_uri)
return 0;
- cleanup:
+cleanup:
clear_socket_create_context (g);
if (console_sock >= 0)
@@ -654,8 +669,8 @@ parse_capabilities (guestfs_h *g, const char *capabilities_xml,
size_t seen_qemu, seen_kvm;
int force_tcg;
- doc = xmlReadMemory (capabilities_xml, strlen (capabilities_xml),
- NULL, NULL, XML_PARSE_NONET);
+ doc = xmlReadMemory (capabilities_xml, strlen (capabilities_xml), NULL,
+ NULL, XML_PARSE_NONET);
if (doc == NULL) {
error (g, _("unable to parse capabilities XML returned by libvirt"));
return -1;
@@ -667,9 +682,9 @@ parse_capabilities (guestfs_h *g, const char *capabilities_xml,
return -1;
}
- /* This gives us a set of all the supported domain types.
- * XXX It ignores architecture, but let's not worry about that.
- */
+/* This gives us a set of all the supported domain types.
+ * XXX It ignores architecture, but let's not worry about that.
+ */
#define XPATH_EXPR "/capabilities/guest/arch/domain/@type"
xpathObj = xmlXPathEvalExpression (BAD_CAST XPATH_EXPR, xpathCtx);
if (xpathObj == NULL) {
@@ -682,7 +697,7 @@ parse_capabilities (guestfs_h *g, const char *capabilities_xml,
seen_qemu = seen_kvm = 0;
if (nodes != NULL) {
- for (i = 0; i < (size_t) nodes->nodeNr; ++i) {
+ for (i = 0; i < (size_t)nodes->nodeNr; ++i) {
CLEANUP_FREE char *type = NULL;
if (seen_qemu && seen_kvm)
@@ -690,8 +705,8 @@ parse_capabilities (guestfs_h *g, const char *capabilities_xml,
assert (nodes->nodeTab[i]);
assert (nodes->nodeTab[i]->type == XML_ATTRIBUTE_NODE);
- attr = (xmlAttrPtr) nodes->nodeTab[i];
- type = (char *) xmlNodeListGetString (doc, attr->children, 1);
+ attr = (xmlAttrPtr)nodes->nodeTab[i];
+ type = (char *)xmlNodeListGetString (doc, attr->children, 1);
if (STREQ (type, "qemu"))
seen_qemu++;
@@ -707,18 +722,20 @@ parse_capabilities (guestfs_h *g, const char *capabilities_xml,
if (!seen_qemu && !seen_kvm) {
CLEANUP_FREE char *backend = guestfs_get_backend (g);
- error (g,
- _("libvirt hypervisor doesn't support qemu or KVM,\n"
- "so we cannot create the libguestfs appliance.\n"
- "The current backend is '%s'.\n"
- "Check that the PATH environment variable is set and contains\n"
- "the path to the qemu ('qemu-system-*') or KVM
('qemu-kvm', 'kvm' etc).\n"
- "Or: try setting:\n"
- " export LIBGUESTFS_BACKEND=libvirt:qemu:///session\n"
- "Or: if you want to have libguestfs run qemu directly, try:\n"
- " export LIBGUESTFS_BACKEND=direct\n"
- "For further help, read the guestfs(3) man page and libguestfs
FAQ."),
- backend);
+ error (
+ g, _("libvirt hypervisor doesn't support qemu or KVM,\n"
+ "so we cannot create the libguestfs appliance.\n"
+ "The current backend is '%s'.\n"
+ "Check that the PATH environment variable is set and contains\n"
+ "the path to the qemu ('qemu-system-*') or KVM
('qemu-kvm', "
+ "'kvm' etc).\n"
+ "Or: try setting:\n"
+ " export LIBGUESTFS_BACKEND=libvirt:qemu:///session\n"
+ "Or: if you want to have libguestfs run qemu directly, try:\n"
+ " export LIBGUESTFS_BACKEND=direct\n"
+ "For further help, read the guestfs(3) man page and libguestfs "
+ "FAQ."),
+ backend);
return -1;
}
@@ -783,9 +800,9 @@ set_socket_create_context (guestfs_h *g)
goto out2;
}
- out2:
+out2:
context_free (con);
- out1:
+out1:
freecon (scon);
}
@@ -813,7 +830,8 @@ clear_socket_create_context (guestfs_h *g)
#endif /* !HAVE_LIBSELINUX */
static void
-debug_permissions_cb (guestfs_h *g, void *data, const char *line, size_t len)
+debug_permissions_cb (guestfs_h *g, void *data, const char *line,
+ size_t len)
{
debug (g, "%s", line);
}
@@ -825,8 +843,8 @@ debug_appliance_permissions (guestfs_h *g)
CLEANUP_FREE char *cachedir = guestfs_get_cachedir (g);
CLEANUP_FREE char *appliance = NULL;
- appliance = safe_asprintf (g, "%s/.guestfs-%ju",
- cachedir, (uintmax_t) geteuid ());
+ appliance =
+ safe_asprintf (g, "%s/.guestfs-%ju", cachedir, (uintmax_t)geteuid ());
guestfs_int_cmd_add_arg (cmd, "ls");
guestfs_int_cmd_add_arg (cmd, "-a");
@@ -849,26 +867,67 @@ debug_socket_permissions (guestfs_h *g)
guestfs_int_cmd_add_arg (cmd, "-l");
guestfs_int_cmd_add_arg (cmd, "-Z");
guestfs_int_cmd_add_arg (cmd, g->sockdir);
- guestfs_int_cmd_set_stdout_callback (cmd, debug_permissions_cb, NULL, 0);
+ guestfs_int_cmd_set_stdout_callback (cmd, debug_permissions_cb, NULL,
+ 0);
guestfs_int_cmd_run (cmd);
}
}
-static int construct_libvirt_xml_domain (guestfs_h *g, const struct libvirt_xml_params
*params, xmlTextWriterPtr xo);
-static int construct_libvirt_xml_name (guestfs_h *g, const struct libvirt_xml_params
*params, xmlTextWriterPtr xo);
-static int construct_libvirt_xml_cpu (guestfs_h *g, const struct libvirt_xml_params
*params, xmlTextWriterPtr xo);
-static int construct_libvirt_xml_boot (guestfs_h *g, const struct libvirt_xml_params
*params, xmlTextWriterPtr xo);
-static int construct_libvirt_xml_seclabel (guestfs_h *g, const struct libvirt_xml_params
*params, xmlTextWriterPtr xo);
-static int construct_libvirt_xml_lifecycle (guestfs_h *g, const struct libvirt_xml_params
*params, xmlTextWriterPtr xo);
-static int construct_libvirt_xml_devices (guestfs_h *g, const struct libvirt_xml_params
*params, xmlTextWriterPtr xo);
-static int construct_libvirt_xml_qemu_cmdline (guestfs_h *g, const struct
libvirt_xml_params *params, xmlTextWriterPtr xo);
-static int construct_libvirt_xml_disk (guestfs_h *g, const struct backend_libvirt_data
*data, xmlTextWriterPtr xo, struct drive *drv, size_t drv_index);
-static int construct_libvirt_xml_disk_target (guestfs_h *g, xmlTextWriterPtr xo, size_t
drv_index);
-static int construct_libvirt_xml_disk_driver_qemu (guestfs_h *g, const struct
backend_libvirt_data *data, struct drive *drv, xmlTextWriterPtr xo, const char *format,
const char *cachemode, enum discard discard, bool copyonread);
-static int construct_libvirt_xml_disk_address (guestfs_h *g, xmlTextWriterPtr xo, size_t
drv_index);
-static int construct_libvirt_xml_disk_source_hosts (guestfs_h *g, xmlTextWriterPtr xo,
const struct drive_source *src);
-static int construct_libvirt_xml_disk_source_seclabel (guestfs_h *g, const struct
backend_libvirt_data *data, xmlTextWriterPtr xo);
-static int construct_libvirt_xml_appliance (guestfs_h *g, const struct libvirt_xml_params
*params, xmlTextWriterPtr xo);
+static int
+construct_libvirt_xml_domain (guestfs_h *g,
+ const struct libvirt_xml_params *params,
+ xmlTextWriterPtr xo);
+static int
+construct_libvirt_xml_name (guestfs_h *g,
+ const struct libvirt_xml_params *params,
+ xmlTextWriterPtr xo);
+static int
+construct_libvirt_xml_cpu (guestfs_h *g,
+ const struct libvirt_xml_params *params,
+ xmlTextWriterPtr xo);
+static int
+construct_libvirt_xml_boot (guestfs_h *g,
+ const struct libvirt_xml_params *params,
+ xmlTextWriterPtr xo);
+static int
+construct_libvirt_xml_seclabel (guestfs_h *g,
+ const struct libvirt_xml_params *params,
+ xmlTextWriterPtr xo);
+static int
+construct_libvirt_xml_lifecycle (guestfs_h *g,
+ const struct libvirt_xml_params *params,
+ xmlTextWriterPtr xo);
+static int
+construct_libvirt_xml_devices (guestfs_h *g,
+ const struct libvirt_xml_params *params,
+ xmlTextWriterPtr xo);
+static int
+construct_libvirt_xml_qemu_cmdline (guestfs_h *g,
+ const struct libvirt_xml_params *params,
+ xmlTextWriterPtr xo);
+static int construct_libvirt_xml_disk (
+ guestfs_h *g, const struct backend_libvirt_data *data,
+ xmlTextWriterPtr xo, struct drive *drv, size_t drv_index);
+static int construct_libvirt_xml_disk_target (guestfs_h *g,
+ xmlTextWriterPtr xo,
+ size_t drv_index);
+static int construct_libvirt_xml_disk_driver_qemu (
+ guestfs_h *g, const struct backend_libvirt_data *data, struct drive *drv,
+ xmlTextWriterPtr xo, const char *format, const char *cachemode,
+ enum discard discard, bool copyonread);
+static int construct_libvirt_xml_disk_address (guestfs_h *g,
+ xmlTextWriterPtr xo,
+ size_t drv_index);
+static int
+construct_libvirt_xml_disk_source_hosts (guestfs_h *g, xmlTextWriterPtr xo,
+ const struct drive_source *src);
+static int construct_libvirt_xml_disk_source_seclabel (
+ guestfs_h *g, const struct backend_libvirt_data *data,
+ xmlTextWriterPtr xo);
+static int
+construct_libvirt_xml_appliance (guestfs_h *g,
+ const struct libvirt_xml_params *params,
+ xmlTextWriterPtr xo);
/* These macros make it easier to write XML, but they also make a lot
* of assumptions:
@@ -884,71 +943,78 @@ static int construct_libvirt_xml_appliance (guestfs_h *g, const
struct libvirt_x
*/
/* <element */
-#define start_element(element) \
- if (xmlTextWriterStartElement (xo, BAD_CAST (element)) == -1) { \
- xml_error ("xmlTextWriterStartElement"); \
- return -1; \
- } \
+#define start_element(element) \
+ if (xmlTextWriterStartElement (xo, BAD_CAST (element)) == -1) { \
+ xml_error ("xmlTextWriterStartElement"); \
+ return -1; \
+ } \
do
/* finish current </element> */
-#define end_element() \
- while (0); \
- do { \
- if (xmlTextWriterEndElement (xo) == -1) { \
- xml_error ("xmlTextWriterEndElement"); \
- return -1; \
- } \
+#define end_element() \
+ while (0) \
+ ; \
+ do { \
+ if (xmlTextWriterEndElement (xo) == -1) { \
+ xml_error ("xmlTextWriterEndElement"); \
+ return -1; \
+ } \
} while (0)
/* <element/> */
-#define empty_element(element) \
- do { start_element(element) {} end_element (); } while (0)
+#define empty_element(element) \
+ do { \
+ start_element (element) {} \
+ end_element (); \
+ } while (0)
/* key=value attribute of the current element. */
-#define attribute(key,value) \
- if (xmlTextWriterWriteAttribute (xo, BAD_CAST (key), BAD_CAST (value)) == -1){ \
- xml_error ("xmlTextWriterWriteAttribute"); \
- return -1; \
+#define attribute(key, value) \
+ if (xmlTextWriterWriteAttribute (xo, BAD_CAST (key), \
+ BAD_CAST (value)) == -1) { \
+ xml_error ("xmlTextWriterWriteAttribute"); \
+ return -1; \
}
/* key=value, but value is a printf-style format string. */
-#define attribute_format(key,fs,...) \
- if (xmlTextWriterWriteFormatAttribute (xo, BAD_CAST (key), \
- fs, ##__VA_ARGS__) == -1) { \
- xml_error ("xmlTextWriterWriteFormatAttribute"); \
- return -1; \
+#define attribute_format(key, fs, ...) \
+ if (xmlTextWriterWriteFormatAttribute (xo, BAD_CAST (key), fs, \
+ ##__VA_ARGS__) == -1) { \
+ xml_error ("xmlTextWriterWriteFormatAttribute"); \
+ return -1; \
}
/* attribute with namespace. */
-#define attribute_ns(prefix,key,namespace_uri,value) \
- if (xmlTextWriterWriteAttributeNS (xo, BAD_CAST (prefix), \
- BAD_CAST (key), BAD_CAST (namespace_uri), \
- BAD_CAST (value)) == -1) { \
- xml_error ("xmlTextWriterWriteAttribute"); \
- return -1; \
+#define attribute_ns(prefix, key, namespace_uri, value) \
+ if (xmlTextWriterWriteAttributeNS ( \
+ xo, BAD_CAST (prefix), BAD_CAST (key), BAD_CAST (namespace_uri), \
+ BAD_CAST (value)) == -1) { \
+ xml_error ("xmlTextWriterWriteAttribute"); \
+ return -1; \
}
/* A string, eg. within an element. */
-#define string(str) \
- if (xmlTextWriterWriteString (xo, BAD_CAST (str)) == -1) { \
- xml_error ("xmlTextWriterWriteString"); \
- return -1; \
+#define string(str) \
+ if (xmlTextWriterWriteString (xo, BAD_CAST (str)) == -1) { \
+ xml_error ("xmlTextWriterWriteString"); \
+ return -1; \
}
/* A string, using printf-style formatting. */
-#define string_format(fs,...) \
- if (xmlTextWriterWriteFormatString (xo, fs, ##__VA_ARGS__) == -1) { \
- xml_error ("xmlTextWriterWriteFormatString"); \
- return -1; \
+#define string_format(fs, ...) \
+ if (xmlTextWriterWriteFormatString (xo, fs, ##__VA_ARGS__) == -1) { \
+ xml_error ("xmlTextWriterWriteFormatString"); \
+ return -1; \
}
#define xml_error(fn) \
- perrorf (g, _("%s:%d: error constructing libvirt XML near call to
\"%s\""), \
- __FILE__, __LINE__, (fn));
+ perrorf ( \
+ g, _("%s:%d: error constructing libvirt XML near call to
\"%s\""), \
+ __FILE__, __LINE__, (fn));
static xmlChar *
-construct_libvirt_xml (guestfs_h *g, const struct libvirt_xml_params *params)
+construct_libvirt_xml (guestfs_h *g,
+ const struct libvirt_xml_params *params)
{
xmlChar *ret = NULL;
CLEANUP_XMLBUFFERFREE xmlBufferPtr xb = NULL;
@@ -1004,7 +1070,8 @@ construct_libvirt_xml_domain (guestfs_h *g,
const struct libvirt_xml_params *params,
xmlTextWriterPtr xo)
{
- start_element ("domain") {
+ start_element ("domain")
+ {
attribute ("type", params->data->is_kvm ? "kvm" :
"qemu");
attribute_ns ("xmlns", "qemu", NULL,
"http://libvirt.org/schemas/domain/qemu/1.0");
@@ -1023,8 +1090,8 @@ construct_libvirt_xml_domain (guestfs_h *g,
return -1;
if (construct_libvirt_xml_qemu_cmdline (g, params, xo) == -1)
return -1;
-
- } end_element ();
+ }
+ end_element ();
return 0;
}
@@ -1034,9 +1101,8 @@ construct_libvirt_xml_name (guestfs_h *g,
const struct libvirt_xml_params *params,
xmlTextWriterPtr xo)
{
- start_element ("name") {
- string (params->data->name);
- } end_element ();
+ start_element ("name") { string (params->data->name); }
+ end_element ();
return 0;
}
@@ -1049,69 +1115,80 @@ construct_libvirt_xml_cpu (guestfs_h *g,
{
const char *cpu_model;
- start_element ("memory") {
+ start_element ("memory")
+ {
attribute ("unit", "MiB");
string_format ("%d", g->memsize);
- } end_element ();
+ }
+ end_element ();
- start_element ("currentMemory") {
+ start_element ("currentMemory")
+ {
attribute ("unit", "MiB");
string_format ("%d", g->memsize);
- } end_element ();
+ }
+ end_element ();
cpu_model = guestfs_int_get_cpu_model (params->data->is_kvm);
if (cpu_model) {
- start_element ("cpu") {
+ start_element ("cpu")
+ {
if (STREQ (cpu_model, "host")) {
attribute ("mode", "host-passthrough");
- start_element ("model") {
- attribute ("fallback", "allow");
- } end_element ();
+ start_element ("model") { attribute ("fallback",
"allow"); }
+ end_element ();
}
else {
- /* XXX This does not work on aarch64, see:
- *
https://www.redhat.com/archives/libvirt-users/2014-August/msg00043.html
- *
https://bugzilla.redhat.com/show_bug.cgi?id=1184411
- * Instead we hack around it using <qemu:commandline> below.
- */
+/* XXX This does not work on aarch64, see:
+ *
https://www.redhat.com/archives/libvirt-users/2014-August/msg00043.html
+ *
https://bugzilla.redhat.com/show_bug.cgi?id=1184411
+ * Instead we hack around it using <qemu:commandline> below.
+ */
#ifndef __aarch64__
- start_element ("model") {
- string (cpu_model);
- } end_element ();
+ start_element ("model") { string (cpu_model); }
+ end_element ();
#endif
}
- } end_element ();
+ }
+ end_element ();
}
- start_element ("vcpu") {
- string_format ("%d", g->smp);
- } end_element ();
+ start_element ("vcpu") { string_format ("%d", g->smp); }
+ end_element ();
- start_element ("clock") {
+ start_element ("clock")
+ {
attribute ("offset", "utc");
/* These are recommended settings, see RHBZ#1053847. */
- start_element ("timer") {
+ start_element ("timer")
+ {
attribute ("name", "rtc");
attribute ("tickpolicy", "catchup");
- } end_element ();
- start_element ("timer") {
+ }
+ end_element ();
+ start_element ("timer")
+ {
attribute ("name", "pit");
attribute ("tickpolicy", "delay");
- } end_element ();
+ }
+ end_element ();
- /* libvirt has a bug (RHBZ#1066145) where it adds the -no-hpet
- * flag on ARM & ppc64 (and possibly any architecture).
- * Since hpet is specific to x86 & x86_64 anyway, just add it only
- * for those architectures.
- */
+/* libvirt has a bug (RHBZ#1066145) where it adds the -no-hpet
+ * flag on ARM & ppc64 (and possibly any architecture).
+ * Since hpet is specific to x86 & x86_64 anyway, just add it only
+ * for those architectures.
+ */
#if defined(__i386__) || defined(__x86_64__)
- start_element ("timer") {
+ start_element ("timer")
+ {
attribute ("name", "hpet");
attribute ("present", "no");
- } end_element ();
+ }
+ end_element ();
#endif
- } end_element ();
+ }
+ end_element ();
return 0;
}
@@ -1129,51 +1206,52 @@ construct_libvirt_xml_boot (guestfs_h *g,
flags = 0;
if (!params->data->is_kvm)
flags |= APPLIANCE_COMMAND_LINE_IS_TCG;
- cmdline = guestfs_int_appliance_command_line (g, params->appliance_dev, flags);
+ cmdline =
+ guestfs_int_appliance_command_line (g, params->appliance_dev, flags);
- start_element ("os") {
- start_element ("type") {
+ start_element ("os")
+ {
+ start_element ("type")
+ {
#ifdef MACHINE_TYPE
attribute ("machine", MACHINE_TYPE);
#endif
string ("hvm");
- } end_element ();
+ }
+ end_element ();
if (params->data->uefi_code) {
- start_element ("loader") {
- attribute ("readonly", "yes");
- attribute ("type", "pflash");
- string (params->data->uefi_code);
- } end_element ();
+ start_element ("loader")
+ {
+ attribute ("readonly", "yes");
+ attribute ("type", "pflash");
+ string (params->data->uefi_code);
+ }
+ end_element ();
if (params->data->uefi_vars) {
- start_element ("nvram") {
- string (params->data->uefi_vars);
- } end_element ();
+ start_element ("nvram") { string (params->data->uefi_vars); }
+ end_element ();
}
}
- start_element ("kernel") {
- string (params->kernel);
- } end_element ();
+ start_element ("kernel") { string (params->kernel); }
+ end_element ();
- start_element ("initrd") {
- string (params->initrd);
- } end_element ();
+ start_element ("initrd") { string (params->initrd); }
+ end_element ();
- start_element ("cmdline") {
- string (cmdline);
- } end_element ();
+ start_element ("cmdline") { string (cmdline); }
+ end_element ();
#if defined(__i386__) || defined(__x86_64__)
if (g->verbose) {
- start_element ("bios") {
- attribute ("useserial", "yes");
- } end_element ();
+ start_element ("bios") { attribute ("useserial",
"yes"); }
+ end_element ();
}
#endif
-
- } end_element ();
+ }
+ end_element ();
return 0;
}
@@ -1185,26 +1263,29 @@ construct_libvirt_xml_seclabel (guestfs_h *g,
{
if (!params->enable_svirt) {
/* This disables SELinux/sVirt confinement. */
- start_element ("seclabel") {
- attribute ("type", "none");
- } end_element ();
+ start_element ("seclabel") { attribute ("type",
"none"); }
+ end_element ();
}
- else if (params->data->selinux_label &&
params->data->selinux_imagelabel) {
+ else if (params->data->selinux_label &&
+ params->data->selinux_imagelabel) {
/* Enable sVirt and pass a custom <seclabel/> inherited from the
* original libvirt domain (when guestfs_add_domain was called).
*
https://bugzilla.redhat.com/show_bug.cgi?id=912499#c7
*/
- start_element ("seclabel") {
+ start_element ("seclabel")
+ {
attribute ("type", "static");
attribute ("model", "selinux");
attribute ("relabel", "yes");
- start_element ("label") {
- string (params->data->selinux_label);
- } end_element ();
- start_element ("imagelabel") {
+ start_element ("label") { string (params->data->selinux_label); }
+ end_element ();
+ start_element ("imagelabel")
+ {
string (params->data->selinux_imagelabel);
- } end_element ();
- } end_element ();
+ }
+ end_element ();
+ }
+ end_element ();
}
return 0;
@@ -1216,9 +1297,8 @@ construct_libvirt_xml_lifecycle (guestfs_h *g,
const struct libvirt_xml_params *params,
xmlTextWriterPtr xo)
{
- start_element ("on_reboot") {
- string ("destroy");
- } end_element ();
+ start_element ("on_reboot") { string ("destroy"); }
+ end_element ();
return 0;
}
@@ -1232,50 +1312,56 @@ construct_libvirt_xml_devices (guestfs_h *g,
struct drive *drv;
size_t i;
- start_element ("devices") {
+ start_element ("devices")
+ {
/* Path to hypervisor. Only write this if the user has changed the
* default, otherwise allow libvirt to choose the best one.
*/
if (is_custom_hv (g)) {
- start_element ("emulator") {
- string (g->hv);
- } end_element ();
+ start_element ("emulator") { string (g->hv); }
+ end_element ();
}
#if defined(__arm__)
/* Hopefully temporary hack to make ARM work (otherwise libvirt
* chooses to run /usr/bin/qemu-kvm).
*/
else {
- start_element ("emulator") {
- string (QEMU);
- } end_element ();
+ start_element ("emulator") { string (QEMU); }
+ end_element ();
}
#endif
/* Add a random number generator (backend for virtio-rng). */
- start_element ("rng") {
+ start_element ("rng")
+ {
attribute ("model", "virtio");
- start_element ("backend") {
+ start_element ("backend")
+ {
attribute ("model", "random");
/* It'd be nice to do this, but libvirt says:
* file '/dev/urandom' is not a supported random source
* Let libvirt pick /dev/random automatically instead.
* See also:
https://bugzilla.redhat.com/show_bug.cgi?id=1074464
*/
- //string ("/dev/urandom");
- } end_element ();
- } end_element ();
+ // string ("/dev/urandom");
+ }
+ end_element ();
+ }
+ end_element ();
/* virtio-scsi controller. */
- start_element ("controller") {
+ start_element ("controller")
+ {
attribute ("type", "scsi");
attribute ("index", "0");
attribute ("model", "virtio-scsi");
- } end_element ();
+ }
+ end_element ();
/* Disks. */
- ITER_DRIVES (g, i, drv) {
+ ITER_DRIVES (g, i, drv)
+ {
if (construct_libvirt_xml_disk (g, params->data, xo, drv, i) == -1)
return -1;
}
@@ -1287,44 +1373,56 @@ construct_libvirt_xml_devices (guestfs_h *g,
}
/* Console. */
- start_element ("serial") {
+ start_element ("serial")
+ {
attribute ("type", "unix");
- start_element ("source") {
+ start_element ("source")
+ {
attribute ("mode", "connect");
attribute ("path", params->data->console_path);
- } end_element ();
- start_element ("target") {
- attribute ("port", "0");
- } end_element ();
- } end_element ();
+ }
+ end_element ();
+ start_element ("target") { attribute ("port", "0");
}
+ end_element ();
+ }
+ end_element ();
/* Virtio-serial for guestfsd communication. */
- start_element ("channel") {
+ start_element ("channel")
+ {
attribute ("type", "unix");
- start_element ("source") {
+ start_element ("source")
+ {
attribute ("mode", "connect");
attribute ("path", params->data->guestfsd_path);
- } end_element ();
- start_element ("target") {
+ }
+ end_element ();
+ start_element ("target")
+ {
attribute ("type", "virtio");
attribute ("name", "org.libguestfs.channel.0");
- } end_element ();
- } end_element ();
+ }
+ end_element ();
+ }
+ end_element ();
/* Connect to libvirt bridge (see: RHBZ#1148012). */
if (g->enable_network) {
- start_element ("interface") {
+ start_element ("interface")
+ {
attribute ("type", "bridge");
- start_element ("source") {
+ start_element ("source")
+ {
attribute ("bridge", params->data->network_bridge);
- } end_element ();
- start_element ("model") {
- attribute ("type", "virtio");
- } end_element ();
- } end_element ();
+ }
+ end_element ();
+ start_element ("model") { attribute ("type",
"virtio"); }
+ end_element ();
+ }
+ end_element ();
}
-
- } end_element (); /* </devices> */
+ }
+ end_element (); /* </devices> */
return 0;
}
@@ -1332,8 +1430,8 @@ construct_libvirt_xml_devices (guestfs_h *g,
static int
construct_libvirt_xml_disk (guestfs_h *g,
const struct backend_libvirt_data *data,
- xmlTextWriterPtr xo,
- struct drive *drv, size_t drv_index)
+ xmlTextWriterPtr xo, struct drive *drv,
+ size_t drv_index)
{
const char *protocol_str;
CLEANUP_FREE char *path = NULL;
@@ -1344,11 +1442,13 @@ construct_libvirt_xml_disk (guestfs_h *g,
/* XXX We probably could support this if we thought about it some more. */
if (drv->iface) {
- error (g, _("'iface' parameter is not supported by the libvirt
backend"));
+ error (g,
+ _("'iface' parameter is not supported by the libvirt
backend"));
return -1;
}
- start_element ("disk") {
+ start_element ("disk")
+ {
attribute ("device", "disk");
if (drv->overlay) {
@@ -1357,19 +1457,20 @@ construct_libvirt_xml_disk (guestfs_h *g,
*/
attribute ("type", "file");
- start_element ("source") {
+ start_element ("source")
+ {
attribute ("file", drv->overlay);
if (construct_libvirt_xml_disk_source_seclabel (g, data, xo) == -1)
return -1;
- } end_element ();
+ }
+ end_element ();
if (construct_libvirt_xml_disk_target (g, xo, drv_index) == -1)
return -1;
- if (construct_libvirt_xml_disk_driver_qemu (g, data, drv,
- xo, "qcow2",
"unsafe",
- discard_disable, false)
- == -1)
+ if (construct_libvirt_xml_disk_driver_qemu (g, data, drv, xo, "qcow2",
+ "unsafe", discard_disable,
+ false) == -1)
return -1;
}
else {
@@ -1390,90 +1491,111 @@ construct_libvirt_xml_disk (guestfs_h *g,
if (!is_host_device) {
path = realpath (drv->src.u.path, NULL);
if (path == NULL) {
- perrorf (g, _("realpath: could not convert '%s' to absolute
path"),
- drv->src.u.path);
+ perrorf (
+ g, _("realpath: could not convert '%s' to absolute
path"),
+ drv->src.u.path);
return -1;
}
attribute ("type", "file");
- start_element ("source") {
+ start_element ("source")
+ {
attribute ("file", path);
- if (construct_libvirt_xml_disk_source_seclabel (g, data, xo) == -1)
+ if (construct_libvirt_xml_disk_source_seclabel (g, data, xo) ==
+ -1)
return -1;
- } end_element ();
+ }
+ end_element ();
}
else {
attribute ("type", "block");
- start_element ("source") {
+ start_element ("source")
+ {
attribute ("dev", drv->src.u.path);
- if (construct_libvirt_xml_disk_source_seclabel (g, data, xo) == -1)
+ if (construct_libvirt_xml_disk_source_seclabel (g, data, xo) ==
+ -1)
return -1;
- } end_element ();
+ }
+ end_element ();
}
break;
- /* For network protocols:
- * <disk type=network device=disk>
- * <source protocol=[protocol] [name=exportname]>
- * and then zero or more of:
- * <host name='example.com' port='10809'/>
- * or:
- * <host transport='unix' socket='/path/to/socket'/>
- */
+ /* For network protocols:
+ * <disk type=network device=disk>
+ * <source protocol=[protocol] [name=exportname]>
+ * and then zero or more of:
+ * <host name='example.com' port='10809'/>
+ * or:
+ * <host transport='unix' socket='/path/to/socket'/>
+ */
case drive_protocol_gluster:
- protocol_str = "gluster"; goto network_protocols;
+ protocol_str = "gluster";
+ goto network_protocols;
case drive_protocol_iscsi:
- protocol_str = "iscsi"; goto network_protocols;
+ protocol_str = "iscsi";
+ goto network_protocols;
case drive_protocol_nbd:
- protocol_str = "nbd"; goto network_protocols;
+ protocol_str = "nbd";
+ goto network_protocols;
case drive_protocol_rbd:
- protocol_str = "rbd"; goto network_protocols;
+ protocol_str = "rbd";
+ goto network_protocols;
case drive_protocol_sheepdog:
- protocol_str = "sheepdog"; goto network_protocols;
+ protocol_str = "sheepdog";
+ goto network_protocols;
case drive_protocol_ssh:
protocol_str = "ssh";
- /*FALLTHROUGH*/
+ /*FALLTHROUGH*/
network_protocols:
attribute ("type", "network");
- start_element ("source") {
+ start_element ("source")
+ {
attribute ("protocol", protocol_str);
if (STRNEQ (drv->src.u.exportname, ""))
attribute ("name", drv->src.u.exportname);
- if (construct_libvirt_xml_disk_source_hosts (g, xo,
- &drv->src) == -1)
+ if (construct_libvirt_xml_disk_source_hosts (g, xo, &drv->src) ==
+ -1)
return -1;
- if (construct_libvirt_xml_disk_source_seclabel (g, data, xo) == -1)
+ if (construct_libvirt_xml_disk_source_seclabel (g, data, xo) ==
+ -1)
return -1;
- } end_element ();
+ }
+ end_element ();
if (drv->src.username != NULL) {
- start_element ("auth") {
+ start_element ("auth")
+ {
attribute ("username", drv->src.username);
r = find_secret (g, data, drv, &type, &uuid);
if (r == -1)
return -1;
if (r == 1) {
- start_element ("secret") {
+ start_element ("secret")
+ {
attribute ("type", type);
attribute ("uuid", uuid);
- } end_element ();
+ }
+ end_element ();
}
- } end_element ();
+ }
+ end_element ();
}
break;
- /* libvirt doesn't support the qemu curl driver yet. Give a
- * reasonable error message instead of trying and failing.
- */
+ /* libvirt doesn't support the qemu curl driver yet. Give a
+ * reasonable error message instead of trying and failing.
+ */
case drive_protocol_ftp:
case drive_protocol_ftps:
case drive_protocol_http:
case drive_protocol_https:
case drive_protocol_tftp:
- error (g, _("libvirt does not support the qemu curl driver protocols (ftp,
http, etc.); try setting LIBGUESTFS_BACKEND=direct"));
+ error (g, _("libvirt does not support the qemu curl driver "
+ "protocols (ftp, http, etc.); try setting "
+ "LIBGUESTFS_BACKEND=direct"));
return -1;
}
@@ -1485,12 +1607,15 @@ construct_libvirt_xml_disk (guestfs_h *g,
else if (drv->src.protocol == drive_protocol_file) {
/* libvirt has disabled the feature of detecting the disk format,
* unless the administrator sets allow_disk_format_probing=1 in
- * qemu.conf. There is no way to detect if this option is set, so we
+ * qemu.conf. There is no way to detect if this option is set, so
+ * we
* have to do format detection here using qemu-img and pass that to
* libvirt.
*
- * This is still a security issue, so in most cases it is recommended
- * the users pass the format to libguestfs which will faithfully pass
+ * This is still a security issue, so in most cases it is
+ * recommended
+ * the users pass the format to libguestfs which will faithfully
+ * pass
* that to libvirt and this function won't be used.
*/
format = guestfs_disk_format (g, drv->src.u.path);
@@ -1499,35 +1624,38 @@ construct_libvirt_xml_disk (guestfs_h *g,
if (STREQ (format, "unknown")) {
error (g, _("could not auto-detect the format.\n"
- "If the format is known, pass the format to libguestfs, eg.
using the\n"
- "'--format' option, or via the optional
'format' argument to 'add-drive'."));
+ "If the format is known, pass the format to "
+ "libguestfs, eg. using the\n"
+ "'--format' option, or via the optional
'format' "
+ "argument to 'add-drive'."));
return -1;
}
}
else {
- error (g, _("could not auto-detect the format when using a non-file
protocol.\n"
- "If the format is known, pass the format to libguestfs, eg.
using the\n"
- "'--format' option, or via the optional 'format'
argument to 'add-drive'."));
+ error (g, _("could not auto-detect the format when using a "
+ "non-file protocol.\n"
+ "If the format is known, pass the format to "
+ "libguestfs, eg. using the\n"
+ "'--format' option, or via the optional 'format'
"
+ "argument to 'add-drive'."));
return -1;
}
- if (construct_libvirt_xml_disk_driver_qemu (g, data, drv, xo, format,
- drv->cachemode ? :
"writeback",
- drv->discard, false)
- == -1)
+ if (construct_libvirt_xml_disk_driver_qemu (
+ g, data, drv, xo, format, drv->cachemode ?: "writeback",
+ drv->discard, false) == -1)
return -1;
}
if (drv->disk_label) {
- start_element ("serial") {
- string (drv->disk_label);
- } end_element ();
+ start_element ("serial") { string (drv->disk_label); }
+ end_element ();
}
if (construct_libvirt_xml_disk_address (g, xo, drv_index) == -1)
return -1;
-
- } end_element (); /* </disk> */
+ }
+ end_element (); /* </disk> */
return 0;
}
@@ -1540,23 +1668,21 @@ construct_libvirt_xml_disk_target (guestfs_h *g, xmlTextWriterPtr
xo,
guestfs_int_drive_name (drv_index, &drive_name[2]);
- start_element ("target") {
+ start_element ("target")
+ {
attribute ("dev", drive_name);
attribute ("bus", "scsi");
- } end_element ();
+ }
+ end_element ();
return 0;
}
static int
-construct_libvirt_xml_disk_driver_qemu (guestfs_h *g,
- const struct backend_libvirt_data *data,
- struct drive *drv,
- xmlTextWriterPtr xo,
- const char *format,
- const char *cachemode,
- enum discard discard,
- bool copyonread)
+construct_libvirt_xml_disk_driver_qemu (
+ guestfs_h *g, const struct backend_libvirt_data *data, struct drive *drv,
+ xmlTextWriterPtr xo, const char *format, const char *cachemode,
+ enum discard discard, bool copyonread)
{
bool discard_unmap = false;
@@ -1574,7 +1700,7 @@ construct_libvirt_xml_disk_driver_qemu (guestfs_h *g,
case discard_enable:
if (!guestfs_int_discard_possible (g, drv, data->qemu_version))
return -1;
- /*FALLTHROUGH*/
+ /*FALLTHROUGH*/
case discard_besteffort:
/* I believe from reading the code that this is always safe as
* long as qemu >= 1.5.
@@ -1584,7 +1710,8 @@ construct_libvirt_xml_disk_driver_qemu (guestfs_h *g,
break;
}
- start_element ("driver") {
+ start_element ("driver")
+ {
attribute ("name", "qemu");
attribute ("type", format);
attribute ("cache", cachemode);
@@ -1592,7 +1719,8 @@ construct_libvirt_xml_disk_driver_qemu (guestfs_h *g,
attribute ("discard", "unmap");
if (copyonread)
attribute ("copy_on_read", "on");
- } end_element ();
+ }
+ end_element ();
return 0;
}
@@ -1601,26 +1729,28 @@ static int
construct_libvirt_xml_disk_address (guestfs_h *g, xmlTextWriterPtr xo,
size_t drv_index)
{
- start_element ("address") {
+ start_element ("address")
+ {
attribute ("type", "drive");
attribute ("controller", "0");
attribute ("bus", "0");
attribute_format ("target", "%zu", drv_index);
attribute ("unit", "0");
- } end_element ();
+ }
+ end_element ();
return 0;
}
static int
-construct_libvirt_xml_disk_source_hosts (guestfs_h *g,
- xmlTextWriterPtr xo,
+construct_libvirt_xml_disk_source_hosts (guestfs_h *g, xmlTextWriterPtr xo,
const struct drive_source *src)
{
size_t i;
for (i = 0; i < src->nr_servers; ++i) {
- start_element ("host") {
+ start_element ("host")
+ {
switch (src->servers[i].transport) {
case drive_transport_none:
case drive_transport_tcp: {
@@ -1636,23 +1766,25 @@ construct_libvirt_xml_disk_source_hosts (guestfs_h *g,
break;
}
}
-
- } end_element ();
+ }
+ end_element ();
}
return 0;
}
static int
-construct_libvirt_xml_disk_source_seclabel (guestfs_h *g,
- const struct backend_libvirt_data *data,
- xmlTextWriterPtr xo)
+construct_libvirt_xml_disk_source_seclabel (
+ guestfs_h *g, const struct backend_libvirt_data *data,
+ xmlTextWriterPtr xo)
{
if (data->selinux_norelabel_disks) {
- start_element ("seclabel") {
+ start_element ("seclabel")
+ {
attribute ("model", "selinux");
attribute ("relabel", "no");
- } end_element ();
+ }
+ end_element ();
}
return 0;
@@ -1663,31 +1795,36 @@ construct_libvirt_xml_appliance (guestfs_h *g,
const struct libvirt_xml_params *params,
xmlTextWriterPtr xo)
{
- start_element ("disk") {
+ start_element ("disk")
+ {
attribute ("type", "file");
attribute ("device", "disk");
- start_element ("source") {
+ start_element ("source")
+ {
attribute ("file", params->appliance_overlay);
- } end_element ();
+ }
+ end_element ();
- start_element ("target") {
+ start_element ("target")
+ {
attribute ("dev", ¶ms->appliance_dev[5]);
attribute ("bus", "scsi");
- } end_element ();
+ }
+ end_element ();
- if (construct_libvirt_xml_disk_driver_qemu (g, params->data, NULL, xo,
- "qcow2", "unsafe",
- discard_disable, false) == -1)
+ if (construct_libvirt_xml_disk_driver_qemu (
+ g, params->data, NULL, xo, "qcow2", "unsafe",
discard_disable,
+ false) == -1)
return -1;
- if (construct_libvirt_xml_disk_address (g, xo, params->appliance_index)
- == -1)
+ if (construct_libvirt_xml_disk_address (g, xo,
+ params->appliance_index) == -1)
return -1;
empty_element ("shareable");
-
- } end_element ();
+ }
+ end_element ();
return 0;
}
@@ -1700,7 +1837,8 @@ construct_libvirt_xml_qemu_cmdline (guestfs_h *g,
struct hv_param *hp;
CLEANUP_FREE char *tmpdir = NULL;
- start_element ("qemu:commandline") {
+ start_element ("qemu:commandline")
+ {
/* We need to ensure the snapshots are created in the persistent
* temporary directory (RHBZ#856619). We must set one, because
@@ -1708,21 +1846,21 @@ construct_libvirt_xml_qemu_cmdline (guestfs_h *g,
*/
tmpdir = guestfs_get_cachedir (g);
- start_element ("qemu:env") {
+ start_element ("qemu:env")
+ {
attribute ("name", "TMPDIR");
attribute ("value", tmpdir);
- } end_element ();
+ }
+ end_element ();
/* The qemu command line arguments requested by the caller. */
for (hp = g->hv_params; hp; hp = hp->next) {
- start_element ("qemu:arg") {
- attribute ("value", hp->hv_param);
- } end_element ();
+ start_element ("qemu:arg") { attribute ("value",
hp->hv_param); }
+ end_element ();
if (hp->hv_value) {
- start_element ("qemu:arg") {
- attribute ("value", hp->hv_value);
- } end_element ();
+ start_element ("qemu:arg") { attribute ("value",
hp->hv_value); }
+ end_element ();
}
}
@@ -1730,18 +1868,17 @@ construct_libvirt_xml_qemu_cmdline (guestfs_h *g,
/* This is a temporary hack until RHBZ#1184411 is resolved.
* See comments above about cpu model and aarch64.
*/
- const char *cpu_model = guestfs_int_get_cpu_model (params->data->is_kvm);
+ const char *cpu_model =
+ guestfs_int_get_cpu_model (params->data->is_kvm);
if (STRNEQ (cpu_model, "host")) {
- start_element ("qemu:arg") {
- attribute ("value", "-cpu");
- } end_element ();
- start_element ("qemu:arg") {
- attribute ("value", cpu_model);
- } end_element ();
+ start_element ("qemu:arg") { attribute ("value",
"-cpu"); }
+ end_element ();
+ start_element ("qemu:arg") { attribute ("value", cpu_model); }
+ end_element ();
}
#endif
-
- } end_element (); /* </qemu:commandline> */
+ }
+ end_element (); /* </qemu:commandline> */
return 0;
}
@@ -1749,17 +1886,20 @@ construct_libvirt_xml_qemu_cmdline (guestfs_h *g,
static int
construct_libvirt_xml_secret (guestfs_h *g,
const struct backend_libvirt_data *data,
- const struct drive *drv,
- xmlTextWriterPtr xo)
+ const struct drive *drv, xmlTextWriterPtr xo)
{
- start_element ("secret") {
+ start_element ("secret")
+ {
attribute ("ephemeral", "yes");
attribute ("private", "yes");
- start_element ("description") {
- string_format ("guestfs secret associated with %s %s",
- data->name, drv->src.u.path);
- } end_element ();
- } end_element ();
+ start_element ("description")
+ {
+ string_format ("guestfs secret associated with %s %s", data->name,
+ drv->src.u.path);
+ }
+ end_element ();
+ }
+ end_element ();
return 0;
}
@@ -1833,7 +1973,7 @@ add_secret (guestfs_h *g, virConnectPtr conn,
debug (g, "libvirt secret XML:\n%s", xml);
/* Pass the XML to libvirt. */
- secret_obj = virSecretDefineXML (conn, (const char *) xml, 0);
+ secret_obj = virSecretDefineXML (conn, (const char *)xml, 0);
if (secret_obj == NULL) {
libvirt_error (g, _("could not define libvirt secret"));
return -1;
@@ -1844,8 +1984,8 @@ add_secret (guestfs_h *g, virConnectPtr conn,
*/
switch (drv->src.protocol) {
case drive_protocol_rbd:
- if (!base64_decode_alloc (secret, strlen (secret),
- (char **) &secret_raw, &secret_raw_len)) {
+ if (!base64_decode_alloc (secret, strlen (secret), (char **)&secret_raw,
+ &secret_raw_len)) {
error (g, _("rbd protocol secret must be base64 encoded"));
return -1;
}
@@ -1865,7 +2005,7 @@ add_secret (guestfs_h *g, virConnectPtr conn,
case drive_protocol_sheepdog:
case drive_protocol_ssh:
case drive_protocol_tftp:
- secret_raw = (unsigned char *) safe_strdup (g, secret);
+ secret_raw = (unsigned char *)safe_strdup (g, secret);
secret_raw_len = strlen (secret);
}
@@ -1878,8 +2018,8 @@ add_secret (guestfs_h *g, virConnectPtr conn,
/* Get back the UUID and save it in the private data. */
i = data->nr_secrets;
data->nr_secrets++;
- data->secrets =
- safe_realloc (g, data->secrets, sizeof (struct secret) * data->nr_secrets);
+ data->secrets = safe_realloc (g, data->secrets,
+ sizeof (struct secret) * data->nr_secrets);
data->secrets[i].secret = safe_strdup (g, secret);
@@ -1892,8 +2032,8 @@ add_secret (guestfs_h *g, virConnectPtr conn,
}
static int
-have_secret (guestfs_h *g,
- const struct backend_libvirt_data *data, const struct drive *drv)
+have_secret (guestfs_h *g, const struct backend_libvirt_data *data,
+ const struct drive *drv)
{
size_t i;
@@ -1914,9 +2054,8 @@ have_secret (guestfs_h *g,
* secret was found and returned.
*/
static int
-find_secret (guestfs_h *g,
- const struct backend_libvirt_data *data, const struct drive *drv,
- const char **type, const char **uuid)
+find_secret (guestfs_h *g, const struct backend_libvirt_data *data,
+ const struct drive *drv, const char **type, const char **uuid)
{
size_t i;
@@ -1946,7 +2085,7 @@ find_secret (guestfs_h *g,
case drive_protocol_sheepdog:
case drive_protocol_ssh:
case drive_protocol_tftp:
- /* set to a default value above */ ;
+ /* set to a default value above */;
}
return 1;
@@ -1993,19 +2132,20 @@ check_bridge_exists (guestfs_h *g, const char *brname)
if (is_dir (path))
return 0;
- error (g,
- _("bridge '%s' not found. Try running:\n"
- "\n"
- " brctl show\n"
- "\n"
- "to get a list of bridges on the host, and then selecting the\n"
- "bridge you wish the appliance network to connect to using:\n"
- "\n"
- " export LIBGUESTFS_BACKEND_SETTINGS=network_bridge=<bridge
name>\n"
- "\n"
- "You may also need to allow the bridge in /etc/qemu/bridge.conf.\n"
- "For further information see guestfs(3)."),
- brname);
+ error (
+ g,
+ _("bridge '%s' not found. Try running:\n"
+ "\n"
+ " brctl show\n"
+ "\n"
+ "to get a list of bridges on the host, and then selecting the\n"
+ "bridge you wish the appliance network to connect to using:\n"
+ "\n"
+ " export LIBGUESTFS_BACKEND_SETTINGS=network_bridge=<bridge
name>\n"
+ "\n"
+ "You may also need to allow the bridge in /etc/qemu/bridge.conf.\n"
+ "For further information see guestfs(3)."),
+ brname);
return -1;
}
@@ -2015,7 +2155,8 @@ ignore_errors (void *ignore, virErrorPtr ignore2)
/* empty */
}
-static int destroy_domain (guestfs_h *g, virDomainPtr dom, int check_for_errors);
+static int destroy_domain (guestfs_h *g, virDomainPtr dom,
+ int check_for_errors);
static int
shutdown_libvirt (guestfs_h *g, void *datav, int check_for_errors)
@@ -2078,7 +2219,7 @@ destroy_domain (guestfs_h *g, virDomainPtr dom, int
check_for_errors)
const int flags = check_for_errors ? VIR_DOMAIN_DESTROY_GRACEFUL : 0;
virErrorPtr err;
- again:
+again:
debug (g, "calling virDomainDestroy flags=%s",
check_for_errors ? "VIR_DOMAIN_DESTROY_GRACEFUL" : "0");
if (virDomainDestroyFlags (dom, flags) == 0)
@@ -2117,15 +2258,14 @@ libvirt_error (guestfs_h *g, const char *fs, ...)
va_end (args);
if (len < 0)
- msg = safe_asprintf (g,
- _("%s: internal error forming error message"),
+ msg = safe_asprintf (g, _("%s: internal error forming error message"),
__func__);
/* In all recent libvirt, this retrieves the thread-local error. */
err = virGetLastError ();
if (err)
- error (g, "%s: %s [code=%d int1=%d]",
- msg, err->message, err->code, err->int1);
+ error (g, "%s: %s [code=%d int1=%d]", msg, err->message, err->code,
+ err->int1);
else
error (g, "%s", msg);
@@ -2150,15 +2290,14 @@ libvirt_debug (guestfs_h *g, const char *fs, ...)
va_end (args);
if (len < 0)
- msg = safe_asprintf (g,
- _("%s: internal error forming error message"),
+ msg = safe_asprintf (g, _("%s: internal error forming error message"),
__func__);
/* In all recent libvirt, this retrieves the thread-local error. */
err = virGetLastError ();
if (err)
- debug (g, "%s: %s [code=%d int1=%d]",
- msg, err->message, err->code, err->int1);
+ debug (g, "%s: %s [code=%d int1=%d]", msg, err->message, err->code,
+ err->int1);
else
debug (g, "%s", msg);
@@ -2168,12 +2307,14 @@ libvirt_debug (guestfs_h *g, const char *fs, ...)
#if HAVE_LIBSELINUX
static void
-selinux_warning (guestfs_h *g, const char *func,
- const char *selinux_op, const char *data)
+selinux_warning (guestfs_h *g, const char *func, const char *selinux_op,
+ const char *data)
{
- debug (g, "%s: %s failed: %s: %m"
- " [you can ignore this message if you are not using SELinux +
sVirt]",
- func, selinux_op, data ? data : "(none)");
+ debug (
+ g,
+ "%s: %s failed: %s: %m"
+ " [you can ignore this message if you are not using SELinux + sVirt]",
+ func, selinux_op, data ? data : "(none)");
}
#endif
@@ -2184,12 +2325,15 @@ max_disks_libvirt (guestfs_h *g, void *datav)
return 255;
}
-static xmlChar *construct_libvirt_xml_hot_add_disk (guestfs_h *g, const struct
backend_libvirt_data *data, struct drive *drv, size_t drv_index);
+static xmlChar *
+construct_libvirt_xml_hot_add_disk (guestfs_h *g,
+ const struct backend_libvirt_data *data,
+ struct drive *drv, size_t drv_index);
/* Hot-add a drive. Note the appliance is up when this is called. */
static int
-hot_add_drive_libvirt (guestfs_h *g, void *datav,
- struct drive *drv, size_t drv_index)
+hot_add_drive_libvirt (guestfs_h *g, void *datav, struct drive *drv,
+ size_t drv_index)
{
struct backend_libvirt_data *data = datav;
virConnectPtr conn = data->conn;
@@ -2212,7 +2356,7 @@ hot_add_drive_libvirt (guestfs_h *g, void *datav,
return -1;
/* Attach it. */
- if (virDomainAttachDeviceFlags (dom, (char *) xml,
+ if (virDomainAttachDeviceFlags (dom, (char *)xml,
VIR_DOMAIN_DEVICE_MODIFY_LIVE) == -1) {
libvirt_error (g, _("could not attach disk to libvirt domain"));
return -1;
@@ -2223,8 +2367,8 @@ hot_add_drive_libvirt (guestfs_h *g, void *datav,
/* Hot-remove a drive. Note the appliance is up when this is called. */
static int
-hot_remove_drive_libvirt (guestfs_h *g, void *datav,
- struct drive *drv, size_t drv_index)
+hot_remove_drive_libvirt (guestfs_h *g, void *datav, struct drive *drv,
+ size_t drv_index)
{
struct backend_libvirt_data *data = datav;
virConnectPtr conn = data->conn;
@@ -2243,7 +2387,7 @@ hot_remove_drive_libvirt (guestfs_h *g, void *datav,
return -1;
/* Detach it. */
- if (virDomainDetachDeviceFlags (dom, (char *) xml,
+ if (virDomainDetachDeviceFlags (dom, (char *)xml,
VIR_DOMAIN_DEVICE_MODIFY_LIVE) == -1) {
libvirt_error (g, _("could not detach disk from libvirt domain"));
return -1;
@@ -2255,8 +2399,7 @@ hot_remove_drive_libvirt (guestfs_h *g, void *datav,
static xmlChar *
construct_libvirt_xml_hot_add_disk (guestfs_h *g,
const struct backend_libvirt_data *data,
- struct drive *drv,
- size_t drv_index)
+ struct drive *drv, size_t drv_index)
{
xmlChar *ret = NULL;
CLEANUP_XMLBUFFERFREE xmlBufferPtr xb = NULL;
diff --git a/src/launch-uml.c b/src/launch-uml.c
index 318081c..d40ac29 100644
--- a/src/launch-uml.c
+++ b/src/launch-uml.c
@@ -38,11 +38,11 @@
/* Per-handle data. */
struct backend_uml_data {
- pid_t pid; /* vmlinux PID. */
- pid_t recoverypid; /* Recovery process PID. */
+ pid_t pid; /* vmlinux PID. */
+ pid_t recoverypid; /* Recovery process PID. */
#define UML_UMID_LEN 16
- char umid[UML_UMID_LEN+1]; /* umid=<...> unique ID. */
+ char umid[UML_UMID_LEN + 1]; /* umid=<...> unique ID. */
};
static void print_vmlinux_command_line (guestfs_h *g, char **argv);
@@ -101,7 +101,8 @@ uml_supported (guestfs_h *g)
return false;
}
- ITER_DRIVES (g, i, drv) {
+ ITER_DRIVES (g, i, drv)
+ {
if (drv->src.protocol != drive_protocol_file) {
error (g, _("uml backend does not support remote drives"));
return false;
@@ -111,19 +112,21 @@ uml_supported (guestfs_h *g)
return false;
}
if (drv->iface) {
- error (g,
- _("uml backend does not support drives with 'iface'
parameter"));
+ error (
+ g,
+ _("uml backend does not support drives with 'iface'
parameter"));
return false;
}
if (drv->disk_label) {
- error (g,
- _("uml backend does not support drives with 'label'
parameter"));
+ error (
+ g,
+ _("uml backend does not support drives with 'label'
parameter"));
return false;
}
/* Note that discard == "besteffort" is fine. */
if (drv->discard == discard_enable) {
- error (g,
- _("uml backend does not support drives with 'discard' parameter
set to 'enable'"));
+ error (g, _("uml backend does not support drives with 'discard'
"
+ "parameter set to 'enable'"));
return false;
}
}
@@ -180,14 +183,14 @@ launch_uml (guestfs_h *g, void *datav, const char *arg)
/* The socket that the daemon will talk to us on.
*/
- if (socketpair (AF_LOCAL, SOCK_STREAM|SOCK_CLOEXEC, 0, dsv) == -1) {
+ if (socketpair (AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0, dsv) == -1) {
perrorf (g, "socketpair");
goto cleanup0;
}
/* The console socket. */
if (!g->direct_mode) {
- if (socketpair (AF_LOCAL, SOCK_STREAM|SOCK_CLOEXEC, 0, csv) == -1) {
+ if (socketpair (AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0, csv) == -1) {
perrorf (g, "socketpair");
close (dsv[0]);
close (dsv[1]);
@@ -195,13 +198,12 @@ launch_uml (guestfs_h *g, void *datav, const char *arg)
}
}
- /* Construct the vmlinux command line. We have to do this before
- * forking, because after fork we are not allowed to use
- * non-signal-safe functions such as malloc.
- */
-#define ADD_CMDLINE(str) \
- guestfs_int_add_string (g, &cmdline, (str))
-#define ADD_CMDLINE_PRINTF(fs,...) \
+/* Construct the vmlinux command line. We have to do this before
+ * forking, because after fork we are not allowed to use
+ * non-signal-safe functions such as malloc.
+ */
+#define ADD_CMDLINE(str) guestfs_int_add_string (g, &cmdline, (str))
+#define ADD_CMDLINE_PRINTF(fs, ...) \
guestfs_int_add_sprintf (g, &cmdline, (fs), ##__VA_ARGS__)
ADD_CMDLINE (g->hv);
@@ -244,7 +246,8 @@ launch_uml (guestfs_h *g, void *datav, const char *arg)
ADD_CMDLINE (g->append);
/* Add the drives. */
- ITER_DRIVES (g, i, drv) {
+ ITER_DRIVES (g, i, drv)
+ {
if (!drv->overlay)
ADD_CMDLINE_PRINTF ("ubd%zu=%s", i, drv->src.u.path);
else
@@ -286,7 +289,7 @@ launch_uml (guestfs_h *g, void *datav, const char *arg)
goto cleanup0;
}
- if (r == 0) { /* Child (vmlinux). */
+ if (r == 0) { /* Child (vmlinux). */
/* Set up the daemon socket for the child. */
close (dsv[0]);
set_cloexec_flag (dsv[1], 0); /* so it doesn't close across exec */
@@ -410,7 +413,7 @@ launch_uml (guestfs_h *g, void *datav, const char *arg)
/* Close the other end of the console socketpair. */
close (csv[1]);
- console_sock = csv[0]; /* stdin of child */
+ console_sock = csv[0]; /* stdin of child */
csv[0] = -1;
}
@@ -454,7 +457,8 @@ launch_uml (guestfs_h *g, void *datav, const char *arg)
* send commands after this function returns.
*/
if (g->state != READY) {
- error (g, _("vmlinux launched and contacted daemon, but state != READY"));
+ error (g,
+ _("vmlinux launched and contacted daemon, but state != READY"));
goto cleanup1;
}
@@ -463,20 +467,24 @@ launch_uml (guestfs_h *g, void *datav, const char *arg)
return 0;
- cleanup1:
+cleanup1:
if (!g->direct_mode && csv[0] >= 0)
close (csv[0]);
if (dsv[0] >= 0)
close (dsv[0]);
- if (data->pid > 0) kill (data->pid, SIGKILL);
- if (data->recoverypid > 0) kill (data->recoverypid, SIGKILL);
- if (data->pid > 0) waitpid (data->pid, NULL, 0);
- if (data->recoverypid > 0) waitpid (data->recoverypid, NULL, 0);
+ if (data->pid > 0)
+ kill (data->pid, SIGKILL);
+ if (data->recoverypid > 0)
+ kill (data->recoverypid, SIGKILL);
+ if (data->pid > 0)
+ waitpid (data->pid, NULL, 0);
+ if (data->recoverypid > 0)
+ waitpid (data->recoverypid, NULL, 0);
data->pid = 0;
data->recoverypid = 0;
memset (&g->launch_t, 0, sizeof g->launch_t);
- cleanup0:
+cleanup0:
if (daemon_sock >= 0)
close (daemon_sock);
if (console_sock >= 0)
@@ -505,14 +513,17 @@ print_vmlinux_command_line (guestfs_h *g, char **argv)
guestfs_int_timeval_diff (&g->launch_t, &tv));
while (argv[i]) {
- if (i > 0) fputc (' ', stderr);
+ if (i > 0)
+ fputc (' ', stderr);
/* Does it need shell quoting? This only deals with simple cases. */
needs_quote = strcspn (argv[i], " ") != strlen (argv[i]);
- if (needs_quote) fputc ('\'', stderr);
+ if (needs_quote)
+ fputc ('\'', stderr);
fprintf (stderr, "%s", argv[i]);
- if (needs_quote) fputc ('\'', stderr);
+ if (needs_quote)
+ fputc ('\'', stderr);
i++;
}
@@ -531,7 +542,8 @@ shutdown_uml (guestfs_h *g, void *datav, int check_for_errors)
debug (g, "sending SIGTERM to process %d", data->pid);
kill (data->pid, SIGTERM);
}
- if (data->recoverypid > 0) kill (data->recoverypid, 9);
+ if (data->recoverypid > 0)
+ kill (data->recoverypid, 9);
/* Wait for subprocess(es) to exit. */
if (data->pid > 0) {
@@ -552,7 +564,8 @@ shutdown_uml (guestfs_h *g, void *datav, int check_for_errors)
ret = -1;
}
}
- if (data->recoverypid > 0) waitpid (data->recoverypid, NULL, 0);
+ if (data->recoverypid > 0)
+ waitpid (data->recoverypid, NULL, 0);
data->pid = data->recoverypid = 0;
diff --git a/src/launch-unix.c b/src/launch-unix.c
index 212de69..3d7215e 100644
--- a/src/launch-unix.c
+++ b/src/launch-unix.c
@@ -22,7 +22,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
-#include <sys/un.h> /* sockaddr_un */
+#include <sys/un.h> /* sockaddr_un */
#include <string.h>
#include <libintl.h>
@@ -47,15 +47,15 @@ launch_unix (guestfs_h *g, void *datav, const char *sockpath)
return -1;
}
- if (strlen (sockpath) > UNIX_PATH_MAX-1) {
+ if (strlen (sockpath) > UNIX_PATH_MAX - 1) {
error (g, _("socket filename too long (more than %d characters): %s"),
- UNIX_PATH_MAX-1, sockpath);
+ UNIX_PATH_MAX - 1, sockpath);
return -1;
}
debug (g, "connecting to %s", sockpath);
- daemon_sock = socket (AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0);
+ daemon_sock = socket (AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
if (daemon_sock == -1) {
perrorf (g, "socket");
return -1;
@@ -63,11 +63,11 @@ launch_unix (guestfs_h *g, void *datav, const char *sockpath)
addr.sun_family = AF_UNIX;
strncpy (addr.sun_path, sockpath, UNIX_PATH_MAX);
- addr.sun_path[UNIX_PATH_MAX-1] = '\0';
+ addr.sun_path[UNIX_PATH_MAX - 1] = '\0';
g->state = LAUNCHING;
- if (connect (daemon_sock, (struct sockaddr *) &addr, sizeof addr) == -1) {
+ if (connect (daemon_sock, (struct sockaddr *)&addr, sizeof addr) == -1) {
perrorf (g, "bind");
goto cleanup;
}
@@ -82,10 +82,14 @@ launch_unix (guestfs_h *g, void *datav, const char *sockpath)
r = guestfs_int_recv_from_daemon (g, &size, &buf);
free (buf);
- if (r == -1) goto cleanup;
+ if (r == -1)
+ goto cleanup;
if (size != GUESTFS_LAUNCH_FLAG) {
- error (g, _("guestfs_launch failed, unexpected initial message from
guestfsd"));
+ error (
+ g,
+ _ (
+ "guestfs_launch failed, unexpected initial message from guestfsd"));
goto cleanup;
}
@@ -98,7 +102,7 @@ launch_unix (guestfs_h *g, void *datav, const char *sockpath)
return 0;
- cleanup:
+cleanup:
if (daemon_sock >= 0)
close (daemon_sock);
if (g->conn) {
@@ -118,9 +122,7 @@ shutdown_unix (guestfs_h *g, void *datav, int check_for_errors)
}
static struct backend_ops backend_unix_ops = {
- .data_size = 0,
- .launch = launch_unix,
- .shutdown = shutdown_unix,
+ .data_size = 0, .launch = launch_unix, .shutdown = shutdown_unix,
};
void
diff --git a/src/launch.c b/src/launch.c
index 7bc9cf9..eacbea5 100644
--- a/src/launch.c
+++ b/src/launch.c
@@ -62,15 +62,14 @@ guestfs_impl_launch (guestfs_h *g)
/* Some common debugging information. */
if (g->verbose) {
- CLEANUP_FREE_VERSION struct guestfs_version *v =
- guestfs_version (g);
+ CLEANUP_FREE_VERSION struct guestfs_version *v = guestfs_version (g);
struct backend *b;
CLEANUP_FREE char *backend = guestfs_get_backend (g);
debug (g, "launch: program=%s", g->program);
if (STRNEQ (g->identifier, ""))
debug (g, "launch: identifier=%s", g->identifier);
- debug (g, "launch:
version=%"PRIi64".%"PRIi64".%"PRIi64"%s",
+ debug (g, "launch: version=%" PRIi64 ".%" PRIi64 ".%"
PRIi64 "%s",
v->major, v->minor, v->release, v->extra);
for (b = backends; b != NULL; b = b->next)
@@ -79,7 +78,7 @@ guestfs_impl_launch (guestfs_h *g)
debug (g, "launch: tmpdir=%s", g->tmpdir);
debug (g, "launch: umask=0%03o", get_umask (g));
- debug (g, "launch: euid=%ju", (uintmax_t) geteuid ());
+ debug (g, "launch: euid=%ju", (uintmax_t)geteuid ());
}
/* Launch the appliance. */
@@ -112,8 +111,9 @@ guestfs_int_launch_send_progress (guestfs_h *g, int perdozen)
gettimeofday (&tv, NULL);
if (guestfs_int_timeval_diff (&g->launch_t, &tv) >= 5000) {
- guestfs_progress progress_message =
- { .proc = 0, .serial = 0, .position = perdozen, .total = 12 };
+ guestfs_progress progress_message = {
+ .proc = 0, .serial = 0, .position = perdozen, .total = 12
+ };
guestfs_int_progress_message_callback (g, &progress_message);
}
@@ -153,8 +153,9 @@ int
guestfs_impl_max_disks (guestfs_h *g)
{
if (g->backend_ops->max_disks == NULL)
- NOT_SUPPORTED (g, -1,
- _("the current backend does not allow max disks to be
queried"));
+ NOT_SUPPORTED (
+ g, -1,
+ _("the current backend does not allow max disks to be queried"));
return g->backend_ops->max_disks (g, g->backend_data);
}
@@ -165,7 +166,7 @@ guestfs_impl_max_disks (guestfs_h *g)
int
guestfs_impl_wait_ready (guestfs_h *g)
{
- if (g->state != READY) {
+ if (g->state != READY) {
error (g, _("qemu has not been launched yet"));
return -1;
}
@@ -213,8 +214,8 @@ guestfs_impl_get_state (guestfs_h *g)
/* Add arbitrary qemu parameters. Useful for testing. */
int
-guestfs_impl_config (guestfs_h *g,
- const char *hv_param, const char *hv_value)
+guestfs_impl_config (guestfs_h *g, const char *hv_param,
+ const char *hv_value)
{
struct hv_param *hp;
@@ -229,14 +230,10 @@ guestfs_impl_config (guestfs_h *g,
/* A bit fascist, but the user will probably break the extra
* parameters that we add if they try to set any of these.
*/
- if (STREQ (hv_param, "-kernel") ||
- STREQ (hv_param, "-initrd") ||
- STREQ (hv_param, "-nographic") ||
- STREQ (hv_param, "-display") ||
- STREQ (hv_param, "-serial") ||
- STREQ (hv_param, "-full-screen") ||
- STREQ (hv_param, "-std-vga") ||
- STREQ (hv_param, "-vnc")) {
+ if (STREQ (hv_param, "-kernel") || STREQ (hv_param, "-initrd") ||
+ STREQ (hv_param, "-nographic") || STREQ (hv_param, "-display")
||
+ STREQ (hv_param, "-serial") || STREQ (hv_param, "-full-screen")
||
+ STREQ (hv_param, "-std-vga") || STREQ (hv_param, "-vnc")) {
error (g, _("parameter '%s' isn't allowed"), hv_param);
return -1;
}
@@ -286,7 +283,7 @@ guestfs_impl_config (guestfs_h *g,
char *
guestfs_int_appliance_command_line (guestfs_h *g, const char *appliance_dev,
- int flags)
+ int flags)
{
char root[64] = "";
char *term = getenv ("TERM");
@@ -303,53 +300,49 @@ guestfs_int_appliance_command_line (guestfs_h *g, const char
*appliance_dev,
snprintf (lpj_s, sizeof lpj_s, " lpj=%d", lpj);
}
- ret = safe_asprintf
- (g,
- "panic=1" /* force kernel to panic if daemon exits */
+ ret = safe_asprintf (
+ g,
+ "panic=1" /* force kernel to panic if daemon exits */
#ifdef __arm__
- " mem=%dM"
+ " mem=%dM"
#endif
#ifdef __i386__
- " noapic" /* workaround for RHBZ#857026 */
+ " noapic" /* workaround for RHBZ#857026 */
#endif
- " " SERIAL_CONSOLE /* serial console */
- EARLYPRINTK /* get messages from early boot */
+ " " SERIAL_CONSOLE /* serial console */
+ EARLYPRINTK /* get messages from early boot */
#ifdef __aarch64__
- " ignore_loglevel"
- /* This option turns off the EFI RTC device. QEMU VMs don't
- * currently provide EFI, and if the device is compiled in it
- * will try to call the EFI function GetTime unconditionally
- * (causing a call to NULL). However this option requires a
- * non-upstream patch.
- */
- " efi-rtc=noprobe"
+ " ignore_loglevel"
+ /* This option turns off the EFI RTC device. QEMU VMs don't
+ * currently provide EFI, and if the device is compiled in it
+ * will try to call the EFI function GetTime unconditionally
+ * (causing a call to NULL). However this option requires a
+ * non-upstream patch.
+ */
+ " efi-rtc=noprobe"
#endif
- " udevtimeout=6000"/* for slow systems (RHBZ#480319, RHBZ#1096579) */
- " udev.event-timeout=6000" /* for newer udevd */
- " no_timer_check" /* fix for RHBZ#502058 */
- "%s" /* lpj */
- " acpi=off" /* ACPI is slow - 150-200ms extra on my laptop */
- " printk.time=1" /* display timestamp before kernel messages */
- " cgroup_disable=memory" /* saves us about 5 MB of RAM */
- "%s" /* root=appliance_dev */
- " %s" /* selinux */
- " %s" /* quiet/verbose */
- "%s" /* network */
- " TERM=%s" /* TERM environment variable */
- "%s%s" /* handle identifier */
- "%s%s", /* append */
+ " udevtimeout=6000" /* for slow systems (RHBZ#480319, RHBZ#1096579) */
+ " udev.event-timeout=6000" /* for newer udevd */
+ " no_timer_check" /* fix for RHBZ#502058 */
+ "%s" /* lpj */
+ " acpi=off" /* ACPI is slow - 150-200ms extra on my laptop */
+ " printk.time=1" /* display timestamp before kernel messages */
+ " cgroup_disable=memory" /* saves us about 5 MB of RAM */
+ "%s" /* root=appliance_dev */
+ " %s" /* selinux */
+ " %s" /* quiet/verbose */
+ "%s" /* network */
+ " TERM=%s" /* TERM environment variable */
+ "%s%s" /* handle identifier */
+ "%s%s", /* append */
#ifdef __arm__
- g->memsize,
+ g->memsize,
#endif
- lpj_s,
- root,
- g->selinux ? "selinux=1 enforcing=0" : "selinux=0",
- g->verbose ? "guestfs_verbose=1" : "quiet",
- g->enable_network ? " guestfs_network=1" : "",
- term ? term : "linux",
- STRNEQ (g->identifier, "") ? " guestfs_identifier=" :
"",
- g->identifier,
- g->append ? " " : "", g->append ? g->append :
"");
+ lpj_s, root, g->selinux ? "selinux=1 enforcing=0" :
"selinux=0",
+ g->verbose ? "guestfs_verbose=1" : "quiet",
+ g->enable_network ? " guestfs_network=1" : "", term ? term :
"linux",
+ STRNEQ (g->identifier, "") ? " guestfs_identifier=" :
"", g->identifier,
+ g->append ? " " : "", g->append ? g->append :
"");
return ret;
}
@@ -403,7 +396,7 @@ guestfs_int_create_socketname (guestfs_h *g, const char *filename,
if (guestfs_int_lazy_make_sockdir (g) == -1)
return -1;
- if (strlen (g->sockdir) + 1 + strlen (filename) > UNIX_PATH_MAX-1) {
+ if (strlen (g->sockdir) + 1 + strlen (filename) > UNIX_PATH_MAX - 1) {
error (g, _("socket path too long: %s/%s"), g->sockdir, filename);
return -1;
}
@@ -424,9 +417,11 @@ get_umask (guestfs_h *g)
mode_t ret;
int fd;
struct stat statbuf;
- CLEANUP_FREE char *filename = safe_asprintf (g, "%s/umask-check",
g->tmpdir);
+ CLEANUP_FREE char *filename =
+ safe_asprintf (g, "%s/umask-check", g->tmpdir);
- fd = open (filename, O_WRONLY|O_CREAT|O_TRUNC|O_NOCTTY|O_CLOEXEC, 0777);
+ fd = open (filename, O_WRONLY | O_CREAT | O_TRUNC | O_NOCTTY | O_CLOEXEC,
+ 0777);
if (fd == -1)
return -1;
@@ -446,12 +441,14 @@ get_umask (guestfs_h *g)
/* Register backends in a global list when the library is loaded. */
void
-guestfs_int_register_backend (const char *name, const struct backend_ops *ops)
+guestfs_int_register_backend (const char *name,
+ const struct backend_ops *ops)
{
struct backend *b;
b = malloc (sizeof *b);
- if (!b) abort ();
+ if (!b)
+ abort ();
b->name = name;
b->ops = ops;
@@ -482,13 +479,13 @@ guestfs_int_set_backend (guestfs_h *g, const char *method)
break;
len = strlen (b->name);
if (STRPREFIX (method, b->name) && method[len] == ':') {
- arg_offs = len+1;
+ arg_offs = len + 1;
break;
}
}
if (b == NULL)
- return -1; /* Not found. */
+ return -1; /* Not found. */
/* At this point, we know it's a valid method. */
free (g->backend);
@@ -512,12 +509,10 @@ guestfs_int_set_backend (guestfs_h *g, const char *method)
/* This hack is only required to make static linking work. See:
*
https://stackoverflow.com/questions/1202494/why-doesnt-attribute-construc...
*/
-void *
-guestfs_int_force_load_backends[] = {
+void *guestfs_int_force_load_backends[] = {
guestfs_int_init_direct_backend,
#ifdef HAVE_LIBVIRT_BACKEND
guestfs_int_init_libvirt_backend,
#endif
- guestfs_int_init_uml_backend,
- guestfs_int_init_unix_backend,
+ guestfs_int_init_uml_backend, guestfs_int_init_unix_backend,
};
diff --git a/src/libvirt-auth.c b/src/libvirt-auth.c
index cbc2461..4963e6b 100644
--- a/src/libvirt-auth.c
+++ b/src/libvirt-auth.c
@@ -28,7 +28,6 @@
#include <libvirt/virterror.h>
#endif
-
#include "guestfs.h"
#include "guestfs-internal.h"
#include "guestfs-internal-actions.h"
@@ -39,15 +38,15 @@ static struct {
int credtype;
const char *credname;
} libvirt_credential_types[NR_CREDENTIAL_TYPES] = {
- { VIR_CRED_USERNAME, "username" },
- { VIR_CRED_AUTHNAME, "authname" },
- { VIR_CRED_LANGUAGE, "language" },
- { VIR_CRED_CNONCE, "cnonce" },
- { VIR_CRED_PASSPHRASE, "passphrase" },
- { VIR_CRED_ECHOPROMPT, "echoprompt" },
+ { VIR_CRED_USERNAME, "username" },
+ { VIR_CRED_AUTHNAME, "authname" },
+ { VIR_CRED_LANGUAGE, "language" },
+ { VIR_CRED_CNONCE, "cnonce" },
+ { VIR_CRED_PASSPHRASE, "passphrase" },
+ { VIR_CRED_ECHOPROMPT, "echoprompt" },
{ VIR_CRED_NOECHOPROMPT, "noechoprompt" },
- { VIR_CRED_REALM, "realm" },
- { VIR_CRED_EXTERNAL, "external" },
+ { VIR_CRED_REALM, "realm" },
+ { VIR_CRED_EXTERNAL, "external" },
};
static int
@@ -79,7 +78,8 @@ get_string_of_credtype (int credtype)
* an error or not, so don't depend on the current behaviour.
*/
int
-guestfs_impl_set_libvirt_supported_credentials (guestfs_h *g, char *const *creds)
+guestfs_impl_set_libvirt_supported_credentials (guestfs_h *g,
+ char *const *creds)
{
size_t i;
int credtype;
@@ -106,7 +106,8 @@ guestfs_impl_set_libvirt_supported_credentials (guestfs_h *g, char
*const *creds
}
g->nr_supported_credentials = ncredtypes;
- memcpy (g->supported_credentials, credtypes, sizeof g->supported_credentials);
+ memcpy (g->supported_credentials, credtypes,
+ sizeof g->supported_credentials);
return 0;
}
@@ -115,8 +116,7 @@ guestfs_impl_set_libvirt_supported_credentials (guestfs_h *g, char
*const *creds
* libguestfs event to collect the desired credentials.
*/
static int
-libvirt_auth_callback (virConnectCredentialPtr cred,
- unsigned int ncred,
+libvirt_auth_callback (virConnectCredentialPtr cred, unsigned int ncred,
void *gv)
{
guestfs_h *g = gv;
@@ -135,8 +135,8 @@ libvirt_auth_callback (virConnectCredentialPtr cred,
g->nr_requested_credentials = ncred;
guestfs_int_call_callbacks_message (g, GUESTFS_EVENT_LIBVIRT_AUTH,
- g->saved_libvirt_uri,
- strlen (g->saved_libvirt_uri));
+ g->saved_libvirt_uri,
+ strlen (g->saved_libvirt_uri));
/* Clarified with Dan that it is not an error for some fields to be
* left as NULL.
@@ -157,14 +157,14 @@ libvirt_auth_callback (virConnectCredentialPtr cred,
*/
static int
libvirt_auth_default_wrapper (virConnectCredentialPtr cred,
- unsigned int ncred,
- void *gv)
+ unsigned int ncred, void *gv)
{
guestfs_h *g = gv;
if (!g->wrapper_warning_done) {
printf (_("libvirt needs authentication to connect to libvirt URI %s\n"
- "(see also:
http://libvirt.org/auth.html
http://libvirt.org/uri.html)\n"),
+ "(see also:
http://libvirt.org/auth.html "
+ "http://libvirt.org/uri.html)\n"),
g->saved_libvirt_uri ? g->saved_libvirt_uri : "NULL");
g->wrapper_warning_done = true;
}
@@ -188,7 +188,7 @@ exists_libvirt_auth_event (guestfs_h *g)
/* Open a libvirt connection (called from other parts of the library). */
virConnectPtr
guestfs_int_open_libvirt_connection (guestfs_h *g, const char *uri,
- unsigned int flags)
+ unsigned int flags)
{
virConnectAuth authdata;
virConnectPtr conn;
@@ -237,11 +237,12 @@ guestfs_int_open_libvirt_connection (guestfs_h *g, const char *uri,
/* The calls below are meant to be called recursively from
* the GUESTFS_EVENT_LIBVIRT_AUTH event.
*/
-#define CHECK_IN_EVENT_HANDLER(r) \
- if (g->nr_requested_credentials == 0) { \
- error (g, _("%s should only be called from within the GUESTFS_EVENT_LIBVIRT_AUTH
event handler"), \
- __func__); \
- return r; \
+#define CHECK_IN_EVENT_HANDLER(r) \
+ if (g->nr_requested_credentials == 0) { \
+ error (g, _("%s should only be called from within the " \
+ "GUESTFS_EVENT_LIBVIRT_AUTH event handler"), \
+ __func__); \
+ return r; \
}
char **
@@ -254,22 +255,23 @@ guestfs_impl_get_libvirt_requested_credentials (guestfs_h *g)
/* Convert the requested_credentials types to a list of strings. */
for (i = 0; i < g->nr_requested_credentials; ++i)
- guestfs_int_add_string (g, &ret,
- get_string_of_credtype (g->requested_credentials[i].type));
+ guestfs_int_add_string (
+ g, &ret, get_string_of_credtype (g->requested_credentials[i].type));
guestfs_int_end_stringsbuf (g, &ret);
- return ret.argv; /* caller frees */
+ return ret.argv; /* caller frees */
}
char *
-guestfs_impl_get_libvirt_requested_credential_prompt (guestfs_h *g, int index)
+guestfs_impl_get_libvirt_requested_credential_prompt (guestfs_h *g,
+ int index)
{
size_t i;
CHECK_IN_EVENT_HANDLER (NULL);
- if (index >= 0 && (unsigned int) index < g->nr_requested_credentials)
- i = (size_t) index;
+ if (index >= 0 && (unsigned int)index < g->nr_requested_credentials)
+ i = (size_t)index;
else {
error (g, _("credential index out of range"));
return NULL;
@@ -282,14 +284,15 @@ guestfs_impl_get_libvirt_requested_credential_prompt (guestfs_h *g,
int index)
}
char *
-guestfs_impl_get_libvirt_requested_credential_challenge (guestfs_h *g, int index)
+guestfs_impl_get_libvirt_requested_credential_challenge (guestfs_h *g,
+ int index)
{
size_t i;
CHECK_IN_EVENT_HANDLER (NULL);
- if (index >= 0 && (unsigned int) index < g->nr_requested_credentials)
- i = (size_t) index;
+ if (index >= 0 && (unsigned int)index < g->nr_requested_credentials)
+ i = (size_t)index;
else {
error (g, _("credential index out of range"));
return NULL;
@@ -302,14 +305,15 @@ guestfs_impl_get_libvirt_requested_credential_challenge (guestfs_h
*g, int index
}
char *
-guestfs_impl_get_libvirt_requested_credential_defresult (guestfs_h *g, int index)
+guestfs_impl_get_libvirt_requested_credential_defresult (guestfs_h *g,
+ int index)
{
size_t i;
CHECK_IN_EVENT_HANDLER (NULL);
- if (index >= 0 && (unsigned int) index < g->nr_requested_credentials)
- i = (size_t) index;
+ if (index >= 0 && (unsigned int)index < g->nr_requested_credentials)
+ i = (size_t)index;
else {
error (g, _("credential index out of range"));
return NULL;
@@ -323,21 +327,23 @@ guestfs_impl_get_libvirt_requested_credential_defresult (guestfs_h
*g, int index
int
guestfs_impl_set_libvirt_requested_credential (guestfs_h *g, int index,
- const char *cred, size_t cred_size)
+ const char *cred,
+ size_t cred_size)
{
size_t i;
CHECK_IN_EVENT_HANDLER (-1);
- if (index >= 0 && (unsigned int) index < g->nr_requested_credentials)
- i = (size_t) index;
+ if (index >= 0 && (unsigned int)index < g->nr_requested_credentials)
+ i = (size_t)index;
else {
error (g, _("credential index out of range"));
return -1;
}
/* All the evidence is that libvirt will free this. */
- g->requested_credentials[i].result = safe_malloc (g, cred_size+1 /* sic */);
+ g->requested_credentials[i].result =
+ safe_malloc (g, cred_size + 1 /* sic */);
memcpy (g->requested_credentials[i].result, cred, cred_size);
/* Some libvirt drivers are buggy (eg. libssh2), and they expect
* that the cred field will be \0 terminated. To avoid surprises,
@@ -351,44 +357,51 @@ guestfs_impl_set_libvirt_requested_credential (guestfs_h *g, int
index,
#else /* no libvirt at compile time */
-#define NOT_IMPL(r) \
- error (g, _("libvirt authentication APIs not available since this version of
libguestfs was compiled without libvirt")); \
+#define NOT_IMPL(r) \
+ error (g, _("libvirt authentication APIs not available since this " \
+ "version of libguestfs was compiled without libvirt")); \
return r
int
-guestfs_impl_set_libvirt_supported_credentials (guestfs_h *g, char *const *creds)
+guestfs_impl_set_libvirt_supported_credentials (guestfs_h *g,
+ char *const *creds)
{
- NOT_IMPL(-1);
+ NOT_IMPL (-1);
}
char **
guestfs_impl_get_libvirt_requested_credentials (guestfs_h *g)
{
- NOT_IMPL(NULL);
+ NOT_IMPL (NULL);
}
char *
-guestfs_impl_get_libvirt_requested_credential_prompt (guestfs_h *g, int index)
+guestfs_impl_get_libvirt_requested_credential_prompt (guestfs_h *g,
+ int index)
{
- NOT_IMPL(NULL);
+ NOT_IMPL (NULL);
}
char *
-guestfs_impl_get_libvirt_requested_credential_challenge (guestfs_h *g, int index)
+guestfs_impl_get_libvirt_requested_credential_challenge (guestfs_h *g,
+ int index)
{
- NOT_IMPL(NULL);
+ NOT_IMPL (NULL);
}
char *
-guestfs_impl_get_libvirt_requested_credential_defresult (guestfs_h *g, int index)
+guestfs_impl_get_libvirt_requested_credential_defresult (guestfs_h *g,
+ int index)
{
- NOT_IMPL(NULL);
+ NOT_IMPL (NULL);
}
int
-guestfs_impl_set_libvirt_requested_credential (guestfs_h *g, int index, const char *cred,
size_t cred_size)
+guestfs_impl_set_libvirt_requested_credential (guestfs_h *g, int index,
+ const char *cred,
+ size_t cred_size)
{
- NOT_IMPL(-1);
+ NOT_IMPL (-1);
}
#endif /* no libvirt at compile time */
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index b096fb3..36b05d8 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -40,8 +40,15 @@
#if defined(HAVE_LIBVIRT)
static xmlDocPtr get_domain_xml (guestfs_h *g, virDomainPtr dom);
-static ssize_t for_each_disk (guestfs_h *g, xmlDocPtr doc, int (*f) (guestfs_h *g, const
char *filename, const char *format, int readonly, const char *protocol, char *const
*server, const char *username, void *data), void *data);
-static int libvirt_selinux_label (guestfs_h *g, xmlDocPtr doc, char **label_rtn, char
**imagelabel_rtn);
+static ssize_t for_each_disk (guestfs_h *g, xmlDocPtr doc,
+ int (*f) (guestfs_h *g, const char *filename,
+ const char *format, int readonly,
+ const char *protocol,
+ char *const *server,
+ const char *username, void *data),
+ void *data);
+static int libvirt_selinux_label (guestfs_h *g, xmlDocPtr doc,
+ char **label_rtn, char **imagelabel_rtn);
static void
ignore_errors (void *ignore, virErrorPtr ignore2)
@@ -51,7 +58,7 @@ ignore_errors (void *ignore, virErrorPtr ignore2)
int
guestfs_impl_add_domain (guestfs_h *g, const char *domain_name,
- const struct guestfs_add_domain_argv *optargs)
+ const struct guestfs_add_domain_argv *optargs)
{
virErrorPtr err;
virConnectPtr conn = NULL;
@@ -66,26 +73,34 @@ guestfs_impl_add_domain (guestfs_h *g, const char *domain_name,
const char *cachemode;
const char *discard;
bool copyonread;
- struct guestfs_add_libvirt_dom_argv optargs2 = { .bitmask = 0 };
+ struct guestfs_add_libvirt_dom_argv optargs2 = {.bitmask = 0 };
libvirturi = optargs->bitmask & GUESTFS_ADD_DOMAIN_LIBVIRTURI_BITMASK
- ? optargs->libvirturi : NULL;
+ ? optargs->libvirturi
+ : NULL;
readonly = optargs->bitmask & GUESTFS_ADD_DOMAIN_READONLY_BITMASK
- ? optargs->readonly : 0;
+ ? optargs->readonly
+ : 0;
iface = optargs->bitmask & GUESTFS_ADD_DOMAIN_IFACE_BITMASK
- ? optargs->iface : NULL;
- live = optargs->bitmask & GUESTFS_ADD_DOMAIN_LIVE_BITMASK
- ? optargs->live : 0;
+ ? optargs->iface
+ : NULL;
+ live =
+ optargs->bitmask & GUESTFS_ADD_DOMAIN_LIVE_BITMASK ? optargs->live : 0;
allowuuid = optargs->bitmask & GUESTFS_ADD_DOMAIN_ALLOWUUID_BITMASK
- ? optargs->allowuuid : 0;
+ ? optargs->allowuuid
+ : 0;
readonlydisk = optargs->bitmask & GUESTFS_ADD_DOMAIN_READONLYDISK_BITMASK
- ? optargs->readonlydisk : NULL;
+ ? optargs->readonlydisk
+ : NULL;
cachemode = optargs->bitmask & GUESTFS_ADD_DOMAIN_CACHEMODE_BITMASK
- ? optargs->cachemode : NULL;
+ ? optargs->cachemode
+ : NULL;
discard = optargs->bitmask & GUESTFS_ADD_DOMAIN_DISCARD_BITMASK
- ? optargs->discard : NULL;
+ ? optargs->discard
+ : NULL;
copyonread = optargs->bitmask & GUESTFS_ADD_DOMAIN_COPYONREAD_BITMASK
- ? optargs->copyonread : false;
+ ? optargs->copyonread
+ : false;
if (live && readonly) {
error (g, _("you cannot set both live and readonly flags"));
@@ -93,7 +108,8 @@ guestfs_impl_add_domain (guestfs_h *g, const char *domain_name,
}
/* Connect to libvirt, find the domain. */
- conn = guestfs_int_open_libvirt_connection (g, libvirturi, VIR_CONNECT_RO);
+ conn =
+ guestfs_int_open_libvirt_connection (g, libvirturi, VIR_CONNECT_RO);
if (!conn) {
err = virGetLastError ();
error (g, _("could not connect to libvirt (code %d, domain %d): %s"),
@@ -117,8 +133,8 @@ guestfs_impl_add_domain (guestfs_h *g, const char *domain_name,
if (!dom) {
err = virGetLastError ();
- error (g, _("no libvirt domain called '%s': %s"),
- domain_name, err->message);
+ error (g, _("no libvirt domain called '%s': %s"), domain_name,
+ err->message);
goto cleanup;
}
@@ -153,14 +169,18 @@ guestfs_impl_add_domain (guestfs_h *g, const char *domain_name,
r = guestfs_add_libvirt_dom_argv (g, dom, &optargs2);
- cleanup:
- if (dom) virDomainFree (dom);
- if (conn) virConnectClose (conn);
+cleanup:
+ if (dom)
+ virDomainFree (dom);
+ if (conn)
+ virConnectClose (conn);
return r;
}
-static int add_disk (guestfs_h *g, const char *filename, const char *format, int
readonly, const char *protocol, char *const *server, const char *username, void *data);
+static int add_disk (guestfs_h *g, const char *filename, const char *format,
+ int readonly, const char *protocol,
+ char *const *server, const char *username, void *data);
static int connect_live (guestfs_h *g, virDomainPtr dom);
enum readonlydisk {
@@ -178,8 +198,9 @@ struct add_disk_data {
};
int
-guestfs_impl_add_libvirt_dom (guestfs_h *g, void *domvp,
- const struct guestfs_add_libvirt_dom_argv *optargs)
+guestfs_impl_add_libvirt_dom (
+ guestfs_h *g, void *domvp,
+ const struct guestfs_add_libvirt_dom_argv *optargs)
{
virDomainPtr dom = domvp;
ssize_t r;
@@ -196,15 +217,15 @@ guestfs_impl_add_libvirt_dom (guestfs_h *g, void *domvp,
CLEANUP_XMLFREEDOC xmlDocPtr doc = NULL;
CLEANUP_FREE char *label = NULL, *imagelabel = NULL;
- readonly =
- optargs->bitmask & GUESTFS_ADD_LIBVIRT_DOM_READONLY_BITMASK
- ? optargs->readonly : 0;
- iface =
- optargs->bitmask & GUESTFS_ADD_LIBVIRT_DOM_IFACE_BITMASK
- ? optargs->iface : NULL;
- live =
- optargs->bitmask & GUESTFS_ADD_LIBVIRT_DOM_LIVE_BITMASK
- ? optargs->live : 0;
+ readonly = optargs->bitmask & GUESTFS_ADD_LIBVIRT_DOM_READONLY_BITMASK
+ ? optargs->readonly
+ : 0;
+ iface = optargs->bitmask & GUESTFS_ADD_LIBVIRT_DOM_IFACE_BITMASK
+ ? optargs->iface
+ : NULL;
+ live = optargs->bitmask & GUESTFS_ADD_LIBVIRT_DOM_LIVE_BITMASK
+ ? optargs->live
+ : 0;
if ((optargs->bitmask & GUESTFS_ADD_LIBVIRT_DOM_READONLYDISK_BITMASK)) {
if (STREQ (optargs->readonlydisk, "error"))
@@ -221,17 +242,17 @@ guestfs_impl_add_libvirt_dom (guestfs_h *g, void *domvp,
}
}
- cachemode =
- optargs->bitmask & GUESTFS_ADD_LIBVIRT_DOM_CACHEMODE_BITMASK
- ? optargs->cachemode : NULL;
+ cachemode = optargs->bitmask & GUESTFS_ADD_LIBVIRT_DOM_CACHEMODE_BITMASK
+ ? optargs->cachemode
+ : NULL;
- discard =
- optargs->bitmask & GUESTFS_ADD_LIBVIRT_DOM_DISCARD_BITMASK
- ? optargs->discard : NULL;
+ discard = optargs->bitmask & GUESTFS_ADD_LIBVIRT_DOM_DISCARD_BITMASK
+ ? optargs->discard
+ : NULL;
- copyonread =
- optargs->bitmask & GUESTFS_ADD_LIBVIRT_DOM_COPYONREAD_BITMASK
- ? optargs->copyonread : false;
+ copyonread = optargs->bitmask & GUESTFS_ADD_LIBVIRT_DOM_COPYONREAD_BITMASK
+ ? optargs->copyonread
+ : false;
if (live && readonly) {
error (g, _("you cannot set both live and readonly flags"));
@@ -260,10 +281,14 @@ guestfs_impl_add_libvirt_dom (guestfs_h *g, void *domvp,
/* Dangerous to modify the disks of a running VM. */
error (g, _("error: domain is a live virtual machine.\n"
- "Writing to the disks of a running virtual machine can cause disk
corruption.\n"
- "Either use read-only access, or if the guest is running the
guestfsd daemon\n"
- "specify live access. In most libguestfs tools these options are
--ro or\n"
- "--live respectively. Consult the documentation for further
information."));
+ "Writing to the disks of a running virtual machine can "
+ "cause disk corruption.\n"
+ "Either use read-only access, or if the guest is "
+ "running the guestfsd daemon\n"
+ "specify live access. In most libguestfs tools these "
+ "options are --ro or\n"
+ "--live respectively. Consult the documentation for "
+ "further information."));
return -1;
}
}
@@ -280,8 +305,10 @@ guestfs_impl_add_libvirt_dom (guestfs_h *g, void *domvp,
return -1;
if (label && imagelabel) {
guestfs_set_backend_setting (g, "internal_libvirt_label", label);
- guestfs_set_backend_setting (g, "internal_libvirt_imagelabel",
imagelabel);
- guestfs_set_backend_setting (g, "internal_libvirt_norelabel_disks",
"1");
+ guestfs_set_backend_setting (g, "internal_libvirt_imagelabel",
+ imagelabel);
+ guestfs_set_backend_setting (g, "internal_libvirt_norelabel_disks",
+ "1");
}
else
guestfs_clear_backend_setting (g, "internal_libvirt_norelabel_disks");
@@ -319,40 +346,58 @@ guestfs_impl_add_libvirt_dom (guestfs_h *g, void *domvp,
}
static int
-add_disk (guestfs_h *g,
- const char *filename, const char *format, int readonly_in_xml,
- const char *protocol, char *const *server, const char *username,
- void *datavp)
+add_disk (guestfs_h *g, const char *filename, const char *format,
+ int readonly_in_xml, const char *protocol, char *const *server,
+ const char *username, void *datavp)
{
struct add_disk_data *data = datavp;
/* Copy whole struct so we can make local changes: */
struct guestfs_add_drive_opts_argv optargs = data->optargs;
int readonly = -1, error = 0, skip = 0;
- if (readonly_in_xml) { /* <readonly/> appears in the XML */
- if (data->readonly) { /* asked to add disk read-only */
+ if (readonly_in_xml) { /* <readonly/> appears in the XML */
+ if (data->readonly) { /* asked to add disk read-only */
switch (data->readonlydisk) {
- case readonlydisk_error: readonly = 1; break;
- case readonlydisk_read: readonly = 1; break;
- case readonlydisk_write: readonly = 1; break;
- case readonlydisk_ignore: skip = 1; break;
+ case readonlydisk_error:
+ readonly = 1;
+ break;
+ case readonlydisk_read:
+ readonly = 1;
+ break;
+ case readonlydisk_write:
+ readonly = 1;
+ break;
+ case readonlydisk_ignore:
+ skip = 1;
+ break;
}
- } else { /* asked to add disk for read/write */
+ }
+ else { /* asked to add disk for read/write */
switch (data->readonlydisk) {
- case readonlydisk_error: error = 1; break;
- case readonlydisk_read: readonly = 1; break;
- case readonlydisk_write: readonly = 0; break;
- case readonlydisk_ignore: skip = 1; break;
+ case readonlydisk_error:
+ error = 1;
+ break;
+ case readonlydisk_read:
+ readonly = 1;
+ break;
+ case readonlydisk_write:
+ readonly = 0;
+ break;
+ case readonlydisk_ignore:
+ skip = 1;
+ break;
}
}
- } else /* no <readonly/> in XML */
+ }
+ else /* no <readonly/> in XML */
readonly = data->readonly;
if (skip)
return 0;
if (error) {
- error (g, _("%s: disk is marked <readonly/> in libvirt XML, and
readonlydisk was set to \"error\""),
+ error (g, _("%s: disk is marked <readonly/> in libvirt XML, and "
+ "readonlydisk was set to \"error\""),
filename);
return -1;
}
@@ -390,8 +435,8 @@ add_disk (guestfs_h *g,
*
https://bugzilla.redhat.com/show_bug.cgi?id=912499#c7
*/
static int
-libvirt_selinux_label (guestfs_h *g, xmlDocPtr doc,
- char **label_rtn, char **imagelabel_rtn)
+libvirt_selinux_label (guestfs_h *g, xmlDocPtr doc, char **label_rtn,
+ char **imagelabel_rtn)
{
CLEANUP_XMLXPATHFREECONTEXT xmlXPathContextPtr xpathCtx = NULL;
CLEANUP_XMLXPATHFREEOBJECT xmlXPathObjectPtr xpathObj = NULL;
@@ -445,14 +490,14 @@ libvirt_selinux_label (guestfs_h *g, xmlDocPtr doc,
/* Find the <label/> and <imagelabel/> child nodes. */
for (child = node->children; child != NULL; child = child->next) {
- if (!gotlabel && STREQ ((char *) child->name, "label")) {
+ if (!gotlabel && STREQ ((char *)child->name, "label")) {
/* Get the label content. */
- *label_rtn = (char *) xmlNodeGetContent (child);
+ *label_rtn = (char *)xmlNodeGetContent (child);
gotlabel = 1;
}
- if (!gotimagelabel && STREQ ((char *) child->name,
"imagelabel")) {
+ if (!gotimagelabel && STREQ ((char *)child->name, "imagelabel"))
{
/* Get the imagelabel content. */
- *imagelabel_rtn = (char *) xmlNodeGetContent (child);
+ *imagelabel_rtn = (char *)xmlNodeGetContent (child);
gotimagelabel = 1;
}
}
@@ -465,14 +510,11 @@ libvirt_selinux_label (guestfs_h *g, xmlDocPtr doc,
* Returns number of disks, or -1 if there was an error.
*/
static ssize_t
-for_each_disk (guestfs_h *g,
- xmlDocPtr doc,
- int (*f) (guestfs_h *g,
- const char *filename, const char *format,
- int readonly,
+for_each_disk (guestfs_h *g, xmlDocPtr doc,
+ int (*f) (guestfs_h *g, const char *filename,
+ const char *format, int readonly,
const char *protocol, char *const *server,
- const char *username,
- void *data),
+ const char *username, void *data),
void *data)
{
size_t i, nr_added = 0, nr_nodes;
@@ -500,7 +542,8 @@ for_each_disk (guestfs_h *g,
if (nodes != NULL) {
nr_nodes = nodes->nodeNr;
for (i = 0; i < nr_nodes; ++i) {
- CLEANUP_FREE char *type = NULL, *filename = NULL, *format = NULL, *protocol = NULL,
*username = NULL;
+ CLEANUP_FREE char *type = NULL, *filename = NULL, *format = NULL,
+ *protocol = NULL, *username = NULL;
CLEANUP_FREE_STRING_LIST char **server = NULL;
CLEANUP_XMLXPATHFREEOBJECT xmlXPathObjectPtr xptype = NULL;
CLEANUP_XMLXPATHFREEOBJECT xmlXPathObjectPtr xpformat = NULL;
@@ -523,76 +566,75 @@ for_each_disk (guestfs_h *g,
* Check the <disk type=..> attribute first to find out which one.
*/
xptype = xmlXPathEvalExpression (BAD_CAST "./@type", xpathCtx);
- if (xptype == NULL ||
- xptype->nodesetval == NULL ||
+ if (xptype == NULL || xptype->nodesetval == NULL ||
xptype->nodesetval->nodeNr == 0) {
- continue; /* no type attribute, skip it */
+ continue; /* no type attribute, skip it */
}
assert (xptype->nodesetval->nodeTab[0]);
assert (xptype->nodesetval->nodeTab[0]->type == XML_ATTRIBUTE_NODE);
- attr = (xmlAttrPtr) xptype->nodesetval->nodeTab[0];
- type = (char *) xmlNodeListGetString (doc, attr->children, 1);
+ attr = (xmlAttrPtr)xptype->nodesetval->nodeTab[0];
+ type = (char *)xmlNodeListGetString (doc, attr->children, 1);
- if (STREQ (type, "file")) { /* type = "file" so look at
source/@file */
+ if (STREQ (type,
+ "file")) { /* type = "file" so look at source/@file
*/
xpathCtx->node = nodes->nodeTab[i];
- xpfilename = xmlXPathEvalExpression (BAD_CAST "./source/@file",
- xpathCtx);
- if (xpfilename == NULL ||
- xpfilename->nodesetval == NULL ||
+ xpfilename =
+ xmlXPathEvalExpression (BAD_CAST "./source/@file", xpathCtx);
+ if (xpfilename == NULL || xpfilename->nodesetval == NULL ||
xpfilename->nodesetval->nodeNr == 0)
- continue; /* disk filename not found, skip this */
- } else if (STREQ (type, "block")) { /* type = "block", use
source/@dev */
+ continue; /* disk filename not found, skip this */
+ }
+ else if (STREQ (type,
+ "block")) { /* type = "block", use source/@dev
*/
xpathCtx->node = nodes->nodeTab[i];
- xpfilename = xmlXPathEvalExpression (BAD_CAST "./source/@dev",
- xpathCtx);
- if (xpfilename == NULL ||
- xpfilename->nodesetval == NULL ||
+ xpfilename =
+ xmlXPathEvalExpression (BAD_CAST "./source/@dev", xpathCtx);
+ if (xpfilename == NULL || xpfilename->nodesetval == NULL ||
xpfilename->nodesetval->nodeNr == 0)
- continue; /* disk filename not found, skip this */
- } else if (STREQ (type, "network")) { /* type = "network", use
source/@name */
+ continue; /* disk filename not found, skip this */
+ }
+ else if (STREQ (type,
+ "network")) { /* type = "network", use
source/@name */
int hi;
debug (g, _("disk[%zu]: network device"), i);
xpathCtx->node = nodes->nodeTab[i];
/* Get the protocol (e.g. "rbd"). Required. */
- xpprotocol = xmlXPathEvalExpression (BAD_CAST "./source/@protocol",
- xpathCtx);
- if (xpprotocol == NULL ||
- xpprotocol->nodesetval == NULL ||
+ xpprotocol =
+ xmlXPathEvalExpression (BAD_CAST "./source/@protocol", xpathCtx);
+ if (xpprotocol == NULL || xpprotocol->nodesetval == NULL ||
xpprotocol->nodesetval->nodeNr == 0)
continue;
assert (xpprotocol->nodesetval->nodeTab[0]);
assert (xpprotocol->nodesetval->nodeTab[0]->type ==
XML_ATTRIBUTE_NODE);
- attr = (xmlAttrPtr) xpprotocol->nodesetval->nodeTab[0];
- protocol = (char *) xmlNodeListGetString (doc, attr->children, 1);
+ attr = (xmlAttrPtr)xpprotocol->nodesetval->nodeTab[0];
+ protocol = (char *)xmlNodeListGetString (doc, attr->children, 1);
debug (g, _("disk[%zu]: protocol: %s"), i, protocol);
/* <source name="..."> is the path/exportname. Optional. */
- xpfilename = xmlXPathEvalExpression (BAD_CAST "./source/@name",
- xpathCtx);
- if (xpfilename == NULL ||
- xpfilename->nodesetval == NULL)
+ xpfilename =
+ xmlXPathEvalExpression (BAD_CAST "./source/@name", xpathCtx);
+ if (xpfilename == NULL || xpfilename->nodesetval == NULL)
continue;
/* <auth username="...">. Optional. */
- xpusername = xmlXPathEvalExpression (BAD_CAST "./auth/@username",
- xpathCtx);
- if (xpusername != NULL &&
- xpusername->nodesetval != NULL &&
+ xpusername =
+ xmlXPathEvalExpression (BAD_CAST "./auth/@username", xpathCtx);
+ if (xpusername != NULL && xpusername->nodesetval != NULL &&
xpusername->nodesetval->nodeNr != 0) {
assert (xpusername->nodesetval->nodeTab[0]);
- assert (xpusername->nodesetval->nodeTab[0]->type ==
XML_ATTRIBUTE_NODE);
- attr = (xmlAttrPtr) xpusername->nodesetval->nodeTab[0];
- username = (char *) xmlNodeListGetString (doc, attr->children, 1);
+ assert (xpusername->nodesetval->nodeTab[0]->type ==
+ XML_ATTRIBUTE_NODE);
+ attr = (xmlAttrPtr)xpusername->nodesetval->nodeTab[0];
+ username = (char *)xmlNodeListGetString (doc, attr->children, 1);
debug (g, _("disk[%zu]: username: %s"), i, username);
}
- xphost = xmlXPathEvalExpression (BAD_CAST "./source/host",
- xpathCtx);
- if (xphost == NULL ||
- xphost->nodesetval == NULL)
+ xphost =
+ xmlXPathEvalExpression (BAD_CAST "./source/host", xpathCtx);
+ if (xphost == NULL || xphost->nodesetval == NULL)
continue;
/* This gives us a list of <host> elements, which each have a
@@ -600,19 +642,19 @@ for_each_disk (guestfs_h *g,
* string, joined by a ':'.
*/
server = safe_malloc (g, sizeof (char *) *
- (xphost->nodesetval->nodeNr + 1));
- for (hi = 0; hi < xphost->nodesetval->nodeNr ; hi++) {
+ (xphost->nodesetval->nodeNr + 1));
+ for (hi = 0; hi < xphost->nodesetval->nodeNr; hi++) {
xmlChar *name, *port;
xmlNodePtr h = xphost->nodesetval->nodeTab[hi];
assert (h);
assert (h->type == XML_ELEMENT_NODE);
- name = xmlGetProp(h, BAD_CAST "name");
- assert(name);
- port = xmlGetProp(h, BAD_CAST "port");
+ name = xmlGetProp (h, BAD_CAST "name");
+ assert (name);
+ port = xmlGetProp (h, BAD_CAST "port");
assert (port);
debug (g, _("disk[%zu]: host: %s:%s"), i, name, port);
- if (asprintf(&server[hi], "%s:%s", name, port) == -1) {
+ if (asprintf (&server[hi], "%s:%s", name, port) == -1) {
perrorf (g, "asprintf");
return -1;
}
@@ -623,7 +665,8 @@ for_each_disk (guestfs_h *g,
* TODO: secrets: ./auth/secret/@type,
* ./auth/secret/@usage || ./auth/secret/@uuid
*/
- } else
+ }
+ else
continue; /* type <> "file", "block", or
"network", skip it */
assert (xpfilename);
@@ -632,8 +675,8 @@ for_each_disk (guestfs_h *g,
assert (xpfilename->nodesetval->nodeTab[0]);
assert (xpfilename->nodesetval->nodeTab[0]->type ==
XML_ATTRIBUTE_NODE);
- attr = (xmlAttrPtr) xpfilename->nodesetval->nodeTab[0];
- filename = (char *) xmlNodeListGetString (doc, attr->children, 1);
+ attr = (xmlAttrPtr)xpfilename->nodesetval->nodeTab[0];
+ filename = (char *)xmlNodeListGetString (doc, attr->children, 1);
debug (g, _("disk[%zu]: filename: %s"), i, filename);
}
else
@@ -642,27 +685,28 @@ for_each_disk (guestfs_h *g,
/* Get the disk format (may not be set). */
xpathCtx->node = nodes->nodeTab[i];
- xpformat = xmlXPathEvalExpression (BAD_CAST "./driver/@type", xpathCtx);
- if (xpformat != NULL &&
- xpformat->nodesetval &&
+ xpformat =
+ xmlXPathEvalExpression (BAD_CAST "./driver/@type", xpathCtx);
+ if (xpformat != NULL && xpformat->nodesetval &&
xpformat->nodesetval->nodeNr > 0) {
assert (xpformat->nodesetval->nodeTab[0]);
- assert (xpformat->nodesetval->nodeTab[0]->type == XML_ATTRIBUTE_NODE);
- attr = (xmlAttrPtr) xpformat->nodesetval->nodeTab[0];
- format = (char *) xmlNodeListGetString (doc, attr->children, 1);
+ assert (xpformat->nodesetval->nodeTab[0]->type ==
+ XML_ATTRIBUTE_NODE);
+ attr = (xmlAttrPtr)xpformat->nodesetval->nodeTab[0];
+ format = (char *)xmlNodeListGetString (doc, attr->children, 1);
}
/* Get the <readonly/> flag. */
xpathCtx->node = nodes->nodeTab[i];
xpreadonly = xmlXPathEvalExpression (BAD_CAST "./readonly", xpathCtx);
readonly = 0;
- if (xpreadonly != NULL &&
- xpreadonly->nodesetval &&
+ if (xpreadonly != NULL && xpreadonly->nodesetval &&
xpreadonly->nodesetval->nodeNr > 0)
readonly = 1;
if (f)
- t = f (g, filename, format, readonly, protocol, server, username, data);
+ t = f (g, filename, format, readonly, protocol, server, username,
+ data);
else
t = 0;
@@ -705,13 +749,13 @@ connect_live (guestfs_h *g, virDomainPtr dom)
/* This gives us a set of all the <channel> nodes related to the
* guestfsd virtio-serial channel.
*/
- xpathObj = xmlXPathEvalExpression (BAD_CAST
- "//devices/channel[@type=\"unix\" and "
- "./source/@mode=\"bind\" and "
- "./source/@path and "
- "./target/@type=\"virtio\" and "
- "./target/(a)name=\"org.libguestfs.channel.0\"]",
- xpathCtx);
+ xpathObj = xmlXPathEvalExpression (
+ BAD_CAST "//devices/channel[@type=\"unix\" and "
+ "./source/@mode=\"bind\" and "
+ "./source/@path and "
+ "./target/@type=\"virtio\" and "
+ "./target/(a)name=\"org.libguestfs.channel.0\"]",
+ xpathCtx);
if (xpathObj == NULL) {
error (g, _("unable to evaluate XPath expression"));
return -1;
@@ -728,23 +772,24 @@ connect_live (guestfs_h *g, virDomainPtr dom)
/* The path is in <source path=..> attribute. */
xppath = xmlXPathEvalExpression (BAD_CAST "./source/@path", xpathCtx);
- if (xppath == NULL ||
- xppath->nodesetval == NULL ||
+ if (xppath == NULL || xppath->nodesetval == NULL ||
xppath->nodesetval->nodeNr == 0) {
xmlXPathFreeObject (xppath);
- continue; /* no type attribute, skip it */
+ continue; /* no type attribute, skip it */
}
assert (xppath->nodesetval->nodeTab[0]);
assert (xppath->nodesetval->nodeTab[0]->type == XML_ATTRIBUTE_NODE);
- attr = (xmlAttrPtr) xppath->nodesetval->nodeTab[0];
- path = (char *) xmlNodeListGetString (doc, attr->children, 1);
+ attr = (xmlAttrPtr)xppath->nodesetval->nodeTab[0];
+ path = (char *)xmlNodeListGetString (doc, attr->children, 1);
break;
}
}
if (path == NULL) {
- error (g, _("this guest has no libvirt <channel> definition for
guestfsd\n"
- "See ATTACHING TO RUNNING DAEMONS in guestfs(3) for further
information."));
+ error (
+ g, _("this guest has no libvirt <channel> definition for
guestfsd\n"
+ "See ATTACHING TO RUNNING DAEMONS in guestfs(3) for further "
+ "information."));
return -1;
}
@@ -762,15 +807,15 @@ get_domain_xml (guestfs_h *g, virDomainPtr dom)
CLEANUP_FREE char *xml = virDomainGetXMLDesc (dom, 0);
if (!xml) {
err = virGetLastError ();
- error (g, _("error reading libvirt XML information: %s"),
err->message);
+ error (g, _("error reading libvirt XML information: %s"),
+ err->message);
return NULL;
}
debug (g, "original domain XML:\n%s", xml);
/* Parse the domain XML into an XML document. */
- doc = xmlReadMemory (xml, strlen (xml),
- NULL, NULL, XML_PARSE_NONET);
+ doc = xmlReadMemory (xml, strlen (xml), NULL, NULL, XML_PARSE_NONET);
if (doc == NULL) {
error (g, _("unable to parse XML information returned by libvirt"));
return NULL;
@@ -781,22 +826,24 @@ get_domain_xml (guestfs_h *g, virDomainPtr dom)
#else /* no libvirt at compile time */
-#define NOT_IMPL(r) \
- error (g, _("add-domain API not available since this version of libguestfs was
compiled without libvirt")); \
+#define NOT_IMPL(r) \
+ error (g, _("add-domain API not available since this version of " \
+ "libguestfs was compiled without libvirt")); \
return r
int
guestfs_impl_add_domain (guestfs_h *g, const char *dom,
- const struct guestfs_add_domain_argv *optargs)
+ const struct guestfs_add_domain_argv *optargs)
{
- NOT_IMPL(-1);
+ NOT_IMPL (-1);
}
int
-guestfs_impl_add_libvirt_dom (guestfs_h *g, void *domvp,
- const struct guestfs_add_libvirt_dom_argv *optargs)
+guestfs_impl_add_libvirt_dom (
+ guestfs_h *g, void *domvp,
+ const struct guestfs_add_libvirt_dom_argv *optargs)
{
- NOT_IMPL(-1);
+ NOT_IMPL (-1);
}
#endif /* no libvirt at compile time */
diff --git a/src/libvirt-is-version.c b/src/libvirt-is-version.c
index e350c4d..90542cb 100644
--- a/src/libvirt-is-version.c
+++ b/src/libvirt-is-version.c
@@ -44,10 +44,10 @@ main (int argc, char *argv[])
switch (argc) {
case 4:
release = argtoint (argv[0], argv[3]);
- /*FALLTHROUGH*/
+ /*FALLTHROUGH*/
case 3:
minor = argtoint (argv[0], argv[2]);
- /*FALLTHROUGH*/
+ /*FALLTHROUGH*/
case 2:
major = argtoint (argv[0], argv[1]);
break;
@@ -60,8 +60,8 @@ main (int argc, char *argv[])
if (virGetVersion (&ver, NULL, NULL) == -1)
exit (EXIT_FAILURE);
- return ver >= (major * 1000000 + minor * 1000 + release)
- ? EXIT_SUCCESS : EXIT_FAILURE;
+ return ver >= (major * 1000000 + minor * 1000 + release) ? EXIT_SUCCESS
+ : EXIT_FAILURE;
}
static unsigned int
@@ -75,5 +75,5 @@ argtoint (const char *prog, const char *arg)
if (errno || *endptr)
error (EXIT_FAILURE, 0, "cannot parse integer argument '%s'",
arg);
- return (unsigned int) res;
+ return (unsigned int)res;
}
diff --git a/src/listfs.c b/src/listfs.c
index de3b6f5..3b62472 100644
--- a/src/listfs.c
+++ b/src/listfs.c
@@ -34,7 +34,8 @@
*/
static void remove_from_list (char **list, const char *item);
-static int check_with_vfs_type (guestfs_h *g, const char *dev, struct stringsbuf *sb);
+static int check_with_vfs_type (guestfs_h *g, const char *dev,
+ struct stringsbuf *sb);
static int is_mbr_partition_type_42 (guestfs_h *g, const char *partition);
char **
@@ -44,9 +45,9 @@ guestfs_impl_list_filesystems (guestfs_h *g)
DECLARE_STRINGSBUF (ret);
const char *lvm2[] = { "lvm2", NULL };
- int has_lvm2 = guestfs_feature_available (g, (char **) lvm2);
+ int has_lvm2 = guestfs_feature_available (g, (char **)lvm2);
const char *ldm[] = { "ldm", NULL };
- int has_ldm = guestfs_feature_available (g, (char **) ldm);
+ int has_ldm = guestfs_feature_available (g, (char **)ldm);
CLEANUP_FREE_STRING_LIST char **devices = NULL;
CLEANUP_FREE_STRING_LIST char **partitions = NULL;
@@ -62,11 +63,14 @@ guestfs_impl_list_filesystems (guestfs_h *g)
* by using part-to-dev.
*/
devices = guestfs_list_devices (g);
- if (devices == NULL) goto error;
+ if (devices == NULL)
+ goto error;
partitions = guestfs_list_partitions (g);
- if (partitions == NULL) goto error;
+ if (partitions == NULL)
+ goto error;
mds = guestfs_list_md_devices (g);
- if (mds == NULL) goto error;
+ if (mds == NULL)
+ goto error;
for (i = 0; partitions[i] != NULL; ++i) {
CLEANUP_FREE char *dev = guestfs_part_to_dev (g, partitions[i]);
@@ -81,7 +85,7 @@ guestfs_impl_list_filesystems (guestfs_h *g)
/* Use vfs-type to check for filesystems on partitions. */
for (i = 0; partitions[i] != NULL; ++i) {
- if (has_ldm == 0 || ! is_mbr_partition_type_42 (g, partitions[i])) {
+ if (has_ldm == 0 || !is_mbr_partition_type_42 (g, partitions[i])) {
if (check_with_vfs_type (g, partitions[i], &ret) == -1)
goto error;
}
@@ -95,7 +99,8 @@ guestfs_impl_list_filesystems (guestfs_h *g)
if (has_lvm2 > 0) {
/* Use vfs-type to check for filesystems on LVs. */
lvs = guestfs_lvs (g);
- if (lvs == NULL) goto error;
+ if (lvs == NULL)
+ goto error;
for (i = 0; lvs[i] != NULL; ++i)
if (check_with_vfs_type (g, lvs[i], &ret) == -1)
@@ -105,14 +110,16 @@ guestfs_impl_list_filesystems (guestfs_h *g)
if (has_ldm > 0) {
/* Use vfs-type to check for filesystems on Windows dynamic disks. */
ldmvols = guestfs_list_ldm_volumes (g);
- if (ldmvols == NULL) goto error;
+ if (ldmvols == NULL)
+ goto error;
for (i = 0; ldmvols[i] != NULL; ++i)
if (check_with_vfs_type (g, ldmvols[i], &ret) == -1)
goto error;
ldmparts = guestfs_list_ldm_partitions (g);
- if (ldmparts == NULL) goto error;
+ if (ldmparts == NULL)
+ goto error;
for (i = 0; ldmparts[i] != NULL; ++i)
if (check_with_vfs_type (g, ldmparts[i], &ret) == -1)
@@ -123,7 +130,7 @@ guestfs_impl_list_filesystems (guestfs_h *g)
guestfs_int_end_stringsbuf (g, &ret);
return ret.argv;
- error:
+error:
guestfs_int_free_stringsbuf (&ret);
return NULL;
}
@@ -137,8 +144,8 @@ remove_from_list (char **list, const char *item)
for (i = 0; list[i] != NULL; ++i)
if (STREQ (list[i], item)) {
free (list[i]);
- for (; list[i+1] != NULL; ++i)
- list[i] = list[i+1];
+ for (; list[i + 1] != NULL; ++i)
+ list[i] = list[i + 1];
list[i] = NULL;
return;
}
@@ -149,7 +156,8 @@ remove_from_list (char **list, const char *item)
* 'ret' string list.
*/
static int
-check_with_vfs_type (guestfs_h *g, const char *device, struct stringsbuf *sb)
+check_with_vfs_type (guestfs_h *g, const char *device,
+ struct stringsbuf *sb)
{
const char *v;
CLEANUP_FREE char *vfs_type = NULL;
@@ -163,13 +171,14 @@ check_with_vfs_type (guestfs_h *g, const char *device, struct
stringsbuf *sb)
else if (STREQ (vfs_type, ""))
v = "unknown";
else if (STREQ (vfs_type, "btrfs")) {
- CLEANUP_FREE_BTRFSSUBVOLUME_LIST struct guestfs_btrfssubvolume_list *vols =
- guestfs_btrfs_subvolume_list (g, device);
+ CLEANUP_FREE_BTRFSSUBVOLUME_LIST struct guestfs_btrfssubvolume_list
+ *vols = guestfs_btrfs_subvolume_list (g, device);
if (vols == NULL)
return -1;
- int64_t default_volume = guestfs_btrfs_subvolume_get_default (g, device);
+ int64_t default_volume =
+ guestfs_btrfs_subvolume_get_default (g, device);
for (size_t i = 0; i < vols->len; i++) {
struct guestfs_btrfssubvolume *this = &vols->val[i];
@@ -177,12 +186,11 @@ check_with_vfs_type (guestfs_h *g, const char *device, struct
stringsbuf *sb)
/* Ignore the default subvolume. We get it by simply mounting
* the whole device of this btrfs filesystem.
*/
- if (this->btrfssubvolume_id == (uint64_t) default_volume)
+ if (this->btrfssubvolume_id == (uint64_t)default_volume)
continue;
- guestfs_int_add_sprintf (g, sb,
- "btrfsvol:%s/%s",
- device, this->btrfssubvolume_path);
+ guestfs_int_add_sprintf (g, sb, "btrfsvol:%s/%s", device,
+ this->btrfssubvolume_path);
guestfs_int_add_string (g, sb, "btrfs");
}
@@ -194,7 +202,7 @@ check_with_vfs_type (guestfs_h *g, const char *device, struct
stringsbuf *sb)
* importantly "LVM2_member" which is a PV.
*/
size_t n = strlen (vfs_type);
- if (n >= 7 && STREQ (&vfs_type[n-7], "_member"))
+ if (n >= 7 && STREQ (&vfs_type[n - 7], "_member"))
return 0;
/* Ignore LUKS-encrypted partitions. These are also containers. */
@@ -237,7 +245,7 @@ is_mbr_partition_type_42 (guestfs_h *g, const char *partition)
ret = mbr_id == 0x42;
- out:
+out:
guestfs_pop_error_handler (g);
return ret;
diff --git a/src/lpj.c b/src/lpj.c
index 37dfe2f..d7133ad 100644
--- a/src/lpj.c
+++ b/src/lpj.c
@@ -54,7 +54,8 @@ gl_lock_define_initialized (static, lpj_lock);
static int lpj = 0;
static int read_lpj_from_dmesg (guestfs_h *g);
static int read_lpj_from_files (guestfs_h *g);
-static int read_lpj_common (guestfs_h *g, const char *func, struct command *cmd);
+static int read_lpj_common (guestfs_h *g, const char *func,
+ struct command *cmd);
int
guestfs_int_get_lpj (guestfs_h *g)
@@ -79,7 +80,7 @@ guestfs_int_get_lpj (guestfs_h *g)
}
lpj = read_lpj_from_files (g);
- out:
+out:
gl_lock_unlock (lpj_lock);
return lpj;
}
@@ -87,7 +88,7 @@ guestfs_int_get_lpj (guestfs_h *g)
/* Grep the output, and print just the matching string "lpj=NNN". */
#define GREP_FLAGS "-Eoh"
#define GREP_REGEX "lpj=[[:digit:]]+"
-#define GREP_CMD "grep " GREP_FLAGS " '" GREP_REGEX
"'"
+#define GREP_CMD "grep " GREP_FLAGS " '" GREP_REGEX
"'"
static int
read_lpj_from_dmesg (guestfs_h *g)
@@ -143,7 +144,7 @@ read_lpj_common (guestfs_h *g, const char *func, struct command *cmd)
CLEANUP_FREE char *buf = NULL;
guestfs_int_cmd_set_stdout_callback (cmd, read_all, &buf,
- CMD_STDOUT_FLAG_WHOLE_BUFFER);
+ CMD_STDOUT_FLAG_WHOLE_BUFFER);
r = guestfs_int_cmd_run (cmd);
if (r == -1)
return -1;
@@ -151,9 +152,8 @@ read_lpj_common (guestfs_h *g, const char *func, struct command *cmd)
char status_string[80];
debug (g, "%s: %s", func,
- guestfs_int_exit_status_to_string (r, "external command",
- status_string,
- sizeof status_string));
+ guestfs_int_exit_status_to_string (
+ r, "external command", status_string, sizeof status_string));
return -1;
}
diff --git a/src/match.c b/src/match.c
index 41cc5f9..4ef2146 100644
--- a/src/match.c
+++ b/src/match.c
@@ -57,13 +57,13 @@ guestfs_int_match1 (guestfs_h *g, const char *str, const pcre *re)
if (r == PCRE_ERROR_NOMATCH)
return NULL;
- return r == 2 ? safe_strndup (g, &str[vec[2]], vec[3]-vec[2]) : NULL;
+ return r == 2 ? safe_strndup (g, &str[vec[2]], vec[3] - vec[2]) : NULL;
}
/* Match a regular expression which contains exactly two captures. */
int
guestfs_int_match2 (guestfs_h *g, const char *str, const pcre *re,
- char **ret1, char **ret2)
+ char **ret1, char **ret2)
{
size_t len = strlen (str);
int vec[30], r;
@@ -75,8 +75,10 @@ guestfs_int_match2 (guestfs_h *g, const char *str, const pcre *re,
*ret1 = NULL;
*ret2 = NULL;
- if (r > 1) *ret1 = safe_strndup (g, &str[vec[2]], vec[3]-vec[2]);
- if (r > 2) *ret2 = safe_strndup (g, &str[vec[4]], vec[5]-vec[4]);
+ if (r > 1)
+ *ret1 = safe_strndup (g, &str[vec[2]], vec[3] - vec[2]);
+ if (r > 2)
+ *ret2 = safe_strndup (g, &str[vec[4]], vec[5] - vec[4]);
return 1;
}
@@ -84,7 +86,7 @@ guestfs_int_match2 (guestfs_h *g, const char *str, const pcre *re,
/* Match a regular expression which contains exactly three captures. */
int
guestfs_int_match3 (guestfs_h *g, const char *str, const pcre *re,
- char **ret1, char **ret2, char **ret3)
+ char **ret1, char **ret2, char **ret3)
{
size_t len = strlen (str);
int vec[30], r;
@@ -97,9 +99,12 @@ guestfs_int_match3 (guestfs_h *g, const char *str, const pcre *re,
*ret2 = NULL;
*ret3 = NULL;
- if (r > 1) *ret1 = safe_strndup (g, &str[vec[2]], vec[3]-vec[2]);
- if (r > 2) *ret2 = safe_strndup (g, &str[vec[4]], vec[5]-vec[4]);
- if (r > 3) *ret3 = safe_strndup (g, &str[vec[6]], vec[7]-vec[6]);
+ if (r > 1)
+ *ret1 = safe_strndup (g, &str[vec[2]], vec[3] - vec[2]);
+ if (r > 2)
+ *ret2 = safe_strndup (g, &str[vec[4]], vec[5] - vec[4]);
+ if (r > 3)
+ *ret3 = safe_strndup (g, &str[vec[6]], vec[7] - vec[6]);
return 1;
}
@@ -107,7 +112,7 @@ guestfs_int_match3 (guestfs_h *g, const char *str, const pcre *re,
/* Match a regular expression which contains exactly four captures. */
int
guestfs_int_match4 (guestfs_h *g, const char *str, const pcre *re,
- char **ret1, char **ret2, char **ret3, char **ret4)
+ char **ret1, char **ret2, char **ret3, char **ret4)
{
size_t len = strlen (str);
int vec[30], r;
@@ -121,10 +126,14 @@ guestfs_int_match4 (guestfs_h *g, const char *str, const pcre *re,
*ret3 = NULL;
*ret4 = NULL;
- if (r > 1) *ret1 = safe_strndup (g, &str[vec[2]], vec[3]-vec[2]);
- if (r > 2) *ret2 = safe_strndup (g, &str[vec[4]], vec[5]-vec[4]);
- if (r > 3) *ret3 = safe_strndup (g, &str[vec[6]], vec[7]-vec[6]);
- if (r > 4) *ret4 = safe_strndup (g, &str[vec[8]], vec[9]-vec[8]);
+ if (r > 1)
+ *ret1 = safe_strndup (g, &str[vec[2]], vec[3] - vec[2]);
+ if (r > 2)
+ *ret2 = safe_strndup (g, &str[vec[4]], vec[5] - vec[4]);
+ if (r > 3)
+ *ret3 = safe_strndup (g, &str[vec[6]], vec[7] - vec[6]);
+ if (r > 4)
+ *ret4 = safe_strndup (g, &str[vec[8]], vec[9] - vec[8]);
return 1;
}
@@ -132,8 +141,8 @@ guestfs_int_match4 (guestfs_h *g, const char *str, const pcre *re,
/* Match a regular expression which contains exactly six captures. */
int
guestfs_int_match6 (guestfs_h *g, const char *str, const pcre *re,
- char **ret1, char **ret2, char **ret3, char **ret4,
- char **ret5, char **ret6)
+ char **ret1, char **ret2, char **ret3, char **ret4,
+ char **ret5, char **ret6)
{
size_t len = strlen (str);
int vec[30], r;
@@ -149,12 +158,18 @@ guestfs_int_match6 (guestfs_h *g, const char *str, const pcre *re,
*ret5 = NULL;
*ret6 = NULL;
- if (r > 1) *ret1 = safe_strndup (g, &str[vec[2]], vec[3]-vec[2]);
- if (r > 2) *ret2 = safe_strndup (g, &str[vec[4]], vec[5]-vec[4]);
- if (r > 3) *ret3 = safe_strndup (g, &str[vec[6]], vec[7]-vec[6]);
- if (r > 4) *ret4 = safe_strndup (g, &str[vec[8]], vec[9]-vec[8]);
- if (r > 5) *ret5 = safe_strndup (g, &str[vec[10]], vec[11]-vec[10]);
- if (r > 6) *ret6 = safe_strndup (g, &str[vec[12]], vec[13]-vec[12]);
+ if (r > 1)
+ *ret1 = safe_strndup (g, &str[vec[2]], vec[3] - vec[2]);
+ if (r > 2)
+ *ret2 = safe_strndup (g, &str[vec[4]], vec[5] - vec[4]);
+ if (r > 3)
+ *ret3 = safe_strndup (g, &str[vec[6]], vec[7] - vec[6]);
+ if (r > 4)
+ *ret4 = safe_strndup (g, &str[vec[8]], vec[9] - vec[8]);
+ if (r > 5)
+ *ret5 = safe_strndup (g, &str[vec[10]], vec[11] - vec[10]);
+ if (r > 6)
+ *ret6 = safe_strndup (g, &str[vec[12]], vec[13] - vec[12]);
return 1;
}
diff --git a/src/mountable.c b/src/mountable.c
index 9f7b451..990ae68 100644
--- a/src/mountable.c
+++ b/src/mountable.c
@@ -24,11 +24,11 @@
#include "guestfs-internal.h"
#include "guestfs-internal-actions.h"
-
char *
guestfs_impl_mountable_device (guestfs_h *g, const char *mountable)
{
- CLEANUP_FREE_INTERNAL_MOUNTABLE struct guestfs_internal_mountable *mnt = NULL;
+ CLEANUP_FREE_INTERNAL_MOUNTABLE struct guestfs_internal_mountable *mnt =
+ NULL;
mnt = guestfs_internal_parse_mountable (g, mountable);
if (mnt == NULL)
@@ -40,7 +40,8 @@ guestfs_impl_mountable_device (guestfs_h *g, const char *mountable)
char *
guestfs_impl_mountable_subvolume (guestfs_h *g, const char *mountable)
{
- CLEANUP_FREE_INTERNAL_MOUNTABLE struct guestfs_internal_mountable *mnt = NULL;
+ CLEANUP_FREE_INTERNAL_MOUNTABLE struct guestfs_internal_mountable *mnt =
+ NULL;
mnt = guestfs_internal_parse_mountable (g, mountable);
if (mnt == NULL || STREQ (mnt->im_volume, "")) {
diff --git a/src/osinfo.c b/src/osinfo.c
index 4a4cbfc..43f93d8 100644
--- a/src/osinfo.c
+++ b/src/osinfo.c
@@ -68,7 +68,8 @@
COMPILE_REGEXP (re_major_minor, "(\\d+)\\.(\\d+)", 0)
gl_lock_define_initialized (static, osinfo_db_lock);
-static ssize_t osinfo_db_size = 0; /* 0 = unread, -1 = error, >= 1 = #records */
+static ssize_t osinfo_db_size =
+ 0; /* 0 = unread, -1 = error, >= 1 = #records */
static struct osinfo *osinfo_db = NULL;
static int read_osinfo_db (guestfs_h *g);
@@ -79,17 +80,19 @@ static void free_osinfo_db_entry (struct osinfo *);
* the operating system.
*
* This returns:
- * -1 => a fatal error ('error' has been called, caller must not ignore it)
+ * -1 => a fatal error ('error' has been called, caller must not ignore
+ * it)
* 0 => could not locate the OS
* 1 => matching OS found, the osinfo_ret pointer has been filled in
*/
int
guestfs_int_osinfo_map (guestfs_h *g, const struct guestfs_isoinfo *isoinfo,
- const struct osinfo **osinfo_ret)
+ const struct osinfo **osinfo_ret)
{
size_t i;
- /* We only need to lock the database when reading it for the first time. */
+ /* We only need to lock the database when reading it for the first time.
+ */
gl_lock_lock (osinfo_db_lock);
if (osinfo_db_size == 0) {
if (read_osinfo_db (g) == -1) {
@@ -103,7 +106,7 @@ guestfs_int_osinfo_map (guestfs_h *g, const struct guestfs_isoinfo
*isoinfo,
return 0;
/* Look in the database to see if we can find a match. */
- for (i = 0; i < (size_t) osinfo_db_size; ++i) {
+ for (i = 0; i < (size_t)osinfo_db_size; ++i) {
if (osinfo_db[i].re_system_id) {
if (!isoinfo->iso_system_id ||
!match (g, isoinfo->iso_system_id, osinfo_db[i].re_system_id))
@@ -118,13 +121,15 @@ guestfs_int_osinfo_map (guestfs_h *g, const struct guestfs_isoinfo
*isoinfo,
if (osinfo_db[i].re_publisher_id) {
if (!isoinfo->iso_publisher_id ||
- !match (g, isoinfo->iso_publisher_id, osinfo_db[i].re_publisher_id))
+ !match (g, isoinfo->iso_publisher_id,
+ osinfo_db[i].re_publisher_id))
continue;
}
if (osinfo_db[i].re_application_id) {
if (!isoinfo->iso_application_id ||
- !match (g, isoinfo->iso_application_id, osinfo_db[i].re_application_id))
+ !match (g, isoinfo->iso_application_id,
+ osinfo_db[i].re_application_id))
continue;
}
@@ -176,7 +181,8 @@ read_osinfo_db (guestfs_h *g)
for (;;) {
errno = 0;
d = readdir (dir);
- if (!d) break;
+ if (!d)
+ break;
if (STRSUFFIX (d->d_name, ".xml")) {
r = read_osinfo_db_xml (g, d->d_name);
@@ -201,7 +207,7 @@ read_osinfo_db (guestfs_h *g)
return 0;
- error:
+error:
if (dir)
closedir (dir);
@@ -209,7 +215,7 @@ read_osinfo_db (guestfs_h *g)
* mark the database as having a permanent error.
*/
if (osinfo_db_size > 0) {
- for (i = 0; i < (size_t) osinfo_db_size; ++i)
+ for (i = 0; i < (size_t)osinfo_db_size; ++i)
free_osinfo_db_entry (&osinfo_db[i]);
}
free (osinfo_db);
@@ -219,9 +225,12 @@ read_osinfo_db (guestfs_h *g)
return -1;
}
-static int read_iso_node (guestfs_h *g, xmlNodePtr iso_node, struct osinfo *osinfo);
-static int read_media_node (guestfs_h *g, xmlXPathContextPtr xpathCtx, xmlNodePtr
media_node, struct osinfo *osinfo);
-static int read_os_node (guestfs_h *g, xmlXPathContextPtr xpathCtx, xmlNodePtr os_node,
struct osinfo *osinfo);
+static int read_iso_node (guestfs_h *g, xmlNodePtr iso_node,
+ struct osinfo *osinfo);
+static int read_media_node (guestfs_h *g, xmlXPathContextPtr xpathCtx,
+ xmlNodePtr media_node, struct osinfo *osinfo);
+static int read_os_node (guestfs_h *g, xmlXPathContextPtr xpathCtx,
+ xmlNodePtr os_node, struct osinfo *osinfo);
/* Read a single XML file from LIBOSINFO_DB_OS_PATH/filename. Only
* memory allocation failures are fatal errors here.
@@ -255,8 +264,8 @@ read_osinfo_db_xml (guestfs_h *g, const char *filename)
/* Get all <iso> nodes at any depth, then use the parent pointers in
* order to work back up the tree.
*/
- xpathObj = xmlXPathEvalExpression (BAD_CAST "/libosinfo/os/media/iso",
- xpathCtx);
+ xpathObj =
+ xmlXPathEvalExpression (BAD_CAST "/libosinfo/os/media/iso", xpathCtx);
if (xpathObj == NULL) {
error (g, _("osinfo: %s: unable to evaluate XPath expression"),
pathname);
@@ -266,27 +275,27 @@ read_osinfo_db_xml (guestfs_h *g, const char *filename)
nodes = xpathObj->nodesetval;
if (nodes != NULL) {
- for (i = 0; i < (size_t) nodes->nodeNr; ++i) {
+ for (i = 0; i < (size_t)nodes->nodeNr; ++i) {
iso_node = nodes->nodeTab[i];
assert (iso_node != NULL);
- assert (STREQ ((const char *) iso_node->name, "iso"));
+ assert (STREQ ((const char *)iso_node->name, "iso"));
assert (iso_node->type == XML_ELEMENT_NODE);
media_node = iso_node->parent;
assert (media_node != NULL);
- assert (STREQ ((const char *) media_node->name, "media"));
+ assert (STREQ ((const char *)media_node->name, "media"));
assert (media_node->type == XML_ELEMENT_NODE);
os_node = media_node->parent;
assert (os_node != NULL);
- assert (STREQ ((const char *) os_node->name, "os"));
+ assert (STREQ ((const char *)os_node->name, "os"));
assert (os_node->type == XML_ELEMENT_NODE);
/* Allocate an osinfo record. */
osinfo_db_size++;
osinfo_db = safe_realloc (g, osinfo_db,
sizeof (struct osinfo) * osinfo_db_size);
- osinfo = &osinfo_db[osinfo_db_size-1];
+ osinfo = &osinfo_db[osinfo_db_size - 1];
memset (osinfo, 0, sizeof *osinfo);
/* Read XML fields into the new osinfo record. */
@@ -329,19 +338,19 @@ read_iso_node (guestfs_h *g, xmlNodePtr iso_node, struct osinfo
*osinfo)
xmlNodePtr child;
for (child = iso_node->children; child; child = child->next) {
- if (STREQ ((const char *) child->name, "system-id")) {
+ if (STREQ ((const char *)child->name, "system-id")) {
if (compile_re (g, child, &osinfo->re_system_id) == -1)
return -1;
}
- else if (STREQ ((const char *) child->name, "volume-id")) {
+ else if (STREQ ((const char *)child->name, "volume-id")) {
if (compile_re (g, child, &osinfo->re_volume_id) == -1)
return -1;
}
- else if (STREQ ((const char *) child->name, "publisher-id")) {
+ else if (STREQ ((const char *)child->name, "publisher-id")) {
if (compile_re (g, child, &osinfo->re_publisher_id) == -1)
return -1;
}
- else if (STREQ ((const char *) child->name, "application-id")) {
+ else if (STREQ ((const char *)child->name, "application-id")) {
if (compile_re (g, child, &osinfo->re_application_id) == -1)
return -1;
}
@@ -355,13 +364,14 @@ compile_re (guestfs_h *g, xmlNodePtr node, pcre **re)
{
const char *err;
int offset;
- CLEANUP_FREE char *content = (char *) xmlNodeGetContent (node);
+ CLEANUP_FREE char *content = (char *)xmlNodeGetContent (node);
if (content) {
*re = pcre_compile (content, 0, &err, &offset, NULL);
if (*re == NULL)
- debug (g, "osinfo: could not parse regular expression '%s': %s
(ignored)",
- content, err);
+ debug (
+ g, "osinfo: could not parse regular expression '%s': %s
(ignored)",
+ content, err);
}
return 0;
@@ -381,7 +391,7 @@ read_media_node (guestfs_h *g, xmlXPathContextPtr xpathCtx,
attr = xp->nodesetval->nodeTab[0];
assert (attr);
assert (attr->type == XML_ATTRIBUTE_NODE);
- osinfo->arch = (char *) xmlNodeGetContent (attr);
+ osinfo->arch = (char *)xmlNodeGetContent (attr);
}
osinfo->is_live_disk = 0; /* If no 'live' attr, defaults to false. */
@@ -394,36 +404,39 @@ read_media_node (guestfs_h *g, xmlXPathContextPtr xpathCtx,
attr = xp2->nodesetval->nodeTab[0];
assert (attr);
assert (attr->type == XML_ATTRIBUTE_NODE);
- content = (char *) xmlNodeGetContent (attr);
+ content = (char *)xmlNodeGetContent (attr);
osinfo->is_live_disk = STREQ (content, "true");
}
return 0;
}
-static int parse_version (guestfs_h *g, xmlNodePtr node, struct osinfo *osinfo);
-static int parse_family (guestfs_h *g, xmlNodePtr node, struct osinfo *osinfo);
-static int parse_distro (guestfs_h *g, xmlNodePtr node, struct osinfo *osinfo);
+static int parse_version (guestfs_h *g, xmlNodePtr node,
+ struct osinfo *osinfo);
+static int parse_family (guestfs_h *g, xmlNodePtr node,
+ struct osinfo *osinfo);
+static int parse_distro (guestfs_h *g, xmlNodePtr node,
+ struct osinfo *osinfo);
/* Read some fields under the <os/> node. */
static int
-read_os_node (guestfs_h *g, xmlXPathContextPtr xpathCtx,
- xmlNodePtr os_node, struct osinfo *osinfo)
+read_os_node (guestfs_h *g, xmlXPathContextPtr xpathCtx, xmlNodePtr os_node,
+ struct osinfo *osinfo)
{
xmlNodePtr child;
for (child = os_node->children; child; child = child->next) {
- if (STREQ ((const char *) child->name, "name"))
- osinfo->product_name = (char *) xmlNodeGetContent (child);
- else if (STREQ ((const char *) child->name, "version")) {
+ if (STREQ ((const char *)child->name, "name"))
+ osinfo->product_name = (char *)xmlNodeGetContent (child);
+ else if (STREQ ((const char *)child->name, "version")) {
if (parse_version (g, child, osinfo) == -1)
return -1;
}
- else if (STREQ ((const char *) child->name, "family")) {
+ else if (STREQ ((const char *)child->name, "family")) {
if (parse_family (g, child, osinfo) == -1)
return -1;
}
- else if (STREQ ((const char *) child->name, "distro")) {
+ else if (STREQ ((const char *)child->name, "distro")) {
if (parse_distro (g, child, osinfo) == -1)
return -1;
}
@@ -438,7 +451,7 @@ parse_version (guestfs_h *g, xmlNodePtr node, struct osinfo *osinfo)
CLEANUP_FREE char *content = NULL;
CLEANUP_FREE char *major = NULL, *minor = NULL;
- content = (char *) xmlNodeGetContent (node);
+ content = (char *)xmlNodeGetContent (node);
if (content) {
if (match2 (g, content, re_major_minor, &major, &minor)) {
osinfo->major_version = guestfs_int_parse_unsigned_int (g, major);
@@ -460,7 +473,7 @@ parse_family (guestfs_h *g, xmlNodePtr node, struct osinfo *osinfo)
osinfo->type = OS_TYPE_UNKNOWN;
- content = (char *) xmlNodeGetContent (node);
+ content = (char *)xmlNodeGetContent (node);
if (content) {
if (STREQ (content, "linux"))
osinfo->type = OS_TYPE_LINUX;
@@ -488,7 +501,7 @@ parse_distro (guestfs_h *g, xmlNodePtr node, struct osinfo *osinfo)
osinfo->distro = OS_DISTRO_UNKNOWN;
- content = (char *) xmlNodeGetContent (node);
+ content = (char *)xmlNodeGetContent (node);
if (content) {
if (STREQ (content, "altlinux"))
osinfo->distro = OS_DISTRO_ALTLINUX;
diff --git a/src/private-data.c b/src/private-data.c
index 3f6e6f1..8cf775b 100644
--- a/src/private-data.c
+++ b/src/private-data.c
@@ -34,8 +34,8 @@
* likely to be NULL.
*/
struct pda_entry {
- char *key; /* key */
- void *data; /* opaque user data pointer */
+ char *key; /* key */
+ void *data; /* opaque user data pointer */
};
static size_t
@@ -91,9 +91,9 @@ void *
guestfs_get_private (guestfs_h *g, const char *key)
{
if (g->pda == NULL)
- return NULL; /* no keys have been set */
+ return NULL; /* no keys have been set */
- const struct pda_entry k = { .key = (char *) key };
+ const struct pda_entry k = {.key = (char *)key };
struct pda_entry *entry = hash_lookup (g->pda, &k);
if (entry)
return entry->data;
diff --git a/src/proto.c b/src/proto.c
index df7be89..9d48e88 100644
--- a/src/proto.c
+++ b/src/proto.c
@@ -102,7 +102,7 @@ child_cleanup (guestfs_h *g)
/* Convenient wrapper to generate a progress message callback. */
void
guestfs_int_progress_message_callback (guestfs_h *g,
- const guestfs_progress *message)
+ const guestfs_progress *message)
{
uint64_t array[4];
@@ -111,8 +111,8 @@ guestfs_int_progress_message_callback (guestfs_h *g,
array[2] = message->position;
array[3] = message->total;
- guestfs_int_call_callbacks_array (g, GUESTFS_EVENT_PROGRESS,
- array, sizeof array / sizeof array[0]);
+ guestfs_int_call_callbacks_array (g, GUESTFS_EVENT_PROGRESS, array,
+ sizeof array / sizeof array[0]);
}
/* Connection modules call us back here when they get a log message. */
@@ -163,8 +163,8 @@ check_daemon_socket (guestfs_h *g)
assert (g->conn); /* callers must check this */
- again:
- if (! g->conn->ops->can_read_data (g, g->conn))
+again:
+ if (!g->conn->ops->can_read_data (g, g->conn))
return 1;
n = g->conn->ops->read_data (g, g->conn, buf, 4);
@@ -194,7 +194,8 @@ check_daemon_socket (guestfs_h *g)
}
if (flag != GUESTFS_CANCEL_FLAG) {
- error (g, _("check_daemon_socket: read 0x%x from daemon, expected 0x%x. Lost
protocol synchronization (bad!)\n"),
+ error (g, _("check_daemon_socket: read 0x%x from daemon, expected "
+ "0x%x. Lost protocol synchronization (bad!)\n"),
flag, GUESTFS_CANCEL_FLAG);
return -1;
}
@@ -203,9 +204,8 @@ check_daemon_socket (guestfs_h *g)
}
int
-guestfs_int_send (guestfs_h *g, int proc_nr,
- uint64_t progress_hint, uint64_t optargs_bitmask,
- xdrproc_t xdrp, char *args)
+guestfs_int_send (guestfs_h *g, int proc_nr, uint64_t progress_hint,
+ uint64_t optargs_bitmask, xdrproc_t xdrp, char *args)
{
struct guestfs_message_header hdr;
XDR xdr;
@@ -305,7 +305,8 @@ fadvise_sequential (int fd)
#endif
}
-static int send_file_chunk (guestfs_h *g, int cancel, const char *buf, size_t len);
+static int send_file_chunk (guestfs_h *g, int cancel, const char *buf,
+ size_t len);
static int send_file_data (guestfs_h *g, const char *buf, size_t len);
static int send_file_cancellation (guestfs_h *g);
static int send_file_complete (guestfs_h *g);
@@ -324,7 +325,7 @@ guestfs_int_send_file (guestfs_h *g, const char *filename)
g->user_cancel = 0;
- fd = open (filename, O_RDONLY|O_CLOEXEC);
+ fd = open (filename, O_RDONLY | O_CLOEXEC);
if (fd == -1) {
perrorf (g, "open: %s", filename);
send_file_cancellation (g);
@@ -338,10 +339,11 @@ guestfs_int_send_file (guestfs_h *g, const char *filename)
r = read (fd, buf, GUESTFS_MAX_CHUNK_SIZE);
if (r == -1 && (errno == EINTR || errno == EAGAIN))
continue;
- if (r <= 0) break;
+ if (r <= 0)
+ break;
err = send_file_data (g, buf, r);
if (err < 0) {
- if (err == -2) /* daemon sent cancellation */
+ if (err == -2) /* daemon sent cancellation */
send_file_cancellation (g);
close (fd);
return err;
@@ -373,7 +375,7 @@ guestfs_int_send_file (guestfs_h *g, const char *filename)
err = send_file_complete (g);
if (err < 0) {
- if (err == -2) /* daemon sent cancellation */
+ if (err == -2) /* daemon sent cancellation */
send_file_cancellation (g);
return err;
}
@@ -417,16 +419,17 @@ send_file_chunk (guestfs_h *g, int cancel, const char *buf, size_t
buflen)
* excessive stack usage and unnecessary copies.
*/
msg_out = safe_malloc (g, GUESTFS_MAX_CHUNK_SIZE + 4 + 48);
- xdrmem_create (&xdr, msg_out + 4, GUESTFS_MAX_CHUNK_SIZE + 48, XDR_ENCODE);
+ xdrmem_create (&xdr, msg_out + 4, GUESTFS_MAX_CHUNK_SIZE + 48,
+ XDR_ENCODE);
/* Serialize the chunk. */
chunk.cancel = cancel;
chunk.data.data_len = buflen;
- chunk.data.data_val = (char *) buf;
+ chunk.data.data_val = (char *)buf;
if (!xdr_guestfs_chunk (&xdr, &chunk)) {
- error (g, _("xdr_guestfs_chunk failed (buf = %p, buflen = %zu)"),
- buf, buflen);
+ error (g, _("xdr_guestfs_chunk failed (buf = %p, buflen = %zu)"), buf,
+ buflen);
xdr_destroy (&xdr);
return -1;
}
@@ -522,8 +525,9 @@ recv_from_daemon (guestfs_h *g, uint32_t *size_rtn, void **buf_rtn)
if (*size_rtn == GUESTFS_LAUNCH_FLAG) {
if (g->state != LAUNCHING)
- error (g, _("received magic signature from guestfsd, but in state %d"),
- (int) g->state);
+ error (g,
+ _("received magic signature from guestfsd, but in state %d"),
+ (int)g->state);
else {
g->state = READY;
guestfs_int_call_callbacks_void (g, GUESTFS_EVENT_LAUNCH_DONE);
@@ -542,7 +546,7 @@ recv_from_daemon (guestfs_h *g, uint32_t *size_rtn, void **buf_rtn)
* synchronization.
*/
error (g, _("message length (%u) > maximum possible size (%d)"),
- (unsigned) *size_rtn, GUESTFS_MESSAGE_MAX);
+ (unsigned)*size_rtn, GUESTFS_MESSAGE_MAX);
return -1;
}
@@ -568,26 +572,26 @@ recv_from_daemon (guestfs_h *g, uint32_t *size_rtn, void **buf_rtn)
return -1;
}
- /* ... it's a normal message (not progress/launch/cancel) so display
- * it if we're debugging.
- */
+/* ... it's a normal message (not progress/launch/cancel) so display
+ * it if we're debugging.
+ */
#ifdef ENABLE_PACKET_DUMP
if (g->verbose) {
ssize_t i, j;
for (i = 0; i < n; i += 16) {
printf ("%04zx: ", i);
- for (j = i; j < MIN (i+16, n); ++j)
+ for (j = i; j < MIN (i + 16, n); ++j)
printf ("%02x ", (*(unsigned char **)buf_rtn)[j]);
- for (; j < i+16; ++j)
+ for (; j < i + 16; ++j)
printf (" ");
printf ("|");
- for (j = i; j < MIN (i+16, n); ++j)
+ for (j = i; j < MIN (i + 16, n); ++j)
if (c_isprint ((*(char **)buf_rtn)[j]))
printf ("%c", (*(char **)buf_rtn)[j]);
else
printf (".");
- for (; j < i+16; ++j)
+ for (; j < i + 16; ++j)
printf (" ");
printf ("|\n");
}
@@ -598,11 +602,12 @@ recv_from_daemon (guestfs_h *g, uint32_t *size_rtn, void **buf_rtn)
}
int
-guestfs_int_recv_from_daemon (guestfs_h *g, uint32_t *size_rtn, void **buf_rtn)
+guestfs_int_recv_from_daemon (guestfs_h *g, uint32_t *size_rtn,
+ void **buf_rtn)
{
int r;
- again:
+again:
r = recv_from_daemon (g, size_rtn, buf_rtn);
if (r == -1)
return -1;
@@ -635,17 +640,15 @@ guestfs_int_recv_from_daemon (guestfs_h *g, uint32_t *size_rtn, void
**buf_rtn)
/* Receive a reply. */
int
-guestfs_int_recv (guestfs_h *g, const char *fn,
- guestfs_message_header *hdr,
- guestfs_message_error *err,
- xdrproc_t xdrp, char *ret)
+guestfs_int_recv (guestfs_h *g, const char *fn, guestfs_message_header *hdr,
+ guestfs_message_error *err, xdrproc_t xdrp, char *ret)
{
XDR xdr;
CLEANUP_FREE void *buf = NULL;
uint32_t size;
int r;
- again:
+again:
r = guestfs_int_recv_from_daemon (g, &size, &buf);
if (r == -1)
return -1;
@@ -658,7 +661,9 @@ guestfs_int_recv (guestfs_h *g, const char *fn,
goto again;
if (size == GUESTFS_LAUNCH_FLAG) {
- error (g, "%s: received unexpected launch flag from daemon when expecting
reply", fn);
+ error (g, "%s: received unexpected launch flag from daemon when "
+ "expecting reply",
+ fn);
return -1;
}
@@ -675,7 +680,8 @@ guestfs_int_recv (guestfs_h *g, const char *fn,
xdr_destroy (&xdr);
return -1;
}
- } else {
+ }
+ else {
if (xdrp && ret && !xdrp (&xdr, ret, 0)) {
error (g, "%s: failed to parse reply", fn);
xdr_destroy (&xdr);
@@ -700,7 +706,7 @@ guestfs_int_recv_discard (guestfs_h *g, const char *fn)
uint32_t size;
int r;
- again:
+again:
r = guestfs_int_recv_from_daemon (g, &size, &buf);
if (r == -1)
return -1;
@@ -713,7 +719,9 @@ guestfs_int_recv_discard (guestfs_h *g, const char *fn)
goto again;
if (size == GUESTFS_LAUNCH_FLAG) {
- error (g, "%s: received unexpected launch flag from daemon when expecting
reply", fn);
+ error (g, "%s: received unexpected launch flag from daemon when "
+ "expecting reply",
+ fn);
return -1;
}
@@ -760,7 +768,8 @@ guestfs_int_recv_file (guestfs_h *g, const char *filename)
else if (STREQ (filename, "/dev/stderr"))
fd = dup (2);
else
- fd = open (filename, O_WRONLY|O_CREAT|O_TRUNC|O_NOCTTY|O_CLOEXEC, 0666);
+ fd = open (filename,
+ O_WRONLY | O_CREAT | O_TRUNC | O_NOCTTY | O_CLOEXEC, 0666);
if (fd == -1) {
perrorf (g, "%s", filename);
goto cancel;
@@ -796,7 +805,7 @@ guestfs_int_recv_file (guestfs_h *g, const char *filename)
return 0;
- cancel: ;
+cancel:;
/* Send cancellation message to daemon, then wait until it
* cancels (just throwing away data).
*/
@@ -804,8 +813,7 @@ guestfs_int_recv_file (guestfs_h *g, const char *filename)
char fbuf[4];
uint32_t flag = GUESTFS_CANCEL_FLAG;
- debug (g, "%s: waiting for daemon to acknowledge cancellation",
- __func__);
+ debug (g, "%s: waiting for daemon to acknowledge cancellation", __func__);
xdrmem_create (&xdr, fbuf, sizeof fbuf, XDR_ENCODE);
xdr_uint32_t (&xdr, &flag);
@@ -817,7 +825,7 @@ guestfs_int_recv_file (guestfs_h *g, const char *filename)
}
while (receive_file_data (g, NULL) > 0)
- ; /* just discard it */
+ ; /* just discard it */
return -1;
}
@@ -838,7 +846,8 @@ receive_file_data (guestfs_h *g, void **buf_r)
return -1;
if (len == GUESTFS_LAUNCH_FLAG || len == GUESTFS_CANCEL_FLAG) {
- error (g, _("receive_file_data: unexpected flag received when reading file
chunks"));
+ error (g, _("receive_file_data: unexpected flag received when reading "
+ "file chunks"));
return -1;
}
@@ -865,8 +874,10 @@ receive_file_data (guestfs_h *g, void **buf_r)
return 0;
}
- if (buf_r) *buf_r = chunk.data.data_val;
- else free (chunk.data.data_val); /* else caller frees */
+ if (buf_r)
+ *buf_r = chunk.data.data_val;
+ else
+ free (chunk.data.data_val); /* else caller frees */
return chunk.data.data_len;
}
diff --git a/src/stringsbuf.c b/src/stringsbuf.c
index 1486998..4d0d003 100644
--- a/src/stringsbuf.c
+++ b/src/stringsbuf.c
@@ -28,7 +28,8 @@
#include "guestfs-internal.h"
void
-guestfs_int_add_string_nodup (guestfs_h *g, struct stringsbuf *sb, char *str)
+guestfs_int_add_string_nodup (guestfs_h *g, struct stringsbuf *sb,
+ char *str)
{
if (sb->size >= sb->alloc) {
sb->alloc += 64;
@@ -40,14 +41,15 @@ guestfs_int_add_string_nodup (guestfs_h *g, struct stringsbuf *sb,
char *str)
}
void
-guestfs_int_add_string (guestfs_h *g, struct stringsbuf *sb, const char *str)
+guestfs_int_add_string (guestfs_h *g, struct stringsbuf *sb,
+ const char *str)
{
guestfs_int_add_string_nodup (g, sb, safe_strdup (g, str));
}
void
guestfs_int_add_sprintf (guestfs_h *g, struct stringsbuf *sb,
- const char *fs, ...)
+ const char *fs, ...)
{
va_list args;
char *str;
diff --git a/src/test-utils.c b/src/test-utils.c
index 0516db5..8c56b43 100644
--- a/src/test-utils.c
+++ b/src/test-utils.c
@@ -97,23 +97,23 @@ test_concat (void)
const char *test4[] = { "a", "", NULL };
const char *test5[] = { "a", "b", NULL };
- ret = guestfs_int_concat_strings ((char **) test1);
+ ret = guestfs_int_concat_strings ((char **)test1);
assert (STREQ (ret, ""));
free (ret);
- ret = guestfs_int_concat_strings ((char **) test2);
+ ret = guestfs_int_concat_strings ((char **)test2);
assert (STREQ (ret, ""));
free (ret);
- ret = guestfs_int_concat_strings ((char **) test3);
+ ret = guestfs_int_concat_strings ((char **)test3);
assert (STREQ (ret, "a"));
free (ret);
- ret = guestfs_int_concat_strings ((char **) test4);
+ ret = guestfs_int_concat_strings ((char **)test4);
assert (STREQ (ret, "a"));
free (ret);
- ret = guestfs_int_concat_strings ((char **) test5);
+ ret = guestfs_int_concat_strings ((char **)test5);
assert (STREQ (ret, "ab"));
free (ret);
}
@@ -129,23 +129,23 @@ test_join (void)
const char *test4[] = { "a", "", NULL };
const char *test5[] = { "a", "b", NULL };
- ret = guestfs_int_join_strings (":!", (char **) test1);
+ ret = guestfs_int_join_strings (":!", (char **)test1);
assert (STREQ (ret, ""));
free (ret);
- ret = guestfs_int_join_strings (":!", (char **) test2);
+ ret = guestfs_int_join_strings (":!", (char **)test2);
assert (STREQ (ret, ""));
free (ret);
- ret = guestfs_int_join_strings (":!", (char **) test3);
+ ret = guestfs_int_join_strings (":!", (char **)test3);
assert (STREQ (ret, "a"));
free (ret);
- ret = guestfs_int_join_strings (":!", (char **) test4);
+ ret = guestfs_int_join_strings (":!", (char **)test4);
assert (STREQ (ret, "a:!"));
free (ret);
- ret = guestfs_int_join_strings (":!", (char **) test5);
+ ret = guestfs_int_join_strings (":!", (char **)test5);
assert (STREQ (ret, "a:!b"));
free (ret);
}
@@ -156,10 +156,13 @@ test_validate_guid (void)
{
assert (guestfs_int_validate_guid ("") == 0);
assert (guestfs_int_validate_guid ("1") == 0);
- assert (guestfs_int_validate_guid ("21EC20203AEA1069A2DD08002B30309D") ==
0);
+ assert (guestfs_int_validate_guid ("21EC20203AEA1069A2DD08002B30309D") ==
+ 0);
- assert (guestfs_int_validate_guid ("{21EC2020-3AEA-1069-A2DD-08002B30309D}")
== 1);
- assert (guestfs_int_validate_guid ("21EC2020-3AEA-1069-A2DD-08002B30309D") ==
1);
+ assert (guestfs_int_validate_guid (
+ "{21EC2020-3AEA-1069-A2DD-08002B30309D}") == 1);
+ assert (guestfs_int_validate_guid (
+ "21EC2020-3AEA-1069-A2DD-08002B30309D") == 1);
}
/* Test guestfs_int_drive_name. */
diff --git a/src/tmpdirs.c b/src/tmpdirs.c
index afa3dd4..59432be 100644
--- a/src/tmpdirs.c
+++ b/src/tmpdirs.c
@@ -139,7 +139,8 @@ guestfs_impl_get_sockdir (guestfs_h *g)
* the directory.
*/
str = "/tmp";
- } else {
+ }
+ else {
if (g->env_runtimedir)
str = g->env_runtimedir;
else
diff --git a/src/utils.c b/src/utils.c
index f099a22..b193e57 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -68,7 +68,7 @@ guestfs_int_copy_string_list (char *const *argv)
size_t i, j;
char **ret;
- ret = malloc ((n+1) * sizeof (char *));
+ ret = malloc ((n + 1) * sizeof (char *));
if (ret == NULL)
return NULL;
ret[n] = NULL;
@@ -162,10 +162,10 @@ guestfs_int_split_string (char sep, const char *str)
/* We always return a list of length 1 + (# separator characters).
* We also have to add a trailing NULL.
*/
- ret = malloc ((n+2) * sizeof (char *));
+ ret = malloc ((n + 2) * sizeof (char *));
if (!ret)
return NULL;
- ret[n+1] = NULL;
+ ret[n + 1] = NULL;
for (n = i = 0; i <= len; ++i, ++n) {
c = strcspn (&str[i], reject);
@@ -187,27 +187,27 @@ guestfs_int_split_string (char sep, const char *str)
/* Translate a wait/system exit status into a printable string. */
char *
guestfs_int_exit_status_to_string (int status, const char *cmd_name,
- char *buffer, size_t buflen)
+ char *buffer, size_t buflen)
{
if (WIFEXITED (status)) {
if (WEXITSTATUS (status) == 0)
- snprintf (buffer, buflen, _("%s exited successfully"),
- cmd_name);
+ snprintf (buffer, buflen, _("%s exited successfully"), cmd_name);
else
snprintf (buffer, buflen, _("%s exited with error status %d"),
cmd_name, WEXITSTATUS (status));
}
else if (WIFSIGNALED (status)) {
- snprintf (buffer, buflen, _("%s killed by signal %d (%s)"),
- cmd_name, WTERMSIG (status), strsignal (WTERMSIG (status)));
+ snprintf (buffer, buflen, _("%s killed by signal %d (%s)"), cmd_name,
+ WTERMSIG (status), strsignal (WTERMSIG (status)));
}
else if (WIFSTOPPED (status)) {
- snprintf (buffer, buflen, _("%s stopped by signal %d (%s)"),
- cmd_name, WSTOPSIG (status), strsignal (WSTOPSIG (status)));
+ snprintf (buffer, buflen, _("%s stopped by signal %d (%s)"), cmd_name,
+ WSTOPSIG (status), strsignal (WSTOPSIG (status)));
}
else {
- snprintf (buffer, buflen, _("%s exited for an unknown reason (status
%d)"),
- cmd_name, status);
+ snprintf (buffer, buflen,
+ _("%s exited for an unknown reason (status %d)"), cmd_name,
+ status);
}
return buffer;
@@ -229,7 +229,7 @@ guestfs_int_random_string (char *ret, size_t len)
unsigned char c;
int saved_errno;
- fd = open ("/dev/urandom", O_RDONLY|O_CLOEXEC);
+ fd = open ("/dev/urandom", O_RDONLY | O_CLOEXEC);
if (fd == -1)
return -1;
@@ -262,7 +262,7 @@ char *
guestfs_int_drive_name (size_t index, char *ret)
{
if (index >= 26)
- ret = guestfs_int_drive_name (index/26 - 1, ret);
+ ret = guestfs_int_drive_name (index / 26 - 1, ret);
index %= 26;
*ret++ = 'a' + index;
*ret = '\0';
@@ -281,49 +281,41 @@ guestfs_int_drive_index (const char *name)
while (*name) {
if (*name >= 'a' && *name <= 'z')
- r = 26*r + (*name - 'a' + 1);
+ r = 26 * r + (*name - 'a' + 1);
else
return -1;
name++;
}
- return r-1;
+ return r - 1;
}
/* Similar to Tcl_GetBoolean. */
int
guestfs_int_is_true (const char *str)
{
- if (STREQ (str, "1") ||
- STRCASEEQ (str, "true") ||
- STRCASEEQ (str, "t") ||
- STRCASEEQ (str, "yes") ||
- STRCASEEQ (str, "y") ||
+ if (STREQ (str, "1") || STRCASEEQ (str, "true") || STRCASEEQ (str,
"t") ||
+ STRCASEEQ (str, "yes") || STRCASEEQ (str, "y") ||
STRCASEEQ (str, "on"))
return 1;
- if (STREQ (str, "0") ||
- STRCASEEQ (str, "false") ||
- STRCASEEQ (str, "f") ||
- STRCASEEQ (str, "no") ||
- STRCASEEQ (str, "n") ||
- STRCASEEQ (str, "off"))
+ if (STREQ (str, "0") || STRCASEEQ (str, "false") ||
+ STRCASEEQ (str, "f") || STRCASEEQ (str, "no") ||
+ STRCASEEQ (str, "n") || STRCASEEQ (str, "off"))
return 0;
return -1;
}
/* See src/appliance.c:guestfs_int_get_uefi. */
-const char *
-guestfs_int_ovmf_i386_firmware[] = {
+const char *guestfs_int_ovmf_i386_firmware[] = {
"/usr/share/edk2.git/ovmf-ia32/OVMF_CODE-pure-efi.fd",
"/usr/share/edk2.git/ovmf-ia32/OVMF_VARS-pure-efi.fd",
NULL
};
-const char *
-guestfs_int_ovmf_x86_64_firmware[] = {
+const char *guestfs_int_ovmf_x86_64_firmware[] = {
"/usr/share/OVMF/OVMF_CODE.fd",
"/usr/share/OVMF/OVMF_VARS.fd",
@@ -336,10 +328,8 @@ guestfs_int_ovmf_x86_64_firmware[] = {
NULL
};
-const char *
-guestfs_int_aavmf_firmware[] = {
- "/usr/share/AAVMF/AAVMF_CODE.fd",
- "/usr/share/AAVMF/AAVMF_VARS.fd",
+const char *guestfs_int_aavmf_firmware[] = {
+ "/usr/share/AAVMF/AAVMF_CODE.fd",
"/usr/share/AAVMF/AAVMF_VARS.fd",
"/usr/share/edk2.git/aarch64/QEMU_EFI-pflash.raw",
"/usr/share/edk2.git/aarch64/vars-template-pflash.raw",
diff --git a/src/whole-file.c b/src/whole-file.c
index ae376b3..5ac2fcc 100644
--- a/src/whole-file.c
+++ b/src/whole-file.c
@@ -42,7 +42,7 @@ guestfs_int_read_whole_file (guestfs_h *g, const char *filename,
ssize_t r;
struct stat statbuf;
- fd = open (filename, O_RDONLY|O_CLOEXEC);
+ fd = open (filename, O_RDONLY | O_CLOEXEC);
if (fd == -1) {
perrorf (g, "open: %s", filename);
return -1;
diff --git a/test-tool/test-tool.c b/test-tool/test-tool.c
index c632440..642b197 100644
--- a/test-tool/test-tool.c
+++ b/test-tool/test-tool.c
@@ -64,8 +64,7 @@ usage (void)
" --timeout n\n"
" -t n Set launch timeout (default: %d seconds)\n"
" --version\n"
- " -V Display libguestfs version and exit\n"
- ),
+ " -V Display libguestfs version and exit\n"),
DEFAULT_TIMEOUT);
}
@@ -80,12 +79,9 @@ main (int argc, char *argv[])
static const char *options = "t:V?";
static const struct option long_options[] = {
- { "help", 0, 0, '?' },
- { "qemu", 1, 0, 0 },
- { "qemudir", 1, 0, 0 },
- { "timeout", 1, 0, 't' },
- { "version", 0, 0, 'V' },
- { 0, 0, 0, 0 }
+ { "help", 0, 0, '?' }, { "qemu", 1, 0, 0 },
+ { "qemudir", 1, 0, 0 }, { "timeout", 1, 0, 't' },
+ { "version", 0, 0, 'V' }, { 0, 0, 0, 0 }
};
int c;
int option_index;
@@ -99,10 +95,11 @@ main (int argc, char *argv[])
for (;;) {
c = getopt_long (argc, argv, options, long_options, &option_index);
- if (c == -1) break;
+ if (c == -1)
+ break;
switch (c) {
- case 0: /* options which are long only */
+ case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "qemu")) {
qemu = optarg;
qemu_use_wrapper = 0;
@@ -112,8 +109,7 @@ main (int argc, char *argv[])
qemu_use_wrapper = 1;
}
else
- error (EXIT_FAILURE, 0,
- _("unknown long option: %s (%d)"),
+ error (EXIT_FAILURE, 0, _("unknown long option: %s (%d)"),
long_options[option_index].name, option_index);
break;
@@ -129,9 +125,9 @@ main (int argc, char *argv[])
vers = guestfs_version (g);
if (vers == NULL)
exit (EXIT_FAILURE);
- printf ("%s
%"PRIi64".%"PRIi64".%"PRIi64"%s\n",
- "libguestfs-test-tool",
- vers->major, vers->minor, vers->release, vers->extra);
+ printf ("%s %" PRIi64 ".%" PRIi64 ".%" PRIi64
"%s\n",
+ "libguestfs-test-tool", vers->major, vers->minor,
+ vers->release, vers->extra);
guestfs_free_version (vers);
guestfs_close (g);
exit (EXIT_SUCCESS);
@@ -149,14 +145,14 @@ main (int argc, char *argv[])
error (EXIT_FAILURE, 0, _("extra arguments on the command line"));
/* Everyone ignores the documentation, so ... */
- printf ("
************************************************************\n"
- " * IMPORTANT NOTICE\n"
- " *\n"
- " * When reporting bugs, include the COMPLETE, UNEDITED\n"
- " * output below in your bug report.\n"
- " *\n"
- "
************************************************************\n"
- );
+ printf (
+ " ************************************************************\n"
+ " * IMPORTANT NOTICE\n"
+ " *\n"
+ " * When reporting bugs, include the COMPLETE, UNEDITED\n"
+ " * output below in your bug report.\n"
+ " *\n"
+ " ************************************************************\n");
sleep (3);
/* Create the handle. */
@@ -164,9 +160,9 @@ main (int argc, char *argv[])
if (g == NULL)
error (EXIT_FAILURE, errno, "guestfs_create_flags");
if (guestfs_parse_environment (g) == -1)
- error (EXIT_FAILURE, 0,
- _("failed parsing environment variables.\n"
- "Check earlier messages, and the output of the 'printenv'
command."));
+ error (EXIT_FAILURE, 0, _("failed parsing environment variables.\n"
+ "Check earlier messages, and the output of "
+ "the 'printenv' command."));
guestfs_set_verbose (g, 1);
if (qemu)
@@ -203,13 +199,13 @@ main (int argc, char *argv[])
ignore_value (system ("getenforce"));
/* Configure the handle. */
- if (guestfs_add_drive_scratch (g, 100*1024*1024, -1) == -1)
+ if (guestfs_add_drive_scratch (g, 100 * 1024 * 1024, -1) == -1)
exit (EXIT_FAILURE);
- printf ("guestfs_get_append: %s\n", guestfs_get_append (g) ? :
"(null)");
+ printf ("guestfs_get_append: %s\n", guestfs_get_append (g) ?:
"(null)");
printf ("guestfs_get_autosync: %d\n", guestfs_get_autosync (g));
p = guestfs_get_backend (g);
- printf ("guestfs_get_backend: %s\n", p ? : "(null)");
+ printf ("guestfs_get_backend: %s\n", p ?: "(null)");
free (p);
pp = guestfs_get_backend_settings (g);
printf ("guestfs_get_backend_settings: [");
@@ -222,7 +218,7 @@ main (int argc, char *argv[])
printf ("]\n");
free (pp);
p = guestfs_get_cachedir (g);
- printf ("guestfs_get_cachedir: %s\n", p ? : "(null)");
+ printf ("guestfs_get_cachedir: %s\n", p ?: "(null)");
free (p);
printf ("guestfs_get_direct: %d\n", guestfs_get_direct (g));
p = guestfs_get_hv (g);
@@ -230,17 +226,17 @@ main (int argc, char *argv[])
free (p);
printf ("guestfs_get_memsize: %d\n", guestfs_get_memsize (g));
printf ("guestfs_get_network: %d\n", guestfs_get_network (g));
- printf ("guestfs_get_path: %s\n", guestfs_get_path (g) ? :
"(null)");
+ printf ("guestfs_get_path: %s\n", guestfs_get_path (g) ?:
"(null)");
printf ("guestfs_get_pgroup: %d\n", guestfs_get_pgroup (g));
printf ("guestfs_get_program: %s\n", guestfs_get_program (g));
printf ("guestfs_get_recovery_proc: %d\n", guestfs_get_recovery_proc (g));
printf ("guestfs_get_selinux: %d\n", guestfs_get_selinux (g));
printf ("guestfs_get_smp: %d\n", guestfs_get_smp (g));
p = guestfs_get_sockdir (g);
- printf ("guestfs_get_sockdir: %s\n", p ? : "(null)");
+ printf ("guestfs_get_sockdir: %s\n", p ?: "(null)");
free (p);
p = guestfs_get_tmpdir (g);
- printf ("guestfs_get_tmpdir: %s\n", p ? : "(null)");
+ printf ("guestfs_get_tmpdir: %s\n", p ?: "(null)");
free (p);
printf ("guestfs_get_trace: %d\n", guestfs_get_trace (g));
printf ("guestfs_get_verbose: %d\n", guestfs_get_verbose (g));
@@ -308,9 +304,9 @@ set_qemu (guestfs_h *g, const char *path, int use_wrapper)
if (getenv ("LIBGUESTFS_QEMU") != NULL ||
getenv ("LIBGUESTFS_HV") != NULL)
- error (EXIT_FAILURE, 0,
- _("LIBGUESTFS_HV/LIBGUESTFS_QEMU environment variable is already set,
so\n"
- "--qemu/--qemudir options cannot be used."));
+ error (EXIT_FAILURE, 0, _("LIBGUESTFS_HV/LIBGUESTFS_QEMU environment "
+ "variable is already set, so\n"
+ "--qemu/--qemudir options cannot be used."));
if (!use_wrapper) {
if (access (path, X_OK) == -1)
@@ -324,8 +320,7 @@ set_qemu (guestfs_h *g, const char *path, int use_wrapper)
/* This should be a source directory, so check it. */
if (asprintf (&buffer, "%s/pc-bios", path) == -1)
error (EXIT_FAILURE, errno, "asprintf");
- if (stat (buffer, &statbuf) == -1 ||
- !S_ISDIR (statbuf.st_mode))
+ if (stat (buffer, &statbuf) == -1 || !S_ISDIR (statbuf.st_mode))
error (EXIT_FAILURE, errno,
_("path does not look like a qemu source directory: %s"), path);
@@ -337,24 +332,25 @@ set_qemu (guestfs_h *g, const char *path, int use_wrapper)
fchmod (fd, 0700);
fp = fdopen (fd, "w");
- fprintf (fp,
- "#!/bin/sh -\n"
- "host_cpu=%s\n"
- "qemudir='%s'\n"
- "case $host_cpu in\n"
- " amd64*)\n"
- "
qemu=\"$qemudir/$host_cpu-softmmu/qemu-system-x86_64\"\n"
- " ;;\n"
- " arm*)
qemu=\"$qemudir/$host_cpu-softmmu/qemu-system-arm\"\n"
- " ;;\n"
- " powerpc64|ppc64le|powerpc64le)\n"
- "
qemu=\"$qemudir/$host_cpu-softmmu/qemu-system-ppc64\"\n"
- " ;;\n"
- " *)
qemu=\"$qemudir/$host_cpu-softmmu/qemu-system-$host_cpu\"\n"
- " ;;\n"
- "esac\n"
- "exec \"$qemu\" -L \"$qemudir/pc-bios\"
\"$@\"\n",
- host_cpu, path);
+ fprintf (
+ fp,
+ "#!/bin/sh -\n"
+ "host_cpu=%s\n"
+ "qemudir='%s'\n"
+ "case $host_cpu in\n"
+ " amd64*)\n"
+ "
qemu=\"$qemudir/$host_cpu-softmmu/qemu-system-x86_64\"\n"
+ " ;;\n"
+ " arm*)
qemu=\"$qemudir/$host_cpu-softmmu/qemu-system-arm\"\n"
+ " ;;\n"
+ " powerpc64|ppc64le|powerpc64le)\n"
+ "
qemu=\"$qemudir/$host_cpu-softmmu/qemu-system-ppc64\"\n"
+ " ;;\n"
+ " *)
qemu=\"$qemudir/$host_cpu-softmmu/qemu-system-$host_cpu\"\n"
+ " ;;\n"
+ "esac\n"
+ "exec \"$qemu\" -L \"$qemudir/pc-bios\"
\"$@\"\n",
+ host_cpu, path);
fclose (fp);
guestfs_set_hv (g, qemuwrapper);
diff --git a/tests/c-api/test-add-drive-opts.c b/tests/c-api/test-add-drive-opts.c
index 4f39e26..d7beffb 100644
--- a/tests/c-api/test-add-drive-opts.c
+++ b/tests/c-api/test-add-drive-opts.c
@@ -42,14 +42,12 @@ main (int argc, char *argv[])
if (r == -1)
exit (EXIT_FAILURE);
r = guestfs_add_drive_opts (g, "/dev/null",
- GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,
- -1);
+ GUESTFS_ADD_DRIVE_OPTS_READONLY, 1, -1);
if (r == -1)
exit (EXIT_FAILURE);
- r = guestfs_add_drive_opts (g, "/dev/null",
- GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,
- GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
- -1);
+ r =
+ guestfs_add_drive_opts (g, "/dev/null", GUESTFS_ADD_DRIVE_OPTS_READONLY,
+ 1, GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw", -1);
if (r == -1)
exit (EXIT_FAILURE);
diff --git a/tests/c-api/test-add-libvirt-dom.c b/tests/c-api/test-add-libvirt-dom.c
index 612b86e..a728d4f 100644
--- a/tests/c-api/test-add-libvirt-dom.c
+++ b/tests/c-api/test-add-libvirt-dom.c
@@ -36,34 +36,33 @@
static void
make_test_xml (FILE *fp, const char *cwd)
{
- fprintf (fp,
- "<?xml version=\"1.0\"?>\n"
- "<node>\n"
- " <domain type='test'>\n"
- " <name>guest</name>\n"
- " <os>\n"
- " <type>hvm</type>\n"
- " <boot dev='hd'/>\n"
- " </os>\n"
- " <memory>524288</memory>\n"
- " <devices>\n"
- " <disk type='file'>\n"
- " <source
file='%s/test-add-libvirt-dom-1.img'/>\n"
- " <target dev='hda'/>\n"
- " </disk>\n"
- " <disk type='file'>\n"
- " <driver name='qemu' type='raw'/>\n"
- " <source
file='%s/test-add-libvirt-dom-2.img'/>\n"
- " <target dev='hdb'/>\n"
- " </disk>\n"
- " <disk type='file'>\n"
- " <driver name='qemu'
type='qcow2'/>\n"
- " <source
file='%s/test-add-libvirt-dom-3.img'/>\n"
- " <target dev='hdc'/>\n"
- " </disk>\n"
- " </devices>\n"
- " </domain>\n"
- "</node>",
+ fprintf (fp, "<?xml version=\"1.0\"?>\n"
+ "<node>\n"
+ " <domain type='test'>\n"
+ " <name>guest</name>\n"
+ " <os>\n"
+ " <type>hvm</type>\n"
+ " <boot dev='hd'/>\n"
+ " </os>\n"
+ " <memory>524288</memory>\n"
+ " <devices>\n"
+ " <disk type='file'>\n"
+ " <source
file='%s/test-add-libvirt-dom-1.img'/>\n"
+ " <target dev='hda'/>\n"
+ " </disk>\n"
+ " <disk type='file'>\n"
+ " <driver name='qemu'
type='raw'/>\n"
+ " <source
file='%s/test-add-libvirt-dom-2.img'/>\n"
+ " <target dev='hdb'/>\n"
+ " </disk>\n"
+ " <disk type='file'>\n"
+ " <driver name='qemu'
type='qcow2'/>\n"
+ " <source
file='%s/test-add-libvirt-dom-3.img'/>\n"
+ " <target dev='hdc'/>\n"
+ " </disk>\n"
+ " </devices>\n"
+ " </domain>\n"
+ "</node>",
cwd, cwd, cwd);
}
@@ -90,7 +89,8 @@ main (int argc, char *argv[])
backend = guestfs_get_backend (g);
if (STREQ (backend, "uml")) {
free (backend);
- error (77, 0, "test skipped because UML backend does not support qcow2");
+ error (77, 0,
+ "test skipped because UML backend does not support qcow2");
}
free (backend);
@@ -104,15 +104,15 @@ main (int argc, char *argv[])
fclose (fp);
if (guestfs_disk_create (g, "test-add-libvirt-dom-1.img", "raw",
- 1024*1024, -1) == -1)
+ 1024 * 1024, -1) == -1)
exit (EXIT_FAILURE);
if (guestfs_disk_create (g, "test-add-libvirt-dom-2.img", "raw",
- 1024*1024, -1) == -1)
+ 1024 * 1024, -1) == -1)
exit (EXIT_FAILURE);
if (guestfs_disk_create (g, "test-add-libvirt-dom-3.img", "qcow2",
- 1024*1024, -1) == -1)
+ 1024 * 1024, -1) == -1)
exit (EXIT_FAILURE);
/* Create the libvirt connection. */
@@ -129,12 +129,11 @@ main (int argc, char *argv[])
dom = virDomainLookupByName (conn, "guest");
if (!dom) {
err = virGetLastError ();
- error (EXIT_FAILURE, 0,
- "no libvirt domain called '%s': %s", "guest",
err->message);
+ error (EXIT_FAILURE, 0, "no libvirt domain called '%s': %s",
"guest",
+ err->message);
}
- r = guestfs_add_libvirt_dom (g, dom,
- GUESTFS_ADD_LIBVIRT_DOM_READONLY, 1,
+ r = guestfs_add_libvirt_dom (g, dom, GUESTFS_ADD_LIBVIRT_DOM_READONLY, 1,
-1);
if (r == -1)
exit (EXIT_FAILURE);
diff --git a/tests/c-api/test-backend-settings.c b/tests/c-api/test-backend-settings.c
index 371a247..86adaa3 100644
--- a/tests/c-api/test-backend-settings.c
+++ b/tests/c-api/test-backend-settings.c
@@ -68,10 +68,9 @@ main (int argc, char *argv[])
*/
for (pass = 0; pass <= 1; ++pass) {
if (pass == 0) {
- const char *initial_settings[] = {
- "foo", "foo=1", "foo=bar", "bar",
"baz=value", NULL
- };
- r = guestfs_set_backend_settings (g, (char **) initial_settings);
+ const char *initial_settings[] = { "foo", "foo=1",
"foo=bar",
+ "bar", "baz=value", NULL };
+ r = guestfs_set_backend_settings (g, (char **)initial_settings);
assert (r == 0);
}
else /* pass == 1 */ {
diff --git a/tests/c-api/test-command.c b/tests/c-api/test-command.c
index b14f0f1..c5265f0 100644
--- a/tests/c-api/test-command.c
+++ b/tests/c-api/test-command.c
@@ -27,7 +27,7 @@
#include <unistd.h>
#include <error.h>
-#define STREQ(a,b) (strcmp((a),(b)) == 0)
+#define STREQ(a, b) (strcmp ((a), (b)) == 0)
int
main (int argc, char *argv[])
@@ -35,29 +35,41 @@ main (int argc, char *argv[])
if (argc > 1) {
if (STREQ (argv[1], "1")) {
printf ("Result1");
- } else if (STREQ (argv[1], "2")) {
+ }
+ else if (STREQ (argv[1], "2")) {
printf ("Result2\n");
- } else if (STREQ (argv[1], "3")) {
+ }
+ else if (STREQ (argv[1], "3")) {
printf ("\nResult3");
- } else if (STREQ (argv[1], "4")) {
+ }
+ else if (STREQ (argv[1], "4")) {
printf ("\nResult4\n");
- } else if (STREQ (argv[1], "5")) {
+ }
+ else if (STREQ (argv[1], "5")) {
printf ("\nResult5\n\n");
- } else if (STREQ (argv[1], "6")) {
+ }
+ else if (STREQ (argv[1], "6")) {
printf ("\n\nResult6\n\n");
- } else if (STREQ (argv[1], "7")) {
+ }
+ else if (STREQ (argv[1], "7")) {
/* nothing */
- } else if (STREQ (argv[1], "8")) {
+ }
+ else if (STREQ (argv[1], "8")) {
printf ("\n");
- } else if (STREQ (argv[1], "9")) {
+ }
+ else if (STREQ (argv[1], "9")) {
printf ("\n\n");
- } else if (STREQ (argv[1], "10")) {
+ }
+ else if (STREQ (argv[1], "10")) {
printf ("Result10-1\nResult10-2\n");
- } else if (STREQ (argv[1], "11")) {
+ }
+ else if (STREQ (argv[1], "11")) {
printf ("Result11-1\nResult11-2");
- } else
+ }
+ else
error (EXIT_FAILURE, 0, "unknown parameter: %s", argv[1]);
- } else
+ }
+ else
error (EXIT_FAILURE, 0, "missing parameter");
exit (EXIT_SUCCESS);
diff --git a/tests/c-api/test-debug-to-file.c b/tests/c-api/test-debug-to-file.c
index 10e36c6..1a22526 100644
--- a/tests/c-api/test-debug-to-file.c
+++ b/tests/c-api/test-debug-to-file.c
@@ -35,12 +35,8 @@
#include "ignore-value.h"
static void
-debug_to_file (guestfs_h *g,
- void *opaque,
- uint64_t event,
- int event_handle,
- int flags,
- const char *buf, size_t buf_len,
+debug_to_file (guestfs_h *g, void *opaque, uint64_t event, int event_handle,
+ int flags, const char *buf, size_t buf_len,
const uint64_t *array, size_t array_len)
{
FILE *fp = opaque;
@@ -63,11 +59,10 @@ main (int argc, char *argv[])
if (g == NULL)
error (EXIT_FAILURE, errno, "guestfs_create");
- if (guestfs_set_event_callback
- (g, debug_to_file,
- GUESTFS_EVENT_LIBRARY | GUESTFS_EVENT_APPLIANCE |
- GUESTFS_EVENT_WARNING | GUESTFS_EVENT_TRACE,
- 0, debugfp) == -1)
+ if (guestfs_set_event_callback (
+ g, debug_to_file, GUESTFS_EVENT_LIBRARY | GUESTFS_EVENT_APPLIANCE |
+ GUESTFS_EVENT_WARNING | GUESTFS_EVENT_TRACE,
+ 0, debugfp) == -1)
exit (EXIT_FAILURE);
if (guestfs_set_verbose (g, 1) == -1)
@@ -76,9 +71,8 @@ main (int argc, char *argv[])
if (guestfs_set_trace (g, 1) == -1)
exit (EXIT_FAILURE);
- if (guestfs_add_drive_opts (g, "/dev/null",
- GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
- GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,
+ if (guestfs_add_drive_opts (g, "/dev/null", GUESTFS_ADD_DRIVE_OPTS_FORMAT,
+ "raw", GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,
-1) == -1)
exit (EXIT_FAILURE);
diff --git a/tests/c-api/test-dlopen.c b/tests/c-api/test-dlopen.c
index 8a4174c..345a51a 100644
--- a/tests/c-api/test-dlopen.c
+++ b/tests/c-api/test-dlopen.c
@@ -31,7 +31,7 @@
typedef struct guestfs_h guestfs_h;
typedef guestfs_h *(*guestfs_create_t) (void);
-typedef const char * (*guestfs_get_program_t) (guestfs_h *);
+typedef const char *(*guestfs_get_program_t) (guestfs_h *);
typedef void (*guestfs_close_t) (guestfs_h *);
#ifndef LIBRARY
@@ -47,8 +47,7 @@ read_symbol (void *lib, const char *symbol)
dlerror (); /* Clear error indicator. */
symval = dlsym (lib, symbol);
if ((err = dlerror ()) != NULL)
- error (EXIT_FAILURE, 0,
- "could not read symbol: %s: %s", symbol, err);
+ error (EXIT_FAILURE, 0, "could not read symbol: %s: %s", symbol, err);
return symval;
}
@@ -62,7 +61,8 @@ main (int argc, char *argv[])
guestfs_h *g;
if (access (LIBRARY, X_OK) == -1)
- error (77, errno, "test skipped because %s cannot be accessed", LIBRARY);
+ error (77, errno, "test skipped because %s cannot be accessed",
+ LIBRARY);
lib = dlopen (LIBRARY, RTLD_LAZY);
if (lib == NULL)
diff --git a/tests/c-api/test-environment.c b/tests/c-api/test-environment.c
index d5a03d4..362d818 100644
--- a/tests/c-api/test-environment.c
+++ b/tests/c-api/test-environment.c
@@ -41,22 +41,27 @@ main (int argc, char *argv[])
/* What's the default memsize? */
g = guestfs_create ();
- if (!g) error (EXIT_FAILURE, errno, "guestfs_create");
+ if (!g)
+ error (EXIT_FAILURE, errno, "guestfs_create");
default_memsize = guestfs_get_memsize (g);
- if (default_memsize == -1) exit (EXIT_FAILURE);
+ if (default_memsize == -1)
+ exit (EXIT_FAILURE);
guestfs_close (g);
/* Check that guestfs_create parses the environment. */
setenv ("LIBGUESTFS_MEMSIZE", "799", 1);
g = guestfs_create ();
- if (!g) error (EXIT_FAILURE, errno, "guestfs_create");
+ if (!g)
+ error (EXIT_FAILURE, errno, "guestfs_create");
assert (guestfs_get_memsize (g) == 799);
guestfs_close (g);
- /* Check that guestfs_create_flags with no flags parses the environment. */
+ /* Check that guestfs_create_flags with no flags parses the environment.
+ */
setenv ("LIBGUESTFS_MEMSIZE", "798", 1);
g = guestfs_create_flags (0);
- if (!g) error (EXIT_FAILURE, errno, "guestfs_create_flags");
+ if (!g)
+ error (EXIT_FAILURE, errno, "guestfs_create_flags");
assert (guestfs_get_memsize (g) == 798);
guestfs_close (g);
@@ -64,10 +69,12 @@ main (int argc, char *argv[])
setenv ("LIBGUESTFS_MEMSIZE", "797", 1);
g = guestfs_create_flags (GUESTFS_CREATE_NO_ENVIRONMENT);
assert (guestfs_get_memsize (g) == default_memsize);
- if (!g) error (EXIT_FAILURE, errno, "guestfs_create_flags");
+ if (!g)
+ error (EXIT_FAILURE, errno, "guestfs_create_flags");
setenv ("LIBGUESTFS_MEMSIZE", "796", 1);
r = guestfs_parse_environment (g);
- if (r == -1) exit (EXIT_FAILURE);
+ if (r == -1)
+ exit (EXIT_FAILURE);
assert (guestfs_get_memsize (g) == 796);
guestfs_close (g);
@@ -75,7 +82,8 @@ main (int argc, char *argv[])
setenv ("LIBGUESTFS_MEMSIZE", "795", 1);
g = guestfs_create_flags (GUESTFS_CREATE_NO_ENVIRONMENT);
assert (guestfs_get_memsize (g) == default_memsize);
- if (!g) error (EXIT_FAILURE, errno, "guestfs_create_flags");
+ if (!g)
+ error (EXIT_FAILURE, errno, "guestfs_create_flags");
setenv ("LIBGUESTFS_MEMSIZE", "794", 1);
const char *local_environment[] = {
"LIBGUESTFS_MEMSIZE=793",
@@ -85,8 +93,9 @@ main (int argc, char *argv[])
"BLAH",
NULL
};
- r = guestfs_parse_environment_list (g, (char **) local_environment);
- if (r == -1) exit (EXIT_FAILURE);
+ r = guestfs_parse_environment_list (g, (char **)local_environment);
+ if (r == -1)
+ exit (EXIT_FAILURE);
assert (guestfs_get_memsize (g) == 793);
guestfs_close (g);
diff --git a/tests/c-api/test-event-string.c b/tests/c-api/test-event-string.c
index e94000d..6007b63 100644
--- a/tests/c-api/test-event-string.c
+++ b/tests/c-api/test-event-string.c
@@ -53,7 +53,8 @@ main (int argc, char *argv[])
assert (STREQ (str, "close,progress"));
free (str);
- events = GUESTFS_EVENT_CLOSE | GUESTFS_EVENT_SUBPROCESS_QUIT | GUESTFS_EVENT_ENTER;
+ events = GUESTFS_EVENT_CLOSE | GUESTFS_EVENT_SUBPROCESS_QUIT |
+ GUESTFS_EVENT_ENTER;
str = guestfs_event_to_string (events);
assert (str != NULL);
assert (STREQ (str, "close,enter,subprocess_quit"));
diff --git a/tests/c-api/test-private-data.c b/tests/c-api/test-private-data.c
index 9ebe7a8..42e7f39 100644
--- a/tests/c-api/test-private-data.c
+++ b/tests/c-api/test-private-data.c
@@ -37,20 +37,16 @@ static size_t close_callback_called = 0;
/* This callback deletes all test keys in the handle. */
static void
-close_callback (guestfs_h *g,
- void *opaque,
- uint64_t event,
- int event_handle,
- int flags,
- const char *buf, size_t buf_len,
- const uint64_t *array, size_t array_len)
+close_callback (guestfs_h *g, void *opaque, uint64_t event,
+ int event_handle, int flags, const char *buf,
+ size_t buf_len, const uint64_t *array, size_t array_len)
{
const char *key;
void *data;
close_callback_called++;
- again:
+again:
data = guestfs_first_private (g, &key);
while (data != NULL) {
if (strncmp (key, PREFIX, strlen (PREFIX)) == 0) {
@@ -73,19 +69,19 @@ main (int argc, char *argv[])
if (g == NULL)
error (EXIT_FAILURE, errno, "guestfs_create");
- if (guestfs_set_event_callback (g, close_callback, GUESTFS_EVENT_CLOSE,
- 0, NULL) == -1)
+ if (guestfs_set_event_callback (g, close_callback, GUESTFS_EVENT_CLOSE, 0,
+ NULL) == -1)
exit (EXIT_FAILURE);
- guestfs_set_private (g, PREFIX "a", (void *) 1);
- guestfs_set_private (g, PREFIX "b", (void *) 2);
- guestfs_set_private (g, PREFIX "c", (void *) 3);
- guestfs_set_private (g, PREFIX "a", (void *) 4); /* overwrites previous */
+ guestfs_set_private (g, PREFIX "a", (void *)1);
+ guestfs_set_private (g, PREFIX "b", (void *)2);
+ guestfs_set_private (g, PREFIX "c", (void *)3);
+ guestfs_set_private (g, PREFIX "a", (void *)4); /* overwrites previous */
/* Check we can fetch keys. */
- assert (guestfs_get_private (g, PREFIX "a") == (void *) 4);
- assert (guestfs_get_private (g, PREFIX "b") == (void *) 2);
- assert (guestfs_get_private (g, PREFIX "c") == (void *) 3);
+ assert (guestfs_get_private (g, PREFIX "a") == (void *)4);
+ assert (guestfs_get_private (g, PREFIX "b") == (void *)2);
+ assert (guestfs_get_private (g, PREFIX "c") == (void *)3);
assert (guestfs_get_private (g, PREFIX "d") == NULL);
/* Check we can count keys by iterating. */
diff --git a/tests/c-api/test-pwd.c b/tests/c-api/test-pwd.c
index 61b88ec..b1dd532 100644
--- a/tests/c-api/test-pwd.c
+++ b/tests/c-api/test-pwd.c
@@ -28,8 +28,8 @@
int
main (int argc, char *argv[])
{
- char *cwd = getcwd(NULL, 0);
- printf("%s", cwd);
+ char *cwd = getcwd (NULL, 0);
+ printf ("%s", cwd);
exit (EXIT_SUCCESS);
}
diff --git a/tests/c-api/test-user-cancel.c b/tests/c-api/test-user-cancel.c
index 3823682..a2d5722 100644
--- a/tests/c-api/test-user-cancel.c
+++ b/tests/c-api/test-user-cancel.c
@@ -48,19 +48,19 @@
#include "guestfs.h"
#include "guestfs-internal-frontend.h"
-static const off_t filesize = 1024*1024*1024;
+static const off_t filesize = 1024 * 1024 * 1024;
static void *start_test_thread (void *) __attribute__((noreturn));
static off_t random_cancel_posn (void);
struct test_thread_data {
- guestfs_h *g; /* handle */
- int direction; /* direction of transfer */
-#define DIRECTION_UP 1 /* upload (test thread is writing) */
-#define DIRECTION_DOWN 2 /* download (test thread is reading) */
- int fd; /* pipe to read/write */
- off_t cancel_posn; /* position at which to cancel */
- off_t transfer_size; /* how much data thread wrote/read */
+ guestfs_h *g; /* handle */
+ int direction; /* direction of transfer */
+#define DIRECTION_UP 1 /* upload (test thread is writing) */
+#define DIRECTION_DOWN 2 /* download (test thread is reading) */
+ int fd; /* pipe to read/write */
+ off_t cancel_posn; /* position at which to cancel */
+ off_t transfer_size; /* how much data thread wrote/read */
};
int
@@ -134,11 +134,12 @@ main (int argc, char *argv[])
/* We expect to get an error, with errno == EINTR. */
if (op_error == -1 && op_errno == EINTR)
printf ("test-user-cancel: upload cancellation test passed (%ld/%ld)\n",
- (long) data.cancel_posn, (long) data.transfer_size);
+ (long)data.cancel_posn, (long)data.transfer_size);
else {
fprintf (stderr, "test-user-cancel: upload cancellation test FAILED\n");
- fprintf (stderr, "cancel_posn %ld, upload returned %d, errno = %d (%s)\n",
- (long) data.cancel_posn, op_error, op_errno, strerror (op_errno));
+ fprintf (
+ stderr, "cancel_posn %ld, upload returned %d, errno = %d (%s)\n",
+ (long)data.cancel_posn, op_error, op_errno, strerror (op_errno));
errors++;
}
@@ -150,7 +151,7 @@ main (int argc, char *argv[])
if (guestfs_touch (g, "/download") == -1)
exit (EXIT_FAILURE);
- if (guestfs_truncate_size (g, "/download", filesize/4) == -1)
+ if (guestfs_truncate_size (g, "/download", filesize / 4) == -1)
exit (EXIT_FAILURE);
data.g = g;
@@ -191,12 +192,15 @@ main (int argc, char *argv[])
/* We expect to get an error, with errno == EINTR. */
if (op_error == -1 && op_errno == EINTR)
- printf ("test-user-cancel: download cancellation test passed (%ld/%ld)\n",
- (long) data.cancel_posn, (long) data.transfer_size);
+ printf (
+ "test-user-cancel: download cancellation test passed (%ld/%ld)\n",
+ (long)data.cancel_posn, (long)data.transfer_size);
else {
- fprintf (stderr, "test-user-cancel: download cancellation test FAILED\n");
- fprintf (stderr, "cancel_posn %ld, upload returned %d, errno = %d (%s)\n",
- (long) data.cancel_posn, op_error, op_errno, strerror (op_errno));
+ fprintf (stderr,
+ "test-user-cancel: download cancellation test FAILED\n");
+ fprintf (
+ stderr, "cancel_posn %ld, upload returned %d, errno = %d (%s)\n",
+ (long)data.cancel_posn, op_error, op_errno, strerror (op_errno));
errors++;
}
@@ -242,7 +246,8 @@ start_test_thread (void *datav)
"test thread: write to pipe after user cancel");
data->transfer_size += r;
}
- } else { /* thread is reading */
+ }
+ else { /* thread is reading */
/* Sink data, up to the cancellation point. */
while (data->transfer_size < data->cancel_posn) {
n = MIN (sizeof buffer,
@@ -292,7 +297,7 @@ random_cancel_posn (void)
r = random_gauss (mu, sd);
} while (r <= 0);
- return (off_t) r;
+ return (off_t)r;
}
/* Generate a random Gaussian distributed number using the Box-Muller
@@ -311,6 +316,6 @@ random_gauss (double mu, double sd)
w = sqrt ((-2. * log (w)) / w);
y1 = x1 * w;
- //y2 = x2 * w;
+ // y2 = x2 * w;
return mu + y1 * sd;
}
diff --git a/tests/c-api/tests-main.c b/tests/c-api/tests-main.c
index e3af651..1753e70 100644
--- a/tests/c-api/tests-main.c
+++ b/tests/c-api/tests-main.c
@@ -119,7 +119,7 @@ init_basic_fs_on_lvm (guestfs_h *g)
if (guestfs_pvcreate (g, "/dev/sda1") == -1)
return -1;
- if (guestfs_vgcreate (g, "VG", (char **) pvs) == -1)
+ if (guestfs_vgcreate (g, "VG", (char **)pvs) == -1)
return -1;
if (guestfs_lvcreate (g, "LV", "VG", 8) == -1)
@@ -167,13 +167,15 @@ print_strings (char *const *argv)
printf ("\t%s\n", argv[argc]);
}
-static int compare_lists (char **, char **, int (*) (const char *, const char *));
+static int compare_lists (char **, char **,
+ int (*) (const char *, const char *));
/* Compare 'ret' to the string list that follows. */
int
is_string_list (char **ret, size_t n, ...)
{
- CLEANUP_FREE /* sic */ char **expected = malloc ((n+1) * sizeof (char *));
+ CLEANUP_FREE /* sic */ char **expected =
+ malloc ((n + 1) * sizeof (char *));
size_t i;
va_list args;
@@ -189,7 +191,8 @@ is_string_list (char **ret, size_t n, ...)
int
is_device_list (char **ret, size_t n, ...)
{
- CLEANUP_FREE /* sic */ char **expected = malloc ((n+1) * sizeof (char *));
+ CLEANUP_FREE /* sic */ char **expected =
+ malloc ((n + 1) * sizeof (char *));
size_t i;
va_list args;
@@ -224,7 +227,7 @@ compare_lists (char **ret, char **expected,
return 1; /* test expecting true for OK */
- fail:
+fail:
fprintf (stderr, "returned list was:\n");
print_strings (ret);
fprintf (stderr, "expected list was:\n");
@@ -290,8 +293,10 @@ check_file_md5 (const char *ret, const char *filename)
md5sum (filename, expected);
if (STRNEQ (ret, expected)) {
- fprintf (stderr, "test failed: MD5 returned (%s) does not match MD5 of file %s
(%s)\n",
- ret, filename, expected);
+ fprintf (
+ stderr,
+ "test failed: MD5 returned (%s) does not match MD5 of file %s (%s)\n",
+ ret, filename, expected);
return -1;
}
@@ -308,7 +313,7 @@ get_key (char **hash, const char *key)
for (i = 0; hash[i] != NULL; i += 2) {
if (STREQ (hash[i], key))
- return hash[i+1];
+ return hash[i + 1];
}
return NULL; /* key not found */
@@ -326,8 +331,10 @@ check_hash (char **ret, const char *key, const char *expected)
}
if (STRNEQ (value, expected)) {
- fprintf (stderr, "test failed: hash key %s = \"%s\" is not expected
value \"%s\"\n",
- key, value, expected);
+ fprintf (
+ stderr,
+ "test failed: hash key %s = \"%s\" is not expected value
\"%s\"\n",
+ key, value, expected);
return -1;
}
@@ -346,8 +353,8 @@ match_re (const char *str, const char *pattern)
re = pcre_compile (pattern, 0, &err, &offset, NULL);
if (re == NULL)
- error (EXIT_FAILURE, 0,
- "cannot compile regular expression '%s': %s", pattern,
err);
+ error (EXIT_FAILURE, 0, "cannot compile regular expression '%s':
%s",
+ pattern, err);
r = pcre_exec (re, NULL, str, len, 0, 0, vec, sizeof vec / sizeof vec[0]);
pcre_free (re);
@@ -369,11 +376,12 @@ substitute_srcdir (const char *path)
srcdir = getenv ("srcdir");
if (!srcdir)
- error (EXIT_FAILURE, 0,
- "environment variable $srcdir is not defined.\n"
- "Normally it is defined by automake. If you are running the\n"
- "tests directly, set $srcdir to point to the source
tests/c-api\n"
- "directory.");
+ error (
+ EXIT_FAILURE, 0,
+ "environment variable $srcdir is not defined.\n"
+ "Normally it is defined by automake. If you are running the\n"
+ "tests directly, set $srcdir to point to the source tests/c-api\n"
+ "directory.");
if (asprintf (&ret, "%s%s", srcdir, path + 7) == -1)
error (EXIT_FAILURE, errno, "asprintf");
@@ -397,7 +405,8 @@ static void
next_test (guestfs_h *g, size_t test_num, const char *test_name)
{
if (guestfs_get_verbose (g))
- printf
("-------------------------------------------------------------------------------\n");
+ printf ("--------------------------------------------------------------"
+ "-----------------\n");
printf ("%3zu/%3zu %s\n", test_num, nr_tests, test_name);
}
@@ -413,8 +422,7 @@ skipped (const char *test_name, const char *fs, ...)
va_end (args);
assert (len >= 0);
- printf (" %s skipped (reason: %s)\n",
- test_name, reason);
+ printf (" %s skipped (reason: %s)\n", test_name, reason);
}
/* Create the handle, with attached disks. */
@@ -429,17 +437,19 @@ create_handle (void)
exit (EXIT_FAILURE);
}
- if (guestfs_add_drive_scratch (g, INT64_C(2)*1024*1024*1024, -1) == -1) {
+ if (guestfs_add_drive_scratch (g, INT64_C (2) * 1024 * 1024 * 1024, -1) ==
+ -1) {
printf ("FAIL: guestfs_add_drive_scratch\n");
exit (EXIT_FAILURE);
}
- if (guestfs_add_drive_scratch (g, INT64_C(2)*1024*1024*1024, -1) == -1) {
+ if (guestfs_add_drive_scratch (g, INT64_C (2) * 1024 * 1024 * 1024, -1) ==
+ -1) {
printf ("FAIL: guestfs_add_drive_scratch\n");
exit (EXIT_FAILURE);
}
- if (guestfs_add_drive_scratch (g, INT64_C(10)*1024*1024, -1) == -1) {
+ if (guestfs_add_drive_scratch (g, INT64_C (10) * 1024 * 1024, -1) == -1) {
printf ("FAIL: guestfs_add_drive_scratch\n");
exit (EXIT_FAILURE);
}
diff --git a/tests/c-api/tests.h b/tests/c-api/tests.h
index d8d5881..1428d07 100644
--- a/tests/c-api/tests.h
+++ b/tests/c-api/tests.h
@@ -38,13 +38,15 @@ extern void no_test_warnings (void);
extern int is_string_list (char **ret, size_t n, ...);
extern int is_device_list (char **ret, size_t n, ...);
extern int compare_devices (const char *dev1, const char *dev2);
-extern int compare_buffers (const char *b1, size_t s1, const char *b2, size_t s2);
+extern int compare_buffers (const char *b1, size_t s1, const char *b2,
+ size_t s2);
extern int check_file_md5 (const char *ret, const char *filename);
extern const char *get_key (char **hash, const char *key);
extern int check_hash (char **ret, const char *key, const char *expected);
extern int match_re (const char *str, const char *pattern);
extern int using_cross_appliance (void);
extern char *substitute_srcdir (const char *path);
-extern void skipped (const char *test_name, const char *fs, ...) __attribute__((format
(printf,2,3)));
+extern void skipped (const char *test_name, const char *fs, ...)
+ __attribute__((format (printf, 2, 3)));
#endif /* TESTS_H_ */
diff --git a/tests/charsets/test-charset-fidelity.c
b/tests/charsets/test-charset-fidelity.c
index 9a477ce..9123448 100644
--- a/tests/charsets/test-charset-fidelity.c
+++ b/tests/charsets/test-charset-fidelity.c
@@ -36,9 +36,9 @@
static const char ourenvvar[] = "SKIP_TEST_CHARSET_FIDELITY";
struct filesystem {
- const char *fs_name; /* Name of filesystem. */
- int fs_case_insensitive; /* True if filesystem is case insensitive. */
- int fs_8bit_only; /* True if fs only supports 8 bit chars. */
+ const char *fs_name; /* Name of filesystem. */
+ int fs_case_insensitive; /* True if filesystem is case insensitive. */
+ int fs_8bit_only; /* True if fs only supports 8 bit chars. */
const char *fs_mount_options; /* Mount options, if required. */
const char *fs_feature; /* Feature test, if required. */
@@ -46,19 +46,19 @@ struct filesystem {
* in libguestfs). The filesystems should be able to pass these
* tests if they are working correctly.
*/
- int fs_skip_latin1; /* Skip latin1 test. */
- int fs_skip_latin2; /* Skip latin2 test. */
+ int fs_skip_latin1; /* Skip latin1 test. */
+ int fs_skip_latin2; /* Skip latin2 test. */
};
static struct filesystem filesystems[] = {
- { "ext2", 0, 0, NULL, NULL, 0, 0 },
- { "ext3", 0, 0, NULL, NULL, 0, 0 },
- { "ext4", 0, 0, NULL, NULL, 0, 0 },
+ { "ext2", 0, 0, NULL, NULL, 0, 0 },
+ { "ext3", 0, 0, NULL, NULL, 0, 0 },
+ { "ext4", 0, 0, NULL, NULL, 0, 0 },
{ "btrfs", 0, 0, NULL, "btrfs", 0, 0 },
- { "vfat", 1, 0, "iocharset=iso8859-1,utf8", NULL, 1, 1 },
+ { "vfat", 1, 0, "iocharset=iso8859-1,utf8", NULL, 1, 1 },
{ "msdos", 1, 1, "iocharset=iso8859-1", NULL, 0, 0 },
/* In reality NTFS is case insensitive, but the ntfs-3g driver isn't. */
- { "ntfs", 0, 0, NULL, "ntfs3g", 0, 0 },
+ { "ntfs", 0, 0, NULL, "ntfs3g", 0, 0 },
};
static void test_filesystem (guestfs_h *g, const struct filesystem *fs);
@@ -91,7 +91,7 @@ main (int argc, char *argv[])
if (g == NULL)
error (EXIT_FAILURE, 0, "failed to create handle");
- if (guestfs_add_drive_scratch (g, 1024*1024*1024, -1) == -1)
+ if (guestfs_add_drive_scratch (g, 1024 * 1024 * 1024, -1) == -1)
exit (EXIT_FAILURE);
if (guestfs_launch (g) == -1)
@@ -118,7 +118,7 @@ test_filesystem (guestfs_h *g, const struct filesystem *fs)
char envvar[sizeof (ourenvvar) + 20];
char *str;
- if (fs->fs_feature && !guestfs_feature_available (g, (char **) feature)) {
+ if (fs->fs_feature && !guestfs_feature_available (g, (char **)feature)) {
printf ("skipped test of %s because %s feature not available\n",
fs->fs_name, fs->fs_feature);
return;
@@ -148,7 +148,7 @@ test_filesystem (guestfs_h *g, const struct filesystem *fs)
test_latin2 (g, fs);
test_chinese (g, fs);
- out:
+out:
unmount_filesystem (g, fs);
}
@@ -164,7 +164,7 @@ mount_filesystem (guestfs_h *g, const struct filesystem *fs)
{
const char *mount_options;
- mount_options = fs->fs_mount_options ? : "";
+ mount_options = fs->fs_mount_options ?: "";
if (guestfs_mount_options (g, mount_options, "/dev/sda1", "/") ==
-1)
exit (EXIT_FAILURE);
}
@@ -199,26 +199,26 @@ test_ascii (guestfs_h *g, const struct filesystem *fs)
if (fs->fs_case_insensitive) { /* case insensitive */
if (count != 2)
- error (EXIT_FAILURE, 0,
- "error: %s: %s is supposed to be case-insensitive, but %zu files
"
- "(instead of 2) were returned",
- __func__, fs->fs_name, count);
+ error (
+ EXIT_FAILURE, 0,
+ "error: %s: %s is supposed to be case-insensitive, but %zu files "
+ "(instead of 2) were returned",
+ __func__, fs->fs_name, count);
- if (STRCASENEQ (files[0], "abc") ||
- STRCASENEQ (files[1], "def"))
+ if (STRCASENEQ (files[0], "abc") || STRCASENEQ (files[1],
"def"))
error (EXIT_FAILURE, 0,
"error: %s: %s returned unexpected filenames '%s' and
'%s'",
__func__, fs->fs_name, files[0], files[1]);
}
- else { /* case sensitive */
+ else { /* case sensitive */
if (count != 3)
- error (EXIT_FAILURE, 0,
- "error: %s: %s is supposed to be case-sensitive, but %zu files "
- "(instead of 3) were returned",
- __func__, fs->fs_name, count);
+ error (
+ EXIT_FAILURE, 0,
+ "error: %s: %s is supposed to be case-sensitive, but %zu files "
+ "(instead of 3) were returned",
+ __func__, fs->fs_name, count);
- if (STRNEQ (files[0], "ABC") ||
- STRNEQ (files[1], "abc") ||
+ if (STRNEQ (files[0], "ABC") || STRNEQ (files[1], "abc") ||
STRNEQ (files[2], "def"))
error (EXIT_FAILURE, 0,
"error: %s: %s returned unexpected filenames '%s',
'%s', '%s'",
@@ -264,23 +264,25 @@ test_latin1 (guestfs_h *g, const struct filesystem *fs)
if (fs->fs_case_insensitive) { /* case insensitive */
if (count != 1)
- error (EXIT_FAILURE, 0,
- "error: %s: %s is supposed to be case-insensitive, but %zu files
"
- "(instead of 1) were returned",
- __func__, fs->fs_name, count);
+ error (
+ EXIT_FAILURE, 0,
+ "error: %s: %s is supposed to be case-insensitive, but %zu files "
+ "(instead of 1) were returned",
+ __func__, fs->fs_name, count);
if (memcmp (files[0], o_tilde, 3) != 0 &&
memcmp (files[0], O_tilde, 3) != 0)
error (EXIT_FAILURE, 0,
- "error: %s: %s returned unexpected filename '%s'",
- __func__, fs->fs_name, files[0]);
+ "error: %s: %s returned unexpected filename '%s'",
__func__,
+ fs->fs_name, files[0]);
}
- else { /* case sensitive */
+ else { /* case sensitive */
if (count != 2)
- error (EXIT_FAILURE, 0,
- "error: %s: %s is supposed to be case-sensitive, but %zu files "
- "(instead of 2) were returned",
- __func__, fs->fs_name, count);
+ error (
+ EXIT_FAILURE, 0,
+ "error: %s: %s is supposed to be case-sensitive, but %zu files "
+ "(instead of 2) were returned",
+ __func__, fs->fs_name, count);
if (memcmp (files[0], O_tilde, 3) != 0 ||
memcmp (files[1], o_tilde, 3) != 0)
@@ -326,23 +328,25 @@ test_latin2 (guestfs_h *g, const struct filesystem *fs)
if (fs->fs_case_insensitive) { /* case insensitive */
if (count != 1)
- error (EXIT_FAILURE, 0,
- "error: %s: %s is supposed to be case-insensitive, but %zu files
"
- "(instead of 1) were returned",
- __func__, fs->fs_name, count);
+ error (
+ EXIT_FAILURE, 0,
+ "error: %s: %s is supposed to be case-insensitive, but %zu files "
+ "(instead of 1) were returned",
+ __func__, fs->fs_name, count);
if (memcmp (files[0], o_dacute, 3) != 0 &&
memcmp (files[0], O_dacute, 3) != 0)
error (EXIT_FAILURE, 0,
- "error: %s: %s returned unexpected filename '%s'",
- __func__, fs->fs_name, files[0]);
+ "error: %s: %s returned unexpected filename '%s'",
__func__,
+ fs->fs_name, files[0]);
}
- else { /* case sensitive */
+ else { /* case sensitive */
if (count != 2)
- error (EXIT_FAILURE, 0,
- "error: %s: %s is supposed to be case-sensitive, but %zu files "
- "(instead of 2) were returned",
- __func__, fs->fs_name, count);
+ error (
+ EXIT_FAILURE, 0,
+ "error: %s: %s is supposed to be case-sensitive, but %zu files "
+ "(instead of 2) were returned",
+ __func__, fs->fs_name, count);
if (memcmp (files[0], O_dacute, 3) != 0 ||
memcmp (files[1], o_dacute, 3) != 0)
@@ -365,12 +369,9 @@ test_chinese (guestfs_h *g, const struct filesystem *fs)
*
https://secure.wikimedia.org/wikipedia/en/wiki/Chinese_characters#Compari...
*/
char filenames[][5] = {
- { '/', 0xe7, 0x94, 0xb5, 0 },
- { '/', 0xe4, 0xb9, 0xb0, 0 },
- { '/', 0xe5, 0xbc, 0x80, 0 },
- { '/', 0xe4, 0xb8, 0x9c, 0 },
- { '/', 0xe8, 0xbd, 0xa6, 0 },
- { '/', 0xe7, 0xba, 0xa2, 0 },
+ { '/', 0xe7, 0x94, 0xb5, 0 }, { '/', 0xe4, 0xb9, 0xb0, 0 },
+ { '/', 0xe5, 0xbc, 0x80, 0 }, { '/', 0xe4, 0xb8, 0x9c, 0 },
+ { '/', 0xe8, 0xbd, 0xa6, 0 }, { '/', 0xe7, 0xba, 0xa2, 0 },
};
const size_t nr_filenames = sizeof filenames / sizeof filenames[0];
size_t i, j;
@@ -400,8 +401,8 @@ test_chinese (guestfs_h *g, const struct filesystem *fs)
if (memcmp (files[j], &filenames[i][1], 4) == 0)
goto next;
error (EXIT_FAILURE, 0,
- "error: %s: %s returned unexpected filename '%s'",
- __func__, fs->fs_name, files[j]);
+ "error: %s: %s returned unexpected filename '%s'",
__func__,
+ fs->fs_name, files[j]);
next:;
}
diff --git a/tests/events/test-libvirt-auth-callbacks.c
b/tests/events/test-libvirt-auth-callbacks.c
index a18ab24..6c241e8 100644
--- a/tests/events/test-libvirt-auth-callbacks.c
+++ b/tests/events/test-libvirt-auth-callbacks.c
@@ -30,7 +30,7 @@
#include "guestfs.h"
#include "guestfs-internal-frontend.h"
-#define EXPECT_OK 1
+#define EXPECT_OK 1
#define EXPECT_FAIL -1
struct auth_data {
@@ -38,8 +38,12 @@ struct auth_data {
const char *password;
};
-static void do_test (const char *prog, const char *libvirt_uri, const struct auth_data
*auth_data, int expected);
-static void auth_callback (guestfs_h *g, void *opaque, uint64_t event, int event_handle,
int flags, const char *buf, size_t buf_len, const uint64_t *array, size_t array_len);
+static void do_test (const char *prog, const char *libvirt_uri,
+ const struct auth_data *auth_data, int expected);
+static void auth_callback (guestfs_h *g, void *opaque, uint64_t event,
+ int event_handle, int flags, const char *buf,
+ size_t buf_len, const uint64_t *array,
+ size_t array_len);
int
main (int argc, char *argv[])
@@ -61,29 +65,31 @@ main (int argc, char *argv[])
/* $srcdir must have been passed (by automake). */
srcdir = getenv ("srcdir");
if (!srcdir)
- error (EXIT_FAILURE, 0,
- "environment variable $srcdir is not defined.\n"
- "Normally it is defined by automake. If you are running the\n"
- "tests directly, set $srcdir to point to the source tests/events\n"
- "directory.");
+ error (
+ EXIT_FAILURE, 0,
+ "environment variable $srcdir is not defined.\n"
+ "Normally it is defined by automake. If you are running the\n"
+ "tests directly, set $srcdir to point to the source tests/events\n"
+ "directory.");
cwd = getcwd (NULL, 0);
if (cwd == NULL)
error (EXIT_FAILURE, errno, "getcwd");
- if (asprintf (&test_uri, "test://%s/%s/libvirt-auth.xml", cwd, srcdir) ==
-1)
+ if (asprintf (&test_uri, "test://%s/%s/libvirt-auth.xml", cwd, srcdir)
==
+ -1)
error (EXIT_FAILURE, errno, "asprintf");
free (cwd);
/* Perform the tests. */
- struct auth_data ad1 = { .username = "rich", .password = "123456"
};
+ struct auth_data ad1 = {.username = "rich", .password = "123456"
};
do_test (argv[0], test_uri, &ad1, EXPECT_OK);
- struct auth_data ad2 = { .username = "rich", .password = "654321"
};
+ struct auth_data ad2 = {.username = "rich", .password = "654321"
};
do_test (argv[0], test_uri, &ad2, EXPECT_FAIL);
- struct auth_data ad3 = { .username = "jane", .password = NULL };
+ struct auth_data ad3 = {.username = "jane", .password = NULL };
do_test (argv[0], test_uri, &ad3, EXPECT_OK);
- struct auth_data ad4 = { .username = "nouser", .password = "123456"
};
+ struct auth_data ad4 = {.username = "nouser", .password = "123456"
};
do_test (argv[0], test_uri, &ad4, EXPECT_FAIL);
free (test_uri);
@@ -92,46 +98,38 @@ main (int argc, char *argv[])
static void
do_test (const char *prog, const char *libvirt_uri,
- const struct auth_data *auth_data,
- int expected)
+ const struct auth_data *auth_data, int expected)
{
guestfs_h *g;
- const char *creds[] =
- { "authname", "passphrase", "noechoprompt", NULL };
+ const char *creds[] = { "authname", "passphrase",
"noechoprompt", NULL };
int r, eh;
g = guestfs_create ();
if (!g)
error (EXIT_FAILURE, errno, "guestfs_create");
- r = guestfs_set_libvirt_supported_credentials (g, (char **) creds);
+ r = guestfs_set_libvirt_supported_credentials (g, (char **)creds);
if (r == -1)
exit (EXIT_FAILURE);
- eh = guestfs_set_event_callback (g, auth_callback,
- GUESTFS_EVENT_LIBVIRT_AUTH, 0,
- (void *) auth_data);
+ eh = guestfs_set_event_callback (
+ g, auth_callback, GUESTFS_EVENT_LIBVIRT_AUTH, 0, (void *)auth_data);
if (eh == -1)
exit (EXIT_FAILURE);
- r = guestfs_add_domain (g, "test",
- GUESTFS_ADD_DOMAIN_LIBVIRTURI, libvirt_uri,
- GUESTFS_ADD_DOMAIN_READONLY, 1,
- -1);
+ r = guestfs_add_domain (g, "test", GUESTFS_ADD_DOMAIN_LIBVIRTURI,
+ libvirt_uri, GUESTFS_ADD_DOMAIN_READONLY, 1, -1);
if (r != expected)
- error (EXIT_FAILURE, 0,
- "test failed: u=%s p=%s: got %d expected %d",
- auth_data->username, auth_data->password ? : "(none)",
- r, expected);
+ error (EXIT_FAILURE, 0, "test failed: u=%s p=%s: got %d expected %d",
+ auth_data->username, auth_data->password ?: "(none)", r,
+ expected);
guestfs_close (g);
}
static void
-auth_callback (guestfs_h *g, void *opaque,
- uint64_t event, int event_handle,
- int flags,
- const char *buf, size_t buf_len,
+auth_callback (guestfs_h *g, void *opaque, uint64_t event, int event_handle,
+ int flags, const char *buf, size_t buf_len,
const uint64_t *array, size_t array_len)
{
CLEANUP_FREE_STRING_LIST char **creds = NULL;
@@ -155,21 +153,22 @@ auth_callback (guestfs_h *g, void *opaque,
else if (STREQ (creds[i], "passphrase") ||
STREQ (creds[i], "noechoprompt")) {
if (!auth_data->password)
- error (EXIT_FAILURE, 0,
- "test failed: libvirt asked for a password, but
auth_data->password == NULL");
+ error (EXIT_FAILURE, 0, "test failed: libvirt asked for a "
+ "password, but auth_data->password == "
+ "NULL");
reply = auth_data->password;
len = strlen (reply);
}
else {
- error (EXIT_FAILURE, 0,
- "test failed: libvirt asked for '%s' which is not in creds
list\n(This is probably a libvirt bug)",
+ error (EXIT_FAILURE, 0, "test failed: libvirt asked for '%s' which
"
+ "is not in creds list\n(This is probably a "
+ "libvirt bug)",
creds[i]);
abort (); /* keeps GCC happy since error(3) is not marked noreturn */
}
- r = guestfs_set_libvirt_requested_credential (g, i,
- reply, len);
+ r = guestfs_set_libvirt_requested_credential (g, i, reply, len);
if (r == -1)
exit (EXIT_FAILURE);
}
diff --git a/tests/mount-local/test-parallel-mount-local.c
b/tests/mount-local/test-parallel-mount-local.c
index 873d20a..00b88f2 100644
--- a/tests/mount-local/test-parallel-mount-local.c
+++ b/tests/mount-local/test-parallel-mount-local.c
@@ -43,14 +43,14 @@
#include "ignore-value.h"
-#define TOTAL_TIME 60 /* Seconds, excluding launch. */
-#define DEBUG 1 /* Print overview debugging messages. */
+#define TOTAL_TIME 60 /* Seconds, excluding launch. */
+#define DEBUG 1 /* Print overview debugging messages. */
#define MAX_THREADS 12
struct thread_state {
- pthread_t thread; /* Thread handle. */
- char *mp; /* Mount point. */
- int exit_status; /* Thread exit status. */
+ pthread_t thread; /* Thread handle. */
+ char *mp; /* Mount point. */
+ int exit_status; /* Thread exit status. */
};
static struct thread_state threads[MAX_THREADS];
static size_t nr_threads;
@@ -101,7 +101,8 @@ main (int argc, char *argv[])
}
if (access ("/dev/fuse", W_OK) == -1) {
- fprintf (stderr, "%s: test skipped because /dev/fuse is not writable.\n",
+ fprintf (stderr,
+ "%s: test skipped because /dev/fuse is not writable.\n",
guestfs_int_program_name);
exit (77);
}
@@ -134,8 +135,8 @@ main (int argc, char *argv[])
printf ("%-8s : starting thread\n", threads[i].mp);
fflush (stdout);
}
- r = pthread_create (&threads[i].thread, NULL, start_thread,
- &threads[i]);
+ r =
+ pthread_create (&threads[i].thread, NULL, start_thread, &threads[i]);
if (r != 0) {
cleanup_thread_state ();
error (EXIT_FAILURE, r, "pthread_create");
@@ -179,7 +180,7 @@ start_thread (void *statevp)
guestfs_set_identifier (g, state->mp);
- if (guestfs_add_drive_scratch (g, 512*1024*1024, -1) == -1)
+ if (guestfs_add_drive_scratch (g, 512 * 1024 * 1024, -1) == -1)
goto error;
if (guestfs_launch (g) == -1)
goto error;
@@ -217,10 +218,10 @@ start_thread (void *statevp)
goto error;
}
- if (pid == 0) { /* child */
- setpgid (0, 0); /* so we don't get ^C from parent */
- execlp ("./test-parallel-mount-local",
- "test-parallel-mount-local", "--test", state->mp,
NULL);
+ if (pid == 0) { /* child */
+ setpgid (0, 0); /* so we don't get ^C from parent */
+ execlp ("./test-parallel-mount-local",
"test-parallel-mount-local",
+ "--test", state->mp, NULL);
perror ("execlp");
goto error;
}
@@ -232,7 +233,7 @@ start_thread (void *statevp)
r = guestfs_mount_local_run (g);
guestfs_pop_error_handler (g);
- /* Wait for child process to exit and catch any errors from it. */
+ /* Wait for child process to exit and catch any errors from it. */
again:
if (waitpid (pid, &status, 0) == -1) {
if (errno == EINTR)
@@ -244,9 +245,8 @@ start_thread (void *statevp)
char status_string[80];
fprintf (stderr, "%s: %s\n", state->mp,
- guestfs_int_exit_status_to_string (status, "test",
- status_string,
- sizeof status_string));
+ guestfs_int_exit_status_to_string (
+ status, "test", status_string, sizeof status_string));
goto error;
}
@@ -267,7 +267,7 @@ start_thread (void *statevp)
state->exit_status = 0;
pthread_exit (&state->exit_status);
- error:
+error:
guestfs_close (g);
state->exit_status = 1;
pthread_exit (&state->exit_status);
@@ -283,7 +283,8 @@ test_mountpoint (const char *mp)
FILE *fp;
if (!mp || STREQ (mp, ""))
- error (EXIT_FAILURE, 0, "%s: invalid or empty mountpoint path", __func__);
+ error (EXIT_FAILURE, 0, "%s: invalid or empty mountpoint path",
+ __func__);
if (DEBUG) {
printf ("%-8s | testing filesystem\n", mp);
@@ -339,10 +340,11 @@ test_mountpoint (const char *mp)
}
ret = EXIT_SUCCESS;
- error:
+error:
ignore_value (chdir (".."));
if (guestunmount (mp, 0) == -1)
- error (EXIT_FAILURE, 0, "guestunmount %s: failed, see earlier errors",
mp);
+ error (EXIT_FAILURE, 0, "guestunmount %s: failed, see earlier errors",
+ mp);
if (DEBUG) {
printf ("%-8s > unmounted filesystem\n", mp);
@@ -364,8 +366,7 @@ guestunmount (const char *mp, unsigned flags)
return 0;
}
- snprintf (cmd, sizeof cmd,
- "../../fuse/guestunmount%s %s",
+ snprintf (cmd, sizeof cmd, "../../fuse/guestunmount%s %s",
(flags & GUESTUNMOUNT_SILENT) ? " --quiet" : "",
mp);
status = system (cmd);
@@ -393,7 +394,8 @@ cleanup_thread_state (void)
for (i = 0; i < nr_threads; ++i) {
if (threads[i].mp) {
- guestunmount (threads[i].mp, GUESTUNMOUNT_SILENT|GUESTUNMOUNT_RMDIR);
+ guestunmount (threads[i].mp,
+ GUESTUNMOUNT_SILENT | GUESTUNMOUNT_RMDIR);
free (threads[i].mp);
}
}
diff --git a/tests/mountable/test-internal-parse-mountable.c
b/tests/mountable/test-internal-parse-mountable.c
index ab86ccb..4c81196 100644
--- a/tests/mountable/test-internal-parse-mountable.c
+++ b/tests/mountable/test-internal-parse-mountable.c
@@ -49,15 +49,16 @@ main (int argc, char *argv[])
if (g == NULL)
error (EXIT_FAILURE, errno, "guestfs_create");
- if (guestfs_add_drive_scratch (g, 1024*1024*1024, -1) == -1) {
+ if (guestfs_add_drive_scratch (g, 1024 * 1024 * 1024, -1) == -1) {
error:
guestfs_close (g);
exit (EXIT_FAILURE);
}
- if (guestfs_launch (g) == -1) goto error;
+ if (guestfs_launch (g) == -1)
+ goto error;
- if (!guestfs_feature_available (g, (char **) feature)) {
+ if (!guestfs_feature_available (g, (char **)feature)) {
printf ("skipping test because btrfs is not available\n");
guestfs_close (g);
exit (77);
@@ -69,23 +70,31 @@ main (int argc, char *argv[])
exit (77);
}
- if (guestfs_part_disk (g, "/dev/sda", "mbr") == -1) goto error;
+ if (guestfs_part_disk (g, "/dev/sda", "mbr") == -1)
+ goto error;
- if (guestfs_pvcreate (g, "/dev/sda1") == -1) goto error;
+ if (guestfs_pvcreate (g, "/dev/sda1") == -1)
+ goto error;
const char *pvs[] = { "/dev/sda1", NULL };
- if (guestfs_vgcreate (g, "VG", (char **) pvs) == -1) goto error;
+ if (guestfs_vgcreate (g, "VG", (char **)pvs) == -1)
+ goto error;
- if (guestfs_lvcreate (g, "LV", "VG", 900) == -1) goto error;
+ if (guestfs_lvcreate (g, "LV", "VG", 900) == -1)
+ goto error;
- if (guestfs_mkfs_btrfs (g, (char * const *)devices, -1) == -1) goto error;
+ if (guestfs_mkfs_btrfs (g, (char *const *)devices, -1) == -1)
+ goto error;
- if (guestfs_mount (g, "/dev/VG/LV", "/") == -1) goto error;
+ if (guestfs_mount (g, "/dev/VG/LV", "/") == -1)
+ goto error;
- if (guestfs_btrfs_subvolume_create (g, "/sv") == -1) goto error;
+ if (guestfs_btrfs_subvolume_create (g, "/sv") == -1)
+ goto error;
mountable = guestfs_internal_parse_mountable (g, "/dev/VG/LV");
- if (mountable == NULL) goto error;
+ if (mountable == NULL)
+ goto error;
if (mountable->im_type != MOUNTABLE_DEVICE ||
STRNEQ ("/dev/VG/LV", mountable->im_device)) {
@@ -96,16 +105,20 @@ main (int argc, char *argv[])
guestfs_free_internal_mountable (mountable);
- mountable = guestfs_internal_parse_mountable (g, "btrfsvol:/dev/VG/LV/sv");
- if (mountable == NULL) goto error;
+ mountable =
+ guestfs_internal_parse_mountable (g, "btrfsvol:/dev/VG/LV/sv");
+ if (mountable == NULL)
+ goto error;
if (mountable->im_type != MOUNTABLE_BTRFSVOL ||
STRNEQ ("/dev/VG/LV", mountable->im_device) ||
STRNEQ ("sv", mountable->im_volume)) {
- fprintf (stderr, "incorrectly parsed /dev/VG/LV/sv: im_device=%s,
im_volume=%s\n",
- mountable->im_device, mountable->im_volume);
+ fprintf (
+ stderr,
+ "incorrectly parsed /dev/VG/LV/sv: im_device=%s, im_volume=%s\n",
+ mountable->im_device, mountable->im_volume);
goto error;
- }
+ }
guestfs_free_internal_mountable (mountable);
guestfs_close (g);
diff --git a/tests/parallel/test-parallel.c b/tests/parallel/test-parallel.c
index 85182f2..a9dd31a 100644
--- a/tests/parallel/test-parallel.c
+++ b/tests/parallel/test-parallel.c
@@ -39,13 +39,13 @@
#include "ignore-value.h"
-#define TOTAL_TIME 600 /* Seconds, excluding launch. */
+#define TOTAL_TIME 600 /* Seconds, excluding launch. */
#define NR_THREADS 5
struct thread_state {
- size_t thread_num; /* Thread number. */
- pthread_t thread; /* Thread handle. */
- int exit_status; /* Thread exit status. */
+ size_t thread_num; /* Thread number. */
+ pthread_t thread; /* Thread handle. */
+ int exit_status; /* Thread exit status. */
};
static struct thread_state threads[NR_THREADS];
@@ -92,8 +92,8 @@ main (int argc, char *argv[])
for (i = 0; i < NR_THREADS; ++i) {
threads[i].thread_num = i;
/* Start the thread. */
- r = pthread_create (&threads[i].thread, NULL, start_thread,
- &threads[i]);
+ r =
+ pthread_create (&threads[i].thread, NULL, start_thread, &threads[i]);
if (r != 0)
error (EXIT_FAILURE, r, "pthread_create");
}
@@ -139,10 +139,9 @@ start_thread (void *statevp)
snprintf (id, sizeof id, "%zu", state->thread_num);
guestfs_set_identifier (g, id);
- if (guestfs_add_drive_opts (g, "/dev/null",
- GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
- GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,
- -1) == -1) {
+ if (guestfs_add_drive_opts (
+ g, "/dev/null", GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
+ GUESTFS_ADD_DRIVE_OPTS_READONLY, 1, -1) == -1) {
error:
guestfs_close (g);
state->exit_status = 1;
diff --git a/tests/protocol/test-error-messages.c b/tests/protocol/test-error-messages.c
index 57a4a21..f26e1ae 100644
--- a/tests/protocol/test-error-messages.c
+++ b/tests/protocol/test-error-messages.c
@@ -37,11 +37,16 @@ main (int argc, char *argv[])
{
guestfs_h *g;
size_t i;
- int lengths[] = { 0, 1, 1024,
- GUESTFS_ERROR_LEN-2, GUESTFS_ERROR_LEN-1,
- GUESTFS_ERROR_LEN, GUESTFS_ERROR_LEN+1,
- GUESTFS_ERROR_LEN+2,
- GUESTFS_ERROR_LEN*2, -1 };
+ int lengths[] = { 0,
+ 1,
+ 1024,
+ GUESTFS_ERROR_LEN - 2,
+ GUESTFS_ERROR_LEN - 1,
+ GUESTFS_ERROR_LEN,
+ GUESTFS_ERROR_LEN + 1,
+ GUESTFS_ERROR_LEN + 2,
+ GUESTFS_ERROR_LEN * 2,
+ -1 };
char len_s[64];
char *args[2];
diff --git a/tests/qemu/boot-analysis-timeline.c b/tests/qemu/boot-analysis-timeline.c
index d35fb49..c18cdd0 100644
--- a/tests/qemu/boot-analysis-timeline.c
+++ b/tests/qemu/boot-analysis-timeline.c
@@ -37,10 +37,9 @@
#include "boot-analysis.h"
-COMPILE_REGEXP(re_initcall_calling_module,
- "calling ([_A-Za-z0-9]+)\\+.*\\[([_A-Za-z0-9]+)]", 0)
-COMPILE_REGEXP(re_initcall_calling,
- "calling ([_A-Za-z0-9]+)\\+", 0)
+COMPILE_REGEXP (re_initcall_calling_module,
+ "calling ([_A-Za-z0-9]+)\\+.*\\[([_A-Za-z0-9]+)]", 0)
+COMPILE_REGEXP (re_initcall_calling, "calling ([_A-Za-z0-9]+)\\+", 0)
static void construct_initcall_timeline (void);
@@ -71,123 +70,124 @@ construct_timeline (void)
for (i = 0; i < NR_TEST_PASSES; ++i) {
data = &pass_data[i];
- /* Find an activity, by matching an event with the condition
- * `begin_cond' through to the second event `end_cond'. Create an
- * activity object in the timeline from the result.
- */
-#define FIND(name, flags, begin_cond, end_cond) \
- do { \
- activity = NULL; \
- for (j = 0; j < data->nr_events; ++j) { \
- if (begin_cond) { \
- for (k = j+1; k < data->nr_events; ++k) { \
- if (end_cond) { \
- if (i == 0) \
- activity = add_activity (name, flags); \
- else \
- activity = find_activity (name); \
- break; \
- } \
- } \
- break; \
- } \
- } \
- if (activity) { \
- activity->start_event[i] = j; \
- activity->end_event[i] = k; \
- } \
- else \
- error (EXIT_FAILURE, 0, "could not find activity '%s' in pass
'%zu'", \
- name, i); \
- } while (0)
+/* Find an activity, by matching an event with the condition
+ * `begin_cond' through to the second event `end_cond'. Create an
+ * activity object in the timeline from the result.
+ */
+#define FIND(name, flags, begin_cond, end_cond) \
+ do { \
+ activity = NULL; \
+ for (j = 0; j < data->nr_events; ++j) { \
+ if (begin_cond) { \
+ for (k = j + 1; k < data->nr_events; ++k) { \
+ if (end_cond) { \
+ if (i == 0) \
+ activity = add_activity (name, flags); \
+ else \
+ activity = find_activity (name); \
+ break; \
+ } \
+ } \
+ break; \
+ } \
+ } \
+ if (activity) { \
+ activity->start_event[i] = j; \
+ activity->end_event[i] = k; \
+ } \
+ else \
+ error (EXIT_FAILURE, 0, \
+ "could not find activity '%s' in pass '%zu'",
name, i); \
+ } while (0)
- /* Same as FIND() macro, but if no matching events are found,
- * ignore it.
- */
-#define FIND_OPTIONAL(name, flags, begin_cond, end_cond) \
- do { \
- activity = NULL; \
- for (j = 0; j < data->nr_events; ++j) { \
- if (begin_cond) { \
- for (k = j+1; k < data->nr_events; ++k) { \
- if (end_cond) { \
- if (i == 0) \
- activity = add_activity (name, flags); \
- else \
- activity = find_activity (name); \
- break; \
- } \
- } \
- break; \
- } \
- } \
- if (activity) { \
- activity->start_event[i] = j; \
- activity->end_event[i] = k; \
- } \
- } while (0)
+/* Same as FIND() macro, but if no matching events are found,
+ * ignore it.
+ */
+#define FIND_OPTIONAL(name, flags, begin_cond, end_cond) \
+ do { \
+ activity = NULL; \
+ for (j = 0; j < data->nr_events; ++j) { \
+ if (begin_cond) { \
+ for (k = j + 1; k < data->nr_events; ++k) { \
+ if (end_cond) { \
+ if (i == 0) \
+ activity = add_activity (name, flags); \
+ else \
+ activity = find_activity (name); \
+ break; \
+ } \
+ } \
+ break; \
+ } \
+ } \
+ if (activity) { \
+ activity->start_event[i] = j; \
+ activity->end_event[i] = k; \
+ } \
+ } while (0)
- /* Find multiple entries, where we check for:
- * next_cond
- * next_cond
- * next_cond
- * end_cond
- */
-#define FIND_MULTIPLE(debug_name, flags, next_cond, end_cond, translate_message) \
- do { \
- activity = NULL; \
- for (j = 0; j < data->nr_events; ++j) { \
- if (next_cond) { \
- CLEANUP_FREE char *message = translate_message (data->events[j].message); \
- if (activity) \
- activity->end_event[i] = j; \
- if (i == 0) \
- activity = add_activity (message, flags); \
- else \
- activity = find_activity (message); \
- activity->start_event[i] = j; \
- } \
- else if (end_cond) \
- break; \
- } \
- if (j < data->nr_events && activity) \
- activity->end_event[i] = j; \
- else \
- error (EXIT_FAILURE, 0, "could not find activity '%s' in pass
'%zu'", \
- debug_name, i); \
- } while (0)
+/* Find multiple entries, where we check for:
+ * next_cond
+ * next_cond
+ * next_cond
+ * end_cond
+ */
+#define FIND_MULTIPLE(debug_name, flags, next_cond, end_cond, \
+ translate_message) \
+ do { \
+ activity = NULL; \
+ for (j = 0; j < data->nr_events; ++j) { \
+ if (next_cond) { \
+ CLEANUP_FREE char *message = \
+ translate_message (data->events[j].message); \
+ if (activity) \
+ activity->end_event[i] = j; \
+ if (i == 0) \
+ activity = add_activity (message, flags); \
+ else \
+ activity = find_activity (message); \
+ activity->start_event[i] = j; \
+ } \
+ else if (end_cond) \
+ break; \
+ } \
+ if (j < data->nr_events && activity)
\
+ activity->end_event[i] = j; \
+ else \
+ error (EXIT_FAILURE, 0, \
+ "could not find activity '%s' in pass '%zu'",
debug_name, i); \
+ } while (0)
/* Add one activity which is going to cover the whole process
* from launch to close. The launch event is always event 0.
* NB: This activity must be called "run" (see below).
*/
- FIND ("run", LONG_ACTIVITY,
- j == 0, data->events[k].source == GUESTFS_EVENT_CLOSE);
+ FIND ("run", LONG_ACTIVITY, j == 0,
+ data->events[k].source == GUESTFS_EVENT_CLOSE);
/* Find where we invoke supermin --build. This should be a null
* operation, but it still takes time to run the external command.
*/
FIND ("supermin:build", 0,
data->events[j].source == GUESTFS_EVENT_LIBRARY &&
- strstr (data->events[j].message,
- "begin building supermin appliance"),
+ strstr (data->events[j].message,
+ "begin building supermin appliance"),
data->events[k].source == GUESTFS_EVENT_LIBRARY &&
- strstr (data->events[k].message,
- "finished building supermin appliance"));
+ strstr (data->events[k].message,
+ "finished building supermin appliance"));
/* Find where we invoke qemu to test features. */
- FIND_OPTIONAL ("qemu:feature-detect", 0,
- data->events[j].source == GUESTFS_EVENT_LIBRARY &&
- strstr (data->events[j].message,
- "begin testing qemu features"),
- data->events[k].source == GUESTFS_EVENT_LIBRARY &&
- strstr (data->events[k].message,
- "finished testing qemu features"));
+ FIND_OPTIONAL (
+ "qemu:feature-detect", 0,
+ data->events[j].source == GUESTFS_EVENT_LIBRARY &&
+ strstr (data->events[j].message, "begin testing qemu features"),
+ data->events[k].source == GUESTFS_EVENT_LIBRARY &&
+ strstr (data->events[k].message, "finished testing qemu
features"));
/* Find where we run qemu. */
FIND_OPTIONAL ("qemu", LONG_ACTIVITY,
data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[j].message, "-nodefconfig"),
+ strstr (data->events[j].message, "-nodefconfig"),
data->events[k].source == GUESTFS_EVENT_CLOSE);
/* For the libvirt backend, connecting to libvirt, getting
@@ -195,207 +195,212 @@ construct_timeline (void)
*/
FIND_OPTIONAL ("libvirt:connect", 0,
data->events[j].source == GUESTFS_EVENT_LIBRARY &&
- strstr (data->events[j].message, "connect to libvirt"),
+ strstr (data->events[j].message, "connect to
libvirt"),
data->events[k].source == GUESTFS_EVENT_LIBRARY &&
- strstr (data->events[k].message, "successfully opened libvirt
handle"));
- FIND_OPTIONAL ("libvirt:get-libvirt-capabilities", 0,
- data->events[j].source == GUESTFS_EVENT_LIBRARY &&
- strstr (data->events[j].message, "get libvirt
capabilities"),
- data->events[k].source == GUESTFS_EVENT_LIBRARY &&
- strstr (data->events[k].message, "parsing capabilities
XML"));
+ strstr (data->events[k].message,
+ "successfully opened libvirt handle"));
+ FIND_OPTIONAL (
+ "libvirt:get-libvirt-capabilities", 0,
+ data->events[j].source == GUESTFS_EVENT_LIBRARY &&
+ strstr (data->events[j].message, "get libvirt capabilities"),
+ data->events[k].source == GUESTFS_EVENT_LIBRARY &&
+ strstr (data->events[k].message, "parsing capabilities XML"));
- FIND_OPTIONAL ("libguestfs:parse-libvirt-capabilities", 0,
- data->events[j].source == GUESTFS_EVENT_LIBRARY &&
- strstr (data->events[j].message, "parsing capabilities
XML"),
- data->events[k].source == GUESTFS_EVENT_LIBRARY &&
- strstr (data->events[k].message,
"get_backend_setting"));
+ FIND_OPTIONAL (
+ "libguestfs:parse-libvirt-capabilities", 0,
+ data->events[j].source == GUESTFS_EVENT_LIBRARY &&
+ strstr (data->events[j].message, "parsing capabilities XML"),
+ data->events[k].source == GUESTFS_EVENT_LIBRARY &&
+ strstr (data->events[k].message, "get_backend_setting"));
FIND_OPTIONAL ("libguestfs:create-libvirt-xml", 0,
data->events[j].source == GUESTFS_EVENT_LIBRARY &&
- strstr (data->events[j].message, "create libvirt XML"),
+ strstr (data->events[j].message, "create libvirt
XML"),
data->events[k].source == GUESTFS_EVENT_LIBRARY &&
- strstr (data->events[k].message, "libvirt XML:"));
+ strstr (data->events[k].message, "libvirt XML:"));
#define SGABIOS_STRING "\033[1;256r\033[256;256H\033[6n"
/* For the libvirt backend, find the overhead of libvirt. */
- FIND_OPTIONAL ("libvirt:overhead", 0,
- data->events[j].source == GUESTFS_EVENT_LIBRARY &&
- strstr (data->events[j].message, "launch libvirt
guest"),
- data->events[k].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[k].message, SGABIOS_STRING));
+ FIND_OPTIONAL (
+ "libvirt:overhead", 0,
+ data->events[j].source == GUESTFS_EVENT_LIBRARY &&
+ strstr (data->events[j].message, "launch libvirt guest"),
+ data->events[k].source == GUESTFS_EVENT_APPLIANCE &&
+ strstr (data->events[k].message, SGABIOS_STRING));
/* From starting qemu up to entering the BIOS is the qemu overhead. */
FIND_OPTIONAL ("qemu:overhead", 0,
data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[j].message, "-nodefconfig"),
+ strstr (data->events[j].message, "-nodefconfig"),
data->events[k].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[k].message, SGABIOS_STRING));
+ strstr (data->events[k].message, SGABIOS_STRING));
- /* From entering the BIOS to starting the kernel is the BIOS overhead. */
+ /* From entering the BIOS to starting the kernel is the BIOS overhead.
+ */
FIND_OPTIONAL ("bios:overhead", 0,
- data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[j].message, SGABIOS_STRING),
- data->events[k].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[k].message, "Probing EDD"));
+ data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
+ strstr (data->events[j].message, SGABIOS_STRING),
+ data->events[k].source == GUESTFS_EVENT_APPLIANCE &&
+ strstr (data->events[k].message, "Probing EDD"));
/* SGABIOS (option ROM). */
FIND_OPTIONAL ("sgabios", 0,
- data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[j].message, SGABIOS_STRING),
- data->events[k].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[k].message, "SeaBIOS (version"));
+ data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
+ strstr (data->events[j].message, SGABIOS_STRING),
+ data->events[k].source == GUESTFS_EVENT_APPLIANCE &&
+ strstr (data->events[k].message, "SeaBIOS (version"));
/* SeaBIOS. */
FIND ("seabios", 0,
data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[j].message, "SeaBIOS (version"),
+ strstr (data->events[j].message, "SeaBIOS (version"),
data->events[k].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[k].message, "Probing EDD"));
+ strstr (data->events[k].message, "Probing EDD"));
/* SeaBIOS - only available when using debug messages. */
- FIND_OPTIONAL ("seabios:pci-probe", 0,
- data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[j].message, "Searching bootorder for:
/pci@"),
- data->events[k].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[k].message, "Scan for option roms"));
+ FIND_OPTIONAL (
+ "seabios:pci-probe", 0,
+ data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
+ strstr (data->events[j].message, "Searching bootorder for: /pci@"),
+ data->events[k].source == GUESTFS_EVENT_APPLIANCE &&
+ strstr (data->events[k].message, "Scan for option roms"));
/* Find where we run the guest kernel. */
FIND ("kernel", LONG_ACTIVITY,
data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[j].message, "Probing EDD"),
+ strstr (data->events[j].message, "Probing EDD"),
data->events[k].source == GUESTFS_EVENT_CLOSE);
/* Kernel startup to userspace. */
FIND ("kernel:overhead", 0,
data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[j].message, "Probing EDD"),
+ strstr (data->events[j].message, "Probing EDD"),
data->events[k].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[k].message, "supermin:") &&
- strstr (data->events[k].message, "starting up"));
+ strstr (data->events[k].message, "supermin:") &&
+ strstr (data->events[k].message, "starting up"));
/* The time taken to get into start_kernel function. */
FIND ("kernel:entry", 0,
data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[j].message, "Probing EDD"),
+ strstr (data->events[j].message, "Probing EDD"),
data->events[k].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[k].message, "Linux version"));
+ strstr (data->events[k].message, "Linux version"));
/* Alternatives patching instructions (XXX not very accurate we
* really need some debug messages inserted into the code).
*/
FIND ("kernel:alternatives", 0,
data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[j].message, "Last level dTLB entries"),
+ strstr (data->events[j].message, "Last level dTLB entries"),
data->events[k].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[k].message, "Freeing SMP alternatives"));
+ strstr (data->events[k].message, "Freeing SMP alternatives"));
/* ftrace patching instructions. */
FIND ("kernel:ftrace", 0,
data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[j].message, "ftrace: allocating"),
+ strstr (data->events[j].message, "ftrace: allocating"),
1);
/* Find where we run supermin mini-initrd. */
FIND ("supermin:mini-initrd", 0,
data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[j].message, "supermin:") &&
- strstr (data->events[j].message, "starting up"),
+ strstr (data->events[j].message, "supermin:") &&
+ strstr (data->events[j].message, "starting up"),
data->events[k].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[k].message, "supermin: chroot"));
+ strstr (data->events[k].message, "supermin: chroot"));
/* Loading kernel modules from supermin initrd. */
- FIND_MULTIPLE
- ("supermin insmod", 0,
- data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[j].message, "supermin: internal insmod"),
- data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[j].message, "supermin: picked"),
- translate_supermin_insmod_message);
+ FIND_MULTIPLE (
+ "supermin insmod", 0,
+ data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
+ strstr (data->events[j].message, "supermin: internal insmod"),
+ data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
+ strstr (data->events[j].message, "supermin: picked"),
+ translate_supermin_insmod_message);
/* Find where we run the /init script. */
FIND ("/init", 0,
data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[j].message, "supermin: chroot"),
+ strstr (data->events[j].message, "supermin: chroot"),
data->events[k].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[k].message, "guestfsd --verbose"));
+ strstr (data->events[k].message, "guestfsd --verbose"));
/* Everything from the chroot to the first echo in the /init
* script counts as bash overhead.
*/
FIND ("bash:overhead", 0,
data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[j].message, "supermin: chroot"),
+ strstr (data->events[j].message, "supermin: chroot"),
data->events[k].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[k].message, "Starting /init script"));
+ strstr (data->events[k].message, "Starting /init script"));
/* /init: Mount special filesystems. */
FIND ("/init:mount-special", 0,
data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[j].message, "*guestfs_boot_analysis=1*"),
+ strstr (data->events[j].message, "*guestfs_boot_analysis=1*"),
data->events[k].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[k].message, "kmod static-nodes"));
+ strstr (data->events[k].message, "kmod static-nodes"));
/* /init: Run kmod static-nodes */
FIND ("/init:kmod-static-nodes", 0,
data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[j].message, "kmod static-nodes"),
+ strstr (data->events[j].message, "kmod static-nodes"),
data->events[k].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[k].message, "systemd-tmpfiles"));
+ strstr (data->events[k].message, "systemd-tmpfiles"));
/* /init: systemd-tmpfiles. */
FIND ("/init:systemd-tmpfiles", 0,
data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[j].message, "systemd-tmpfiles"),
+ strstr (data->events[j].message, "systemd-tmpfiles"),
data->events[k].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[k].message, "udev"));
+ strstr (data->events[k].message, "udev"));
/* /init: start udevd. */
FIND ("/init:udev-overhead", 0,
data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[j].message, "udevd --daemon"),
+ strstr (data->events[j].message, "udevd --daemon"),
data->events[k].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[k].message, "nullglob"));
+ strstr (data->events[k].message, "nullglob"));
/* /init: set up network. */
FIND ("/init:network-overhead", 0,
data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[j].message, "+ ip addr"),
+ strstr (data->events[j].message, "+ ip addr"),
data->events[k].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[k].message, "+ test"));
+ strstr (data->events[k].message, "+ test"));
/* /init: probe MD arrays. */
FIND ("/init:md-probe", 0,
data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[j].message, "+ mdadm"),
+ strstr (data->events[j].message, "+ mdadm"),
data->events[k].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[k].message, "+ modprobe dm_mod"));
+ strstr (data->events[k].message, "+ modprobe dm_mod"));
/* /init: probe DM/LVM. */
FIND ("/init:lvm-probe", 0,
data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[j].message, "+ modprobe dm_mod"),
+ strstr (data->events[j].message, "+ modprobe dm_mod"),
data->events[k].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[k].message, "+ ldmtool"));
+ strstr (data->events[k].message, "+ ldmtool"));
/* /init: probe Windows dynamic disks. */
FIND ("/init:windows-dynamic-disks-probe", 0,
data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[j].message, "+ ldmtool"),
+ strstr (data->events[j].message, "+ ldmtool"),
data->events[k].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[k].message, "+ test"));
+ strstr (data->events[k].message, "+ test"));
/* Find where we run guestfsd. */
FIND ("guestfsd", 0,
data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[j].message, "guestfsd --verbose"),
+ strstr (data->events[j].message, "guestfsd --verbose"),
data->events[k].source == GUESTFS_EVENT_APPLIANCE &&
- strstr (data->events[k].message, "fsync /dev/sda"));
+ strstr (data->events[k].message, "fsync /dev/sda"));
/* Shutdown process. */
- FIND ("shutdown", 0,
- data->events[j].source == GUESTFS_EVENT_TRACE &&
- STREQ (data->events[j].message, "close"),
+ FIND ("shutdown", 0, data->events[j].source == GUESTFS_EVENT_TRACE
&&
+ STREQ (data->events[j].message, "close"),
data->events[k].source == GUESTFS_EVENT_CLOSE);
}
@@ -423,7 +428,8 @@ construct_initcall_timeline (void)
* For initcall functions in modules:
*
* calling virtio_mmio_init+0x0/0x1000 [virtio_mmio] @ 1"
- * initcall virtio_mmio_init+0x0/0x1000 [virtio_mmio] returned 0 after 14
usecs"
+ * initcall virtio_mmio_init+0x0/0x1000 [virtio_mmio] returned 0 after
+ * 14 usecs"
*
* Initcall functions can be nested, and do not have unique names.
*/
@@ -432,18 +438,18 @@ construct_initcall_timeline (void)
const char *message = data->events[j].message;
if (data->events[j].source == GUESTFS_EVENT_APPLIANCE &&
- ((r = pcre_exec (re_initcall_calling_module, NULL,
- message, strlen (message),
- 0, 0, vec, sizeof vec / sizeof vec[0])) >= 1 ||
- (r = pcre_exec (re_initcall_calling, NULL,
- message, strlen (message),
- 0, 0, vec, sizeof vec / sizeof vec[0])) >= 1)) {
+ ((r = pcre_exec (re_initcall_calling_module, NULL, message,
+ strlen (message), 0, 0, vec,
+ sizeof vec / sizeof vec[0])) >= 1 ||
+ (r = pcre_exec (re_initcall_calling, NULL, message,
+ strlen (message), 0, 0, vec,
+ sizeof vec / sizeof vec[0])) >= 1)) {
CLEANUP_FREE char *fn_name = NULL, *module_name = NULL;
if (r >= 2) /* because pcre_exec returns 1 + number of captures */
- fn_name = strndup (message + vec[2], vec[3]-vec[2]);
+ fn_name = strndup (message + vec[2], vec[3] - vec[2]);
if (r >= 3)
- module_name = strndup (message + vec[4], vec[5]-vec[4]);
+ module_name = strndup (message + vec[4], vec[5] - vec[4]);
CLEANUP_FREE char *fullname;
if (asprintf (&fullname, "%s.%s",
@@ -465,7 +471,8 @@ construct_initcall_timeline (void)
int n = 1;
while (activity_exists (activity_name)) {
free (activity_name);
- if (asprintf (&activity_name, "initcall %s:%d", fullname, n) ==
-1)
+ if (asprintf (&activity_name, "initcall %s:%d", fullname, n)
==
+ -1)
error (EXIT_FAILURE, errno, "asprintf");
n++;
}
@@ -474,7 +481,8 @@ construct_initcall_timeline (void)
int n = 1;
while (!activity_exists_with_no_data (activity_name, i)) {
free (activity_name);
- if (asprintf (&activity_name, "initcall %s:%d", fullname, n) ==
-1)
+ if (asprintf (&activity_name, "initcall %s:%d", fullname, n)
==
+ -1)
error (EXIT_FAILURE, errno, "asprintf");
n++;
}
@@ -483,7 +491,7 @@ construct_initcall_timeline (void)
/* Find the matching end event. It might be some time later,
* since it appears initcalls can be nested.
*/
- for (k = j+1; k < data->nr_events; ++k) {
+ for (k = j + 1; k < data->nr_events; ++k) {
if (data->events[k].source == GUESTFS_EVENT_APPLIANCE &&
strstr (data->events[k].message, initcall_match)) {
if (i == 0)
diff --git a/tests/qemu/boot-analysis-utils.c b/tests/qemu/boot-analysis-utils.c
index bcd470e..c0ba05f 100644
--- a/tests/qemu/boot-analysis-utils.c
+++ b/tests/qemu/boot-analysis-utils.c
@@ -43,7 +43,7 @@ timespec_diff (const struct timespec *x, const struct timespec *y)
{
int64_t nsec;
- nsec = (y->tv_sec - x->tv_sec) * UINT64_C(1000000000);
+ nsec = (y->tv_sec - x->tv_sec) * UINT64_C (1000000000);
nsec += y->tv_nsec - x->tv_nsec;
return nsec;
}
@@ -64,7 +64,8 @@ test_info (guestfs_h *g, int nr_test_passes)
ignore_value (system ("uname -a"));
printf (" host CPU: ");
fflush (stdout);
- ignore_value (system ("perl -n -e 'if (/^model name.*: (.*)/) { print
\"$1\\n\"; exit }' /proc/cpuinfo"));
+ ignore_value (system ("perl -n -e 'if (/^model name.*: (.*)/) { print "
+ "\"$1\\n\"; exit }' /proc/cpuinfo"));
/* Related to qemu. */
printf (" backend: %s\n", guestfs_get_backend (g));
@@ -80,5 +81,5 @@ test_info (guestfs_h *g, int nr_test_passes)
/* Related to the guest kernel. Be nice to get the guest
* kernel version here somehow (XXX).
*/
- printf (" append: %s\n", guestfs_get_append (g) ? : "");
+ printf (" append: %s\n", guestfs_get_append (g) ?: "");
}
diff --git a/tests/qemu/boot-analysis-utils.h b/tests/qemu/boot-analysis-utils.h
index 95e4f06..755bb72 100644
--- a/tests/qemu/boot-analysis-utils.h
+++ b/tests/qemu/boot-analysis-utils.h
@@ -25,7 +25,8 @@
extern void get_time (struct timespec *ts);
/* Computes Y - X, returning nanoseconds. */
-extern int64_t timespec_diff (const struct timespec *x, const struct timespec *y);
+extern int64_t timespec_diff (const struct timespec *x,
+ const struct timespec *y);
/* Display host machine and test parameters (to stdout). 'g' should
* be an open libguestfs handle. It is used for reading hv, memsize
diff --git a/tests/qemu/boot-analysis.c b/tests/qemu/boot-analysis.c
index 37d8b3c..3c1fb67 100644
--- a/tests/qemu/boot-analysis.c
+++ b/tests/qemu/boot-analysis.c
@@ -147,23 +147,20 @@ main (int argc, char *argv[])
enum { HELP_OPTION = CHAR_MAX + 1 };
static const char *options = "m:v";
static const struct option long_options[] = {
- { "help", 0, 0, HELP_OPTION },
- { "append", 1, 0, 0 },
- { "color", 0, 0, 0 },
- { "colour", 0, 0, 0 },
- { "memsize", 1, 0, 'm' },
- { "smp", 1, 0, 0 },
- { "verbose", 0, 0, 'v' },
- { 0, 0, 0, 0 }
+ { "help", 0, 0, HELP_OPTION }, { "append", 1, 0, 0 },
+ { "color", 0, 0, 0 }, { "colour", 0, 0, 0 },
+ { "memsize", 1, 0, 'm' }, { "smp", 1, 0, 0 },
+ { "verbose", 0, 0, 'v' }, { 0, 0, 0, 0 }
};
int c, option_index;
for (;;) {
c = getopt_long (argc, argv, options, long_options, &option_index);
- if (c == -1) break;
+ if (c == -1)
+ break;
switch (c) {
- case 0: /* Options which are long only. */
+ case 0: /* Options which are long only. */
if (STREQ (long_options[option_index].name, "append")) {
append = optarg;
break;
@@ -182,7 +179,8 @@ main (int argc, char *argv[])
break;
}
fprintf (stderr, "%s: unknown long option: %s (%d)\n",
- guestfs_int_program_name, long_options[option_index].name, option_index);
+ guestfs_int_program_name, long_options[option_index].name,
+ option_index);
exit (EXIT_FAILURE);
case 'm':
@@ -206,7 +204,8 @@ main (int argc, char *argv[])
}
if (STRNEQ (host_cpu, "x86_64"))
- fprintf (stderr, "WARNING: host_cpu != x86_64: This program may not work or give
bogus results.\n");
+ fprintf (stderr, "WARNING: host_cpu != x86_64: This program may not "
+ "work or give bogus results.\n");
run_test ();
}
@@ -235,8 +234,8 @@ run_test (void)
exit (EXIT_FAILURE);
guestfs_close (g);
- printf (" pass %zu: %zu events collected in %" PRIi64 "
ns\n",
- i+1, pass_data[i].nr_events, pass_data[i].elapsed_ns);
+ printf (" pass %zu: %zu events collected in %" PRIi64 " ns\n",
i + 1,
+ pass_data[i].nr_events, pass_data[i].elapsed_ns);
}
if (verbose)
@@ -271,11 +270,11 @@ add_event (struct pass_data *data, uint64_t source)
struct event *ret;
data->nr_events++;
- data->events = realloc (data->events,
- sizeof (struct event) * data->nr_events);
+ data->events =
+ realloc (data->events, sizeof (struct event) * data->nr_events);
if (data->events == NULL)
error (EXIT_FAILURE, errno, "realloc");
- ret = &data->events[data->nr_events-1];
+ ret = &data->events[data->nr_events - 1];
get_time (&ret->t);
ret->source = source;
ret->message = NULL;
@@ -290,7 +289,8 @@ create_handle (void)
CLEANUP_FREE char *full_append = NULL;
g = guestfs_create ();
- if (!g) error (EXIT_FAILURE, errno, "guestfs_create");
+ if (!g)
+ error (EXIT_FAILURE, errno, "guestfs_create");
if (memsize != 0)
if (guestfs_set_memsize (g, memsize) == -1)
@@ -303,10 +303,9 @@ create_handle (void)
/* This changes some details in appliance/init and enables a
* detailed trace of calls to initcall functions in the kernel.
*/
- if (asprintf (&full_append,
- "guestfs_boot_analysis=1 "
- "ignore_loglevel initcall_debug "
- "%s",
+ if (asprintf (&full_append, "guestfs_boot_analysis=1 "
+ "ignore_loglevel initcall_debug "
+ "%s",
append != NULL ? append : "") == -1)
error (EXIT_FAILURE, errno, "asprintf");
@@ -320,9 +319,8 @@ create_handle (void)
static void
add_drive (guestfs_h *g)
{
- if (guestfs_add_drive_opts (g, "/dev/null",
- GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
- GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,
+ if (guestfs_add_drive_opts (g, "/dev/null", GUESTFS_ADD_DRIVE_OPTS_FORMAT,
+ "raw", GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,
-1) == -1)
exit (EXIT_FAILURE);
}
@@ -331,9 +329,8 @@ add_drive (guestfs_h *g)
* the pass_data here.
*/
static void
-close_callback (guestfs_h *g, void *datavp, uint64_t source,
- int eh, int flags,
- const char *buf, size_t buf_len,
+close_callback (guestfs_h *g, void *datavp, uint64_t source, int eh,
+ int flags, const char *buf, size_t buf_len,
const uint64_t *array, size_t array_len)
{
struct pass_data *data = datavp;
@@ -356,9 +353,9 @@ close_callback (guestfs_h *g, void *datavp, uint64_t source,
*/
static void
subprocess_quit_callback (guestfs_h *g, void *datavp, uint64_t source,
- int eh, int flags,
- const char *buf, size_t buf_len,
- const uint64_t *array, size_t array_len)
+ int eh, int flags, const char *buf,
+ size_t buf_len, const uint64_t *array,
+ size_t array_len)
{
struct pass_data *data = datavp;
struct event *event;
@@ -376,9 +373,8 @@ subprocess_quit_callback (guestfs_h *g, void *datavp, uint64_t
source,
* guestfs daemon and talking to each other).
*/
static void
-launch_done_callback (guestfs_h *g, void *datavp, uint64_t source,
- int eh, int flags,
- const char *buf, size_t buf_len,
+launch_done_callback (guestfs_h *g, void *datavp, uint64_t source, int eh,
+ int flags, const char *buf, size_t buf_len,
const uint64_t *array, size_t array_len)
{
struct pass_data *data = datavp;
@@ -399,8 +395,8 @@ trim_r (char *message)
{
size_t len = strlen (message);
- while (len > 0 && message[len-1] == '\r') {
- message[len-1] = '\0';
+ while (len > 0 && message[len - 1] == '\r') {
+ message[len - 1] = '\0';
len--;
}
}
@@ -410,9 +406,8 @@ trim_r (char *message)
* BIOS, kernel, etc).
*/
static void
-appliance_callback (guestfs_h *g, void *datavp, uint64_t source,
- int eh, int flags,
- const char *buf, size_t buf_len,
+appliance_callback (guestfs_h *g, void *datavp, uint64_t source, int eh,
+ int flags, const char *buf, size_t buf_len,
const uint64_t *array, size_t array_len)
{
struct pass_data *data = datavp;
@@ -459,7 +454,7 @@ appliance_callback (guestfs_h *g, void *datavp, uint64_t source,
buf += len;
buf_len -= len;
- if (buf_len == 0) /* still not complete, more to come! */
+ if (buf_len == 0) /* still not complete, more to come! */
return;
/* Skip the \n in the buffer. */
@@ -508,9 +503,8 @@ appliance_callback (guestfs_h *g, void *datavp, uint64_t source,
* are always delivered as complete messages.
*/
static void
-library_callback (guestfs_h *g, void *datavp, uint64_t source,
- int eh, int flags,
- const char *buf, size_t buf_len,
+library_callback (guestfs_h *g, void *datavp, uint64_t source, int eh,
+ int flags, const char *buf, size_t buf_len,
const uint64_t *array, size_t array_len)
{
struct pass_data *data = datavp;
@@ -530,9 +524,8 @@ library_callback (guestfs_h *g, void *datavp, uint64_t source,
* complete messages.
*/
static void
-trace_callback (guestfs_h *g, void *datavp, uint64_t source,
- int eh, int flags,
- const char *buf, size_t buf_len,
+trace_callback (guestfs_h *g, void *datavp, uint64_t source, int eh,
+ int flags, const char *buf, size_t buf_len,
const uint64_t *array, size_t array_len)
{
struct pass_data *data = datavp;
@@ -573,18 +566,18 @@ set_up_event_handlers (guestfs_h *g, size_t pass)
data->incomplete_log_message = -1;
data->seen_launch = 0;
- guestfs_set_event_callback (g, close_callback,
- GUESTFS_EVENT_CLOSE, 0, data);
+ guestfs_set_event_callback (g, close_callback, GUESTFS_EVENT_CLOSE, 0,
+ data);
guestfs_set_event_callback (g, subprocess_quit_callback,
GUESTFS_EVENT_SUBPROCESS_QUIT, 0, data);
guestfs_set_event_callback (g, launch_done_callback,
GUESTFS_EVENT_LAUNCH_DONE, 0, data);
guestfs_set_event_callback (g, appliance_callback,
GUESTFS_EVENT_APPLIANCE, 0, data);
- guestfs_set_event_callback (g, library_callback,
- GUESTFS_EVENT_LIBRARY, 0, data);
- guestfs_set_event_callback (g, trace_callback,
- GUESTFS_EVENT_TRACE, 0, data);
+ guestfs_set_event_callback (g, library_callback, GUESTFS_EVENT_LIBRARY, 0,
+ data);
+ guestfs_set_event_callback (g, trace_callback, GUESTFS_EVENT_TRACE, 0,
+ data);
guestfs_set_verbose (g, 1);
guestfs_set_trace (g, 1);
@@ -607,7 +600,7 @@ check_pass_data (void)
for (j = 0; j < pass_data[i].nr_events; ++j) {
assert (pass_data[i].events[j].t.tv_sec > 0);
if (j > 0) {
- ns = timespec_diff (&pass_data[i].events[j-1].t,
+ ns = timespec_diff (&pass_data[i].events[j - 1].t,
&pass_data[i].events[j].t);
assert (ns >= 0);
}
@@ -617,7 +610,7 @@ check_pass_data (void)
assert (pass_data[i].events[j].source != GUESTFS_EVENT_APPLIANCE ||
strchr (message, '\n') == NULL);
len = strlen (message);
- assert (len == 0 || message[len-1] != '\r');
+ assert (len == 0 || message[len - 1] != '\r');
}
}
}
@@ -629,7 +622,7 @@ print_escaped_string (const char *message)
if (isprint (*message))
putchar (*message);
else
- printf ("\\x%02x", (unsigned int) *message);
+ printf ("\\x%02x", (unsigned int)*message);
message++;
}
}
@@ -679,10 +672,11 @@ add_activity (const char *name, int flags)
assert (!activity_exists (name));
nr_activities++;
- activities = realloc (activities, sizeof (struct activity) * nr_activities);
+ activities =
+ realloc (activities, sizeof (struct activity) * nr_activities);
if (activities == NULL)
error (EXIT_FAILURE, errno, "realloc");
- ret = &activities[nr_activities-1];
+ ret = &activities[nr_activities - 1];
ret->name = strdup (name);
if (ret->name == NULL)
error (EXIT_FAILURE, errno, "strdup");
@@ -702,8 +696,8 @@ find_activity (const char *name)
for (i = 0; i < nr_activities; ++i)
if (STREQ (activities[i].name, name))
return &activities[i];
- error (EXIT_FAILURE, 0,
- "internal error: could not find activity '%s'", name);
+ error (EXIT_FAILURE, 0, "internal error: could not find activity
'%s'",
+ name);
/*NOTREACHED*/
abort ();
}
@@ -787,9 +781,8 @@ analyze_timeline (void)
for (j = 0; j < nr_activities; ++j) {
activities[j].percent = 100.0 * activities[j].mean / activity->mean;
- activities[j].warning =
- !(activities[j].flags & LONG_ACTIVITY) &&
- activities[j].percent >= WARNING_THRESHOLD;
+ activities[j].warning = !(activities[j].flags & LONG_ACTIVITY) &&
+ activities[j].percent >= WARNING_THRESHOLD;
}
/* Sort the activities by start time. */
@@ -806,8 +799,8 @@ dump_timeline (void)
for (i = 0; i < nr_activities; ++i) {
printf ("activity %zu:\n", i);
printf (" name = %s\n", activities[i].name);
- printf (" start - end = %.1f - %.1f\n",
- activities[i].t, activities[i].end_t);
+ printf (" start - end = %.1f - %.1f\n", activities[i].t,
+ activities[i].end_t);
printf (" mean elapsed = %.1f\n", activities[i].mean);
printf (" variance = %.1f\n", activities[i].variance);
printf (" s.d = %.1f\n", activities[i].sd);
@@ -818,12 +811,18 @@ dump_timeline (void)
static void
print_activity (struct activity *activity)
{
- if (activity->warning) ansi_red (); else ansi_green ();
+ if (activity->warning)
+ ansi_red ();
+ else
+ ansi_green ();
print_escaped_string (activity->name);
ansi_restore ();
- printf (" %.1fms ±%.1fms ",
- activity->mean / 1000000, activity->sd / 1000000);
- if (activity->warning) ansi_red (); else ansi_green ();
+ printf (" %.1fms ±%.1fms ", activity->mean / 1000000,
+ activity->sd / 1000000);
+ if (activity->warning)
+ ansi_red ();
+ else
+ ansi_green ();
printf ("(%.1f%%) ", activity->percent);
ansi_restore ();
}
@@ -831,7 +830,7 @@ print_activity (struct activity *activity)
static void
print_analysis (void)
{
- double t = -1; /* Current time. */
+ double t = -1; /* Current time. */
/* Which columns contain activities that we are displaying now?
* -1 == unused column, else index of an activity
*/
@@ -844,7 +843,8 @@ print_analysis (void)
const double MAX_T = 1e20;
columns = malloc (nr_columns * sizeof (ssize_t));
- if (columns == NULL) error (EXIT_FAILURE, errno, "malloc");
+ if (columns == NULL)
+ error (EXIT_FAILURE, errno, "malloc");
for (j = 0; j < nr_columns; ++j)
columns[j] = -1;
@@ -856,11 +856,12 @@ print_analysis (void)
for (i = 0; i < nr_activities; ++i) {
if (t < activities[i].t && activities[i].t < smallest_next_t)
smallest_next_t = activities[i].t;
- else if (t < activities[i].end_t && activities[i].end_t <
smallest_next_t)
+ else if (t < activities[i].end_t &&
+ activities[i].end_t < smallest_next_t)
smallest_next_t = activities[i].end_t;
}
if (smallest_next_t == MAX_T)
- break; /* Finished. */
+ break; /* Finished. */
last_t = t;
t = smallest_next_t;
@@ -886,7 +887,7 @@ print_analysis (void)
for (i = 0; i < nr_activities; ++i) {
if (activities[i].end_t < t) {
for (j = 0; j < nr_columns; ++j)
- if (columns[j] == (ssize_t) i) {
+ if (columns[j] == (ssize_t)i) {
columns[j] = -1;
break;
}
@@ -894,7 +895,7 @@ print_analysis (void)
}
/* May need to adjust last_free_column after previous operation. */
- while (last_free_column > 0 && columns[last_free_column-1] == -1)
+ while (last_free_column > 0 && columns[last_free_column - 1] == -1)
last_free_column--;
/* If there are any activities starting at this time, add them to
@@ -936,8 +937,8 @@ print_analysis (void)
static int
compare_activities_pointers_by_mean (const void *av, const void *bv)
{
- const struct activity * const *a = av;
- const struct activity * const *b = bv;
+ const struct activity *const *a = av;
+ const struct activity *const *b = bv;
return (*b)->mean - (*a)->mean;
}
diff --git a/tests/qemu/boot-analysis.h b/tests/qemu/boot-analysis.h
index 86d403e..4031750 100644
--- a/tests/qemu/boot-analysis.h
+++ b/tests/qemu/boot-analysis.h
@@ -59,9 +59,9 @@ extern struct pass_data pass_data[NR_TEST_PASSES];
* long they take (mean, variance, standard deviation of length).
*/
struct activity {
- char *name; /* Name of this activity. */
+ char *name; /* Name of this activity. */
int flags;
-#define LONG_ACTIVITY 1 /* Expected to take a long time. */
+#define LONG_ACTIVITY 1 /* Expected to take a long time. */
/* For each pass, record the actual start & end events of this
* activity.
@@ -69,16 +69,16 @@ struct activity {
size_t start_event[NR_TEST_PASSES];
size_t end_event[NR_TEST_PASSES];
- double t; /* Start (ns offset). */
- double end_t; /* t + mean - 1 */
+ double t; /* Start (ns offset). */
+ double end_t; /* t + mean - 1 */
/* Length of this activity. */
- double mean; /* Mean time elapsed (ns). */
- double variance; /* Variance. */
- double sd; /* Standard deviation. */
- double percent; /* Percent of total elapsed time. */
+ double mean; /* Mean time elapsed (ns). */
+ double variance; /* Variance. */
+ double sd; /* Standard deviation. */
+ double percent; /* Percent of total elapsed time. */
- int warning; /* Appears in red. */
+ int warning; /* Appears in red. */
};
extern size_t nr_activities;
diff --git a/tests/qemu/boot-benchmark.c b/tests/qemu/boot-benchmark.c
index 0508ee9..b2e9712 100644
--- a/tests/qemu/boot-benchmark.c
+++ b/tests/qemu/boot-benchmark.c
@@ -61,16 +61,16 @@ usage (int exitcode)
guestfs_close (g);
}
- fprintf (stderr,
- "boot-benchmark: Benchmark the time taken to boot the libguestfs
appliance.\n"
- "Usage:\n"
- " boot-benchmark [--options]\n"
- "Options:\n"
- " --help Display this usage text and exit.\n"
- " --append OPTS Append OPTS to kernel command line.\n"
- " -m MB\n"
- " --memsize MB Set memory size in MB (default: %d).\n"
- " --smp N Enable N virtual CPUs (default: 1).\n",
+ fprintf (stderr, "boot-benchmark: Benchmark the time taken to boot the "
+ "libguestfs appliance.\n"
+ "Usage:\n"
+ " boot-benchmark [--options]\n"
+ "Options:\n"
+ " --help Display this usage text and exit.\n"
+ " --append OPTS Append OPTS to kernel command line.\n"
+ " -m MB\n"
+ " --memsize MB Set memory size in MB (default: %d).\n"
+ " --smp N Enable N virtual CPUs (default: 1).\n",
default_memsize);
exit (exitcode);
}
@@ -80,21 +80,21 @@ main (int argc, char *argv[])
{
enum { HELP_OPTION = CHAR_MAX + 1 };
static const char *options = "m:";
- static const struct option long_options[] = {
- { "help", 0, 0, HELP_OPTION },
- { "append", 1, 0, 0 },
- { "memsize", 1, 0, 'm' },
- { "smp", 1, 0, 0 },
- { 0, 0, 0, 0 }
- };
+ static const struct option long_options[] = { { "help", 0, 0,
+ HELP_OPTION },
+ { "append", 1, 0, 0 },
+ { "memsize", 1, 0, 'm'
},
+ { "smp", 1, 0, 0 },
+ { 0, 0, 0, 0 } };
int c, option_index;
for (;;) {
c = getopt_long (argc, argv, options, long_options, &option_index);
- if (c == -1) break;
+ if (c == -1)
+ break;
switch (c) {
- case 0: /* Options which are long only. */
+ case 0: /* Options which are long only. */
if (STREQ (long_options[option_index].name, "append")) {
append = optarg;
break;
@@ -108,7 +108,8 @@ main (int argc, char *argv[])
break;
}
fprintf (stderr, "%s: unknown long option: %s (%d)\n",
- guestfs_int_program_name, long_options[option_index].name, option_index);
+ guestfs_int_program_name, long_options[option_index].name,
+ option_index);
exit (EXIT_FAILURE);
case 'm':
@@ -196,7 +197,8 @@ create_handle (void)
CLEANUP_FREE char *full_append = NULL;
g = guestfs_create ();
- if (!g) error (EXIT_FAILURE, errno, "guestfs_create");
+ if (!g)
+ error (EXIT_FAILURE, errno, "guestfs_create");
if (memsize != 0)
if (guestfs_set_memsize (g, memsize) == -1)
@@ -217,9 +219,8 @@ create_handle (void)
static void
add_drive (guestfs_h *g)
{
- if (guestfs_add_drive_opts (g, "/dev/null",
- GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
- GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,
+ if (guestfs_add_drive_opts (g, "/dev/null", GUESTFS_ADD_DRIVE_OPTS_FORMAT,
+ "raw", GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,
-1) == -1)
exit (EXIT_FAILURE);
}
diff --git a/tests/qemu/qemu-boot.c b/tests/qemu/qemu-boot.c
index 61d2ff0..aca60fe 100644
--- a/tests/qemu/qemu-boot.c
+++ b/tests/qemu/qemu-boot.c
@@ -39,7 +39,7 @@
#include "guestfs-internal-frontend.h"
#include "estimate-max-threads.h"
-#define MIN(a,b) ((a)<(b)?(a):(b))
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
/* Maximum number of threads we would ever run. Note this should not
* be > 20, unless libvirt is modified to increase the maximum number
@@ -47,7 +47,7 @@
*/
#define MAX_THREADS 12
-static size_t n; /* Number of qemu processes to run in total. */
+static size_t n; /* Number of qemu processes to run in total. */
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static int ignore_errors = 0;
@@ -58,9 +58,7 @@ static int verbose = 0;
/* Events captured by the --log option. */
static const uint64_t event_bitmask =
- GUESTFS_EVENT_LIBRARY |
- GUESTFS_EVENT_WARNING |
- GUESTFS_EVENT_APPLIANCE |
+ GUESTFS_EVENT_LIBRARY | GUESTFS_EVENT_WARNING | GUESTFS_EVENT_APPLIANCE |
GUESTFS_EVENT_TRACE;
struct thread_data {
@@ -70,17 +68,23 @@ struct thread_data {
static void run_test (size_t P);
static void *start_thread (void *thread_data_vp);
-static void message_callback (guestfs_h *g, void *opaque, uint64_t event, int
event_handle, int flags, const char *buf, size_t buf_len, const uint64_t *array, size_t
array_len);
+static void message_callback (guestfs_h *g, void *opaque, uint64_t event,
+ int event_handle, int flags, const char *buf,
+ size_t buf_len, const uint64_t *array,
+ size_t array_len);
static void
usage (int exitcode)
{
fprintf (stderr,
- "qemu-boot: A program for repeatedly running the libguestfs
appliance.\n"
- "qemu-boot [-i] [--log output.%%] [-P <nr-threads>] -n
<nr-appliances>\n"
+ "qemu-boot: A program for repeatedly running the libguestfs "
+ "appliance.\n"
+ "qemu-boot [-i] [--log output.%%] [-P <nr-threads>] -n "
+ "<nr-appliances>\n"
" -i Ignore errors\n"
" --log <file.%%>\n"
- " Write per-appliance logs to file (%% in name replaced by boot
number)\n"
+ " Write per-appliance logs to file (%% in name replaced "
+ "by boot number)\n"
" -P <n> Set number of parallel threads\n"
" (default is based on the amount of free memory)\n"
" -n <n> Set number of appliances to run before exiting\n"
@@ -109,7 +113,8 @@ main (int argc, char *argv[])
for (;;) {
c = getopt_long (argc, argv, options, long_options, &option_index);
- if (c == -1) break;
+ if (c == -1)
+ break;
switch (c) {
case 0:
@@ -123,8 +128,7 @@ main (int argc, char *argv[])
}
}
else
- error (EXIT_FAILURE, 0,
- "unknown long option: %s (%d)",
+ error (EXIT_FAILURE, 0, "unknown long option: %s (%d)",
long_options[option_index].name, option_index);
break;
@@ -163,8 +167,7 @@ main (int argc, char *argv[])
"must specify number of processes to run (-n option)");
if (optind != argc)
- error (EXIT_FAILURE, 0,
- "extra arguments found on the command line");
+ error (EXIT_FAILURE, 0, "extra arguments found on the command line");
/* Calculate the number of threads to use. */
if (P > 0)
@@ -256,7 +259,7 @@ start_thread (void *thread_data_vp)
goto error;
}
- if (quit) /* Work finished. */
+ if (quit) /* Work finished. */
break;
g = guestfs_create ();
@@ -267,12 +270,14 @@ start_thread (void *thread_data_vp)
goto error;
}
- /* Only if using --log, set up a callback. See examples/debug-logging.c */
+ /* Only if using --log, set up a callback. See examples/debug-logging.c
+ */
if (log_template != NULL) {
size_t j, k;
log_file = malloc (log_file_size + 1);
- if (log_file == NULL) abort ();
+ if (log_file == NULL)
+ abort ();
for (j = 0, k = 0; j < strlen (log_template); ++j) {
if (log_template[j] == '%') {
snprintf (&log_file[k], log_file_size - k, "%zu", i);
@@ -287,8 +292,8 @@ start_thread (void *thread_data_vp)
perror (log_file);
abort ();
}
- guestfs_set_event_callback (g, message_callback,
- event_bitmask, 0, log_fp);
+ guestfs_set_event_callback (g, message_callback, event_bitmask, 0,
+ log_fp);
}
snprintf (id, sizeof id, "%zu", i);
@@ -327,18 +332,16 @@ start_thread (void *thread_data_vp)
thread_data->r = 0;
return &thread_data->r;
- error:
+error:
thread_data->r = -1;
return &thread_data->r;
}
/* If using --log, this is called to write messages to the log file. */
static void
-message_callback (guestfs_h *g, void *opaque,
- uint64_t event, int event_handle,
- int flags,
- const char *buf, size_t buf_len,
- const uint64_t *array, size_t array_len)
+message_callback (guestfs_h *g, void *opaque, uint64_t event,
+ int event_handle, int flags, const char *buf,
+ size_t buf_len, const uint64_t *array, size_t array_len)
{
FILE *fp = opaque;
diff --git a/tests/qemu/qemu-speed-test.c b/tests/qemu/qemu-speed-test.c
index 375a9a4..7601e01 100644
--- a/tests/qemu/qemu-speed-test.c
+++ b/tests/qemu/qemu-speed-test.c
@@ -67,24 +67,24 @@ reset_default_tests (int *flag)
static void
usage (int exitcode)
{
- fprintf (stderr,
- "qemu-speed-test: Test the speed of qemu features.\n"
- "\n"
- "To run all tests (recommended), do:\n"
- " qemu-speed-test\n"
- "\n"
- "To run only specific tests, do:\n"
- " qemu-speed-test --option [--option ...]\n"
- "where the test options are:\n"
- " --virtio-serial-upload\n"
- " --virtio-serial-download\n"
- " --block-device-write\n"
- " --block-device-read\n"
- "\n"
- "Other options:\n"
- " --help Display help output and exit\n"
- " -t <SECS> | --time=<SECS> Set max length of test in
seconds\n"
- );
+ fprintf (
+ stderr,
+ "qemu-speed-test: Test the speed of qemu features.\n"
+ "\n"
+ "To run all tests (recommended), do:\n"
+ " qemu-speed-test\n"
+ "\n"
+ "To run only specific tests, do:\n"
+ " qemu-speed-test --option [--option ...]\n"
+ "where the test options are:\n"
+ " --virtio-serial-upload\n"
+ " --virtio-serial-download\n"
+ " --block-device-write\n"
+ " --block-device-read\n"
+ "\n"
+ "Other options:\n"
+ " --help Display help output and exit\n"
+ " -t <SECS> | --time=<SECS> Set max length of test in
seconds\n");
exit (exitcode);
}
@@ -110,7 +110,8 @@ main (int argc, char *argv[])
for (;;) {
c = getopt_long (argc, argv, options, long_options, &option_index);
- if (c == -1) break;
+ if (c == -1)
+ break;
switch (c) {
case 0:
@@ -119,21 +120,25 @@ main (int argc, char *argv[])
reset_default_tests (&reset_flag);
virtio_serial_upload = 1;
}
- else if (STREQ (long_options[option_index].name,
"virtio-serial-download")) {
+ else if (STREQ (long_options[option_index].name,
+ "virtio-serial-download")) {
reset_default_tests (&reset_flag);
virtio_serial_download = 1;
}
- else if (STREQ (long_options[option_index].name, "block-device-write"))
{
+ else if (STREQ (long_options[option_index].name,
+ "block-device-write")) {
reset_default_tests (&reset_flag);
block_device_write = 1;
}
- else if (STREQ (long_options[option_index].name, "block-device-read")) {
+ else if (STREQ (long_options[option_index].name,
+ "block-device-read")) {
reset_default_tests (&reset_flag);
block_device_read = 1;
}
else {
fprintf (stderr, "%s: unknown long option: %s (%d)\n",
- guestfs_int_program_name, long_options[option_index].name,
option_index);
+ guestfs_int_program_name, long_options[option_index].name,
+ option_index);
exit (EXIT_FAILURE);
}
break;
@@ -170,8 +175,8 @@ main (int argc, char *argv[])
static void
print_rate (const char *msg, int64_t rate)
{
- printf ("%-40s %" PRIi64 " bytes/sec (%" PRIi64 "
Mbytes/sec)\n",
- msg, rate, rate / 1024 / 1024);
+ printf ("%-40s %" PRIi64 " bytes/sec (%" PRIi64 "
Mbytes/sec)\n", msg,
+ rate, rate / 1024 / 1024);
fflush (stdout);
}
@@ -181,8 +186,8 @@ print_rate (const char *msg, int64_t rate)
/* The maximum amount of data to copy. You can safely make this very
* large because it's only making sparse files.
*/
-#define TEST_SERIAL_MAX_SIZE \
- (INT64_C(1024) * INT64_C(1024) * INT64_C(1024) * INT64_C(1024))
+#define TEST_SERIAL_MAX_SIZE \
+ (INT64_C (1024) * INT64_C (1024) * INT64_C (1024) * INT64_C (1024))
static guestfs_h *g;
static struct timeval start;
@@ -210,10 +215,9 @@ timeval_diff (const struct timeval *x, const struct timeval *y)
}
static void
-progress_cb (guestfs_h *g, void *vp, uint64_t event,
- int eh, int flags,
- const char *buf, size_t buflen,
- const uint64_t *array, size_t arraylen)
+progress_cb (guestfs_h *g, void *vp, uint64_t event, int eh, int flags,
+ const char *buf, size_t buflen, const uint64_t *array,
+ size_t arraylen)
{
uint64_t transferred;
struct timeval now;
@@ -233,8 +237,7 @@ progress_cb (guestfs_h *g, void *vp, uint64_t event,
if (millis != 0) {
rate = 1000 * transferred / millis;
- printf ("%s: %" PRIi64 " bytes/sec \r",
- operation, rate);
+ printf ("%s: %" PRIi64 " bytes/sec \r", operation,
rate);
fflush (stdout);
}
}
@@ -265,7 +268,7 @@ test_virtio_serial (void)
if (!g)
error (EXIT_FAILURE, errno, "guestfs_create");
- if (guestfs_add_drive_scratch (g, INT64_C (100*1024*1024), -1) == -1)
+ if (guestfs_add_drive_scratch (g, INT64_C (100 * 1024 * 1024), -1) == -1)
exit (EXIT_FAILURE);
if (guestfs_launch (g) == -1)
@@ -295,7 +298,8 @@ test_virtio_serial (void)
gettimeofday (&start, NULL);
rate = -1;
operation = "upload";
- alarm (max_time_override > 0 ? max_time_override : TEST_SERIAL_MAX_TIME);
+ alarm (max_time_override > 0 ? max_time_override
+ : TEST_SERIAL_MAX_TIME);
/* For the upload test, upload the sparse file to /dev/null in the
* appliance. Hopefully this is mostly testing just virtio-serial.
@@ -310,17 +314,16 @@ test_virtio_serial (void)
* or that the upload will be stopped by the alarm.
*/
if (r == -1 && guestfs_last_errno (g) != EINTR) {
- fprintf (stderr,
- "%s: expecting upload command to return EINTR\n%s\n",
+ fprintf (stderr, "%s: expecting upload command to return EINTR\n%s\n",
guestfs_int_program_name, guestfs_last_error (g));
exit (EXIT_FAILURE);
}
if (rate == -1) {
rate_error:
- fprintf (stderr, "%s: internal error: progress callback was not called! (r=%d,
errno=%d)\n",
- guestfs_int_program_name,
- r, guestfs_last_errno (g));
+ fprintf (stderr, "%s: internal error: progress callback was not "
+ "called! (r=%d, errno=%d)\n",
+ guestfs_int_program_name, r, guestfs_last_errno (g));
exit (EXIT_FAILURE);
}
@@ -339,7 +342,8 @@ test_virtio_serial (void)
gettimeofday (&start, NULL);
rate = -1;
operation = "download";
- alarm (max_time_override > 0 ? max_time_override : TEST_SERIAL_MAX_TIME);
+ alarm (max_time_override > 0 ? max_time_override
+ : TEST_SERIAL_MAX_TIME);
guestfs_push_error_handler (g, NULL, NULL);
r = guestfs_download (g, "/sparse", "/dev/null");
alarm (0);
@@ -378,7 +382,8 @@ test_block_device (void)
CLEANUP_FREE char **devices = NULL;
char *r;
const char *argv[4];
- int t = max_time_override > 0 ? max_time_override : TEST_BLOCK_DEVICE_TIME;
+ int t =
+ max_time_override > 0 ? max_time_override : TEST_BLOCK_DEVICE_TIME;
char tbuf[64];
int64_t bytes_written, bytes_read;
@@ -399,8 +404,7 @@ test_block_device (void)
error (EXIT_FAILURE, errno, "mkstemp: %s", tmpfile);
close (fd);
- if (guestfs_disk_create (g, tmpfile, "raw",
- INT64_C (1024*1024*1024),
+ if (guestfs_disk_create (g, tmpfile, "raw", INT64_C (1024 * 1024 * 1024),
GUESTFS_DISK_CREATE_PREALLOCATION, "full",
-1) == -1)
exit (EXIT_FAILURE);
@@ -415,8 +419,10 @@ test_block_device (void)
if (devices == NULL)
exit (EXIT_FAILURE);
if (devices[0] == NULL) {
- fprintf (stderr, "%s: expected guestfs_list_devices to return at least 1
device\n",
- guestfs_int_program_name);
+ fprintf (
+ stderr,
+ "%s: expected guestfs_list_devices to return at least 1 device\n",
+ guestfs_int_program_name);
exit (EXIT_FAILURE);
}
@@ -426,7 +432,7 @@ test_block_device (void)
argv[1] = "w";
argv[2] = tbuf;
argv[3] = NULL;
- r = guestfs_debug (g, "device_speed", (char **) argv);
+ r = guestfs_debug (g, "device_speed", (char **)argv);
if (r == NULL)
exit (EXIT_FAILURE);
@@ -445,7 +451,7 @@ test_block_device (void)
argv[1] = "r";
argv[2] = tbuf;
argv[3] = NULL;
- r = guestfs_debug (g, "device_speed", (char **) argv);
+ r = guestfs_debug (g, "device_speed", (char **)argv);
if (r == NULL)
exit (EXIT_FAILURE);
diff --git a/tests/regressions/rhbz1055452.c b/tests/regressions/rhbz1055452.c
index 79cd540..1c018b9 100644
--- a/tests/regressions/rhbz1055452.c
+++ b/tests/regressions/rhbz1055452.c
@@ -39,7 +39,8 @@ int
main (int argc, char *argv[])
{
guestfs_h *g;
- const char *var[] = { "LIBGUESTFS_BACKEND",
"LIBGUESTFS_ATTACH_METHOD", NULL };
+ const char *var[] = { "LIBGUESTFS_BACKEND",
"LIBGUESTFS_ATTACH_METHOD",
+ NULL };
const char *value[] = { "appliance", "direct", NULL };
size_t i, j;
char *r;
@@ -75,7 +76,8 @@ main (int argc, char *argv[])
if (!r)
exit (EXIT_FAILURE);
if (STRNEQ (r, "appliance")) {
- fprintf (stderr, "%s: expecting guestfs_get_attach_method to return
'appliance', but it returned '%s'.\n",
+ fprintf (stderr, "%s: expecting guestfs_get_attach_method to return "
+ "'appliance', but it returned '%s'.\n",
argv[0], r);
exit (EXIT_FAILURE);
}
@@ -87,7 +89,8 @@ main (int argc, char *argv[])
if (!r)
exit (EXIT_FAILURE);
if (STRNEQ (r, "direct")) {
- fprintf (stderr, "%s: expecting guestfs_get_backend to return 'direct',
but it returned '%s'.\n",
+ fprintf (stderr, "%s: expecting guestfs_get_backend to return "
+ "'direct', but it returned '%s'.\n",
argv[0], r);
exit (EXIT_FAILURE);
}
diff --git a/tests/regressions/rhbz501893.c b/tests/regressions/rhbz501893.c
index f6111c9..2736bc1 100644
--- a/tests/regressions/rhbz501893.c
+++ b/tests/regressions/rhbz501893.c
@@ -42,9 +42,8 @@ main (int argc, char *argv[])
/* This optional argument must not be NULL. */
- assert (guestfs_add_drive_opts (g, "/dev/null",
- GUESTFS_ADD_DRIVE_OPTS_FORMAT, NULL,
- -1) == -1);
+ assert (guestfs_add_drive_opts (
+ g, "/dev/null", GUESTFS_ADD_DRIVE_OPTS_FORMAT, NULL, -1) == -1);
/* These can be safely set to NULL, should be no error. */
diff --git a/tests/regressions/rhbz790721.c b/tests/regressions/rhbz790721.c
index e2178e5..b03b687 100644
--- a/tests/regressions/rhbz790721.c
+++ b/tests/regressions/rhbz790721.c
@@ -100,7 +100,7 @@ main (int argc, char *argv[])
for (i = 0; i < NR_THREADS; ++i) {
int *ret;
- r = pthread_join (thread[i], (void **) &ret);
+ r = pthread_join (thread[i], (void **)&ret);
if (r != 0)
error (EXIT_FAILURE, r, "pthread_join");
if (*ret == -1)
@@ -124,9 +124,8 @@ start_thread (void *vi)
pthread_exit (vi);
}
- if (guestfs_add_drive_opts (g, "/dev/null",
- GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
- GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,
+ if (guestfs_add_drive_opts (g, "/dev/null", GUESTFS_ADD_DRIVE_OPTS_FORMAT,
+ "raw", GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,
-1) == -1) {
*(int *)vi = -1;
pthread_exit (vi);
@@ -141,8 +140,8 @@ start_thread (void *vi)
/* Wait for the other threads to finish starting up. */
r = pthread_barrier_wait (&barrier);
if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) {
- fprintf (stderr, "pthread_barrier_wait: [thread %d]: %s\n",
- thread_id, strerror (r));
+ fprintf (stderr, "pthread_barrier_wait: [thread %d]: %s\n", thread_id,
+ strerror (r));
*(int *)vi = -1;
pthread_exit (vi);
}
@@ -156,16 +155,18 @@ start_thread (void *vi)
error = guestfs_last_error (g);
if (r == 0) { /* This should NOT happen. */
- fprintf (stderr, "rhbz790721: [thread %d]: "
- "strangeness in test: expected launch to fail, but it
didn't!\n",
- thread_id);
+ fprintf (
+ stderr,
+ "rhbz790721: [thread %d]: "
+ "strangeness in test: expected launch to fail, but it didn't!\n",
+ thread_id);
*(int *)vi = -1;
pthread_exit (vi);
}
if (error == NULL) { /* This also should NOT happen. */
fprintf (stderr, "rhbz790721: [thread %d]: "
- "strangeness in test: no error message!\n",
+ "strangeness in test: no error message!\n",
thread_id);
*(int *)vi = -1;
pthread_exit (vi);
@@ -177,7 +178,8 @@ start_thread (void *vi)
* is designed to spot.
*/
if (strstr (error, "guestfs_launch failed") == NULL) {
- fprintf (stderr, "rhbz790721: [thread %d]: error: %s\n", thread_id,
error);
+ fprintf (stderr, "rhbz790721: [thread %d]: error: %s\n", thread_id,
+ error);
*(int *)vi = -1;
pthread_exit (vi);
}
diff --git a/tests/regressions/rhbz914931.c b/tests/regressions/rhbz914931.c
index 61b81ba..23b442f 100644
--- a/tests/regressions/rhbz914931.c
+++ b/tests/regressions/rhbz914931.c
@@ -52,9 +52,8 @@ main (int argc, char *argv[])
if (!g)
error (EXIT_FAILURE, errno, "guestfs_create");
- if (guestfs_add_drive_opts (g, "/dev/null",
- GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
- GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,
+ if (guestfs_add_drive_opts (g, "/dev/null", GUESTFS_ADD_DRIVE_OPTS_FORMAT,
+ "raw", GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,
-1) == -1)
exit (EXIT_FAILURE);
diff --git a/tests/regressions/test-big-heap.c b/tests/regressions/test-big-heap.c
index 1cbf8d2..2e490d3 100644
--- a/tests/regressions/test-big-heap.c
+++ b/tests/regressions/test-big-heap.c
@@ -61,9 +61,8 @@ main (int argc, char *argv[])
*/
mem = calloc (1100, 1024 * 1024);
if (mem == NULL) {
- fprintf (stderr,
- "%s: test skipped because cannot allocate enough "
- "contiguous heap\n",
+ fprintf (stderr, "%s: test skipped because cannot allocate enough "
+ "contiguous heap\n",
argv[0]);
exit (77);
}
@@ -74,7 +73,8 @@ main (int argc, char *argv[])
fmt = guestfs_disk_format (g, "/dev/null");
if (fmt == NULL) {
/* Test failed. */
- fprintf (stderr, "%s: unexpected failure of test, see earlier messages\n",
+ fprintf (stderr,
+ "%s: unexpected failure of test, see earlier messages\n",
argv[0]);
exit (EXIT_FAILURE);
}
diff --git a/tests/xml/fake-libvirt-xml.c b/tests/xml/fake-libvirt-xml.c
index a34b700..fadf42b 100644
--- a/tests/xml/fake-libvirt-xml.c
+++ b/tests/xml/fake-libvirt-xml.c
@@ -51,8 +51,8 @@ virDomainGetXMLDesc (virDomainPtr dom, unsigned int flags)
_exit (1);
}
- fprintf (stderr,
- "fake_libvirt_xml: returning fake libvirt XML from %s\n", path);
+ fprintf (stderr, "fake_libvirt_xml: returning fake libvirt XML from %s\n",
+ path);
fd = open (path, O_RDONLY | O_CLOEXEC);
if (fd == -1) {
@@ -90,5 +90,5 @@ virDomainGetXMLDesc (virDomainPtr dom, unsigned int flags)
_exit (1);
}
- return buf; /* caller frees */
+ return buf; /* caller frees */
}
diff --git a/v2v/domainxml-c.c b/v2v/domainxml-c.c
index 4876f94..fc0d164 100644
--- a/v2v/domainxml-c.c
+++ b/v2v/domainxml-c.c
@@ -81,8 +81,7 @@ get_dom_state (virDomainPtr dom)
/* See src/libvirt-auth.c for why we need this. */
static int
libvirt_auth_default_wrapper (virConnectCredentialPtr cred,
- unsigned int ncred,
- void *passwordvp)
+ unsigned int ncred, void *passwordvp)
{
const char *password = passwordvp;
unsigned int i;
@@ -131,14 +130,15 @@ connect_and_load_pool (value connv, value poolnamev)
* since it handles all the PolicyKit crap. However it also makes
* coding this simpler.
*/
- conn = virConnectOpenAuth (conn_uri, virConnectAuthPtrDefault,
- VIR_CONNECT_RO);
+ conn =
+ virConnectOpenAuth (conn_uri, virConnectAuthPtrDefault, VIR_CONNECT_RO);
if (conn == NULL) {
if (conn_uri)
snprintf (errmsg, sizeof errmsg,
_("cannot open libvirt connection '%s'"), conn_uri);
else
- snprintf (errmsg, sizeof errmsg, _("cannot open libvirt connection"));
+ snprintf (errmsg, sizeof errmsg,
+ _("cannot open libvirt connection"));
caml_invalid_argument (errmsg);
}
@@ -158,9 +158,13 @@ connect_and_load_pool (value connv, value poolnamev)
if (!pool) {
err = virGetLastError ();
- snprintf (errmsg, sizeof errmsg,
- _("cannot find libvirt pool '%s': %s\n\nUse `virsh pool-list
--all' to list all available pools, and `virsh pool-dumpxml <pool>' to
display details about a particular pool.\n\nTo set the pool which virt-v2v uses, add the
`-os <pool>' option."),
- poolname, err->message);
+ snprintf (
+ errmsg, sizeof errmsg,
+ _("cannot find libvirt pool '%s': %s\n\nUse `virsh pool-list
--all' "
+ "to list all available pools, and `virsh pool-dumpxml <pool>' to
"
+ "display details about a particular pool.\n\nTo set the pool "
+ "which virt-v2v uses, add the `-os <pool>' option."),
+ poolname, err->message);
virConnectClose (conn);
caml_invalid_argument (errmsg);
}
@@ -198,7 +202,7 @@ v2v_dumpxml (value passwordv, value connv, value domnamev)
/* Set up authentication wrapper. */
authdata = *virConnectAuthPtrDefault;
authdata.cb = libvirt_auth_default_wrapper;
- authdata.cbdata = (void *) password;
+ authdata.cbdata = (void *)password;
/* Note this cannot be a read-only connection since we need to use
* the VIR_DOMAIN_XML_SECURE flag below.
@@ -209,7 +213,8 @@ v2v_dumpxml (value passwordv, value connv, value domnamev)
snprintf (errmsg, sizeof errmsg,
_("cannot open libvirt connection '%s'"), conn_uri);
else
- snprintf (errmsg, sizeof errmsg, _("cannot open libvirt connection"));
+ snprintf (errmsg, sizeof errmsg,
+ _("cannot open libvirt connection"));
caml_invalid_argument (errmsg);
}
@@ -230,7 +235,8 @@ v2v_dumpxml (value passwordv, value connv, value domnamev)
if (!dom) {
err = virGetLastError ();
snprintf (errmsg, sizeof errmsg,
- _("cannot find libvirt domain '%s': %s"), domname,
err->message);
+ _("cannot find libvirt domain '%s': %s"), domname,
+ err->message);
virConnectClose (conn);
caml_invalid_argument (errmsg);
}
@@ -241,11 +247,11 @@ v2v_dumpxml (value passwordv, value connv, value domnamev)
if (!is_test_uri) {
int state = get_dom_state (dom);
- if (state == VIR_DOMAIN_RUNNING ||
- state == VIR_DOMAIN_BLOCKED ||
+ if (state == VIR_DOMAIN_RUNNING || state == VIR_DOMAIN_BLOCKED ||
state == VIR_DOMAIN_PAUSED) {
snprintf (errmsg, sizeof errmsg,
- _("libvirt domain '%s' is running or paused. It must be
shut down in order to perform virt-v2v conversion"),
+ _("libvirt domain '%s' is running or paused. It must be
"
+ "shut down in order to perform virt-v2v conversion"),
domname);
virDomainFree (dom);
virConnectClose (conn);
@@ -258,8 +264,8 @@ v2v_dumpxml (value passwordv, value connv, value domnamev)
if (xml == NULL) {
err = virGetLastError ();
snprintf (errmsg, sizeof errmsg,
- _("cannot fetch XML description of guest '%s': %s"),
- domname, err->message);
+ _("cannot fetch XML description of guest '%s': %s"),
domname,
+ err->message);
virDomainFree (dom);
virConnectClose (conn);
caml_invalid_argument (errmsg);
@@ -338,7 +344,8 @@ v2v_vol_dumpxml (value connv, value poolnamev, value volnamev)
if (!vol) {
err = virGetLastError ();
snprintf (errmsg, sizeof errmsg,
- _("cannot find libvirt volume '%s': %s"), volname,
err->message);
+ _("cannot find libvirt volume '%s': %s"), volname,
+ err->message);
virStoragePoolFree (pool);
virConnectClose (conn);
caml_invalid_argument (errmsg);
@@ -386,14 +393,15 @@ v2v_capabilities (value connv, value unitv)
* since it handles all the PolicyKit crap. However it also makes
* coding this simpler.
*/
- conn = virConnectOpenAuth (conn_uri, virConnectAuthPtrDefault,
- VIR_CONNECT_RO);
+ conn =
+ virConnectOpenAuth (conn_uri, virConnectAuthPtrDefault, VIR_CONNECT_RO);
if (conn == NULL) {
if (conn_uri)
snprintf (errmsg, sizeof errmsg,
_("cannot open libvirt connection '%s'"), conn_uri);
else
- snprintf (errmsg, sizeof errmsg, _("cannot open libvirt connection"));
+ snprintf (errmsg, sizeof errmsg,
+ _("cannot open libvirt connection"));
caml_invalid_argument (errmsg);
}
@@ -443,14 +451,15 @@ v2v_domain_exists (value connv, value domnamev)
* since it handles all the PolicyKit crap. However it also makes
* coding this simpler.
*/
- conn = virConnectOpenAuth (conn_uri, virConnectAuthPtrDefault,
- VIR_CONNECT_RO);
+ conn =
+ virConnectOpenAuth (conn_uri, virConnectAuthPtrDefault, VIR_CONNECT_RO);
if (conn == NULL) {
if (conn_uri)
snprintf (errmsg, sizeof errmsg,
_("cannot open libvirt connection '%s'"), conn_uri);
else
- snprintf (errmsg, sizeof errmsg, _("cannot open libvirt connection"));
+ snprintf (errmsg, sizeof errmsg,
+ _("cannot open libvirt connection"));
caml_invalid_argument (errmsg);
}
@@ -474,8 +483,8 @@ v2v_domain_exists (value connv, value domnamev)
domain_exists = 0;
else {
snprintf (errmsg, sizeof errmsg,
- _("cannot find libvirt domain '%s': %s"),
- domname, err->message);
+ _("cannot find libvirt domain '%s': %s"), domname,
+ err->message);
virConnectClose (conn);
caml_invalid_argument (errmsg);
}
@@ -488,16 +497,18 @@ v2v_domain_exists (value connv, value domnamev)
#else /* !HAVE_LIBVIRT */
-#define NO_LIBVIRT(proto) \
- proto __attribute__((noreturn)); \
- proto \
- { \
- caml_invalid_argument ("virt-v2v was compiled without libvirt support"); \
+#define NO_LIBVIRT(proto) \
+ proto __attribute__((noreturn)); \
+ proto \
+ { \
+ caml_invalid_argument ( \
+ "virt-v2v was compiled without libvirt support"); \
}
NO_LIBVIRT (value v2v_dumpxml (value connv, value domv))
NO_LIBVIRT (value v2v_pool_dumpxml (value connv, value poolv))
-NO_LIBVIRT (value v2v_vol_dumpxml (value connv, value poolnamev, value volnamev))
+NO_LIBVIRT (value v2v_vol_dumpxml (value connv, value poolnamev,
+ value volnamev))
NO_LIBVIRT (value v2v_capabilities (value connv, value unitv))
NO_LIBVIRT (value v2v_domain_exists (value connv, value domnamev))
diff --git a/v2v/utils-c.c b/v2v/utils-c.c
index 5098952..f000ce2 100644
--- a/v2v/utils-c.c
+++ b/v2v/utils-c.c
@@ -71,8 +71,8 @@ get_firmware (char **firmware)
len = guestfs_int_count_strings (firmware);
for (i = len; i > 0; i -= 2) {
- v1 = caml_copy_string (firmware[i-2]);
- v2 = caml_copy_string (firmware[i-1]);
+ v1 = caml_copy_string (firmware[i - 2]);
+ v2 = caml_copy_string (firmware[i - 1]);
v = caml_alloc (2, 0);
Store_field (v, 0, v1);
Store_field (v, 1, v2);
@@ -88,17 +88,17 @@ get_firmware (char **firmware)
value
v2v_utils_ovmf_i386_firmware (value unitv)
{
- return get_firmware ((char **) guestfs_int_ovmf_i386_firmware);
+ return get_firmware ((char **)guestfs_int_ovmf_i386_firmware);
}
value
v2v_utils_ovmf_x86_64_firmware (value unitv)
{
- return get_firmware ((char **) guestfs_int_ovmf_x86_64_firmware);
+ return get_firmware ((char **)guestfs_int_ovmf_x86_64_firmware);
}
value
v2v_utils_aavmf_firmware (value unitv)
{
- return get_firmware ((char **) guestfs_int_aavmf_firmware);
+ return get_firmware ((char **)guestfs_int_aavmf_firmware);
}
diff --git a/v2v/xml-c.c b/v2v/xml-c.c
index ecaaedf..ebf21b7 100644
--- a/v2v/xml-c.c
+++ b/v2v/xml-c.c
@@ -38,15 +38,12 @@
#pragma GCC diagnostic ignored "-Wmissing-prototypes"
/* xmlDocPtr type */
-#define Doc_val(v) (*((xmlDocPtr *)Data_custom_val(v)))
+#define Doc_val(v) (*((xmlDocPtr *)Data_custom_val (v)))
static struct custom_operations doc_custom_operations = {
- (char *) "doc_custom_operations",
- custom_finalize_default,
- custom_compare_default,
- custom_hash_default,
- custom_serialize_default,
- custom_deserialize_default
+ (char *)"doc_custom_operations", custom_finalize_default,
+ custom_compare_default, custom_hash_default,
+ custom_serialize_default, custom_deserialize_default
};
value
@@ -60,10 +57,10 @@ v2v_xml_free_doc_ptr (value docv)
}
/* xmlXPathContextPtr type */
-#define Xpathctx_ptr_val(v) (*((xmlXPathContextPtr *)Data_custom_val(v)))
+#define Xpathctx_ptr_val(v) (*((xmlXPathContextPtr *)Data_custom_val (v)))
static struct custom_operations xpathctx_ptr_custom_operations = {
- (char *) "xpathctx_ptr_custom_operations",
+ (char *)"xpathctx_ptr_custom_operations",
custom_finalize_default,
custom_compare_default,
custom_hash_default,
@@ -82,10 +79,10 @@ v2v_xml_free_xpathctx_ptr (value xpathctxv)
}
/* xmlXPathObjectPtr type */
-#define Xpathobj_ptr_val(v) (*((xmlXPathObjectPtr *)Data_custom_val(v)))
+#define Xpathobj_ptr_val(v) (*((xmlXPathObjectPtr *)Data_custom_val (v)))
static struct custom_operations xpathobj_ptr_custom_operations = {
- (char *) "xpathobj_ptr_custom_operations",
+ (char *)"xpathobj_ptr_custom_operations",
custom_finalize_default,
custom_compare_default,
custom_hash_default,
@@ -113,12 +110,14 @@ v2v_xml_parse_memory (value xmlv)
/* For security reasons, call xmlReadMemory (not xmlParseMemory) and
* pass XML_PARSE_NONET. See commit 845daded5fddc70f.
*/
- doc = xmlReadMemory (String_val (xmlv), caml_string_length (xmlv),
- NULL, NULL, XML_PARSE_NONET);
+ doc = xmlReadMemory (String_val (xmlv), caml_string_length (xmlv), NULL,
+ NULL, XML_PARSE_NONET);
if (doc == NULL)
- caml_invalid_argument ("parse_memory: unable to parse XML from libvirt");
+ caml_invalid_argument (
+ "parse_memory: unable to parse XML from libvirt");
- docv = caml_alloc_custom (&doc_custom_operations, sizeof (xmlDocPtr), 0, 1);
+ docv =
+ caml_alloc_custom (&doc_custom_operations, sizeof (xmlDocPtr), 0, 1);
Doc_val (docv) = doc;
CAMLreturn (docv);
@@ -136,7 +135,8 @@ v2v_xml_copy_doc (value docv, value recursivev)
if (copy == NULL)
caml_invalid_argument ("copy_doc: failed to copy");
- copyv = caml_alloc_custom (&doc_custom_operations, sizeof (xmlDocPtr), 0, 1);
+ copyv =
+ caml_alloc_custom (&doc_custom_operations, sizeof (xmlDocPtr), 0, 1);
Doc_val (copyv) = copy;
CAMLreturn (copyv);
@@ -172,7 +172,8 @@ v2v_xml_xpath_new_context_ptr (value docv)
doc = Doc_val (docv);
xpathctx = xmlXPathNewContext (doc);
if (xpathctx == NULL)
- caml_invalid_argument ("xpath_new_context: unable to create
xmlXPathNewContext");
+ caml_invalid_argument (
+ "xpath_new_context: unable to create xmlXPathNewContext");
xpathctxv = caml_alloc_custom (&xpathctx_ptr_custom_operations,
sizeof (xmlXPathContextPtr), 0, 1);
@@ -189,9 +190,11 @@ v2v_xml_xpathctx_ptr_register_ns (value xpathctxv, value prefix,
value uri)
int r;
xpathctx = Xpathctx_ptr_val (xpathctxv);
- r = xmlXPathRegisterNs (xpathctx, BAD_CAST String_val (prefix), BAD_CAST String_val
(uri));
+ r = xmlXPathRegisterNs (xpathctx, BAD_CAST String_val (prefix),
+ BAD_CAST String_val (uri));
if (r == -1)
- caml_invalid_argument ("xpath_register_ns: unable to register namespace");
+ caml_invalid_argument (
+ "xpath_register_ns: unable to register namespace");
CAMLreturn (Val_unit);
}
@@ -207,7 +210,8 @@ v2v_xml_xpathctx_ptr_eval_expression (value xpathctxv, value exprv)
xpathctx = Xpathctx_ptr_val (xpathctxv);
xpathobj = xmlXPathEvalExpression (BAD_CAST String_val (exprv), xpathctx);
if (xpathobj == NULL)
- caml_invalid_argument ("xpath_eval_expression: unable to evaluate XPath
expression");
+ caml_invalid_argument (
+ "xpath_eval_expression: unable to evaluate XPath expression");
xpathobjv = caml_alloc_custom (&xpathobj_ptr_custom_operations,
sizeof (xmlXPathObjectPtr), 0, 1);
@@ -246,7 +250,7 @@ v2v_xml_xpathobj_ptr_get_node_ptr (value xpathobjv, value iv)
* pointer with the doc in the OCaml layer so the GC will not free
* one without freeing the other.
*/
- CAMLreturn ((value) xpathobj->nodesetval->nodeTab[i]);
+ CAMLreturn ((value)xpathobj->nodesetval->nodeTab[i]);
}
value
@@ -254,7 +258,7 @@ v2v_xml_xpathctx_set_node_ptr (value xpathctxv, value nodev)
{
CAMLparam2 (xpathctxv, nodev);
xmlXPathContextPtr xpathctx = Xpathctx_ptr_val (xpathctxv);
- xmlNodePtr node = (xmlNodePtr) nodev;
+ xmlNodePtr node = (xmlNodePtr)nodev;
xpathctx->node = node;
@@ -265,15 +269,16 @@ value
v2v_xml_node_ptr_name (value nodev)
{
CAMLparam1 (nodev);
- xmlNodePtr node = (xmlNodePtr) nodev;
+ xmlNodePtr node = (xmlNodePtr)nodev;
switch (node->type) {
case XML_ATTRIBUTE_NODE:
case XML_ELEMENT_NODE:
- CAMLreturn (caml_copy_string ((char *) node->name));
+ CAMLreturn (caml_copy_string ((char *)node->name));
default:
- caml_invalid_argument ("node_name: don't know how to get the name of this
node");
+ caml_invalid_argument (
+ "node_name: don't know how to get the name of this node");
}
}
@@ -283,7 +288,7 @@ v2v_xml_node_ptr_as_string (value docv, value nodev)
CAMLparam2 (docv, nodev);
CAMLlocal1 (strv);
xmlDocPtr doc = Doc_val (docv);
- xmlNodePtr node = (xmlNodePtr) nodev;
+ xmlNodePtr node = (xmlNodePtr)nodev;
char *str;
switch (node->type) {
@@ -291,21 +296,23 @@ v2v_xml_node_ptr_as_string (value docv, value nodev)
case XML_COMMENT_NODE:
case XML_CDATA_SECTION_NODE:
case XML_PI_NODE:
- CAMLreturn (caml_copy_string ((char *) node->content));
+ CAMLreturn (caml_copy_string ((char *)node->content));
case XML_ATTRIBUTE_NODE:
case XML_ELEMENT_NODE:
- str = (char *) xmlNodeListGetString (doc, node->children, 1);
+ str = (char *)xmlNodeListGetString (doc, node->children, 1);
if (str == NULL)
- caml_invalid_argument ("node_as_string: xmlNodeListGetString cannot convert
node to string");
+ caml_invalid_argument ("node_as_string: xmlNodeListGetString cannot "
+ "convert node to string");
strv = caml_copy_string (str);
free (str);
CAMLreturn (strv);
default:
- caml_invalid_argument ("node_as_string: don't know how to convert this node
to a string");
+ caml_invalid_argument (
+ "node_as_string: don't know how to convert this node to a string");
}
}
@@ -313,7 +320,7 @@ value
v2v_xml_node_ptr_set_content (value nodev, value contentv)
{
CAMLparam2 (nodev, contentv);
- xmlNodePtr node = (xmlNodePtr) nodev;
+ xmlNodePtr node = (xmlNodePtr)nodev;
xmlNodeSetContent (node, BAD_CAST String_val (contentv));
@@ -324,29 +331,29 @@ value
v2v_xml_node_ptr_new_text_child (value nodev, value namev, value contentv)
{
CAMLparam3 (nodev, namev, contentv);
- xmlNodePtr node = (xmlNodePtr) nodev;
+ xmlNodePtr node = (xmlNodePtr)nodev;
xmlNodePtr new_node;
- new_node = xmlNewTextChild (node, NULL,
- BAD_CAST String_val (namev),
+ new_node = xmlNewTextChild (node, NULL, BAD_CAST String_val (namev),
BAD_CAST String_val (contentv));
if (new_node == NULL)
- caml_invalid_argument ("node_ptr_new_text_child: failed to create new
node");
+ caml_invalid_argument (
+ "node_ptr_new_text_child: failed to create new node");
/* See comment in v2v_xml_xpathobj_ptr_get_node_ptr about returning
* named xmlNodePtr here.
*/
- CAMLreturn ((value) new_node);
+ CAMLreturn ((value)new_node);
}
value
v2v_xml_node_ptr_set_prop (value nodev, value namev, value valv)
{
CAMLparam3 (nodev, namev, valv);
- xmlNodePtr node = (xmlNodePtr) nodev;
+ xmlNodePtr node = (xmlNodePtr)nodev;
- if (xmlSetProp (node, BAD_CAST String_val (namev), BAD_CAST String_val (valv))
- == NULL)
+ if (xmlSetProp (node, BAD_CAST String_val (namev),
+ BAD_CAST String_val (valv)) == NULL)
caml_invalid_argument ("node_ptr_set_prop: failed to set property");
CAMLreturn (Val_unit);
@@ -356,7 +363,7 @@ value
v2v_xml_node_ptr_unset_prop (value nodev, value namev)
{
CAMLparam2 (nodev, namev);
- xmlNodePtr node = (xmlNodePtr) nodev;
+ xmlNodePtr node = (xmlNodePtr)nodev;
int r;
r = xmlUnsetProp (node, BAD_CAST String_val (namev));
@@ -368,7 +375,7 @@ value
v2v_xml_node_ptr_unlink_node (value nodev)
{
CAMLparam1 (nodev);
- xmlNodePtr node = (xmlNodePtr) nodev;
+ xmlNodePtr node = (xmlNodePtr)nodev;
xmlUnlinkNode (node);
xmlFreeNode (node);
@@ -386,11 +393,11 @@ v2v_xml_doc_get_root_element (value docv)
root = xmlDocGetRootElement (doc);
if (root == NULL)
- CAMLreturn (Val_int (0)); /* None */
+ CAMLreturn (Val_int (0)); /* None */
else {
v = caml_alloc (1, 0);
- Store_field (v, 0, (value) root);
- CAMLreturn (v); /* Some node_ptr */
+ Store_field (v, 0, (value)root);
+ CAMLreturn (v); /* Some node_ptr */
}
}
@@ -413,7 +420,8 @@ v2v_xml_parse_uri (value strv)
ov = caml_alloc (1, 0);
Store_field (ov, 0, sv);
}
- else ov = Val_int (0);
+ else
+ ov = Val_int (0);
Store_field (rv, 0, ov);
/* field 1: uri_opaque : string option */
@@ -422,7 +430,8 @@ v2v_xml_parse_uri (value strv)
ov = caml_alloc (1, 0);
Store_field (ov, 0, sv);
}
- else ov = Val_int (0);
+ else
+ ov = Val_int (0);
Store_field (rv, 1, ov);
/* field 2: uri_authority : string option */
@@ -431,7 +440,8 @@ v2v_xml_parse_uri (value strv)
ov = caml_alloc (1, 0);
Store_field (ov, 0, sv);
}
- else ov = Val_int (0);
+ else
+ ov = Val_int (0);
Store_field (rv, 2, ov);
/* field 3: uri_server : string option */
@@ -440,7 +450,8 @@ v2v_xml_parse_uri (value strv)
ov = caml_alloc (1, 0);
Store_field (ov, 0, sv);
}
- else ov = Val_int (0);
+ else
+ ov = Val_int (0);
Store_field (rv, 3, ov);
/* field 4: uri_user : string option */
@@ -449,7 +460,8 @@ v2v_xml_parse_uri (value strv)
ov = caml_alloc (1, 0);
Store_field (ov, 0, sv);
}
- else ov = Val_int (0);
+ else
+ ov = Val_int (0);
Store_field (rv, 4, ov);
/* field 5: uri_port : int */
@@ -461,7 +473,8 @@ v2v_xml_parse_uri (value strv)
ov = caml_alloc (1, 0);
Store_field (ov, 0, sv);
}
- else ov = Val_int (0);
+ else
+ ov = Val_int (0);
Store_field (rv, 6, ov);
/* field 7: uri_fragment : string option */
@@ -470,7 +483,8 @@ v2v_xml_parse_uri (value strv)
ov = caml_alloc (1, 0);
Store_field (ov, 0, sv);
}
- else ov = Val_int (0);
+ else
+ ov = Val_int (0);
Store_field (rv, 7, ov);
/* field 8: uri_query_raw : string option */
@@ -479,7 +493,8 @@ v2v_xml_parse_uri (value strv)
ov = caml_alloc (1, 0);
Store_field (ov, 0, sv);
}
- else ov = Val_int (0);
+ else
+ ov = Val_int (0);
Store_field (rv, 8, ov);
xmlFreeURI (uri);
--
2.7.4