From 07698b55a874c5172dad01911d224fda87faf26b Mon Sep 17 00:00:00 2001 From: Erlend Midttun Date: Mon, 25 Sep 2017 10:49:58 +0000 Subject: [PATCH] =?UTF-8?q?Kopierer=20inn=20denne=20fila=20fr=C3=A5=20pakk?= =?UTF-8?q?en?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mysql-dbadm.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/mysql-dbadm.c b/mysql-dbadm.c index 8a54a87..4f5b721 100644 --- a/mysql-dbadm.c +++ b/mysql-dbadm.c @@ -363,6 +363,7 @@ editperm(MYSQL *pmysql, const char *db) char fn[] = "/tmp/mysql-dbadm.tmp.XXXXXX"; FILE *f; char *editor; + char *cmd; char line[1024]; /* buffer to hold one line */ char *cp; /* used to interate through a line */ char *user, *select_priv, *insert_priv, *update_priv, *delete_priv, @@ -414,13 +415,15 @@ editperm(MYSQL *pmysql, const char *db) exit(1); } - /* exec sh -c '${EDITOR:-pico} "$1"' sh /tmp/filename - * - * The parameter expansion syntax doesn't work with old bourne - * shells, but it works with newer bourne as well as POSIX shells, - * so it should be fine. - */ - execlp("sh", "sh", "-c", "${EDITOR:-pico} \"$1\"", "sh", fn, NULL); + editor = getenv("EDITOR"); + if (!editor) + editor = "pico"; /* OK since editor won't be freed */ + + cmd = malloc(sizeof(char) * strlen(editor) + 7); + sprintf(cmd, "%s \"$1\"", editor); + + /* sh -c '$EDITOR "$1"' sh "$fn" */ + execlp("sh", "sh", "-c", cmd, "sh", fn, NULL); perror("Failed to execute editor"); fprintf(stderr, "Make sure the EDITOR environment variable contains" " a valid editor\n");