X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=daemon%2Ffind.c;h=2147c57946c7d63768240a93cb712d604189bb34;hb=7eda9e6fb2b1f6504167ab650886f5a336fc6919;hp=85994b6dc4e4c8e73b8ecfdde7cebb2ebf75682a;hpb=a7b73d4a1e09f12b2002083618056f0c823c1dcf;p=libguestfs.git diff --git a/daemon/find.c b/daemon/find.c index 85994b6..2147c57 100644 --- a/daemon/find.c +++ b/daemon/find.c @@ -48,7 +48,7 @@ input_to_nul (FILE *fp, char *buf, int maxlen) } char ** -do_find (char *dir) +do_find (const char *dir) { struct stat statbuf; int r, len, sysrootdirlen; @@ -56,40 +56,38 @@ do_find (char *dir) FILE *fp; char **res = NULL; int size = 0, alloc = 0; - char sysrootdir[PATH_MAX]; + char *sysrootdir; char str[PATH_MAX]; - NEED_ROOT (NULL); - ABS_PATH (dir, NULL); - - snprintf (sysrootdir, sizeof sysrootdir, "/sysroot%s", dir); + sysrootdir = sysroot_path (dir); + if (!sysrootdir) { + reply_with_perror ("malloc"); + return NULL; + } r = stat (sysrootdir, &statbuf); if (r == -1) { reply_with_perror ("%s", dir); + free (sysrootdir); return NULL; } if (!S_ISDIR (statbuf.st_mode)) { reply_with_error ("%s: not a directory", dir); + free (sysrootdir); return NULL; } sysrootdirlen = strlen (sysrootdir); /* Assemble the external find command. */ - len = 2 * sysrootdirlen + 32; - cmd = malloc (len); - if (!cmd) { + if (asprintf_nowarn (&cmd, "find %Q -print0", sysrootdir) == -1) { reply_with_perror ("malloc"); + free (sysrootdir); return NULL; } - strcpy (cmd, "find "); - shell_quote (cmd+5, len-5, sysrootdir); - strcat (cmd, " -print0"); - if (verbose) - printf ("%s\n", cmd); + fprintf (stderr, "%s\n", cmd); fp = popen (cmd, "r"); if (fp == NULL) {