Just letting sh expand the env var is saner and simpler.

This commit is contained in:
Geir Hauge 2012-12-11 15:18:30 +00:00
parent dca812bd27
commit 22615506bf
1 changed files with 7 additions and 10 deletions

View File

@ -363,7 +363,6 @@ 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,
@ -415,15 +414,13 @@ editperm(MYSQL *pmysql, const char *db)
exit(1);
}
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);
/* 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);
perror("Failed to execute editor");
fprintf(stderr, "Make sure the EDITOR environment variable contains"
" a valid editor\n");