--- plugin/down-root/down-root.c.orig 2009-12-11 00:35:04.000000000 +0100 +++ plugin/down-root/down-root.c 2010-08-16 13:44:45.754293154 +0200 @@ -44,12 +44,14 @@ /* Command codes for foreground -> background communication */ #define COMMAND_RUN_SCRIPT 0 #define COMMAND_EXIT 1 +#define COMMAND_PING 2 /* Response codes for background -> foreground communication */ #define RESPONSE_INIT_SUCCEEDED 10 #define RESPONSE_INIT_FAILED 11 #define RESPONSE_SCRIPT_SUCCEEDED 12 #define RESPONSE_SCRIPT_FAILED 13 +#define RESPONSE_PING_REQUEST 14 /* Background process function */ static void down_root_server (const int fd, char *command, const char *argv[], const char *envp[], const int verb); @@ -388,6 +390,28 @@ return 0; /* NOTREACHED */ } } + else if (type == OPENVPN_PLUGIN_UP && context->foreground_fd >= 0) /* no need to fork a second process */ + { + + /* Check process communication */ + + if (send_control (context->foreground_fd, COMMAND_PING) == -1) + { + fprintf (stderr, "DOWN-ROOT: Error sending ping request signal to background process\n"); + } + else + { + const int status = recv_control (context->foreground_fd); + if (status == RESPONSE_PING_REQUEST) + { + return OPENVPN_PLUGIN_FUNC_SUCCESS; + } + else + { + fprintf (stderr, "DOWN-ROOT: Error receiving ping reception confirmation from background process\n"); + } + } + } else if (type == OPENVPN_PLUGIN_DOWN && context->foreground_fd >= 0) { if (send_control (context->foreground_fd, COMMAND_RUN_SCRIPT) == -1) @@ -527,6 +551,15 @@ } break; + case COMMAND_PING: /* allows to check if process is listening */ + + if (send_control (fd, RESPONSE_PING_REQUEST) == -1) + { + fprintf (stderr, "DOWN-ROOT: BACKGROUND: write error on response socket [4]\n"); + goto done; + } + break; + case COMMAND_EXIT: goto done;