1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-23 17:34:00 +03:00

shared/pager: abort if we cannot set environment variables

This most likely means oom, it's better to exit than to run less with
incomplete settings.

CID #714383.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2017-02-19 13:52:18 -05:00
parent 643f4706b0
commit 0357fa0dce

View File

@ -104,7 +104,8 @@ int pager_open(bool no_pager, bool jump_to_end) {
less_opts = "FRSXMK";
if (jump_to_end)
less_opts = strjoina(less_opts, " +G");
setenv("LESS", less_opts, 1);
if (setenv("LESS", less_opts, 1) < 0)
_exit(EXIT_FAILURE);
/* Initialize a good charset for less. This is
* particularly important if we output UTF-8
@ -112,8 +113,9 @@ int pager_open(bool no_pager, bool jump_to_end) {
less_charset = getenv("SYSTEMD_LESSCHARSET");
if (!less_charset && is_locale_utf8())
less_charset = "utf-8";
if (less_charset)
setenv("LESSCHARSET", less_charset, 1);
if (less_charset &&
setenv("LESSCHARSET", less_charset, 1) < 0)
_exit(EXIT_FAILURE);
/* Make sure the pager goes away when the parent dies */
if (prctl(PR_SET_PDEATHSIG, SIGTERM) < 0)