Commit b007a32d authored by Geoff Simmons's avatar Geoff Simmons

trackrdrd: Added assert.c, removed some code duplication

parent 077cf989
...@@ -19,7 +19,8 @@ trackrdrd_SOURCES = \ ...@@ -19,7 +19,8 @@ trackrdrd_SOURCES = \
worker.c \ worker.c \
sandbox.c \ sandbox.c \
child.c \ child.c \
handler.c handler.c \
assert.c
trackrdrd_LDADD = \ trackrdrd_LDADD = \
$(VARNISHSRC)/lib/libvarnishcompat/libvarnishcompat.la \ $(VARNISHSRC)/lib/libvarnishcompat/libvarnishcompat.la \
......
/*-
* Copyright (c) 2012 UPLEX Nils Goroll Systemoptimierung
* Copyright (c) 2012 Otto Gmbh & Co KG
* All rights reserved
* Use only with permission
*
* Authors: Geoffrey Simmons <geoffrey.simmons@uplex.de>
* Nils Goroll <nils.goroll@uplex.de>
*
* Portions adopted from varnishlog.c from the Varnish project
* Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
* Copyright (c) 2006 Verdens Gang AS
* Copyright (c) 2006-2011 Varnish Software AS
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include "trackrdrd.h"
void
ASRT_Fail(const char *func, const char *file, int line, const char *cond,
int err, int xxx)
{
(void) xxx;
LOG_Log(LOG_ALERT, "Condition (%s) failed in %s(), %s line %d",
cond, func, file, line);
if (err)
LOG_Log(LOG_ALERT, "errno = %d (%s)", err, strerror(err));
abort();
}
...@@ -136,7 +136,7 @@ struct hashtable_s { ...@@ -136,7 +136,7 @@ struct hashtable_s {
unsigned occ_hi; /* Occupancy high water mark */ unsigned occ_hi; /* Occupancy high water mark */
unsigned occ_hi_this; /* Occupancy high water mark this reporting unsigned occ_hi_this; /* Occupancy high water mark this reporting
interval*/ interval */
}; };
typedef struct hashtable_s hashtable; typedef struct hashtable_s hashtable;
...@@ -153,9 +153,6 @@ static hashtable htbl; ...@@ -153,9 +153,6 @@ static hashtable htbl;
errno, 0); \ errno, 0); \
} while (0) } while (0)
static void assert_failure(const char *func, const char *file, int line,
const char *cond, int err, int xxx);
static void static void
entry_assert_failure(const char *func, const char *file, int line, entry_assert_failure(const char *func, const char *file, int line,
const char *cond, hashentry *he, int err, int xxx) const char *cond, hashentry *he, int err, int xxx)
...@@ -170,25 +167,12 @@ entry_assert_failure(const char *func, const char *file, int line, ...@@ -170,25 +167,12 @@ entry_assert_failure(const char *func, const char *file, int line,
(de), (de)->magic, (de)->state, (de)->xid, (de)->tid, (de)->end); (de), (de)->magic, (de)->state, (de)->xid, (de)->tid, (de)->end);
else else
LOG_Log(LOG_ALERT, "Dataentry %p NULL!", (de)); LOG_Log(LOG_ALERT, "Dataentry %p NULL!", (de));
assert_failure(func, file, line, cond, err, xxx); ASRT_Fail(func, file, line, cond, err, xxx);
} }
#endif #endif
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
static void
assert_failure(const char *func, const char *file, int line, const char *cond,
int err, int xxx)
{
(void) xxx;
LOG_Log(LOG_ALERT, "Condition (%s) failed in %s(), %s line %d",
cond, func, file, line);
if (err)
LOG_Log(LOG_ALERT, "errno = %d (%s)", err, strerror(err));
abort();
}
static inline void static inline void
check_entry(hashentry *he, unsigned xid, unsigned tid) check_entry(hashentry *he, unsigned xid, unsigned tid)
{ {
......
...@@ -72,18 +72,6 @@ ...@@ -72,18 +72,6 @@
#include "revision.h" #include "revision.h"
#include "usage.h" #include "usage.h"
/* 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)
static volatile sig_atomic_t reload; static volatile sig_atomic_t reload;
static struct sigaction restart_action; static struct sigaction restart_action;
...@@ -97,19 +85,6 @@ restart(int sig) ...@@ -97,19 +85,6 @@ restart(int sig)
reload = 1; reload = 1;
} }
static void
assert_failure(const char *func, const char *file, int line, const char *cond,
int err, int xxx)
{
(void) xxx;
LOG_Log(LOG_ALERT, "Condition (%s) failed in %s(), %s line %d",
cond, func, file, line);
if (err)
LOG_Log(LOG_ALERT, "errno = %d (%s)", err, strerror(err));
abort();
}
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
/* Handle for the PID file */ /* Handle for the PID file */
...@@ -166,7 +141,11 @@ parent_main(pid_t child_pid, struct VSM_data *vd, int endless) ...@@ -166,7 +141,11 @@ parent_main(pid_t child_pid, struct VSM_data *vd, int endless)
pid_t wpid; pid_t wpid;
LOG_Log0(LOG_INFO, "Management process starting"); LOG_Log0(LOG_INFO, "Management process starting");
restart_action.sa_handler = restart;
AZ(sigemptyset(&restart_action.sa_mask));
restart_action.sa_flags &= ~SA_RESTART;
term = 0; term = 0;
reload = 0; reload = 0;
/* install signal handlers */ /* install signal handlers */
...@@ -340,7 +319,7 @@ main(int argc, char * const *argv) ...@@ -340,7 +319,7 @@ main(int argc, char * const *argv)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
VAS_Fail = assert_failure; VAS_Fail = ASRT_Fail;
if (d_flag) if (d_flag)
LOG_SetLevel(LOG_DEBUG); LOG_SetLevel(LOG_DEBUG);
...@@ -370,10 +349,6 @@ main(int argc, char * const *argv) ...@@ -370,10 +349,6 @@ main(int argc, char * const *argv)
AZ(sigemptyset(&terminate_action.sa_mask)); AZ(sigemptyset(&terminate_action.sa_mask));
terminate_action.sa_flags &= ~SA_RESTART; terminate_action.sa_flags &= ~SA_RESTART;
restart_action.sa_handler = restart;
AZ(sigemptyset(&restart_action.sa_mask));
restart_action.sa_flags &= ~SA_RESTART;
stacktrace_action.sa_handler = HNDL_Abort; stacktrace_action.sa_handler = HNDL_Abort;
ignore_action.sa_handler = SIG_IGN; ignore_action.sa_handler = SIG_IGN;
......
...@@ -43,6 +43,11 @@ ...@@ -43,6 +43,11 @@
#define MIN(x, y) ((x) < (y) ? (x) : (y)) #define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) < (y) ? (y) : (x)) #define MAX(x, y) ((x) < (y) ? (y) : (x))
/* assert.c */
void ASRT_Fail(const char *func, const char *file, int line, const char *cond,
int err, int xxx);
/* handler.c */ /* handler.c */
/* Hack, because we cannot have #ifdef in the macro definition SIGDISP */ /* Hack, because we cannot have #ifdef in the macro definition SIGDISP */
......
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