svn commit: r299217 - head/usr.bin/sdiff
Baptiste Daroussin
bapt at FreeBSD.org
Sat May 7 18:44:32 UTC 2016
Author: bapt
Date: Sat May 7 18:44:30 2016
New Revision: 299217
URL: https://svnweb.freebsd.org/changeset/base/299217
Log:
Directly call the editor if needed instead of spawning /bin/sh
Modified:
head/usr.bin/sdiff/edit.c
Modified: head/usr.bin/sdiff/edit.c
==============================================================================
--- head/usr.bin/sdiff/edit.c Sat May 7 18:21:58 2016 (r299216)
+++ head/usr.bin/sdiff/edit.c Sat May 7 18:44:30 2016 (r299217)
@@ -35,19 +35,16 @@ int editit(const char *);
int
editit(const char *pathname)
{
- char *argp[] = {"sh", "-c", NULL, NULL}, *ed, *p;
sig_t sighup, sigint, sigquit, sigchld;
pid_t pid;
int saved_errno, st, ret = -1;
+ const char *ed;
ed = getenv("VISUAL");
- if (ed == NULL || ed[0] == '\0')
+ if (ed == NULL)
ed = getenv("EDITOR");
- if (ed == NULL || ed[0] == '\0')
+ if (ed == NULL)
ed = _PATH_VI;
- if (asprintf(&p, "%s %s", ed, pathname) == -1)
- return (-1);
- argp[2] = p;
sighup = signal(SIGHUP, SIG_IGN);
sigint = signal(SIGINT, SIG_IGN);
@@ -56,7 +53,7 @@ editit(const char *pathname)
if ((pid = fork()) == -1)
goto fail;
if (pid == 0) {
- execv(_PATH_BSHELL, argp);
+ execlp(ed, ed, pathname, (char *)NULL);
_exit(127);
}
while (waitpid(pid, &st, 0) == -1)
@@ -73,7 +70,6 @@ editit(const char *pathname)
(void)signal(SIGINT, sigint);
(void)signal(SIGQUIT, sigquit);
(void)signal(SIGCHLD, sigchld);
- free(p);
errno = saved_errno;
return (ret);
}
More information about the svn-src-head
mailing list