Polished error mesesages, and made them consistent.

This commit is contained in:
vraatikka
2013-11-22 21:17:38 +02:00
parent 841c51fc5c
commit 4f14c65040

View File

@ -165,7 +165,9 @@ static int signal_set (int sig, void (*handler)(int)) {
memset(&sigact, 0, sizeof(struct sigaction)); memset(&sigact, 0, sizeof(struct sigaction));
sigact.sa_handler = handler; sigact.sa_handler = handler;
GW_NOINTR_CALL(err = sigaction(sig, &sigact, NULL)); GW_NOINTR_CALL(err = sigaction(sig, &sigact, NULL));
if (err < 0) {
if (err < 0)
{
int eno = errno; int eno = errno;
errno = 0; errno = 0;
skygw_log_write_flush( skygw_log_write_flush(
@ -324,9 +326,27 @@ return_succp:
return succp; return succp;
} }
static void print_signal_set_error(
int sig,
int eno)
{
fprintf(stderr,
"*\n* Error : Failed to set signal handler for %s due "
"%d, %s.\n* "
"Exiting.\n*\n",
strsignal(sig),
eno,
strerror(eno));
skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Failed to set signal handler for %s due "
"%d, %s. Exiting.",
strsignal(sig),
eno,
strerror(eno));
}
/** /**
* @node The main entry point into the gateway * @node The main entry point into the gateway
* *
@ -352,6 +372,7 @@ int main(int argc, char **argv)
int n; int n;
int n_threads; /**<! number of epoll listener threads */ int n_threads; /**<! number of epoll listener threads */
int n_services; int n_services;
int eno = 0; /**<! local variable for errno */
void** threads; /**<! thread list */ void** threads; /**<! thread list */
char mysql_home[1024]; char mysql_home[1024];
char buf[1024]; char buf[1024];
@ -379,7 +400,7 @@ int main(int argc, char **argv)
file_write_header(stderr); file_write_header(stderr);
l = atexit(skygw_logmanager_exit); l = atexit(skygw_logmanager_exit);
/*l=1;/**/
if (l != 0) { if (l != 0) {
fprintf(stderr, fprintf(stderr,
"*\n* Error : Failed to register exit function for " "*\n* Error : Failed to register exit function for "
@ -389,7 +410,7 @@ int main(int argc, char **argv)
goto return_main; goto return_main;
} }
l = atexit(datadir_cleanup); l = atexit(datadir_cleanup);
/*l=1;/**/
if (l != 0) { if (l != 0) {
fprintf(stderr, fprintf(stderr,
"*\n* Error : Failed to register exit function for " "*\n* Error : Failed to register exit function for "
@ -399,7 +420,7 @@ int main(int argc, char **argv)
goto return_main; goto return_main;
} }
l = atexit(write_footer); l = atexit(write_footer);
/*l=1;/**/
if (l != 0) { if (l != 0) {
fprintf(stderr, fprintf(stderr,
"*\n* Error : Failed to register exit function for " "*\n* Error : Failed to register exit function for "
@ -422,26 +443,28 @@ int main(int argc, char **argv)
* 1. Resolve config file location from command-line argument. * 1. Resolve config file location from command-line argument.
*/ */
r = strncmp(argv[n], "-c", 2); r = strncmp(argv[n], "-c", 2);
/*r=0;/**/
if (r == 0) if (r == 0)
{ {
int s=2; const int arg_limit = 10; /**<! max. 10 space chars allowed */
int s = 2; /**<! start index of arg string */
while (argv[n][s] == 0 && s<10) s++; while (argv[n][s] == 0 && s<arg_limit) s++;
/*s=arg_limit; /**/
if (s == 10) { if (s == arg_limit)
{
fprintf(stderr, fprintf(stderr,
"*\n* Error : Unable to find the MaxScale " "*\n* Error : Unable to find the MaxScale "
"configuration file MaxScale.cnf.\n" "configuration file MaxScale.cnf.\n"
"* Either install one in /etc/ , " "* Either install one in /etc/ , "
"$MAXSCALE_HOME/etc , or specify the file " "$MAXSCALE_HOME/etc/ , or specify the file "
"with the -c option.\n* Exiting.\n*\n"); "with the -c option.\n* Exiting.\n*\n");
skygw_log_write_flush( skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : Unable to find the MaxScale " "Error : Unable to find the MaxScale "
"configuration file, either install one " "configuration file, either install one "
"in /etc/MaxScale.cnf, " "in /etc/, "
"$MAXSCALE_HOME/etc/MaxScale.cnf " "$MAXSCALE_HOME/etc/ "
"or use the -c option. Exiting."); "or use the -c option. Exiting.");
rc = 1; rc = 1;
goto return_main; goto return_main;
@ -468,8 +491,9 @@ int main(int argc, char **argv)
"Info : MaxScale will be run in a daemon process.\n\n"); "Info : MaxScale will be run in a daemon process.\n\n");
r = sigfillset(&sigset); r = sigfillset(&sigset);
/*r=1;/**/
if (r != 0) { if (r != 0)
{
eno = errno; eno = errno;
errno = 0; errno = 0;
skygw_log_write_flush( skygw_log_write_flush(
@ -483,8 +507,9 @@ int main(int argc, char **argv)
goto return_main; goto return_main;
} }
r = sigdelset(&sigset, SIGHUP); r = sigdelset(&sigset, SIGHUP);
/*r=1;/**/
if (r != 0) { if (r != 0)
{
eno = errno; eno = errno;
errno = 0; errno = 0;
skygw_log_write_flush( skygw_log_write_flush(
@ -499,8 +524,9 @@ int main(int argc, char **argv)
goto return_main; goto return_main;
} }
r = sigdelset(&sigset, SIGTERM); r = sigdelset(&sigset, SIGTERM);
/*r=1;/**/
if (r != 0) { if (r != 0)
{
eno = errno; eno = errno;
errno = 0; errno = 0;
skygw_log_write_flush( skygw_log_write_flush(
@ -515,7 +541,7 @@ int main(int argc, char **argv)
goto return_main; goto return_main;
} }
r = sigprocmask(SIG_SETMASK, &sigset, NULL); r = sigprocmask(SIG_SETMASK, &sigset, NULL);
/*r=1;/**/
if (r != 0) { if (r != 0) {
eno = errno; eno = errno;
errno = 0; errno = 0;
@ -533,17 +559,58 @@ int main(int argc, char **argv)
} }
l = signal_set(SIGHUP, sighup_handler); l = signal_set(SIGHUP, sighup_handler);
/*l=1;/**/
if (l != 0)
{
eno = errno;
errno = 0;
print_signal_set_error(SIGHUP, eno);
rc = 1;
goto return_main;
}
l = signal_set(SIGTERM, sigterm_handler);
/*l=1;/**/
if (l != 0)
{
eno = errno;
errno = 0;
print_signal_set_error(SIGTERM, eno);
rc = 1;
goto return_main;
}
l = signal_set(SIGINT, sigint_handler);
/*l=1; /**/
if (l != 0)
{
eno = errno;
errno = 0;
print_signal_set_error(SIGINT, eno);
rc = 1;
goto return_main;
}
eno = pthread_sigmask(SIG_BLOCK, &sigpipe_mask, &saved_mask);
signal_set(SIGTERM, sigterm_handler); /*eno=EINTR; /**/
signal_set(SIGINT, sigint_handler); if (eno != 0)
{
if (pthread_sigmask(SIG_BLOCK, &sigpipe_mask, &saved_mask) == -1) { fprintf(stderr,
perror("pthread_sigmask"); "*\n* Error : Failed to set signal mask for %s due to "
exit(1); "%d, %s.\n* Exiting.\n*\n",
program_invocation_short_name,
eno,
strerror(eno));
skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Failed to set signal mask for %s. due to "
"%d, %s. Exiting.",
program_invocation_short_name,
eno,
strerror(eno));
rc = 1;
goto return_main;
} }
l = atexit(libmysqld_done); l = atexit(libmysqld_done);
/*l=1;/**/
if (l != 0) { if (l != 0) {
fprintf(stderr, fprintf(stderr,
"*\n* Error : Failed to register exit function libmysql_done " "*\n* Error : Failed to register exit function libmysql_done "
@ -551,19 +618,21 @@ int main(int argc, char **argv)
program_invocation_short_name); program_invocation_short_name);
skygw_log_write_flush( skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"* Error : Failed to register exit function " "Error : Failed to register exit function "
"libmysql_done for %s. Exiting.", "libmysql_done for %s. Exiting.",
program_invocation_short_name); program_invocation_short_name);
rc = 1; rc = 1;
goto return_main; goto return_main;
} }
if ((home = getenv("MAXSCALE_HOME")) != NULL) home = getenv("MAXSCALE_HOME");
/*home=NULL; /**/
if (home != NULL)
{ {
int r = access(home, R_OK); int r = access(home, R_OK);
int eno = 0; int eno = 0;
/*r=1; /**/
if (r != 0) if (r != 0)
{ {
eno = errno; eno = errno;
@ -578,7 +647,7 @@ int main(int argc, char **argv)
strerror(eno)); strerror(eno));
skygw_log_write_flush( skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"* Error : Failed to read the " "Error : Failed to read the "
"value of MAXSCALE_HOME, %s, due " "value of MAXSCALE_HOME, %s, due "
"to %d, %s. Exiting.", "to %d, %s. Exiting.",
home, home,
@ -592,20 +661,21 @@ int main(int argc, char **argv)
/** /**
* 2. Resolve config file location from $MAXSCALE_HOME/etc. * 2. Resolve config file location from $MAXSCALE_HOME/etc.
*/ */
/*cnf_file=NULL; /**/
if (cnf_file == NULL) { if (cnf_file == NULL) {
int r; int r;
int eno = 0; int eno = 0;
sprintf(buf, "%s/etc/MaxScale.cnf", home); sprintf(buf, "%s/etc/MaxScale.cnf", home);
r = access(buf, R_OK); r = access(buf, R_OK);
/*r=1; /**/
if (r != 0) if (r != 0)
{ {
eno = errno; eno = errno;
errno = 0; errno = 0;
fprintf(stderr, fprintf(stderr,
"*\n* Error : Failed to read the " "*\n* Error : Failed to read the "
"configuration \n* * file %s \n* * due " "configuration \n* file %s \n* due "
"to %d, %s.\n* " "to %d, %s.\n* "
"Exiting.\n*\n", "Exiting.\n*\n",
buf, buf,
@ -613,8 +683,8 @@ int main(int argc, char **argv)
strerror(eno)); strerror(eno));
skygw_log_write_flush( skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"* Error : Failed to read the " "Error : Failed to read the "
"configuration file %s due to %d, %s.\n" "configuration \nfile %s due to %d, %s.\n"
"Exiting.", "Exiting.",
buf, buf,
eno, eno,
@ -629,9 +699,11 @@ int main(int argc, char **argv)
* If not done yet, * If not done yet,
* 3. Resolve config file location from /etc/MaxScale. * 3. Resolve config file location from /etc/MaxScale.
*/ */
if (cnf_file == NULL && access("/etc/MaxScale.cnf", R_OK) == 0) if (cnf_file == NULL &&
access("/etc/MaxScale.cnf", R_OK) == 0)
{
cnf_file = "/etc/MaxScale.cnf"; cnf_file = "/etc/MaxScale.cnf";
}
/* /*
* Set a data directory for the mysqld library, we use * Set a data directory for the mysqld library, we use
* a unique directory name to avoid clauses if multiple * a unique directory name to avoid clauses if multiple
@ -675,15 +747,19 @@ int main(int argc, char **argv)
} }
if (cnf_file == NULL) { if (cnf_file == NULL) {
fprintf(stderr,
"*\n* Error : Failed to find or read the "
"configuration file MaxScale.cnf.\n* Either install one in /etc/, "
"$MAXSCALE_HOME/etc/ or specify it by using the -c option.\n* "
"Exiting.\n*\n");
skygw_log_write_flush( skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Fatal : Unable to find a MaxScale configuration " "Error : Failed to find or read the configuration "
"file, either install one in /etc/MaxScale.cnf, " "file MaxScale.cnf.\n Either install one in /etc/, "
"$MAXSCALE_HOME/etc/MaxScale.cnf " "$MAXSCALE_HOME/etc/ "
"or use the -c option. Exiting."); "or use the -c option. Exiting.");
fprintf(stderr, "* Unable to find MaxScale configuration file. " rc = 1;
"Exiting.\n"); goto return_main;
exit(1);
} }
/* Update the server options */ /* Update the server options */