From patchwork Fri Jan 20 20:25:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 9529583 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B028D60113 for ; Fri, 20 Jan 2017 22:08:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9019D286E1 for ; Fri, 20 Jan 2017 22:08:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 84BED286EB; Fri, 20 Jan 2017 22:08:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F0D0E286E1 for ; Fri, 20 Jan 2017 22:08:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753338AbdATUZw (ORCPT ); Fri, 20 Jan 2017 15:25:52 -0500 Received: from userp1040.oracle.com ([156.151.31.81]:29243 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753217AbdATUZe (ORCPT ); Fri, 20 Jan 2017 15:25:34 -0500 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v0KKPUR5000842 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Jan 2017 20:25:30 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id v0KKPUHT032418 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Jan 2017 20:25:30 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id v0KKPTsF031048; Fri, 20 Jan 2017 20:25:30 GMT Received: from localhost (/24.21.211.40) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 20 Jan 2017 12:25:29 -0800 Subject: [PATCH 2/5] xfs_db: fix the 'source' command when passed as a -c option From: "Darrick J. Wong" To: sandeen@redhat.com, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Fri, 20 Jan 2017 12:25:28 -0800 Message-ID: <148494392855.5256.2805905613919243845.stgit@birch.djwong.org> In-Reply-To: <148494391629.5256.3328772079712970611.stgit@birch.djwong.org> References: <148494391629.5256.3328772079712970611.stgit@birch.djwong.org> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Source-IP: userv0021.oracle.com [156.151.31.71] Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The 'source' command is supposed to read commands out of a file and execute them. This works great when done from an interactive command line, but it doesn't work at all when invoked from the command line because we never actually do anything with the opened file. So don't load stdin into the input stack when we're only executing command line options, and use that to decide if source_f is executing from the command line so that we can actually run the input loop. We'll use this for the per-field fuzzing xfstests. Signed-off-by: Darrick J. Wong --- db/init.c | 2 +- db/input.c | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/db/init.c b/db/init.c index e60ac66..46af024 100644 --- a/db/init.c +++ b/db/init.c @@ -254,7 +254,6 @@ main( char **v; int start_iocur_sp; - pushfile(stdin); init(argc, argv); start_iocur_sp = iocur_sp; @@ -269,6 +268,7 @@ main( goto close_devices; } + pushfile(stdin); while (!done) { if ((input = fetchline()) == NULL) break; diff --git a/db/input.c b/db/input.c index 8f65190..7b12c97 100644 --- a/db/input.c +++ b/db/input.c @@ -145,6 +145,12 @@ get_prompt(void) return prompt; } +static bool +interactive_input(void) +{ + return inputstacksize == 1 && inputstack[0] == stdin; +} + static char * fetchline_internal(void) { @@ -156,7 +162,9 @@ fetchline_internal(void) rval = NULL; for (rlen = iscont = 0; ; ) { - if (inputstacksize == 1) { + if (curinput == NULL) + return NULL; + if (interactive_input()) { if (iscont) dbprintf("... "); else @@ -183,7 +191,8 @@ fetchline_internal(void) (len = strlen(buf)) == 0) { popfile(); if (curinput == NULL) { - dbprintf("\n"); + if (interactive_input()) + dbprintf("\n"); return NULL; } iscont = 0; @@ -314,12 +323,28 @@ source_f( char **argv) { FILE *f; + int c, done = 0; + char *input; + char **v; f = fopen(argv[1], "r"); if (f == NULL) dbprintf(_("can't open %s\n"), argv[0]); else pushfile(f); + + /* If this isn't an interactive shell, run the commands now. */ + if (inputstacksize == 0 || inputstack[0] == stdin) + return 0; + while (!done) { + if ((input = fetchline_internal()) == NULL) + break; + v = breakline(input, &c); + if (c) + done = command(c, v); + doneline(input, v); + } + return 0; }