Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
f9e7f82d
Commit
f9e7f82d
authored
Jan 26, 2015
by
Nirbhay Choubey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backported changes done in wsrep_guess_ip() from 10.1.
parent
fffc9f58
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
46 deletions
+29
-46
sql/wsrep_utils.cc
sql/wsrep_utils.cc
+29
-46
No files found.
sql/wsrep_utils.cc
View file @
f9e7f82d
...
@@ -34,6 +34,10 @@
...
@@ -34,6 +34,10 @@
#include <sys/socket.h>
#include <sys/socket.h>
#include <netdb.h> // getaddrinfo()
#include <netdb.h> // getaddrinfo()
#ifdef HAVE_GETIFADDRS
#include <ifaddrs.h>
#endif
extern
char
**
environ
;
// environment variables
extern
char
**
environ
;
// environment variables
static
wsp
::
string
wsrep_PATH
;
static
wsp
::
string
wsrep_PATH
;
...
@@ -361,20 +365,23 @@ unsigned int wsrep_check_ip (const char* const addr)
...
@@ -361,20 +365,23 @@ unsigned int wsrep_check_ip (const char* const addr)
return
ret
;
return
ret
;
}
}
extern
const
char
*
my_bind_addr_str
;
extern
char
*
my_bind_addr_str
;
extern
uint
mysqld_port
;
size_t
wsrep_guess_ip
(
char
*
buf
,
size_t
buf_len
)
size_t
wsrep_guess_ip
(
char
*
buf
,
size_t
buf_len
)
{
{
size_t
ip_len
=
0
;
size_t
ip_len
=
0
;
if
(
my_bind_addr_str
&&
strlen
(
my_bind_addr_str
)
)
if
(
my_bind_addr_str
&&
my_bind_addr_str
[
0
]
!=
'\0'
)
{
{
unsigned
int
const
ip_type
=
wsrep_check_ip
(
my_bind_addr_str
);
unsigned
int
const
ip_type
=
wsrep_check_ip
(
my_bind_addr_str
);
if
(
INADDR_NONE
==
ip_type
)
{
if
(
INADDR_NONE
==
ip_type
)
{
WSREP_ERROR
(
"Node IP address not obtained from bind_address, trying alternate methods"
);
WSREP_ERROR
(
"Networking not configured, cannot receive state "
}
else
if
(
INADDR_ANY
!=
ip_type
)
{
"transfer."
);
return
0
;
}
if
(
INADDR_ANY
!=
ip_type
)
{
strncpy
(
buf
,
my_bind_addr_str
,
buf_len
);
strncpy
(
buf
,
my_bind_addr_str
,
buf_len
);
return
strlen
(
buf
);
return
strlen
(
buf
);
}
}
...
@@ -399,53 +406,29 @@ size_t wsrep_guess_ip (char* buf, size_t buf_len)
...
@@ -399,53 +406,29 @@ size_t wsrep_guess_ip (char* buf, size_t buf_len)
return
ip_len
;
return
ip_len
;
}
}
// try to find the address of the first one
#if HAVE_GETIFADDRS
#if (TARGET_OS_LINUX == 1)
struct
ifaddrs
*
ifaddr
,
*
ifa
;
const
char
cmd
[]
=
"ip addr show | grep -E '^[[:space:]]*inet' | grep -m1 global |"
if
(
getifaddrs
(
&
ifaddr
)
==
0
)
" awk '{ print $2 }' | sed -e 's/
\\
/.*//'"
;
{
#elif defined(__sun__)
for
(
ifa
=
ifaddr
;
ifa
!=
NULL
;
ifa
=
ifa
->
ifa_next
)
const
char
cmd
[]
=
"/sbin/ifconfig -a | "
{
"/usr/gnu/bin/grep -m1 -1 -E 'net[0-9]:' | tail -n 1 | awk '{ print $2 }'"
;
if
(
!
ifa
->
ifa_addr
||
ifa
->
ifa_addr
->
sa_family
!=
AF_INET
)
// TODO AF_INET6
#elif defined(__APPLE__) || defined(__FreeBSD__)
continue
;
const
char
cmd
[]
=
"/sbin/route -nv get 8.8.8.8 | tail -n1 | awk '{print $(NF)}'"
;
#else
char
*
cmd
;
#error "OS not supported"
#endif
wsp
::
process
proc
(
cmd
,
"r"
);
if
(
NULL
!=
proc
.
pipe
())
{
char
*
ret
;
ret
=
fgets
(
buf
,
buf_len
,
proc
.
pipe
());
if
(
proc
.
wait
())
return
0
;
if
(
NULL
==
ret
)
{
if
(
vio_getnameinfo
(
ifa
->
ifa_addr
,
buf
,
buf_len
,
NULL
,
0
,
NI_NUMERICHOST
))
WSREP_ERROR
(
"Failed to read output of: '%s'"
,
cmd
);
continue
;
return
0
;
}
}
else
{
WSREP_ERROR
(
"Failed to execute: '%s'"
,
cmd
);
return
0
;
}
// clear possible \n at the end of ip string left by fgets()
if
(
strcmp
(
buf
,
"127.0.0.1"
)
==
0
)
// lame
ip_len
=
strlen
(
buf
);
continue
;
if
(
ip_len
>
0
&&
'\n'
==
buf
[
ip_len
-
1
])
{
ip_len
--
;
buf
[
ip_len
]
=
'\0'
;
}
if
(
INADDR_NONE
==
inet_addr
(
buf
))
{
freeifaddrs
(
ifaddr
);
if
(
strlen
(
buf
)
!=
0
)
{
return
strlen
(
buf
);
WSREP_WARN
(
"Shell command returned invalid address: '%s'"
,
buf
);
}
}
return
0
;
freeifaddrs
(
ifaddr
)
;
}
}
#endif
return
ip_len
;
return
0
;
}
}
size_t
wsrep_guess_address
(
char
*
buf
,
size_t
buf_len
)
size_t
wsrep_guess_address
(
char
*
buf
,
size_t
buf_len
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment