git.annexia.org
/
libguestfs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
configure.ac: more quoting
[libguestfs.git]
/
daemon
/
find.c
diff --git
a/daemon/find.c
b/daemon/find.c
index
6a7e3e8
..
40f1b3b
100644
(file)
--- a/
daemon/find.c
+++ b/
daemon/find.c
@@
-1,5
+1,5
@@
/* libguestfs - the guestfsd daemon
/* 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
*
* 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
@@
-48,7
+48,7
@@
input_to_nul (FILE *fp, char *buf, int maxlen)
}
char **
}
char **
-do_find (c
onst c
har *dir)
+do_find (char *dir)
{
struct stat statbuf;
int r, len, sysrootdirlen;
{
struct stat statbuf;
int r, len, sysrootdirlen;
@@
-56,40
+56,41
@@
do_find (const char *dir)
FILE *fp;
char **res = NULL;
int size = 0, alloc = 0;
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);
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);
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);
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. */
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");
reply_with_perror ("malloc");
+ free (sysrootdir);
return NULL;
}
return NULL;
}
- strcpy (cmd, "find ");
- shell_quote (cmd+5, len-5, sysrootdir);
- strcat (cmd, " -print0");
-
if (verbose)
if (verbose)
-
printf (
"%s\n", cmd);
+
fprintf (stderr,
"%s\n", cmd);
fp = popen (cmd, "r");
if (fp == NULL) {
fp = popen (cmd, "r");
if (fp == NULL) {
@@
-113,7
+114,11
@@
do_find (const char *dir)
return NULL;
}
}
return NULL;
}
}
- pclose (fp);
+ if (pclose (fp) != 0) {
+ reply_with_perror ("pclose: find");
+ free_stringslen (res, size);
+ return NULL;
+ }
if (r == -1) {
free_stringslen (res, size);
if (r == -1) {
free_stringslen (res, size);