diff options
author | PiBa-NL <pba_2k3@yahoo.com> | 2017-01-07 00:17:42 +0100 |
---|---|---|
committer | Renato Botelho <renato@netgate.com> | 2017-01-11 09:30:08 -0200 |
commit | 1b03abe35bb9d384881be68f90cb304ff206ae76 (patch) | |
tree | 5bea9507b3fc07298f5c420de357cfa8be4bda73 | |
parent | ee8d47c7e931d233f5eeaf19342f0e83741b1c7d (diff) | |
download | pfsense-1b03abe35bb9d384881be68f90cb304ff206ae76.zip pfsense-1b03abe35bb9d384881be68f90cb304ff206ae76.tar.gz |
openvpn, make sure config is written and not overwritten while starting openvpn, and wait for pid of child process to be written before exiting function
(cherry picked from commit 8845e137b630497d47a8ce93fb072e47419f8af5)
-rw-r--r-- | src/etc/inc/openvpn.inc | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/etc/inc/openvpn.inc b/src/etc/inc/openvpn.inc index 1b25403..909e4a8 100644 --- a/src/etc/inc/openvpn.inc +++ b/src/etc/inc/openvpn.inc @@ -1104,6 +1104,7 @@ function openvpn_restart($mode, $settings) { $vpnid = $settings['vpnid']; $mode_id = $mode.$vpnid; $lockhandle = lock("openvpnservice{$mode_id}", LOCK_EX); + openvpn_reconfigure($mode, $settings); /* kill the process if running */ $pfile = $g['varrun_path']."/openvpn_{$mode_id}.pid"; if (file_exists($pfile)) { @@ -1111,6 +1112,7 @@ function openvpn_restart($mode, $settings) { /* read the pid file */ $pid = rtrim(file_get_contents($pfile)); unlink($pfile); + syslog(LOG_INFO, "OpenVPN terminate old pid: {$pid}"); /* send a term signal to the process */ posix_kill($pid, SIGTERM); @@ -1152,8 +1154,24 @@ function openvpn_restart($mode, $settings) { /* start the new process */ $fpath = $g['varetc_path']."/openvpn/{$mode_id}.conf"; openvpn_clear_route($mode, $settings); - mwexec("/usr/local/sbin/openvpn --config " . escapeshellarg($fpath)); - + $res = mwexec("/usr/local/sbin/openvpn --config " . escapeshellarg($fpath)); + if ($res == 0) { + $i = 0; + $pid = "--"; + while ($i < 3000) { + if (file_exists($pfile) ) { + $pid = rtrim(file_get_contents($pfile)); + if (is_numericint($pid)) { + break; + } + } + usleep(1000); + $i++; + } + syslog(LOG_INFO, "OpenVPN PID written: {$pid}"); + } else { + syslog(LOG_ERR, "OpenVPN failed to start"); + } if (!platform_booting()) { send_event("filter reload"); } @@ -1314,7 +1332,6 @@ function openvpn_delete_csc(& $settings) { // Resync the configuration and restart the VPN function openvpn_resync($mode, $settings) { - openvpn_reconfigure($mode, $settings); openvpn_restart($mode, $settings); } |