summaryrefslogtreecommitdiffstats
path: root/source/a/util-linux/0001-chfn-Make-readline-prompt-for-each-field-on-a-separa.patch
blob: 2c2f3903dd203e0e53e0f6bf74040164e63eb0ff (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
From 49848aa53ae3a599277e8ceb50feda565f140b45 Mon Sep 17 00:00:00 2001
From: Damien Goutte-Gattat <dgouttegattat@incenp.org>
Date: Sat, 27 Jun 2020 19:58:13 +0100
Subject: [PATCH] chfn: Make readline prompt for each field on a separate line

When readline is called to get user input, it is called without
a prompt argument. As a result, if the user does not enter anything
for a given field, then the next field is displayed on the same
line, yielding the following output:

  $ chfn
  Changing finger information for user.
  Password:
  Name []: Office []: Office Phone []: Home Phone []:

instead of the expected:

  $ chfn
  Changing finger information for user.
  Password:
  Full Name []:
  Room Number []:
  Work Phone []:
  Home Phone []:

This patch restores the expected behavior by feeding readline with
a character to display as "prompt".

[kzak@redhat.com: - do the same change in chsh
                  - use ' ' rather than '\n' for non-readline code]

Signed-off-by: Damien Goutte-Gattat <dgouttegattat@incenp.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
---
 login-utils/chfn.c | 5 +++--
 login-utils/chsh.c | 5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/login-utils/chfn.c b/login-utils/chfn.c
index 1b203a83e..4b2b42912 100644
--- a/login-utils/chfn.c
+++ b/login-utils/chfn.c
@@ -235,12 +235,13 @@ static char *ask_new_field(struct chfn_control *ctl, const char *question,
 	if (!def_val)
 		def_val = "";
 	while (true) {
-		printf("%s [%s]: ", question, def_val);
+		printf("%s [%s]:", question, def_val);
 		__fpurge(stdin);
 #ifdef HAVE_LIBREADLINE
 		rl_bind_key('\t', rl_insert);
-		if ((buf = readline(NULL)) == NULL)
+		if ((buf = readline(" ")) == NULL)
 #else
+		putchar(' ');
 		if (getline(&buf, &dummy, stdin) < 0)
 #endif
 			errx(EXIT_FAILURE, _("Aborted."));
diff --git a/login-utils/chsh.c b/login-utils/chsh.c
index a9ebec86f..17cc9f1e0 100644
--- a/login-utils/chsh.c
+++ b/login-utils/chsh.c
@@ -205,10 +205,11 @@ static char *ask_new_shell(char *question, char *oldshell)
 #endif
 	if (!oldshell)
 		oldshell = "";
-	printf("%s [%s]\n", question, oldshell);
+	printf("%s [%s]:", question, oldshell);
 #ifdef HAVE_LIBREADLINE
-	if ((ans = readline("> ")) == NULL)
+	if ((ans = readline(" ")) == NULL)
 #else
+	putchar(' ');
 	if (getline(&ans, &dummy, stdin) < 0)
 #endif
 		return NULL;
-- 
2.27.0