Index: openvpn-2.2.1/misc.c =================================================================== --- openvpn-2.2.1.orig/misc.c +++ openvpn-2.2.1/misc.c @@ -1333,26 +1333,49 @@ get_console_input (const char *prompt, c ASSERT (input); ASSERT (capacity > 0); input[0] = '\0'; + bool is_systemd_running; + struct stat a, b; + + /* We simply test whether the systemd cgroup hierarchy is + * mounted */ + + is_systemd_running = (lstat("/sys/fs/cgroup", &a) == 0) + && (lstat("/sys/fs/cgroup/systemd", &b) == 0) + && (a.st_dev != b.st_dev); #if defined(WIN32) return get_console_input_win32 (prompt, echo, input, capacity); #elif defined(HAVE_GETPASS) - if (echo) + if (echo || is_systemd_running) { FILE *fp; - fp = open_tty (true); - fprintf (fp, "%s", prompt); - fflush (fp); - close_tty (fp); + if (is_systemd_running) + { + char *cmd; + + asprintf(&cmd, "/bin/systemd-ask-password \"%s\"", prompt); + fp = popen (cmd, "re"); + free (cmd); + } + else + { + fp = open_tty (true); + fprintf (fp, "%s", prompt); + fflush (fp); + close_tty (fp); - fp = open_tty (false); + fp = open_tty (false); + } if (fgets (input, capacity, fp) != NULL) { chomp (input); ret = true; } - close_tty (fp); + if (is_systemd_running) + fclose (fp); + else + close_tty (fp); } else {