Cleanup gw.h, part 1.
Gw.h contained a fair amount of obsolete function declarations, duplicate declarations of functions declared in utils.h and declarations of functions that conceptually are similar to those in utils.h. The obsolete and duplicate ones were removed and all but one of the remaining moved to utils.h. Correspondingly the implementation was moved from gw_utils.c to utils.c. The one remaining function - gw_daemonize() - is not really worthy of a file of its own, so that is to be moved to gateway.c after which gw_utils.c can be removed. Gw.h still contains defines that are duplicated in maxscale/protocol/mysql.h. The ones in gw.h are to be removed. It appears that the entire gw.h will disappear.
This commit is contained in:
parent
1333da0712
commit
d5cf74bd24
@ -72,5 +72,6 @@
|
||||
*/
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#endif
|
||||
|
@ -69,23 +69,7 @@ MXS_BEGIN_DECLS
|
||||
#define MYSQL_CONN_DEBUG
|
||||
#undef MYSQL_CONN_DEBUG
|
||||
|
||||
#include "dcb.h"
|
||||
|
||||
bool gw_daemonize(void);
|
||||
int do_read_dcb(DCB *dcb);
|
||||
void MySQLListener(int epfd, char *config_bind);
|
||||
int MySQLAccept(DCB *listener);
|
||||
int do_read_dcb(DCB *dcb);
|
||||
int do_read_10(DCB *dcb, uint8_t *buffer);
|
||||
int MySQLWrite(DCB *dcb, GWBUF *queue);
|
||||
int setnonblocking(int fd);
|
||||
int gw_getsockerrno(int fd);
|
||||
int parse_bindconfig(const char *, struct sockaddr_in *);
|
||||
int setipaddress(struct in_addr *, char *);
|
||||
char* get_libdir();
|
||||
long get_processor_count();
|
||||
void clean_up_pathname(char *path);
|
||||
bool mxs_mkdir_all(const char *path, int mask);
|
||||
|
||||
MXS_END_DECLS
|
||||
|
||||
|
@ -27,8 +27,10 @@
|
||||
*/
|
||||
|
||||
#include <maxscale/cdefs.h>
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
MXS_BEGIN_DECLS
|
||||
|
||||
@ -41,6 +43,9 @@ bool utils_init(); /*< Call this first before using any other function */
|
||||
void utils_end();
|
||||
|
||||
int setnonblocking(int fd);
|
||||
int parse_bindconfig(const char *, struct sockaddr_in *);
|
||||
int setipaddress(struct in_addr *, char *);
|
||||
|
||||
char *gw_strend(register const char *s);
|
||||
static char gw_randomchar();
|
||||
int gw_generate_random_str(char *output, int len);
|
||||
@ -67,6 +72,12 @@ char* replace_literal(char* haystack,
|
||||
const char* replacement);
|
||||
char* replace_quoted(const char** src, const size_t* srcsize, char** dest, size_t* destsize);
|
||||
|
||||
void clean_up_pathname(char *path);
|
||||
|
||||
bool mxs_mkdir_all(const char *path, int mask);
|
||||
|
||||
long get_processor_count();
|
||||
|
||||
MXS_END_DECLS
|
||||
|
||||
#endif
|
||||
|
@ -90,6 +90,7 @@
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <maxscale/alloc.h>
|
||||
#include <maxscale/utils.h>
|
||||
|
||||
#if defined(FAKE_CODE)
|
||||
unsigned char dcb_fake_write_errno[10240];
|
||||
|
@ -39,96 +39,6 @@
|
||||
#include <maxscale/session.h>
|
||||
#include <maxscale/log_manager.h>
|
||||
|
||||
SPINLOCK tmplock = SPINLOCK_INIT;
|
||||
|
||||
/*
|
||||
* Set IP address in socket structure in_addr
|
||||
*
|
||||
* @param a Pointer to a struct in_addr into which the address is written
|
||||
* @param p The hostname to lookup
|
||||
* @return 1 on success, 0 on failure
|
||||
*/
|
||||
int
|
||||
setipaddress(struct in_addr *a, char *p)
|
||||
{
|
||||
#ifdef __USE_POSIX
|
||||
struct addrinfo *ai = NULL, hint;
|
||||
int rc;
|
||||
struct sockaddr_in *res_addr;
|
||||
memset(&hint, 0, sizeof (hint));
|
||||
|
||||
hint.ai_socktype = SOCK_STREAM;
|
||||
|
||||
/*
|
||||
* This is for the listening socket, matching INADDR_ANY only for now.
|
||||
* For future specific addresses bind, a dedicated routine woulbd be better
|
||||
*/
|
||||
|
||||
if (strcmp(p, "0.0.0.0") == 0)
|
||||
{
|
||||
hint.ai_flags = AI_PASSIVE;
|
||||
hint.ai_family = AF_UNSPEC;
|
||||
if ((rc = getaddrinfo(p, NULL, &hint, &ai)) != 0)
|
||||
{
|
||||
MXS_ERROR("Failed to obtain address for host %s, %s",
|
||||
p,
|
||||
gai_strerror(rc));
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hint.ai_flags = AI_CANONNAME;
|
||||
hint.ai_family = AF_INET;
|
||||
|
||||
if ((rc = getaddrinfo(p, NULL, &hint, &ai)) != 0)
|
||||
{
|
||||
MXS_ERROR("Failed to obtain address for host %s, %s",
|
||||
p,
|
||||
gai_strerror(rc));
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* take the first one */
|
||||
if (ai != NULL)
|
||||
{
|
||||
res_addr = (struct sockaddr_in *)(ai->ai_addr);
|
||||
memcpy(a, &res_addr->sin_addr, sizeof(struct in_addr));
|
||||
|
||||
freeaddrinfo(ai);
|
||||
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
struct hostent *h;
|
||||
|
||||
spinlock_acquire(&tmplock);
|
||||
h = gethostbyname(p);
|
||||
spinlock_release(&tmplock);
|
||||
|
||||
if (h == NULL)
|
||||
{
|
||||
if ((a->s_addr = inet_addr(p)) == -1)
|
||||
{
|
||||
MXS_ERROR("gethostbyname failed for [%s]", p);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* take the first one */
|
||||
memcpy(a, h->h_addr, h->h_length);
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Daemonize the process by forking and putting the process into the
|
||||
* background.
|
||||
@ -160,80 +70,3 @@ bool gw_daemonize(void)
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the bind config data. This is passed in a string as address:port.
|
||||
*
|
||||
* The address may be either a . separated IP address or a hostname to
|
||||
* lookup. The address 0.0.0.0 is the wildcard address for SOCKADR_ANY.
|
||||
* The ':' and port are required.
|
||||
*
|
||||
* @param config The bind address and port separated by a ':'
|
||||
* @param addr The sockaddr_in in which the data is written
|
||||
* @return 0 on failure
|
||||
*/
|
||||
int
|
||||
parse_bindconfig(const char *config, struct sockaddr_in *addr)
|
||||
{
|
||||
char buf[strlen(config) + 1];
|
||||
strcpy(buf, config);
|
||||
|
||||
char *port = strrchr(buf, ':');
|
||||
short pnum;
|
||||
if (port)
|
||||
{
|
||||
*port = 0;
|
||||
port++;
|
||||
pnum = atoi(port);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!strcmp(buf, "0.0.0.0"))
|
||||
{
|
||||
addr->sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!inet_aton(buf, &addr->sin_addr))
|
||||
{
|
||||
struct hostent *hp = gethostbyname(buf);
|
||||
|
||||
if (hp)
|
||||
{
|
||||
bcopy(hp->h_addr, &(addr->sin_addr.s_addr), hp->h_length);
|
||||
}
|
||||
else
|
||||
{
|
||||
MXS_ERROR("Failed to lookup host '%s'.", buf);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addr->sin_family = AF_INET;
|
||||
addr->sin_port = htons(pnum);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of processors available.
|
||||
* @return Number of processors or 1 if the required definition of _SC_NPROCESSORS_CONF
|
||||
* is not found
|
||||
*/
|
||||
long get_processor_count()
|
||||
{
|
||||
long processors = 1;
|
||||
#ifdef _SC_NPROCESSORS_ONLN
|
||||
if ((processors = sysconf(_SC_NPROCESSORS_ONLN)) <= 0)
|
||||
{
|
||||
MXS_WARNING("Unable to establish the number of available cores. Defaulting to 1.");
|
||||
processors = 1;
|
||||
}
|
||||
#else
|
||||
#error _SC_NPROCESSORS_ONLN not available.
|
||||
#endif
|
||||
return processors;
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
#include <maxscale/gwdirs.h>
|
||||
#include <maxscale/alloc.h>
|
||||
#include <maxscale/gw.h>
|
||||
#include <maxscale/utils.h>
|
||||
|
||||
/**
|
||||
* Set the configuration file directory
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include <maxscale/session.h>
|
||||
#include <maxscale/statistics.h>
|
||||
#include <maxscale/query_classifier.h>
|
||||
#include <maxscale/utils.h>
|
||||
|
||||
#define PROFILE_POLL 0
|
||||
|
||||
|
@ -28,18 +28,21 @@
|
||||
* @endverbatim
|
||||
*/
|
||||
|
||||
|
||||
#include <maxscale/utils.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <regex.h>
|
||||
#include <maxscale/gw.h>
|
||||
#include <maxscale/dcb.h>
|
||||
#include <maxscale/session.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <maxscale/alloc.h>
|
||||
#include <maxscale/poll.h>
|
||||
#include <maxscale/dcb.h>
|
||||
#include <maxscale/log_manager.h>
|
||||
#include <maxscale/secrets.h>
|
||||
#include <maxscale/random_jkiss.h>
|
||||
#include <maxscale/pcre2.h>
|
||||
#include <maxscale/poll.h>
|
||||
#include <maxscale/random_jkiss.h>
|
||||
#include <maxscale/secrets.h>
|
||||
#include <maxscale/session.h>
|
||||
|
||||
#if !defined(PATH_MAX)
|
||||
# if defined(__USE_POSIX)
|
||||
@ -880,3 +883,171 @@ void utils_end()
|
||||
pcre2_code_free(replace_values_re);
|
||||
replace_values_re = NULL;
|
||||
}
|
||||
|
||||
SPINLOCK tmplock = SPINLOCK_INIT;
|
||||
|
||||
/*
|
||||
* Set IP address in socket structure in_addr
|
||||
*
|
||||
* @param a Pointer to a struct in_addr into which the address is written
|
||||
* @param p The hostname to lookup
|
||||
* @return 1 on success, 0 on failure
|
||||
*/
|
||||
int
|
||||
setipaddress(struct in_addr *a, char *p)
|
||||
{
|
||||
#ifdef __USE_POSIX
|
||||
struct addrinfo *ai = NULL, hint;
|
||||
int rc;
|
||||
struct sockaddr_in *res_addr;
|
||||
memset(&hint, 0, sizeof (hint));
|
||||
|
||||
hint.ai_socktype = SOCK_STREAM;
|
||||
|
||||
/*
|
||||
* This is for the listening socket, matching INADDR_ANY only for now.
|
||||
* For future specific addresses bind, a dedicated routine woulbd be better
|
||||
*/
|
||||
|
||||
if (strcmp(p, "0.0.0.0") == 0)
|
||||
{
|
||||
hint.ai_flags = AI_PASSIVE;
|
||||
hint.ai_family = AF_UNSPEC;
|
||||
if ((rc = getaddrinfo(p, NULL, &hint, &ai)) != 0)
|
||||
{
|
||||
MXS_ERROR("Failed to obtain address for host %s, %s",
|
||||
p,
|
||||
gai_strerror(rc));
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hint.ai_flags = AI_CANONNAME;
|
||||
hint.ai_family = AF_INET;
|
||||
|
||||
if ((rc = getaddrinfo(p, NULL, &hint, &ai)) != 0)
|
||||
{
|
||||
MXS_ERROR("Failed to obtain address for host %s, %s",
|
||||
p,
|
||||
gai_strerror(rc));
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* take the first one */
|
||||
if (ai != NULL)
|
||||
{
|
||||
res_addr = (struct sockaddr_in *)(ai->ai_addr);
|
||||
memcpy(a, &res_addr->sin_addr, sizeof(struct in_addr));
|
||||
|
||||
freeaddrinfo(ai);
|
||||
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
struct hostent *h;
|
||||
|
||||
spinlock_acquire(&tmplock);
|
||||
h = gethostbyname(p);
|
||||
spinlock_release(&tmplock);
|
||||
|
||||
if (h == NULL)
|
||||
{
|
||||
if ((a->s_addr = inet_addr(p)) == -1)
|
||||
{
|
||||
MXS_ERROR("gethostbyname failed for [%s]", p);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* take the first one */
|
||||
memcpy(a, h->h_addr, h->h_length);
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse the bind config data. This is passed in a string as address:port.
|
||||
*
|
||||
* The address may be either a . separated IP address or a hostname to
|
||||
* lookup. The address 0.0.0.0 is the wildcard address for SOCKADR_ANY.
|
||||
* The ':' and port are required.
|
||||
*
|
||||
* @param config The bind address and port separated by a ':'
|
||||
* @param addr The sockaddr_in in which the data is written
|
||||
* @return 0 on failure
|
||||
*/
|
||||
int
|
||||
parse_bindconfig(const char *config, struct sockaddr_in *addr)
|
||||
{
|
||||
char buf[strlen(config) + 1];
|
||||
strcpy(buf, config);
|
||||
|
||||
char *port = strrchr(buf, ':');
|
||||
short pnum;
|
||||
if (port)
|
||||
{
|
||||
*port = 0;
|
||||
port++;
|
||||
pnum = atoi(port);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!strcmp(buf, "0.0.0.0"))
|
||||
{
|
||||
addr->sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!inet_aton(buf, &addr->sin_addr))
|
||||
{
|
||||
struct hostent *hp = gethostbyname(buf);
|
||||
|
||||
if (hp)
|
||||
{
|
||||
bcopy(hp->h_addr, &(addr->sin_addr.s_addr), hp->h_length);
|
||||
}
|
||||
else
|
||||
{
|
||||
MXS_ERROR("Failed to lookup host '%s'.", buf);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addr->sin_family = AF_INET;
|
||||
addr->sin_port = htons(pnum);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of processors available.
|
||||
* @return Number of processors or 1 if the required definition of _SC_NPROCESSORS_CONF
|
||||
* is not found
|
||||
*/
|
||||
long get_processor_count()
|
||||
{
|
||||
long processors = 1;
|
||||
#ifdef _SC_NPROCESSORS_ONLN
|
||||
if ((processors = sysconf(_SC_NPROCESSORS_ONLN)) <= 0)
|
||||
{
|
||||
MXS_WARNING("Unable to establish the number of available cores. Defaulting to 1.");
|
||||
processors = 1;
|
||||
}
|
||||
#else
|
||||
#error _SC_NPROCESSORS_ONLN not available.
|
||||
#endif
|
||||
return processors;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user