Better recovery flag implementation
This commit is contained in:
+3
-3
@@ -115,9 +115,9 @@ MsgSQLStatement *MsgSQLPrepare(MsgSQLHandle *handle, const char *statement, MsgS
|
||||
|
||||
// Misc. util functions
|
||||
|
||||
// FIXME: This API is wrong, should include agent name
|
||||
EXPORT BOOL MsgSetRecoveryFlag(void);
|
||||
EXPORT BOOL MsgGetRecoveryFlag(void);
|
||||
EXPORT BOOL MsgSetRecoveryFlag(unsigned char *agent_name);
|
||||
EXPORT BOOL MsgGetRecoveryFlag(unsigned char *agent_name);
|
||||
EXPORT BOOL MsgClearRecoveryFlag(unsigned char *agent_name);
|
||||
|
||||
EXPORT BOOL MsgGetServerCredential(char *buffer);
|
||||
EXPORT BOOL MsgSetServerCredential(void);
|
||||
|
||||
@@ -117,7 +117,7 @@ ReadConfiguration (BOOL *recover)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*recover = MsgGetRecoveryFlag();
|
||||
*recover = MsgGetRecoveryFlag("queue");
|
||||
|
||||
/* set some arrays up */
|
||||
if (Conf.deferEnabled) {
|
||||
|
||||
@@ -346,12 +346,6 @@ ProcessClient(void *clientp, Connection *conn)
|
||||
return HandleCommand(client);
|
||||
}
|
||||
|
||||
static BOOL
|
||||
InternalSetServerState(const unsigned char *state)
|
||||
{
|
||||
return MsgGetRecoveryFlag();
|
||||
}
|
||||
|
||||
static void
|
||||
QueueServer(void *ignored)
|
||||
{
|
||||
@@ -368,8 +362,6 @@ QueueServer(void *ignored)
|
||||
ProcessClient,
|
||||
&Agent.clientMemPool);
|
||||
|
||||
InternalSetServerState("Shutting down");
|
||||
|
||||
/* Shutting down */
|
||||
if (Agent.clientListener) {
|
||||
ConnClose(Agent.clientListener, 1);
|
||||
@@ -391,7 +383,7 @@ QueueServer(void *ignored)
|
||||
|
||||
BongoThreadPoolShutdown(Agent.clientThreadPool);
|
||||
|
||||
InternalSetServerState("Shutdown");
|
||||
MsgClearRecoveryFlag("queue");
|
||||
|
||||
BongoAgentShutdown(&Agent.agent);
|
||||
|
||||
@@ -576,7 +568,7 @@ XplServiceMain(int argc, char *argv[])
|
||||
|
||||
BongoAgentStartMonitor(&Agent.agent);
|
||||
|
||||
InternalSetServerState("Running");
|
||||
MsgSetRecoveryFlag("queue");
|
||||
|
||||
/* Start the server thread */
|
||||
XplStartMainThread(AGENT_NAME, &id, QueueServer, 8192, NULL, ccode);
|
||||
|
||||
@@ -75,7 +75,7 @@ StoreAgentReadConfiguration(BOOL *recover)
|
||||
// can't proceed without the server hash..
|
||||
return(FALSE);
|
||||
|
||||
if (recover && MsgGetRecoveryFlag()) {
|
||||
if (recover && MsgGetRecoveryFlag("store")) {
|
||||
*recover = TRUE;
|
||||
}
|
||||
|
||||
|
||||
@@ -300,9 +300,11 @@ _XplServiceMain(int argc, char *argv[])
|
||||
XplSignalHandler(SignalHandler);
|
||||
|
||||
/* Start the server thread */
|
||||
MsgSetRecoveryFlag("store");
|
||||
XplStartMainThread(AGENT_NAME, &id, StoreServer, 8192, NULL, ccode);
|
||||
|
||||
XplUnloadApp(XplGetThreadID());
|
||||
MsgClearRecoveryFlag("store");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -643,18 +643,56 @@ MsgInit(void)
|
||||
}
|
||||
}
|
||||
|
||||
EXPORT BOOL
|
||||
MsgSetRecoveryFlag(void)
|
||||
void
|
||||
MsgRecoveryFlagFile(char *agent, char *buffer, size_t buffer_len)
|
||||
{
|
||||
// FIXME: TODO :)
|
||||
return FALSE;
|
||||
snprintf(buffer, buffer_len - 1, "%s/%s.pid", XPL_DEFAULT_WORK_DIR, agent);
|
||||
}
|
||||
|
||||
EXPORT BOOL
|
||||
MsgGetRecoveryFlag(void)
|
||||
MsgSetRecoveryFlag(unsigned char *agent_name)
|
||||
{
|
||||
// FIXME: TODO :)
|
||||
return FALSE;
|
||||
FILE *flag;
|
||||
unsigned char flagfile[XPL_MAX_PATH];
|
||||
unsigned char pidstr[20];
|
||||
pid_t pid;
|
||||
|
||||
MsgRecoveryFlagFile(agent_name, flagfile, XPL_MAX_PATH);
|
||||
|
||||
flag = fopen(flagfile, "w");
|
||||
if (flag == -1) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
snprintf(pidstr, 18, "%lu\n", getpid());
|
||||
fwrite(pidstr, strlen(pidstr), sizeof(unsigned char), flag);
|
||||
|
||||
fclose(flag);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
EXPORT BOOL
|
||||
MsgGetRecoveryFlag(unsigned char *agent_name)
|
||||
{
|
||||
unsigned char flagfile[XPL_MAX_PATH];
|
||||
struct stat filestat;
|
||||
|
||||
MsgRecoveryFlagFile(agent_name, flagfile, XPL_MAX_PATH);
|
||||
if (stat(flagfile, &filestat) == 0) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
EXPORT BOOL
|
||||
MsgClearRecoveryFlag(unsigned char *agent_name)
|
||||
{
|
||||
unsigned char flagfile[XPL_MAX_PATH];
|
||||
|
||||
MsgRecoveryFlagFile(agent_name, flagfile, XPL_MAX_PATH);
|
||||
unlink(flagfile);
|
||||
}
|
||||
|
||||
EXPORT BOOL
|
||||
|
||||
Reference in New Issue
Block a user