summaryrefslogtreecommitdiff
path: root/source3/lib/readline.c
diff options
context:
space:
mode:
authorJames Peach <jpeach@samba.org>2006-06-15 23:51:20 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:17:30 -0500
commit06491a4cb12d8753c63525b3ba4d754d2ab1e822 (patch)
tree305b4dbe67646ac5e09cfc599a66ea334acd69f9 /source3/lib/readline.c
parentae2fb4f1093e28e4656371b9bbeb229fd1ed1ada (diff)
downloadsamba-06491a4cb12d8753c63525b3ba4d754d2ab1e822.tar.gz
samba-06491a4cb12d8753c63525b3ba4d754d2ab1e822.tar.bz2
samba-06491a4cb12d8753c63525b3ba4d754d2ab1e822.zip
r16274: Fix the smbclient prompting behaviour for both systems that have
libreadline and those that don't. We always use the built-in readline replacement for non-interactive mode. Interactive prompts are always emitted to stdout and non-interactive mode never prompts at all. Introduce x_fdup to avoid spuriously closing stdout when a logfile is specified on the command line and setup_logging is called a second time. (This used to be commit 848ac756f651a4be231e5635580c0fd5f3d3fa0e)
Diffstat (limited to 'source3/lib/readline.c')
-rw-r--r--source3/lib/readline.c65
1 files changed, 38 insertions, 27 deletions
diff --git a/source3/lib/readline.c b/source3/lib/readline.c
index c1f1dc7f40..1f599dc0a7 100644
--- a/source3/lib/readline.c
+++ b/source3/lib/readline.c
@@ -59,8 +59,11 @@ static char *smb_readline_replacement(const char *prompt, void (*callback)(void)
int fd = x_fileno(x_stdin);
char *ret;
- x_fprintf(dbf, "%s", prompt);
- x_fflush(dbf);
+ /* Prompt might be NULL in non-interactive mode. */
+ if (prompt) {
+ x_fprintf(x_stdout, "%s", prompt);
+ x_fflush(x_stdout);
+ }
while (1) {
timeout.tv_sec = 5;
@@ -85,34 +88,42 @@ static char *smb_readline_replacement(const char *prompt, void (*callback)(void)
char *smb_readline(const char *prompt, void (*callback)(void),
char **(completion_fn)(const char *text, int start, int end))
{
+ char *ret;
+ BOOL interactive;
+
+ interactive = isatty(x_fileno(x_stdin)) || getenv("CLI_FORCE_INTERACTIVE");
+ if (!interactive) {
+ return smb_readline_replacement(NULL, callback, completion_fn);
+ }
+
#if HAVE_LIBREADLINE
- if (isatty(x_fileno(x_stdin))) {
- char *ret;
-
- /* Aargh! Readline does bizzare things with the terminal width
- that mucks up expect(1). Set CLI_NO_READLINE in the environment
- to force readline not to be used. */
-
- if (getenv("CLI_NO_READLINE"))
- return smb_readline_replacement(prompt, callback, completion_fn);
-
- if (completion_fn) {
- /* The callback prototype has changed slightly between
- different versions of Readline, so the same function
- works in all of them to date, but we get compiler
- warnings in some. */
- rl_attempted_completion_function = RL_COMPLETION_CAST completion_fn;
- }
- if (callback)
- rl_event_hook = (Function *)callback;
- ret = readline(prompt);
- if (ret && *ret)
- add_history(ret);
- return ret;
- } else
+ /* Aargh! Readline does bizzare things with the terminal width
+ that mucks up expect(1). Set CLI_NO_READLINE in the environment
+ to force readline not to be used. */
+
+ if (getenv("CLI_NO_READLINE"))
+ return smb_readline_replacement(prompt, callback, completion_fn);
+
+ if (completion_fn) {
+ /* The callback prototype has changed slightly between
+ different versions of Readline, so the same function
+ works in all of them to date, but we get compiler
+ warnings in some. */
+ rl_attempted_completion_function = RL_COMPLETION_CAST completion_fn;
+ }
+
+ if (callback)
+ rl_event_hook = (Function *)callback;
+ ret = readline(prompt);
+ if (ret && *ret)
+ add_history(ret);
+
+#else
+ ret = smb_readline_replacement(prompt, callback, completion_fn);
#endif
- return smb_readline_replacement(prompt, callback, completion_fn);
+
+ return ret;
}
/****************************************************************************