public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfsdump: handle Ctrl-D during prompts
@ 2011-11-09 22:15 Bill Kendall
  2011-11-10  8:31 ` Christoph Hellwig
  0 siblings, 1 reply; 3+ messages in thread
From: Bill Kendall @ 2011-11-09 22:15 UTC (permalink / raw)
  To: xfs

xfsdump does not currently handle Ctrl-D well during a dialog
prompt. If some text is entered followed by Ctrl-D, an assert
will trip because xfsdump expects a new-line character at the
end of the user's input (or if asserts are disabled, the last
character the user entered will be dropped).

If Ctrl-D is entered without entering any response, some dialog
callers (e.g., tree_subtree_inter()) will abort because they
receive an unexpected response code.

This patch changes xfsdump to treat Ctrl-D as if the user hit
enter. User input (if any) will be passed back to the caller,
and a new line will be echoed to the terminal.

Signed-off-by: Bill Kendall <wkendall@sgi.com>
---
 common/dlog.c |   17 +++++++++--------
 1 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/common/dlog.c b/common/dlog.c
index 51666cf..ddd5524 100644
--- a/common/dlog.c
+++ b/common/dlog.c
@@ -489,17 +489,18 @@ promptinput( char *buf,
 			*exceptionixp = sigquitix;
 		}
 		return BOOL_FALSE;
-	} else if ( nread == 0 ) {
-		*exceptionixp = timeoutix;
-		if ( bufsz > 0 ) {
-			buf[ 0 ] = 0;
-		}
-		return BOOL_FALSE;
 	} else {
 		ASSERT( dlog_signo_received == -1 );
 		ASSERT( ( size_t )nread < bufsz );
-		ASSERT( buf[ nread - 1 ] == '\n' );
-		buf[ nread - 1 ] = 0;
+		/* Eat the newline if there is one. If there isn't one
+		 * (e.g., Ctrl-D) echo one to keep the output readable.
+		 */
+		if ( !nread || buf[ nread - 1 ] != '\n' ) {
+			buf[ nread ] = 0;
+			mlog( MLOG_NORMAL | MLOG_NOLOCK | MLOG_BARE, "\n" );
+		} else {
+			buf[ nread - 1 ] = 0;
+		}
 		*exceptionixp = 0;
 		return BOOL_TRUE;
 	}
-- 
1.7.0.4

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] xfsdump: handle Ctrl-D during prompts
  2011-11-09 22:15 [PATCH] xfsdump: handle Ctrl-D during prompts Bill Kendall
@ 2011-11-10  8:31 ` Christoph Hellwig
  2011-11-10 16:39   ` Bill Kendall
  0 siblings, 1 reply; 3+ messages in thread
From: Christoph Hellwig @ 2011-11-10  8:31 UTC (permalink / raw)
  To: Bill Kendall; +Cc: xfs

On Wed, Nov 09, 2011 at 04:15:46PM -0600, Bill Kendall wrote:
> xfsdump does not currently handle Ctrl-D well during a dialog
> prompt. If some text is entered followed by Ctrl-D, an assert
> will trip because xfsdump expects a new-line character at the
> end of the user's input (or if asserts are disabled, the last
> character the user entered will be dropped).
> 
> If Ctrl-D is entered without entering any response, some dialog
> callers (e.g., tree_subtree_inter()) will abort because they
> receive an unexpected response code.
> 
> This patch changes xfsdump to treat Ctrl-D as if the user hit
> enter. User input (if any) will be passed back to the caller,
> and a new line will be echoed to the terminal.

Shouldn't Ctrl+D cause us to ignore the input that was added
before?  That's what I would expect from command line applications.

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] xfsdump: handle Ctrl-D during prompts
  2011-11-10  8:31 ` Christoph Hellwig
@ 2011-11-10 16:39   ` Bill Kendall
  0 siblings, 0 replies; 3+ messages in thread
From: Bill Kendall @ 2011-11-10 16:39 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: xfs

Christoph Hellwig wrote:
> On Wed, Nov 09, 2011 at 04:15:46PM -0600, Bill Kendall wrote:
>> xfsdump does not currently handle Ctrl-D well during a dialog
>> prompt. If some text is entered followed by Ctrl-D, an assert
>> will trip because xfsdump expects a new-line character at the
>> end of the user's input (or if asserts are disabled, the last
>> character the user entered will be dropped).
>>
>> If Ctrl-D is entered without entering any response, some dialog
>> callers (e.g., tree_subtree_inter()) will abort because they
>> receive an unexpected response code.
>>
>> This patch changes xfsdump to treat Ctrl-D as if the user hit
>> enter. User input (if any) will be passed back to the caller,
>> and a new line will be echoed to the terminal.
> 
> Shouldn't Ctrl+D cause us to ignore the input that was added
> before?  That's what I would expect from command line applications.

Ctrl-C will behave the way you describe.

I tried a some interactive programs (parted, python, sftp, bash,
xfs_db), and Ctrl-D seems to be ignored if there's already some input.
I'll rework the patch to behave this way unless I hear back from
you.

Thanks,
Bill

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-11-10 16:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-09 22:15 [PATCH] xfsdump: handle Ctrl-D during prompts Bill Kendall
2011-11-10  8:31 ` Christoph Hellwig
2011-11-10 16:39   ` Bill Kendall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox