From 62b1b34a1230885a37e6108d1c988aff56350c2c Mon Sep 17 00:00:00 2001
From: David Sommerseth <davids@redhat.com>
Date: Tue, 13 Oct 2015 11:57:59 +0200
Subject: [PATCH] Fix systemd errors when openvpn is started when there is no
tty available
It was discovered that starting openvpn during boot on systemd enabled
systems after commit b131c7b974d9d4d did not work as expected. This is
due to that there is no tty available at that point.
This patch adds an extra check considering if systemd is available or not.
Trac: #618
Reported-by: Ismail Donmez <idonmez@suse.com>
Signed-off-by: David Sommerseth <davids@redhat.com>
---
src/openvpn/console.c | 11 +++++++----
src/openvpn/console.h | 3 +++
src/openvpn/misc.c | 2 +-
3 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/openvpn/console.c b/src/openvpn/console.c
index d66d408..b0fa417 100644
a
|
b
|
close_tty (FILE *fp) |
138 | 138 | |
139 | 139 | #endif |
140 | 140 | |
141 | | #ifdef ENABLE_SYSTEMD |
142 | | |
143 | 141 | /* |
144 | 142 | * is systemd running |
145 | 143 | */ |
146 | 144 | |
147 | | static bool |
| 145 | bool |
148 | 146 | check_systemd_running () |
149 | 147 | { |
| 148 | #ifdef ENABLE_SYSTEMD |
150 | 149 | struct stat c; |
151 | 150 | |
152 | 151 | /* We simply test whether the systemd cgroup hierarchy is |
… |
… |
check_systemd_running () |
155 | 154 | |
156 | 155 | return (sd_booted() > 0) |
157 | 156 | && (stat(SYSTEMD_ASK_PASSWORD_PATH, &c) == 0); |
158 | | |
| 157 | #else |
| 158 | return false; |
| 159 | #endif |
159 | 160 | } |
160 | 161 | |
| 162 | #ifdef ENABLE_SYSTEMD |
| 163 | |
161 | 164 | static bool |
162 | 165 | get_console_input_systemd (const char *prompt, const bool echo, char *input, const int capacity) |
163 | 166 | { |
diff --git a/src/openvpn/console.h b/src/openvpn/console.h
index 268f3fe..e29dd2e 100644
a
|
b
|
|
28 | 28 | #include "basic.h" |
29 | 29 | |
30 | 30 | bool |
| 31 | check_systemd_running (); |
| 32 | |
| 33 | bool |
31 | 34 | get_console_input (const char *prompt, const bool echo, char *input, const int capacity); |
32 | 35 | |
33 | 36 | #endif |
diff --git a/src/openvpn/misc.c b/src/openvpn/misc.c
index fd1930a..6c85677 100644
a
|
b
|
get_user_pass_cr (struct user_pass *up, |
1058 | 1058 | { |
1059 | 1059 | #ifndef WIN32 |
1060 | 1060 | /* did we --daemon'ize before asking for passwords? */ |
1061 | | if ( !isatty(0) && !isatty(2) ) |
| 1061 | if ( !isatty(0) && !isatty(2) && !check_systemd_running() ) |
1062 | 1062 | { msg(M_FATAL, "neither stdin nor stderr are a tty device, can't ask for %s password. If you used --daemon, you need to use --askpass to make passphrase-protected keys work, and you can not use --auth-nocache.", prefix ); } |
1063 | 1063 | #endif |
1064 | 1064 | |