summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-08-28 18:17:14 +0200
committerSven Eden <yamakuzure@gmx.net>2017-03-29 10:45:08 +0200
commit8ee406453b04c18674c10d7a8b0c112fe4a30942 (patch)
tree297b697643a6eb14fd8683c97e4826732e26154a
parent1e8d75e46d3c1633e8c5a290677bf64ccd06195e (diff)
pager: set $LESSCHARSET when we output UTF8 chars
This way we can be sure that less has the same idea of the terminal as we do. This solves issues in systems that have locale uninitalized, where elogind would output UTF-8 but less wouldn't allow it and show them as control characters.
-rw-r--r--src/shared/pager.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/shared/pager.c b/src/shared/pager.c
index 7721e29ff..f1f3dc7e7 100644
--- a/src/shared/pager.c
+++ b/src/shared/pager.c
@@ -82,7 +82,7 @@ int pager_open(bool jump_to_end) {
/* In the child start the pager */
if (pager_pid == 0) {
- const char* less_opts;
+ const char* less_opts, *less_charset;
(void) reset_all_signal_handlers();
(void) reset_signal_mask();
@@ -90,6 +90,7 @@ int pager_open(bool jump_to_end) {
dup2(fd[0], STDIN_FILENO);
safe_close_pair(fd);
+ /* Initialize a good set of less options */
less_opts = getenv("SYSTEMD_LESS");
if (!less_opts)
less_opts = "FRSXMK";
@@ -97,6 +98,15 @@ int pager_open(bool jump_to_end) {
less_opts = strjoina(less_opts, " +G");
setenv("LESS", less_opts, 1);
+ /* Initialize a good charset for less. This is
+ * particularly important if we output UTF-8
+ * characters. */
+ less_charset = getenv("SYSTEMD_LESSCHARSET");
+ if (!less_charset && is_locale_utf8())
+ less_charset = "utf-8";
+ if (less_charset)
+ setenv("LESSCHARSET", less_charset, 1);
+
/* Make sure the pager goes away when the parent dies */
if (prctl(PR_SET_PDEATHSIG, SIGTERM) < 0)
_exit(EXIT_FAILURE);