summaryrefslogtreecommitdiffstats
path: root/daemon/initrd.c
diff options
context:
space:
mode:
authorRichard Jones <rjones@trick.home.annexia.org>2009-07-27 22:27:45 +0100
committerRichard Jones <rjones@trick.home.annexia.org>2009-07-28 10:57:57 +0100
commit0f2e9c84e9ff1071260770930068642ecc8ac0d9 (patch)
treef4e466d6fb3710d589c21c8849c27f9f2f55ced2 /daemon/initrd.c
parentbf920f57677c67f903cf8c4c985ce3d290b1dbde (diff)
downloadlibguestfs-0f2e9c84e9ff1071260770930068642ecc8ac0d9.tar.gz
libguestfs-0f2e9c84e9ff1071260770930068642ecc8ac0d9.tar.xz
libguestfs-0f2e9c84e9ff1071260770930068642ecc8ac0d9.zip
Replace shell_quote function with %Q and %R printf specifiers.
%Q => simple shell quoted string %R => path will be prefixed by /sysroot eg. snprintf (cmd, sizeof cmd, "cat %R", path); system (cmd);
Diffstat (limited to 'daemon/initrd.c')
-rw-r--r--daemon/initrd.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/daemon/initrd.c b/daemon/initrd.c
index 392b811e..59749bba 100644
--- a/daemon/initrd.c
+++ b/daemon/initrd.c
@@ -31,29 +31,23 @@ char **
do_initrd_list (char *path)
{
FILE *fp;
- int len;
char *cmd;
char filename[PATH_MAX];
char **filenames = NULL;
int size = 0, alloc = 0;
+ size_t len;
NEED_ROOT (NULL);
ABS_PATH (path, NULL);
/* "zcat /sysroot/<path> | cpio --quiet -it", but path must be quoted. */
- len = 64 + sysroot_len + 2 * strlen (path);
- cmd = malloc (len);
- if (!cmd) {
- reply_with_perror ("malloc");
+ if (asprintf_nowarn (&cmd, "zcat %R | cpio --quiet -it", path) == -1) {
+ reply_with_perror ("asprintf");
return NULL;
}
- strcpy (cmd, "zcat ");
- strcat (cmd, sysroot);
- shell_quote (cmd+13, len-13, path);
- strcat (cmd, " | cpio --quiet -it");
-
- fprintf (stderr, "%s\n", cmd);
+ if (verbose)
+ fprintf (stderr, "%s\n", cmd);
fp = popen (cmd, "r");
if (fp == NULL) {