summaryrefslogtreecommitdiffstats
path: root/src/filearch.c
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-10-18 13:33:12 +0100
committerRichard W.M. Jones <rjones@redhat.com>2012-10-18 22:12:28 +0100
commit0e0bea70dd166143670b5d01375fbfe2aebaf23e (patch)
tree851a2000efce88881ee809749d80edb973f5bb3c /src/filearch.c
parentaf5ec9381ea3b4e54aa7ef3a50d474d827f7ef19 (diff)
downloadlibguestfs-0e0bea70dd166143670b5d01375fbfe2aebaf23e.tar.gz
libguestfs-0e0bea70dd166143670b5d01375fbfe2aebaf23e.tar.xz
libguestfs-0e0bea70dd166143670b5d01375fbfe2aebaf23e.zip
filearch: Use command mini-library to run external cpio command.
Diffstat (limited to 'src/filearch.c')
-rw-r--r--src/filearch.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/filearch.c b/src/filearch.c
index 10c1d4a3..93a697f5 100644
--- a/src/filearch.c
+++ b/src/filearch.c
@@ -131,8 +131,7 @@ cpio_arch (guestfs_h *g, const char *file, const char *path)
#define dir_len (strlen (dir))
#define initrd_len (dir_len + 16)
char initrd[initrd_len];
-#define cmd_len (dir_len + 256)
- char cmd[cmd_len];
+ struct command *cmd = NULL;
#define bin_len (dir_len + 32)
char bin[bin_len];
char *ret = NULL;
@@ -166,11 +165,16 @@ cpio_arch (guestfs_h *g, const char *file, const char *path)
if (guestfs_download (g, path, initrd) == -1)
goto out;
- snprintf (cmd, cmd_len,
- "cd %s && %s initrd | cpio --quiet -id " INITRD_BINARIES1,
- dir, method);
- r = system (cmd);
- if (r == -1 || WEXITSTATUS (r) != 0) {
+ cmd = guestfs___new_command (g);
+ guestfs___cmd_add_string_unquoted (cmd, "cd ");
+ guestfs___cmd_add_string_quoted (cmd, dir);
+ guestfs___cmd_add_string_unquoted (cmd, " && ");
+ guestfs___cmd_add_string_unquoted (cmd, method);
+ guestfs___cmd_add_string_unquoted (cmd,
+ " initrd | cpio --quiet -id "
+ INITRD_BINARIES1);
+ r = guestfs___cmd_run (cmd);
+ if (r == -1 || !WIFEXITED (r) || WEXITSTATUS (r) != 0) {
perrorf (g, "cpio command failed");
goto out;
}
@@ -214,12 +218,14 @@ cpio_arch (guestfs_h *g, const char *file, const char *path)
error (g, "file_architecture: could not determine architecture of cpio archive");
out:
+ if (cmd)
+ guestfs___cmd_close (cmd);
+
guestfs___remove_tmpdir (g, dir);
return ret;
#undef dir_len
#undef initrd_len
-#undef cmd_len
#undef bin_len
}