Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 7 May 2016 18:44:30 +0000 (UTC)
From:      Baptiste Daroussin <bapt@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r299217 - head/usr.bin/sdiff
Message-ID:  <201605071844.u47IiUkS007357@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201605071844.u47IiUkS007357>