Project

General

Profile

« Previous | Next » 

Revision ce983754

Added by Pi Ba over 8 years ago

openvpn, startup locking sequence to prevent issues around pid file / process management
fixes: https://redmine.pfsense.org/issues/6940

View differences:

src/etc/inc/openvpn.inc
1079 1079

  
1080 1080
	$vpnid = $settings['vpnid'];
1081 1081
	$mode_id = $mode.$vpnid;
1082

  
1082
	$lockhandle = lock("openvpnservice{$mode_id}", LOCK_EX);
1083 1083
	/* kill the process if running */
1084 1084
	$pfile = $g['varrun_path']."/openvpn_{$mode_id}.pid";
1085 1085
	if (file_exists($pfile)) {
......
1105 1105
	}
1106 1106

  
1107 1107
	if (isset($settings['disable'])) {
1108
		unlock($lockhandle);
1108 1109
		return;
1109 1110
	}
1110 1111

  
1111 1112
	/* Do not start an instance if we are not CARP master on this vip! */
1112 1113
	if (strstr($settings['interface'], "_vip") && get_carp_interface_status($settings['interface']) != "MASTER") {
1114
		unlock($lockhandle);
1113 1115
		return;
1114 1116
	}
1115 1117

  
......
1118 1120
	if (is_array($a_groups[$settings['interface']])) {
1119 1121
		/* the interface is a gateway group. If a vip is defined and its a CARP backup then do not start */
1120 1122
		if (($a_groups[$settings['interface']][0]['vip'] <> "") && (get_carp_interface_status($a_groups[$settings['interface']][0]['vip']) != "MASTER")) {
1123
			unlock($lockhandle);
1121 1124
			return;
1122 1125
		}
1123 1126
	}
......
1125 1128
	/* start the new process */
1126 1129
	$fpath = $g['varetc_path']."/openvpn/{$mode_id}.conf";
1127 1130
	openvpn_clear_route($mode, $settings);
1128
	mwexec_bg("/usr/local/sbin/openvpn --config " . escapeshellarg($fpath));
1131
	mwexec("/usr/local/sbin/openvpn --config " . escapeshellarg($fpath));
1129 1132

  
1130 1133
	if (!platform_booting()) {
1131 1134
		send_event("filter reload");
1132 1135
	}
1136
	unlock($lockhandle);
1133 1137
}
1134 1138

  
1135 1139
function openvpn_delete($mode, & $settings) {

Also available in: Unified diff