Slightly untested initial ringlog.

This commit is contained in:
alexhudson
2009-11-24 19:56:54 +00:00
parent 6fa1f2ddab
commit 906916e83f
5 changed files with 104 additions and 4 deletions
+1
View File
@@ -22,6 +22,7 @@ add_executable(bongostore
properties.c
query-builder.c
query-parser.c
ringlog.c
search.c
store.c
stored.c
+9 -1
View File
@@ -249,7 +249,10 @@ StoreCommandLoop(StoreClient *client)
if (-1 == ccode || ccode >= CONN_BUFSIZE) {
break;
}
char command_message[256];
snprintf(command_message, 255, "-> %s", client->buffer);
Ringlog(command_message);
memset(tokens, 0, sizeof(tokens));
n = CommandSplit(client->buffer, tokens, TOK_ARR_SZ);
if (0 == n) {
@@ -1318,8 +1321,13 @@ StoreCommandLoop(StoreClient *client)
if (ccode >= 0) {
ccode = ConnFlush(client->conn);
}
command_message[0] = '<';
command_message[1] = '-';
Ringlog(command_message);
}
return ccode;
}
+67
View File
@@ -0,0 +1,67 @@
#include "stored.h"
#include "messages.h"
#include "lock.h"
/* ring log for debugging purposes */
typedef struct {
time_t timestamp;
char message[256];
} RingLogItem;
#define RINGLOG_SIZE 200
static RingLogItem ringlog[RINGLOG_SIZE];
// ringlog_pos points to the next "free" ringlog entry.
static int ringlog_pos = 0;
static XplMutex ringlog_lock;
void
RinglogInit()
{
// initialise lock; this must be held to access the ringlog.
XplMutexInit(ringlog_lock);
// clear the ringlog.
memset(ringlog, 0, sizeof(ringlog));
}
void
Ringlog(char *message)
{
XplMutexLock(ringlog_lock);
// find the next ring log entry and write into it
ringlog[ringlog_pos].timestamp = time(NULL);
strncpy(ringlog[ringlog_pos].message, message, 255);
// advance the ring pointer, and wrap around if necessary
ringlog_pos++;
if (ringlog_pos == RINGLOG_SIZE) ringlog_pos = 0;
XplMutexUnlock(ringlog_lock);
}
void
RinglogDumpFilehandle(int fh)
{
XplMutexLock(ringlog_lock);
for (int i = ringlog_pos; i < ringlog_pos + RINGLOG_SIZE; i++) {
// print the next ring log entry - wraps by cunning use of modulo
char message[300];
size_t len = snprintf(message, 299, "%20s %s\n",
ctime(&(ringlog[i % RINGLOG_SIZE].timestamp)),
ringlog[i % RINGLOG_SIZE].message);
write(fh, message, len);
}
XplMutexUnlock(ringlog_lock);
}
void
RinglogDumpConsole()
{
// hope we still have STDOUT around?!
RinglogDumpFilehandle(1);
}
+21 -3
View File
@@ -188,7 +188,18 @@ int _NonAppCheckUnload(void)
static void
SignalHandler(int sigtype)
{
BongoAgentHandleSignal(&StoreAgent.agent, sigtype);
if (sigtype == SIGSEGV) {
char path[XPL_MAX_PATH + 1];
int boomfile;
snprintf(path, XPL_MAX_PATH, "%s/store-ringlog-%d", XPL_DEFAULT_WORK_DIR, (int)time(NULL));
boomfile = open(path, O_CREAT | O_WRONLY);
if (boomfile != -1) {
RinglogDumpFilehandle(boomfile);
close(boomfile);
}
}
BongoAgentHandleSignal(&StoreAgent.agent, sigtype);
}
@@ -207,6 +218,8 @@ _XplServiceMain(int argc, char *argv[])
int startupOpts;
LogStart();
RinglogInit();
Ringlog("Started store daemon");
if (XplSetEffectiveUser(MsgGetUnprivilegedUser()) < 0) {
Log(LOG_ERROR, "Could not drop to unprivileged user '%s'", MsgGetUnprivilegedUser());
@@ -229,7 +242,9 @@ _XplServiceMain(int argc, char *argv[])
Log(LOG_FATAL, "Couldn't initialize Bongo libraries");
return -1;
}
Ringlog("Initialising libraries");
MsgInit();
cal_success = BongoCalInit(MsgGetDir(MSGAPI_DIR_DBF, NULL, 0));
@@ -263,7 +278,7 @@ _XplServiceMain(int argc, char *argv[])
}
/* Create a thread pool for managing connections */
Ringlog("Initialising threads");
BongoQueueAgentGetThreadPoolParameters (&StoreAgent.agent, &minThreads,
&maxThreads, &minSleep);
@@ -298,12 +313,15 @@ _XplServiceMain(int argc, char *argv[])
/* Start the server thread */
MsgSetRecoveryFlag("store");
Ringlog("Starting main thread");
XplStartMainThread(AGENT_NAME, &id, StoreServer, 8192, NULL, ccode);
Ringlog("Stopping main thread");
XplUnloadApp(XplGetThreadID());
MsgClearRecoveryFlag("store");
g_mime_shutdown();
Ringlog("Shutdown complete");
return 0;
}
+6
View File
@@ -412,6 +412,12 @@ int MimeGetGuid(StoreClient *client, uint64_t guid, MimeReport **outReport);
/** config.c **/
BOOL StoreAgentReadConfiguration(BOOL *recover);
/** ringlog.c **/
void RinglogInit();
void Ringlog(char *message);
void RinglogDumpConsole();
void RinglogDumpFilehandle(int fh);
/** locking.c **/
typedef enum {
LLOCK_NONE,