Bug #49967 built-in libedit doesn't read .editrc on linux
Submitted: 29 Dec 2009 0:02 Modified: 2 May 2011 18:29
Reporter: Walter Doekes Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.1.37, 5.0, 5.1, next-mr bzr OS:Linux
Assigned to: Nirbhay Choubey CPU Architecture:Any
Tags: Contribution, regression

[29 Dec 2009 0:02] Walter Doekes
Description:
Somewhere after 5.1.31 cmd-line-utils/libedit/el.c got modified so that not having issetugid() disables the reading of $HOME/.editrc.

(If not HAVE_ISSETUGID then return (-1).)

Linux does not have this syscall and is therefore barred from reading .editrc.

Google tells me that issetugid can be emulated by checking get(e)uid and get(e)gid against each other. So I'm guessing that would be an adequate replacement.

See also: http://wjd.nu/notes/2009#mysql-ubuntu-readline-delete-char-karmic
for a more verbose description of the issue and my motivation for getting it fixed.

How to repeat:
Install the mysql-client on linux with --with-libedit and watch it ignore the .editrc.

Suggested fix:
--- mysql-dfsg-5.1-5.1.37/configure.in.orig	2009-12-28 23:18:40.513709610 +0100
+++ mysql-dfsg-5.1-5.1.37/configure.in	2009-12-28 23:06:32.445022108 +0100
@@ -1974,7 +1974,7 @@
     [AC_DEFINE([HAVE_VIS_H], [1],[Found vis.h and the strvis() function])])])
 
 AC_CHECK_FUNCS(strlcat strlcpy)
-AC_CHECK_FUNCS(issetugid)
+AC_CHECK_FUNCS(issetugid getuid geteuid getgid getegid)
 AC_CHECK_FUNCS(fgetln)
 AC_CHECK_FUNCS(getline flockfile)
 
--- mysql-dfsg-5.1-5.1.37/configure.orig	2009-12-28 23:18:50.324800051 +0100
+++ mysql-dfsg-5.1-5.1.37/configure	2009-12-28 23:06:21.014800251 +0100
@@ -32077,7 +32077,7 @@
 done
 
 
-for ac_func in issetugid
+for ac_func in issetugid getuid geteuid getgid getegid
 do
 as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 { $as_echo "$as_me:$LINENO: checking for $ac_func" >&5
--- mysql-dfsg-5.1-5.1.37/cmd-line-utils/libedit/el.c.orig	2009-12-28 23:21:20.273570913 +0100
+++ mysql-dfsg-5.1-5.1.37/cmd-line-utils/libedit/el.c	2009-12-28 23:21:26.703705820 +0100
@@ -478,7 +478,8 @@
 
 	fp = NULL;
 	if (fname == NULL) {
-#ifdef HAVE_ISSETUGID
+#if defined(HAVE_ISSETUGID) || (defined(HAVE_GETUID) && defined(HAVE_GETEUID) \
+	&& defined(HAVE_GETGID) && defined(HAVE_GETEGID))
 		static const char elpath[] = "/.editrc";
 /* XXXMYSQL: Portability fix (for which platforms?) */
 #ifdef MAXPATHLEN
@@ -487,8 +488,13 @@
 		char path[4096];
 #endif
 
+#ifdef HAVE_ISSETUGID
 		if (issetugid())
 			return (-1);
+#else
+		if (getuid() != geteuid() || getgid() != getegid())
+			return (-1);
+#endif 
 		if ((ptr = getenv("HOME")) == NULL)
 			return (-1);
 		if (strlcpy(path, ptr, sizeof(path)) >= sizeof(path))
[29 Dec 2009 10:51] Sveta Smirnova
Thank you for the report.

Verified as described.

$cat ~/.editrc
bind \\t ed-clear-screen
[29 Dec 2009 10:58] Sveta Smirnova
Introduced in 5.1.32
[2 May 2011 18:29] Paul DuBois
Noted in 5.1.58, 5.5.13, 5.6.3 changelogs.

On Linux, the mysql client built using the bundled libedit did not
read ~/.editrc. 

CHANGESET - http://lists.mysql.com/commits/136456