X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2Finitrd.c;h=59749bba89967addfe6f0204f2371d39134cd377;hp=2d6cbddec010a758ce819adb53d2328fcfa55b55;hb=afaff775c12f32b7912f194e2fcc8e76b8c82572;hpb=3e2d925717d1dac6b3862e98192c12d1080c2152 diff --git a/daemon/initrd.c b/daemon/initrd.c index 2d6cbdd..59749bb 100644 --- a/daemon/initrd.c +++ b/daemon/initrd.c @@ -1,5 +1,5 @@ /* libguestfs - the guestfsd daemon - * Copyright (C) 2009 Red Hat Inc. + * Copyright (C) 2009 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 @@ -31,28 +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/ | 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) {