diff options
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/cgroup-show.c | 2 | ||||
-rw-r--r-- | src/shared/cgroup-show.h | 2 | ||||
-rw-r--r-- | src/shared/dissect-image.c | 8 | ||||
-rw-r--r-- | src/shared/pager.c | 29 | ||||
-rw-r--r-- | src/shared/sleep-config.c | 6 |
5 files changed, 34 insertions, 13 deletions
diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c index 8765cf2f49..436130edea 100644 --- a/src/shared/cgroup-show.c +++ b/src/shared/cgroup-show.c @@ -24,8 +24,6 @@ #include <stdlib.h> #include <string.h> -#include <systemd/sd-bus.h> - #include "alloc-util.h" #include "bus-error.h" #include "bus-util.h" diff --git a/src/shared/cgroup-show.h b/src/shared/cgroup-show.h index 736f0f34c8..1764f76744 100644 --- a/src/shared/cgroup-show.h +++ b/src/shared/cgroup-show.h @@ -22,7 +22,7 @@ #include <stdbool.h> #include <sys/types.h> -#include <systemd/sd-bus.h> +#include "sd-bus.h" #include "logs-show.h" #include "output-mode.h" diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index 36c94ac71b..163995c1e5 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -42,8 +42,8 @@ #include "udev-util.h" #include "xattr-util.h" +_unused_ static int probe_filesystem(const char *node, char **ret_fstype) { #ifdef HAVE_BLKID -static int probe_filesystem(const char *node, char **ret_fstype) { _cleanup_blkid_free_probe_ blkid_probe b = NULL; const char *fstype; int r; @@ -80,8 +80,10 @@ static int probe_filesystem(const char *node, char **ret_fstype) { not_found: *ret_fstype = NULL; return 0; -} +#else + return -EOPNOTSUPP; #endif +} int dissect_image(int fd, const void *root_hash, size_t root_hash_size, DissectImageFlags flags, DissectedImage **ret) { @@ -949,7 +951,7 @@ int dissected_image_decrypt( * * = 0 → There was nothing to decrypt * > 0 → Decrypted successfully - * -ENOKEY → There's some to decrypt but no key was supplied + * -ENOKEY → There's something to decrypt but no key was supplied * -EKEYREJECTED → Passed key was not correct */ diff --git a/src/shared/pager.c b/src/shared/pager.c index c1480a718b..2501a53c19 100644 --- a/src/shared/pager.c +++ b/src/shared/pager.c @@ -53,6 +53,11 @@ noreturn static void pager_fallback(void) { _exit(EXIT_SUCCESS); } +static int stored_stdout = -1; +static int stored_stderr = -1; +static bool stdout_redirected = false; +static bool stderr_redirected = false; + int pager_open(bool no_pager, bool jump_to_end) { _cleanup_close_pair_ int fd[2] = { -1, -1 }; const char *pager; @@ -147,10 +152,19 @@ int pager_open(bool no_pager, bool jump_to_end) { } /* Return in the parent */ - if (dup2(fd[1], STDOUT_FILENO) < 0) + 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"); - if (dup2(fd[1], STDERR_FILENO) < 0) + } + 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"); + } + stderr_redirected = true; return 1; } @@ -161,8 +175,15 @@ void pager_close(void) { return; /* Inform pager that we are done */ - safe_fclose(stdout); - safe_fclose(stderr); + (void) fflush(stdout); + if (stdout_redirected && (stored_stdout < 0 || dup2(stored_stdout, STDOUT_FILENO)) < 0) + (void) close(STDOUT_FILENO); + stored_stdout = safe_close(stored_stdout); + (void) fflush(stderr); + if (stderr_redirected && (stored_stderr < 0 || dup2(stored_stderr, STDERR_FILENO)) < 0) + (void) close(STDERR_FILENO); + stored_stderr = safe_close(stored_stderr); + stdout_redirected = stderr_redirected = false; (void) kill(pager_pid, SIGCONT); (void) wait_for_terminate(pager_pid, NULL); diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c index ed31a80c8d..8c1624ff46 100644 --- a/src/shared/sleep-config.c +++ b/src/shared/sleep-config.c @@ -59,9 +59,9 @@ int parse_sleep_config(const char *verb, char ***_modes, char ***_states) { }; config_parse_many_nulstr(PKGSYSCONFDIR "/sleep.conf", - CONF_PATHS_NULSTR("systemd/sleep.conf.d"), - "Sleep\0", config_item_table_lookup, items, - false, NULL); + CONF_PATHS_NULSTR("systemd/sleep.conf.d"), + "Sleep\0", config_item_table_lookup, items, + false, NULL); if (streq(verb, "suspend")) { /* empty by default */ |