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