X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=daemon%2Fgrep.c;h=3562f3691c0fbe88fbe6957ff58ade893c14feef;hb=d24e088dc3475db4496e5cbd67c143c25ef12b1e;hp=d1f5a3f773f837bbadee955f9416f3091b6568dc;hpb=84fc760439e82e6b3616abd0d1f9bd7d7eb01ec0;p=libguestfs.git diff --git a/daemon/grep.c b/daemon/grep.c index d1f5a3f..3562f36 100644 --- a/daemon/grep.c +++ b/daemon/grep.c @@ -13,7 +13,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include @@ -22,31 +22,33 @@ #include #include #include +#include -#include "../src/guestfs_protocol.h" +#include "guestfs_protocol.h" #include "daemon.h" #include "actions.h" static char ** grep (const char *prog, const char *flag, const char *regex, const char *path) { - char *buf; char *out, *err; - int r; + int fd, flags, r; char **lines; - /* Make the path relative to /sysroot. */ - buf = sysroot_path (path); - if (!buf) { - reply_with_perror ("malloc"); + CHROOT_IN; + fd = open (path, O_RDONLY); + CHROOT_OUT; + + if (fd == -1) { + reply_with_perror ("%s", path); return NULL; } /* Note that grep returns an error if no match. We want to * suppress this error and return an empty list. */ - r = commandr (&out, &err, prog, flag, regex, buf, NULL); - free (buf); + flags = COMMAND_FLAG_CHROOT_COPY_FILE_TO_STDIN | fd; + r = commandrf (&out, &err, flags, prog, flag, regex, NULL); if (r == -1 || r > 1) { reply_with_error ("%s %s %s: %s", prog, flag, regex, err); free (out);