Project

General

Profile

« Previous | Next » 

Revision 1b03abe3

Added by Pi Ba over 8 years ago

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)

View differences:

src/etc/inc/openvpn.inc
1104 1104
	$vpnid = $settings['vpnid'];
1105 1105
	$mode_id = $mode.$vpnid;
1106 1106
	$lockhandle = lock("openvpnservice{$mode_id}", LOCK_EX);
1107
	openvpn_reconfigure($mode, $settings);
1107 1108
	/* kill the process if running */
1108 1109
	$pfile = $g['varrun_path']."/openvpn_{$mode_id}.pid";
1109 1110
	if (file_exists($pfile)) {
......
1111 1112
		/* read the pid file */
1112 1113
		$pid = rtrim(file_get_contents($pfile));
1113 1114
		unlink($pfile);
1115
		syslog(LOG_INFO, "OpenVPN terminate old pid: {$pid}");
1114 1116

  
1115 1117
		/* send a term signal to the process */
1116 1118
		posix_kill($pid, SIGTERM);
......
1152 1154
	/* start the new process */
1153 1155
	$fpath = $g['varetc_path']."/openvpn/{$mode_id}.conf";
1154 1156
	openvpn_clear_route($mode, $settings);
1155
	mwexec("/usr/local/sbin/openvpn --config " . escapeshellarg($fpath));
1156

  
1157
	$res = mwexec("/usr/local/sbin/openvpn --config " . escapeshellarg($fpath));
1158
	if ($res == 0) {
1159
		$i = 0;
1160
		$pid = "--";
1161
		while ($i < 3000) {
1162
			if (file_exists($pfile) ) {
1163
				$pid = rtrim(file_get_contents($pfile));
1164
				if (is_numericint($pid)) {
1165
					break;
1166
				}
1167
			}
1168
			usleep(1000);
1169
			$i++;
1170
		}
1171
		syslog(LOG_INFO, "OpenVPN PID written: {$pid}");
1172
	} else {
1173
		syslog(LOG_ERR, "OpenVPN failed to start");
1174
	}
1157 1175
	if (!platform_booting()) {
1158 1176
		send_event("filter reload");
1159 1177
	}
......
1314 1332

  
1315 1333
// Resync the configuration and restart the VPN
1316 1334
function openvpn_resync($mode, $settings) {
1317
	openvpn_reconfigure($mode, $settings);
1318 1335
	openvpn_restart($mode, $settings);
1319 1336
}
1320 1337

  

Also available in: Unified diff