summaryrefslogtreecommitdiff
path: root/src/shared/pager.c
diff options
context:
space:
mode:
authorLuca Boccassi <luca.boccassi@microsoft.com>2021-11-05 13:57:30 +0000
committerGitHub <noreply@github.com>2021-11-05 13:57:30 +0000
commit8389fd19d20370077f2d5601af0a089ec92ece05 (patch)
tree15402f17ca3b5fced203a7b8b3c79e8d6fe936e0 /src/shared/pager.c
parent5f035b13deb15daab34c2b5da30fabe8600fd803 (diff)
parent384c2c3239c51b7bdaddc7cbd4958b5b923cce42 (diff)
downloadsystemd-8389fd19d20370077f2d5601af0a089ec92ece05.tar.gz
Merge pull request #20138 from keszybz/coding-style-variable-decls
A coding style tweak and checking of sd_notify() calls and voidification of pager_open()
Diffstat (limited to 'src/shared/pager.c')
-rw-r--r--src/shared/pager.c28
1 files changed, 12 insertions, 16 deletions
diff --git a/src/shared/pager.c b/src/shared/pager.c
index 5418065333..f75ef62d2d 100644
--- a/src/shared/pager.c
+++ b/src/shared/pager.c
@@ -83,23 +83,23 @@ static int no_quit_on_interrupt(int exe_name_fd, const char *less_opts) {
return r;
}
-int pager_open(PagerFlags flags) {
+void pager_open(PagerFlags flags) {
_cleanup_close_pair_ int fd[2] = { -1, -1 }, exe_name_pipe[2] = { -1, -1 };
_cleanup_strv_free_ char **pager_args = NULL;
const char *pager, *less_opts;
int r;
if (flags & PAGER_DISABLE)
- return 0;
+ return;
if (pager_pid > 0)
- return 1;
+ return;
if (terminal_is_dumb())
- return 0;
+ return;
if (!is_main_thread())
- return log_error_errno(SYNTHETIC_ERRNO(EPERM), "Pager invoked from wrong thread.");
+ return (void) log_error_errno(SYNTHETIC_ERRNO(EPERM), "Pager invoked from wrong thread.");
pager = getenv("SYSTEMD_PAGER");
if (!pager)
@@ -108,11 +108,11 @@ int pager_open(PagerFlags flags) {
if (pager) {
pager_args = strv_split(pager, WHITESPACE);
if (!pager_args)
- return log_oom();
+ return (void) log_oom();
/* If the pager is explicitly turned off, honour it */
if (strv_isempty(pager_args) || strv_equal(pager_args, STRV_MAKE("cat")))
- return 0;
+ return;
}
/* Determine and cache number of columns/lines before we spawn the pager so that we get the value from the
@@ -121,11 +121,11 @@ int pager_open(PagerFlags flags) {
(void) lines();
if (pipe2(fd, O_CLOEXEC) < 0)
- return log_error_errno(errno, "Failed to create pager pipe: %m");
+ return (void) log_error_errno(errno, "Failed to create pager pipe: %m");
/* This is a pipe to feed the name of the executed pager binary into the parent */
if (pipe2(exe_name_pipe, O_CLOEXEC) < 0)
- return log_error_errno(errno, "Failed to create exe_name pipe: %m");
+ return (void) log_error_errno(errno, "Failed to create exe_name pipe: %m");
/* Initialize a good set of less options */
less_opts = getenv("SYSTEMD_LESS");
@@ -137,7 +137,7 @@ int pager_open(PagerFlags flags) {
/* We set SIGINT as PR_DEATHSIG signal here, to match the "K" parameter we set in $LESS, which enables SIGINT behaviour. */
r = safe_fork("(pager)", FORK_RESET_SIGNALS|FORK_DEATHSIG_SIGINT|FORK_RLIMIT_NOFILE_SAFE|FORK_LOG, &pager_pid);
if (r < 0)
- return r;
+ return;
if (r == 0) {
const char *less_charset, *exe;
@@ -245,26 +245,22 @@ int pager_open(PagerFlags flags) {
stored_stdout = fcntl(STDOUT_FILENO, F_DUPFD_CLOEXEC, 3);
if (dup2(fd[1], STDOUT_FILENO) < 0) {
stored_stdout = safe_close(stored_stdout);
- return log_error_errno(errno, "Failed to duplicate pager pipe: %m");
+ return (void) log_error_errno(errno, "Failed to duplicate pager pipe: %m");
}
stdout_redirected = true;
stored_stderr = fcntl(STDERR_FILENO, F_DUPFD_CLOEXEC, 3);
if (dup2(fd[1], STDERR_FILENO) < 0) {
stored_stderr = safe_close(stored_stderr);
- return log_error_errno(errno, "Failed to duplicate pager pipe: %m");
+ return (void) log_error_errno(errno, "Failed to duplicate pager pipe: %m");
}
stderr_redirected = true;
exe_name_pipe[1] = safe_close(exe_name_pipe[1]);
r = no_quit_on_interrupt(TAKE_FD(exe_name_pipe[0]), less_opts);
- if (r < 0)
- return r;
if (r > 0)
(void) ignore_signals(SIGINT);
-
- return 1;
}
void pager_close(void) {