[PATCH V2] virt-diff: add new virt-diff tool
by Wanlong Gao
add new virt-diff tool
Signed-off-by: Wanlong Gao <gaowanlong(a)cn.fujitsu.com>
---
Hi Rich,
It can work now, please give some comments. ;)
Cheers,
Wanlong Gao
cat/Makefile.am | 20 ++-
cat/virt-diff.c | 525 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
po/POTFILES | 1 +
3 files changed, 545 insertions(+), 1 deletion(-)
create mode 100644 cat/virt-diff.c
diff --git a/cat/Makefile.am b/cat/Makefile.am
index f7c763a..5f6a986 100644
--- a/cat/Makefile.am
+++ b/cat/Makefile.am
@@ -27,7 +27,7 @@ EXTRA_DIST = \
CLEANFILES = stamp-virt-cat.pod stamp-virt-ls.pod stamp-virt-filesystems.pod
-bin_PROGRAMS = virt-cat virt-filesystems virt-ls
+bin_PROGRAMS = virt-cat virt-filesystems virt-ls virt-diff
SHARED_SOURCE_FILES = \
../fish/config.c \
@@ -91,6 +91,24 @@ virt_ls_LDADD = \
$(top_builddir)/src/libguestfs.la \
../gnulib/lib/libgnu.la
+virt_diff_SOURCES = \
+ ../fish/keys.c \
+ virt-diff.c
+
+virt_diff_CFLAGS = \
+ -DGUESTFS_WARN_DEPRECATED=1 \
+ -I$(top_srcdir)/src -I$(top_builddir)/src \
+ -I$(top_srcdir)/fish \
+ -I$(srcdir)/../gnulib/lib -I../gnulib/lib \
+ -DLOCALEBASEDIR=\""$(datadir)/locale"\" \
+ $(WARN_CFLAGS) $(WERROR_CFLAGS) \
+ $(LIBCONFIG_CFLAGS)
+
+virt_diff_LDADD = \
+ $(LIBCONFIG_LIBS) \
+ $(top_builddir)/src/libguestfs.la \
+ ../gnulib/lib/libgnu.la
+
# Manual pages and HTML files for the website.
man_MANS = virt-cat.1 virt-filesystems.1 virt-ls.1
diff --git a/cat/virt-diff.c b/cat/virt-diff.c
new file mode 100644
index 0000000..c2c59a6
--- /dev/null
+++ b/cat/virt-diff.c
@@ -0,0 +1,525 @@
+/* virt-diff
+ * Copyright (C) 2012 Fujitsu Limited.
+ * Copyright (C) 2012 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <termios.h>
+#include <string.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <fcntl.h>
+#include <locale.h>
+#include <assert.h>
+#include <time.h>
+#include <libintl.h>
+#include <sys/wait.h>
+
+#include "c-ctype.h"
+
+#include "human.h"
+#include "progname.h"
+
+#include "guestfs.h"
+#include "options.h"
+
+#ifndef O_CLOEXEC
+#define O_CLOEXEC 0
+#endif
+
+int keys_from_stdin = 0;
+int echo_keys = 0;
+/* libguestfs handle for seed. */
+static guestfs_h *sg;
+
+/* libguestfs handle for temp. */
+static guestfs_h *dg;
+
+const char *libvirt_uri = NULL;
+
+static inline char *
+diff_bad_case (char const *s)
+{
+ return (char *) s;
+}
+
+static void __attribute__((noreturn))
+diff_usage (int status)
+{
+ if (status != EXIT_SUCCESS) {
+ fprintf (stderr, _("Try `%s --help' for more information.\n"),
+ program_name);
+ } else {
+ fprintf (stdout,
+ _("%s: Show the differences between seed Guest and the others\n"
+ "Copyright (C) 2012 Fujitsu Limited.\n"
+ "Copyright (C) 2012 Red Hat Inc.\n"
+ "Usage:\n"
+ " %s [--options] -s domname -d domname path\n"
+ "Options:\n"
+ " -c|--connect uri Specify libvirt URI for -s and -d options\n"
+ " -s|--seed guest Add seed disk from libvirt guest\n"
+ " -d|--domain guest Add target disk from libvirt guest\n"
+ " --keys-from-stdin Read passphrases from stdin\n"
+ " --echo-keys Don't turn off echo for passphrases\n"
+ " --help Display brief help\n"),
+ program_name, program_name);
+ }
+ exit (status);
+}
+
+/* Make a LUKS map name from the partition name,
+ * eg "/dev/vda2" => "luksvda2"
+ */
+static void
+diff_make_mapname (const char *device, char *mapname, size_t len)
+{
+ size_t i = 0;
+
+ if (len < 5)
+ abort ();
+ strcpy (mapname, "luks");
+ mapname += 4;
+ len -= 4;
+
+ if (STRPREFIX (device, "/dev/"))
+ i = 5;
+
+ for (; device[i] != '\0' && len >= 1; ++i) {
+ if (c_isalnum (device[i])) {
+ *mapname++ = device[i];
+ len--;
+ }
+ }
+
+ *mapname = '\0';
+}
+
+static void
+free_strings (char **strings)
+{
+ size_t i;
+
+ for (i = 0; strings[i] != NULL; ++i)
+ free (strings[i]);
+ free (strings);
+}
+
+static size_t
+count_strings (char **strings)
+{
+ size_t i;
+
+ for (i = 0; strings[i] != NULL; ++i)
+ ;
+ return i;
+}
+
+/* Simple implementation of decryption: look for any crypto_LUKS
+ * partitions and decrypt them, then rescan for VGs. This only works
+ * for Fedora whole-disk encryption. WIP to make this work for other
+ * encryption schemes.
+ */
+static void
+diff_inspect_do_decrypt (guestfs_h *g)
+{
+ char **partitions = guestfs_list_partitions (g);
+ if (partitions == NULL)
+ exit (EXIT_FAILURE);
+
+ int need_rescan = 0;
+ size_t i;
+ for (i = 0; partitions[i] != NULL; ++i) {
+ char *type = guestfs_vfs_type (g, partitions[i]);
+ if (type && STREQ (type, "crypto_LUKS")) {
+ char mapname[32];
+ diff_make_mapname (partitions[i], mapname, sizeof mapname);
+
+ char *key = read_key (partitions[i]);
+ /* XXX Should we call guestfs_luks_open_ro if readonly flag
+ * is set? This might break 'mount_ro'.
+ */
+ if (guestfs_luks_open (g, partitions[i], key, mapname) == -1)
+ exit (EXIT_FAILURE);
+
+ free (key);
+
+ need_rescan = 1;
+ }
+ free (type);
+ }
+
+ free_strings (partitions);
+
+ if (need_rescan) {
+ if (guestfs_vgscan (g) == -1)
+ exit (EXIT_FAILURE);
+ if (guestfs_vg_activate_all (g, 1) == -1)
+ exit (EXIT_FAILURE);
+ }
+}
+
+static int
+compare_keys (const void *p1, const void *p2)
+{
+ const char *key1 = * (char * const *) p1;
+ const char *key2 = * (char * const *) p2;
+
+ return strcmp (key1, key2);
+}
+
+static int
+compare_keys_len (const void *p1, const void *p2)
+{
+ const char *key1 = * (char * const *) p1;
+ const char *key2 = * (char * const *) p2;
+ int c;
+
+ c = strlen (key1) - strlen (key2);
+ if (c != 0)
+ return c;
+
+ return compare_keys (p1, p2);
+}
+
+static void
+diff_inspect_mount_root (guestfs_h *g, const char *root)
+{
+ char **mountpoints = guestfs_inspect_get_mountpoints (g, root);
+ if (mountpoints == NULL)
+ exit (EXIT_FAILURE);
+
+ /* Sort by key length, shortest key first, so that we end up
+ * mounting the filesystems in the correct order.
+ */
+ qsort (mountpoints, count_strings (mountpoints) / 2, 2 * sizeof (char *),
+ compare_keys_len);
+
+ size_t i;
+ size_t mount_errors = 0;
+ for (i = 0; mountpoints[i] != NULL; i += 2) {
+ int r;
+ 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.
+ */
+ if (STREQ (mountpoints[i], "/"))
+ exit (EXIT_FAILURE);
+ mount_errors++;
+ }
+ }
+
+ free_strings (mountpoints);
+
+ if (mount_errors)
+ fprintf (stderr, _("%s: some filesystems could not be mounted (ignored)\n"),
+ program_name);
+}
+
+/* This function implements the -i option. */
+static void
+diff_inspect_mount (guestfs_h *g)
+{
+ const char *root = NULL;
+ diff_inspect_do_decrypt (g);
+
+ char **roots = guestfs_inspect_os (g);
+ if (roots == NULL)
+ 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"),
+ program_name);
+ free_strings (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"),
+ program_name);
+ free_strings (roots);
+ exit (EXIT_FAILURE);
+ }
+
+ root = roots[0];
+ free (roots);
+
+ diff_inspect_mount_root (g, root);
+}
+
+static void
+free_drive (struct drv *drv)
+{
+ if (!drv) return;
+
+ free (drv->device);
+ free (drv);
+}
+
+int
+main (int argc, char *argv[])
+{
+ /* set global program name that is not polluted with libtool artifacts. */
+ set_program_name (argv[0]);
+ bindtextdomain (PACKAGE, LOCALEBASEDIR);
+ textdomain (PACKAGE);
+
+ enum { HELP_OPTION = CHAR_MAX + 1 };
+
+ static const char *options = "s:d:";
+ static const struct option long_options[] = {
+ {"seed", 1, 0, 's'},
+ {"domain", 1, 0, 'd'},
+ {"help", 0, 0, HELP_OPTION},
+ {0, 0, 0, 0}
+ };
+
+ struct drv *sdrv = NULL;
+ struct drv *ddrv = NULL;
+ int c, nr;
+ int option_index;
+ int spid, dpid;
+
+ sg = guestfs_create ();
+ if (sg == NULL) {
+ fprintf (stderr, _("guestfs_create: failed to create seed handle\n"));
+ exit (EXIT_FAILURE);
+ }
+
+ dg = guestfs_create ();
+ if (dg == NULL) {
+ fprintf (stderr, _("guestfs_create: failed to create comparison handle\n"));
+ exit (EXIT_FAILURE);
+ }
+
+ argv[0] = diff_bad_case (program_name);
+
+ for (;;) {
+ c = getopt_long (argc, argv, options, long_options, &option_index);
+ if (c == -1) break;
+
+ switch (c) {
+ case 0:
+ if (STREQ (long_options[option_index].name, "keys-from-stdin")) {
+ keys_from_stdin = 1;
+ } else if (STREQ (long_options[option_index].name, "echo-keys")) {
+ echo_keys = 1;
+ } else if (STREQ (long_options[option_index].name, "seed")) {
+ if (sdrv) {
+ fprintf(stderr, _("Only one seed device"));
+ exit (EXIT_FAILURE);
+ }
+ sdrv = calloc (1, sizeof (struct drv));
+ if (!sdrv) {
+ perror ("malloc");
+ exit (EXIT_FAILURE);
+ }
+ sdrv->type = drv_d;
+ sdrv->nr_drives = -1;
+ sdrv->d.guest = optarg;
+ sdrv->next = NULL;
+ } else if (STREQ (long_options[option_index].name, "domain")) {
+ if (ddrv) {
+ fprintf (stderr, _("Only one diff device"));
+ exit (EXIT_FAILURE);
+ }
+ ddrv = calloc (1, sizeof (struct drv));
+ if (!ddrv) {
+ perror ("malloc");
+ exit (EXIT_FAILURE);
+ }
+ ddrv->type = drv_d;
+ ddrv->nr_drives = -1;
+ ddrv->d.guest = optarg;
+ ddrv->next = NULL;
+ } else {
+ fprintf (stderr, _("%s: unknown long option: %s (%d)\n"),
+ program_name, long_options[option_index].name, option_index);
+ exit (EXIT_FAILURE);
+ }
+ break;
+
+ case 'c':
+ libvirt_uri = optarg;
+
+ case 's':
+ if (sdrv) {
+ fprintf(stderr, _("Only one seed device"));
+ exit (EXIT_FAILURE);
+ }
+ sdrv = calloc (1, sizeof (struct drv));
+ if (!sdrv) {
+ perror ("malloc");
+ exit (EXIT_FAILURE);
+ }
+ sdrv->type = drv_d;
+ sdrv->nr_drives = -1;
+ sdrv->d.guest = optarg;
+ sdrv->next = NULL;
+ break;
+
+ case 'd':
+ if (ddrv) {
+ fprintf (stderr, _("Only one diff device"));
+ exit (EXIT_FAILURE);
+ }
+ ddrv = calloc (1, sizeof (struct drv));
+ if (!ddrv) {
+ perror ("malloc");
+ exit (EXIT_FAILURE);
+ }
+ ddrv->type = drv_d;
+ ddrv->nr_drives = -1;
+ ddrv->d.guest = optarg;
+ ddrv->next = NULL;
+ break;
+
+ case HELP_OPTION:
+ diff_usage (EXIT_SUCCESS);
+
+ default:
+ diff_usage (EXIT_FAILURE);
+ }
+ }
+
+ if (sdrv == NULL)
+ diff_usage (EXIT_FAILURE);
+ if (ddrv == NULL)
+ diff_usage (EXIT_FAILURE);
+
+ struct guestfs_add_domain_argv optargs = {
+ .bitmask = 0,
+ .libvirturi = libvirt_uri,
+ .readonly = 1,
+ .allowuuid = 1,
+ .readonlydisk = "read",
+ };
+ nr = guestfs_add_domain_argv (sg, sdrv->d.guest, &optargs);
+ if (nr == -1)
+ exit (EXIT_FAILURE);
+ sdrv->nr_drives = nr;
+ nr = guestfs_add_domain_argv (dg, ddrv->d.guest, &optargs);
+ if (nr == -1)
+ exit (EXIT_FAILURE);
+ ddrv->nr_drives = nr;
+
+ if (guestfs_launch (sg) == -1)
+ exit (EXIT_FAILURE);
+ if (guestfs_launch (dg) == -1)
+ exit (EXIT_FAILURE);
+
+ diff_inspect_mount (sg);
+ diff_inspect_mount (dg);
+
+ char stempdir[] = "/tmp/sGuestXXXXXX";
+ char dtempdir[] = "/tmp/dGuestXXXXXX";
+
+ if (mkdtemp (stempdir) == NULL) {
+ perror ("mkdtemp");
+ exit (EXIT_FAILURE);
+ }
+ if (mkdtemp (dtempdir) == NULL) {
+ perror ("mkdtemp");
+ exit (EXIT_FAILURE);
+ }
+
+ if (guestfs_mount_local (sg, stempdir, -1) == -1)
+ exit (EXIT_FAILURE);
+ if (guestfs_mount_local (dg, dtempdir, -1) == -1)
+ exit (EXIT_FAILURE);
+
+ spid = fork ();
+ if (spid == -1) {
+ perror ("fork");
+ exit (EXIT_FAILURE);
+ }
+ if (spid == 0) {
+ if (guestfs_mount_local_run (sg) == -1)
+ exit (EXIT_FAILURE);
+ _exit (EXIT_SUCCESS);
+ }
+
+ dpid = fork();
+ if (dpid == -1) {
+ perror ("fork");
+ exit (EXIT_FAILURE);
+ }
+ if (dpid == 0) {
+ if (guestfs_mount_local_run (dg) == -1)
+ exit (EXIT_FAILURE);
+ _exit (EXIT_SUCCESS);
+ }
+
+ const char *dir = argv[optind];
+ char system_arg[BUFSIZ];
+ sprintf (system_arg, "diff -urN %s%s %s%s", stempdir, dir,
+ dtempdir, dir);
+ sleep (5);
+ if (system (system_arg) == -1)
+ exit (EXIT_FAILURE);
+
+ guestfs_umount_local (sg, GUESTFS_UMOUNT_LOCAL_RETRY, 1, -1);
+ waitpid (spid, NULL, 0);
+ guestfs_umount_local (dg, GUESTFS_UMOUNT_LOCAL_RETRY, 1, -1);
+ waitpid (dpid, NULL, 0);
+
+ if (guestfs_shutdown (sg) == -1)
+ exit (EXIT_FAILURE);
+ if (guestfs_shutdown (dg) == -1)
+ exit (EXIT_FAILURE);
+
+ free_drive (sdrv);
+ free_drive (ddrv);
+
+ guestfs_close (sg);
+ guestfs_close (dg);
+
+ exit (EXIT_SUCCESS);
+}
diff --git a/po/POTFILES b/po/POTFILES
index dffa899..3f51648 100644
--- a/po/POTFILES
+++ b/po/POTFILES
@@ -1,6 +1,7 @@
align/domains.c
align/scan.c
cat/virt-cat.c
+cat/virt-diff.c
cat/virt-filesystems.c
cat/virt-ls.c
daemon/9p.c
--
1.7.12.rc1
11 years, 10 months
Fwd: hivex: patch for read support of "li"-records from "ri" intermediate
by Richard W.M. Jones
[The bug which this fixes is:
https://bugzilla.redhat.com/show_bug.cgi?id=717583 ]
----- Forwarded message from Peter Fokker <peter(a)berestijn.nl> -----
Date: Thu, 8 Mar 2012 11:37:06 +0100 (CET)
From: Peter Fokker <peter(a)berestijn.nl>
To: rjones(a)redhat.com
Cc: Peter Fokker <peter(a)berestijn.nl>
Subject: hivex: patch for read support of "li"-records from "ri"
intermediate
User-Agent: SquirrelMail/1.4.9a
Richard,
Thank you for creating the hivex-library. Studying your source code helped
me a great deal to better understand the internals of the Windows Registry.
However, while I was browsing a real-world SOFTWARE-hive (XP, SP3) I
could not browse to the '\Classes' key. Instead I got this (debug)-message:
get_children: returning ENOTSUP because ri-record offset does not
point to lf/lh (0x49020)
I tracked this issue down and I discovered that the intermediate
"ri"-record may not only contain offsets to "lf" and "lh" but to
"li"-records too.
Attached is a patch against hivex.c v1.3.3 that recognises
"li"-records referenced from "ri"-records. For me this fixed the issue
with browsing the '\Classes' key.
Note that I have not fixed the related problem of rewriting
"li"-records when inserting a new subkey or deleting an
existing one. This sure would cause problems when I were to
add/delete a subkey to/from '\Classes'.
I would very much appreciate it if would be so kind to take a look at
my patch, allthough I cannot blame you if you immediately dump this
unsollicited message+patch from some random stranger from The Netherlands.
Kind regards,
--Peter Fokker
--
Peter Fokker <peter(a)berestijn.nl>
Ingenieursbureau PSD +31 35 695 29 99 / +31 644 238 568
Stargardlaan 7 1404 BC Bussum, The Netherlands
----- End forwarded message -----
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
libguestfs lets you edit virtual machines. Supports shell scripting,
bindings from many languages. http://libguestfs.org
11 years, 11 months
[PATCH V1] NEW API:ext:mke2fs
by Wanlong Gao
New api mke2fs for full configuration of filesystem.
Signed-off-by: Wanlong Gao <gaowanlong(a)cn.fujitsu.com>
---
daemon/ext2.c | 452 +++++++++++++++++++++++++++++++++++++++++
generator/generator_actions.ml | 18 ++
gobject/Makefile.inc | 6 +-
src/MAX_PROC_NR | 2 +-
4 files changed, 475 insertions(+), 3 deletions(-)
diff --git a/daemon/ext2.c b/daemon/ext2.c
index 40b36d2..ee87d05 100644
--- a/daemon/ext2.c
+++ b/daemon/ext2.c
@@ -811,3 +811,455 @@ do_set_e2generation (const char *filename, int64_t generation)
return 0;
}
+
+int
+do_mke2fs (const char *device,
+ int checkbadblock, const char *badblockfile,
+ int64_t blocksize, int directwrite,
+ int64_t fragsize, int forcecreate,
+ int64_t blockspergroup, int64_t numberofgroups,
+ int64_t bytesperinode, int64_t inodesize,
+ int withjournal, int64_t journalsize,
+ const char *journaldevice, const char *newvolumelabel,
+ int reservedblockspercentage, const char *lastmounteddir,
+ int64_t numberofinodes, const char *creatoros,
+ int writesbandgrouponly,
+ const char *fstype, const char *usagetype,
+ const char *fsuuid, int mmpupdateinterval,
+ int64_t stridesize, int64_t stripewidth,
+ int64_t maxonlineresize, int lazyitableinit,
+ int lazyjournalinit, int testfs,
+ int discard, int quotatype,
+ int dirindex, int extent, int filetype,
+ int flexbg, int hasjournal, int journaldev,
+ int largefile, int quota, int resizeinode,
+ int sparsesuper, int uninitbg,
+ int64_t blockscount)
+{
+ int r;
+ char *err = NULL;
+ const char *argv[MAX_ARGS];
+ char blocksize_s[64];
+ char fragsize_s[64];
+ char blockspergroup_s[64];
+ char numberofgroups_s[64];
+ char bytesperinode_s[64];
+ char inodesize_s[64];
+ char journalsize_s[64];
+ char journaldevice_s[256];
+ char reservedblockspercentage_s[64];
+ char numberofinodes_s[64];
+ char mmpupdateinterval_s[84];
+ char stridesize_s[74];
+ char stripewidth_s[84];
+ char maxonlineresize_s[74];
+ char blockscount_s[64];
+ size_t i = 0;
+ int feature = 0;
+ char features[256];
+
+ ADD_ARG (argv, i, str_mke2fs);
+
+ if (optargs_bitmask & GUESTFS_MKE2FS_CHECKBADBLOCK_BITMASK) {
+ if (checkbadblock)
+ ADD_ARG (argv, i, "-c");
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_BADBLOCKFILE_BITMASK) {
+ if (badblockfile) {
+ ADD_ARG (argv, i, "-l");
+ ADD_ARG (argv, i, badblockfile);
+ }
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSIZE_BITMASK) {
+ if (blocksize < 0) {
+ reply_with_error ("blocksize must be >= 0");
+ goto error;
+ }
+ snprintf (blocksize_s, sizeof blocksize_s, "%" PRIi64, blocksize);
+ ADD_ARG (argv, i, "-b");
+ ADD_ARG (argv, i, blocksize_s);
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_DIRECTWRITE_BITMASK) {
+ if (directwrite)
+ ADD_ARG (argv, i, "-D");
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_FRAGSIZE_BITMASK) {
+ if (fragsize < 0) {
+ reply_with_error ("fragsize must be >= 0");
+ goto error;
+ }
+ snprintf (fragsize_s, sizeof fragsize_s, "%" PRIi64, fragsize);
+ ADD_ARG (argv, i, "-f");
+ ADD_ARG (argv, i, fragsize_s);
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_FORCECREATE_BITMASK) {
+ if (forcecreate)
+ ADD_ARG (argv, i, "-F");
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSPERGROUP_BITMASK) {
+ if (blockspergroup < 0) {
+ reply_with_error ("blockspergroup must be >= 0");
+ goto error;
+ }
+ snprintf (blockspergroup_s, sizeof blockspergroup_s,
+ "%" PRIi64, blockspergroup);
+ ADD_ARG (argv, i, "-g");
+ ADD_ARG (argv, i, blockspergroup_s);
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_NUMBEROFGROUPS_BITMASK) {
+ if (numberofgroups < 0) {
+ reply_with_error ("numberofgroups must be >= 0");
+ goto error;
+ }
+ snprintf (numberofgroups_s, sizeof numberofgroups_s,
+ "%" PRIi64, numberofgroups);
+ ADD_ARG (argv, i, "-G");
+ ADD_ARG (argv, i, numberofgroups_s);
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_BYTESPERINODE_BITMASK) {
+ if (bytesperinode < 0) {
+ reply_with_error ("bytesperinode must be >= 0");
+ goto error;
+ }
+ snprintf (bytesperinode_s, sizeof bytesperinode_s, "%" PRIi64, bytesperinode);
+ ADD_ARG (argv, i, "-i");
+ ADD_ARG (argv, i, bytesperinode_s);
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_INODESIZE_BITMASK) {
+ if (inodesize < 0) {
+ reply_with_error ("inodesize must be >= 0");
+ goto error;
+ }
+ snprintf (inodesize_s, sizeof inodesize_s, "%" PRIi64, inodesize);
+ ADD_ARG (argv, i, "-I");
+ ADD_ARG (argv, i, inodesize_s);
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_WITHJOURNAL_BITMASK) {
+ if (withjournal)
+ ADD_ARG (argv, i, "-j");
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALSIZE_BITMASK) {
+ if (journalsize < 0) {
+ reply_with_error ("journalsize must be >= 0");
+ goto error;
+ }
+ snprintf (journalsize_s, sizeof journalsize_s,
+ "size=" "%" PRIi64, journalsize);
+ ADD_ARG (argv, i, "-J");
+ ADD_ARG (argv, i, journalsize_s);
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALDEVICE_BITMASK) {
+ if (journaldevice) {
+ snprintf (journaldevice_s, sizeof journaldevice_s,
+ "device=%s", journaldevice);
+ ADD_ARG (argv, i, "-J");
+ ADD_ARG (argv, i, journaldevice_s);
+ }
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_NEWVOLUMELABEL_BITMASK) {
+ if (newvolumelabel) {
+ ADD_ARG (argv, i, "-L");
+ ADD_ARG (argv, i, newvolumelabel);
+ }
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_RESERVEDBLOCKSPERCENTAGE_BITMASK) {
+ if (reservedblockspercentage < 0) {
+ reply_with_error ("reservedblockspercentage must be >= 0");
+ goto error;
+ }
+ snprintf (reservedblockspercentage_s, sizeof reservedblockspercentage_s,
+ "%" PRIi32, reservedblockspercentage);
+ ADD_ARG (argv, i, "-m");
+ ADD_ARG (argv, i, reservedblockspercentage_s);
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_LASTMOUNTEDDIR_BITMASK) {
+ if (lastmounteddir) {
+ ADD_ARG (argv, i, "-M");
+ ADD_ARG (argv, i, lastmounteddir);
+ }
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_NUMBEROFINODES_BITMASK) {
+ if (numberofinodes < 0) {
+ reply_with_error ("numberofinodes must be >= 0");
+ goto error;
+ }
+ snprintf (numberofinodes_s, sizeof numberofinodes_s,
+ "%" PRIi64, numberofinodes);
+ ADD_ARG (argv, i, "-N");
+ ADD_ARG (argv, i, numberofinodes_s);
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_CREATOROS_BITMASK) {
+ if (creatoros) {
+ ADD_ARG (argv, i, "-o");
+ ADD_ARG (argv, i, creatoros);
+ }
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_WRITESBANDGROUPONLY_BITMASK) {
+ if (writesbandgrouponly)
+ ADD_ARG (argv, i, "-S");
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_FSTYPE_BITMASK) {
+ if (fstype) {
+ ADD_ARG (argv, i, "-t");
+ ADD_ARG (argv, i, fstype);
+ }
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_USAGETYPE_BITMASK) {
+ if (usagetype) {
+ ADD_ARG (argv, i, "-T");
+ ADD_ARG (argv, i, usagetype);
+ }
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_FSUUID_BITMASK) {
+ if (fsuuid) {
+ ADD_ARG (argv, i, "-U");
+ ADD_ARG (argv, i, fsuuid);
+ }
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_MMPUPDATEINTERVAL_BITMASK) {
+ if (mmpupdateinterval < 0) {
+ reply_with_error ("mmpupdateinterval must be >= 0");
+ goto error;
+ }
+ snprintf (mmpupdateinterval_s, sizeof mmpupdateinterval_s,
+ "mmp_update_interval=" "%" PRIi32, mmpupdateinterval);
+ ADD_ARG (argv, i, "-E");
+ ADD_ARG (argv, i, mmpupdateinterval_s);
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_STRIDESIZE_BITMASK) {
+ if (stridesize < 0) {
+ reply_with_error ("stridesize must be >= 0");
+ goto error;
+ }
+ 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) {
+ reply_with_error ("stripewidth must be >= 0");
+ goto error;
+ }
+ snprintf (stripewidth_s, sizeof stripewidth_s,
+ "stripe_width=" "%" PRIi64, stripewidth);
+ ADD_ARG (argv, i, "-E");
+ ADD_ARG (argv, i, stripewidth_s);
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_MAXONLINERESIZE_BITMASK) {
+ if (maxonlineresize < 0) {
+ reply_with_error ("maxonlineresize must be >= 0");
+ goto error;
+ }
+ snprintf (maxonlineresize_s, sizeof maxonlineresize_s,
+ "resize=" "%" PRIi64, maxonlineresize);
+ ADD_ARG (argv, i, "-E");
+ ADD_ARG (argv, i, maxonlineresize_s);
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_LAZYITABLEINIT_BITMASK) {
+ ADD_ARG (argv, i, "-E");
+ if (lazyitableinit)
+ ADD_ARG (argv, i, "lazy_itable_init=1");
+ else
+ ADD_ARG (argv, i, "lazy_itable_init=0");
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_LAZYJOURNALINIT_BITMASK) {
+ ADD_ARG (argv, i, "-E");
+ if (lazyjournalinit)
+ ADD_ARG (argv, i, "lazy_journal_init=1");
+ else
+ ADD_ARG (argv, i, "lazy_journal_init=0");
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_TESTFS_BITMASK) {
+ if (testfs) {
+ ADD_ARG (argv, i, "-E");
+ ADD_ARG (argv, i, "test_fs");
+ }
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_DISCARD_BITMASK) {
+ ADD_ARG (argv, i, "-E");
+ if (discard)
+ ADD_ARG (argv, i, "discard");
+ else
+ ADD_ARG (argv, i, "nodiscard");
+ }
+
+ if (optargs_bitmask & GUESTFS_MKE2FS_DIRINDEX_BITMASK) {
+ if (dirindex)
+ strncat (features, "dir_index", 9);
+ else
+ strncat (features, "^dir_index", 10);
+ feature++;
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_EXTENT_BITMASK) {
+ if (feature == 0) {
+ if (extent)
+ strncat (features, "extent", 6);
+ else
+ strncat (features, "^extent", 7);
+ feature++;
+ } else {
+ if (extent)
+ strncat (features, ",extent", 7);
+ else
+ strncat (features, ",^extent", 8);
+ }
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_FILETYPE_BITMASK) {
+ if (feature == 0) {
+ if (filetype)
+ strncat (features, "filetype", 8);
+ else
+ strncat (features, "^filetype", 9);
+ feature++;
+ } else {
+ if (filetype)
+ strncat (features, ",filetype", 9);
+ else
+ strncat (features, ",^filetype", 10);
+ }
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_FLEXBG_BITMASK) {
+ if (feature == 0) {
+ if (flexbg)
+ strncat (features, "flex_bg", 7);
+ else
+ strncat (features, "^flex_bg", 8);
+ feature++;
+ } else {
+ if (flexbg)
+ strncat (features, ",flex_bg", 8);
+ else
+ strncat (features, ",^flex_bg", 9);
+ }
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_HASJOURNAL_BITMASK) {
+ if (feature == 0) {
+ if (hasjournal)
+ strncat (features, "has_journal", 11);
+ else
+ strncat (features, "^has_journal", 12);
+ feature++;
+ } else {
+ if (hasjournal)
+ strncat (features, ",has_journal", 12);
+ else
+ strncat (features, ",^has_journal", 13);
+ }
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALDEV_BITMASK) {
+ if (feature == 0) {
+ if (journaldev)
+ strncat (features, "journal_dev", 11);
+ else
+ strncat (features, "^journal_dev", 12);
+ feature++;
+ } else {
+ if (journaldev)
+ strncat (features, ",journal_dev", 12);
+ else
+ strncat (features, ",^journal_dev", 13);
+ }
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_LARGEFILE_BITMASK) {
+ if (feature == 0) {
+ if (largefile)
+ strncat (features, "large_file", 10);
+ else
+ strncat (features, "^large_file", 11);
+ feature++;
+ } else {
+ if (largefile)
+ strncat (features, ",large_file", 11);
+ else
+ strncat (features, ",^large_file", 12);
+ }
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_QUOTA_BITMASK) {
+ if (feature == 0) {
+ if (quota)
+ strncat (features, "quota", 5);
+ else
+ strncat (features, "^quota", 6);
+ feature++;
+ } else {
+ if (quota)
+ strncat (features, ",quota", 6);
+ else
+ strncat (features, ",^quota", 7);
+ }
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_RESIZEINODE_BITMASK) {
+ if (feature == 0) {
+ if (resizeinode)
+ strncat (features, "resize_inode", 12);
+ else
+ strncat (features, "^resize_inode", 13);
+ feature++;
+ } else {
+ if (resizeinode)
+ strncat (features, ",resize_inode", 13);
+ else
+ strncat (features, ",^resize_inode", 14);
+ }
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_SPARSESUPER_BITMASK) {
+ if (feature == 0) {
+ if (sparsesuper)
+ strncat (features, "sparse_super", 12);
+ else
+ strncat (features, "^sparse_super", 13);
+ feature++;
+ } else {
+ if (sparsesuper)
+ strncat (features, ",sparse_super", 13);
+ else
+ strncat (features, ",^sparse_super", 14);
+ }
+ }
+ if (optargs_bitmask & GUESTFS_MKE2FS_UNINITBG_BITMASK) {
+ if (feature == 0) {
+ if (uninitbg)
+ strncat (features, "uninit_bg", 9);
+ else
+ strncat (features, "^uninit_bg", 10);
+ feature++;
+ } else {
+ if (uninitbg)
+ strncat (features, ",uninit_bg", 10);
+ else
+ strncat (features, ",^uninit_bg", 11);
+ }
+ }
+
+ if (feature != 0) {
+ ADD_ARG (argv, i, "-O");
+ ADD_ARG (argv, i, features);
+ }
+
+ ADD_ARG (argv, i, device);
+
+ if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSCOUNT_BITMASK) {
+ if (blockscount < 0) {
+ reply_with_error ("blockscount must be >= 0");
+ goto error;
+ }
+ snprintf (blockscount_s, sizeof blockscount_s, "%" PRIi64, blockscount);
+ ADD_ARG (argv, i, blockscount_s);
+ }
+
+ ADD_ARG (argv, i, NULL);
+
+ r = commandv (NULL, &err, argv);
+ if (r == -1) {
+ reply_with_error ("%s: %s", device, err);
+ goto error;
+ }
+
+ free (err);
+ return 0;
+
+error:
+ if (err) free (err);
+ return -1;
+}
diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml
index 0033e3a..2c71263 100644
--- a/generator/generator_actions.ml
+++ b/generator/generator_actions.ml
@@ -9710,6 +9710,24 @@ the resulting filesystem may be inconsistent or corrupt.
The returned status indicates whether filesystem corruption was
detected (returns C<1>) or was not detected (returns C<0>)." };
+ { defaults with
+ name = "mke2fs";
+ style = RErr, [Device "device"], [OBool "checkbadblock"; OString "badblockfile"; OInt64 "blocksize"; OBool "directwrite"; OInt64 "fragsize"; OBool "forcecreate"; OInt64 "blockspergroup"; OInt64 "numberofgroups"; OInt64 "bytesperinode"; OInt64 "inodesize"; OBool "withjournal"; OInt64 "journalsize"; OString "journaldevice"; OString "newvolumelabel"; OInt "reservedblockspercentage"; OString "lastmounteddir"; OInt64 "numberofinodes"; OString "creatoros"; OBool "writesbandgrouponly"; OString "fstype"; OString "usagetype"; OString "fsuuid"; OInt "mmpupdateinterval"; OInt64 "stridesize"; OInt64 "stripewidth"; OInt64 "maxonlineresize"; OBool "lazyitableinit"; OBool "lazyjournalinit"; OBool "testfs"; OBool "discard"; OBool "quotatype"; OBool "dirindex"; OBool "extent"; OBool "filetype"; OBool "flexbg"; OBool "hasjournal"; OBool "journaldev"; OBool "largefile"; OBool "quota"; OBool "resizeinode"; OBool "sparsesuper"; OBool "uninitbg"; OInt64 "blockscount"];
+ proc_nr = Some 367;
+ tests = [
+ InitEmpty, IfAvailable "ext2", TestRun (
+ [["part_disk"; "/dev/sda"; "mbr"];
+ ["mke2fs"; "/dev/sda1"; ""; "NOARG"; ""; ""; ""; ""; ""; ""; ""; ""; "true"; ""; "NOARG"; "NOARG"; ""; "NOARG"; ""; "NOARG"; ""; "ext4"; "NOARG"; "NOARG"; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""];
+ ])
+ ];
+ shortdesc = "create an ext2/ext3/ext4 filesystem on C<device>";
+ longdesc = "\
+C<mke2fs> is used to create an ext2, ext3, or ext4 filesystem,
+usually in a disk partition. C<device> is the special file corresponding
+to the device (e.g /dev/sdXX). C<blockscount> is the number of blocks
+on C<device>. If omitted, C<mke2fs> automagically figures the file system
+size." };
+
]
(* Non-API meta-commands available only in guestfish.
diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc
index ba41b48..de8e1e7 100644
--- a/gobject/Makefile.inc
+++ b/gobject/Makefile.inc
@@ -78,7 +78,8 @@ guestfs_gobject_headers= \
include/guestfs-gobject/optargs-rsync_out.h \
include/guestfs-gobject/optargs-xfs_admin.h \
include/guestfs-gobject/optargs-hivex_open.h \
- include/guestfs-gobject/optargs-xfs_repair.h
+ include/guestfs-gobject/optargs-xfs_repair.h \
+ include/guestfs-gobject/optargs-mke2fs.h
guestfs_gobject_sources= \
src/session.c \
@@ -138,4 +139,5 @@ guestfs_gobject_sources= \
src/optargs-rsync_out.c \
src/optargs-xfs_admin.c \
src/optargs-hivex_open.c \
- src/optargs-xfs_repair.c
+ src/optargs-xfs_repair.c \
+ src/optargs-mke2fs.c
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index 4203007..526204c 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-366
+367
--
1.7.12
11 years, 11 months
[PATCH] collect list of called external commands
by Olaf Hering
guestfsd calls many different tools. Keeping track of all of them is
error prone. This patch introduces a new helper macro to put the command
string into its own ELF section:
GUESTFS_EXT_CMD(C_variable, command_name);
This syntax makes it still possible to grep for used command names.
The actual usage of the collected list could be like this:
objcopy -j .guestfs_ext_cmds -O binary daemon/guestfsd /dev/stdout | strings | sort -u
The resulting output will be used to tell mkinitrd which programs to
copy into the initrd.
Signed-off-by: Olaf Hering <olaf(a)aepfle.de>
---
contrib/intro/libguestfs-intro.html | 3 +-
daemon/9p.c | 3 +-
daemon/available.c | 7 ++-
daemon/base64.c | 6 ++-
daemon/blkid.c | 10 +++--
daemon/blockdev.c | 4 +-
daemon/btrfs.c | 33 ++++++++------
daemon/checksum.c | 6 ++-
daemon/cmp.c | 4 +-
daemon/command.c | 15 ++++---
daemon/compress.c | 24 ++++++----
daemon/cpmv.c | 9 ++--
daemon/daemon.h | 5 ++-
daemon/dd.c | 4 +-
daemon/debug.c | 35 ++++++++++-----
daemon/df.c | 6 ++-
daemon/dir.c | 4 +-
daemon/dmesg.c | 4 +-
daemon/du.c | 4 +-
daemon/ext2.c | 90 +++++++++++++++++--------------------
daemon/file.c | 10 +++--
daemon/find.c | 4 +-
daemon/findfs.c | 4 +-
daemon/fsck.c | 4 +-
daemon/fstrim.c | 6 ++-
daemon/grub.c | 6 ++-
daemon/guestfsd.c | 7 ++-
daemon/initrd.c | 5 ++-
daemon/inotify.c | 4 +-
daemon/isoinfo.c | 4 +-
daemon/labels.c | 10 +++--
daemon/link.c | 6 ++-
daemon/ls.c | 6 ++-
daemon/luks.c | 14 +++---
daemon/lvm-filter.c | 13 ++++--
daemon/lvm.c | 64 +++++++++++++-------------
daemon/md.c | 10 +++--
daemon/mkfs.c | 10 +++--
daemon/modprobe.c | 6 ++-
daemon/mount.c | 13 +++---
daemon/ntfs.c | 14 +++---
daemon/ntfsclone.c | 9 ++--
daemon/parted.c | 25 ++++++-----
daemon/rsync.c | 6 ++-
daemon/scrub.c | 10 +++--
daemon/sfdisk.c | 9 ++--
daemon/swap.c | 26 ++++++-----
daemon/tar.c | 8 +++-
daemon/xfs.c | 13 ++++--
daemon/zero.c | 6 ++-
daemon/zerofree.c | 6 ++-
51 Dateien geändert, 375 Zeilen hinzugefügt(+), 239 Zeilen entfernt(-)
diff --git a/contrib/intro/libguestfs-intro.html b/contrib/intro/libguestfs-intro.html
index 380e290..a413207 100644
--- a/contrib/intro/libguestfs-intro.html
+++ b/contrib/intro/libguestfs-intro.html
@@ -119,6 +119,7 @@ char *
return get_blkid_tag (device, "TYPE");
}
+GUESTFS_EXT_CMD(str_blkid, blkid);
static char *
get_blkid_tag (const char *device, const char *tag)
{
@@ -126,7 +127,7 @@ get_blkid_tag (const char *device, const char *tag)
int r;
r = commandr (&out, &err,
- "blkid",
+ str_blkid,
"-c", "/dev/null",
"-o", "value", "-s", tag, device, NULL);
if (r != 0 && r != 2) {
diff --git a/daemon/9p.c b/daemon/9p.c
index 8c0eeb6..5124a52 100644
--- a/daemon/9p.c
+++ b/daemon/9p.c
@@ -33,6 +33,7 @@
#include "actions.h"
#define BUS_PATH "/sys/bus/virtio/drivers/9pnet_virtio"
+GUESTFS_EXT_CMD(str_mount, mount);
static char *read_whole_file (const char *filename);
@@ -211,7 +212,7 @@ do_mount_9p (const char *mount_tag, const char *mountpoint, const char *options)
}
r = command (NULL, &err,
- "mount", "-o", opts, "-t", "9p", mount_tag, mp, NULL);
+ str_mount, "-o", opts, "-t", "9p", mount_tag, mp, NULL);
if (r == -1) {
reply_with_error ("%s on %s: %s", mount_tag, mountpoint, err);
goto out;
diff --git a/daemon/available.c b/daemon/available.c
index 08e72f3..48e5eb5 100644
--- a/daemon/available.c
+++ b/daemon/available.c
@@ -29,6 +29,9 @@
#include "actions.h"
#include "optgroups.h"
+GUESTFS_EXT_CMD(str_grep, grep);
+GUESTFS_EXT_CMD(str_modprobe, modprobe);
+
int
do_available (char *const *groups)
{
@@ -85,7 +88,7 @@ test_proc_filesystems (const char *filesystem)
snprintf (regex, len, "^[[:space:]]*%s$", filesystem);
- r = commandr (NULL, &err, "grep", regex, "/proc/filesystems", NULL);
+ r = commandr (NULL, &err, str_grep, regex, "/proc/filesystems", NULL);
if (r == -1 || r >= 2) {
fprintf (stderr, "grep /proc/filesystems: %s", err);
free (err);
@@ -100,7 +103,7 @@ test_proc_filesystems (const char *filesystem)
static void
modprobe (const char *module)
{
- command (NULL, NULL, "modprobe", module, NULL);
+ command (NULL, NULL, str_modprobe, module, NULL);
}
/* Internal function for testing if a filesystem is available. Note
diff --git a/daemon/base64.c b/daemon/base64.c
index 215812a..402313d 100644
--- a/daemon/base64.c
+++ b/daemon/base64.c
@@ -27,6 +27,8 @@
#include "daemon.h"
#include "actions.h"
+GUESTFS_EXT_CMD(str_base64, base64);
+
static int
write_cb (void *fd_ptr, const void *buf, size_t len)
{
@@ -42,7 +44,7 @@ do_base64_in (const char *file)
FILE *fp;
char *cmd;
- if (asprintf_nowarn (&cmd, "base64 -d -i > %R", file) == -1) {
+ if (asprintf_nowarn (&cmd, "%s -d -i > %R", str_base64, file) == -1) {
err = errno;
cancel_receive ();
errno = err;
@@ -102,7 +104,7 @@ do_base64_out (const char *file)
char *cmd;
char buf[GUESTFS_MAX_CHUNK_SIZE];
- if (asprintf_nowarn (&cmd, "base64 %R", file) == -1) {
+ if (asprintf_nowarn (&cmd, "%s %R", str_base64, file) == -1) {
reply_with_perror ("asprintf");
return -1;
}
diff --git a/daemon/blkid.c b/daemon/blkid.c
index 7cc7889..b239594 100644
--- a/daemon/blkid.c
+++ b/daemon/blkid.c
@@ -27,6 +27,8 @@
#include "daemon.h"
#include "actions.h"
+GUESTFS_EXT_CMD(str_blkid, blkid);
+
static char *
get_blkid_tag (const char *device, const char *tag)
{
@@ -34,7 +36,7 @@ get_blkid_tag (const char *device, const char *tag)
int r;
r = commandr (&out, &err,
- "blkid",
+ str_blkid,
/* Adding -c option kills all caching, even on RHEL 5. */
"-c", "/dev/null",
"-o", "value", "-s", tag, device, NULL);
@@ -96,7 +98,7 @@ test_blkid_p_i_opt (void)
int r;
char *err;
- r = commandr (NULL, &err, "blkid", "-p", "/dev/null", NULL);
+ r = commandr (NULL, &err, str_blkid, "-p", "/dev/null", NULL);
if (r == -1) {
/* This means we couldn't run the blkid command at all. */
command_failed:
@@ -111,7 +113,7 @@ test_blkid_p_i_opt (void)
}
free (err);
- r = commandr (NULL, &err, "blkid", "-i", NULL);
+ r = commandr (NULL, &err, str_blkid, "-i", NULL);
if (r == -1)
goto command_failed;
@@ -134,7 +136,7 @@ blkid_with_p_i_opt (const char *device)
char **lines = NULL;
DECLARE_STRINGSBUF (ret);
- r = command (&out, &err, "blkid", "-c", "/dev/null",
+ r = command (&out, &err, str_blkid, "-c", "/dev/null",
"-p", "-i", "-o", "export", device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
diff --git a/daemon/blockdev.c b/daemon/blockdev.c
index a7fd2cb..03bb68e 100644
--- a/daemon/blockdev.c
+++ b/daemon/blockdev.c
@@ -28,6 +28,8 @@
#include "daemon.h"
#include "actions.h"
+GUESTFS_EXT_CMD(str_blockdev, blockdev);
+
/* These functions are all about using the blockdev command, so
* we centralize it in one call.
*/
@@ -38,7 +40,7 @@ call_blockdev (const char *device, const char *switc, int extraarg, int prints)
int64_t rv;
char *out, *err;
const char *argv[] = {
- "blockdev",
+ str_blockdev,
switc,
NULL,
NULL,
diff --git a/daemon/btrfs.c b/daemon/btrfs.c
index 411fdea..b055267 100644
--- a/daemon/btrfs.c
+++ b/daemon/btrfs.c
@@ -28,10 +28,15 @@
#include "actions.h"
#include "optgroups.h"
+GUESTFS_EXT_CMD(str_btrfs, btrfs);
+GUESTFS_EXT_CMD(str_btrfstune, btrfstune);
+GUESTFS_EXT_CMD(str_btrfsck, btrfsck);
+GUESTFS_EXT_CMD(str_mkfs_btrfs, mkfs.btrfs);
+
int
optgroup_btrfs_available (void)
{
- return prog_exists ("btrfs") && filesystem_available ("btrfs") > 0;
+ return prog_exists (str_btrfs) && filesystem_available ("btrfs") > 0;
}
/* Takes optional arguments, consult optargs_bitmask. */
@@ -46,7 +51,7 @@ do_btrfs_filesystem_resize (const char *filesystem, int64_t size)
size_t i = 0;
char size_str[32];
- ADD_ARG (argv, i, "btrfs");
+ ADD_ARG (argv, i, str_btrfs);
ADD_ARG (argv, i, "filesystem");
ADD_ARG (argv, i, "resize");
@@ -109,7 +114,7 @@ do_mkfs_btrfs (char *const *devices,
char nodesize_s[64];
char sectorsize_s[64];
- ADD_ARG (argv, i, "mkfs.btrfs");
+ ADD_ARG (argv, i, str_mkfs_btrfs);
/* Optional arguments. */
if (optargs_bitmask & GUESTFS_MKFS_BTRFS_ALLOCSTART_BITMASK) {
@@ -225,7 +230,7 @@ do_btrfs_subvolume_snapshot (const char *source, const char *dest)
return -1;
}
- ADD_ARG (argv, i, "btrfs");
+ ADD_ARG (argv, i, str_btrfs);
ADD_ARG (argv, i, "subvolume");
ADD_ARG (argv, i, "snapshot");
ADD_ARG (argv, i, source_buf);
@@ -261,7 +266,7 @@ do_btrfs_subvolume_delete (const char *subvolume)
return -1;
}
- ADD_ARG (argv, i, "btrfs");
+ ADD_ARG (argv, i, str_btrfs);
ADD_ARG (argv, i, "subvolume");
ADD_ARG (argv, i, "delete");
ADD_ARG (argv, i, subvolume_buf);
@@ -295,7 +300,7 @@ do_btrfs_subvolume_create (const char *dest)
return -1;
}
- ADD_ARG (argv, i, "btrfs");
+ ADD_ARG (argv, i, str_btrfs);
ADD_ARG (argv, i, "subvolume");
ADD_ARG (argv, i, "create");
ADD_ARG (argv, i, dest_buf);
@@ -331,7 +336,7 @@ do_btrfs_subvolume_list (const char *fs)
return NULL;
}
- ADD_ARG (argv, i, "btrfs");
+ ADD_ARG (argv, i, str_btrfs);
ADD_ARG (argv, i, "subvolume");
ADD_ARG (argv, i, "list");
ADD_ARG (argv, i, fs_buf);
@@ -428,7 +433,7 @@ do_btrfs_subvolume_set_default (int64_t id, const char *fs)
return -1;
}
- ADD_ARG (argv, i, "btrfs");
+ ADD_ARG (argv, i, str_btrfs);
ADD_ARG (argv, i, "subvolume");
ADD_ARG (argv, i, "set-default");
ADD_ARG (argv, i, buf);
@@ -463,7 +468,7 @@ do_btrfs_filesystem_sync (const char *fs)
return -1;
}
- ADD_ARG (argv, i, "btrfs");
+ ADD_ARG (argv, i, str_btrfs);
ADD_ARG (argv, i, "filesystem");
ADD_ARG (argv, i, "sync");
ADD_ARG (argv, i, fs_buf);
@@ -497,7 +502,7 @@ do_btrfs_filesystem_balance (const char *fs)
return -1;
}
- ADD_ARG (argv, i, "btrfs");
+ ADD_ARG (argv, i, str_btrfs);
ADD_ARG (argv, i, "filesystem");
ADD_ARG (argv, i, "balance");
ADD_ARG (argv, i, fs_buf);
@@ -536,7 +541,7 @@ do_btrfs_device_add (char *const *devices, const char *fs)
return -1;
}
- ADD_ARG (argv, i, "btrfs");
+ ADD_ARG (argv, i, str_btrfs);
ADD_ARG (argv, i, "device");
ADD_ARG (argv, i, "add");
@@ -579,7 +584,7 @@ do_btrfs_device_delete (char *const *devices, const char *fs)
return -1;
}
- ADD_ARG (argv, i, "btrfs");
+ ADD_ARG (argv, i, str_btrfs);
ADD_ARG (argv, i, "device");
ADD_ARG (argv, i, "delete");
@@ -609,7 +614,7 @@ do_btrfs_set_seeding (const char *device, int svalue)
const char *s_value = svalue ? "1" : "0";
- r = commandr (NULL, &err, "btrfstune", "-S", s_value, device, NULL);
+ r = commandr (NULL, &err, str_btrfstune, "-S", s_value, device, NULL);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
free (err);
@@ -631,7 +636,7 @@ do_btrfs_fsck (const char *device, int64_t superblock, int repair)
const char *argv[MAX_ARGS];
char super_s[64];
- ADD_ARG (argv, i, "btrfsck");
+ ADD_ARG (argv, i, str_btrfsck);
/* Optional arguments. */
if (optargs_bitmask & GUESTFS_BTRFS_FSCK_SUPERBLOCK_BITMASK) {
diff --git a/daemon/checksum.c b/daemon/checksum.c
index 2cc4a2b..8d6cbdb 100644
--- a/daemon/checksum.c
+++ b/daemon/checksum.c
@@ -29,6 +29,9 @@
#include "daemon.h"
#include "actions.h"
+GUESTFS_EXT_CMD(str_find, find);
+GUESTFS_EXT_CMD(str_xargs, xargs);
+
static const char *
program_of_csum (const char *csumtype)
{
@@ -150,7 +153,8 @@ do_checksums_out (const char *csumtype, const char *dir)
}
char *cmd;
- if (asprintf_nowarn (&cmd, "cd %Q && find -type f -print0 | xargs -0 %s",
+ if (asprintf_nowarn (&cmd, "cd %Q && %s -type f -print0 | %s -0 %s",
+ str_find, str_xargs,
sysrootdir, program) == -1) {
reply_with_perror ("asprintf");
free (sysrootdir);
diff --git a/daemon/cmp.c b/daemon/cmp.c
index 0673403..a63b36f 100644
--- a/daemon/cmp.c
+++ b/daemon/cmp.c
@@ -27,6 +27,8 @@
#include "daemon.h"
#include "actions.h"
+GUESTFS_EXT_CMD(str_cmp, cmp);
+
int
do_equal (const char *file1, const char *file2)
{
@@ -47,7 +49,7 @@ do_equal (const char *file1, const char *file2)
return -1;
}
- r = commandr (NULL, &err, "cmp", "-s", file1buf, file2buf, NULL);
+ r = commandr (NULL, &err, str_cmp, "-s", file1buf, file2buf, NULL);
free (file1buf);
free (file2buf);
diff --git a/daemon/command.c b/daemon/command.c
index 7c67d83..4ab2432 100644
--- a/daemon/command.c
+++ b/daemon/command.c
@@ -28,10 +28,13 @@
#include "ignore-value.h"
+GUESTFS_EXT_CMD(str_mount, mount);
+GUESTFS_EXT_CMD(str_umount, umount);
+
static inline void
umount_ignore_fail (const char *path)
{
- ignore_value (command (NULL, NULL, "umount", path, NULL));
+ ignore_value (command (NULL, NULL, str_umount, path, NULL));
}
char *
@@ -81,15 +84,15 @@ do_command (char *const *argv)
return NULL;
}
- r = command (NULL, NULL, "mount", "--bind", "/dev", sysroot_dev, NULL);
+ r = command (NULL, NULL, str_mount, "--bind", "/dev", sysroot_dev, NULL);
dev_ok = r != -1;
- r = command (NULL, NULL, "mount", "--bind", "/dev/pts", sysroot_dev_pts, NULL);
+ r = command (NULL, NULL, str_mount, "--bind", "/dev/pts", sysroot_dev_pts, NULL);
dev_pts_ok = r != -1;
- r = command (NULL, NULL, "mount", "--bind", "/proc", sysroot_proc, NULL);
+ r = command (NULL, NULL, str_mount, "--bind", "/proc", sysroot_proc, NULL);
proc_ok = r != -1;
- r = command (NULL, NULL, "mount", "--bind", "/selinux", sysroot_selinux, NULL);
+ r = command (NULL, NULL, str_mount, "--bind", "/selinux", sysroot_selinux, NULL);
selinux_ok = r != -1;
- r = command (NULL, NULL, "mount", "--bind", "/sys", sysroot_sys, NULL);
+ r = command (NULL, NULL, str_mount, "--bind", "/sys", sysroot_sys, NULL);
sys_ok = r != -1;
CHROOT_IN;
diff --git a/daemon/compress.c b/daemon/compress.c
index b9967d9..118f00d 100644
--- a/daemon/compress.c
+++ b/daemon/compress.c
@@ -27,6 +27,12 @@
#include "daemon.h"
#include "actions.h"
+GUESTFS_EXT_CMD(str_compress, compress);
+GUESTFS_EXT_CMD(str_gzip, gzip);
+GUESTFS_EXT_CMD(str_bzip2, bzip2);
+GUESTFS_EXT_CMD(str_xz, xz);
+GUESTFS_EXT_CMD(str_lzop, lzop);
+
/* Has one FileOut parameter. */
static int
do_compressX_out (const char *file, const char *filter, int is_device)
@@ -118,15 +124,15 @@ get_filter (const char *ctype, int level, char *ret, size_t n)
reply_with_error ("compress: cannot use optional level parameter with this compression type");
return -1;
}
- snprintf (ret, n, "compress -c");
+ snprintf (ret, n, "%s -c", str_compress);
return 0;
}
else if (STREQ (ctype, "gzip")) {
CHECK_SUPPORTED ("gzip");
if (level == -1)
- snprintf (ret, n, "gzip -c");
+ snprintf (ret, n, "%s -c", str_gzip);
else if (level >= 1 && level <= 9)
- snprintf (ret, n, "gzip -c -%d", level);
+ snprintf (ret, n, "%s -c -%d", str_gzip, level);
else {
reply_with_error ("gzip: incorrect value for level parameter");
return -1;
@@ -136,9 +142,9 @@ get_filter (const char *ctype, int level, char *ret, size_t n)
else if (STREQ (ctype, "bzip2")) {
CHECK_SUPPORTED ("bzip2");
if (level == -1)
- snprintf (ret, n, "bzip2 -c");
+ snprintf (ret, n, "%s -c", str_bzip2);
else if (level >= 1 && level <= 9)
- snprintf (ret, n, "bzip2 -c -%d", level);
+ snprintf (ret, n, "%s -c -%d", str_bzip2, level);
else {
reply_with_error ("bzip2: incorrect value for level parameter");
return -1;
@@ -148,9 +154,9 @@ get_filter (const char *ctype, int level, char *ret, size_t n)
else if (STREQ (ctype, "xz")) {
CHECK_SUPPORTED ("xz");
if (level == -1)
- snprintf (ret, n, "xz -c");
+ snprintf (ret, n, "%s -c", str_xz);
else if (level >= 0 && level <= 9)
- snprintf (ret, n, "xz -c -%d", level);
+ snprintf (ret, n, "%s -c -%d", str_xz, level);
else {
reply_with_error ("xz: incorrect value for level parameter");
return -1;
@@ -160,9 +166,9 @@ get_filter (const char *ctype, int level, char *ret, size_t n)
else if (STREQ (ctype, "lzop")) {
CHECK_SUPPORTED ("lzop");
if (level == -1)
- snprintf (ret, n, "lzop -c");
+ snprintf (ret, n, "%s -c", str_lzop);
else if (level >= 1 && level <= 9)
- snprintf (ret, n, "lzop -c -%d", level);
+ snprintf (ret, n, "%s -c -%d", str_lzop, level);
else {
reply_with_error ("lzop: incorrect value for level parameter");
return -1;
diff --git a/daemon/cpmv.c b/daemon/cpmv.c
index ba7de2b..d4bfe1d 100644
--- a/daemon/cpmv.c
+++ b/daemon/cpmv.c
@@ -25,24 +25,27 @@
#include "daemon.h"
#include "actions.h"
+GUESTFS_EXT_CMD(str_cp, cp);
+GUESTFS_EXT_CMD(str_mv, mv);
+
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)
{
- return cpmv_cmd ("cp", NULL, src, dest);
+ return cpmv_cmd (str_cp, NULL, src, dest);
}
int
do_cp_a (const char *src, const char *dest)
{
- return cpmv_cmd ("cp", "-a", src, dest);
+ return cpmv_cmd (str_cp, "-a", src, dest);
}
int
do_mv (const char *src, const char *dest)
{
- return cpmv_cmd ("mv", NULL, src, dest);
+ return cpmv_cmd (str_mv, NULL, src, dest);
}
static int
diff --git a/daemon/daemon.h b/daemon/daemon.h
index bbe77f9..f848914 100644
--- a/daemon/daemon.h
+++ b/daemon/daemon.h
@@ -96,6 +96,9 @@ extern char **split_lines (char *str);
#define commandv(out,err,argv) commandvf((out),(err),0,(argv))
#define commandrv(out,err,argv) commandrvf((out),(err),0,(argv))
+#define __external_command __attribute__((__section__(".guestfs_ext_cmds")))
+#define GUESTFS_EXT_CMD(___ext_cmd_var, ___ext_cmd_str) static const char ___ext_cmd_var[] __external_command = #___ext_cmd_str
+
#define COMMAND_FLAG_FD_MASK (1024-1)
#define COMMAND_FLAG_FOLD_STDOUT_ON_STDERR 1024
#define COMMAND_FLAG_CHROOT_COPY_FILE_TO_STDIN 2048
@@ -171,7 +174,7 @@ extern int filesystem_available (const char *filesystem);
extern int sync_disks (void);
/*-- in ext2.c --*/
-extern int e2prog (char *name); /* Massive hack for RHEL 5. */
+extern int e2prog (const char *name); /* Massive hack for RHEL 5. */
/* Confirmed this is true up to ext4 from the Linux sources. */
#define EXT2_LABEL_MAX 16
diff --git a/daemon/dd.c b/daemon/dd.c
index 8bc4aab..d4ee094 100644
--- a/daemon/dd.c
+++ b/daemon/dd.c
@@ -27,6 +27,8 @@
#include "daemon.h"
#include "actions.h"
+GUESTFS_EXT_CMD(str_dd, dd);
+
int
do_dd (const char *src, const char *dest)
{
@@ -58,7 +60,7 @@ do_dd (const char *src, const char *dest)
return -1;
}
- r = command (NULL, &err, "dd", "bs=1024K", if_arg, of_arg, NULL);
+ r = command (NULL, &err, str_dd, "bs=1024K", if_arg, of_arg, NULL);
free (if_arg);
free (of_arg);
diff --git a/daemon/debug.c b/daemon/debug.c
index 97d21f0..db1a8cc 100644
--- a/daemon/debug.c
+++ b/daemon/debug.c
@@ -32,6 +32,15 @@
#include "daemon.h"
#include "actions.h"
+GUESTFS_EXT_CMD(str_printenv, printenv);
+GUESTFS_EXT_CMD(str_ldd, ldd);
+GUESTFS_EXT_CMD(str_ls, ls);
+GUESTFS_EXT_CMD(str_find, find);
+GUESTFS_EXT_CMD(str_xargs, xargs);
+GUESTFS_EXT_CMD(str_file, file);
+GUESTFS_EXT_CMD(str_grep, grep);
+GUESTFS_EXT_CMD(str_gawk, gawk);
+
/* This command exposes debugging information, internals and
* status. There is no comprehensive documentation for this
* command. You have to look at the source code in this file
@@ -275,7 +284,7 @@ debug_env (const char *subcmd, size_t argc, char *const *const argv)
int r;
char *out, *err;
- r = command (&out, &err, "printenv", NULL);
+ r = command (&out, &err, str_printenv, NULL);
if (r == -1) {
reply_with_error ("printenv: %s", err);
free (out);
@@ -318,13 +327,17 @@ debug_binaries (const char *subcmd, size_t argc, char *const *const argv)
{
int r;
char *out, *err;
-
- const char cmd[] =
- "find / -xdev -type f -executable "
- "| xargs file -i "
- "| grep application/x-executable "
- "| gawk -F: '{print $1}'";
-
+ char cmd[123];
+
+ if (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) >= sizeof(cmd)) {
+ reply_with_error ("find: %s", err);
+ return NULL;
+ }
r = command (&out, &err, "sh", "-c", cmd, NULL);
if (r == -1) {
reply_with_error ("find: %s", err);
@@ -358,7 +371,7 @@ debug_ldd (const char *subcmd, size_t argc, char *const *const argv)
* Also 'ldd' randomly sends messages to stderr and errors to stdout
* depending on the phase of the moon.
*/
- r = command (&out, &err, "ldd", "-r", argv[0], NULL);
+ r = command (&out, &err, str_ldd, "-r", argv[0], NULL);
if (r == -1) {
reply_with_error ("ldd: %s: %s", argv[0], err);
free (out);
@@ -389,7 +402,7 @@ debug_ls (const char *subcmd, size_t argc, char *const *const argv)
const char *cargv[len+3];
size_t i;
- cargv[0] = "ls";
+ cargv[0] = str_ls;
cargv[1] = "-a";
for (i = 0; i < len; ++i)
cargv[2+i] = argv[i];
@@ -419,7 +432,7 @@ debug_ll (const char *subcmd, size_t argc, char *const *const argv)
const char *cargv[len+3];
size_t i;
- cargv[0] = "ls";
+ cargv[0] = str_ls;
cargv[1] = "-la";
for (i = 0; i < len; ++i)
cargv[2+i] = argv[i];
diff --git a/daemon/df.c b/daemon/df.c
index 14954d2..ad71e05 100644
--- a/daemon/df.c
+++ b/daemon/df.c
@@ -27,6 +27,8 @@
#include "daemon.h"
#include "actions.h"
+GUESTFS_EXT_CMD(str_df, df);
+
char *
do_df (void)
{
@@ -35,7 +37,7 @@ do_df (void)
NEED_ROOT (, return NULL);
- r = command (&out, &err, "df", NULL);
+ r = command (&out, &err, str_df, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (out);
@@ -56,7 +58,7 @@ do_df_h (void)
NEED_ROOT (, return NULL);
- r = command (&out, &err, "df", "-h", NULL);
+ r = command (&out, &err, str_df, "-h", NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (out);
diff --git a/daemon/dir.c b/daemon/dir.c
index 3b18d48..6ddc8a4 100644
--- a/daemon/dir.c
+++ b/daemon/dir.c
@@ -29,6 +29,8 @@
#include "daemon.h"
#include "actions.h"
+GUESTFS_EXT_CMD(str_rm, rm);
+
int
do_rmdir (const char *path)
{
@@ -67,7 +69,7 @@ do_rm_rf (const char *path)
return -1;
}
- r = command (NULL, &err, "rm", "-rf", buf, NULL);
+ r = command (NULL, &err, str_rm, "-rf", buf, NULL);
free (buf);
/* rm -rf is never supposed to fail. I/O errors perhaps? */
diff --git a/daemon/dmesg.c b/daemon/dmesg.c
index 5e98a18..0402f08 100644
--- a/daemon/dmesg.c
+++ b/daemon/dmesg.c
@@ -27,13 +27,15 @@
#include "daemon.h"
#include "actions.h"
+GUESTFS_EXT_CMD(str_dmesg, dmesg);
+
char *
do_dmesg (void)
{
char *out, *err;
int r;
- r = command (&out, &err, "dmesg", NULL);
+ r = command (&out, &err, str_dmesg, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (out);
diff --git a/daemon/du.c b/daemon/du.c
index 62f1142..1aa3b52 100644
--- a/daemon/du.c
+++ b/daemon/du.c
@@ -28,6 +28,8 @@
#include "daemon.h"
#include "actions.h"
+GUESTFS_EXT_CMD(str_du, du);
+
int64_t
do_du (const char *path)
{
@@ -45,7 +47,7 @@ do_du (const char *path)
pulse_mode_start ();
- r = command (&out, &err, "du", "-s", buf, NULL);
+ r = command (&out, &err, str_du, "-s", buf, NULL);
free (buf);
if (r == -1) {
pulse_mode_cancel ();
diff --git a/daemon/ext2.c b/daemon/ext2.c
index 7876e66..7a769bd 100644
--- a/daemon/ext2.c
+++ b/daemon/ext2.c
@@ -31,6 +31,13 @@
#define MAX_ARGS 64
+GUESTFS_EXT_CMD(str_tune2fs, tune2fs);
+GUESTFS_EXT_CMD(str_e2fsck, e2fsck);
+GUESTFS_EXT_CMD(str_resize2fs, resize2fs);
+GUESTFS_EXT_CMD(str_mke2fs, mke2fs);
+GUESTFS_EXT_CMD(str_lsattr, lsattr);
+GUESTFS_EXT_CMD(str_chattr, chattr);
+
/* Choose which tools like mke2fs to use. For RHEL 5 (only) there
* is a special set of tools which support ext2/3/4. eg. On RHEL 5,
* mke2fs only supports ext2/3, but mke4fs supports ext2/3/4.
@@ -39,11 +46,12 @@
* if it exists.
*/
int
-e2prog (char *name)
+e2prog (const char *name)
{
char *p = strstr (name, "e2");
if (!p) return 0;
p++;
+ return 0;
*p = '4';
if (prog_exists (name))
@@ -65,11 +73,10 @@ do_tune2fs_l (const char *device)
char *p, *pend, *colon;
DECLARE_STRINGSBUF (ret);
- char prog[] = "tune2fs";
- if (e2prog (prog) == -1)
+ if (e2prog (str_tune2fs) == -1)
return NULL;
- r = command (&out, &err, prog, "-l", device, NULL);
+ r = command (&out, &err, str_tune2fs, "-l", device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -165,11 +172,10 @@ do_set_e2uuid (const char *device, const char *uuid)
int r;
char *err;
- char prog[] = "tune2fs";
- if (e2prog (prog) == -1)
+ if (e2prog (str_tune2fs) == -1)
return -1;
- r = command (NULL, &err, prog, "-U", uuid, device, NULL);
+ r = command (NULL, &err, str_tune2fs, "-U", uuid, device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -192,9 +198,8 @@ if_not_mounted_run_e2fsck (const char *device)
{
char *err;
int r, mounted;
- char prog[] = "e2fsck";
- if (e2prog (prog) == -1)
+ if (e2prog (str_e2fsck) == -1)
return -1;
mounted = is_device_mounted (device);
@@ -202,7 +207,7 @@ if_not_mounted_run_e2fsck (const char *device)
return -1;
if (!mounted) {
- r = command (NULL, &err, prog, "-fy", device, NULL);
+ r = command (NULL, &err, str_e2fsck, "-fy", device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -220,14 +225,13 @@ do_resize2fs (const char *device)
char *err;
int r;
- char prog[] = "resize2fs";
- if (e2prog (prog) == -1)
+ if (e2prog (str_resize2fs) == -1)
return -1;
if (if_not_mounted_run_e2fsck (device) == -1)
return -1;
- r = command (NULL, &err, prog, device, NULL);
+ r = command (NULL, &err, str_resize2fs, device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -244,8 +248,7 @@ do_resize2fs_size (const char *device, int64_t size)
char *err;
int r;
- char prog[] = "resize2fs";
- if (e2prog (prog) == -1)
+ if (e2prog (str_resize2fs) == -1)
return -1;
/* resize2fs itself may impose additional limits. Since we are
@@ -265,7 +268,7 @@ do_resize2fs_size (const char *device, int64_t size)
char buf[32];
snprintf (buf, sizeof buf, "%" PRIi64 "K", size);
- r = command (NULL, &err, prog, device, buf, NULL);
+ r = command (NULL, &err, str_resize2fs, device, buf, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -282,14 +285,13 @@ do_resize2fs_M (const char *device)
char *err;
int r;
- char prog[] = "resize2fs";
- if (e2prog (prog) == -1)
+ if (e2prog (str_resize2fs) == -1)
return -1;
if (if_not_mounted_run_e2fsck (device) == -1)
return -1;
- r = command (NULL, &err, prog, "-M", device, NULL);
+ r = command (NULL, &err, str_resize2fs, "-M", device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -310,9 +312,8 @@ do_e2fsck (const char *device,
char *err;
size_t i = 0;
int r;
- char prog[] = "e2fsck";
- if (e2prog (prog) == -1)
+ if (e2prog (str_e2fsck) == -1)
return -1;
/* Default if not selected. */
@@ -326,7 +327,7 @@ do_e2fsck (const char *device,
return -1;
}
- ADD_ARG (argv, i, prog);
+ ADD_ARG (argv, i, str_e2fsck);
ADD_ARG (argv, i, "-f");
if (correct)
@@ -369,15 +370,14 @@ do_mke2journal (int blocksize, const char *device)
char *err;
int r;
- char prog[] = "mke2fs";
- if (e2prog (prog) == -1)
+ if (e2prog (str_mke2fs) == -1)
return -1;
char blocksize_s[32];
snprintf (blocksize_s, sizeof blocksize_s, "%d", blocksize);
r = command (NULL, &err,
- prog, "-F", "-O", "journal_dev", "-b", blocksize_s,
+ str_mke2fs, "-F", "-O", "journal_dev", "-b", blocksize_s,
device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
@@ -395,8 +395,7 @@ do_mke2journal_L (int blocksize, const char *label, const char *device)
char *err;
int r;
- char prog[] = "mke2fs";
- if (e2prog (prog) == -1)
+ if (e2prog (str_mke2fs) == -1)
return -1;
if (strlen (label) > EXT2_LABEL_MAX) {
@@ -409,7 +408,7 @@ do_mke2journal_L (int blocksize, const char *label, const char *device)
snprintf (blocksize_s, sizeof blocksize_s, "%d", blocksize);
r = command (NULL, &err,
- prog, "-F", "-O", "journal_dev", "-b", blocksize_s,
+ str_mke2fs, "-F", "-O", "journal_dev", "-b", blocksize_s,
"-L", label,
device, NULL);
if (r == -1) {
@@ -428,15 +427,14 @@ do_mke2journal_U (int blocksize, const char *uuid, const char *device)
char *err;
int r;
- char prog[] = "mke2fs";
- if (e2prog (prog) == -1)
+ if (e2prog (str_mke2fs) == -1)
return -1;
char blocksize_s[32];
snprintf (blocksize_s, sizeof blocksize_s, "%d", blocksize);
r = command (NULL, &err,
- prog, "-F", "-O", "journal_dev", "-b", blocksize_s,
+ str_mke2fs, "-F", "-O", "journal_dev", "-b", blocksize_s,
"-U", uuid,
device, NULL);
if (r == -1) {
@@ -456,8 +454,7 @@ do_mke2fs_J (const char *fstype, int blocksize, const char *device,
char *err;
int r;
- char prog[] = "mke2fs";
- if (e2prog (prog) == -1)
+ if (e2prog (str_mke2fs) == -1)
return -1;
char blocksize_s[32];
@@ -468,7 +465,7 @@ do_mke2fs_J (const char *fstype, int blocksize, const char *device,
snprintf (jdev, len+32, "device=%s", journal);
r = command (NULL, &err,
- prog, "-F", "-t", fstype, "-J", jdev, "-b", blocksize_s,
+ str_mke2fs, "-F", "-t", fstype, "-J", jdev, "-b", blocksize_s,
device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
@@ -487,8 +484,7 @@ do_mke2fs_JL (const char *fstype, int blocksize, const char *device,
char *err;
int r;
- char prog[] = "mke2fs";
- if (e2prog (prog) == -1)
+ if (e2prog (str_mke2fs) == -1)
return -1;
if (strlen (label) > EXT2_LABEL_MAX) {
@@ -505,7 +501,7 @@ do_mke2fs_JL (const char *fstype, int blocksize, const char *device,
snprintf (jdev, len+32, "device=LABEL=%s", label);
r = command (NULL, &err,
- prog, "-F", "-t", fstype, "-J", jdev, "-b", blocksize_s,
+ str_mke2fs, "-F", "-t", fstype, "-J", jdev, "-b", blocksize_s,
device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
@@ -524,8 +520,7 @@ do_mke2fs_JU (const char *fstype, int blocksize, const char *device,
char *err;
int r;
- char prog[] = "mke2fs";
- if (e2prog (prog) == -1)
+ if (e2prog (str_mke2fs) == -1)
return -1;
char blocksize_s[32];
@@ -536,7 +531,7 @@ do_mke2fs_JU (const char *fstype, int blocksize, const char *device,
snprintf (jdev, len+32, "device=UUID=%s", uuid);
r = command (NULL, &err,
- prog, "-F", "-t", fstype, "-J", jdev, "-b", blocksize_s,
+ str_mke2fs, "-F", "-t", fstype, "-J", jdev, "-b", blocksize_s,
device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
@@ -566,7 +561,6 @@ do_tune2fs (const char *device, /* only required parameter */
size_t i = 0;
int r;
char *err;
- char prog[] = "tune2fs";
char maxmountcount_s[64];
char mountcount_s[64];
char group_s[64];
@@ -575,10 +569,10 @@ do_tune2fs (const char *device, /* only required parameter */
char reservedblockscount_s[64];
char user_s[64];
- if (e2prog (prog) == -1)
+ if (e2prog (str_tune2fs) == -1)
return -1;
- ADD_ARG (argv, i, prog);
+ ADD_ARG (argv, i, str_tune2fs);
if (optargs_bitmask & GUESTFS_TUNE2FS_FORCE_BITMASK) {
if (force)
@@ -686,7 +680,7 @@ do_tune2fs (const char *device, /* only required parameter */
r = commandv (NULL, &err, argv);
if (r == -1) {
- reply_with_error ("%s: %s: %s", prog, device, err);
+ reply_with_error ("%s: %s: %s", str_tune2fs, device, err);
free (err);
return -1;
}
@@ -717,7 +711,7 @@ do_get_e2attrs (const char *filename)
return NULL;
}
- r = command (&out, &err, "lsattr", "-d", "--", buf, NULL);
+ r = command (&out, &err, str_lsattr, "-d", "--", buf, NULL);
free (buf);
if (r == -1) {
reply_with_error ("%s: %s: %s", "lsattr", filename, err);
@@ -811,7 +805,7 @@ do_set_e2attrs (const char *filename, const char *attrs, int clear)
return -1;
}
- r = command (NULL, &err, "chattr", attr_arg, "--", buf, NULL);
+ r = command (NULL, &err, str_chattr, attr_arg, "--", buf, NULL);
free (buf);
if (r == -1) {
reply_with_error ("%s: %s: %s", "chattr", filename, err);
@@ -837,7 +831,7 @@ do_get_e2generation (const char *filename)
return -1;
}
- r = command (&out, &err, "lsattr", "-dv", "--", buf, NULL);
+ r = command (&out, &err, str_lsattr, "-dv", "--", buf, NULL);
free (buf);
if (r == -1) {
reply_with_error ("%s: %s: %s", "lsattr", filename, err);
@@ -875,7 +869,7 @@ do_set_e2generation (const char *filename, int64_t generation)
snprintf (generation_str, sizeof generation_str,
"%" PRIu64, (uint64_t) generation);
- r = command (NULL, &err, "chattr", "-v", generation_str, "--", buf, NULL);
+ r = command (NULL, &err, str_chattr, "-v", generation_str, "--", buf, NULL);
free (buf);
if (r == -1) {
reply_with_error ("%s: %s: %s", "chattr", filename, err);
diff --git a/daemon/file.c b/daemon/file.c
index 2756755..8f86bec 100644
--- a/daemon/file.c
+++ b/daemon/file.c
@@ -29,6 +29,10 @@
#include "daemon.h"
#include "actions.h"
+GUESTFS_EXT_CMD(str_file, file);
+GUESTFS_EXT_CMD(str_zcat, zcat);
+GUESTFS_EXT_CMD(str_bzcat, bzcat);
+
int
do_touch (const char *path)
{
@@ -473,7 +477,7 @@ do_file (const char *path)
const char *flags = is_dev ? "-zbsL" : "-zb";
char *out, *err;
- int r = command (&out, &err, "file", flags, path, NULL);
+ int r = command (&out, &err, str_file, flags, path, NULL);
free (buf);
if (r == -1) {
@@ -503,9 +507,9 @@ do_zfile (const char *method, const char *path)
char line[256];
if (STREQ (method, "gzip") || STREQ (method, "compress"))
- zcat = "zcat";
+ zcat = str_zcat;
else if (STREQ (method, "bzip2"))
- zcat = "bzcat";
+ zcat = str_bzcat;
else {
reply_with_error ("unknown method");
return NULL;
diff --git a/daemon/find.c b/daemon/find.c
index 2ee2cf5..0ccea20 100644
--- a/daemon/find.c
+++ b/daemon/find.c
@@ -30,6 +30,8 @@
#include "daemon.h"
#include "actions.h"
+GUESTFS_EXT_CMD(str_find, find);
+
static int
input_to_nul (FILE *fp, char *buf, size_t maxlen)
{
@@ -89,7 +91,7 @@ do_find0 (const char *dir)
sysrootdirlen = strlen (sysrootdir);
- if (asprintf_nowarn (&cmd, "find %Q -print0", sysrootdir) == -1) {
+ if (asprintf_nowarn (&cmd, "%s %Q -print0", str_find, sysrootdir) == -1) {
reply_with_perror ("asprintf");
free (sysrootdir);
return -1;
diff --git a/daemon/findfs.c b/daemon/findfs.c
index 55d2d2e..311845a 100644
--- a/daemon/findfs.c
+++ b/daemon/findfs.c
@@ -26,6 +26,8 @@
#include "daemon.h"
#include "actions.h"
+GUESTFS_EXT_CMD(str_findfs, findfs);
+
static char *
findfs (const char *tag, const char *label_or_uuid)
{
@@ -42,7 +44,7 @@ findfs (const char *tag, const char *label_or_uuid)
snprintf (arg, len, "%s=%s", tag, label_or_uuid);
char *out, *err;
- int r = command (&out, &err, "findfs", arg, NULL);
+ int r = command (&out, &err, str_findfs, arg, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (out);
diff --git a/daemon/fsck.c b/daemon/fsck.c
index 7e835a7..1afa8b0 100644
--- a/daemon/fsck.c
+++ b/daemon/fsck.c
@@ -26,13 +26,15 @@
#include "daemon.h"
#include "actions.h"
+GUESTFS_EXT_CMD(str_fsck, fsck);
+
int
do_fsck (const char *fstype, const char *device)
{
char *err;
int r;
- r = commandr (NULL, &err, "fsck", "-a", "-t", fstype, device, NULL);
+ r = commandr (NULL, &err, str_fsck, "-a", "-t", fstype, device, NULL);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
free (err);
diff --git a/daemon/fstrim.c b/daemon/fstrim.c
index e2daf6a..e0a2377 100644
--- a/daemon/fstrim.c
+++ b/daemon/fstrim.c
@@ -30,10 +30,12 @@
#define MAX_ARGS 64
+GUESTFS_EXT_CMD(str_fstrim, fstrim);
+
int
optgroup_fstrim_available (void)
{
- return prog_exists ("fstrim");
+ return prog_exists (str_fstrim);
}
/* Takes optional arguments, consult optargs_bitmask. */
@@ -47,7 +49,7 @@ do_fstrim (const char *path,
char *err;
int r;
- ADD_ARG (argv, i, "fstrim");
+ ADD_ARG (argv, i, str_fstrim);
if ((optargs_bitmask & GUESTFS_FSTRIM_OFFSET_BITMASK)) {
if (offset < 0) {
diff --git a/daemon/grub.c b/daemon/grub.c
index 9cd4f6e..291ac75 100644
--- a/daemon/grub.c
+++ b/daemon/grub.c
@@ -26,10 +26,12 @@
#include "actions.h"
#include "optgroups.h"
+GUESTFS_EXT_CMD(str_grub_install, grub-install);
+
int
optgroup_grub_available (void)
{
- return prog_exists ("grub-install");
+ return prog_exists (str_grub_install);
}
int
@@ -44,7 +46,7 @@ do_grub_install (const char *root, const char *device)
return -1;
}
- r = command (NULL, &err, "grub-install", buf, device, NULL);
+ r = command (NULL, &err, str_grub_install, buf, device, NULL);
free (buf);
if (r == -1) {
diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c
index 80175e0..0f3c603 100644
--- a/daemon/guestfsd.c
+++ b/daemon/guestfsd.c
@@ -53,6 +53,9 @@
#include "daemon.h"
+GUESTFS_EXT_CMD(str_udevadm, udevadm);
+GUESTFS_EXT_CMD(str_udevsettle, udevsettle);
+
static char *read_cmdline (void);
#ifndef MAX
@@ -1294,6 +1297,6 @@ random_name (char *template)
void
udev_settle (void)
{
- (void) command (NULL, NULL, "udevadm", "settle", NULL);
- (void) command (NULL, NULL, "udevsettle", NULL);
+ (void) command (NULL, NULL, str_udevadm, "settle", NULL);
+ (void) command (NULL, NULL, str_udevsettle, NULL);
}
diff --git a/daemon/initrd.c b/daemon/initrd.c
index 2ded14a..b066a8a 100644
--- a/daemon/initrd.c
+++ b/daemon/initrd.c
@@ -30,6 +30,9 @@
#include "daemon.h"
#include "actions.h"
+GUESTFS_EXT_CMD(str_zcat, zcat);
+GUESTFS_EXT_CMD(str_cpio, cpio);
+
char **
do_initrd_list (const char *path)
{
@@ -40,7 +43,7 @@ do_initrd_list (const char *path)
size_t len;
/* "zcat /sysroot/<path> | cpio --quiet -it", but path must be quoted. */
- if (asprintf_nowarn (&cmd, "zcat %R | cpio --quiet -it", path) == -1) {
+ if (asprintf_nowarn (&cmd, "%s %R | %s --quiet -it", str_zcat, path, str_cpio) == -1) {
reply_with_perror ("asprintf");
return NULL;
}
diff --git a/daemon/inotify.c b/daemon/inotify.c
index ed425b8..3cbb237 100644
--- a/daemon/inotify.c
+++ b/daemon/inotify.c
@@ -35,6 +35,8 @@
#include "optgroups.h"
#ifdef HAVE_SYS_INOTIFY_H
+GUESTFS_EXT_CMD(str_sort, sort);
+
/* Currently open inotify handle, or -1 if not opened. */
static int inotify_fd = -1;
@@ -318,7 +320,7 @@ do_inotify_files (void)
return NULL;
}
- snprintf (cmd, sizeof cmd, "sort -u > %s", tempfile);
+ snprintf (cmd, sizeof cmd, "%s -u > %s", str_sort, tempfile);
fp = popen (cmd, "w");
if (fp == NULL) {
diff --git a/daemon/isoinfo.c b/daemon/isoinfo.c
index c0ee1c9..ce92240 100644
--- a/daemon/isoinfo.c
+++ b/daemon/isoinfo.c
@@ -30,6 +30,8 @@
#include "daemon.h"
#include "actions.h"
+GUESTFS_EXT_CMD(str_isoinfo, isoinfo);
+
static int
parse_uint32 (uint32_t *ret, const char *str)
{
@@ -244,7 +246,7 @@ isoinfo (const char *path)
/* --debug is necessary to get additional fields, in particular
* the date & time fields.
*/
- r = command (&out, &err, "isoinfo", "--debug", "-d", "-i", path, NULL);
+ r = command (&out, &err, str_isoinfo, "--debug", "-d", "-i", path, NULL);
if (r == -1) {
reply_with_error ("%s", err);
goto done;
diff --git a/daemon/labels.c b/daemon/labels.c
index b28d1b2..5c4a930 100644
--- a/daemon/labels.c
+++ b/daemon/labels.c
@@ -27,14 +27,16 @@
#include "actions.h"
#include "optgroups.h"
+GUESTFS_EXT_CMD(str_e2label, e2label);
+GUESTFS_EXT_CMD(str_ntfslabel, ntfslabel);
+
static int
e2label (const char *device, const char *label)
{
int r;
char *err;
- char prog[] = "e2label";
- if (e2prog (prog) == -1)
+ if (e2prog (str_e2label) == -1)
return -1;
if (strlen (label) > EXT2_LABEL_MAX) {
@@ -43,7 +45,7 @@ e2label (const char *device, const char *label)
return -1;
}
- r = command (NULL, &err, prog, device, label, NULL);
+ r = command (NULL, &err, str_e2label, device, label, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -64,7 +66,7 @@ ntfslabel (const char *device, const char *label)
* characters and return an error. This is not so easy since we
* don't have the required libraries.
*/
- r = command (NULL, &err, "ntfslabel", device, label, NULL);
+ r = command (NULL, &err, str_ntfslabel, device, label, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
diff --git a/daemon/link.c b/daemon/link.c
index 4536f00..f5e3cbe 100644
--- a/daemon/link.c
+++ b/daemon/link.c
@@ -28,6 +28,8 @@
#include "daemon.h"
#include "actions.h"
+GUESTFS_EXT_CMD(str_ln, ln);
+
char *
do_readlink (const char *path)
{
@@ -132,11 +134,11 @@ _link (const char *flag, int symbolic, const char *target, const char *linkname)
if (flag)
r = command (NULL, &err,
- "ln", flag, "--", /* target could begin with '-' */
+ str_ln, flag, "--", /* target could begin with '-' */
buf_target ? : target, buf_linkname, NULL);
else
r = command (NULL, &err,
- "ln", "--",
+ str_ln, "--",
buf_target ? : target, buf_linkname, NULL);
free (buf_linkname);
free (buf_target);
diff --git a/daemon/ls.c b/daemon/ls.c
index 5adf5ef..0a748f7 100644
--- a/daemon/ls.c
+++ b/daemon/ls.c
@@ -30,6 +30,8 @@
#include "daemon.h"
#include "actions.h"
+GUESTFS_EXT_CMD(str_ls, ls);
+
/* Has one FileOut parameter. */
int
do_ls0 (const char *path)
@@ -112,7 +114,7 @@ do_ll (const char *path)
return NULL;
}
- r = command (&out, &err, "ls", "-la", spath, NULL);
+ r = command (&out, &err, str_ls, "-la", spath, NULL);
free (spath);
if (r == -1) {
reply_with_error ("%s", err);
@@ -138,7 +140,7 @@ do_llz (const char *path)
return NULL;
}
- r = command (&out, &err, "ls", "-laZ", spath, NULL);
+ r = command (&out, &err, str_ls, "-laZ", spath, NULL);
free (spath);
if (r == -1) {
reply_with_error ("%s", err);
diff --git a/daemon/luks.c b/daemon/luks.c
index 02620ef..14dc47b 100644
--- a/daemon/luks.c
+++ b/daemon/luks.c
@@ -28,10 +28,12 @@
#define MAX_ARGS 64
+GUESTFS_EXT_CMD(str_cryptsetup, cryptsetup);
+
int
optgroup_luks_available (void)
{
- return prog_exists ("cryptsetup");
+ return prog_exists (str_cryptsetup);
}
/* Callers must also call remove_temp (tempfile). */
@@ -100,7 +102,7 @@ luks_open (const char *device, const char *key, const char *mapname,
const char *argv[MAX_ARGS];
size_t i = 0;
- ADD_ARG (argv, i, "cryptsetup");
+ ADD_ARG (argv, i, str_cryptsetup);
ADD_ARG (argv, i, "-d");
ADD_ARG (argv, i, tempfile);
if (readonly) ADD_ARG (argv, i, "--readonly");
@@ -150,7 +152,7 @@ do_luks_close (const char *device)
const char *mapname = &device[12];
char *err;
- int r = command (NULL, &err, "cryptsetup", "luksClose", mapname, NULL);
+ int r = command (NULL, &err, str_cryptsetup, "luksClose", mapname, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -176,7 +178,7 @@ luks_format (const char *device, const char *key, int keyslot,
char keyslot_s[16];
size_t i = 0;
- ADD_ARG (argv, i, "cryptsetup");
+ ADD_ARG (argv, i, str_cryptsetup);
ADD_ARG (argv, i, "-q");
if (cipher) {
ADD_ARG (argv, i, "--cipher");
@@ -238,7 +240,7 @@ do_luks_add_key (const char *device, const char *key, const char *newkey,
char keyslot_s[16];
size_t i = 0;
- ADD_ARG (argv, i, "cryptsetup");
+ ADD_ARG (argv, i, str_cryptsetup);
ADD_ARG (argv, i, "-q");
ADD_ARG (argv, i, "-d");
ADD_ARG (argv, i, keyfile);
@@ -277,7 +279,7 @@ do_luks_kill_slot (const char *device, const char *key, int keyslot)
char keyslot_s[16];
size_t i = 0;
- ADD_ARG (argv, i, "cryptsetup");
+ ADD_ARG (argv, i, str_cryptsetup);
ADD_ARG (argv, i, "-q");
ADD_ARG (argv, i, "-d");
ADD_ARG (argv, i, tempfile);
diff --git a/daemon/lvm-filter.c b/daemon/lvm-filter.c
index 5eb2402..c57beec 100644
--- a/daemon/lvm-filter.c
+++ b/daemon/lvm-filter.c
@@ -31,6 +31,11 @@
#include "daemon.h"
#include "actions.h"
+GUESTFS_EXT_CMD(str_lvm, lvm);
+GUESTFS_EXT_CMD(str_vgchange, vgchange);
+GUESTFS_EXT_CMD(str_cp, cp);
+GUESTFS_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
* LVM_SYSTEM_DIR to point to the copy.
@@ -65,7 +70,7 @@ copy_lvm (void)
}
/* Hopefully no dotfiles in there ... XXX */
- snprintf (cmd, sizeof cmd, "cp -a /etc/lvm/* %s", lvm_system_dir);
+ snprintf (cmd, sizeof cmd, "%s -a /etc/lvm/* %s", str_cp, lvm_system_dir);
r = system (cmd);
if (r == -1) {
perror (cmd);
@@ -92,7 +97,7 @@ rm_lvm_system_dir (void)
{
char cmd[64];
- snprintf (cmd, sizeof cmd, "rm -rf %s", lvm_system_dir);
+ snprintf (cmd, sizeof cmd, "%s -rf %s", str_rm, lvm_system_dir);
ignore_value (system (cmd));
}
@@ -189,7 +194,7 @@ static int
vgchange (const char *vgchange_flag)
{
char *err;
- int r = command (NULL, &err, "lvm", "vgchange", vgchange_flag, NULL);
+ int r = command (NULL, &err, str_lvm, str_vgchange, vgchange_flag, NULL);
if (r == -1) {
reply_with_error ("vgchange: %s", err);
free (err);
@@ -224,7 +229,7 @@ rescan (void)
unlink (lvm_cache);
char *err;
- int r = command (NULL, &err, "lvm", "vgscan", NULL);
+ int r = command (NULL, &err, str_lvm, "vgscan", NULL);
if (r == -1) {
reply_with_error ("vgscan: %s", err);
free (err);
diff --git a/daemon/lvm.c b/daemon/lvm.c
index 5f0c3a6..d2539c4 100644
--- a/daemon/lvm.c
+++ b/daemon/lvm.c
@@ -32,10 +32,12 @@
#include "actions.h"
#include "optgroups.h"
+GUESTFS_EXT_CMD(str_lvm, lvm);
+
int
optgroup_lvm2_available (void)
{
- return prog_exists ("lvm");
+ return prog_exists (str_lvm);
}
/* LVM actions. Keep an eye on liblvm, although at the time
@@ -105,7 +107,7 @@ do_pvs (void)
int r;
r = command (&out, &err,
- "lvm", "pvs", "-o", "pv_name", "--noheadings", NULL);
+ str_lvm, "pvs", "-o", "pv_name", "--noheadings", NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (out);
@@ -125,7 +127,7 @@ do_vgs (void)
int r;
r = command (&out, &err,
- "lvm", "vgs", "-o", "vg_name", "--noheadings", NULL);
+ str_lvm, "vgs", "-o", "vg_name", "--noheadings", NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (out);
@@ -145,7 +147,7 @@ do_lvs (void)
int r;
r = command (&out, &err,
- "lvm", "lvs",
+ str_lvm, "lvs",
"-o", "vg_name,lv_name", "--noheadings",
"--separator", "/", NULL);
if (r == -1) {
@@ -189,7 +191,7 @@ do_pvcreate (const char *device)
int r;
r = command (NULL, &err,
- "lvm", "pvcreate", device, NULL);
+ str_lvm, "pvcreate", device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -216,7 +218,7 @@ do_vgcreate (const char *volgroup, char *const *physvols)
reply_with_perror ("malloc");
return -1;
}
- argv[0] = "lvm";
+ argv[0] = str_lvm;
argv[1] = "vgcreate";
argv[2] = volgroup;
for (i = 3; i <= argc; ++i)
@@ -248,7 +250,7 @@ do_lvcreate (const char *logvol, const char *volgroup, int mbytes)
snprintf (size, sizeof size, "%d", mbytes);
r = command (NULL, &err,
- "lvm", "lvcreate",
+ str_lvm, "lvcreate",
"-L", size, "-n", logvol, volgroup, NULL);
if (r == -1) {
reply_with_error ("%s", err);
@@ -278,7 +280,7 @@ do_lvcreate_free (const char *logvol, const char *volgroup, int percent)
snprintf (size, sizeof size, "%d%%FREE", percent);
r = command (NULL, &err,
- "lvm", "lvcreate",
+ str_lvm, "lvcreate",
"-l", size, "-n", logvol, volgroup, NULL);
if (r == -1) {
reply_with_error ("%s", err);
@@ -303,7 +305,7 @@ do_lvresize (const char *logvol, int mbytes)
snprintf (size, sizeof size, "%d", mbytes);
r = command (NULL, &err,
- "lvm", "lvresize",
+ str_lvm, "lvresize",
"--force", "-L", size, logvol, NULL);
if (r == -1) {
reply_with_error ("%s", err);
@@ -330,7 +332,7 @@ do_lvresize_free (const char *logvol, int percent)
snprintf (size, sizeof size, "+%d%%FREE", percent);
r = command (NULL, &err,
- "lvm", "lvresize", "-l", size, logvol, NULL);
+ str_lvm, "lvresize", "-l", size, logvol, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -361,10 +363,10 @@ do_lvm_remove_all (void)
/* Deactivate the LV first. On Ubuntu, lvremove '-f' option
* does not remove active LVs reliably.
*/
- (void) command (NULL, NULL, "lvm", "lvchange", "-an", xs[i], NULL);
+ (void) command (NULL, NULL, str_lvm, "lvchange", "-an", xs[i], NULL);
udev_settle ();
- r = command (NULL, &err, "lvm", "lvremove", "-f", xs[i], NULL);
+ r = command (NULL, &err, str_lvm, "lvremove", "-f", xs[i], NULL);
if (r == -1) {
reply_with_error ("lvremove: %s: %s", xs[i], err);
free (err);
@@ -382,10 +384,10 @@ do_lvm_remove_all (void)
for (i = 0; xs[i] != NULL; ++i) {
/* Deactivate the VG first, see note above. */
- (void) command (NULL, NULL, "lvm", "vgchange", "-an", xs[i], NULL);
+ (void) command (NULL, NULL, str_lvm, "vgchange", "-an", xs[i], NULL);
udev_settle ();
- r = command (NULL, &err, "lvm", "vgremove", "-f", xs[i], NULL);
+ r = command (NULL, &err, str_lvm, "vgremove", "-f", xs[i], NULL);
if (r == -1) {
reply_with_error ("vgremove: %s: %s", xs[i], err);
free (err);
@@ -402,7 +404,7 @@ do_lvm_remove_all (void)
return -1;
for (i = 0; xs[i] != NULL; ++i) {
- r = command (NULL, &err, "lvm", "pvremove", "-f", xs[i], NULL);
+ r = command (NULL, &err, str_lvm, "pvremove", "-f", xs[i], NULL);
if (r == -1) {
reply_with_error ("pvremove: %s: %s", xs[i], err);
free (err);
@@ -426,7 +428,7 @@ do_lvremove (const char *device)
int r;
r = command (NULL, &err,
- "lvm", "lvremove", "-f", device, NULL);
+ str_lvm, "lvremove", "-f", device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -447,7 +449,7 @@ do_vgremove (const char *device)
int r;
r = command (NULL, &err,
- "lvm", "vgremove", "-f", device, NULL);
+ str_lvm, "vgremove", "-f", device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -468,7 +470,7 @@ do_pvremove (const char *device)
int r;
r = command (NULL, &err,
- "lvm", "pvremove", "-ff", device, NULL);
+ str_lvm, "pvremove", "-ff", device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -489,7 +491,7 @@ do_pvresize (const char *device)
int r;
r = command (NULL, &err,
- "lvm", "pvresize", device, NULL);
+ str_lvm, "pvresize", device, NULL);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
free (err);
@@ -510,7 +512,7 @@ do_pvresize_size (const char *device, int64_t size)
snprintf (buf, sizeof buf, "%" PRIi64 "b", size);
r = command (NULL, &err,
- "lvm", "pvresize",
+ str_lvm, "pvresize",
"--setphysicalvolumesize", buf,
device, NULL);
if (r == -1) {
@@ -537,7 +539,7 @@ do_vg_activate (int activate, char *const *volgroups)
return -1;
}
- argv[0] = "lvm";
+ argv[0] = str_lvm;
argv[1] = "vgchange";
argv[2] = "-a";
argv[3] = activate ? "y" : "n";
@@ -574,7 +576,7 @@ do_lvrename (const char *logvol, const char *newlogvol)
int r;
r = command (NULL, &err,
- "lvm", "lvrename",
+ str_lvm, "lvrename",
logvol, newlogvol, NULL);
if (r == -1) {
reply_with_error ("%s -> %s: %s", logvol, newlogvol, err);
@@ -596,7 +598,7 @@ do_vgrename (const char *volgroup, const char *newvolgroup)
int r;
r = command (NULL, &err,
- "lvm", "vgrename",
+ str_lvm, "vgrename",
volgroup, newvolgroup, NULL);
if (r == -1) {
reply_with_error ("%s -> %s: %s", volgroup, newvolgroup, err);
@@ -617,7 +619,7 @@ get_lvm_field (const char *cmd, const char *field, const char *device)
char *out;
char *err;
int r = command (&out, &err,
- "lvm", cmd,
+ str_lvm, cmd,
"--unbuffered", "--noheadings", "-o", field,
device, NULL);
if (r == -1) {
@@ -657,7 +659,7 @@ get_lvm_fields (const char *cmd, const char *field, const char *device)
char *out;
char *err;
int r = command (&out, &err,
- "lvm", cmd,
+ str_lvm, cmd,
"--unbuffered", "--noheadings", "-o", field,
device, NULL);
if (r == -1) {
@@ -701,7 +703,7 @@ do_vgscan (void)
int r;
r = command (NULL, &err,
- "lvm", "vgscan", NULL);
+ str_lvm, "vgscan", NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -893,7 +895,7 @@ do_vgmeta (const char *vg, size_t *size_r)
close (fd);
- r = command (NULL, &err, "lvm", "vgcfgbackup", "-f", tmp, vg, NULL);
+ r = command (NULL, &err, str_lvm, "vgcfgbackup", "-f", tmp, vg, NULL);
if (r == -1) {
reply_with_error ("vgcfgbackup: %s", err);
free (err);
@@ -968,7 +970,7 @@ do_pvchange_uuid (const char *device)
int r;
r = command (NULL, &err,
- "lvm", "pvchange", "-u", device, NULL);
+ str_lvm, "pvchange", "-u", device, NULL);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
free (err);
@@ -989,7 +991,7 @@ do_pvchange_uuid_all (void)
int r;
r = command (NULL, &err,
- "lvm", "pvchange", "-u", "-a", NULL);
+ str_lvm, "pvchange", "-u", "-a", NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -1010,7 +1012,7 @@ do_vgchange_uuid (const char *vg)
int r;
r = command (NULL, &err,
- "lvm", "vgchange", "-u", vg, NULL);
+ str_lvm, "vgchange", "-u", vg, NULL);
if (r == -1) {
reply_with_error ("%s: %s", vg, err);
free (err);
@@ -1031,7 +1033,7 @@ do_vgchange_uuid_all (void)
int r;
r = command (NULL, &err,
- "lvm", "vgchange", "-u", NULL);
+ str_lvm, "vgchange", "-u", NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
diff --git a/daemon/md.c b/daemon/md.c
index 0e2f704..6570086 100644
--- a/daemon/md.c
+++ b/daemon/md.c
@@ -29,10 +29,12 @@
#include "optgroups.h"
#include "c-ctype.h"
+GUESTFS_EXT_CMD(str_mdadm, mdadm);
+
int
optgroup_mdadm_available (void)
{
- return prog_exists ("mdadm");
+ return prog_exists (str_mdadm);
}
static size_t
@@ -121,7 +123,7 @@ do_md_create (const char *name, char *const *devices,
const char *argv[MAX_ARGS];
size_t i = 0;
- ADD_ARG (argv, i, "mdadm");
+ ADD_ARG (argv, i, str_mdadm);
ADD_ARG (argv, i, "--create");
/* --run suppresses "Continue creating array" question */
ADD_ARG (argv, i, "--run");
@@ -244,7 +246,7 @@ do_md_detail(const char *md)
DECLARE_STRINGSBUF (ret);
- const char *mdadm[] = { "mdadm", "-D", "--export", md, NULL };
+ const char *mdadm[] = { str_mdadm, "-D", "--export", md, NULL };
r = commandv (&out, &err, mdadm);
if (r == -1) {
reply_with_error ("%s", err);
@@ -319,7 +321,7 @@ do_md_stop(const char *md)
int r;
char *err = NULL;
- const char *mdadm[] = { "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);
diff --git a/daemon/mkfs.c b/daemon/mkfs.c
index c7ae50d..dc28b33 100644
--- a/daemon/mkfs.c
+++ b/daemon/mkfs.c
@@ -31,6 +31,9 @@
#define MAX_ARGS 64
+GUESTFS_EXT_CMD(str_mke2fs, mke2fs);
+GUESTFS_EXT_CMD(str_mkfs, mkfs);
+
/* Takes optional arguments, consult optargs_bitmask. */
int
do_mkfs (const char *fstype, const char *device, int blocksize,
@@ -43,7 +46,6 @@ do_mkfs (const char *fstype, const char *device, int blocksize,
char sectorsize_str[32];
int r;
char *err;
- char mke2fs[] = "mke2fs";
int extfs = 0;
if (STREQ (fstype, "ext2") || STREQ (fstype, "ext3") ||
@@ -55,12 +57,12 @@ do_mkfs (const char *fstype, const char *device, int blocksize,
* option.
*/
if (extfs) {
- if (e2prog (mke2fs) == -1)
+ if (e2prog (str_mke2fs) == -1)
return -1;
- ADD_ARG (argv, i, mke2fs);
+ ADD_ARG (argv, i, str_mke2fs);
}
else
- ADD_ARG (argv, i, "mkfs");
+ ADD_ARG (argv, i, str_mkfs);
ADD_ARG (argv, i, "-t");
ADD_ARG (argv, i, fstype);
diff --git a/daemon/modprobe.c b/daemon/modprobe.c
index 1063043..33c9450 100644
--- a/daemon/modprobe.c
+++ b/daemon/modprobe.c
@@ -25,17 +25,19 @@
#include "actions.h"
#include "optgroups.h"
+GUESTFS_EXT_CMD(str_modprobe, modprobe);
+
int
optgroup_linuxmodules_available (void)
{
- return prog_exists ("modprobe");
+ return prog_exists (str_modprobe);
}
int
do_modprobe (const char *module)
{
char *err;
- int r = command (NULL, &err, "modprobe", module, NULL);
+ int r = command (NULL, &err, str_modprobe, module, NULL);
if (r == -1) {
reply_with_error ("%s", err);
diff --git a/daemon/mount.c b/daemon/mount.c
index bd27f94..f665f81 100644
--- a/daemon/mount.c
+++ b/daemon/mount.c
@@ -31,6 +31,9 @@
#define MAX_ARGS 64
+GUESTFS_EXT_CMD(str_mount, mount);
+GUESTFS_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
* mounted on *or under* the sysroot directory. (It has to be *or
@@ -150,10 +153,10 @@ do_mount_vfs (const char *options, const char *vfstype,
if (vfstype)
r = command (NULL, &error,
- "mount", "-o", options, "-t", vfstype, device, mp, NULL);
+ str_mount, "-o", options, "-t", vfstype, device, mp, NULL);
else
r = command (NULL, &error,
- "mount", "-o", options, device, mp, NULL);
+ str_mount, "-o", options, device, mp, NULL);
free (mp);
if (r == -1) {
reply_with_error ("%s on %s (options: '%s'): %s",
@@ -213,7 +216,7 @@ do_umount (const char *pathordevice,
/* Use the external /bin/umount program, so that /etc/mtab is kept
* updated.
*/
- ADD_ARG (argv, i, "umount");
+ ADD_ARG (argv, i, str_umount);
if (force)
ADD_ARG (argv, i, "-f");
@@ -382,7 +385,7 @@ do_umount_all (void)
/* Unmount them. */
for (i = 0; i < mounts.size; ++i) {
- r = command (NULL, &err, "umount", mounts.argv[i], NULL);
+ r = command (NULL, &err, str_umount, mounts.argv[i], NULL);
if (r == -1) {
reply_with_error ("umount: %s: %s", mounts.argv[i], err);
free (err);
@@ -422,7 +425,7 @@ do_mount_loop (const char *file, const char *mountpoint)
return -1;
}
- r = command (NULL, &error, "mount", "-o", "loop", buf, mp, NULL);
+ r = command (NULL, &error, str_mount, "-o", "loop", buf, mp, NULL);
free (mp);
free (buf);
if (r == -1) {
diff --git a/daemon/ntfs.c b/daemon/ntfs.c
index 2dedc26..4f8791e 100644
--- a/daemon/ntfs.c
+++ b/daemon/ntfs.c
@@ -30,16 +30,20 @@
#define MAX_ARGS 64
+GUESTFS_EXT_CMD(str_ntfs3g_probe, ntfs-3g.probe);
+GUESTFS_EXT_CMD(str_ntfsresize, ntfsresize);
+GUESTFS_EXT_CMD(str_ntfsfix, ntfsfix);
+
int
optgroup_ntfs3g_available (void)
{
- return prog_exists ("ntfs-3g.probe");
+ return prog_exists (str_ntfs3g_probe);
}
int
optgroup_ntfsprogs_available (void)
{
- return prog_exists ("ntfsresize");
+ return prog_exists (str_ntfsresize);
}
int
@@ -51,7 +55,7 @@ do_ntfs_3g_probe (int rw, const char *device)
rw_flag = rw ? "-w" : "-r";
- r = commandr (NULL, &err, "ntfs-3g.probe", rw_flag, device, NULL);
+ r = commandr (NULL, &err, str_ntfs3g_probe, rw_flag, device, NULL);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
free (err);
@@ -72,7 +76,7 @@ do_ntfsresize (const char *device, int64_t size, int force)
size_t i = 0;
char size_str[32];
- ADD_ARG (argv, i, "ntfsresize");
+ ADD_ARG (argv, i, str_ntfsresize);
ADD_ARG (argv, i, "-P");
if (optargs_bitmask & GUESTFS_NTFSRESIZE_SIZE_BITMASK) {
@@ -119,7 +123,7 @@ do_ntfsfix (const char *device, int clearbadsectors)
int r;
char *err;
- ADD_ARG (argv, i, "ntfsfix");
+ ADD_ARG (argv, i, str_ntfsfix);
if ((optargs_bitmask & GUESTFS_NTFSFIX_CLEARBADSECTORS_BITMASK) &&
clearbadsectors)
diff --git a/daemon/ntfsclone.c b/daemon/ntfsclone.c
index 4287edb..e90b545 100644
--- a/daemon/ntfsclone.c
+++ b/daemon/ntfsclone.c
@@ -30,6 +30,8 @@
#include "actions.h"
#include "optgroups.h"
+GUESTFS_EXT_CMD(str_ntfsclone, ntfsclone);
+
/* Read the error file. Returns a string that the caller must free. */
static char *
read_error_file (char *error_file)
@@ -80,8 +82,8 @@ do_ntfsclone_in (const char *device)
close (fd);
/* Construct the command. */
- if (asprintf_nowarn (&cmd, "ntfsclone -O %s --restore-image - 2> %s",
- device, error_file) == -1) {
+ if (asprintf_nowarn (&cmd, "%s -O %s --restore-image - 2> %s",
+ str_ntfsclone, device, error_file) == -1) {
err = errno;
r = cancel_receive ();
errno = err;
@@ -157,7 +159,8 @@ do_ntfsclone_out (const char *device,
char buf[GUESTFS_MAX_CHUNK_SIZE];
/* Construct the ntfsclone command. */
- if (asprintf (&cmd, "ntfsclone -o - --save-image%s%s%s%s%s %s",
+ 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" : "",
diff --git a/daemon/parted.c b/daemon/parted.c
index ceefc4a..eab892f 100644
--- a/daemon/parted.c
+++ b/daemon/parted.c
@@ -28,6 +28,9 @@
#include "daemon.h"
#include "actions.h"
+GUESTFS_EXT_CMD(str_parted, parted);
+GUESTFS_EXT_CMD(str_sfdisk, sfdisk);
+
/* Notes:
*
* Parted 1.9 sends error messages to stdout, hence use of the
@@ -82,7 +85,7 @@ do_part_init (const char *device, const char *parttype)
udev_settle ();
r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
- "parted", "-s", "--", device, "mklabel", parttype, NULL);
+ str_parted, "-s", "--", device, "mklabel", parttype, NULL);
if (r == -1) {
reply_with_error ("parted: %s: %s", device, err);
free (err);
@@ -137,7 +140,7 @@ do_part_add (const char *device, const char *prlogex,
* this as a bug in the parted mkpart command.
*/
r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
- "parted", "-s", "--",
+ str_parted, "-s", "--",
device, "mkpart", prlogex, startstr, endstr, NULL);
if (r == -1) {
reply_with_error ("parted: %s: %s", device, err);
@@ -168,7 +171,7 @@ do_part_del (const char *device, int partnum)
udev_settle ();
r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
- "parted", "-s", "--", device, "rm", partnum_str, NULL);
+ str_parted, "-s", "--", device, "rm", partnum_str, NULL);
if (r == -1) {
reply_with_error ("parted: %s: %s", device, err);
free (err);
@@ -209,7 +212,7 @@ do_part_disk (const char *device, const char *parttype)
udev_settle ();
r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
- "parted", "-s", "--",
+ str_parted, "-s", "--",
device,
"mklabel", parttype,
/* See comment about about the parted mkpart command. */
@@ -245,7 +248,7 @@ do_part_set_bootable (const char *device, int partnum, int bootable)
udev_settle ();
r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
- "parted", "-s", "--",
+ str_parted, "-s", "--",
device, "set", partstr, "boot", bootable ? "on" : "off", NULL);
if (r == -1) {
reply_with_error ("parted: %s: %s", device, err);
@@ -277,7 +280,7 @@ do_part_set_name (const char *device, int partnum, const char *name)
udev_settle ();
r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
- "parted", "-s", "--", device, "name", partstr, name, NULL);
+ str_parted, "-s", "--", device, "name", partstr, name, NULL);
if (r == -1) {
reply_with_error ("parted: %s: %s", device, err);
free (err);
@@ -333,7 +336,7 @@ test_parted_m_opt (void)
return result;
char *err = NULL;
- int r = commandr (NULL, &err, "parted", "-s", "-m", "/dev/null", NULL);
+ int r = commandr (NULL, &err, str_parted, "-s", "-m", "/dev/null", NULL);
if (r == -1) {
/* Test failed, eg. missing or completely unusable parted binary. */
reply_with_error ("could not run 'parted' command");
@@ -356,11 +359,11 @@ print_partition_table (const char *device, int parted_has_m_opt)
int r;
if (parted_has_m_opt)
- r = command (&out, &err, "parted", "-m", "--", device,
+ r = command (&out, &err, str_parted, "-m", "--", device,
"unit", "b",
"print", NULL);
else
- r = command (&out, &err, "parted", "-s", "--", device,
+ r = command (&out, &err, str_parted, "-s", "--", device,
"unit", "b",
"print", NULL);
if (r == -1) {
@@ -744,7 +747,7 @@ do_part_get_mbr_id (const char *device, int partnum)
udev_settle ();
- r = command (&out, &err, "sfdisk", "--print-id", device, partnum_str, NULL);
+ r = command (&out, &err, str_sfdisk, "--print-id", device, partnum_str, NULL);
if (r == -1) {
reply_with_error ("sfdisk --print-id: %s", err);
free (out);
@@ -786,7 +789,7 @@ do_part_set_mbr_id (const char *device, int partnum, int idbyte)
udev_settle ();
- r = command (NULL, &err, "sfdisk",
+ r = command (NULL, &err, str_sfdisk,
"--change-id", device, partnum_str, idbyte_str, NULL);
if (r == -1) {
reply_with_error ("sfdisk --change-id: %s", err);
diff --git a/daemon/rsync.c b/daemon/rsync.c
index 95f0f86..f5fa907 100644
--- a/daemon/rsync.c
+++ b/daemon/rsync.c
@@ -30,10 +30,12 @@
#define MAX_ARGS 64
+GUESTFS_EXT_CMD(str_rsync, rsync);
+
int
optgroup_rsync_available (void)
{
- return prog_exists ("rsync");
+ return prog_exists (str_rsync);
}
static int
@@ -46,7 +48,7 @@ rsync (const char *src, const char *src_orig,
int r;
char *err;
- ADD_ARG (argv, i, "rsync");
+ ADD_ARG (argv, i, str_rsync);
if (archive)
ADD_ARG (argv, i, "--archive");
diff --git a/daemon/scrub.c b/daemon/scrub.c
index 2cef69d..b3096cb 100644
--- a/daemon/scrub.c
+++ b/daemon/scrub.c
@@ -28,10 +28,12 @@
#include "actions.h"
#include "optgroups.h"
+GUESTFS_EXT_CMD(str_scrub, scrub);
+
int
optgroup_scrub_available (void)
{
- return prog_exists ("scrub");
+ return prog_exists (str_scrub);
}
int
@@ -40,7 +42,7 @@ do_scrub_device (const char *device)
char *err;
int r;
- r = command (NULL, &err, "scrub", device, NULL);
+ r = command (NULL, &err, str_scrub, device, NULL);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
free (err);
@@ -66,7 +68,7 @@ do_scrub_file (const char *file)
return -1;
}
- r = command (NULL, &err, "scrub", "-r", buf, NULL);
+ r = command (NULL, &err, str_scrub, "-r", buf, NULL);
free (buf);
if (r == -1) {
reply_with_error ("%s: %s", file, err);
@@ -93,7 +95,7 @@ do_scrub_freespace (const char *dir)
return -1;
}
- r = command (NULL, &err, "scrub", "-X", buf, NULL);
+ r = command (NULL, &err, str_scrub, "-X", buf, NULL);
free (buf);
if (r == -1) {
reply_with_error ("%s: %s", dir, err);
diff --git a/daemon/sfdisk.c b/daemon/sfdisk.c
index 8221ffa..5f9bfd6 100644
--- a/daemon/sfdisk.c
+++ b/daemon/sfdisk.c
@@ -29,6 +29,9 @@
#include "daemon.h"
#include "actions.h"
+GUESTFS_EXT_CMD(str_sfdisk, sfdisk);
+GUESTFS_EXT_CMD(str_blockdev, blockdev);
+
static int
sfdisk (const char *device, int n, int cyls, int heads, int sectors,
const char *extra_flag,
@@ -38,7 +41,7 @@ sfdisk (const char *device, int n, int cyls, int heads, int sectors,
char buf[256];
int i;
- strcpy (buf, "sfdisk");
+ strcpy (buf, str_sfdisk);
if (n > 0)
sprintf (buf + strlen (buf), " -N %d", n);
@@ -101,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, "blockdev", "--rereadpt", device, NULL);
+ (void) command (NULL, NULL, str_blockdev, "--rereadpt", device, NULL);
udev_settle ();
@@ -136,7 +139,7 @@ sfdisk_flag (const char *device, const char *flag)
char *out, *err;
int r;
- r = command (&out, &err, "sfdisk", flag, device, NULL);
+ r = command (&out, &err, str_sfdisk, flag, device, NULL);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
free (out);
diff --git a/daemon/swap.c b/daemon/swap.c
index 8f1b59d..9fe1b17 100644
--- a/daemon/swap.c
+++ b/daemon/swap.c
@@ -30,6 +30,10 @@
#include "ignore-value.h"
+GUESTFS_EXT_CMD(str_mkswap, mkswap);
+GUESTFS_EXT_CMD(str_swapon, swapon);
+GUESTFS_EXT_CMD(str_swapoff, swapoff);
+
/* Confirmed this is true for Linux swap partitions from the Linux sources. */
#define SWAP_LABEL_MAX 16
@@ -49,7 +53,7 @@ optgroup_linuxfsuuid_available (void)
* return code.
*/
ignore_value (commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
- "mkswap", "--help", NULL));
+ str_mkswap, "--help", NULL));
av = strstr (err, "-U") != NULL;
free (err);
@@ -66,7 +70,7 @@ do_mkswap (const char *device, const char *label, const char *uuid)
int r;
char *err;
- ADD_ARG (argv, i, "mkswap");
+ ADD_ARG (argv, i, str_mkswap);
ADD_ARG (argv, i, "-f");
if (optargs_bitmask & GUESTFS_MKSWAP_LABEL_BITMASK) {
@@ -129,7 +133,7 @@ do_mkswap_file (const char *path)
return -1;
}
- r = command (NULL, &err, "mkswap", "-f", buf, NULL);
+ r = command (NULL, &err, str_mkswap, "-f", buf, NULL);
free (buf);
if (r == -1) {
@@ -173,13 +177,13 @@ swaponoff (const char *cmd, const char *flag, const char *value)
int
do_swapon_device (const char *device)
{
- return swaponoff ("swapon", NULL, device);
+ return swaponoff (str_swapon, NULL, device);
}
int
do_swapoff_device (const char *device)
{
- return swaponoff ("swapoff", NULL, device);
+ return swaponoff (str_swapoff, NULL, device);
}
int
@@ -194,7 +198,7 @@ do_swapon_file (const char *path)
return -1;
}
- r = swaponoff ("swapon", NULL, buf);
+ r = swaponoff (str_swapon, NULL, buf);
free (buf);
return r;
}
@@ -211,7 +215,7 @@ do_swapoff_file (const char *path)
return -1;
}
- r = swaponoff ("swapoff", NULL, buf);
+ r = swaponoff (str_swapoff, NULL, buf);
free (buf);
return r;
}
@@ -225,7 +229,7 @@ do_swapon_label (const char *label)
return -1;
}
- return swaponoff ("swapon", "-L", label);
+ return swaponoff (str_swapon, "-L", label);
}
int
@@ -237,17 +241,17 @@ do_swapoff_label (const char *label)
return -1;
}
- return swaponoff ("swapoff", "-L", label);
+ return swaponoff (str_swapoff, "-L", label);
}
int
do_swapon_uuid (const char *uuid)
{
- return swaponoff ("swapon", "-U", uuid);
+ return swaponoff (str_swapon, "-U", uuid);
}
int
do_swapoff_uuid (const char *uuid)
{
- return swaponoff ("swapoff", "-U", uuid);
+ return swaponoff (str_swapoff, "-U", uuid);
}
diff --git a/daemon/tar.c b/daemon/tar.c
index 13f87e7..86987b1 100644
--- a/daemon/tar.c
+++ b/daemon/tar.c
@@ -30,6 +30,8 @@
#include "actions.h"
#include "optgroups.h"
+GUESTFS_EXT_CMD(str_tar, tar);
+
int
optgroup_xz_available (void)
{
@@ -155,7 +157,8 @@ do_tar_in (const char *dir, const char *compress)
close (fd);
/* "tar -C /sysroot%s -xf -" but we have to quote the dir. */
- if (asprintf_nowarn (&cmd, "tar -C %R%s -xf - %s2> %s",
+ if (asprintf_nowarn (&cmd, "%s -C %R%s -xf - %s2> %s",
+ str_tar,
dir, filter,
chown_supported ? "" : "--no-same-owner ",
error_file) == -1) {
@@ -321,7 +324,8 @@ do_tar_out (const char *dir, const char *compress, int numericowner,
}
/* "tar -C /sysroot%s -cf - ." but we have to quote the dir. */
- if (asprintf_nowarn (&cmd, "tar -C %R%s%s%s -cf - .",
+ if (asprintf_nowarn (&cmd, "%s -C %R%s%s%s -cf - .",
+ str_tar,
dir, filter,
numericowner ? " --numeric-owner" : "",
excludes_args) == -1) {
diff --git a/daemon/xfs.c b/daemon/xfs.c
index 5c65db1..907e68a 100644
--- a/daemon/xfs.c
+++ b/daemon/xfs.c
@@ -30,10 +30,15 @@
#define MAX_ARGS 64
+GUESTFS_EXT_CMD(str_mkfs_xfs, mkfs.xfs);
+GUESTFS_EXT_CMD(str_xfs_admin, xfs_admin);
+GUESTFS_EXT_CMD(str_xfs_info, xfs_info);
+GUESTFS_EXT_CMD(str_xfs_growfs, xfs_growfs);
+
int
optgroup_xfs_available (void)
{
- return prog_exists ("mkfs.xfs");
+ return prog_exists (str_mkfs_xfs);
}
static char *
@@ -330,7 +335,7 @@ do_xfs_info (const char *pathordevice)
return NULL;
}
- r = command (&out, &err, "xfs_info", buf, NULL);
+ r = command (&out, &err, str_xfs_info, buf, NULL);
free (buf);
if (r == -1) {
reply_with_error ("%s", err);
@@ -374,7 +379,7 @@ do_xfs_growfs (const char *path,
return -1;
}
- ADD_ARG (argv, i, "xfs_growfs");
+ ADD_ARG (argv, i, str_xfs_growfs);
/* Optional arguments */
if (!(optargs_bitmask & GUESTFS_XFS_GROWFS_DATASEC_BITMASK))
@@ -471,7 +476,7 @@ do_xfs_admin (const char *device,
const char *argv[MAX_ARGS];
size_t i = 0;
- ADD_ARG (argv, i, "xfs_admin");
+ ADD_ARG (argv, i, str_xfs_admin);
/* Optional arguments */
if (!(optargs_bitmask & GUESTFS_XFS_ADMIN_EXTUNWRITTEN_BITMASK))
diff --git a/daemon/zero.c b/daemon/zero.c
index 14aef75..22d2958 100644
--- a/daemon/zero.c
+++ b/daemon/zero.c
@@ -30,6 +30,8 @@
#include "actions.h"
#include "optgroups.h"
+GUESTFS_EXT_CMD(str_wipefs, wipefs);
+
static const char zero_buf[4096];
int
@@ -77,7 +79,7 @@ do_zero (const char *device)
int
optgroup_wipefs_available (void)
{
- return prog_exists ("wipefs");
+ return prog_exists (str_wipefs);
}
int
@@ -86,7 +88,7 @@ do_wipefs (const char *device)
int r;
char *err = NULL;
- const char *wipefs[] = {"wipefs", "-a", device, NULL};
+ const char *wipefs[] = {str_wipefs, "-a", device, NULL};
r = commandv (NULL, &err, wipefs);
if (r == -1) {
reply_with_error ("%s", err);
diff --git a/daemon/zerofree.c b/daemon/zerofree.c
index e9be8fc..d64a93d 100644
--- a/daemon/zerofree.c
+++ b/daemon/zerofree.c
@@ -28,10 +28,12 @@
#include "actions.h"
#include "optgroups.h"
+GUESTFS_EXT_CMD(str_zerofree, zerofree);
+
int
optgroup_zerofree_available (void)
{
- return prog_exists ("zerofree");
+ return prog_exists (str_zerofree);
}
int
@@ -40,7 +42,7 @@ do_zerofree (const char *device)
char *err;
int r;
- r = command (NULL, &err, "zerofree", device, NULL);
+ r = command (NULL, &err, str_zerofree, device, NULL);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
free (err);
--
1.7.11.5
12 years
[PATCH v2] daemon: collect list of called external commands
by Olaf Hering
guestfsd calls many different tools. Keeping track of all of them is
error prone. This patch introduces a new helper macro to put the command
string into its own ELF section:
GUESTFSD_EXT_CMD(C_variable, command_name);
This syntax makes it still possible to grep for used command names.
The actual usage of the collected list could be like this:
objcopy -j .guestfsd_ext_cmds -O binary daemon/guestfsd /dev/stdout | strings | sort -u
The resulting output will be used to tell mkinitrd which programs to
copy into the initrd.
Signed-off-by: Olaf Hering <olaf(a)aepfle.de>
---
(still not runtime tested)
v2:
rename "guestfs" strings to "guestfsd"
rebase to 1.9.36 and incluce new xfs command
contrib/intro/libguestfs-intro.html | 3 +-
daemon/9p.c | 3 +-
daemon/available.c | 7 ++--
daemon/base64.c | 6 ++--
daemon/blkid.c | 10 +++---
daemon/blockdev.c | 4 ++-
daemon/btrfs.c | 33 +++++++++++--------
daemon/checksum.c | 6 +++-
daemon/cmp.c | 4 ++-
daemon/command.c | 15 +++++----
daemon/compress.c | 24 ++++++++------
daemon/cpmv.c | 9 ++++--
daemon/daemon.h | 3 ++
daemon/dd.c | 4 ++-
daemon/debug.c | 35 +++++++++++++-------
daemon/df.c | 6 ++--
daemon/dir.c | 4 ++-
daemon/dmesg.c | 4 ++-
daemon/du.c | 4 ++-
daemon/ext2.c | 43 ++++++++++++++-----------
daemon/file.c | 10 ++++--
daemon/find.c | 4 ++-
daemon/findfs.c | 4 ++-
daemon/fsck.c | 4 ++-
daemon/fstrim.c | 6 ++--
daemon/grub.c | 6 ++--
daemon/guestfsd.c | 7 ++--
daemon/initrd.c | 5 ++-
daemon/inotify.c | 4 ++-
daemon/isoinfo.c | 4 ++-
daemon/labels.c | 7 ++--
daemon/link.c | 6 ++--
daemon/ls.c | 6 ++--
daemon/luks.c | 14 ++++----
daemon/lvm-filter.c | 13 +++++---
daemon/lvm.c | 64 +++++++++++++++++++------------------
daemon/md.c | 10 +++---
daemon/mkfs.c | 7 ++--
daemon/modprobe.c | 6 ++--
daemon/mount.c | 13 +++++---
daemon/ntfs.c | 14 +++++---
daemon/ntfsclone.c | 9 ++++--
daemon/parted.c | 25 ++++++++-------
daemon/rsync.c | 6 ++--
daemon/scrub.c | 10 +++---
daemon/sfdisk.c | 9 ++++--
daemon/swap.c | 26 ++++++++-------
daemon/tar.c | 8 +++--
daemon/xfs.c | 16 +++++++---
daemon/zero.c | 6 ++--
daemon/zerofree.c | 6 ++--
51 Dateien geändert, 357 Zeilen hinzugefügt(+), 205 Zeilen entfernt(-)
diff --git a/contrib/intro/libguestfs-intro.html b/contrib/intro/libguestfs-intro.html
index 380e290..52dcce5 100644
--- a/contrib/intro/libguestfs-intro.html
+++ b/contrib/intro/libguestfs-intro.html
@@ -119,6 +119,7 @@ char *
return get_blkid_tag (device, "TYPE");
}
+GUESTFSD_EXT_CMD(str_blkid, blkid);
static char *
get_blkid_tag (const char *device, const char *tag)
{
@@ -126,7 +127,7 @@ get_blkid_tag (const char *device, const char *tag)
int r;
r = commandr (&out, &err,
- "blkid",
+ str_blkid,
"-c", "/dev/null",
"-o", "value", "-s", tag, device, NULL);
if (r != 0 && r != 2) {
diff --git a/daemon/9p.c b/daemon/9p.c
index 8c0eeb6..49efafc 100644
--- a/daemon/9p.c
+++ b/daemon/9p.c
@@ -33,6 +33,7 @@
#include "actions.h"
#define BUS_PATH "/sys/bus/virtio/drivers/9pnet_virtio"
+GUESTFSD_EXT_CMD(str_mount, mount);
static char *read_whole_file (const char *filename);
@@ -211,7 +212,7 @@ do_mount_9p (const char *mount_tag, const char *mountpoint, const char *options)
}
r = command (NULL, &err,
- "mount", "-o", opts, "-t", "9p", mount_tag, mp, NULL);
+ str_mount, "-o", opts, "-t", "9p", mount_tag, mp, NULL);
if (r == -1) {
reply_with_error ("%s on %s: %s", mount_tag, mountpoint, err);
goto out;
diff --git a/daemon/available.c b/daemon/available.c
index 08e72f3..7bd8a3c 100644
--- a/daemon/available.c
+++ b/daemon/available.c
@@ -29,6 +29,9 @@
#include "actions.h"
#include "optgroups.h"
+GUESTFSD_EXT_CMD(str_grep, grep);
+GUESTFSD_EXT_CMD(str_modprobe, modprobe);
+
int
do_available (char *const *groups)
{
@@ -85,7 +88,7 @@ test_proc_filesystems (const char *filesystem)
snprintf (regex, len, "^[[:space:]]*%s$", filesystem);
- r = commandr (NULL, &err, "grep", regex, "/proc/filesystems", NULL);
+ r = commandr (NULL, &err, str_grep, regex, "/proc/filesystems", NULL);
if (r == -1 || r >= 2) {
fprintf (stderr, "grep /proc/filesystems: %s", err);
free (err);
@@ -100,7 +103,7 @@ test_proc_filesystems (const char *filesystem)
static void
modprobe (const char *module)
{
- command (NULL, NULL, "modprobe", module, NULL);
+ command (NULL, NULL, str_modprobe, module, NULL);
}
/* Internal function for testing if a filesystem is available. Note
diff --git a/daemon/base64.c b/daemon/base64.c
index 215812a..fcbeec8 100644
--- a/daemon/base64.c
+++ b/daemon/base64.c
@@ -27,6 +27,8 @@
#include "daemon.h"
#include "actions.h"
+GUESTFSD_EXT_CMD(str_base64, base64);
+
static int
write_cb (void *fd_ptr, const void *buf, size_t len)
{
@@ -42,7 +44,7 @@ do_base64_in (const char *file)
FILE *fp;
char *cmd;
- if (asprintf_nowarn (&cmd, "base64 -d -i > %R", file) == -1) {
+ if (asprintf_nowarn (&cmd, "%s -d -i > %R", str_base64, file) == -1) {
err = errno;
cancel_receive ();
errno = err;
@@ -102,7 +104,7 @@ do_base64_out (const char *file)
char *cmd;
char buf[GUESTFS_MAX_CHUNK_SIZE];
- if (asprintf_nowarn (&cmd, "base64 %R", file) == -1) {
+ if (asprintf_nowarn (&cmd, "%s %R", str_base64, file) == -1) {
reply_with_perror ("asprintf");
return -1;
}
diff --git a/daemon/blkid.c b/daemon/blkid.c
index 7cc7889..b6bc22d 100644
--- a/daemon/blkid.c
+++ b/daemon/blkid.c
@@ -27,6 +27,8 @@
#include "daemon.h"
#include "actions.h"
+GUESTFSD_EXT_CMD(str_blkid, blkid);
+
static char *
get_blkid_tag (const char *device, const char *tag)
{
@@ -34,7 +36,7 @@ get_blkid_tag (const char *device, const char *tag)
int r;
r = commandr (&out, &err,
- "blkid",
+ str_blkid,
/* Adding -c option kills all caching, even on RHEL 5. */
"-c", "/dev/null",
"-o", "value", "-s", tag, device, NULL);
@@ -96,7 +98,7 @@ test_blkid_p_i_opt (void)
int r;
char *err;
- r = commandr (NULL, &err, "blkid", "-p", "/dev/null", NULL);
+ r = commandr (NULL, &err, str_blkid, "-p", "/dev/null", NULL);
if (r == -1) {
/* This means we couldn't run the blkid command at all. */
command_failed:
@@ -111,7 +113,7 @@ test_blkid_p_i_opt (void)
}
free (err);
- r = commandr (NULL, &err, "blkid", "-i", NULL);
+ r = commandr (NULL, &err, str_blkid, "-i", NULL);
if (r == -1)
goto command_failed;
@@ -134,7 +136,7 @@ blkid_with_p_i_opt (const char *device)
char **lines = NULL;
DECLARE_STRINGSBUF (ret);
- r = command (&out, &err, "blkid", "-c", "/dev/null",
+ r = command (&out, &err, str_blkid, "-c", "/dev/null",
"-p", "-i", "-o", "export", device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
diff --git a/daemon/blockdev.c b/daemon/blockdev.c
index a7fd2cb..f216bf7 100644
--- a/daemon/blockdev.c
+++ b/daemon/blockdev.c
@@ -28,6 +28,8 @@
#include "daemon.h"
#include "actions.h"
+GUESTFSD_EXT_CMD(str_blockdev, blockdev);
+
/* These functions are all about using the blockdev command, so
* we centralize it in one call.
*/
@@ -38,7 +40,7 @@ call_blockdev (const char *device, const char *switc, int extraarg, int prints)
int64_t rv;
char *out, *err;
const char *argv[] = {
- "blockdev",
+ str_blockdev,
switc,
NULL,
NULL,
diff --git a/daemon/btrfs.c b/daemon/btrfs.c
index 411fdea..8ecde01 100644
--- a/daemon/btrfs.c
+++ b/daemon/btrfs.c
@@ -28,10 +28,15 @@
#include "actions.h"
#include "optgroups.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);
+
int
optgroup_btrfs_available (void)
{
- return prog_exists ("btrfs") && filesystem_available ("btrfs") > 0;
+ return prog_exists (str_btrfs) && filesystem_available ("btrfs") > 0;
}
/* Takes optional arguments, consult optargs_bitmask. */
@@ -46,7 +51,7 @@ do_btrfs_filesystem_resize (const char *filesystem, int64_t size)
size_t i = 0;
char size_str[32];
- ADD_ARG (argv, i, "btrfs");
+ ADD_ARG (argv, i, str_btrfs);
ADD_ARG (argv, i, "filesystem");
ADD_ARG (argv, i, "resize");
@@ -109,7 +114,7 @@ do_mkfs_btrfs (char *const *devices,
char nodesize_s[64];
char sectorsize_s[64];
- ADD_ARG (argv, i, "mkfs.btrfs");
+ ADD_ARG (argv, i, str_mkfs_btrfs);
/* Optional arguments. */
if (optargs_bitmask & GUESTFS_MKFS_BTRFS_ALLOCSTART_BITMASK) {
@@ -225,7 +230,7 @@ do_btrfs_subvolume_snapshot (const char *source, const char *dest)
return -1;
}
- ADD_ARG (argv, i, "btrfs");
+ ADD_ARG (argv, i, str_btrfs);
ADD_ARG (argv, i, "subvolume");
ADD_ARG (argv, i, "snapshot");
ADD_ARG (argv, i, source_buf);
@@ -261,7 +266,7 @@ do_btrfs_subvolume_delete (const char *subvolume)
return -1;
}
- ADD_ARG (argv, i, "btrfs");
+ ADD_ARG (argv, i, str_btrfs);
ADD_ARG (argv, i, "subvolume");
ADD_ARG (argv, i, "delete");
ADD_ARG (argv, i, subvolume_buf);
@@ -295,7 +300,7 @@ do_btrfs_subvolume_create (const char *dest)
return -1;
}
- ADD_ARG (argv, i, "btrfs");
+ ADD_ARG (argv, i, str_btrfs);
ADD_ARG (argv, i, "subvolume");
ADD_ARG (argv, i, "create");
ADD_ARG (argv, i, dest_buf);
@@ -331,7 +336,7 @@ do_btrfs_subvolume_list (const char *fs)
return NULL;
}
- ADD_ARG (argv, i, "btrfs");
+ ADD_ARG (argv, i, str_btrfs);
ADD_ARG (argv, i, "subvolume");
ADD_ARG (argv, i, "list");
ADD_ARG (argv, i, fs_buf);
@@ -428,7 +433,7 @@ do_btrfs_subvolume_set_default (int64_t id, const char *fs)
return -1;
}
- ADD_ARG (argv, i, "btrfs");
+ ADD_ARG (argv, i, str_btrfs);
ADD_ARG (argv, i, "subvolume");
ADD_ARG (argv, i, "set-default");
ADD_ARG (argv, i, buf);
@@ -463,7 +468,7 @@ do_btrfs_filesystem_sync (const char *fs)
return -1;
}
- ADD_ARG (argv, i, "btrfs");
+ ADD_ARG (argv, i, str_btrfs);
ADD_ARG (argv, i, "filesystem");
ADD_ARG (argv, i, "sync");
ADD_ARG (argv, i, fs_buf);
@@ -497,7 +502,7 @@ do_btrfs_filesystem_balance (const char *fs)
return -1;
}
- ADD_ARG (argv, i, "btrfs");
+ ADD_ARG (argv, i, str_btrfs);
ADD_ARG (argv, i, "filesystem");
ADD_ARG (argv, i, "balance");
ADD_ARG (argv, i, fs_buf);
@@ -536,7 +541,7 @@ do_btrfs_device_add (char *const *devices, const char *fs)
return -1;
}
- ADD_ARG (argv, i, "btrfs");
+ ADD_ARG (argv, i, str_btrfs);
ADD_ARG (argv, i, "device");
ADD_ARG (argv, i, "add");
@@ -579,7 +584,7 @@ do_btrfs_device_delete (char *const *devices, const char *fs)
return -1;
}
- ADD_ARG (argv, i, "btrfs");
+ ADD_ARG (argv, i, str_btrfs);
ADD_ARG (argv, i, "device");
ADD_ARG (argv, i, "delete");
@@ -609,7 +614,7 @@ do_btrfs_set_seeding (const char *device, int svalue)
const char *s_value = svalue ? "1" : "0";
- r = commandr (NULL, &err, "btrfstune", "-S", s_value, device, NULL);
+ r = commandr (NULL, &err, str_btrfstune, "-S", s_value, device, NULL);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
free (err);
@@ -631,7 +636,7 @@ do_btrfs_fsck (const char *device, int64_t superblock, int repair)
const char *argv[MAX_ARGS];
char super_s[64];
- ADD_ARG (argv, i, "btrfsck");
+ ADD_ARG (argv, i, str_btrfsck);
/* Optional arguments. */
if (optargs_bitmask & GUESTFS_BTRFS_FSCK_SUPERBLOCK_BITMASK) {
diff --git a/daemon/checksum.c b/daemon/checksum.c
index 2cc4a2b..f2e040d 100644
--- a/daemon/checksum.c
+++ b/daemon/checksum.c
@@ -29,6 +29,9 @@
#include "daemon.h"
#include "actions.h"
+GUESTFSD_EXT_CMD(str_find, find);
+GUESTFSD_EXT_CMD(str_xargs, xargs);
+
static const char *
program_of_csum (const char *csumtype)
{
@@ -150,7 +153,8 @@ do_checksums_out (const char *csumtype, const char *dir)
}
char *cmd;
- if (asprintf_nowarn (&cmd, "cd %Q && find -type f -print0 | xargs -0 %s",
+ if (asprintf_nowarn (&cmd, "cd %Q && %s -type f -print0 | %s -0 %s",
+ str_find, str_xargs,
sysrootdir, program) == -1) {
reply_with_perror ("asprintf");
free (sysrootdir);
diff --git a/daemon/cmp.c b/daemon/cmp.c
index 0673403..89da3b8 100644
--- a/daemon/cmp.c
+++ b/daemon/cmp.c
@@ -27,6 +27,8 @@
#include "daemon.h"
#include "actions.h"
+GUESTFSD_EXT_CMD(str_cmp, cmp);
+
int
do_equal (const char *file1, const char *file2)
{
@@ -47,7 +49,7 @@ do_equal (const char *file1, const char *file2)
return -1;
}
- r = commandr (NULL, &err, "cmp", "-s", file1buf, file2buf, NULL);
+ r = commandr (NULL, &err, str_cmp, "-s", file1buf, file2buf, NULL);
free (file1buf);
free (file2buf);
diff --git a/daemon/command.c b/daemon/command.c
index 7c67d83..5839033 100644
--- a/daemon/command.c
+++ b/daemon/command.c
@@ -28,10 +28,13 @@
#include "ignore-value.h"
+GUESTFSD_EXT_CMD(str_mount, mount);
+GUESTFSD_EXT_CMD(str_umount, umount);
+
static inline void
umount_ignore_fail (const char *path)
{
- ignore_value (command (NULL, NULL, "umount", path, NULL));
+ ignore_value (command (NULL, NULL, str_umount, path, NULL));
}
char *
@@ -81,15 +84,15 @@ do_command (char *const *argv)
return NULL;
}
- r = command (NULL, NULL, "mount", "--bind", "/dev", sysroot_dev, NULL);
+ r = command (NULL, NULL, str_mount, "--bind", "/dev", sysroot_dev, NULL);
dev_ok = r != -1;
- r = command (NULL, NULL, "mount", "--bind", "/dev/pts", sysroot_dev_pts, NULL);
+ r = command (NULL, NULL, str_mount, "--bind", "/dev/pts", sysroot_dev_pts, NULL);
dev_pts_ok = r != -1;
- r = command (NULL, NULL, "mount", "--bind", "/proc", sysroot_proc, NULL);
+ r = command (NULL, NULL, str_mount, "--bind", "/proc", sysroot_proc, NULL);
proc_ok = r != -1;
- r = command (NULL, NULL, "mount", "--bind", "/selinux", sysroot_selinux, NULL);
+ r = command (NULL, NULL, str_mount, "--bind", "/selinux", sysroot_selinux, NULL);
selinux_ok = r != -1;
- r = command (NULL, NULL, "mount", "--bind", "/sys", sysroot_sys, NULL);
+ r = command (NULL, NULL, str_mount, "--bind", "/sys", sysroot_sys, NULL);
sys_ok = r != -1;
CHROOT_IN;
diff --git a/daemon/compress.c b/daemon/compress.c
index b9967d9..3dc398e 100644
--- a/daemon/compress.c
+++ b/daemon/compress.c
@@ -27,6 +27,12 @@
#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);
+
/* Has one FileOut parameter. */
static int
do_compressX_out (const char *file, const char *filter, int is_device)
@@ -118,15 +124,15 @@ get_filter (const char *ctype, int level, char *ret, size_t n)
reply_with_error ("compress: cannot use optional level parameter with this compression type");
return -1;
}
- snprintf (ret, n, "compress -c");
+ snprintf (ret, n, "%s -c", str_compress);
return 0;
}
else if (STREQ (ctype, "gzip")) {
CHECK_SUPPORTED ("gzip");
if (level == -1)
- snprintf (ret, n, "gzip -c");
+ snprintf (ret, n, "%s -c", str_gzip);
else if (level >= 1 && level <= 9)
- snprintf (ret, n, "gzip -c -%d", level);
+ snprintf (ret, n, "%s -c -%d", str_gzip, level);
else {
reply_with_error ("gzip: incorrect value for level parameter");
return -1;
@@ -136,9 +142,9 @@ get_filter (const char *ctype, int level, char *ret, size_t n)
else if (STREQ (ctype, "bzip2")) {
CHECK_SUPPORTED ("bzip2");
if (level == -1)
- snprintf (ret, n, "bzip2 -c");
+ snprintf (ret, n, "%s -c", str_bzip2);
else if (level >= 1 && level <= 9)
- snprintf (ret, n, "bzip2 -c -%d", level);
+ snprintf (ret, n, "%s -c -%d", str_bzip2, level);
else {
reply_with_error ("bzip2: incorrect value for level parameter");
return -1;
@@ -148,9 +154,9 @@ get_filter (const char *ctype, int level, char *ret, size_t n)
else if (STREQ (ctype, "xz")) {
CHECK_SUPPORTED ("xz");
if (level == -1)
- snprintf (ret, n, "xz -c");
+ snprintf (ret, n, "%s -c", str_xz);
else if (level >= 0 && level <= 9)
- snprintf (ret, n, "xz -c -%d", level);
+ snprintf (ret, n, "%s -c -%d", str_xz, level);
else {
reply_with_error ("xz: incorrect value for level parameter");
return -1;
@@ -160,9 +166,9 @@ get_filter (const char *ctype, int level, char *ret, size_t n)
else if (STREQ (ctype, "lzop")) {
CHECK_SUPPORTED ("lzop");
if (level == -1)
- snprintf (ret, n, "lzop -c");
+ snprintf (ret, n, "%s -c", str_lzop);
else if (level >= 1 && level <= 9)
- snprintf (ret, n, "lzop -c -%d", level);
+ snprintf (ret, n, "%s -c -%d", str_lzop, level);
else {
reply_with_error ("lzop: incorrect value for level parameter");
return -1;
diff --git a/daemon/cpmv.c b/daemon/cpmv.c
index ba7de2b..c182f68 100644
--- a/daemon/cpmv.c
+++ b/daemon/cpmv.c
@@ -25,24 +25,27 @@
#include "daemon.h"
#include "actions.h"
+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);
int
do_cp (const char *src, const char *dest)
{
- return cpmv_cmd ("cp", NULL, src, dest);
+ return cpmv_cmd (str_cp, NULL, src, dest);
}
int
do_cp_a (const char *src, const char *dest)
{
- return cpmv_cmd ("cp", "-a", src, dest);
+ return cpmv_cmd (str_cp, "-a", src, dest);
}
int
do_mv (const char *src, const char *dest)
{
- return cpmv_cmd ("mv", NULL, src, dest);
+ return cpmv_cmd (str_mv, NULL, src, dest);
}
static int
diff --git a/daemon/daemon.h b/daemon/daemon.h
index d17dcbd..a483208 100644
--- a/daemon/daemon.h
+++ b/daemon/daemon.h
@@ -96,6 +96,9 @@ extern char **split_lines (char *str);
#define commandv(out,err,argv) commandvf((out),(err),0,(argv))
#define commandrv(out,err,argv) commandrvf((out),(err),0,(argv))
+#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 COMMAND_FLAG_FD_MASK (1024-1)
#define COMMAND_FLAG_FOLD_STDOUT_ON_STDERR 1024
#define COMMAND_FLAG_CHROOT_COPY_FILE_TO_STDIN 2048
diff --git a/daemon/dd.c b/daemon/dd.c
index 8bc4aab..7184ab6 100644
--- a/daemon/dd.c
+++ b/daemon/dd.c
@@ -27,6 +27,8 @@
#include "daemon.h"
#include "actions.h"
+GUESTFSD_EXT_CMD(str_dd, dd);
+
int
do_dd (const char *src, const char *dest)
{
@@ -58,7 +60,7 @@ do_dd (const char *src, const char *dest)
return -1;
}
- r = command (NULL, &err, "dd", "bs=1024K", if_arg, of_arg, NULL);
+ r = command (NULL, &err, str_dd, "bs=1024K", if_arg, of_arg, NULL);
free (if_arg);
free (of_arg);
diff --git a/daemon/debug.c b/daemon/debug.c
index 97d21f0..39bda48 100644
--- a/daemon/debug.c
+++ b/daemon/debug.c
@@ -32,6 +32,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);
+
/* This command exposes debugging information, internals and
* status. There is no comprehensive documentation for this
* command. You have to look at the source code in this file
@@ -275,7 +284,7 @@ debug_env (const char *subcmd, size_t argc, char *const *const argv)
int r;
char *out, *err;
- r = command (&out, &err, "printenv", NULL);
+ r = command (&out, &err, str_printenv, NULL);
if (r == -1) {
reply_with_error ("printenv: %s", err);
free (out);
@@ -318,13 +327,17 @@ debug_binaries (const char *subcmd, size_t argc, char *const *const argv)
{
int r;
char *out, *err;
-
- const char cmd[] =
- "find / -xdev -type f -executable "
- "| xargs file -i "
- "| grep application/x-executable "
- "| gawk -F: '{print $1}'";
-
+ char cmd[123];
+
+ if (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) >= sizeof(cmd)) {
+ reply_with_error ("find: %s", err);
+ return NULL;
+ }
r = command (&out, &err, "sh", "-c", cmd, NULL);
if (r == -1) {
reply_with_error ("find: %s", err);
@@ -358,7 +371,7 @@ debug_ldd (const char *subcmd, size_t argc, char *const *const argv)
* Also 'ldd' randomly sends messages to stderr and errors to stdout
* depending on the phase of the moon.
*/
- r = command (&out, &err, "ldd", "-r", argv[0], NULL);
+ r = command (&out, &err, str_ldd, "-r", argv[0], NULL);
if (r == -1) {
reply_with_error ("ldd: %s: %s", argv[0], err);
free (out);
@@ -389,7 +402,7 @@ debug_ls (const char *subcmd, size_t argc, char *const *const argv)
const char *cargv[len+3];
size_t i;
- cargv[0] = "ls";
+ cargv[0] = str_ls;
cargv[1] = "-a";
for (i = 0; i < len; ++i)
cargv[2+i] = argv[i];
@@ -419,7 +432,7 @@ debug_ll (const char *subcmd, size_t argc, char *const *const argv)
const char *cargv[len+3];
size_t i;
- cargv[0] = "ls";
+ cargv[0] = str_ls;
cargv[1] = "-la";
for (i = 0; i < len; ++i)
cargv[2+i] = argv[i];
diff --git a/daemon/df.c b/daemon/df.c
index 14954d2..e723685 100644
--- a/daemon/df.c
+++ b/daemon/df.c
@@ -27,6 +27,8 @@
#include "daemon.h"
#include "actions.h"
+GUESTFSD_EXT_CMD(str_df, df);
+
char *
do_df (void)
{
@@ -35,7 +37,7 @@ do_df (void)
NEED_ROOT (, return NULL);
- r = command (&out, &err, "df", NULL);
+ r = command (&out, &err, str_df, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (out);
@@ -56,7 +58,7 @@ do_df_h (void)
NEED_ROOT (, return NULL);
- r = command (&out, &err, "df", "-h", NULL);
+ r = command (&out, &err, str_df, "-h", NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (out);
diff --git a/daemon/dir.c b/daemon/dir.c
index 3b18d48..aed45d6 100644
--- a/daemon/dir.c
+++ b/daemon/dir.c
@@ -29,6 +29,8 @@
#include "daemon.h"
#include "actions.h"
+GUESTFSD_EXT_CMD(str_rm, rm);
+
int
do_rmdir (const char *path)
{
@@ -67,7 +69,7 @@ do_rm_rf (const char *path)
return -1;
}
- r = command (NULL, &err, "rm", "-rf", buf, NULL);
+ r = command (NULL, &err, str_rm, "-rf", buf, NULL);
free (buf);
/* rm -rf is never supposed to fail. I/O errors perhaps? */
diff --git a/daemon/dmesg.c b/daemon/dmesg.c
index 5e98a18..69d4f37 100644
--- a/daemon/dmesg.c
+++ b/daemon/dmesg.c
@@ -27,13 +27,15 @@
#include "daemon.h"
#include "actions.h"
+GUESTFSD_EXT_CMD(str_dmesg, dmesg);
+
char *
do_dmesg (void)
{
char *out, *err;
int r;
- r = command (&out, &err, "dmesg", NULL);
+ r = command (&out, &err, str_dmesg, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (out);
diff --git a/daemon/du.c b/daemon/du.c
index 62f1142..4392bef 100644
--- a/daemon/du.c
+++ b/daemon/du.c
@@ -28,6 +28,8 @@
#include "daemon.h"
#include "actions.h"
+GUESTFSD_EXT_CMD(str_du, du);
+
int64_t
do_du (const char *path)
{
@@ -45,7 +47,7 @@ do_du (const char *path)
pulse_mode_start ();
- r = command (&out, &err, "du", "-s", buf, NULL);
+ r = command (&out, &err, str_du, "-s", buf, NULL);
free (buf);
if (r == -1) {
pulse_mode_cancel ();
diff --git a/daemon/ext2.c b/daemon/ext2.c
index 943b441..40b36d2 100644
--- a/daemon/ext2.c
+++ b/daemon/ext2.c
@@ -31,6 +31,13 @@
#define MAX_ARGS 64
+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);
+
char **
do_tune2fs_l (const char *device)
{
@@ -39,7 +46,7 @@ do_tune2fs_l (const char *device)
char *p, *pend, *colon;
DECLARE_STRINGSBUF (ret);
- r = command (&out, &err, "tune2fs", "-l", device, NULL);
+ r = command (&out, &err, str_tune2fs, "-l", device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -135,7 +142,7 @@ do_set_e2uuid (const char *device, const char *uuid)
int r;
char *err;
- r = command (NULL, &err, "tune2fs", "-U", uuid, device, NULL);
+ r = command (NULL, &err, str_tune2fs, "-U", uuid, device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -164,7 +171,7 @@ if_not_mounted_run_e2fsck (const char *device)
return -1;
if (!mounted) {
- r = command (NULL, &err, "e2fsck", "-fy", device, NULL);
+ r = command (NULL, &err, str_e2fsck, "-fy", device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -185,7 +192,7 @@ do_resize2fs (const char *device)
if (if_not_mounted_run_e2fsck (device) == -1)
return -1;
- r = command (NULL, &err, "resize2fs", device, NULL);
+ r = command (NULL, &err, str_resize2fs, device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -219,7 +226,7 @@ do_resize2fs_size (const char *device, int64_t size)
char buf[32];
snprintf (buf, sizeof buf, "%" PRIi64 "K", size);
- r = command (NULL, &err, "resize2fs", device, buf, NULL);
+ r = command (NULL, &err, str_resize2fs, device, buf, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -239,7 +246,7 @@ do_resize2fs_M (const char *device)
if (if_not_mounted_run_e2fsck (device) == -1)
return -1;
- r = command (NULL, &err, "resize2fs", "-M", device, NULL);
+ r = command (NULL, &err, str_resize2fs, "-M", device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -272,7 +279,7 @@ do_e2fsck (const char *device,
return -1;
}
- ADD_ARG (argv, i, "e2fsck");
+ ADD_ARG (argv, i, str_e2fsck);
ADD_ARG (argv, i, "-f");
if (correct)
@@ -319,7 +326,7 @@ do_mke2journal (int blocksize, const char *device)
snprintf (blocksize_s, sizeof blocksize_s, "%d", blocksize);
r = command (NULL, &err,
- "mke2fs", "-F", "-O", "journal_dev", "-b", blocksize_s,
+ str_mke2fs, "-F", "-O", "journal_dev", "-b", blocksize_s,
device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
@@ -347,7 +354,7 @@ do_mke2journal_L (int blocksize, const char *label, const char *device)
snprintf (blocksize_s, sizeof blocksize_s, "%d", blocksize);
r = command (NULL, &err,
- "mke2fs", "-F", "-O", "journal_dev", "-b", blocksize_s,
+ str_mke2fs, "-F", "-O", "journal_dev", "-b", blocksize_s,
"-L", label,
device, NULL);
if (r == -1) {
@@ -370,7 +377,7 @@ do_mke2journal_U (int blocksize, const char *uuid, const char *device)
snprintf (blocksize_s, sizeof blocksize_s, "%d", blocksize);
r = command (NULL, &err,
- "mke2fs", "-F", "-O", "journal_dev", "-b", blocksize_s,
+ str_mke2fs, "-F", "-O", "journal_dev", "-b", blocksize_s,
"-U", uuid,
device, NULL);
if (r == -1) {
@@ -398,7 +405,7 @@ do_mke2fs_J (const char *fstype, int blocksize, const char *device,
snprintf (jdev, len+32, "device=%s", journal);
r = command (NULL, &err,
- "mke2fs", "-F", "-t", fstype, "-J", jdev, "-b", blocksize_s,
+ str_mke2fs, "-F", "-t", fstype, "-J", jdev, "-b", blocksize_s,
device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
@@ -431,7 +438,7 @@ do_mke2fs_JL (const char *fstype, int blocksize, const char *device,
snprintf (jdev, len+32, "device=LABEL=%s", label);
r = command (NULL, &err,
- "mke2fs", "-F", "-t", fstype, "-J", jdev, "-b", blocksize_s,
+ str_mke2fs, "-F", "-t", fstype, "-J", jdev, "-b", blocksize_s,
device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
@@ -458,7 +465,7 @@ do_mke2fs_JU (const char *fstype, int blocksize, const char *device,
snprintf (jdev, len+32, "device=UUID=%s", uuid);
r = command (NULL, &err,
- "mke2fs", "-F", "-t", fstype, "-J", jdev, "-b", blocksize_s,
+ str_mke2fs, "-F", "-t", fstype, "-J", jdev, "-b", blocksize_s,
device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
@@ -496,7 +503,7 @@ do_tune2fs (const char *device, /* only required parameter */
char reservedblockscount_s[64];
char user_s[64];
- ADD_ARG (argv, i, "tune2fs");
+ ADD_ARG (argv, i, str_tune2fs);
if (optargs_bitmask & GUESTFS_TUNE2FS_FORCE_BITMASK) {
if (force)
@@ -635,7 +642,7 @@ do_get_e2attrs (const char *filename)
return NULL;
}
- r = command (&out, &err, "lsattr", "-d", "--", buf, NULL);
+ r = command (&out, &err, str_lsattr, "-d", "--", buf, NULL);
free (buf);
if (r == -1) {
reply_with_error ("%s: %s: %s", "lsattr", filename, err);
@@ -729,7 +736,7 @@ do_set_e2attrs (const char *filename, const char *attrs, int clear)
return -1;
}
- r = command (NULL, &err, "chattr", attr_arg, "--", buf, NULL);
+ r = command (NULL, &err, str_chattr, attr_arg, "--", buf, NULL);
free (buf);
if (r == -1) {
reply_with_error ("%s: %s: %s", "chattr", filename, err);
@@ -755,7 +762,7 @@ do_get_e2generation (const char *filename)
return -1;
}
- r = command (&out, &err, "lsattr", "-dv", "--", buf, NULL);
+ r = command (&out, &err, str_lsattr, "-dv", "--", buf, NULL);
free (buf);
if (r == -1) {
reply_with_error ("%s: %s: %s", "lsattr", filename, err);
@@ -793,7 +800,7 @@ do_set_e2generation (const char *filename, int64_t generation)
snprintf (generation_str, sizeof generation_str,
"%" PRIu64, (uint64_t) generation);
- r = command (NULL, &err, "chattr", "-v", generation_str, "--", buf, NULL);
+ r = command (NULL, &err, str_chattr, "-v", generation_str, "--", buf, NULL);
free (buf);
if (r == -1) {
reply_with_error ("%s: %s: %s", "chattr", filename, err);
diff --git a/daemon/file.c b/daemon/file.c
index 2756755..a5b3e85 100644
--- a/daemon/file.c
+++ b/daemon/file.c
@@ -29,6 +29,10 @@
#include "daemon.h"
#include "actions.h"
+GUESTFSD_EXT_CMD(str_file, file);
+GUESTFSD_EXT_CMD(str_zcat, zcat);
+GUESTFSD_EXT_CMD(str_bzcat, bzcat);
+
int
do_touch (const char *path)
{
@@ -473,7 +477,7 @@ do_file (const char *path)
const char *flags = is_dev ? "-zbsL" : "-zb";
char *out, *err;
- int r = command (&out, &err, "file", flags, path, NULL);
+ int r = command (&out, &err, str_file, flags, path, NULL);
free (buf);
if (r == -1) {
@@ -503,9 +507,9 @@ do_zfile (const char *method, const char *path)
char line[256];
if (STREQ (method, "gzip") || STREQ (method, "compress"))
- zcat = "zcat";
+ zcat = str_zcat;
else if (STREQ (method, "bzip2"))
- zcat = "bzcat";
+ zcat = str_bzcat;
else {
reply_with_error ("unknown method");
return NULL;
diff --git a/daemon/find.c b/daemon/find.c
index 2ee2cf5..060d584 100644
--- a/daemon/find.c
+++ b/daemon/find.c
@@ -30,6 +30,8 @@
#include "daemon.h"
#include "actions.h"
+GUESTFSD_EXT_CMD(str_find, find);
+
static int
input_to_nul (FILE *fp, char *buf, size_t maxlen)
{
@@ -89,7 +91,7 @@ do_find0 (const char *dir)
sysrootdirlen = strlen (sysrootdir);
- if (asprintf_nowarn (&cmd, "find %Q -print0", sysrootdir) == -1) {
+ if (asprintf_nowarn (&cmd, "%s %Q -print0", str_find, sysrootdir) == -1) {
reply_with_perror ("asprintf");
free (sysrootdir);
return -1;
diff --git a/daemon/findfs.c b/daemon/findfs.c
index 55d2d2e..3dd74b4 100644
--- a/daemon/findfs.c
+++ b/daemon/findfs.c
@@ -26,6 +26,8 @@
#include "daemon.h"
#include "actions.h"
+GUESTFSD_EXT_CMD(str_findfs, findfs);
+
static char *
findfs (const char *tag, const char *label_or_uuid)
{
@@ -42,7 +44,7 @@ findfs (const char *tag, const char *label_or_uuid)
snprintf (arg, len, "%s=%s", tag, label_or_uuid);
char *out, *err;
- int r = command (&out, &err, "findfs", arg, NULL);
+ int r = command (&out, &err, str_findfs, arg, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (out);
diff --git a/daemon/fsck.c b/daemon/fsck.c
index 7e835a7..aa3537e 100644
--- a/daemon/fsck.c
+++ b/daemon/fsck.c
@@ -26,13 +26,15 @@
#include "daemon.h"
#include "actions.h"
+GUESTFSD_EXT_CMD(str_fsck, fsck);
+
int
do_fsck (const char *fstype, const char *device)
{
char *err;
int r;
- r = commandr (NULL, &err, "fsck", "-a", "-t", fstype, device, NULL);
+ r = commandr (NULL, &err, str_fsck, "-a", "-t", fstype, device, NULL);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
free (err);
diff --git a/daemon/fstrim.c b/daemon/fstrim.c
index e2daf6a..ea47c95 100644
--- a/daemon/fstrim.c
+++ b/daemon/fstrim.c
@@ -30,10 +30,12 @@
#define MAX_ARGS 64
+GUESTFSD_EXT_CMD(str_fstrim, fstrim);
+
int
optgroup_fstrim_available (void)
{
- return prog_exists ("fstrim");
+ return prog_exists (str_fstrim);
}
/* Takes optional arguments, consult optargs_bitmask. */
@@ -47,7 +49,7 @@ do_fstrim (const char *path,
char *err;
int r;
- ADD_ARG (argv, i, "fstrim");
+ ADD_ARG (argv, i, str_fstrim);
if ((optargs_bitmask & GUESTFS_FSTRIM_OFFSET_BITMASK)) {
if (offset < 0) {
diff --git a/daemon/grub.c b/daemon/grub.c
index 9cd4f6e..cb1fac2 100644
--- a/daemon/grub.c
+++ b/daemon/grub.c
@@ -26,10 +26,12 @@
#include "actions.h"
#include "optgroups.h"
+GUESTFSD_EXT_CMD(str_grub_install, grub-install);
+
int
optgroup_grub_available (void)
{
- return prog_exists ("grub-install");
+ return prog_exists (str_grub_install);
}
int
@@ -44,7 +46,7 @@ do_grub_install (const char *root, const char *device)
return -1;
}
- r = command (NULL, &err, "grub-install", buf, device, NULL);
+ r = command (NULL, &err, str_grub_install, buf, device, NULL);
free (buf);
if (r == -1) {
diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c
index 80175e0..e6d5fde 100644
--- a/daemon/guestfsd.c
+++ b/daemon/guestfsd.c
@@ -53,6 +53,9 @@
#include "daemon.h"
+GUESTFSD_EXT_CMD(str_udevadm, udevadm);
+GUESTFSD_EXT_CMD(str_udevsettle, udevsettle);
+
static char *read_cmdline (void);
#ifndef MAX
@@ -1294,6 +1297,6 @@ random_name (char *template)
void
udev_settle (void)
{
- (void) command (NULL, NULL, "udevadm", "settle", NULL);
- (void) command (NULL, NULL, "udevsettle", NULL);
+ (void) command (NULL, NULL, str_udevadm, "settle", NULL);
+ (void) command (NULL, NULL, str_udevsettle, NULL);
}
diff --git a/daemon/initrd.c b/daemon/initrd.c
index 2ded14a..d9bc0f7 100644
--- a/daemon/initrd.c
+++ b/daemon/initrd.c
@@ -30,6 +30,9 @@
#include "daemon.h"
#include "actions.h"
+GUESTFSD_EXT_CMD(str_zcat, zcat);
+GUESTFSD_EXT_CMD(str_cpio, cpio);
+
char **
do_initrd_list (const char *path)
{
@@ -40,7 +43,7 @@ do_initrd_list (const char *path)
size_t len;
/* "zcat /sysroot/<path> | cpio --quiet -it", but path must be quoted. */
- if (asprintf_nowarn (&cmd, "zcat %R | cpio --quiet -it", path) == -1) {
+ if (asprintf_nowarn (&cmd, "%s %R | %s --quiet -it", str_zcat, path, str_cpio) == -1) {
reply_with_perror ("asprintf");
return NULL;
}
diff --git a/daemon/inotify.c b/daemon/inotify.c
index ed425b8..cb0a366 100644
--- a/daemon/inotify.c
+++ b/daemon/inotify.c
@@ -35,6 +35,8 @@
#include "optgroups.h"
#ifdef HAVE_SYS_INOTIFY_H
+GUESTFSD_EXT_CMD(str_sort, sort);
+
/* Currently open inotify handle, or -1 if not opened. */
static int inotify_fd = -1;
@@ -318,7 +320,7 @@ do_inotify_files (void)
return NULL;
}
- snprintf (cmd, sizeof cmd, "sort -u > %s", tempfile);
+ snprintf (cmd, sizeof cmd, "%s -u > %s", str_sort, tempfile);
fp = popen (cmd, "w");
if (fp == NULL) {
diff --git a/daemon/isoinfo.c b/daemon/isoinfo.c
index c0ee1c9..d117b40 100644
--- a/daemon/isoinfo.c
+++ b/daemon/isoinfo.c
@@ -30,6 +30,8 @@
#include "daemon.h"
#include "actions.h"
+GUESTFSD_EXT_CMD(str_isoinfo, isoinfo);
+
static int
parse_uint32 (uint32_t *ret, const char *str)
{
@@ -244,7 +246,7 @@ isoinfo (const char *path)
/* --debug is necessary to get additional fields, in particular
* the date & time fields.
*/
- r = command (&out, &err, "isoinfo", "--debug", "-d", "-i", path, NULL);
+ r = command (&out, &err, str_isoinfo, "--debug", "-d", "-i", path, NULL);
if (r == -1) {
reply_with_error ("%s", err);
goto done;
diff --git a/daemon/labels.c b/daemon/labels.c
index 5c59a4c..ead6b46 100644
--- a/daemon/labels.c
+++ b/daemon/labels.c
@@ -27,6 +27,9 @@
#include "actions.h"
#include "optgroups.h"
+GUESTFSD_EXT_CMD(str_e2label, e2label);
+GUESTFSD_EXT_CMD(str_ntfslabel, ntfslabel);
+
static int
e2label (const char *device, const char *label)
{
@@ -39,7 +42,7 @@ e2label (const char *device, const char *label)
return -1;
}
- r = command (NULL, &err, "e2label", device, label, NULL);
+ r = command (NULL, &err, str_e2label, device, label, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -60,7 +63,7 @@ ntfslabel (const char *device, const char *label)
* characters and return an error. This is not so easy since we
* don't have the required libraries.
*/
- r = command (NULL, &err, "ntfslabel", device, label, NULL);
+ r = command (NULL, &err, str_ntfslabel, device, label, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
diff --git a/daemon/link.c b/daemon/link.c
index 4536f00..6abe3ca 100644
--- a/daemon/link.c
+++ b/daemon/link.c
@@ -28,6 +28,8 @@
#include "daemon.h"
#include "actions.h"
+GUESTFSD_EXT_CMD(str_ln, ln);
+
char *
do_readlink (const char *path)
{
@@ -132,11 +134,11 @@ _link (const char *flag, int symbolic, const char *target, const char *linkname)
if (flag)
r = command (NULL, &err,
- "ln", flag, "--", /* target could begin with '-' */
+ str_ln, flag, "--", /* target could begin with '-' */
buf_target ? : target, buf_linkname, NULL);
else
r = command (NULL, &err,
- "ln", "--",
+ str_ln, "--",
buf_target ? : target, buf_linkname, NULL);
free (buf_linkname);
free (buf_target);
diff --git a/daemon/ls.c b/daemon/ls.c
index 5adf5ef..b2de9e5 100644
--- a/daemon/ls.c
+++ b/daemon/ls.c
@@ -30,6 +30,8 @@
#include "daemon.h"
#include "actions.h"
+GUESTFSD_EXT_CMD(str_ls, ls);
+
/* Has one FileOut parameter. */
int
do_ls0 (const char *path)
@@ -112,7 +114,7 @@ do_ll (const char *path)
return NULL;
}
- r = command (&out, &err, "ls", "-la", spath, NULL);
+ r = command (&out, &err, str_ls, "-la", spath, NULL);
free (spath);
if (r == -1) {
reply_with_error ("%s", err);
@@ -138,7 +140,7 @@ do_llz (const char *path)
return NULL;
}
- r = command (&out, &err, "ls", "-laZ", spath, NULL);
+ r = command (&out, &err, str_ls, "-laZ", spath, NULL);
free (spath);
if (r == -1) {
reply_with_error ("%s", err);
diff --git a/daemon/luks.c b/daemon/luks.c
index 02620ef..3e3b456 100644
--- a/daemon/luks.c
+++ b/daemon/luks.c
@@ -28,10 +28,12 @@
#define MAX_ARGS 64
+GUESTFSD_EXT_CMD(str_cryptsetup, cryptsetup);
+
int
optgroup_luks_available (void)
{
- return prog_exists ("cryptsetup");
+ return prog_exists (str_cryptsetup);
}
/* Callers must also call remove_temp (tempfile). */
@@ -100,7 +102,7 @@ luks_open (const char *device, const char *key, const char *mapname,
const char *argv[MAX_ARGS];
size_t i = 0;
- ADD_ARG (argv, i, "cryptsetup");
+ ADD_ARG (argv, i, str_cryptsetup);
ADD_ARG (argv, i, "-d");
ADD_ARG (argv, i, tempfile);
if (readonly) ADD_ARG (argv, i, "--readonly");
@@ -150,7 +152,7 @@ do_luks_close (const char *device)
const char *mapname = &device[12];
char *err;
- int r = command (NULL, &err, "cryptsetup", "luksClose", mapname, NULL);
+ int r = command (NULL, &err, str_cryptsetup, "luksClose", mapname, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -176,7 +178,7 @@ luks_format (const char *device, const char *key, int keyslot,
char keyslot_s[16];
size_t i = 0;
- ADD_ARG (argv, i, "cryptsetup");
+ ADD_ARG (argv, i, str_cryptsetup);
ADD_ARG (argv, i, "-q");
if (cipher) {
ADD_ARG (argv, i, "--cipher");
@@ -238,7 +240,7 @@ do_luks_add_key (const char *device, const char *key, const char *newkey,
char keyslot_s[16];
size_t i = 0;
- ADD_ARG (argv, i, "cryptsetup");
+ ADD_ARG (argv, i, str_cryptsetup);
ADD_ARG (argv, i, "-q");
ADD_ARG (argv, i, "-d");
ADD_ARG (argv, i, keyfile);
@@ -277,7 +279,7 @@ do_luks_kill_slot (const char *device, const char *key, int keyslot)
char keyslot_s[16];
size_t i = 0;
- ADD_ARG (argv, i, "cryptsetup");
+ ADD_ARG (argv, i, str_cryptsetup);
ADD_ARG (argv, i, "-q");
ADD_ARG (argv, i, "-d");
ADD_ARG (argv, i, tempfile);
diff --git a/daemon/lvm-filter.c b/daemon/lvm-filter.c
index 5eb2402..cde773d 100644
--- a/daemon/lvm-filter.c
+++ b/daemon/lvm-filter.c
@@ -31,6 +31,11 @@
#include "daemon.h"
#include "actions.h"
+GUESTFSD_EXT_CMD(str_lvm, lvm);
+GUESTFSD_EXT_CMD(str_vgchange, vgchange);
+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
* LVM_SYSTEM_DIR to point to the copy.
@@ -65,7 +70,7 @@ copy_lvm (void)
}
/* Hopefully no dotfiles in there ... XXX */
- snprintf (cmd, sizeof cmd, "cp -a /etc/lvm/* %s", lvm_system_dir);
+ snprintf (cmd, sizeof cmd, "%s -a /etc/lvm/* %s", str_cp, lvm_system_dir);
r = system (cmd);
if (r == -1) {
perror (cmd);
@@ -92,7 +97,7 @@ rm_lvm_system_dir (void)
{
char cmd[64];
- snprintf (cmd, sizeof cmd, "rm -rf %s", lvm_system_dir);
+ snprintf (cmd, sizeof cmd, "%s -rf %s", str_rm, lvm_system_dir);
ignore_value (system (cmd));
}
@@ -189,7 +194,7 @@ static int
vgchange (const char *vgchange_flag)
{
char *err;
- int r = command (NULL, &err, "lvm", "vgchange", vgchange_flag, NULL);
+ int r = command (NULL, &err, str_lvm, str_vgchange, vgchange_flag, NULL);
if (r == -1) {
reply_with_error ("vgchange: %s", err);
free (err);
@@ -224,7 +229,7 @@ rescan (void)
unlink (lvm_cache);
char *err;
- int r = command (NULL, &err, "lvm", "vgscan", NULL);
+ int r = command (NULL, &err, str_lvm, "vgscan", NULL);
if (r == -1) {
reply_with_error ("vgscan: %s", err);
free (err);
diff --git a/daemon/lvm.c b/daemon/lvm.c
index 5f0c3a6..24473f4 100644
--- a/daemon/lvm.c
+++ b/daemon/lvm.c
@@ -32,10 +32,12 @@
#include "actions.h"
#include "optgroups.h"
+GUESTFSD_EXT_CMD(str_lvm, lvm);
+
int
optgroup_lvm2_available (void)
{
- return prog_exists ("lvm");
+ return prog_exists (str_lvm);
}
/* LVM actions. Keep an eye on liblvm, although at the time
@@ -105,7 +107,7 @@ do_pvs (void)
int r;
r = command (&out, &err,
- "lvm", "pvs", "-o", "pv_name", "--noheadings", NULL);
+ str_lvm, "pvs", "-o", "pv_name", "--noheadings", NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (out);
@@ -125,7 +127,7 @@ do_vgs (void)
int r;
r = command (&out, &err,
- "lvm", "vgs", "-o", "vg_name", "--noheadings", NULL);
+ str_lvm, "vgs", "-o", "vg_name", "--noheadings", NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (out);
@@ -145,7 +147,7 @@ do_lvs (void)
int r;
r = command (&out, &err,
- "lvm", "lvs",
+ str_lvm, "lvs",
"-o", "vg_name,lv_name", "--noheadings",
"--separator", "/", NULL);
if (r == -1) {
@@ -189,7 +191,7 @@ do_pvcreate (const char *device)
int r;
r = command (NULL, &err,
- "lvm", "pvcreate", device, NULL);
+ str_lvm, "pvcreate", device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -216,7 +218,7 @@ do_vgcreate (const char *volgroup, char *const *physvols)
reply_with_perror ("malloc");
return -1;
}
- argv[0] = "lvm";
+ argv[0] = str_lvm;
argv[1] = "vgcreate";
argv[2] = volgroup;
for (i = 3; i <= argc; ++i)
@@ -248,7 +250,7 @@ do_lvcreate (const char *logvol, const char *volgroup, int mbytes)
snprintf (size, sizeof size, "%d", mbytes);
r = command (NULL, &err,
- "lvm", "lvcreate",
+ str_lvm, "lvcreate",
"-L", size, "-n", logvol, volgroup, NULL);
if (r == -1) {
reply_with_error ("%s", err);
@@ -278,7 +280,7 @@ do_lvcreate_free (const char *logvol, const char *volgroup, int percent)
snprintf (size, sizeof size, "%d%%FREE", percent);
r = command (NULL, &err,
- "lvm", "lvcreate",
+ str_lvm, "lvcreate",
"-l", size, "-n", logvol, volgroup, NULL);
if (r == -1) {
reply_with_error ("%s", err);
@@ -303,7 +305,7 @@ do_lvresize (const char *logvol, int mbytes)
snprintf (size, sizeof size, "%d", mbytes);
r = command (NULL, &err,
- "lvm", "lvresize",
+ str_lvm, "lvresize",
"--force", "-L", size, logvol, NULL);
if (r == -1) {
reply_with_error ("%s", err);
@@ -330,7 +332,7 @@ do_lvresize_free (const char *logvol, int percent)
snprintf (size, sizeof size, "+%d%%FREE", percent);
r = command (NULL, &err,
- "lvm", "lvresize", "-l", size, logvol, NULL);
+ str_lvm, "lvresize", "-l", size, logvol, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -361,10 +363,10 @@ do_lvm_remove_all (void)
/* Deactivate the LV first. On Ubuntu, lvremove '-f' option
* does not remove active LVs reliably.
*/
- (void) command (NULL, NULL, "lvm", "lvchange", "-an", xs[i], NULL);
+ (void) command (NULL, NULL, str_lvm, "lvchange", "-an", xs[i], NULL);
udev_settle ();
- r = command (NULL, &err, "lvm", "lvremove", "-f", xs[i], NULL);
+ r = command (NULL, &err, str_lvm, "lvremove", "-f", xs[i], NULL);
if (r == -1) {
reply_with_error ("lvremove: %s: %s", xs[i], err);
free (err);
@@ -382,10 +384,10 @@ do_lvm_remove_all (void)
for (i = 0; xs[i] != NULL; ++i) {
/* Deactivate the VG first, see note above. */
- (void) command (NULL, NULL, "lvm", "vgchange", "-an", xs[i], NULL);
+ (void) command (NULL, NULL, str_lvm, "vgchange", "-an", xs[i], NULL);
udev_settle ();
- r = command (NULL, &err, "lvm", "vgremove", "-f", xs[i], NULL);
+ r = command (NULL, &err, str_lvm, "vgremove", "-f", xs[i], NULL);
if (r == -1) {
reply_with_error ("vgremove: %s: %s", xs[i], err);
free (err);
@@ -402,7 +404,7 @@ do_lvm_remove_all (void)
return -1;
for (i = 0; xs[i] != NULL; ++i) {
- r = command (NULL, &err, "lvm", "pvremove", "-f", xs[i], NULL);
+ r = command (NULL, &err, str_lvm, "pvremove", "-f", xs[i], NULL);
if (r == -1) {
reply_with_error ("pvremove: %s: %s", xs[i], err);
free (err);
@@ -426,7 +428,7 @@ do_lvremove (const char *device)
int r;
r = command (NULL, &err,
- "lvm", "lvremove", "-f", device, NULL);
+ str_lvm, "lvremove", "-f", device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -447,7 +449,7 @@ do_vgremove (const char *device)
int r;
r = command (NULL, &err,
- "lvm", "vgremove", "-f", device, NULL);
+ str_lvm, "vgremove", "-f", device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -468,7 +470,7 @@ do_pvremove (const char *device)
int r;
r = command (NULL, &err,
- "lvm", "pvremove", "-ff", device, NULL);
+ str_lvm, "pvremove", "-ff", device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -489,7 +491,7 @@ do_pvresize (const char *device)
int r;
r = command (NULL, &err,
- "lvm", "pvresize", device, NULL);
+ str_lvm, "pvresize", device, NULL);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
free (err);
@@ -510,7 +512,7 @@ do_pvresize_size (const char *device, int64_t size)
snprintf (buf, sizeof buf, "%" PRIi64 "b", size);
r = command (NULL, &err,
- "lvm", "pvresize",
+ str_lvm, "pvresize",
"--setphysicalvolumesize", buf,
device, NULL);
if (r == -1) {
@@ -537,7 +539,7 @@ do_vg_activate (int activate, char *const *volgroups)
return -1;
}
- argv[0] = "lvm";
+ argv[0] = str_lvm;
argv[1] = "vgchange";
argv[2] = "-a";
argv[3] = activate ? "y" : "n";
@@ -574,7 +576,7 @@ do_lvrename (const char *logvol, const char *newlogvol)
int r;
r = command (NULL, &err,
- "lvm", "lvrename",
+ str_lvm, "lvrename",
logvol, newlogvol, NULL);
if (r == -1) {
reply_with_error ("%s -> %s: %s", logvol, newlogvol, err);
@@ -596,7 +598,7 @@ do_vgrename (const char *volgroup, const char *newvolgroup)
int r;
r = command (NULL, &err,
- "lvm", "vgrename",
+ str_lvm, "vgrename",
volgroup, newvolgroup, NULL);
if (r == -1) {
reply_with_error ("%s -> %s: %s", volgroup, newvolgroup, err);
@@ -617,7 +619,7 @@ get_lvm_field (const char *cmd, const char *field, const char *device)
char *out;
char *err;
int r = command (&out, &err,
- "lvm", cmd,
+ str_lvm, cmd,
"--unbuffered", "--noheadings", "-o", field,
device, NULL);
if (r == -1) {
@@ -657,7 +659,7 @@ get_lvm_fields (const char *cmd, const char *field, const char *device)
char *out;
char *err;
int r = command (&out, &err,
- "lvm", cmd,
+ str_lvm, cmd,
"--unbuffered", "--noheadings", "-o", field,
device, NULL);
if (r == -1) {
@@ -701,7 +703,7 @@ do_vgscan (void)
int r;
r = command (NULL, &err,
- "lvm", "vgscan", NULL);
+ str_lvm, "vgscan", NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -893,7 +895,7 @@ do_vgmeta (const char *vg, size_t *size_r)
close (fd);
- r = command (NULL, &err, "lvm", "vgcfgbackup", "-f", tmp, vg, NULL);
+ r = command (NULL, &err, str_lvm, "vgcfgbackup", "-f", tmp, vg, NULL);
if (r == -1) {
reply_with_error ("vgcfgbackup: %s", err);
free (err);
@@ -968,7 +970,7 @@ do_pvchange_uuid (const char *device)
int r;
r = command (NULL, &err,
- "lvm", "pvchange", "-u", device, NULL);
+ str_lvm, "pvchange", "-u", device, NULL);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
free (err);
@@ -989,7 +991,7 @@ do_pvchange_uuid_all (void)
int r;
r = command (NULL, &err,
- "lvm", "pvchange", "-u", "-a", NULL);
+ str_lvm, "pvchange", "-u", "-a", NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
@@ -1010,7 +1012,7 @@ do_vgchange_uuid (const char *vg)
int r;
r = command (NULL, &err,
- "lvm", "vgchange", "-u", vg, NULL);
+ str_lvm, "vgchange", "-u", vg, NULL);
if (r == -1) {
reply_with_error ("%s: %s", vg, err);
free (err);
@@ -1031,7 +1033,7 @@ do_vgchange_uuid_all (void)
int r;
r = command (NULL, &err,
- "lvm", "vgchange", "-u", NULL);
+ str_lvm, "vgchange", "-u", NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
diff --git a/daemon/md.c b/daemon/md.c
index 0e2f704..4281b4e 100644
--- a/daemon/md.c
+++ b/daemon/md.c
@@ -29,10 +29,12 @@
#include "optgroups.h"
#include "c-ctype.h"
+GUESTFSD_EXT_CMD(str_mdadm, mdadm);
+
int
optgroup_mdadm_available (void)
{
- return prog_exists ("mdadm");
+ return prog_exists (str_mdadm);
}
static size_t
@@ -121,7 +123,7 @@ do_md_create (const char *name, char *const *devices,
const char *argv[MAX_ARGS];
size_t i = 0;
- ADD_ARG (argv, i, "mdadm");
+ ADD_ARG (argv, i, str_mdadm);
ADD_ARG (argv, i, "--create");
/* --run suppresses "Continue creating array" question */
ADD_ARG (argv, i, "--run");
@@ -244,7 +246,7 @@ do_md_detail(const char *md)
DECLARE_STRINGSBUF (ret);
- const char *mdadm[] = { "mdadm", "-D", "--export", md, NULL };
+ const char *mdadm[] = { str_mdadm, "-D", "--export", md, NULL };
r = commandv (&out, &err, mdadm);
if (r == -1) {
reply_with_error ("%s", err);
@@ -319,7 +321,7 @@ do_md_stop(const char *md)
int r;
char *err = NULL;
- const char *mdadm[] = { "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);
diff --git a/daemon/mkfs.c b/daemon/mkfs.c
index 7d28061..241d346 100644
--- a/daemon/mkfs.c
+++ b/daemon/mkfs.c
@@ -31,6 +31,9 @@
#define MAX_ARGS 64
+GUESTFSD_EXT_CMD(str_mke2fs, mke2fs);
+GUESTFSD_EXT_CMD(str_mkfs, mkfs);
+
/* Takes optional arguments, consult optargs_bitmask. */
int
do_mkfs (const char *fstype, const char *device, int blocksize,
@@ -54,9 +57,9 @@ do_mkfs (const char *fstype, const char *device, int blocksize,
* option.
*/
if (extfs)
- ADD_ARG (argv, i, "mke2fs");
+ ADD_ARG (argv, i, str_mke2fs);
else
- ADD_ARG (argv, i, "mkfs");
+ ADD_ARG (argv, i, str_mkfs);
ADD_ARG (argv, i, "-t");
ADD_ARG (argv, i, fstype);
diff --git a/daemon/modprobe.c b/daemon/modprobe.c
index 1063043..3f45270 100644
--- a/daemon/modprobe.c
+++ b/daemon/modprobe.c
@@ -25,17 +25,19 @@
#include "actions.h"
#include "optgroups.h"
+GUESTFSD_EXT_CMD(str_modprobe, modprobe);
+
int
optgroup_linuxmodules_available (void)
{
- return prog_exists ("modprobe");
+ return prog_exists (str_modprobe);
}
int
do_modprobe (const char *module)
{
char *err;
- int r = command (NULL, &err, "modprobe", module, NULL);
+ int r = command (NULL, &err, str_modprobe, module, NULL);
if (r == -1) {
reply_with_error ("%s", err);
diff --git a/daemon/mount.c b/daemon/mount.c
index bd27f94..c84faaf 100644
--- a/daemon/mount.c
+++ b/daemon/mount.c
@@ -31,6 +31,9 @@
#define MAX_ARGS 64
+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
* mounted on *or under* the sysroot directory. (It has to be *or
@@ -150,10 +153,10 @@ do_mount_vfs (const char *options, const char *vfstype,
if (vfstype)
r = command (NULL, &error,
- "mount", "-o", options, "-t", vfstype, device, mp, NULL);
+ str_mount, "-o", options, "-t", vfstype, device, mp, NULL);
else
r = command (NULL, &error,
- "mount", "-o", options, device, mp, NULL);
+ str_mount, "-o", options, device, mp, NULL);
free (mp);
if (r == -1) {
reply_with_error ("%s on %s (options: '%s'): %s",
@@ -213,7 +216,7 @@ do_umount (const char *pathordevice,
/* Use the external /bin/umount program, so that /etc/mtab is kept
* updated.
*/
- ADD_ARG (argv, i, "umount");
+ ADD_ARG (argv, i, str_umount);
if (force)
ADD_ARG (argv, i, "-f");
@@ -382,7 +385,7 @@ do_umount_all (void)
/* Unmount them. */
for (i = 0; i < mounts.size; ++i) {
- r = command (NULL, &err, "umount", mounts.argv[i], NULL);
+ r = command (NULL, &err, str_umount, mounts.argv[i], NULL);
if (r == -1) {
reply_with_error ("umount: %s: %s", mounts.argv[i], err);
free (err);
@@ -422,7 +425,7 @@ do_mount_loop (const char *file, const char *mountpoint)
return -1;
}
- r = command (NULL, &error, "mount", "-o", "loop", buf, mp, NULL);
+ r = command (NULL, &error, str_mount, "-o", "loop", buf, mp, NULL);
free (mp);
free (buf);
if (r == -1) {
diff --git a/daemon/ntfs.c b/daemon/ntfs.c
index 2dedc26..613b9c3 100644
--- a/daemon/ntfs.c
+++ b/daemon/ntfs.c
@@ -30,16 +30,20 @@
#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);
+
int
optgroup_ntfs3g_available (void)
{
- return prog_exists ("ntfs-3g.probe");
+ return prog_exists (str_ntfs3g_probe);
}
int
optgroup_ntfsprogs_available (void)
{
- return prog_exists ("ntfsresize");
+ return prog_exists (str_ntfsresize);
}
int
@@ -51,7 +55,7 @@ do_ntfs_3g_probe (int rw, const char *device)
rw_flag = rw ? "-w" : "-r";
- r = commandr (NULL, &err, "ntfs-3g.probe", rw_flag, device, NULL);
+ r = commandr (NULL, &err, str_ntfs3g_probe, rw_flag, device, NULL);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
free (err);
@@ -72,7 +76,7 @@ do_ntfsresize (const char *device, int64_t size, int force)
size_t i = 0;
char size_str[32];
- ADD_ARG (argv, i, "ntfsresize");
+ ADD_ARG (argv, i, str_ntfsresize);
ADD_ARG (argv, i, "-P");
if (optargs_bitmask & GUESTFS_NTFSRESIZE_SIZE_BITMASK) {
@@ -119,7 +123,7 @@ do_ntfsfix (const char *device, int clearbadsectors)
int r;
char *err;
- ADD_ARG (argv, i, "ntfsfix");
+ ADD_ARG (argv, i, str_ntfsfix);
if ((optargs_bitmask & GUESTFS_NTFSFIX_CLEARBADSECTORS_BITMASK) &&
clearbadsectors)
diff --git a/daemon/ntfsclone.c b/daemon/ntfsclone.c
index 4287edb..bf97eaf 100644
--- a/daemon/ntfsclone.c
+++ b/daemon/ntfsclone.c
@@ -30,6 +30,8 @@
#include "actions.h"
#include "optgroups.h"
+GUESTFSD_EXT_CMD(str_ntfsclone, ntfsclone);
+
/* Read the error file. Returns a string that the caller must free. */
static char *
read_error_file (char *error_file)
@@ -80,8 +82,8 @@ do_ntfsclone_in (const char *device)
close (fd);
/* Construct the command. */
- if (asprintf_nowarn (&cmd, "ntfsclone -O %s --restore-image - 2> %s",
- device, error_file) == -1) {
+ if (asprintf_nowarn (&cmd, "%s -O %s --restore-image - 2> %s",
+ str_ntfsclone, device, error_file) == -1) {
err = errno;
r = cancel_receive ();
errno = err;
@@ -157,7 +159,8 @@ do_ntfsclone_out (const char *device,
char buf[GUESTFS_MAX_CHUNK_SIZE];
/* Construct the ntfsclone command. */
- if (asprintf (&cmd, "ntfsclone -o - --save-image%s%s%s%s%s %s",
+ 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" : "",
diff --git a/daemon/parted.c b/daemon/parted.c
index ceefc4a..cc9a84b 100644
--- a/daemon/parted.c
+++ b/daemon/parted.c
@@ -28,6 +28,9 @@
#include "daemon.h"
#include "actions.h"
+GUESTFSD_EXT_CMD(str_parted, parted);
+GUESTFSD_EXT_CMD(str_sfdisk, sfdisk);
+
/* Notes:
*
* Parted 1.9 sends error messages to stdout, hence use of the
@@ -82,7 +85,7 @@ do_part_init (const char *device, const char *parttype)
udev_settle ();
r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
- "parted", "-s", "--", device, "mklabel", parttype, NULL);
+ str_parted, "-s", "--", device, "mklabel", parttype, NULL);
if (r == -1) {
reply_with_error ("parted: %s: %s", device, err);
free (err);
@@ -137,7 +140,7 @@ do_part_add (const char *device, const char *prlogex,
* this as a bug in the parted mkpart command.
*/
r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
- "parted", "-s", "--",
+ str_parted, "-s", "--",
device, "mkpart", prlogex, startstr, endstr, NULL);
if (r == -1) {
reply_with_error ("parted: %s: %s", device, err);
@@ -168,7 +171,7 @@ do_part_del (const char *device, int partnum)
udev_settle ();
r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
- "parted", "-s", "--", device, "rm", partnum_str, NULL);
+ str_parted, "-s", "--", device, "rm", partnum_str, NULL);
if (r == -1) {
reply_with_error ("parted: %s: %s", device, err);
free (err);
@@ -209,7 +212,7 @@ do_part_disk (const char *device, const char *parttype)
udev_settle ();
r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
- "parted", "-s", "--",
+ str_parted, "-s", "--",
device,
"mklabel", parttype,
/* See comment about about the parted mkpart command. */
@@ -245,7 +248,7 @@ do_part_set_bootable (const char *device, int partnum, int bootable)
udev_settle ();
r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
- "parted", "-s", "--",
+ str_parted, "-s", "--",
device, "set", partstr, "boot", bootable ? "on" : "off", NULL);
if (r == -1) {
reply_with_error ("parted: %s: %s", device, err);
@@ -277,7 +280,7 @@ do_part_set_name (const char *device, int partnum, const char *name)
udev_settle ();
r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
- "parted", "-s", "--", device, "name", partstr, name, NULL);
+ str_parted, "-s", "--", device, "name", partstr, name, NULL);
if (r == -1) {
reply_with_error ("parted: %s: %s", device, err);
free (err);
@@ -333,7 +336,7 @@ test_parted_m_opt (void)
return result;
char *err = NULL;
- int r = commandr (NULL, &err, "parted", "-s", "-m", "/dev/null", NULL);
+ int r = commandr (NULL, &err, str_parted, "-s", "-m", "/dev/null", NULL);
if (r == -1) {
/* Test failed, eg. missing or completely unusable parted binary. */
reply_with_error ("could not run 'parted' command");
@@ -356,11 +359,11 @@ print_partition_table (const char *device, int parted_has_m_opt)
int r;
if (parted_has_m_opt)
- r = command (&out, &err, "parted", "-m", "--", device,
+ r = command (&out, &err, str_parted, "-m", "--", device,
"unit", "b",
"print", NULL);
else
- r = command (&out, &err, "parted", "-s", "--", device,
+ r = command (&out, &err, str_parted, "-s", "--", device,
"unit", "b",
"print", NULL);
if (r == -1) {
@@ -744,7 +747,7 @@ do_part_get_mbr_id (const char *device, int partnum)
udev_settle ();
- r = command (&out, &err, "sfdisk", "--print-id", device, partnum_str, NULL);
+ r = command (&out, &err, str_sfdisk, "--print-id", device, partnum_str, NULL);
if (r == -1) {
reply_with_error ("sfdisk --print-id: %s", err);
free (out);
@@ -786,7 +789,7 @@ do_part_set_mbr_id (const char *device, int partnum, int idbyte)
udev_settle ();
- r = command (NULL, &err, "sfdisk",
+ r = command (NULL, &err, str_sfdisk,
"--change-id", device, partnum_str, idbyte_str, NULL);
if (r == -1) {
reply_with_error ("sfdisk --change-id: %s", err);
diff --git a/daemon/rsync.c b/daemon/rsync.c
index 95f0f86..e4a7237 100644
--- a/daemon/rsync.c
+++ b/daemon/rsync.c
@@ -30,10 +30,12 @@
#define MAX_ARGS 64
+GUESTFSD_EXT_CMD(str_rsync, rsync);
+
int
optgroup_rsync_available (void)
{
- return prog_exists ("rsync");
+ return prog_exists (str_rsync);
}
static int
@@ -46,7 +48,7 @@ rsync (const char *src, const char *src_orig,
int r;
char *err;
- ADD_ARG (argv, i, "rsync");
+ ADD_ARG (argv, i, str_rsync);
if (archive)
ADD_ARG (argv, i, "--archive");
diff --git a/daemon/scrub.c b/daemon/scrub.c
index 2cef69d..cce8da5 100644
--- a/daemon/scrub.c
+++ b/daemon/scrub.c
@@ -28,10 +28,12 @@
#include "actions.h"
#include "optgroups.h"
+GUESTFSD_EXT_CMD(str_scrub, scrub);
+
int
optgroup_scrub_available (void)
{
- return prog_exists ("scrub");
+ return prog_exists (str_scrub);
}
int
@@ -40,7 +42,7 @@ do_scrub_device (const char *device)
char *err;
int r;
- r = command (NULL, &err, "scrub", device, NULL);
+ r = command (NULL, &err, str_scrub, device, NULL);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
free (err);
@@ -66,7 +68,7 @@ do_scrub_file (const char *file)
return -1;
}
- r = command (NULL, &err, "scrub", "-r", buf, NULL);
+ r = command (NULL, &err, str_scrub, "-r", buf, NULL);
free (buf);
if (r == -1) {
reply_with_error ("%s: %s", file, err);
@@ -93,7 +95,7 @@ do_scrub_freespace (const char *dir)
return -1;
}
- r = command (NULL, &err, "scrub", "-X", buf, NULL);
+ r = command (NULL, &err, str_scrub, "-X", buf, NULL);
free (buf);
if (r == -1) {
reply_with_error ("%s: %s", dir, err);
diff --git a/daemon/sfdisk.c b/daemon/sfdisk.c
index 8221ffa..1ce6962 100644
--- a/daemon/sfdisk.c
+++ b/daemon/sfdisk.c
@@ -29,6 +29,9 @@
#include "daemon.h"
#include "actions.h"
+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,
@@ -38,7 +41,7 @@ sfdisk (const char *device, int n, int cyls, int heads, int sectors,
char buf[256];
int i;
- strcpy (buf, "sfdisk");
+ strcpy (buf, str_sfdisk);
if (n > 0)
sprintf (buf + strlen (buf), " -N %d", n);
@@ -101,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, "blockdev", "--rereadpt", device, NULL);
+ (void) command (NULL, NULL, str_blockdev, "--rereadpt", device, NULL);
udev_settle ();
@@ -136,7 +139,7 @@ sfdisk_flag (const char *device, const char *flag)
char *out, *err;
int r;
- r = command (&out, &err, "sfdisk", flag, device, NULL);
+ r = command (&out, &err, str_sfdisk, flag, device, NULL);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
free (out);
diff --git a/daemon/swap.c b/daemon/swap.c
index 8f1b59d..cf25e23 100644
--- a/daemon/swap.c
+++ b/daemon/swap.c
@@ -30,6 +30,10 @@
#include "ignore-value.h"
+GUESTFSD_EXT_CMD(str_mkswap, mkswap);
+GUESTFSD_EXT_CMD(str_swapon, swapon);
+GUESTFSD_EXT_CMD(str_swapoff, swapoff);
+
/* Confirmed this is true for Linux swap partitions from the Linux sources. */
#define SWAP_LABEL_MAX 16
@@ -49,7 +53,7 @@ optgroup_linuxfsuuid_available (void)
* return code.
*/
ignore_value (commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
- "mkswap", "--help", NULL));
+ str_mkswap, "--help", NULL));
av = strstr (err, "-U") != NULL;
free (err);
@@ -66,7 +70,7 @@ do_mkswap (const char *device, const char *label, const char *uuid)
int r;
char *err;
- ADD_ARG (argv, i, "mkswap");
+ ADD_ARG (argv, i, str_mkswap);
ADD_ARG (argv, i, "-f");
if (optargs_bitmask & GUESTFS_MKSWAP_LABEL_BITMASK) {
@@ -129,7 +133,7 @@ do_mkswap_file (const char *path)
return -1;
}
- r = command (NULL, &err, "mkswap", "-f", buf, NULL);
+ r = command (NULL, &err, str_mkswap, "-f", buf, NULL);
free (buf);
if (r == -1) {
@@ -173,13 +177,13 @@ swaponoff (const char *cmd, const char *flag, const char *value)
int
do_swapon_device (const char *device)
{
- return swaponoff ("swapon", NULL, device);
+ return swaponoff (str_swapon, NULL, device);
}
int
do_swapoff_device (const char *device)
{
- return swaponoff ("swapoff", NULL, device);
+ return swaponoff (str_swapoff, NULL, device);
}
int
@@ -194,7 +198,7 @@ do_swapon_file (const char *path)
return -1;
}
- r = swaponoff ("swapon", NULL, buf);
+ r = swaponoff (str_swapon, NULL, buf);
free (buf);
return r;
}
@@ -211,7 +215,7 @@ do_swapoff_file (const char *path)
return -1;
}
- r = swaponoff ("swapoff", NULL, buf);
+ r = swaponoff (str_swapoff, NULL, buf);
free (buf);
return r;
}
@@ -225,7 +229,7 @@ do_swapon_label (const char *label)
return -1;
}
- return swaponoff ("swapon", "-L", label);
+ return swaponoff (str_swapon, "-L", label);
}
int
@@ -237,17 +241,17 @@ do_swapoff_label (const char *label)
return -1;
}
- return swaponoff ("swapoff", "-L", label);
+ return swaponoff (str_swapoff, "-L", label);
}
int
do_swapon_uuid (const char *uuid)
{
- return swaponoff ("swapon", "-U", uuid);
+ return swaponoff (str_swapon, "-U", uuid);
}
int
do_swapoff_uuid (const char *uuid)
{
- return swaponoff ("swapoff", "-U", uuid);
+ return swaponoff (str_swapoff, "-U", uuid);
}
diff --git a/daemon/tar.c b/daemon/tar.c
index 13f87e7..dc4ddc2 100644
--- a/daemon/tar.c
+++ b/daemon/tar.c
@@ -30,6 +30,8 @@
#include "actions.h"
#include "optgroups.h"
+GUESTFSD_EXT_CMD(str_tar, tar);
+
int
optgroup_xz_available (void)
{
@@ -155,7 +157,8 @@ do_tar_in (const char *dir, const char *compress)
close (fd);
/* "tar -C /sysroot%s -xf -" but we have to quote the dir. */
- if (asprintf_nowarn (&cmd, "tar -C %R%s -xf - %s2> %s",
+ if (asprintf_nowarn (&cmd, "%s -C %R%s -xf - %s2> %s",
+ str_tar,
dir, filter,
chown_supported ? "" : "--no-same-owner ",
error_file) == -1) {
@@ -321,7 +324,8 @@ do_tar_out (const char *dir, const char *compress, int numericowner,
}
/* "tar -C /sysroot%s -cf - ." but we have to quote the dir. */
- if (asprintf_nowarn (&cmd, "tar -C %R%s%s%s -cf - .",
+ if (asprintf_nowarn (&cmd, "%s -C %R%s%s%s -cf - .",
+ str_tar,
dir, filter,
numericowner ? " --numeric-owner" : "",
excludes_args) == -1) {
diff --git a/daemon/xfs.c b/daemon/xfs.c
index 5c65db1..90c99b2 100644
--- a/daemon/xfs.c
+++ b/daemon/xfs.c
@@ -30,10 +30,16 @@
#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);
+
int
optgroup_xfs_available (void)
{
- return prog_exists ("mkfs.xfs");
+ return prog_exists (str_mkfs_xfs);
}
static char *
@@ -330,7 +336,7 @@ do_xfs_info (const char *pathordevice)
return NULL;
}
- r = command (&out, &err, "xfs_info", buf, NULL);
+ r = command (&out, &err, str_xfs_info, buf, NULL);
free (buf);
if (r == -1) {
reply_with_error ("%s", err);
@@ -374,7 +380,7 @@ do_xfs_growfs (const char *path,
return -1;
}
- ADD_ARG (argv, i, "xfs_growfs");
+ ADD_ARG (argv, i, str_xfs_growfs);
/* Optional arguments */
if (!(optargs_bitmask & GUESTFS_XFS_GROWFS_DATASEC_BITMASK))
@@ -471,7 +477,7 @@ do_xfs_admin (const char *device,
const char *argv[MAX_ARGS];
size_t i = 0;
- ADD_ARG (argv, i, "xfs_admin");
+ ADD_ARG (argv, i, str_xfs_admin);
/* Optional arguments */
if (!(optargs_bitmask & GUESTFS_XFS_ADMIN_EXTUNWRITTEN_BITMASK))
@@ -548,7 +554,7 @@ do_xfs_repair (const char *device,
size_t i = 0;
int is_device;
- ADD_ARG (argv, i, "xfs_repair");
+ ADD_ARG (argv, i, str_xfs_repair);
/* Optional arguments */
if (optargs_bitmask & GUESTFS_XFS_REPAIR_FORCELOGZERO_BITMASK) {
diff --git a/daemon/zero.c b/daemon/zero.c
index 14aef75..1a66881 100644
--- a/daemon/zero.c
+++ b/daemon/zero.c
@@ -30,6 +30,8 @@
#include "actions.h"
#include "optgroups.h"
+GUESTFSD_EXT_CMD(str_wipefs, wipefs);
+
static const char zero_buf[4096];
int
@@ -77,7 +79,7 @@ do_zero (const char *device)
int
optgroup_wipefs_available (void)
{
- return prog_exists ("wipefs");
+ return prog_exists (str_wipefs);
}
int
@@ -86,7 +88,7 @@ do_wipefs (const char *device)
int r;
char *err = NULL;
- const char *wipefs[] = {"wipefs", "-a", device, NULL};
+ const char *wipefs[] = {str_wipefs, "-a", device, NULL};
r = commandv (NULL, &err, wipefs);
if (r == -1) {
reply_with_error ("%s", err);
diff --git a/daemon/zerofree.c b/daemon/zerofree.c
index e9be8fc..17338f4 100644
--- a/daemon/zerofree.c
+++ b/daemon/zerofree.c
@@ -28,10 +28,12 @@
#include "actions.h"
#include "optgroups.h"
+GUESTFSD_EXT_CMD(str_zerofree, zerofree);
+
int
optgroup_zerofree_available (void)
{
- return prog_exists ("zerofree");
+ return prog_exists (str_zerofree);
}
int
@@ -40,7 +42,7 @@ do_zerofree (const char *device)
char *err;
int r;
- r = command (NULL, &err, "zerofree", device, NULL);
+ r = command (NULL, &err, str_zerofree, device, NULL);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
free (err);
--
1.7.11.5
12 years