X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=daemon%2Finitrd.c;h=9c92fee598bc24e4d054f0a0b2da93d6778f04b2;hb=c372c7c23a298a940b8a0868396ef2ae0d824e4d;hp=7b32a08a8c46d4adac82df18d62dc5bc427c5a26;hpb=a7b73d4a1e09f12b2002083618056f0c823c1dcf;p=libguestfs.git diff --git a/daemon/initrd.c b/daemon/initrd.c index 7b32a08..9c92fee 100644 --- a/daemon/initrd.c +++ b/daemon/initrd.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include "../src/guestfs_protocol.h" @@ -28,31 +29,23 @@ #include "actions.h" char ** -do_initrd_list (char *path) +do_initrd_list (const char *path) { FILE *fp; - int len; char *cmd; char filename[PATH_MAX]; char **filenames = NULL; int size = 0, alloc = 0; - - NEED_ROOT (NULL); - ABS_PATH (path, NULL); + size_t len; /* "zcat /sysroot/ | cpio --quiet -it", but path must be quoted. */ - len = 64 + 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 /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) {