X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=daemon%2Finitrd.c;h=9c92fee598bc24e4d054f0a0b2da93d6778f04b2;hb=835c0186c8771bb1c850f6c82356f9c731323413;hp=513ed8daa0ba0e0a3299cf9f6cf2d68ec6c46e53;hpb=4dff42aa13dd726fb6b02843d0f4db4b4b330fe3;p=libguestfs.git diff --git a/daemon/initrd.c b/daemon/initrd.c index 513ed8d..9c92fee 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 @@ -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) { @@ -78,7 +71,7 @@ do_initrd_list (char *path) return NULL; } - if (pclose (fp) == -1) { + if (pclose (fp) != 0) { reply_with_perror ("pclose"); free_strings (filenames); return NULL;