Ticket #618: 0001-Fix-systemd-errors-when-openvpn-is-started-when-ther.patch

File 0001-Fix-systemd-errors-when-openvpn-is-started-when-ther.patch, 2.4 KB (added by David Sommerseth, 9 years ago)

[PATCH] Fix systemd errors when openvpn is started when there is no tty available

  • src/openvpn/console.c

    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) 
    138138
    139139#endif
    140140
    141 #ifdef ENABLE_SYSTEMD
    142 
    143141/*
    144142 * is systemd running
    145143 */
    146144
    147 static bool
     145bool
    148146check_systemd_running ()
    149147{
     148#ifdef ENABLE_SYSTEMD
    150149  struct stat c;
    151150
    152151  /* We simply test whether the systemd cgroup hierarchy is
    check_systemd_running () 
    155154
    156155  return (sd_booted() > 0)
    157156          && (stat(SYSTEMD_ASK_PASSWORD_PATH, &c) == 0);
    158 
     157#else
     158  return false;
     159#endif
    159160}
    160161
     162#ifdef ENABLE_SYSTEMD
     163
    161164static bool
    162165get_console_input_systemd (const char *prompt, const bool echo, char *input, const int capacity)
    163166{
  • src/openvpn/console.h

    diff --git a/src/openvpn/console.h b/src/openvpn/console.h
    index 268f3fe..e29dd2e 100644
    a b  
    2828#include "basic.h"
    2929
    3030bool
     31check_systemd_running ();
     32
     33bool
    3134get_console_input (const char *prompt, const bool echo, char *input, const int capacity);
    3235
    3336#endif
  • src/openvpn/misc.c

    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, 
    10581058        {
    10591059#ifndef WIN32
    10601060          /* did we --daemon'ize before asking for passwords? */
    1061           if ( !isatty(0) && !isatty(2) )
     1061          if ( !isatty(0) && !isatty(2) && !check_systemd_running() )
    10621062            { 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 ); }
    10631063#endif
    10641064