summaryrefslogtreecommitdiffstats
path: root/usr.bin/units
diff options
context:
space:
mode:
authorjmmv <jmmv@FreeBSD.org>2015-06-28 16:43:07 +0000
committerjmmv <jmmv@FreeBSD.org>2015-06-28 16:43:07 +0000
commit60e4da10152ec074703107ef2ed5b40182c294ca (patch)
treedc950f91c0c832e278f5899cb20ea265a19832c2 /usr.bin/units
parent2c18b3486c85f09c2db9ba5da61ab60515a00646 (diff)
downloadFreeBSD-src-60e4da10152ec074703107ef2ed5b40182c294ca.zip
FreeBSD-src-60e4da10152ec074703107ef2ed5b40182c294ca.tar.gz
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
Diffstat (limited to 'usr.bin/units')
-rw-r--r--usr.bin/units/units.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/usr.bin/units/units.c b/usr.bin/units/units.c
index 3d39d0e..929510f 100644
--- a/usr.bin/units/units.c
+++ b/usr.bin/units/units.c
@@ -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);
}
OpenPOWER on IntegriCloud