Move daemonize() to gateway.c
The one remaining function in gw_utils.c was moved to gateway.c, so gw_utils.c could be removed.
This commit is contained in:
@ -38,8 +38,6 @@
|
||||
|
||||
MXS_BEGIN_DECLS
|
||||
|
||||
bool gw_daemonize(void);
|
||||
|
||||
MXS_END_DECLS
|
||||
|
||||
#endif
|
||||
|
@ -1,4 +1,4 @@
|
||||
add_library(maxscale-common SHARED adminusers.c alloc.c authenticator.c atomic.c buffer.c config.c dbusers.c dcb.c filter.c externcmd.c gwbitmask.c gwdirs.c gw_utils.c hashtable.c hint.c housekeeper.c listmanager.c load_utils.c log_manager.cc maxscale_pcre2.c memlog.c misc.c mlist.c modutil.c monitor.c queuemanager.c query_classifier.c poll.c random_jkiss.c resultset.c secrets.c server.c service.c session.c spinlock.c thread.c users.c utils.c skygw_utils.cc statistics.c listener.c gw_ssl.c mysql_utils.c mysql_binlog.c)
|
||||
add_library(maxscale-common SHARED adminusers.c alloc.c authenticator.c atomic.c buffer.c config.c dbusers.c dcb.c filter.c externcmd.c gwbitmask.c gwdirs.c hashtable.c hint.c housekeeper.c listmanager.c load_utils.c log_manager.cc maxscale_pcre2.c memlog.c misc.c mlist.c modutil.c monitor.c queuemanager.c query_classifier.c poll.c random_jkiss.c resultset.c secrets.c server.c service.c session.c spinlock.c thread.c users.c utils.c skygw_utils.cc statistics.c listener.c gw_ssl.c mysql_utils.c mysql_binlog.c)
|
||||
|
||||
target_link_libraries(maxscale-common ${MARIADB_CONNECTOR_LIBRARIES} ${LZMA_LINK_FLAGS} ${PCRE2_LIBRARIES} ${CURL_LIBRARIES} ssl pthread crypt dl crypto inih z rt m stdc++)
|
||||
|
||||
|
@ -190,6 +190,7 @@ void write_child_exit_code(int fd, int code);
|
||||
static bool change_cwd();
|
||||
void shutdown_server();
|
||||
static void log_exit_status();
|
||||
static bool daemonize();
|
||||
|
||||
/** SSL multi-threading functions and structures */
|
||||
|
||||
@ -1578,7 +1579,7 @@ int main(int argc, char **argv)
|
||||
|
||||
/** Daemonize the process and wait for the child process to notify
|
||||
* the parent process of its exit status. */
|
||||
parent_process = gw_daemonize();
|
||||
parent_process = daemonize();
|
||||
|
||||
if (parent_process)
|
||||
{
|
||||
@ -2663,3 +2664,38 @@ static void log_exit_status()
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Daemonize the process by forking and putting the process into the
|
||||
* background.
|
||||
*
|
||||
* @return True if context is that of the parent process, false if that of the
|
||||
* child process.
|
||||
*/
|
||||
static bool daemonize(void)
|
||||
{
|
||||
pid_t pid;
|
||||
|
||||
pid = fork();
|
||||
|
||||
if (pid < 0)
|
||||
{
|
||||
char errbuf[MXS_STRERROR_BUFLEN];
|
||||
fprintf(stderr, "fork() error %s\n", strerror_r(errno, errbuf, sizeof(errbuf)));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (pid != 0)
|
||||
{
|
||||
/* exit from main */
|
||||
return true;
|
||||
}
|
||||
|
||||
if (setsid() < 0)
|
||||
{
|
||||
char errbuf[MXS_STRERROR_BUFLEN];
|
||||
fprintf(stderr, "setsid() error %s\n", strerror_r(errno, errbuf, sizeof(errbuf)));
|
||||
exit(1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl.
|
||||
*
|
||||
* Change Date: 2019-07-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file gw_utils.c - A set if utility functions useful within the context
|
||||
* of the gateway.
|
||||
*
|
||||
* @verbatim
|
||||
* Revision History
|
||||
*
|
||||
* Date Who Description
|
||||
* 03-06-2013 Massimiliano Pinto gateway utils
|
||||
* 12-06-2013 Massimiliano Pinto gw_read_gwbuff
|
||||
* with error detection
|
||||
* and its handling
|
||||
* 01-07-2013 Massimiliano Pinto Removed session->backends
|
||||
* from gw_read_gwbuff()
|
||||
* 25-09-2013 Massimiliano Pinto setipaddress uses getaddrinfo
|
||||
* 06-02-2014 Mark Riddoch Added parse_bindconfig
|
||||
* 10-02-2014 Massimiliano Pinto Added return code to setipaddress
|
||||
* 02-09-2014 Martin Brampton Replace C++ comment with C comment
|
||||
* 02-03-2016 Martin Brampton Remove default from parse_bindconfig
|
||||
*
|
||||
*@endverbatim
|
||||
*/
|
||||
|
||||
#include <maxscale/gw.h>
|
||||
#include <maxscale/dcb.h>
|
||||
#include <maxscale/session.h>
|
||||
#include <maxscale/log_manager.h>
|
||||
|
||||
/**
|
||||
* Daemonize the process by forking and putting the process into the
|
||||
* background.
|
||||
*/
|
||||
bool gw_daemonize(void)
|
||||
{
|
||||
pid_t pid;
|
||||
|
||||
pid = fork();
|
||||
|
||||
if (pid < 0)
|
||||
{
|
||||
char errbuf[MXS_STRERROR_BUFLEN];
|
||||
fprintf(stderr, "fork() error %s\n", strerror_r(errno, errbuf, sizeof(errbuf)));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (pid != 0)
|
||||
{
|
||||
/* exit from main */
|
||||
return true;
|
||||
}
|
||||
|
||||
if (setsid() < 0)
|
||||
{
|
||||
char errbuf[MXS_STRERROR_BUFLEN];
|
||||
fprintf(stderr, "setsid() error %s\n", strerror_r(errno, errbuf, sizeof(errbuf)));
|
||||
exit(1);
|
||||
}
|
||||
return false;
|
||||
}
|
Reference in New Issue
Block a user