mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-11 05:17:44 +03:00
Merge pull request #1061 from poettering/pager
A few auto-pager improvements
This commit is contained in:
commit
9f917da977
@ -30,7 +30,7 @@
|
||||
#define COPY_BUFFER_SIZE (16*1024)
|
||||
|
||||
int copy_bytes(int fdf, int fdt, off_t max_bytes, bool try_reflink) {
|
||||
bool try_sendfile = true;
|
||||
bool try_sendfile = true, try_splice = true;
|
||||
int r;
|
||||
|
||||
assert(fdf >= 0);
|
||||
@ -69,7 +69,23 @@ int copy_bytes(int fdf, int fdt, off_t max_bytes, bool try_reflink) {
|
||||
} else if (n == 0) /* EOF */
|
||||
break;
|
||||
else if (n > 0)
|
||||
/* Succcess! */
|
||||
/* Success! */
|
||||
goto next;
|
||||
}
|
||||
|
||||
/* The try splice, unless we already tried */
|
||||
if (try_splice) {
|
||||
n = splice(fdf, NULL, fdt, NULL, m, 0);
|
||||
if (n < 0) {
|
||||
if (errno != EINVAL && errno != ENOSYS)
|
||||
return -errno;
|
||||
|
||||
try_splice = false;
|
||||
/* use fallback below */
|
||||
} else if (n == 0) /* EOF */
|
||||
break;
|
||||
else if (n > 0)
|
||||
/* Success! */
|
||||
goto next;
|
||||
}
|
||||
|
||||
|
@ -31,18 +31,16 @@
|
||||
#include "macro.h"
|
||||
#include "terminal-util.h"
|
||||
#include "signal-util.h"
|
||||
#include "copy.h"
|
||||
|
||||
static pid_t pager_pid = 0;
|
||||
|
||||
noreturn static void pager_fallback(void) {
|
||||
ssize_t n;
|
||||
int r;
|
||||
|
||||
do {
|
||||
n = splice(STDIN_FILENO, NULL, STDOUT_FILENO, NULL, 64*1024, 0);
|
||||
} while (n > 0);
|
||||
|
||||
if (n < 0) {
|
||||
log_error_errno(errno, "Internal pager failed: %m");
|
||||
r = copy_bytes(STDIN_FILENO, STDOUT_FILENO, (off_t) -1, false);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Internal pager failed: %m");
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@ -131,6 +129,8 @@ int pager_open(bool jump_to_end) {
|
||||
/* Return in the parent */
|
||||
if (dup2(fd[1], STDOUT_FILENO) < 0)
|
||||
return log_error_errno(errno, "Failed to duplicate pager pipe: %m");
|
||||
if (dup2(fd[1], STDERR_FILENO) < 0)
|
||||
return log_error_errno(errno, "Failed to duplicate pager pipe: %m");
|
||||
|
||||
safe_close_pair(fd);
|
||||
return 1;
|
||||
@ -143,6 +143,11 @@ void pager_close(void) {
|
||||
|
||||
/* Inform pager that we are done */
|
||||
fclose(stdout);
|
||||
stdout = NULL;
|
||||
|
||||
fclose(stderr);
|
||||
stderr = NULL;
|
||||
|
||||
kill(pager_pid, SIGCONT);
|
||||
(void) wait_for_terminate(pager_pid, NULL);
|
||||
pager_pid = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user