Reindented server/core/gateway.c

This commit is contained in:
Johan Wikman
2015-11-30 13:01:36 +02:00
parent 20c4a0aa67
commit ecb5ae528c

View File

@ -220,9 +220,13 @@ static SPINLOCK* ssl_locks;
static void ssl_locking_function(int mode, int n, const char* file, int line) static void ssl_locking_function(int mode, int n, const char* file, int line)
{ {
if (mode & CRYPTO_LOCK) if (mode & CRYPTO_LOCK)
{
spinlock_acquire(&ssl_locks[n]); spinlock_acquire(&ssl_locks[n]);
}
else else
{
spinlock_release(&ssl_locks[n]); spinlock_release(&ssl_locks[n]);
}
} }
/** /**
* OpenSSL requires this struct to be defined in order to use dynamic locks * OpenSSL requires this struct to be defined in order to use dynamic locks
@ -376,7 +380,8 @@ static int signal_set(int sig, void (*handler)(int));
static void static void
sigfatal_handler(int i) sigfatal_handler(int i)
{ {
if (fatal_handling) { if (fatal_handling)
{
fprintf(stderr, "Fatal signal %d while backtracing\n", i); fprintf(stderr, "Fatal signal %d while backtracing\n", i);
_exit(1); _exit(1);
} }
@ -395,12 +400,16 @@ sigfatal_handler(int i)
int n, count = backtrace(addrs, 128); int n, count = backtrace(addrs, 128);
char** symbols = backtrace_symbols(addrs, count); char** symbols = backtrace_symbols(addrs, count);
if (symbols) { if (symbols)
for (n = 0; n < count; n++) { {
for (n = 0; n < count; n++)
{
MXS_ERROR(" %s\n", symbols[n]); MXS_ERROR(" %s\n", symbols[n]);
} }
free(symbols); free(symbols);
} else { }
else
{
fprintf(stderr, "\nresolving symbols to error log failed, writing call trace to stderr:\n"); fprintf(stderr, "\nresolving symbols to error log failed, writing call trace to stderr:\n");
backtrace_symbols_fd(addrs, count, fileno(stderr)); backtrace_symbols_fd(addrs, count, fileno(stderr));
} }
@ -429,7 +438,8 @@ sigfatal_handler(int i)
* @details (write detailed description here) * @details (write detailed description here)
* *
*/ */
static int signal_set(int sig, void (*handler)(int)) { static int signal_set(int sig, void (*handler)(int))
{
static struct sigaction sigact; static struct sigaction sigact;
static int err; static int err;
int rc = 0; int rc = 0;
@ -457,8 +467,7 @@ static int signal_set(int sig, void (*handler)(int)) {
/** /**
* Cleanup the temporary data directory we created for the gateway * Cleanup the temporary data directory we created for the gateway
*/ */
int ntfw_cb( int ntfw_cb(const char* filename,
const char* filename,
const struct stat* filestat, const struct stat* filestat,
int fileflags, int fileflags,
struct FTW* pfwt) struct FTW* pfwt)
@ -492,7 +501,8 @@ void datadir_cleanup()
static void libmysqld_done(void) static void libmysqld_done(void)
{ {
if (libmysqld_started) { if (libmysqld_started)
{
mysql_library_end(); mysql_library_end();
} }
} }
@ -503,8 +513,7 @@ static void write_footer(void)
file_write_footer(stdout); file_write_footer(stdout);
} }
static bool file_write_footer( static bool file_write_footer(FILE* outfile)
FILE* outfile)
{ {
bool succp = false; bool succp = false;
size_t len1; size_t len1;
@ -522,8 +531,7 @@ static bool file_write_footer(
// Documentation says 26 bytes is enough, but 32 is a nice round number. // Documentation says 26 bytes is enough, but 32 is a nice round number.
#define ASCTIME_BUF_LEN 32 #define ASCTIME_BUF_LEN 32
static bool file_write_header( static bool file_write_header(FILE* outfile)
FILE* outfile)
{ {
bool succp = false; bool succp = false;
size_t len1; size_t len1;
@ -567,8 +575,7 @@ static bool file_write_header(
return succp; return succp;
} }
static bool resolve_maxscale_conf_fname( static bool resolve_maxscale_conf_fname(char** cnf_full_path,
char** cnf_full_path,
char* home_dir, char* home_dir,
char* cnf_file_arg) char* cnf_file_arg)
{ {
@ -592,9 +599,7 @@ static bool resolve_maxscale_conf_fname(
* directory. * directory.
* '-f MaxScale.cnf' * '-f MaxScale.cnf'
*/ */
*cnf_full_path = get_expanded_pathname(NULL, *cnf_full_path = get_expanded_pathname(NULL, home_dir, cnf_file_arg);
home_dir,
cnf_file_arg);
if (*cnf_full_path != NULL) if (*cnf_full_path != NULL)
{ {
@ -680,8 +685,7 @@ return_succp:
* @return NULL if directory can be read and written, an error message if either * @return NULL if directory can be read and written, an error message if either
* read or write is not permitted. * read or write is not permitted.
*/ */
static char* check_dir_access( static char* check_dir_access(char* dirname, bool rd, bool wr)
char* dirname, bool rd, bool wr)
{ {
char errbuf[PATH_MAX * 2]; char errbuf[PATH_MAX * 2];
char* errstr = NULL; char* errstr = NULL;
@ -747,7 +751,8 @@ static void print_log_n_stderr(
char* fpr_err = "*\n* Error :"; char* fpr_err = "*\n* Error :";
char* fpr_end = "\n*\n"; char* fpr_end = "\n*\n";
if (do_log) { if (do_log)
{
char errbuf[STRERROR_BUFLEN]; char errbuf[STRERROR_BUFLEN];
MXS_ERROR("%s %s %s %s", MXS_ERROR("%s %s %s %s",
log_err, log_err,
@ -755,7 +760,8 @@ static void print_log_n_stderr(
eno == 0 ? " " : "Error :", eno == 0 ? " " : "Error :",
eno == 0 ? " " : strerror_r(eno, errbuf, sizeof(errbuf))); eno == 0 ? " " : strerror_r(eno, errbuf, sizeof(errbuf)));
} }
if (do_stderr) { if (do_stderr)
{
char errbuf[STRERROR_BUFLEN]; char errbuf[STRERROR_BUFLEN];
fprintf(stderr, fprintf(stderr,
"%s %s %s %s %s", "%s %s %s %s %s",
@ -767,8 +773,7 @@ static void print_log_n_stderr(
} }
} }
static bool file_is_readable( static bool file_is_readable(char* absolute_pathname)
char* absolute_pathname)
{ {
bool succp = true; bool succp = true;
@ -797,8 +802,7 @@ static bool file_is_readable(
return succp; return succp;
} }
static bool file_is_writable( static bool file_is_writable(char* absolute_pathname)
char* absolute_pathname)
{ {
bool succp = true; bool succp = true;
@ -846,8 +850,7 @@ static bool file_is_writable(
* *
* *
*/ */
static char* get_expanded_pathname( static char* get_expanded_pathname(char** output_path,
char** output_path,
char* relative_path, char* relative_path,
const char* fname) const char* fname)
{ {
@ -893,9 +896,7 @@ static char* get_expanded_pathname(
* readability. * readability.
*/ */
size_t pathlen = strnlen(expanded_path, PATH_MAX)+ size_t pathlen = strnlen(expanded_path, PATH_MAX)+
1+ 1 + strnlen(fname, PATH_MAX) + 1;
strnlen(fname, PATH_MAX)+
1;
cnf_file_buf = (char*)malloc(pathlen); cnf_file_buf = (char*)malloc(pathlen);
if (cnf_file_buf == NULL) if (cnf_file_buf == NULL)
@ -1627,7 +1628,9 @@ int main(int argc, char **argv)
snprintf(pathbuf, PATH_MAX, "%s", get_configdir()); snprintf(pathbuf, PATH_MAX, "%s", get_configdir());
pathbuf[PATH_MAX] = '\0'; pathbuf[PATH_MAX] = '\0';
if (pathbuf[strlen(pathbuf) - 1] != '/') if (pathbuf[strlen(pathbuf) - 1] != '/')
{
strcat(pathbuf, "/"); strcat(pathbuf, "/");
}
if (!resolve_maxscale_conf_fname(&cnf_file_path, pathbuf, cnf_file_arg)) if (!resolve_maxscale_conf_fname(&cnf_file_path, pathbuf, cnf_file_arg))
{ {
@ -1988,8 +1991,7 @@ static void log_flush_shutdown(void)
* *
* *
*/ */
static void log_flush_cb( static void log_flush_cb(void* arg)
void* arg)
{ {
ssize_t timeout_ms = *(ssize_t *)arg; ssize_t timeout_ms = *(ssize_t *)arg;
struct timespec ts1; struct timespec ts1;
@ -1998,7 +2000,8 @@ static void log_flush_cb(
ts1.tv_nsec = (timeout_ms%1000) * 1000000; ts1.tv_nsec = (timeout_ms%1000) * 1000000;
MXS_NOTICE("Started MaxScale log flusher."); MXS_NOTICE("Started MaxScale log flusher.");
while (!do_exit) { while (!do_exit)
{
mxs_log_flush(); mxs_log_flush();
nanosleep(&ts1, NULL); nanosleep(&ts1, NULL);
} }
@ -2025,7 +2028,8 @@ static void unlock_pidfile()
*/ */
static void unlink_pidfile(void) static void unlink_pidfile(void)
{ {
if (strlen(pidfile)) { if (strlen(pidfile))
{
if (unlink(pidfile)) if (unlink(pidfile))
{ {
char errbuf[STRERROR_BUFLEN]; char errbuf[STRERROR_BUFLEN];
@ -2057,7 +2061,9 @@ bool pid_file_exists()
pathbuf[PATH_MAX] = '\0'; pathbuf[PATH_MAX] = '\0';
if (access(pathbuf, F_OK) != 0) if (access(pathbuf, F_OK) != 0)
{
return false; return false;
}
if (access(pathbuf, R_OK) == 0) if (access(pathbuf, R_OK) == 0)
{ {
@ -2249,7 +2255,9 @@ bool handle_path_arg(char** dest, char* path, char* arg, bool rd, bool wr)
bool rval = false; bool rval = false;
if (path == NULL && arg == NULL) if (path == NULL && arg == NULL)
{
return rval; return rval;
}
if (path) if (path)
{ {