[PATCH 2/2] chfn: stop adding trailing commas to gecos

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The other field should not appear automatically, it causes not-automatically
trimmed trailing commas to appear in gecos.

Signed-off-by: Sami Kerola <kerolasa@xxxxxx>
---
 login-utils/chfn.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/login-utils/chfn.c b/login-utils/chfn.c
index 2d58fc3..c56f510 100644
--- a/login-utils/chfn.c
+++ b/login-utils/chfn.c
@@ -346,7 +346,7 @@ static void add_missing(struct chfn_control *ctl)
 	ctl->newf.office = find_field(ctl->newf.office, ctl->oldf.office);
 	ctl->newf.office_phone = find_field(ctl->newf.office_phone, ctl->oldf.office_phone);
 	ctl->newf.home_phone = find_field(ctl->newf.home_phone, ctl->oldf.home_phone);
-	ctl->newf.other = find_field(ctl->newf.other, ctl->oldf.other);
+	ctl->newf.other = ctl->oldf.other ? ctl->oldf.other : NULL;
 	printf("\n");
 }
 
@@ -361,12 +361,13 @@ static int save_new_data(struct chfn_control *ctl)
 	int len;
 
 	/* create the new gecos string */
-	len = xasprintf(&gecos, "%s,%s,%s,%s,%s",
+	len = xasprintf(&gecos, "%s,%s,%s,%s%s%s",
 			ctl->newf.full_name,
 			ctl->newf.office,
 			ctl->newf.office_phone,
 			ctl->newf.home_phone,
-			ctl->newf.other);
+			ctl->newf.other ? "," : "",
+			ctl->newf.other ? ctl->newf.other : "");
 
 	/* remove trailing empty fields (but not subfields of ctl->newf.other) */
 	if (!ctl->newf.other || ctl->trim) {
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux