Commit cd5bf4d7 authored by Geoff Simmons's avatar Geoff Simmons

trackrdrd code reorg:

	- child process in child.c (including hashing code)
	- common signal handlers in handler.c
	- other code common to parent and child in trackrdrd.h & config.c
parent 644b0b5c
......@@ -10,7 +10,6 @@ trackrdrd_SOURCES = \
parse.c \
log.c \
config.c \
hash.c \
data.c \
monitor.c \
mq.c \
......@@ -18,7 +17,9 @@ trackrdrd_SOURCES = \
activemq/amq.cpp \
spmcq.c \
worker.c \
sandbox.c
sandbox.c \
child.c \
handler.c
trackrdrd_LDADD = \
$(VARNISHSRC)/lib/libvarnishcompat/libvarnishcompat.la \
......
......@@ -290,6 +290,20 @@ CONF_ReadFile(const char *file) {
return(0);
}
/* XXX: stdout is /dev/null in child process */
int
CONF_ReadDefault(void)
{
if (access(DEFAULT_CONFIG, F_OK) == 0) {
if (access(DEFAULT_CONFIG, R_OK) != 0)
return(errno);
printf("Reading config from %s\n", DEFAULT_CONFIG);
if (CONF_ReadFile(DEFAULT_CONFIG) != 0)
return -1;
}
return 0;
}
#define confdump(str,val) \
LOG_Log(LOG_DEBUG, "config: " str, (val))
......
......@@ -29,21 +29,25 @@
*
*/
PARENT(SIGTERM, terminate_action);
PARENT(SIGINT, terminate_action);
PARENT(SIGHUP, restart_action);
PARENT(SIGUSR1, restart_action);
PARENT(SIGUSR2, ignore_action);
PARENT(SIGHUP, restart_action);
#ifndef DISABLE_STACKTRACE
PARENT(SIGABRT, stacktrace_action);
PARENT(SIGSEGV, stacktrace_action);
PARENT(SIGBUS, stacktrace_action);
#endif
CHILD(SIGTERM, terminate_action);
CHILD(SIGINT, terminate_action);
CHILD(SIGUSR1, dump_action);
CHILD(SIGUSR2, ignore_action);
CHILD(SIGHUP, ignore_action);
#ifndef DISABLE_STACKTRACE
CHILD(SIGABRT, stacktrace_action);
CHILD(SIGSEGV, stacktrace_action);
CHILD(SIGBUS, stacktrace_action);
#endif
This diff is collapsed.
......@@ -35,11 +35,36 @@
#include <pthread.h>
#include <sys/types.h>
#include <time.h>
#include <signal.h>
#include "vqueue.h"
#include "varnishapi.h"
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) < (y) ? (y) : (x))
/* handler.c */
/* Hack, because we cannot have #ifdef in the macro definition SIGDISP */
#define _UNDEFINED(SIG) ((#SIG)[0] == 0)
#define UNDEFINED(SIG) _UNDEFINED(SIG)
#define SIGDISP(SIG, action) \
do { if (UNDEFINED(SIG)) break; \
if (sigaction((SIG), (&action), NULL) != 0) \
LOG_Log(LOG_ALERT, \
"Cannot install handler for " #SIG ": %s", \
strerror(errno)); \
} while(0)
volatile sig_atomic_t term;
struct sigaction terminate_action, ignore_action, stacktrace_action,
default_action;
void HNDL_Abort(int sig);
void HNDL_Terminate(int sig);
/* sandbox.c */
void PRIV_Sandbox(void);
......@@ -63,12 +88,12 @@ void WRK_Shutdown(void);
/* Single producer multiple consumer bounded FIFO queue */
typedef struct {
unsigned magic;
unsigned magic;
#define SPMCQ_MAGIC 0xe9a5d0a8
const unsigned mask;
void **data;
volatile unsigned head;
volatile unsigned tail;
const unsigned mask;
void **data;
volatile unsigned head;
volatile unsigned tail;
} spmcq_t;
spmcq_t spmcq;
......@@ -80,14 +105,14 @@ bool SPMCQ_NeedWorker(int running);
bool SPMCQ_StopWorker(int running);
#define spmcq_wait(what) \
do { \
do { \
AZ(pthread_mutex_lock(&spmcq_##what##waiter_lock)); \
spmcq_##what##waiter++; \
AZ(pthread_cond_wait(&spmcq_##what##waiter_cond, \
&spmcq_##what##waiter_lock)); \
spmcq_##what##waiter--; \
AZ(pthread_mutex_unlock(&spmcq_##what##waiter_lock)); \
} while (0)
spmcq_##what##waiter++; \
AZ(pthread_cond_wait(&spmcq_##what##waiter_cond, \
&spmcq_##what##waiter_lock)); \
spmcq_##what##waiter--; \
AZ(pthread_mutex_unlock(&spmcq_##what##waiter_lock)); \
} while (0)
/*
* the first test is not synced, so we might enter the if body too late or
......@@ -98,14 +123,14 @@ bool SPMCQ_StopWorker(int running);
*/
#define spmcq_signal(what) \
do { \
if (spmcq_##what##waiter) { \
AZ(pthread_mutex_lock(&spmcq_##what##waiter_lock)); \
if (spmcq_##what##waiter) \
AZ(pthread_cond_signal(&spmcq_##what##waiter_cond)); \
AZ(pthread_mutex_unlock(&spmcq_##what##waiter_lock)); \
} \
} while (0)
do { \
if (spmcq_##what##waiter) { \
AZ(pthread_mutex_lock(&spmcq_##what##waiter_lock)); \
if (spmcq_##what##waiter) \
AZ(pthread_cond_signal(&spmcq_##what##waiter_cond)); \
AZ(pthread_mutex_unlock(&spmcq_##what##waiter_lock)); \
} \
} while (0)
/* Producer waits for this condition when the spmc queue is full.
Consumers signal this condition after dequeue. */
......@@ -206,88 +231,17 @@ void DATA_Dump1(dataentry *entry, int i);
void DATA_Dump(void);
/* trackrdrd.c */
void HASH_Stats(void);
#if 0
typedef enum {
HASH_EMPTY = 0,
/* OPEN when the main thread is filling data, ReqEnd not yet seen. */
HASH_OPEN
/* hashes become HASH_EMPTY for DATA_DONE */
} hash_state_e;
struct hashentry_s {
unsigned magic;
#define HASH_MAGIC 0xf8e12130
/* set in HASH_Insert */
hash_state_e state;
unsigned xid; /* == de->xid */
float insert_time;
VTAILQ_ENTRY(hashentry_s) insert_list;
dataentry *de;
};
typedef struct hashentry_s hashentry;
VTAILQ_HEAD(insert_head_s, hashentry_s);
struct hashtable_s {
unsigned magic;
#define HASHTABLE_MAGIC 0x89ea1d00
unsigned len;
hashentry *entry;
struct insert_head_s insert_head;
/* config */
unsigned max_probes;
float ttl; /* max age for a record */
float mlt; /* min life time */
/* == stats == */
unsigned seen; /* Records (ReqStarts) seen */
/*
* records we have dropped because of no hash, no data
* or no entry
*/
unsigned drop_reqstart;
unsigned drop_vcl_log;
unsigned drop_reqend;
unsigned expired;
unsigned evacuated;
unsigned open;
unsigned collisions;
unsigned insert_probes;
unsigned find_probes;
unsigned fail; /* failed to get record - no space */
unsigned occ_hi; /* Occupancy high water mark */
unsigned occ_hi_this; /* Occupancy high water mark this reporting interval*/
};
typedef struct hashtable_s hashtable;
hashtable htbl;
int HASH_Init(void);
void HASH_Exp(float limit);
void HASH_Submit(hashentry *he);
void HASH_Evacuate(hashentry *he);
hashentry *HASH_Insert(const unsigned xid, dataentry *de, const float t);
hashentry *HASH_Find(unsigned xid);
void HASH_Dump1(hashentry *entry, int i);
void HASH_Dump(void);
#endif
/* child.c */
void CHILD_Main(struct VSM_data *vd, int endless, int readconfig);
/* config.c */
#define EMPTY(s) (s[0] == '\0')
#define DEFAULT_CONFIG "/etc/trackrdrd.conf"
char cli_config_filename[BUFSIZ];
struct config {
char pid_file[BUFSIZ];
char varnish_name[BUFSIZ];
......@@ -357,6 +311,7 @@ struct config {
void CONF_Init(void);
int CONF_Add(const char *lval, const char *rval);
int CONF_ReadFile(const char *file);
int CONF_ReadDefault(void);
void CONF_Dump(void);
/* log.c */
......@@ -409,6 +364,3 @@ int Parse_VCL_Log(const char *ptr, int len, unsigned *xid,
/* generic init attributes */
pthread_mutexattr_t attr_lock;
pthread_condattr_t attr_cond;
/* globals */
extern int nworkers;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment