Don't assume all ethernet devices are named ethX

Resolves: #682365
This commit is contained in:
Honza Horák 2011-11-02 12:42:22 +01:00 committed by Michal Schorm
parent 247bef4027
commit 885b130b70
2 changed files with 66 additions and 1 deletions

59
mysql-netdevname.patch Normal file
View File

@ -0,0 +1,59 @@
diff -up mysql-5.5.15/mysys/my_gethwaddr.c.netdevname mysql-5.5.15/mysys/my_gethwaddr.c
--- mysql-5.5.15/mysys/my_gethwaddr.c.netdevname 2011-07-13 21:09:02.000000000 +0200
+++ mysql-5.5.15/mysys/my_gethwaddr.c 2011-11-01 12:32:35.356119715 +0100
@@ -68,28 +68,47 @@ err:
#include <sys/ioctl.h>
#include <net/ethernet.h>
+#define MAX_IFS 64
+
my_bool my_gethwaddr(uchar *to)
{
int fd, res= 1;
struct ifreq ifr;
char zero_array[ETHER_ADDR_LEN] = {0};
+ struct ifconf ifc;
+ struct ifreq ifs[MAX_IFS], *ifri, *ifend;
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0)
goto err;
- bzero(&ifr, sizeof(ifr));
- strnmov(ifr.ifr_name, "eth0", sizeof(ifr.ifr_name) - 1);
+ ifc.ifc_len = sizeof(ifs);
+ ifc.ifc_req = ifs;
+ if (ioctl(fd, SIOCGIFCONF, &ifc) < 0)
+ {
+ close(fd);
+ goto err;
+ }
+
+ memcpy(to, zero_array, ETHER_ADDR_LEN);
- do
+ ifend = ifs + (ifc.ifc_len / sizeof(struct ifreq));
+ for (ifri = ifc.ifc_req; ifri < ifend; ifri++)
{
- if (ioctl(fd, SIOCGIFHWADDR, &ifr) >= 0)
+ if (ifri->ifr_addr.sa_family == AF_INET)
{
- memcpy(to, &ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
- res= memcmp(to, zero_array, ETHER_ADDR_LEN) ? 0 : 1;
+ bzero(&ifr, sizeof(ifr));
+ strncpy(ifr.ifr_name, ifri->ifr_name, sizeof(ifr.ifr_name));
+
+ /* Get HW address */
+ if (ioctl(fd, SIOCGIFHWADDR, &ifr) >= 0)
+ {
+ memcpy(to, &ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
+ if (!(res= memcmp(to, zero_array, ETHER_ADDR_LEN) ? 0 : 1))
+ break;
+ }
}
- } while (res && (errno == 0 || errno == ENODEV) && ifr.ifr_name[3]++ < '6');
-
+ }
close(fd);
err:
return res;

View File

@ -1,6 +1,6 @@
Name: mysql
Version: 5.5.16
Release: 3%{?dist}
Release: 4%{?dist}
# Update this whenever F15 gets rebased; it must be NVR-greater than F15 pkg.
# Our convention for the life of F15 is that sysv packages will be numbered
# 1dist.n while systemd packages will be 2dist and higher.
@ -54,6 +54,7 @@ Patch11: mysql-s390-tsc.patch
Patch12: mysql-openssl-test.patch
Patch13: mysqld-nowatch.patch
Patch14: mysql-va-list.patch
Patch15: mysql-netdevname.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
BuildRequires: perl, readline-devel, openssl-devel
@ -205,6 +206,7 @@ the MySQL sources.
%patch12 -p1
%patch13 -p1
%patch14 -p1
%patch15 -p1
# workaround for upstream bug #56342
rm -f mysql-test/t/ssl_8k_key-master.opt
@ -654,6 +656,10 @@ fi
%{_mandir}/man1/mysql_client_test.1*
%changelog
* Wed Nov 02 2011 Honza Horak <hhorak@redhat.com> 5.5.16-4
- Don't assume all ethernet devices are named ethX
Resolves: #682365
* Sun Oct 16 2011 Tom Lane <tgl@redhat.com> 5.5.16-3
- Fix unportable usage associated with va_list arguments
Resolves: #744707