Tidy up of the exit status based on the issues founf during startup.

See Bugzilla 370.
This commit is contained in:
Mark Riddoch
2014-02-05 12:20:53 +01:00
parent fa79a121e6
commit e97ab93966
3 changed files with 61 additions and 17 deletions

View File

@ -63,7 +63,7 @@ HDRS= ../include/atomic.h ../include/buffer.h ../include/dcb.h \
../include/session.h ../include/spinlock.h ../include/thread.h \ ../include/session.h ../include/spinlock.h ../include/thread.h \
../include/modules.h ../include/poll.h ../include/config.h \ ../include/modules.h ../include/poll.h ../include/config.h \
../include/users.h ../include/hashtable.h ../include/gwbitmask.h \ ../include/users.h ../include/hashtable.h ../include/gwbitmask.h \
../include/adminusers.h ../include/version.h ../include/adminusers.h ../include/version.h ../include/maxscale.h
OBJ=$(SRCS:.c=.o) OBJ=$(SRCS:.c=.o)

View File

@ -55,6 +55,7 @@
#include <mysql.h> #include <mysql.h>
#include <monitor.h> #include <monitor.h>
#include <version.h> #include <version.h>
#include <maxscale.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
@ -867,7 +868,7 @@ static void usage(void)
*/ */
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int rc = 0; int rc = MAXSCALE_SHUTDOWN;
int l; int l;
int i; int i;
int n; int n;
@ -916,7 +917,7 @@ int main(int argc, char **argv)
{ {
char* fprerr = "Failed to register exit functions for MaxScale"; char* fprerr = "Failed to register exit functions for MaxScale";
print_log_n_stderr(false, true, NULL, fprerr, 0); print_log_n_stderr(false, true, NULL, fprerr, 0);
rc = 1; rc = MAXSCALE_INTERNALERROR;
goto return_main; goto return_main;
} }
} }
@ -994,7 +995,7 @@ int main(int argc, char **argv)
if (!succp) if (!succp)
{ {
rc = 1; rc = MAXSCALE_BADARG;
goto return_main; goto return_main;
} }
} }
@ -1026,7 +1027,7 @@ int main(int argc, char **argv)
eno = errno; eno = errno;
errno = 0; errno = 0;
print_log_n_stderr(true, true, fprerr, fprerr, eno); print_log_n_stderr(true, true, fprerr, fprerr, eno);
rc = 1; rc = MAXSCALE_INTERNALERROR;
goto return_main; goto return_main;
} }
r = sigdelset(&sigset, SIGHUP); r = sigdelset(&sigset, SIGHUP);
@ -1038,7 +1039,7 @@ int main(int argc, char **argv)
eno = errno; eno = errno;
errno = 0; errno = 0;
print_log_n_stderr(true, true, fprerr, logerr, eno); print_log_n_stderr(true, true, fprerr, logerr, eno);
rc = 1; rc = MAXSCALE_INTERNALERROR;
goto return_main; goto return_main;
} }
r = sigdelset(&sigset, SIGTERM); r = sigdelset(&sigset, SIGTERM);
@ -1050,7 +1051,7 @@ int main(int argc, char **argv)
eno = errno; eno = errno;
errno = 0; errno = 0;
print_log_n_stderr(true, true, fprerr, logerr, eno); print_log_n_stderr(true, true, fprerr, logerr, eno);
rc = 1; rc = MAXSCALE_INTERNALERROR;
goto return_main; goto return_main;
} }
r = sigprocmask(SIG_SETMASK, &sigset, NULL); r = sigprocmask(SIG_SETMASK, &sigset, NULL);
@ -1061,7 +1062,7 @@ int main(int argc, char **argv)
eno = errno; eno = errno;
errno = 0; errno = 0;
print_log_n_stderr(true, true, fprerr, logerr, eno); print_log_n_stderr(true, true, fprerr, logerr, eno);
rc = 1; rc = MAXSCALE_INTERNALERROR;
goto return_main; goto return_main;
} }
gw_daemonize(); gw_daemonize();
@ -1103,7 +1104,7 @@ int main(int argc, char **argv)
errno = 0; errno = 0;
print_log_n_stderr(true, !daemon_mode, logerr, fprerr, eno); print_log_n_stderr(true, !daemon_mode, logerr, fprerr, eno);
free(logerr); free(logerr);
rc = 1; rc = MAXSCALE_INTERNALERROR;
goto return_main; goto return_main;
} }
} }
@ -1114,7 +1115,7 @@ int main(int argc, char **argv)
char* logerr = "Failed to initialise signal mask for MaxScale. " char* logerr = "Failed to initialise signal mask for MaxScale. "
"Exiting."; "Exiting.";
print_log_n_stderr(true, true, logerr, logerr, eno); print_log_n_stderr(true, true, logerr, logerr, eno);
rc = 1; rc = MAXSCALE_INTERNALERROR;
goto return_main; goto return_main;
} }
l = atexit(libmysqld_done); l = atexit(libmysqld_done);
@ -1125,7 +1126,7 @@ int main(int argc, char **argv)
char* logerr = "Failed to register exit function libmysql_done " char* logerr = "Failed to register exit function libmysql_done "
"for MaxScale. Exiting."; "for MaxScale. Exiting.";
print_log_n_stderr(true, true, logerr, fprerr, 0); print_log_n_stderr(true, true, logerr, fprerr, 0);
rc = 1; rc = MAXSCALE_INTERNALERROR;
goto return_main; goto return_main;
} }
/*< /*<
@ -1138,7 +1139,7 @@ int main(int argc, char **argv)
if (!resolve_maxscale_homedir(&home_dir)) if (!resolve_maxscale_homedir(&home_dir))
{ {
ss_dassert(home_dir == NULL); ss_dassert(home_dir == NULL);
rc = 1; rc = MAXSCALE_HOMELESS;
goto return_main; goto return_main;
} }
sprintf(mysql_home, "%s/mysql", home_dir); sprintf(mysql_home, "%s/mysql", home_dir);
@ -1176,7 +1177,7 @@ int main(int argc, char **argv)
if (!resolve_maxscale_conf_fname(&cnf_file_path, home_dir, cnf_file_arg)) if (!resolve_maxscale_conf_fname(&cnf_file_path, home_dir, cnf_file_arg))
{ {
ss_dassert(cnf_file_path == NULL); ss_dassert(cnf_file_path == NULL);
rc = 1; rc = MAXSCALE_BADCONFIG;
goto return_main; goto return_main;
} }
@ -1276,7 +1277,7 @@ int main(int argc, char **argv)
mysql_error(NULL), mysql_error(NULL),
__FILE__, __FILE__,
__LINE__))); __LINE__)));
rc = 1; rc = MAXSCALE_NOLIBRARY;
goto return_main; goto return_main;
} }
libmysqld_started = TRUE; libmysqld_started = TRUE;
@ -1291,7 +1292,7 @@ int main(int argc, char **argv)
"Error : Failed to load MaxScale configuration file %s. " "Error : Failed to load MaxScale configuration file %s. "
"Exiting.", "Exiting.",
cnf_file_path))); cnf_file_path)));
rc = 1; rc = MAXSCALE_BADCONFIG;
goto return_main; goto return_main;
} }
LOGIF(LM, (skygw_log_write( LOGIF(LM, (skygw_log_write(
@ -1313,7 +1314,7 @@ int main(int argc, char **argv)
{ {
char* logerr = "Failed to start any MaxScale services. Exiting."; char* logerr = "Failed to start any MaxScale services. Exiting.";
print_log_n_stderr(true, !daemon_mode, logerr, logerr, 0); print_log_n_stderr(true, !daemon_mode, logerr, logerr, 0);
rc = 1; rc = MAXSCALE_NOSERVICES;
goto return_main; goto return_main;
} }
/*< /*<
@ -1370,7 +1371,7 @@ int main(int argc, char **argv)
"MaxScale shutdown completed."))); "MaxScale shutdown completed.")));
return_main: return_main:
return 0; return rc;
} /*< End of main */ } /*< End of main */
/*< /*<

43
server/include/maxscale.h Normal file
View File

@ -0,0 +1,43 @@
#ifndef _MAXSCALE_H
#define _MAXSCALE_H
/*
* This file is distributed as part of the SkySQL Gateway. It is free
* software: you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation,
* version 2.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright SkySQL Ab 2014
*/
/**
* @file maxscale.h
*
* Some general definitions for MaxScale
*
* @verbatim
* Revision History
*
* Date Who Description
* 05/02/14 Mark Riddoch Initial implementation
*
* @endverbatim
*/
/* Exit status for MaxScale */
#define MAXSCALE_SHUTDOWN 0 /* Good shutdown */
#define MAXSCALE_BADCONFIG 1 /* Configuration fiel error */
#define MAXSCALE_NOLIBRARY 2 /* No embedded library found */
#define MAXSCALE_NOSERVICES 3 /* No servics are running */
#define MAXSCALE_HOMELESS 4 /* No MaxScale Home */
#define MAXSCALE_BADARG 5 /* Bad command line argument */
#define MAXSCALE_INTERNALERROR 6 /* Internal error, see error log */
#endif