mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
filearch: Use command mini-library to run external cpio command.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user