|
From: <jsa...@us...> - 2008-06-02 23:36:32
|
Revision: 1250
http://como.svn.sourceforge.net/como/?rev=1250&view=rev
Author: jsanjuas
Date: 2008-06-02 16:36:26 -0700 (Mon, 02 Jun 2008)
Log Message:
-----------
. now data structures shall use standard malloc/free if passed a null allocator
. removing unnecessary alc_t's from several funcs of config and supervisor
. decoupling memory.c and shmem.c
. protecting define _GNU_SOURCEs with ifdefs
. reverting to clearer safe_* notation for safe_calloc and such
Modified Paths:
--------------
src/branches/2.0/base/CMakeLists.txt
src/branches/2.0/base/capture.c
src/branches/2.0/base/config-lexic.l
src/branches/2.0/base/config-syntax.y
src/branches/2.0/base/config.c
src/branches/2.0/base/export.c
src/branches/2.0/base/filter-lexic.l
src/branches/2.0/base/filter-syntax.y
src/branches/2.0/base/metadesc.c
src/branches/2.0/base/ppbuf.c
src/branches/2.0/base/query-comms.c
src/branches/2.0/base/query-lexic.l
src/branches/2.0/base/query-ondemand.c
src/branches/2.0/base/query-syntax.y
src/branches/2.0/base/query.c
src/branches/2.0/base/storage.c
src/branches/2.0/base/supervisor.c
src/branches/2.0/base/util-timers.c
src/branches/2.0/include/comofunc.h
src/branches/2.0/include/comopriv.h
src/branches/2.0/include/os.h
src/branches/2.0/lib/bitmap.c
src/branches/2.0/lib/flowtable.c
src/branches/2.0/lib/heap.c
src/branches/2.0/libcomo/array.c
src/branches/2.0/libcomo/como.c
src/branches/2.0/libcomo/hash.c
src/branches/2.0/libcomo/ipc.c
src/branches/2.0/libcomo/log.c
src/branches/2.0/libcomo/memory.c
src/branches/2.0/libcomo/shmem.c
src/branches/2.0/libcomo/shobj.c
src/branches/2.0/libcomo/socket.c
src/branches/2.0/libcomo/storage-client.c
src/branches/2.0/loadshed/feats.c
src/branches/2.0/loadshed/loadshed.c
src/branches/2.0/loadshed/ls-profiling.c
src/branches/2.0/misc/gen-csclass.c
src/branches/2.0/misc/gen-csglue.c
src/branches/2.0/misc/gen-serial.c
src/branches/2.0/misc/structmagic.c
src/branches/2.0/mono/proxy-mono.c
src/branches/2.0/services/status.c
src/branches/2.0/sniffers/sniffer-como.c
src/branches/2.0/sniffers/sniffer-flowtools.c
src/branches/2.0/sniffers/sniffer-netflow.c
Modified: src/branches/2.0/base/CMakeLists.txt
===================================================================
--- src/branches/2.0/base/CMakeLists.txt 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/CMakeLists.txt 2008-06-02 23:36:26 UTC (rev 1250)
@@ -244,6 +244,8 @@
TARGET_LINK_LIBRARIES(como ${MONO_LIBS})
ENDIF(MONO_FOUND)
+TARGET_LINK_LIBRARIES(como ${APR_LIBS})
+
#
# Installation
#
Modified: src/branches/2.0/base/capture.c
===================================================================
--- src/branches/2.0/base/capture.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/capture.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -179,7 +179,7 @@
if (size < i) {
size = i;
- which = como_realloc(which, i);
+ which = safe_realloc(which, i);
}
bzero(which, i);
@@ -300,7 +300,7 @@
ntuples++;
}
- msg = como_malloc(sz + sizeof(msg_process_ser_tuples_t));
+ msg = safe_malloc(sz + sizeof(msg_process_ser_tuples_t));
strcpy(msg->mdl_name, mdl->name);
msg->ntuples = ntuples;
msg->tuple_mem = ic->tuple_mem;
@@ -909,7 +909,7 @@
cl = como_new0(cabuf_cl_t);
cl->peer = peer;
cl->ref_mask = (1LL << (uint64_t) (id + 1)); /* id 0 -> mask 2 */
- cl->sniff_usage = como_calloc(como_ca->sniffers_count , sizeof(float));
+ cl->sniff_usage = safe_calloc(como_ca->sniffers_count , sizeof(float));
cl->sampling = alc_new0(&como_ca->shalc, int); /* sampling rate is kept
into shared memory */
@@ -1756,7 +1756,7 @@
}
- como_ca.first_ref_pkts = como_calloc(sizeof(void *),
+ como_ca.first_ref_pkts = safe_calloc(sizeof(void *),
(max_sniffer_id + 1));
/* initialize the capture buffer */
Modified: src/branches/2.0/base/config-lexic.l
===================================================================
--- src/branches/2.0/base/config-lexic.l 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/config-lexic.l 2008-06-02 23:36:26 UTC (rev 1250)
@@ -83,7 +83,7 @@
if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
error("reading cfg: imports nested too deeply\n");
- str = como_strdup(yytext + 1); /* remove "s */
+ str = safe_strdup(yytext + 1); /* remove "s */
str[strlen(str) - 1] = '\0';
include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
@@ -164,7 +164,7 @@
}
\"[^"]*\" { /* string literal */
- yclval.string = como_strdup(yytext + 1);
+ yclval.string = safe_strdup(yytext + 1);
yclval.string[strlen(yclval.string) - 1] = '\0';
dbg_return(TOK_STRING);
}
Modified: src/branches/2.0/base/config-syntax.y
===================================================================
--- src/branches/2.0/base/config-syntax.y 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/config-syntax.y 2008-06-02 23:36:26 UTC (rev 1250)
@@ -66,7 +66,6 @@
void config_lexic_init();
/* global variables */
-alc_t *alc;
static mdl_def_t mdl;
static virtual_node_def_t vnode;
static como_config_t *cfg; /* result */
@@ -139,11 +138,11 @@
virtual_node_def:
TOK_VIRTUAL_NODE TOK_STRING
{
- initialize_virtual_node_def(&vnode, alc);
+ initialize_virtual_node_def(&vnode);
vnode.name = $2;
}
virtual_node_keywords
- TOK_END { define_virtual_node(&vnode, cfg, alc); }
+ TOK_END { define_virtual_node(&vnode, cfg); }
;
virtual_node_keywords:
@@ -171,7 +170,7 @@
;
module_def: /* beware: actions in mid-rule */
- TOK_MODULE { initialize_module_def(&mdl, alc); }
+ TOK_MODULE { initialize_module_def(&mdl); }
TOK_STRING { mdl.name = $3; }
optional_module_keywords
TOK_END { define_module(&mdl, cfg); }
@@ -242,28 +241,28 @@
r = stat(path, &st);
if (r != 0) {
warn(GFC_ERROR_STR, path);
- return como_strdup("");
+ return safe_strdup("");
}
fd = open(path, O_RDONLY);
if (fd < 0) {
warn(GFC_ERROR_STR, path);
- return como_strdup("");
+ return safe_strdup("");
}
- buffer = como_malloc(st.st_size);
+ buffer = safe_malloc(st.st_size);
r = como_read(fd, buffer, st.st_size);
if (r != st.st_size) {
free(buffer);
warn(GFC_ERROR_STR, path);
- return como_strdup("");
+ return safe_strdup("");
}
r = close(fd);
if (r < 0) {
free(buffer);
warn(GFC_ERROR_STR, path);
- return como_strdup("");
+ return safe_strdup("");
}
return buffer;
}
@@ -282,7 +281,7 @@
}
como_config_t *
-parse_config_file(char *f, alc_t *my_alc, como_config_t *my_cfg)
+parse_config_file(char *f, como_config_t *my_cfg)
{
mode = PARSING_FILE;
what = f;
@@ -290,7 +289,6 @@
config_lexic_init();
cfg = my_cfg;
- alc = my_alc;
ycin = fopen(f, "r");
if (ycin == NULL)
@@ -301,7 +299,7 @@
}
como_config_t *
-parse_config_string(char *str, alc_t *my_alc, como_config_t *my_cfg)
+parse_config_string(char *str, como_config_t *my_cfg)
{
void *buffer;
@@ -311,7 +309,6 @@
config_lexic_init();
cfg = my_cfg;
- alc = my_alc;
buffer = yc_scan_string(str);
ycparse();
Modified: src/branches/2.0/base/config.c
===================================================================
--- src/branches/2.0/base/config.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/config.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -64,35 +64,34 @@
* values.
*/
void
-initialize_module_def(mdl_def_t *mdl, alc_t *alc)
+initialize_module_def(mdl_def_t *mdl)
{
bzero(mdl, sizeof(mdl_def_t));
- mdl->args = hash_new(alc, HASHKEYS_STRING, NULL, NULL);
+ mdl->args = hash_new(NULL, HASHKEYS_STRING, NULL, NULL);
mdl->streamsize = 128 * 1024 * 1024;
- mdl->filter = como_strdup("all");
+ mdl->filter = safe_strdup("all");
#ifdef LOADSHED
mdl->minimum_srate = 0;
#endif
}
static void
-destroy_sniffer_def(sniffer_def_t *d, alc_t *alc)
+destroy_sniffer_def(sniffer_def_t *d)
{
- alc_free(alc, d->name);
- alc_free(alc, d->device);
+ free(d->name);
+ free(d->device);
if (d->args)
- alc_free(alc, d->args);
+ free(d->args);
}
void
-initialize_virtual_node_def(virtual_node_def_t *vnode, UNUSED alc_t *alc)
+initialize_virtual_node_def(virtual_node_def_t *vnode)
{
bzero(vnode, sizeof(virtual_node_def_t));
}
void
-define_virtual_node(virtual_node_def_t *vnode, UNUSED como_config_t *cfg,
- alc_t *alc)
+define_virtual_node(virtual_node_def_t *vnode, UNUSED como_config_t *cfg)
{
int ok = 1;
@@ -125,7 +124,7 @@
/* if not ok, output error notice and return */
if (ok == 0) {
warn("(ignoring virtual node definition)\n");
- destroy_virtual_node_def(vnode, alc);
+ destroy_virtual_node_def(vnode);
return;
}
@@ -134,41 +133,41 @@
}
void
-destroy_virtual_node_def(virtual_node_def_t *vnode, alc_t *alc)
+destroy_virtual_node_def(virtual_node_def_t *vnode)
{
- alc_free(alc, vnode->name);
- alc_free(alc, vnode->location);
- alc_free(alc, vnode->type);
- alc_free(alc, vnode->filter);
- alc_free(alc, vnode->source);
+ free(vnode->name);
+ free(vnode->location);
+ free(vnode->type);
+ free(vnode->filter);
+ free(vnode->source);
}
static void
-free_hash_entries(hash_t *h, alc_t *alc)
+free_hash_entries(hash_t *h)
{
hash_iter_t it;
hash_iter_init(h, &it); /* destroy the args */
while(hash_iter_next(&it)) {
- alc_free(alc, (void *)hash_iter_get_string_key(&it));
- alc_free(alc, (void *)hash_iter_get_value(&it));
+ free((void *)hash_iter_get_string_key(&it));
+ free((void *)hash_iter_get_value(&it));
hash_iter_remove_entry(&it);
}
}
static void
-destroy_module_def(mdl_def_t *d, alc_t *alc)
+destroy_module_def(mdl_def_t *d)
{
- free_hash_entries(d->args, alc);
+ free_hash_entries(d->args);
hash_destroy(d->args);
- alc_free(alc, d->name);
- alc_free(alc, d->mdlname);
- alc_free(alc, d->output);
- alc_free(alc, d->filter);
- alc_free(alc, d->descr);
+ free(d->name);
+ free(d->mdlname);
+ free(d->output);
+ free(d->filter);
+ free(d->descr);
#ifdef LOADSHED
- alc_free(alc, d->shed_method);
+ free(d->shed_method);
#endif
}
@@ -181,14 +180,14 @@
define_module(mdl_def_t *mdl, como_config_t *cfg)
{
if (mdl->output == NULL)
- mdl->output = como_strdup(mdl->name);
+ mdl->output = safe_strdup(mdl->name);
if (mdl->mdlname == NULL)
- mdl->mdlname = como_strdup(mdl->name);
+ mdl->mdlname = safe_strdup(mdl->name);
if (mdl->descr == NULL)
- mdl->descr = como_strdup("");
+ mdl->descr = safe_strdup("");
#ifdef LOADSHED
if (mdl->shed_method == NULL)
- mdl->shed_method = como_strdup("");
+ mdl->shed_method = safe_strdup("");
#endif
array_add(cfg->mdl_defs, mdl);
@@ -323,7 +322,7 @@
* Parse the command line and config files.
*/
como_config_t *
-configure(int argc, char **argv, alc_t *alc, como_config_t *cfg)
+configure(int argc, char **argv, como_config_t *cfg)
{
static const char *opts = "hi:St:q:c:C:D:L:p:m:vx:s:e";
int i, c, cfg_item_count = 0;
@@ -335,18 +334,18 @@
cfg->sniffer_defs = array_new(sizeof(sniffer_def_t));
cfg->vnode_defs = array_new(sizeof(virtual_node_def_t));
- cfg->como_executable_full_path = como_strdup(argv[0]);
+ cfg->como_executable_full_path = safe_strdup(argv[0]);
/*
* set some defaults
*/
cfg->query_port = 44444;
set_memsize(B2MB(64), cfg);
- cfg->db_path = como_strdup(DEFAULT_DBDIR);
+ cfg->db_path = safe_strdup(DEFAULT_DBDIR);
cfg->filesize = 128 * 1024 * 1024;
- cfg->libdir = como_strdup(DEFAULT_LIBDIR);
- cfg->query_args = hash_new(alc, HASHKEYS_STRING, NULL, NULL);
- cfg->query_alias = hash_new(alc, HASHKEYS_STRING, NULL, NULL);
+ cfg->libdir = safe_strdup(DEFAULT_LIBDIR);
+ cfg->query_args = hash_new(NULL, HASHKEYS_STRING, NULL, NULL);
+ cfg->query_alias = hash_new(NULL, HASHKEYS_STRING, NULL, NULL);
optind = 1; /* force getopt to start from 1st arg */
@@ -377,11 +376,11 @@
break;
case 'D': /* db-path */
- cfg->db_path = como_strdup(optarg);
+ cfg->db_path = safe_strdup(optarg);
break;
case 'L': /* libdir */
- cfg->libdir = como_strdup(optarg);
+ cfg->libdir = safe_strdup(optarg);
break;
case 'p':
@@ -392,9 +391,9 @@
{
char *name, *device, *args;
- name = como_strdup(strtok(optarg, ","));
- device = como_strdup(strtok(NULL, ","));
- args = como_strdup(strtok(NULL, ""));
+ name = safe_strdup(strtok(optarg, ","));
+ device = safe_strdup(strtok(NULL, ","));
+ args = safe_strdup(strtok(NULL, ""));
if (name && device)
define_sniffer(name, device, args, cfg);
@@ -419,7 +418,7 @@
case 'i': /* run inline: also silent & exit when done */
cfg->inline_mode = 1;
- cfg->inline_module = como_strdup(optarg);
+ cfg->inline_module = safe_strdup(optarg);
cfg->silent_mode = 1;
cfg->exit_when_done = 1;
break;
@@ -430,7 +429,7 @@
case 'q': { /* query args for inline mode */
char *str, *strbak;
- strbak = str = como_strdup(optarg);
+ strbak = str = safe_strdup(optarg);
while (str != NULL) {
char *k, *v;
@@ -451,8 +450,8 @@
str = s2 + 1;
}
- hash_insert_string(cfg->query_args, como_strdup(k),
- como_strdup(v));
+ hash_insert_string(cfg->query_args, safe_strdup(k),
+ safe_strdup(v));
}
free(strbak);
@@ -460,7 +459,7 @@
}
case 't': /* path to storage */
- cfg->storage_path = como_strdup(optarg);
+ cfg->storage_path = safe_strdup(optarg);
break;
case '?': /* unknown */
@@ -489,10 +488,10 @@
for (i = 0; i < cfg_item_count; i++) { /* parse config items here */
switch (cfg_items[i].type) {
case CFG_ITEM_FILE:
- parse_config_file(cfg_items[i].info, alc, cfg);
+ parse_config_file(cfg_items[i].info, cfg);
break;
case CFG_ITEM_STRING:
- parse_config_string(cfg_items[i].info, alc, cfg);
+ parse_config_string(cfg_items[i].info, cfg);
break;
}
}
@@ -503,7 +502,7 @@
bzero(&mdl, sizeof(mdl));
- buf = como_strdup(argv[optind]);
+ buf = safe_strdup(argv[optind]);
s = strchr(buf, ':');
if (s != NULL) {
@@ -511,8 +510,8 @@
args = s + 1;
}
- initialize_module_def(&mdl, alc);
- mdl.name = como_strdup(buf);
+ initialize_module_def(&mdl);
+ mdl.name = safe_strdup(buf);
while (args != NULL) { /* parse the arguments */
char *s1, *s2;
@@ -529,8 +528,8 @@
if (s2 != NULL)
*s2 = '\0'; /* null-terminate value */
- hash_insert_string(mdl.args, como_strdup(args),
- como_strdup(s1 + 1));
+ hash_insert_string(mdl.args, safe_strdup(args),
+ safe_strdup(s1 + 1));
if (s2)
args = s2 + 1;
@@ -635,24 +634,24 @@
* Free a configuration.
*/
void
-destroy_config(como_config_t *cfg, alc_t *alc)
+destroy_config(como_config_t *cfg)
{
int i;
for (i = 0; i < cfg->sniffer_defs->len; i++) { /* free sniff defs */
sniffer_def_t *def = &array_at(cfg->sniffer_defs, sniffer_def_t, i);
- destroy_sniffer_def(def, alc);
+ destroy_sniffer_def(def);
}
for (i = 0; i < cfg->mdl_defs->len; i++) { /* free mdl defs */
mdl_def_t *def = &array_at(cfg->mdl_defs, mdl_def_t, i);
- destroy_module_def(def, alc);
+ destroy_module_def(def);
}
for (i = 0; i < cfg->vnode_defs->len; i++) { /* free vnode defs */
virtual_node_def_t *def = &array_at(cfg->vnode_defs,
virtual_node_def_t, i);
- destroy_virtual_node_def(def, alc);
+ destroy_virtual_node_def(def);
}
array_free(cfg->sniffer_defs, 1); /* free the arrays themselves */
@@ -672,9 +671,9 @@
free(cfg->inline_module);
- free_hash_entries(cfg->query_args, alc);
+ free_hash_entries(cfg->query_args);
hash_destroy(cfg->query_args);
- free_hash_entries(cfg->query_alias, alc);
+ free_hash_entries(cfg->query_alias);
hash_destroy(cfg->query_alias);
}
Modified: src/branches/2.0/base/export.c
===================================================================
--- src/branches/2.0/base/export.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/export.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -145,7 +145,7 @@
/*
* open output file
*/
- str = como_asprintf("%s/%s", como_ex->st_dir, mdl->name);
+ str = safe_asprintf("%s/%s", como_ex->st_dir, mdl->name);
ie->cs_writer = csopen(str, CS_WRITER, (off_t) mdl->streamsize,
(ipc_peer_t *) COMO_ST);
if (ie->cs_writer < 0) {
@@ -254,7 +254,7 @@
debug("handle_ca_ex_process_shm_tuples -- recv'd %d tuples in shared mem\n",
msg->ntuples);
- tset = como_malloc(sizeof(tupleset_t));
+ tset = safe_malloc(sizeof(tupleset_t));
tset->tuples = msg->tuples;
tset->ntuples = msg->ntuples;
@@ -307,7 +307,7 @@
void **tuples;
size_t i;
- tuples = como_calloc(tset->ntuples, sizeof(void *));
+ tuples = safe_calloc(tset->ntuples, sizeof(void *));
debug("handle_ca_ex_process_shm_tuples -- building tuple array\n");
i = 0;
@@ -509,7 +509,7 @@
como_ex.mdls = hash_new(como_alc(), HASHKEYS_STRING, NULL, NULL);
tupleset_queue_init(&como_ex.queue);
- como_ex.st_dir = como_asprintf("%s/%s", como_config->db_path, node->name);
+ como_ex.st_dir = safe_asprintf("%s/%s", como_config->db_path, node->name);
#ifdef MONO_SUPPORT
/* initialize mono */
Modified: src/branches/2.0/base/filter-lexic.l
===================================================================
--- src/branches/2.0/base/filter-lexic.l 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/filter-lexic.l 2008-06-02 23:36:26 UTC (rev 1250)
@@ -114,12 +114,12 @@
}
{IPADDR} {
/* Copy the dots and numbers notation string */
- yflval.string = como_strdup(yytext);
+ yflval.string = safe_strdup(yytext);
dbg_return(IPADDR);
}
{MACADDR} {
/* Copy the dots and numbers notation string */
- yflval.string = como_strdup(yytext);
+ yflval.string = safe_strdup(yytext);
dbg_return(MACADDR);
}
{NETMASK} {
Modified: src/branches/2.0/base/filter-syntax.y
===================================================================
--- src/branches/2.0/base/filter-syntax.y 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/filter-syntax.y 2008-06-02 23:36:26 UTC (rev 1250)
@@ -221,7 +221,7 @@
char *
append_string(char *dest, char *src)
{
- dest = (char *)como_realloc(dest, strlen(dest) + strlen(src) + 1);
+ dest = (char *)safe_realloc(dest, strlen(dest) + strlen(src) + 1);
strcat(dest, src);
return dest;
}
@@ -238,11 +238,11 @@
{
treenode_t *t;
- t = (treenode_t *)como_malloc(sizeof(treenode_t));
+ t = (treenode_t *)safe_malloc(sizeof(treenode_t));
t->type = type;
if (t->type == Tpred) {
t->pred_type = pred_type;
- t->data = (nodedata_t *)como_malloc(sizeof(nodedata_t));
+ t->data = (nodedata_t *)safe_malloc(sizeof(nodedata_t));
switch(t->pred_type) {
case Tip:
asprintf(&(t->string), "%d ip %d/%d",
@@ -321,15 +321,15 @@
listnode_t *laux;
if (!list) {
- list = (listnode_t *)como_malloc(sizeof(listnode_t));
+ list = (listnode_t *)safe_malloc(sizeof(listnode_t));
list->next = NULL;
list->prev = NULL;
- list->string = como_strdup(s);
+ list->string = safe_strdup(s);
}
else {
if (strcmp(s, list->string) <= 0) {
- laux = (listnode_t *)como_malloc(sizeof(listnode_t));
- laux->string = como_strdup(s);
+ laux = (listnode_t *)safe_malloc(sizeof(listnode_t));
+ laux->string = safe_strdup(s);
laux->next = list;
laux->prev = list->prev;
list->prev = laux;
@@ -415,7 +415,7 @@
case Tand:
list = list_make(NULL, Tand, tree->left);
list = list_merge(list, list_make(NULL, Tand, tree->right));
- s = como_strdup("(");
+ s = safe_strdup("(");
for (laux = list; laux->next; laux = laux->next) {
s = append_string(s, laux->string);
s = append_string(s, " && ");
@@ -433,7 +433,7 @@
case Tor:
list = list_make(NULL, Tor, tree->left);
list = list_merge(list, list_make(NULL, Tor, tree->right));
- s = como_strdup("(");
+ s = safe_strdup("(");
for (laux = list; laux->next; laux = laux->next) {
s = append_string(s, laux->string);
s = append_string(s, " || ");
@@ -449,11 +449,11 @@
} while (laux);
break;
case Tnot:
- s = como_strdup("!");
+ s = safe_strdup("!");
s = append_string(s, tree_to_string(tree->left));
break;
case Tpred:
- s = como_strdup(tree->string);
+ s = safe_strdup(tree->string);
break;
}
Modified: src/branches/2.0/base/metadesc.c
===================================================================
--- src/branches/2.0/base/metadesc.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/metadesc.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -168,7 +168,7 @@
const headerinfo_t *hi;
layer_t l;
const char d[] = ":";
- char *protos_copy = como_strdup(protos);
+ char *protos_copy = safe_strdup(protos);
char *t, *s;
t = s = protos_copy;
@@ -475,7 +475,7 @@
for (outit = out; outit != NULL; outit = outit->_next) {
affinity = metadesc_try_match_pair(outit, init);
if (affinity > 0) {
- res = como_realloc(res, (matches_count + 1) *
+ res = safe_realloc(res, (matches_count + 1) *
sizeof(metadesc_match_t));
res[matches_count].in = init;
@@ -483,7 +483,7 @@
res[matches_count].affinity = affinity;
matches_count++;
} else {
- incomps = como_realloc(incomps, (incomps_count + 1) *
+ incomps = safe_realloc(incomps, (incomps_count + 1) *
sizeof(metadesc_incompatibility_t));
incomps[incomps_count].in = init;
incomps[incomps_count].out = outit;
@@ -562,7 +562,7 @@
layers[L2] = NULL;
for (l = L3; l <= L4; l++)
- layers[l] = como_calloc(md->_tpl_count, sizeof(int));
+ layers[l] = safe_calloc(md->_tpl_count, sizeof(int));
/*
* Iterate over the template list and keep the information of used
Modified: src/branches/2.0/base/ppbuf.c
===================================================================
--- src/branches/2.0/base/ppbuf.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/ppbuf.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -65,7 +65,7 @@
ppbuf = como_new0(ppbuf_t);
ppbuf->size = size;
- ppbuf->pp = como_calloc(size, sizeof(pkt_t *));
+ ppbuf->pp = safe_calloc(size, sizeof(pkt_t *));
ppbuf->id = sniff->priv->id;
ppbuf->sniffer = sniff;
Modified: src/branches/2.0/base/query-comms.c
===================================================================
--- src/branches/2.0/base/query-comms.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/query-comms.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -360,19 +360,19 @@
switch (*name) {
case 'm':
if_have_kw("module") {
- q->module = como_strdup(value);
+ q->module = safe_strdup(value);
insert_arg = FALSE;
}
break;
case 'f':
if_have_kw("filter") {
char *v = value[0] != '\0' ? value : "all";
- q->filter_str = como_strdup(v);
+ q->filter_str = safe_strdup(v);
parse_filter(v, NULL, &(q->filter_cmp));
insert_arg = FALSE;
}
else if_have_kw("format") {
- q->format = como_strdup(value);
+ q->format = safe_strdup(value);
insert_arg = FALSE;
}
break;
@@ -381,7 +381,7 @@
q->start = atoi(value);
insert_arg = FALSE;
} else if_have_kw("source") {
- q->source = como_strdup(value);
+ q->source = safe_strdup(value);
insert_arg = FALSE;
} else if_have_kw("status") {
q->mode = QMODE_SERVICE;
Modified: src/branches/2.0/base/query-lexic.l
===================================================================
--- src/branches/2.0/base/query-lexic.l 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/query-lexic.l 2008-06-02 23:36:26 UTC (rev 1250)
@@ -56,7 +56,7 @@
= { return TOK_EQUALS; }
" " { return TOK_SPACE; }
-{URICHAR}+ { yqlval.string = como_strdup(yytext); return TOK_STRING; }
+{URICHAR}+ { yqlval.string = safe_strdup(yytext); return TOK_STRING; }
.|\n
Modified: src/branches/2.0/base/query-ondemand.c
===================================================================
--- src/branches/2.0/base/query-ondemand.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/query-ondemand.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -68,7 +68,7 @@
if (input[i] == '\\' || input[i] == '"')
final_len++;
- output = como_malloc(final_len + 1);
+ output = safe_malloc(final_len + 1);
for (i = j = 0; i < s; i++) {
if (input[i] == '\\' || input[i] == '"')
@@ -125,7 +125,7 @@
if (req->filter_str == NULL)
req->filter_str = "all";
- buffer = como_malloc(10 * 1024);
+ buffer = safe_malloc(10 * 1024);
sprintf(buffer, "module \"%s\" source \"%s\" filter \"%s\"",
req->module, mdl_code, req->filter_str);
@@ -152,7 +152,7 @@
my_argv[i++] = "-i"; /* do an inline execution of the mdl */
- buffer = como_malloc(8 * 1024);
+ buffer = safe_malloc(8 * 1024);
sprintf(buffer, "%s?format=%s", req->module, req->format);
hash_iter_init(req->args, &it);
@@ -165,7 +165,7 @@
my_argv[i++] = buffer;
my_argv[i++] = "-s"; /* with the appropriate input sniffer */
- my_argv[i++] = como_asprintf("como,http://localhost:%d/%s"
+ my_argv[i++] = safe_asprintf("como,http://localhost:%d/%s"
"?format=como&start=%d&end=%d&wait=%s",
como_config->query_port,
req->source,
Modified: src/branches/2.0/base/query-syntax.y
===================================================================
--- src/branches/2.0/base/query-syntax.y 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/query-syntax.y 2008-06-02 23:36:26 UTC (rev 1250)
@@ -100,17 +100,17 @@
fullpath:
slashes relpath {
- $$ = como_asprintf("/%s", $2);
+ $$ = safe_asprintf("/%s", $2);
free($2);
}
| slashes {
- $$ = como_asprintf("/");
+ $$ = safe_asprintf("/");
}
;
relpath:
relpath slashes TOK_STRING {
- $$ = como_asprintf("%s/%s", $1, $3);
+ $$ = safe_asprintf("%s/%s", $1, $3);
free($1);
free($3);
}
@@ -143,12 +143,12 @@
}
| TOK_STRING TOK_EQUALS { /* value is not there */
ast.keyvals[ast.nkeyvals].key = $1;
- ast.keyvals[ast.nkeyvals].val = como_strdup("");
+ ast.keyvals[ast.nkeyvals].val = safe_strdup("");
ast.nkeyvals++;
}
| TOK_STRING {
ast.keyvals[ast.nkeyvals].key = $1;
- ast.keyvals[ast.nkeyvals].val = como_strdup("");
+ ast.keyvals[ast.nkeyvals].val = safe_strdup("");
ast.nkeyvals++;
}
| { /* tolerate missing key=val */ }
@@ -159,7 +159,7 @@
$$ = $1;
}
| value TOK_EQUALS TOK_STRING {
- $$ = como_asprintf("%s=%s", $1, $3);
+ $$ = safe_asprintf("%s=%s", $1, $3);
free($1);
free($3);
}
Modified: src/branches/2.0/base/query.c
===================================================================
--- src/branches/2.0/base/query.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/query.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -166,7 +166,7 @@
req->source = node->source; /* from the virtual node's source */
if (req->filter_str)
- req->filter_str = como_asprintf("(%s) and (%s)", req->filter_str,
+ req->filter_str = safe_asprintf("(%s) and (%s)", req->filter_str,
node->filter);
else
req->filter_str = node->filter;
@@ -206,9 +206,9 @@
* if necessary first get the default format
*/
if (req->format == NULL)
- req->format = como_strdup(iq->dflt_format);
+ req->format = safe_strdup(iq->dflt_format);
if (req->format == NULL) /* mdl has no default */
- req->format = como_strdup("plain");
+ req->format = safe_strdup("plain");
/*
* set the qu_format
@@ -478,7 +478,7 @@
uint8_t *sbuf;
void *mdlrec;
qreq_t req = *qreq;
- int client_fd = como_fileno(client_stream);
+ int client_fd = safe_fileno(client_stream);
if (req.mode == QMODE_SERVICE) {
service_fn service = service_lookup(req.service);
@@ -534,7 +534,7 @@
*/
storage_fd = ipc_connect(COMO_ST);
- dbname = como_asprintf("%s/%s/%s", como_config->db_path, node->name,
+ dbname = safe_asprintf("%s/%s/%s", como_config->db_path, node->name,
req.mdl->name);
debug("opening file for reading (%s)\n", dbname);
mode = req.wait ? CS_READER : CS_READER_NOBLOCK;
@@ -700,7 +700,7 @@
int supervisor_fd, ret, errcode;
qreq_t req;
char *errstr, *httpstr;
- int client_fd = como_fileno(client_stream);
+ int client_fd = safe_fileno(client_stream);
query_initialize(parent, &supervisor_fd);
ret = query_recv(&req, client_fd, como_stats->ts);
@@ -742,7 +742,7 @@
*/
if (req.mode == QMODE_MODULE) {
httpstr = NULL;
- httpstr = como_asprintf("HTTP/1.0 200 OK\r\nContent-Type: %s\r\n\r\n",
+ httpstr = safe_asprintf("HTTP/1.0 200 OK\r\nContent-Type: %s\r\n\r\n",
req.qu_format->content_type);
if (como_write(client_fd, httpstr, strlen(httpstr)) < 0)
error("sending data to the client");
@@ -763,11 +763,11 @@
int supervisor_fd, errcode;
char *errstr, *to_http;
qreq_t req;
- int client_fd = como_fileno(client_stream);
+ int client_fd = safe_fileno(client_stream);
query_initialize(parent, &supervisor_fd);
- to_http = como_asprintf("GET /%s HTTP/1.0\r\n\r\n",
+ to_http = safe_asprintf("GET /%s HTTP/1.0\r\n\r\n",
como_config->inline_module);
/*
Modified: src/branches/2.0/base/storage.c
===================================================================
--- src/branches/2.0/base/storage.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/storage.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -30,7 +30,9 @@
* $Id$
*/
+#ifndef _GNU_SOURCE
#define _GNU_SOURCE
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
@@ -1405,7 +1407,7 @@
}
/* finally, prepare to extend the file */
- buf = como_calloc(1, ext);
+ buf = safe_calloc(1, ext);
if (write(bs->wfd, buf, ext) < 0) {
free(buf);
warn("id: %d,%s; write to extend file failed: %s\n",
@@ -1817,7 +1819,7 @@
exit(EXIT_FAILURE);
}
- location = como_strdup(argv[1]);
+ location = safe_strdup(argv[1]);
como_init("ST", argc, argv);
if (atoi(argv[3])) /* inline mode */
Modified: src/branches/2.0/base/supervisor.c
===================================================================
--- src/branches/2.0/base/supervisor.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/supervisor.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -97,7 +97,7 @@
size_t sz;
sz = mdl_sersize(mdl);
- buf = sbuf = como_malloc(sz);
+ buf = sbuf = safe_malloc(sz);
mdl_serialize(&sbuf, mdl);
@@ -379,24 +379,24 @@
* the array of working modules.
*/
static mdl_t *
-como_node_init_mdl(como_node_t * node, mdl_def_t * def, alc_t * alc)
+como_node_init_mdl(como_node_t * node, mdl_def_t * def)
{
static int s_mdl_ids = 0;
mdl_isupervisor_t *is;
- mdl_t *mdl = alc_new0(alc, mdl_t);
+ mdl_t *mdl = safe_malloc(sizeof(mdl_t));
mdl->id = s_mdl_ids++;
if (mdl->id > MDL_ID_MAX)
error("the system currently supports %d mdls\n", MDL_ID_MAX);
- mdl->name = alc_strdup(alc, def->name);
- mdl->mdlname = alc_strdup(alc, def->mdlname);
+ mdl->name = safe_strdup(def->name);
+ mdl->mdlname = safe_strdup(def->mdlname);
mdl->streamsize = def->streamsize;
- mdl->filter = alc_strdup(alc, def->filter);
- mdl->description = alc_strdup(alc, def->descr);
+ mdl->filter = safe_strdup(def->filter);
+ mdl->description = safe_strdup(def->descr);
#ifdef LOADSHED
- mdl->shed_method = alc_strdup(alc, def->shed_method);
+ mdl->shed_method = safe_strdup(def->shed_method);
mdl->minimum_srate = def->minimum_srate;
#endif
@@ -428,12 +428,12 @@
* array of definitions.
*/
static void
-como_node_init_mdls(como_node_t * node, array_t * mdl_defs, alc_t * alc)
+como_node_init_mdls(como_node_t * node, array_t * mdl_defs)
{
int i;
for (i = 0; i < mdl_defs->len; i++) {
mdl_def_t *def = &array_at(mdl_defs, mdl_def_t, i);
- como_node_init_mdl(node, def, alc);
+ como_node_init_mdl(node, def);
}
}
@@ -454,7 +454,6 @@
{
hash_t *current_modules, *newcfg_modules, *new_modules, *rem_modules;
como_config_t new_cfg;
- alc_t *alc = como_su->alc;
como_node_t *node;
hash_iter_t it;
ipc_type t;
@@ -463,24 +462,24 @@
node = &array_at(como_su->nodes, como_node_t, 0);
/* re-run the config routines */
- configure(s_saved_argc, s_saved_argv, s_como_su->alc, &new_cfg);
+ configure(s_saved_argc, s_saved_argv, &new_cfg);
/* load module names from current cfg into a hash */
- current_modules = hash_new(alc, HASHKEYS_STRING, NULL, NULL);
+ current_modules = hash_new(NULL, HASHKEYS_STRING, NULL, NULL);
for (i = 0; i < como_config->mdl_defs->len; i++) {
mdl_def_t *def = &array_at(como_config->mdl_defs, mdl_def_t, i);
hash_insert_string(current_modules, def->name, def);
}
/* load module names from the new cfg info a hash */
- newcfg_modules = hash_new(alc, HASHKEYS_STRING, NULL, NULL);
+ newcfg_modules = hash_new(NULL, HASHKEYS_STRING, NULL, NULL);
for (i = 0; i < new_cfg.mdl_defs->len; i++) {
mdl_def_t *def = &array_at(new_cfg.mdl_defs, mdl_def_t, i);
hash_insert_string(newcfg_modules, def->name, def);
}
/* find new modules */
- new_modules = hash_new(alc, HASHKEYS_STRING, NULL, NULL);
+ new_modules = hash_new(NULL, HASHKEYS_STRING, NULL, NULL);
hash_iter_init(newcfg_modules, &it);
while(hash_iter_next(&it)) {
mdl_def_t *def = hash_iter_get_value(&it);
@@ -490,7 +489,7 @@
continue;
/* new module */
- mdl = como_node_init_mdl(node, def, alc);
+ mdl = como_node_init_mdl(node, def);
if (mdl == NULL)
continue;
@@ -501,7 +500,7 @@
}
/* find modules to be removed */
- rem_modules = hash_new(alc, HASHKEYS_STRING, NULL, NULL);
+ rem_modules = hash_new(NULL, HASHKEYS_STRING, NULL, NULL);
hash_iter_init(current_modules, &it);
while(hash_iter_next(&it)) {
mdl_def_t *def = hash_iter_get_value(&it);
@@ -579,7 +578,7 @@
size_t sz;
sz = sersize_string(name);
- buffer = como_malloc(sz);
+ buffer = safe_malloc(sz);
ptr = buffer;
serialize_string(&ptr, name);
@@ -602,7 +601,7 @@
size_t sz;
sz = sersize_string(name);
- buffer = como_malloc(sz);
+ buffer = safe_malloc(sz);
ptr = buffer;
serialize_string(&ptr, name);
@@ -622,7 +621,7 @@
hash_destroy(newcfg_modules);
hash_destroy(new_modules);
hash_destroy(rem_modules);
- destroy_config(&new_cfg, alc);
+ destroy_config(&new_cfg);
}
@@ -798,7 +797,7 @@
}
s->cb = cb;
- s->device = como_strdup(def->device);
+ s->device = safe_strdup(def->device);
/* check that the sniffer is consistent with the sniffers already
* configured */
@@ -839,9 +838,9 @@
char **argv2;
int i;
- argv2 = como_calloc(argc + 1, sizeof(char *));
+ argv2 = safe_calloc(argc + 1, sizeof(char *));
for (i = 0; i <= argc; i++) /* <= is correct, must copy final NULL */
- argv2[i] = como_strdup(argv[i]);
+ argv2[i] = safe_strdup(argv[i]);
*out_argc = argc;
*out_argv = argv2;
@@ -867,18 +866,18 @@
node.kind = COMO_NODE_REAL;
node.id = 0;
- node.name = como_strdup("CoMo Node");
- node.location = como_strdup(cfg->location);
- node.type = como_strdup(cfg->type);
+ node.name = safe_strdup("CoMo Node");
+ node.location = safe_strdup(cfg->location);
+ node.type = safe_strdup(cfg->type);
node.query_port = cfg->query_port;
node.mdls = array_new(sizeof(mdl_t *));
if (node.location == NULL)
- node.location = como_strdup("Unknown");
+ node.location = safe_strdup("Unknown");
if (node.type == NULL)
- node.type = como_strdup("Unknown");
+ node.type = safe_strdup("Unknown");
- str = como_asprintf("%s/%s", como_config->db_path, node.name);
+ str = safe_asprintf("%s/%s", como_config->db_path, node.name);
if (mkdir(str, 0700) == -1 && errno != EEXIST)
error("cannot create db dir `%s'\n", str);
free(str);
@@ -896,17 +895,17 @@
node.real_node_id = 0;
node.id = i + 1;
- node.name = como_strdup(def->name);
- node.location = como_strdup(def->location);
- node.type = como_strdup(def->type);
+ node.name = safe_strdup(def->name);
+ node.location = safe_strdup(def->location);
+ node.type = safe_strdup(def->type);
node.query_port = def->query_port;
- node.source = como_strdup(def->source);
- node.filter = como_strdup(def->filter);
+ node.source = safe_strdup(def->source);
+ node.filter = safe_strdup(def->filter);
if (node.location == NULL)
- node.location = como_strdup("Unknown");
+ node.location = safe_strdup("Unknown");
if (node.type == NULL)
- node.type = como_strdup("Unknown");
+ node.type = safe_strdup("Unknown");
array_add(como_su->nodes, &node);
}
@@ -926,17 +925,10 @@
{
static como_config_t cfg;
como_su_t *como_su;
- alc_t alc;
como_node_t *main_node;
int i;
- /* create a global pool */
- pool_t *pool = pool_create();
-
- pool_alc_init(pool, &alc);
- como_su = alc_new0(&alc, como_su_t);
- como_su->pool = pool;
- como_su->alc = &alc;
+ como_su = safe_malloc(sizeof(como_su_t));
como_su->su_pid = getpid();
como_su->workdir = mkdtemp(strdup("/tmp/comoXXXXXX"));
s_como_su = como_su;
@@ -947,13 +939,13 @@
* parse command line and configuration files
*/
copy_args(argc, argv, &s_saved_argc, &s_saved_argv);
- como_config = configure(s_saved_argc, s_saved_argv, &alc, &cfg);
+ como_config = configure(s_saved_argc, s_saved_argv, &cfg);
if (como_config->silent_mode)
log_set_level(LOG_LEVEL_WARNING); /* disable most UI messages */
if (como_config->inline_mode) { /* use temporary storage */
- char *template = como_asprintf("%s/XXXXXX", como_su->workdir);
+ char *template = safe_asprintf("%s/XXXXXX", como_su->workdir);
como_config->db_path = como_config->db_path = mkdtemp(template);
}
@@ -982,7 +974,8 @@
* CAPTURE and QUERY processes will be able to see it.
*/
como_su->shmem = shmem_create(como_config->shmem_size, NULL);
- como_su->memmap = memmap_create(como_su->shmem, 2048);
+ como_su->memmap = memmap_create(shmem_baseaddr(como_su->shmem),
+ shmem_size(como_su->shmem), 2048);
memmap_alc_init(como_su->memmap, &como_su->shalc);
/* allocate statistics into shared memory */
@@ -1003,7 +996,7 @@
if (n->kind != COMO_NODE_REAL)
continue;
como_node_init_sniffers(n, como_config->sniffer_defs, &como_su->shalc);
- como_node_init_mdls(n, como_config->mdl_defs, como_su->alc);
+ como_node_init_mdls(n, como_config->mdl_defs);
}
if (como_config->inline_mode && main_node->mdls->len == 0) {
Modified: src/branches/2.0/base/util-timers.c
===================================================================
--- src/branches/2.0/base/util-timers.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/base/util-timers.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -70,7 +70,7 @@
ctimer_t * t;
t = como_new0(ctimer_t);
- t->name = como_strdup(name);
+ t->name = safe_strdup(name);
t->min = ~0;
return t;
}
Modified: src/branches/2.0/include/comofunc.h
===================================================================
--- src/branches/2.0/include/comofunc.h 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/include/comofunc.h 2008-06-02 23:36:26 UTC (rev 1250)
@@ -89,26 +89,25 @@
*/
void define_sniffer(char *name, char *device, char *args, como_config_t *cfg);
void define_module(mdl_def_t *mdl, como_config_t *cfg);
-void define_virtual_node(virtual_node_def_t *vnode, como_config_t *cfg,
- alc_t *alc);
-void initialize_module_def(mdl_def_t *mdl, alc_t *alc);
-void initialize_virtual_node_def(virtual_node_def_t *vnode, alc_t *alc);
+void define_virtual_node(virtual_node_def_t *vnode, como_config_t *cfg);
+void initialize_module_def(mdl_def_t *mdl);
+void initialize_virtual_node_def(virtual_node_def_t *vnode);
void set_filesize(int64_t size, como_config_t *cfg);
void set_memsize(int64_t size, como_config_t *cfg);
void set_queryport(int64_t port, como_config_t *cfg);
-como_config_t *configure(int argc, char **argv, alc_t *alc, como_config_t *cfg);
+como_config_t *configure(int argc, char **argv, como_config_t *cfg);
mdl_def_t * config_get_module_def_by_name(como_config_t *cfg, char *name);
char *config_resolve_alias(como_config_t *cfg, char *name);
-void destroy_config(como_config_t *cfg, alc_t *alc);
-void destroy_virtual_node_def(virtual_node_def_t *cfg, alc_t *alc);
+void destroy_config(como_config_t *cfg);
+void destroy_virtual_node_def(virtual_node_def_t *cfg);
/*
* config-syntax.y
*/
-como_config_t * parse_config_file(char *file, alc_t *alc, como_config_t *cfg);
-como_config_t * parse_config_string(char *str, alc_t *alc, como_config_t *cfg);
+como_config_t * parse_config_file(char *file, como_config_t *cfg);
+como_config_t * parse_config_string(char *str, como_config_t *cfg);
/*
* filter-syntax.c
Modified: src/branches/2.0/include/comopriv.h
===================================================================
--- src/branches/2.0/include/comopriv.h 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/include/comopriv.h 2008-06-02 23:36:26 UTC (rev 1250)
@@ -45,32 +45,32 @@
*/
void como_init(const char * progname, int argc, char ** argv);
-#define como_malloc(sz) \
-como__malloc(sz, __FILE__, __LINE__)
+#define safe_malloc(sz) \
+safe__malloc(sz, __FILE__, __LINE__)
-#define como_calloc(n,sz) \
-como__calloc(n, sz, __FILE__, __LINE__)
+#define safe_calloc(n,sz) \
+safe__calloc(n, sz, __FILE__, __LINE__)
-#define como_realloc(ptr,sz) \
-como__realloc(ptr, sz, __FILE__, __LINE__)
+#define safe_realloc(ptr,sz) \
+safe__realloc(ptr, sz, __FILE__, __LINE__)
-#define como_strdup(str) \
-como__strdup(str, __FILE__, __LINE__)
+#define safe_strdup(str) \
+safe__strdup(str, __FILE__, __LINE__)
-#define como_dup(dst,src) \
-como__dup(dst, src, __FILE__, __LINE__)
+#define safe_dup(dst,src) \
+safe__dup(dst, src, __FILE__, __LINE__)
-#define como_fileno(stream) \
-como__fileno(stream, __FILE__, __LINE__)
+#define safe_fileno(stream) \
+safe__fileno(stream, __FILE__, __LINE__)
-#define como_asprintf(fmt...) \
-como__asprintf(__FILE__, __LINE__, fmt)
+#define safe_asprintf(fmt...) \
+safe__asprintf(__FILE__, __LINE__, fmt)
#define como_new(type) \
-((type *) como_malloc(sizeof(type)))
+((type *) safe_malloc(sizeof(type)))
#define como_new0(type) \
-((type *) como_calloc(1, sizeof(type)))
+((type *) safe_calloc(1, sizeof(type)))
char * como_basename (const char * path);
@@ -128,14 +128,14 @@
CCA_ACK_BATCH,
};
-void * como__malloc (size_t sz, const char * file, int line);
-void * como__calloc (size_t n, size_t sz, const char * file, int line);
-void * como__realloc (void * ptr, size_t sz, const char * file,
+void * safe__malloc (size_t sz, const char * file, int line);
+void * safe__calloc (size_t n, size_t sz, const char * file, int line);
+void * safe__realloc (void * ptr, size_t sz, const char * file,
const int line);
-char * como__strdup (const char * str, const char * file, const int line);
-char * como__dup (char **dst, char *src, const char * file, const int line);
-int como__fileno (FILE* stream, const char * file, const int line);
-char * como__asprintf (const char * file, const int line, char *fmt, ...);
+char * safe__strdup (const char * str, const char * file, const int line);
+char * safe__dup (char **dst, char *src, const char * file, const int line);
+int safe__fileno (FILE* stream, const char * file, const int line);
+char * safe__asprintf (const char * file, const int line, char *fmt, ...);
/*
* memory.c
@@ -147,7 +147,8 @@
size_t peak; /* peak usage */
} memmap_stats_t;
-memmap_t * memmap_create (shmem_t * shmem, uint32_t entries);
+memmap_t * memmap_create (void * baseaddr, size_t size,
+ uint32_t entries);
void memmap_alc_init (memmap_t * m, alc_t * alc);
memmap_stats_t * memmap_stats_location (memmap_t * m);
size_t memmap_usage (memmap_t * m);
@@ -447,10 +448,6 @@
array_t * nodes; /* node information */
- pool_t * pool; /* the pool used to allocate this
- structure */
- alc_t * alc; /* the pool's allocator */
-
shmem_t * shmem; /* main shared memory used to store
capture data structures, stats */
memmap_t * memmap;
Modified: src/branches/2.0/include/os.h
===================================================================
--- src/branches/2.0/include/os.h 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/include/os.h 2008-06-02 23:36:26 UTC (rev 1250)
@@ -50,7 +50,9 @@
/*** ***/
#ifdef linux
+#ifndef _GNU_SOURCE
#define _GNU_SOURCE /* Required to use asprintf in Linux */
+#endif
/*
* EPROGUNAVAIL is not defined in Linux
*/
Modified: src/branches/2.0/lib/bitmap.c
===================================================================
--- src/branches/2.0/lib/bitmap.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/lib/bitmap.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -117,9 +117,9 @@
{
bitmap_t *bm;
- bm = como_malloc(sizeof(bitmap_t));
+ bm = safe_malloc(sizeof(bitmap_t));
_initialize_bitmap(bm, max_elements);
- bm->map = como_malloc(bm->bytes); /* no need to bzero */
+ bm->map = safe_malloc(bm->bytes); /* no need to bzero */
return bm;
}
Modified: src/branches/2.0/lib/flowtable.c
===================================================================
--- src/branches/2.0/lib/flowtable.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/lib/flowtable.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -602,7 +602,7 @@
* Print out the histogram and a few other pieces of information.
*/
- result = (char *) como_malloc((NUM_COUNTERS * 60) + 300);
+ result = (char *) safe_malloc((NUM_COUNTERS * 60) + 300);
sprintf(result, "%d entries in table, %d buckets\n",
ftable->numEntries, ftable->numBuckets);
p = result + strlen(result);
Modified: src/branches/2.0/lib/heap.c
===================================================================
--- src/branches/2.0/lib/heap.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/lib/heap.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -63,11 +63,11 @@
return NULL;
}
- h = (heap_t*) como_malloc(sizeof(heap_t));
+ h = (heap_t*) safe_malloc(sizeof(heap_t));
h->cmp = cmp;
h->size = size;
h->maxsize = 0; /* dynamic heap. no max size set */
- h->array = como_malloc(h->size * sizeof(void*));
+ h->array = safe_malloc(h->size * sizeof(void*));
h->first_free = 0; /* the heap is empty */
return h;
@@ -106,7 +106,7 @@
if (h->maxsize == 0) {
/* dynamic heap. double its size */
h->size <<= 1;
- h->array = como_realloc(h->array, h->size * sizeof(void*));
+ h->array = safe_realloc(h->array, h->size * sizeof(void*));
} else {
/* return an error and let the caller decide */
errno = ENOSPC;
Modified: src/branches/2.0/libcomo/array.c
===================================================================
--- src/branches/2.0/libcomo/array.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/libcomo/array.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -86,7 +86,7 @@
}
array->size = MAX(array->size, 16);
- array->base = como_realloc(array->base, array->size * array->element_size);
+ array->base = safe_realloc(array->base, array->size * array->element_size);
array->data = array->base + off;
}
Modified: src/branches/2.0/libcomo/como.c
===================================================================
--- src/branches/2.0/libcomo/como.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/libcomo/como.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -30,7 +30,9 @@
* $Id:como.c 1032 2006-11-14 13:29:01Z m_canini $
*/
+#ifndef _GNU_SOURCE
#define _GNU_SOURCE
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
@@ -77,9 +79,9 @@
}
/**
- * -- como__malloc
+ * -- safe__malloc
*
- * Not to be called directly, but through como_malloc()
+ * Not to be called directly, but through safe_malloc()
*
* simple wrapper to malloc that handles errors
* and returns only if the malloc call succeded. it
@@ -87,7 +89,7 @@
*
*/
void *
-como__malloc(size_t sz, const char * file, int line)
+safe__malloc(size_t sz, const char * file, int line)
{
void * v;
@@ -102,9 +104,9 @@
/**
- * -- como__calloc
+ * -- safe__calloc
*
- * Not to be called directly, but through como_calloc()
+ * Not to be called directly, but through safe_calloc()
*
* simple interface to calloc that handles errors
* and returns only if the calloc call succeded. it
@@ -112,7 +114,7 @@
*
*/
void *
-como__calloc(size_t n, size_t sz, const char * file, int line)
+safe__calloc(size_t n, size_t sz, const char * file, int line)
{
void * v;
@@ -127,9 +129,9 @@
/**
- * -- como__realloc
+ * -- safe__realloc
*
- * Not to be called directly, but through como_realloc()
+ * Not to be called directly, but through safe_realloc()
*
* simple interface to realloc that handles errors
* and returns only if the realloc call succeded. it
@@ -137,7 +139,7 @@
*
*/
void *
-como__realloc(void * ptr, size_t sz, const char * file, const int line)
+safe__realloc(void * ptr, size_t sz, const char * file, const int line)
{
void * v;
@@ -152,9 +154,9 @@
/**
- * -- como__strdup
+ * -- safe__strdup
*
- * Not to be called directly, but through como_strdup()
+ * Not to be called directly, but through safe_strdup()
*
* simple interface to strdup() that handles errors
* and returns only if the call succeded. it
@@ -162,7 +164,7 @@
*
*/
char *
-como__strdup(const char * str, const char * file, const int line)
+safe__strdup(const char * str, const char * file, const int line)
{
char * v;
@@ -180,25 +182,25 @@
/*
- * -- como__dup
+ * -- safe__freedup
*
- * Not to be called directly, but through como_dup()
+ * Not to be called directly, but through safe_freedup()
*
* Makes a malloc'ed copy of src into *dst,
* freeing the previous one if any
*/
char *
-como__dup(char **dst, char *src, const char * file, const int line)
+safe__freedup(char **dst, char *src, const char * file, const int line)
{
if (*dst)
free(*dst);
- *dst = como__strdup(src, file, line);
+ *dst = safe__strdup(src, file, line);
return *dst;
}
int
-como__fileno(FILE *stream, const char *file, const int line)
+safe__fileno(FILE *stream, const char *file, const int line)
{
int i = fileno(stream);
if (i < 1)
@@ -212,14 +214,14 @@
char *
-como__asprintf(const char * file, const int line, char *fmt, ...)
+safe__asprintf(const char * file, const int line, char *fmt, ...)
{
char *str;
va_list ap;
va_start(ap, fmt);
vasprintf(&str, fmt, ap);
if (str == NULL) {
- error("asprintf failed (%s:%d): %s\n",
+ error("vasprintf failed (%s:%d): %s\n",
file, line, strerror(errno));
}
va_end(ap);
@@ -237,8 +239,8 @@
como_alc()
{
static alc_t alc = {
- malloc: (alc_malloc_fn) como__malloc,
- calloc: (alc_calloc_fn) como__calloc,
+ malloc: (alc_malloc_fn) safe__malloc,
+ calloc: (alc_calloc_fn) safe__calloc,
free: (alc_free_fn) free,
data: NULL
};
Modified: src/branches/2.0/libcomo/hash.c
===================================================================
--- src/branches/2.0/libcomo/hash.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/libcomo/hash.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -89,6 +89,7 @@
#include <assert.h>
#include "como.h"
+#include "comopriv.h"
/*
* When there are this many entries per bucket, on average, rebuild
@@ -230,7 +231,9 @@
{
hash_t *tablePtr;
- assert(alc != NULL);
+ if (alc == NULL)
+ alc = como_alc();
+
tablePtr = alc_new0(alc, hash_t);
#if (SMALL_HASH_TABLE != 4)
Modified: src/branches/2.0/libcomo/ipc.c
===================================================================
--- src/branches/2.0/libcomo/ipc.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/libcomo/ipc.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -48,7 +48,9 @@
* in the s_handlers.
*/
+#ifndef _GNU_SOURCE
#define _GNU_SOURCE
+#endif
#include <stdio.h>
#include <string.h> /* strlen */
#include <errno.h>
@@ -154,7 +156,7 @@
p2 = como_new(ipc_peer_full_t);
*p2 = *p;
p2->fd = -1;
- p2->at = como_strdup(at);
+ p2->at = safe_strdup(at);
p2->swap = 0;
memset(&p2->next, 0, sizeof(p2->next));
return p2;
@@ -202,7 +204,7 @@
*p = *kind;
p->parent_class = s_me->class;
p->id = id;
- p->at = como_strdup(s_me->at);
+ p->at = safe_strdup(s_me->at);
p->fd = -1;
memset(&p->next, 0, sizeof(p->next));
return p;
@@ -350,7 +352,7 @@
int r;
if (dst->at == NULL) {
- dst->at = como_strdup(s_me->at);
+ dst->at = safe_strdup(s_me->at);
}
dst->fd = ipc_create_socket(dst, FALSE);
Modified: src/branches/2.0/libcomo/log.c
===================================================================
--- src/branches/2.0/libcomo/log.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/libcomo/log.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -196,16 +196,16 @@
if (h == NULL) {
s_log.handlers_count++;
if (s_log.handlers != &s_initial_handler) {
- s_log.handlers = como_realloc(s_log.handlers, s_log.handlers_count *
+ s_log.handlers = safe_realloc(s_log.handlers, s_log.handlers_count *
sizeof(log_handler_t));
} else {
- s_log.handlers = como_malloc(s_log.handlers_count *
+ s_log.handlers = safe_malloc(s_log.handlers_count *
sizeof(log_handler_t));
s_log.handlers[0] = s_initial_handler;
}
h = &s_log.handlers[s_log.handlers_count - 1];
}
- h->domain = como_strdup(domain);
+ h->domain = safe_strdup(domain);
h->user_fn = user_fn;
h->user_data = user_data;
}
@@ -245,7 +245,7 @@
s_log.buf_len += 4 - s_log.buf_len % 4;
}
}
- s_log.buf = como_realloc(s_log.buf, s_log.buf_len);
+ s_log.buf = safe_realloc(s_log.buf, s_log.buf_len);
len = 1 + vsnprintf(s_log.buf, s_log.buf_len, format, ap);
}
Modified: src/branches/2.0/libcomo/memory.c
===================================================================
--- src/branches/2.0/libcomo/memory.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/libcomo/memory.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -320,37 +320,33 @@
*
*/
memmap_t *
-memmap_create(shmem_t * shmem, uint32_t entries)
+memmap_create(void * baseaddr, size_t size, uint32_t entries)
{
- void *x;
memmap_state_t *mem;
memmap_t *map;
memblock_t *m;
size_t ctrl;
- size_t size;
/*
* we put the memmap state structure at the beginning of the
* chunk, followed by the memory block that contains the actual
* allocated space.
*/
- x = shmem_baseaddr(shmem);
- size = shmem_size(shmem);
/* size of control structures */
ctrl = sizeof(memmap_state_t) + (sizeof(memmap_t) * (1 + entries));
- memset(x, 0, ctrl);
+ memset(baseaddr, 0, ctrl);
- mem = (memmap_state_t *) x;
- x += sizeof(memmap_state_t);
+ mem = (memmap_state_t *) baseaddr;
+ baseaddr += sizeof(memmap_state_t);
map = &mem->map[0];
- x += sizeof(memmap_t) * (1 + entries);
+ baseaddr += sizeof(memmap_t) * (1 + entries);
/* initially the map has only a big block */
- m = (memblock_t *) x;
+ m = (memblock_t *) baseaddr;
m->size = size - ctrl - sizeof(memblock_t);
m->_magic = MY_MAGIC;
m->next = NULL;
Modified: src/branches/2.0/libcomo/shmem.c
===================================================================
--- src/branches/2.0/libcomo/shmem.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/libcomo/shmem.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -120,7 +120,7 @@
key_t shmkey;
new_m->realsize = reqsize;
- new_m->filename = como_strdup(filename);
+ new_m->filename = safe_strdup(filename);
fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0600);
if (fd < 0) {
@@ -277,7 +277,7 @@
goto error;
}
- new_m->filename = como_strdup(filename);
+ new_m->filename = safe_strdup(filename);
shmkey = ftok(filename, 1);
if (shmkey == (key_t)-1) {
goto error;
Modified: src/branches/2.0/libcomo/shobj.c
===================================================================
--- src/branches/2.0/libcomo/shobj.c 2008-05-30 17:50:39 UTC (rev 1249)
+++ src/branches/2.0/libcomo/shobj.c 2008-06-02 23:36:26 UTC (rev 1250)
@@ -29,7 +29,9 @@
*
* $Id$
*/
+#ifndef _GNU_SOURCE
...
[truncated message content] |