Commit 720acc9e authored by Franco Fichtner's avatar Franco Fichtner

util: make dmesg probing optional #1135

While there, turn the probing upside down for general sanity:

o Only pull dmesg output once
o Pattern-match one pattern only
o Anchor the match to the line start
parent c77dd450
......@@ -59,7 +59,7 @@ function set_networking_interfaces_ports($probe = false)
/* kernel messages clobber stty probing on ifconfig up */
mute_kernel_msgs();
$iflist = get_interface_list();
$iflist = get_interface_list(false, true);
if ($probe) {
echo PHP_EOL . gettext('Press any key to start the manual interface assignment: ');
......
......@@ -876,12 +876,21 @@ function get_configured_ipv6_addresses()
*
* $only_active = false -- interfaces that are available in the system
* true -- interfaces that are physically connected
*
* $include_dmesg = false -- skip probing dmesg for more information
* true -- probe dmesg for more information
*/
function get_interface_list($only_active = false)
function get_interface_list($only_active = false, $include_dmesg = false)
{
global $config;
$dmesg_arr = array();
$iflist = array();
if ($include_dmesg) {
exec('/sbin/dmesg', $dmesg_arr);
}
/* list of virtual interface types */
$vfaces = array(
'_vlan',
......@@ -935,25 +944,22 @@ function get_interface_list($only_active = false)
$toput = array(
'up' => in_array($ifname, $ifnames_up),
'ipaddr' => !empty($ifdata['ipaddr']) ? $ifdata['ipaddr'] : null,
'mac' => $ifdata['macaddr']
'mac' => $ifdata['macaddr'],
'dmesg' => '',
);
if (isset($config['interfaces'])) {
foreach (legacy_config_get_interfaces(array("virtual" => false)) as $name => $int) {
foreach (legacy_config_get_interfaces(array('virtual' => false)) as $name => $int) {
if ($int['if'] == $ifname) {
$toput['friendly'] = $name;
break;
}
}
}
$dmesg_arr = array();
$toput['dmesg'] = null;
exec("/sbin/dmesg |grep $ifname", $dmesg_arr);
if (count($dmesg_arr) > 0) {
preg_match_all("/<(.*?)>/i", $dmesg_arr[0], $dmesg);
if (isset($dmesg[1][0])) {
$toput['dmesg'] = $dmesg[1][0];
foreach ($dmesg_arr as $dmesg_line) {
$dmesg = array();
if (preg_match("/^{$ifname}: <(.*?)>/i", $dmesg_line, $dmesg) == 1) {
$toput['dmesg'] = $dmesg[1];
break;
}
}
......
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