diff options
Diffstat (limited to 'src/progman.c')
-rw-r--r-- | src/progman.c | 76 |
1 files changed, 39 insertions, 37 deletions
diff --git a/src/progman.c b/src/progman.c index 4420a21..d24ea1a 100644 --- a/src/progman.c +++ b/src/progman.c @@ -1,5 +1,5 @@ /* This file is part of GNU Pies. - Copyright (C) 2007, 2008, 2009, 2010 Sergey Poznyakoff + Copyright (C) 2007, 2008, 2009, 2010, 2011 Sergey Poznyakoff GNU Pies is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -15,7 +15,6 @@ along with GNU Pies. If not, see <http://www.gnu.org/licenses/>. */ #include "pies.h" -#include <hash.h> enum prog_type { @@ -89,7 +88,7 @@ static size_t numcomp; static struct prog *proghead, *progtail; static pies_depmap_t depmap; static int recompute_alarm; -static Hash_table *conn_tab; +static struct grecs_symtab *conn_tab; void progman_iterate_comp (int (*fun) (struct component *, void *), void *data) @@ -357,10 +356,10 @@ prog_rebuild_prerequisites (struct prog *prog) if (comp->prereq) { - depc = gl_list_size (comp->prereq); + depc = grecs_list_size (comp->prereq); if (depc == 1) { - const char *item = gl_list_get_at (comp->prereq, 0); + const char *item = grecs_list_index (comp->prereq, 0); if (strcmp (item, "all") == 0) { dep_all = 1; @@ -370,7 +369,7 @@ prog_rebuild_prerequisites (struct prog *prog) } else if (strcmp (item, "none") == 0) { - gl_list_free (comp->prereq); + grecs_list_free (comp->prereq); comp->prereq = NULL; } } @@ -392,13 +391,10 @@ prog_rebuild_prerequisites (struct prog *prog) } else { - const void *p; - gl_list_iterator_t itr = gl_list_iterator (comp->prereq); - while (gl_list_iterator_next (&itr, &p, NULL)) - { - prog->prereq[depc++] = (char*) p; - } - gl_list_iterator_free (&itr); + struct grecs_list_entry *ep; + + for (ep = comp->prereq->head; ep; ep = ep->next) + prog->prereq[depc++] = (char*) ep->data; } } prog->prereq[depc] = NULL; @@ -521,10 +517,10 @@ open_redirector (struct prog *master, int stream) } -static size_t -conn_class_hasher (void const *data, size_t n_buckets) +static unsigned +conn_class_hasher (void *data, unsigned long n_buckets) { - struct conn_class const *pcclass = data; + struct conn_class *pcclass = data; unsigned char const *tag = (unsigned char const *)pcclass->tag; size_t value = 0; unsigned char ch; @@ -542,15 +538,15 @@ conn_class_hasher (void const *data, size_t n_buckets) } /* Compare two strings for equality. */ -static bool +static int conn_class_compare (void const *data1, void const *data2) { struct conn_class const *p1 = data1; struct conn_class const *p2 = data2; - return p1->sa_len == p2->sa_len && + return !(p1->sa_len == p2->sa_len && memcmp (&p1->sa_storage, &p2->sa_storage, p1->sa_len) == 0 && - strcmp (p1->tag, p2->tag) == 0; + strcmp (p1->tag, p2->tag) == 0); } static void @@ -559,11 +555,20 @@ conn_class_free (void *data) free (data); } +static int +conn_class_copy(void *a, void *b) +{ + memcpy(a, b, sizeof(struct conn_class)); + memset(a, 0, sizeof(struct conn_class)); + return 0; +} + static struct conn_class * conn_class_lookup (const char *tag, union pies_sockaddr_storage const *sa_storage_ptr, size_t sa_len) { + int install = 1; struct conn_class *probe, *ret; probe = xmalloc (sizeof (probe[0])); @@ -586,16 +591,19 @@ conn_class_lookup (const char *tag, } probe->count = 0; - - if (!((conn_tab - || (conn_tab = hash_initialize (0, 0, + if (!conn_tab) + { + conn_tab = grecs_symtab_create(sizeof (struct conn_class), conn_class_hasher, conn_class_compare, - conn_class_free))) - && (ret = hash_insert (conn_tab, probe)))) + conn_class_copy, + NULL, + conn_class_free); + if (!conn_tab) xalloc_die (); + } - if (probe != ret) + ret = grecs_symtab_lookup_or_install (conn_tab, probe, &install); free (probe); return ret; } @@ -1411,16 +1419,14 @@ progman_accept (int socket) void component_fixup_depend (struct component *comp) { - const void *p; - gl_list_iterator_t itr; + struct grecs_list_entry *ep; if (comp->depend == NULL) return; - itr = gl_list_iterator (comp->depend); - while (gl_list_iterator_next (&itr, &p, NULL)) + for (ep = comp->depend->head; ep; ep = ep->next) { - const char *tag = p; + const char *tag = ep->data; struct component *tgt; tgt = progman_lookup_component (tag); @@ -1434,16 +1440,12 @@ component_fixup_depend (struct component *comp) } if (!tgt->prereq) { - tgt->prereq = gl_list_create_empty(&gl_linked_list_implementation, - NULL, - NULL, - NULL, - false); + tgt->prereq = grecs_list_create(); } /* FIXME: memory allocation */ - gl_list_add_last (tgt->prereq, xstrdup (comp->tag)); + grecs_list_append (tgt->prereq, xstrdup (comp->tag)); } - gl_list_free (comp->depend); + grecs_list_free (comp->depend); comp->depend = NULL; } |