Commit 410a8bc5 authored by Franco Fichtner's avatar Franco Fichtner

src: remove the need for PHP's posix extension

parent 3bb1d29e
...@@ -1296,8 +1296,9 @@ function interface_bring_down($interface = "wan", $destroy = false, $ifacecfg = ...@@ -1296,8 +1296,9 @@ function interface_bring_down($interface = "wan", $destroy = false, $ifacecfg =
case "slaac": case "slaac":
case "dhcp6": case "dhcp6":
$pidv6 = find_dhcp6c_process($realif); $pidv6 = find_dhcp6c_process($realif);
if($pidv6) if ($pidv6) {
posix_kill($pidv6, SIGTERM); sigkillbypid($pidv6, 'TERM');
}
sleep(3); sleep(3);
unlink_if_exists("{$g['varetc_path']}/dhcp6c_{$interface}.conf"); unlink_if_exists("{$g['varetc_path']}/dhcp6c_{$interface}.conf");
if (does_interface_exist($realifv6)) { if (does_interface_exist($realifv6)) {
...@@ -2777,15 +2778,17 @@ function find_dhclient_process($interface) { ...@@ -2777,15 +2778,17 @@ function find_dhclient_process($interface) {
return intval($pid); return intval($pid);
} }
function kill_dhclient_process($interface) { function kill_dhclient_process($interface)
if (empty($interface) || !does_interface_exist($interface)) {
if (empty($interface) || !does_interface_exist($interface)) {
return; return;
}
$i = 0; $i = 0;
while ((($pid = find_dhclient_process($interface)) != 0) && ($i < 3)) { while ((($pid = find_dhclient_process($interface)) != 0) && ($i < 3)) {
/* 3rd time make it die for sure */ /* 3rd time make it die for sure */
$sig = ($i == 2 ? SIGKILL : SIGTERM); $sig = ($i == 2 ? 'KILL' : 'TERM');
posix_kill($pid, $sig); sigkillbypid($pid, $sig);
sleep(1); sleep(1);
$i++; $i++;
} }
...@@ -3217,8 +3220,9 @@ function interface_track6_configure($interface = "lan", $wancfg, $linkupevent = ...@@ -3217,8 +3220,9 @@ function interface_track6_configure($interface = "lan", $wancfg, $linkupevent =
*/ */
$parentrealif = get_real_interface($wancfg['track6-interface']); $parentrealif = get_real_interface($wancfg['track6-interface']);
$pidv6 = find_dhcp6c_process($parentrealif); $pidv6 = find_dhcp6c_process($parentrealif);
if($pidv6) if ($pidv6) {
posix_kill($pidv6, SIGHUP); sigkillbypid($pidv6, 'HUP');
}
} }
break; break;
} }
......
...@@ -176,7 +176,7 @@ function parse_cisco_acl($attribs) { ...@@ -176,7 +176,7 @@ function parse_cisco_acl($attribs) {
$rules = parse_cisco_acl($attributes); $rules = parse_cisco_acl($attributes);
if (!empty($rules)) { if (!empty($rules)) {
$pid = posix_getpid(); $pid = getmypid();
@file_put_contents("/tmp/ipsec_{$pid}{$common_name}.rules", $rules); @file_put_contents("/tmp/ipsec_{$pid}{$common_name}.rules", $rules);
mwexec("/sbin/pfctl -a " . escapeshellarg("ipsec/{$common_name}") . " -f /tmp/ipsec_{$pid}" . escapeshellarg($common_name) . ".rules"); mwexec("/sbin/pfctl -a " . escapeshellarg("ipsec/{$common_name}") . " -f /tmp/ipsec_{$pid}" . escapeshellarg($common_name) . ".rules");
@unlink("/tmp/ipsec_{$pid}{$common_name}.rules"); @unlink("/tmp/ipsec_{$pid}{$common_name}.rules");
......
...@@ -178,10 +178,8 @@ function parse_cisco_acl($attribs) { ...@@ -178,10 +178,8 @@ function parse_cisco_acl($attribs) {
$rules = parse_cisco_acl($attributes); $rules = parse_cisco_acl($attributes);
if (!empty($rules)) { if (!empty($rules)) {
$pid = posix_getpid(); $pid = getmypid();
@file_put_contents("/tmp/ovpn_{$pid}{$common_name}.rules", $rules); @file_put_contents("/tmp/ovpn_{$pid}{$common_name}.rules", $rules);
mwexec("/sbin/pfctl -a " . escapeshellarg("openvpn/{$common_name}") . " -f /tmp/ovpn_{$pid}" . escapeshellarg($common_name) . ".rules"); mwexec("/sbin/pfctl -a " . escapeshellarg("openvpn/{$common_name}") . " -f /tmp/ovpn_{$pid}" . escapeshellarg($common_name) . ".rules");
@unlink("/tmp/ovpn_{$pid}{$common_name}.rules"); @unlink("/tmp/ovpn_{$pid}{$common_name}.rules");
} }
?>
...@@ -33,6 +33,7 @@ require_once('config.inc'); ...@@ -33,6 +33,7 @@ require_once('config.inc');
require_once('certs.inc'); require_once('certs.inc');
require_once('pfsense-utils.inc'); require_once('pfsense-utils.inc');
require_once('auth.inc'); require_once('auth.inc');
require_once('util.inc');
global $openvpn_prots; global $openvpn_prots;
$openvpn_prots = array("UDP", "UDP6", "TCP", "TCP6"); $openvpn_prots = array("UDP", "UDP6", "TCP", "TCP6");
...@@ -824,12 +825,13 @@ function openvpn_restart($mode, $settings) { ...@@ -824,12 +825,13 @@ function openvpn_restart($mode, $settings) {
unlink($pfile); unlink($pfile);
/* send a term signal to the process */ /* send a term signal to the process */
posix_kill($pid, SIGTERM); sigkillbypid($pid, 'TERM');
/* wait until the process exits */ /* wait until the process exits */
while(posix_kill($pid, 0)) while(isvalidpid($pid)) {
usleep(250000); usleep(250000);
} }
}
if (isset($settings['disable'])) if (isset($settings['disable']))
return; return;
...@@ -881,7 +883,7 @@ function openvpn_delete($mode, & $settings) { ...@@ -881,7 +883,7 @@ function openvpn_delete($mode, & $settings) {
unlink($pfile); unlink($pfile);
/* send a term signal to the process */ /* send a term signal to the process */
posix_kill($pid, SIGTERM); sigkillbypid($pid, 'TERM');
} }
/* remove the device from the openvpn group */ /* remove the device from the openvpn group */
......
...@@ -768,11 +768,11 @@ function is_serial_enabled() ...@@ -768,11 +768,11 @@ function is_serial_enabled()
function reload_ttys() function reload_ttys()
{ {
// Send a HUP signal to init will make it reload /etc/ttys /* Send a HUP signal to init will make it reload /etc/ttys */
posix_kill(1, SIGHUP); require_once('util.inc');
sigkillbypid(1, 'HUP');
} }
/* DHCP enabled on any interfaces? */ /* DHCP enabled on any interfaces? */
function is_dhcp_server_enabled() { function is_dhcp_server_enabled() {
global $config; global $config;
......
...@@ -48,9 +48,6 @@ PHPMODULES="$PHPMODULES hash" ...@@ -48,9 +48,6 @@ PHPMODULES="$PHPMODULES hash"
PHPMODULES="$PHPMODULES mcrypt" PHPMODULES="$PHPMODULES mcrypt"
# Regexs, PERL style! # Regexs, PERL style!
PHPMODULES="$PHPMODULES pcre" PHPMODULES="$PHPMODULES pcre"
# The mighty posix!
PHPMODULES="$PHPMODULES posix"
PHPMODULES="$PHPMODULES readline"
# Login sessions # Login sessions
PHPMODULES="$PHPMODULES session" PHPMODULES="$PHPMODULES session"
# Extra sanity seatbelts # Extra sanity seatbelts
......
...@@ -38,6 +38,7 @@ require_once("filter.inc"); ...@@ -38,6 +38,7 @@ require_once("filter.inc");
require_once("shaper.inc"); require_once("shaper.inc");
require_once("rrd.inc"); require_once("rrd.inc");
require_once("vpn.inc"); require_once("vpn.inc");
require_once("util.inc");
require_once("xmlparse_attr.inc"); require_once("xmlparse_attr.inc");
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces.php'); $referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces.php');
...@@ -787,8 +788,9 @@ if ($_POST['apply']) { ...@@ -787,8 +788,9 @@ if ($_POST['apply']) {
} }
if ($wancfg['ipaddrv6'] == "dhcp6") { if ($wancfg['ipaddrv6'] == "dhcp6") {
$pid = find_dhcp6c_process($wancfg['if']); $pid = find_dhcp6c_process($wancfg['if']);
if($pid) if ($pid) {
posix_kill($pid, SIGTERM); sigkillbypid($pid, 'TERM');
}
} }
} }
$ppp = array(); $ppp = array();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment