svn commit: r284912 - head/usr.bin/units
Julio Merino
jmmv at FreeBSD.org
Sun Jun 28 16:43:08 UTC 2015
Author: jmmv
Date: Sun Jun 28 16:43:07 2015
New Revision: 284912
URL: https://svnweb.freebsd.org/changeset/base/284912
Log:
Only initialize libedit when necessary
The code path to support units conversions from the command line
need not initialize neither libedit nor the history. Therefore, only do
that when in interactive mode.
This hides the issue reported in PR bin/201167 whereby running commands
of the form 'echo "$(units ft in)"' would corrupt the terminal. The real
issue causing the corruption most likely still remains somewhere.
PR: bin/201167
Differential Revision: D2935
Reviewed by: eadler
Modified:
head/usr.bin/units/units.c
Modified: head/usr.bin/units/units.c
==============================================================================
--- head/usr.bin/units/units.c Sun Jun 28 12:52:28 2015 (r284911)
+++ head/usr.bin/units/units.c Sun Jun 28 16:43:07 2015 (r284912)
@@ -802,17 +802,6 @@ main(int argc, char **argv)
if (!readfile)
readunits(NULL);
- inhistory = history_init();
- el = el_init(argv[0], stdin, stdout, stderr);
- el_set(el, EL_PROMPT, &prompt);
- el_set(el, EL_EDITOR, "emacs");
- el_set(el, EL_SIGNAL, 1);
- el_set(el, EL_HIST, history, inhistory);
- el_source(el, NULL);
- history(inhistory, &ev, H_SETSIZE, 800);
- if (inhistory == 0)
- err(1, "Could not initialize history");
-
if (cap_enter() < 0 && errno != ENOSYS)
err(1, "unable to enter capability mode");
@@ -828,6 +817,17 @@ main(int argc, char **argv)
showanswer(&have, &want);
}
else {
+ inhistory = history_init();
+ el = el_init(argv[0], stdin, stdout, stderr);
+ el_set(el, EL_PROMPT, &prompt);
+ el_set(el, EL_EDITOR, "emacs");
+ el_set(el, EL_SIGNAL, 1);
+ el_set(el, EL_HIST, history, inhistory);
+ el_source(el, NULL);
+ history(inhistory, &ev, H_SETSIZE, 800);
+ if (inhistory == 0)
+ err(1, "Could not initialize history");
+
if (!quiet)
printf("%d units, %d prefixes\n", unitcount,
prefixcount);
@@ -858,9 +858,10 @@ main(int argc, char **argv)
completereduce(&want));
showanswer(&have, &want);
}
+
+ history_end(inhistory);
+ el_end(el);
}
- history_end(inhistory);
- el_end(el);
return (0);
}
More information about the svn-src-head
mailing list