|
|
89952e |
From c8dc4235614292020f82a031545d66c000b455f9 Mon Sep 17 00:00:00 2001
|
|
|
89952e |
From: "Darrick J. Wong" <darrick.wong@oracle.com>
|
|
|
89952e |
Date: Wed, 25 Jan 2017 20:02:43 -0600
|
|
|
89952e |
Subject: [PATCH] xfs_db: fix the 'source' command when passed as a -c option
|
|
|
89952e |
|
|
|
89952e |
The 'source' command is supposed to read commands out of a file and
|
|
|
89952e |
execute them. This works great when done from an interactive command
|
|
|
89952e |
line, but it doesn't work at all when invoked from the command line
|
|
|
89952e |
because we never actually do anything with the opened file.
|
|
|
89952e |
|
|
|
89952e |
So don't load stdin into the input stack when we're only executing
|
|
|
89952e |
command line options, and use that to decide if source_f is executing
|
|
|
89952e |
from the command line so that we can actually run the input loop. We'll
|
|
|
89952e |
use this for the per-field fuzzing xfstests.
|
|
|
89952e |
|
|
|
89952e |
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
|
|
|
89952e |
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
|
|
|
89952e |
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
|
|
|
89952e |
---
|
|
|
89952e |
db/init.c | 2 +-
|
|
|
89952e |
db/input.c | 43 +++++++++++++++++++++++++++++++++----------
|
|
|
89952e |
2 files changed, 34 insertions(+), 11 deletions(-)
|
|
|
89952e |
|
|
|
89952e |
Index: xfsprogs-4.5.0/db/init.c
|
|
|
89952e |
===================================================================
|
|
|
89952e |
--- xfsprogs-4.5.0.orig/db/init.c
|
|
|
89952e |
+++ xfsprogs-4.5.0/db/init.c
|
|
|
89952e |
@@ -192,7 +192,6 @@ main(
|
|
|
89952e |
char **v;
|
|
|
89952e |
int start_iocur_sp;
|
|
|
89952e |
|
|
|
89952e |
- pushfile(stdin);
|
|
|
89952e |
init(argc, argv);
|
|
|
89952e |
start_iocur_sp = iocur_sp;
|
|
|
89952e |
|
|
|
89952e |
@@ -207,6 +206,7 @@ main(
|
|
|
89952e |
goto close_devices;
|
|
|
89952e |
}
|
|
|
89952e |
|
|
|
89952e |
+ pushfile(stdin);
|
|
|
89952e |
while (!done) {
|
|
|
89952e |
if ((input = fetchline()) == NULL)
|
|
|
89952e |
break;
|
|
|
89952e |
Index: xfsprogs-4.5.0/db/input.c
|
|
|
89952e |
===================================================================
|
|
|
89952e |
--- xfsprogs-4.5.0.orig/db/input.c
|
|
|
89952e |
+++ xfsprogs-4.5.0/db/input.c
|
|
|
89952e |
@@ -156,7 +156,7 @@ fetchline_internal(void)
|
|
|
89952e |
|
|
|
89952e |
rval = NULL;
|
|
|
89952e |
for (rlen = iscont = 0; ; ) {
|
|
|
89952e |
- if (inputstacksize == 1) {
|
|
|
89952e |
+ if (curinput == stdin) {
|
|
|
89952e |
if (iscont)
|
|
|
89952e |
dbprintf("... ");
|
|
|
89952e |
else
|
|
|
89952e |
@@ -181,18 +181,24 @@ fetchline_internal(void)
|
|
|
89952e |
}
|
|
|
89952e |
if (ferror(curinput) || feof(curinput) ||
|
|
|
89952e |
(len = strlen(buf)) == 0) {
|
|
|
89952e |
- popfile();
|
|
|
89952e |
- if (curinput == NULL) {
|
|
|
89952e |
+ /*
|
|
|
89952e |
+ * No more input at this inputstack level; pop
|
|
|
89952e |
+ * our fd off and return so that a lower
|
|
|
89952e |
+ * level fetchline can handle us. If this was
|
|
|
89952e |
+ * an interactive session, print a newline
|
|
|
89952e |
+ * because ^D doesn't emit one.
|
|
|
89952e |
+ */
|
|
|
89952e |
+ if (curinput == stdin)
|
|
|
89952e |
dbprintf("\n");
|
|
|
89952e |
- return NULL;
|
|
|
89952e |
- }
|
|
|
89952e |
+
|
|
|
89952e |
+ popfile();
|
|
|
89952e |
iscont = 0;
|
|
|
89952e |
rlen = 0;
|
|
|
89952e |
if (rval) {
|
|
|
89952e |
xfree(rval);
|
|
|
89952e |
rval = NULL;
|
|
|
89952e |
}
|
|
|
89952e |
- continue;
|
|
|
89952e |
+ return NULL;
|
|
|
89952e |
}
|
|
|
89952e |
if (inputstacksize == 1)
|
|
|
89952e |
logprintf("%s", buf);
|
|
|
89952e |
@@ -225,7 +231,9 @@ fetchline(void)
|
|
|
89952e |
|
|
|
89952e |
if (inputstacksize == 1) {
|
|
|
89952e |
line = readline(get_prompt());
|
|
|
89952e |
- if (line && *line) {
|
|
|
89952e |
+ if (!line)
|
|
|
89952e |
+ dbprintf("\n");
|
|
|
89952e |
+ else if (line && *line) {
|
|
|
89952e |
add_history(line);
|
|
|
89952e |
logprintf("%s", line);
|
|
|
89952e |
}
|
|
|
89952e |
@@ -314,12 +322,27 @@ source_f(
|
|
|
89952e |
char **argv)
|
|
|
89952e |
{
|
|
|
89952e |
FILE *f;
|
|
|
89952e |
+ int c, done = 0;
|
|
|
89952e |
+ char *input;
|
|
|
89952e |
+ char **v;
|
|
|
89952e |
|
|
|
89952e |
f = fopen(argv[1], "r");
|
|
|
89952e |
- if (f == NULL)
|
|
|
89952e |
+ if (f == NULL) {
|
|
|
89952e |
dbprintf(_("can't open %s\n"), argv[0]);
|
|
|
89952e |
- else
|
|
|
89952e |
- pushfile(f);
|
|
|
89952e |
+ return 0;
|
|
|
89952e |
+ }
|
|
|
89952e |
+
|
|
|
89952e |
+ /* Run the sourced commands now. */
|
|
|
89952e |
+ pushfile(f);
|
|
|
89952e |
+ while (!done) {
|
|
|
89952e |
+ if ((input = fetchline_internal()) == NULL)
|
|
|
89952e |
+ break;
|
|
|
89952e |
+ v = breakline(input, &c);
|
|
|
89952e |
+ if (c)
|
|
|
89952e |
+ done = command(c, v);
|
|
|
89952e |
+ doneline(input, v);
|
|
|
89952e |
+ }
|
|
|
89952e |
+
|
|
|
89952e |
return 0;
|
|
|
89952e |
}
|
|
|
89952e |
|