summaryrefslogtreecommitdiff
path: root/src/systemctl.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2011-02-13 17:18:45 +0100
committerLennart Poettering <lennart@poettering.net>2011-02-13 17:18:45 +0100
commit7fc01d33196f329c24766795b7af66e598c3e65b (patch)
tree1e98d191dd5083dcaa5971fa92e12f103109a39c /src/systemctl.c
parent060ed82ec24d942c5f519e3dae45e9e2bfb227d8 (diff)
systemctl: minor optimizations
Diffstat (limited to 'src/systemctl.c')
-rw-r--r--src/systemctl.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/systemctl.c b/src/systemctl.c
index 94a12ddeb2..dfa952ed46 100644
--- a/src/systemctl.c
+++ b/src/systemctl.c
@@ -161,6 +161,7 @@ static void spawn_ask_password_agent(void) {
};
int fd;
+ bool stdout_is_tty, stderr_is_tty;
/* Make sure the agent goes away when the parent dies */
if (prctl(PR_SET_PDEATHSIG, SIGTERM) < 0)
@@ -174,7 +175,10 @@ static void spawn_ask_password_agent(void) {
/* Don't leak fds to the agent */
close_all_fds(NULL, 0);
- if (!isatty(STDOUT_FILENO) || !isatty(STDERR_FILENO)) {
+ stdout_is_tty = isatty(STDOUT_FILENO);
+ stderr_is_tty = isatty(STDERR_FILENO);
+
+ if (!stdout_is_tty || !stderr_is_tty) {
/* Detach from stdout/stderr. and reopen
* /dev/tty for them. This is important to
* ensure that when systemctl is started via
@@ -187,15 +191,11 @@ static void spawn_ask_password_agent(void) {
_exit(EXIT_FAILURE);
}
- if (!isatty(STDOUT_FILENO)) {
- close(STDOUT_FILENO);
+ if (!stdout_is_tty)
dup2(fd, STDOUT_FILENO);
- }
- if (!isatty(STDERR_FILENO)) {
- close(STDERR_FILENO);
+ if (!stderr_is_tty)
dup2(fd, STDERR_FILENO);
- }
if (fd > 2)
close(fd);