git.annexia.org
/
libguestfs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Version 1.10.11.
[libguestfs.git]
/
daemon
/
grep.c
diff --git
a/daemon/grep.c
b/daemon/grep.c
index
c51dc0b
..
09683ef
100644
(file)
--- a/
daemon/grep.c
+++ b/
daemon/grep.c
@@
-22,34
+22,33
@@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <fcntl.h>
-#include "
../src/
guestfs_protocol.h"
+#include "guestfs_protocol.h"
#include "daemon.h"
#include "actions.h"
static char **
#include "daemon.h"
#include "actions.h"
static char **
-grep (const char *prog, const char *flag, c
har *regex,
char *path)
+grep (const char *prog, const char *flag, c
onst char *regex, const
char *path)
{
{
- char *buf;
char *out, *err;
char *out, *err;
- int r;
+ int
fd, flags,
r;
char **lines;
char **lines;
- NEED_ROOT (NULL);
- ABS_PATH (path, NULL);
+ CHROOT_IN;
+ fd = open (path, O_RDONLY);
+ CHROOT_OUT;
- /* Make the path relative to /sysroot. */
- buf = sysroot_path (path);
- if (!buf) {
- reply_with_perror ("malloc");
+ 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.
*/
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);
if (r == -1 || r > 1) {
reply_with_error ("%s %s %s: %s", prog, flag, regex, err);
free (out);
@@
-67,74
+66,74
@@
grep (const char *prog, const char *flag, char *regex, char *path)
}
char **
}
char **
-do_grep (c
har *regex,
char *path)
+do_grep (c
onst char *regex, const
char *path)
{
/* The "--" is not really needed, but it helps when we don't need a flag. */
return grep ("grep", "--", regex, path);
}
char **
{
/* The "--" is not really needed, but it helps when we don't need a flag. */
return grep ("grep", "--", regex, path);
}
char **
-do_egrep (c
har *regex,
char *path)
+do_egrep (c
onst char *regex, const
char *path)
{
return grep ("egrep", "--", regex, path);
}
char **
{
return grep ("egrep", "--", regex, path);
}
char **
-do_fgrep (c
har *regex,
char *path)
+do_fgrep (c
onst char *regex, const
char *path)
{
return grep ("fgrep", "--", regex, path);
}
char **
{
return grep ("fgrep", "--", regex, path);
}
char **
-do_grepi (c
har *regex,
char *path)
+do_grepi (c
onst char *regex, const
char *path)
{
return grep ("grep", "-i", regex, path);
}
char **
{
return grep ("grep", "-i", regex, path);
}
char **
-do_egrepi (c
har *regex,
char *path)
+do_egrepi (c
onst char *regex, const
char *path)
{
return grep ("egrep", "-i", regex, path);
}
char **
{
return grep ("egrep", "-i", regex, path);
}
char **
-do_fgrepi (c
har *regex,
char *path)
+do_fgrepi (c
onst char *regex, const
char *path)
{
return grep ("fgrep", "-i", regex, path);
}
char **
{
return grep ("fgrep", "-i", regex, path);
}
char **
-do_zgrep (c
har *regex,
char *path)
+do_zgrep (c
onst char *regex, const
char *path)
{
return grep ("zgrep", "--", regex, path);
}
char **
{
return grep ("zgrep", "--", regex, path);
}
char **
-do_zegrep (c
har *regex,
char *path)
+do_zegrep (c
onst char *regex, const
char *path)
{
return grep ("zegrep", "--", regex, path);
}
char **
{
return grep ("zegrep", "--", regex, path);
}
char **
-do_zfgrep (c
har *regex,
char *path)
+do_zfgrep (c
onst char *regex, const
char *path)
{
return grep ("zfgrep", "--", regex, path);
}
char **
{
return grep ("zfgrep", "--", regex, path);
}
char **
-do_zgrepi (c
har *regex,
char *path)
+do_zgrepi (c
onst char *regex, const
char *path)
{
return grep ("zgrep", "-i", regex, path);
}
char **
{
return grep ("zgrep", "-i", regex, path);
}
char **
-do_zegrepi (c
har *regex,
char *path)
+do_zegrepi (c
onst char *regex, const
char *path)
{
return grep ("zegrep", "-i", regex, path);
}
char **
{
return grep ("zegrep", "-i", regex, path);
}
char **
-do_zfgrepi (c
har *regex,
char *path)
+do_zfgrepi (c
onst char *regex, const
char *path)
{
return grep ("zfgrep", "-i", regex, path);
}
{
return grep ("zfgrep", "-i", regex, path);
}