chiark / gitweb /
Major cleanup of all leftovers after rebasing on master.
[elogind.git] / src / shared / pager.c
index 1c1cf1605a1db7db71ba0f90ab993a584f60a387..f1f3dc7e7edb41a3c5d9320ffa02b7557efe5217 100644 (file)
@@ -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);
@@ -143,10 +153,14 @@ void pager_close(void) {
 
         /* Inform pager that we are done */
         fclose(stdout);
+#if defined(__GLIBC__)
         stdout = NULL;
+#endif // in musl-libc this is a const
 
         fclose(stderr);
+#if defined(__GLIBC__)
         stderr = NULL;
+#endif // in musl-libc this is a const
 
         kill(pager_pid, SIGCONT);
         (void) wait_for_terminate(pager_pid, NULL);