aboutsummaryrefslogtreecommitdiff
path: root/src/progman.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/progman.c')
-rw-r--r--src/progman.c86
1 files changed, 44 insertions, 42 deletions
diff --git a/src/progman.c b/src/progman.c
index 4420a21..d24ea1a 100644
--- a/src/progman.c
+++ b/src/progman.c
@@ -1,8 +1,8 @@
/* 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
the Free Software Foundation; either version 3, or (at your option)
any later version.
@@ -12,13 +12,12 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Pies. If not, see <http://www.gnu.org/licenses/>. */
#include "pies.h"
-#include <hash.h>
enum prog_type
{
TYPE_COMPONENT,
TYPE_REDIRECTOR,
TYPE_COMMAND
@@ -86,13 +85,13 @@ struct prog
#define IS_COMPONENT(p) ((p)->type == TYPE_COMPONENT)
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)
{
struct prog *prog;
@@ -354,26 +353,26 @@ prog_rebuild_prerequisites (struct prog *prog)
struct prog *p;
int dep_all = 0;
size_t depc = 0;
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;
for (p = proghead; p; p = p->next)
if (p->type == TYPE_COMPONENT)
depc++;
}
else if (strcmp (item, "none") == 0)
{
- gl_list_free (comp->prereq);
+ grecs_list_free (comp->prereq);
comp->prereq = NULL;
}
}
}
if (depc == 0)
@@ -389,19 +388,16 @@ prog_rebuild_prerequisites (struct prog *prog)
for (p = proghead; p; p = p->next)
if (p->type == TYPE_COMPONENT)
prog->prereq[depc++] = p->tag;
}
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;
}
size_t
@@ -518,16 +514,16 @@ open_redirector (struct prog *master, int stream)
close (p[0]);
return p[1];
}
}
-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;
size_t len;
while ((ch = *tag++))
@@ -539,34 +535,43 @@ conn_class_hasher (void const *data, size_t n_buckets)
tag++, len--)
value = (value * 31 + *tag) % n_buckets;
return value;
}
/* 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 &&
- memcmp (&p1->sa_storage, &p2->sa_storage, p1->sa_len) == 0 &&
- strcmp (p1->tag, p2->tag) == 0;
+ return !(p1->sa_len == p2->sa_len &&
+ memcmp (&p1->sa_storage, &p2->sa_storage, p1->sa_len) == 0 &&
+ strcmp (p1->tag, p2->tag) == 0);
}
static void
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]));
probe->tag = tag;
probe->sa_storage = *sa_storage_ptr;
probe->sa_len = sa_len;
@@ -583,23 +588,26 @@ conn_class_lookup (const char *tag,
logmsg (LOG_ERR, _("unexpected socket family: %d"),
probe->sa_storage.s.sa_family);
break;
}
probe->count = 0;
+ if (!conn_tab)
+ {
+ conn_tab = grecs_symtab_create(sizeof (struct conn_class),
+ conn_class_hasher,
+ conn_class_compare,
+ conn_class_copy,
+ NULL,
+ conn_class_free);
+ if (!conn_tab)
+ xalloc_die ();
+ }
- if (!((conn_tab
- || (conn_tab = hash_initialize (0, 0,
- conn_class_hasher,
- conn_class_compare,
- conn_class_free)))
- && (ret = hash_insert (conn_tab, probe))))
- xalloc_die ();
-
- if (probe != ret)
- free (probe);
+ ret = grecs_symtab_lookup_or_install (conn_tab, probe, &install);
+ free (probe);
return ret;
}
static void
conn_class_report (struct conn_class *pcclass)
{
@@ -1408,22 +1416,20 @@ 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);
if (!tgt)
{
logmsg (LOG_ERR,
@@ -1431,22 +1437,18 @@ component_fixup_depend (struct component *comp)
"which is not declared"),
comp->tag, tag);
continue;
}
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;
}
void
fixup_prerequisites ()
{

Return to:

Send suggestions and report system problems to the System administrator.