summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorGuillaume Friloux <guillaume.friloux@gmail.com>2013-12-27 09:28:53 +0100
committerGuillaume Friloux <guillaume.friloux@gmail.com>2013-12-27 09:28:53 +0100
commit1e835f4f36c5b66630606aae0510604d90d1a2c3 (patch)
tree4af575705ad860d727d45a60f7d9446b67a89d46 /src/lib
parent7648d81d7cab7a537c3c7f6a660e394bb097f765 (diff)
Make Smman catch SIGUSR1 signals to reload rules. Make Smman v2.0.0
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/rules/rules_load.c7
-rw-r--r--src/lib/rules/rules_main.c23
-rw-r--r--src/lib/spy/spy_main.c28
-rw-r--r--src/lib/spy/spy_private.h1
4 files changed, 50 insertions, 9 deletions
diff --git a/src/lib/rules/rules_load.c b/src/lib/rules/rules_load.c
index c961739..a4f24af 100644
--- a/src/lib/rules/rules_load.c
+++ b/src/lib/rules/rules_load.c
@@ -83,6 +83,8 @@ rules_load_rule(void *data,
83 } 83 }
84 eina_iterator_free(it); 84 eina_iterator_free(it);
85 rl->cb.progress((void *)rl->cb.data, rl->rules, rule); 85 rl->cb.progress((void *)rl->cb.data, rl->rules, rule);
86 rl->rules->rules = eina_inlist_append(rl->rules->rules,
87 EINA_INLIST_GET(rule));
86} 88}
87 89
88void 90void
@@ -127,10 +129,13 @@ rules_load_ls(void *data,
127} 129}
128 130
129void 131void
130rules_load_ls_done(void *data EINA_UNUSED, 132rules_load_ls_done(void *data,
131 Eio_File *handler EINA_UNUSED) 133 Eio_File *handler EINA_UNUSED)
132{ 134{
135 Rules_Load *rl = data;
133 DBG("End of rules listing."); 136 DBG("End of rules listing.");
137 rl->cb.done((void *)rl->cb.data, rl->rules);
138 free(rl);
134} 139}
135 140
136 141
diff --git a/src/lib/rules/rules_main.c b/src/lib/rules/rules_main.c
index e1f73a8..208dead 100644
--- a/src/lib/rules/rules_main.c
+++ b/src/lib/rules/rules_main.c
@@ -7,20 +7,26 @@ int _rules_log_dom_global = -1;
7void 7void
8rules_rule_free(Rule *rule) 8rules_rule_free(Rule *rule)
9{ 9{
10 Rule_Regex *rr; 10 char *s;
11 EINA_SAFETY_ON_NULL_RETURN(rule); 11 EINA_SAFETY_ON_NULL_RETURN(rule);
12 12
13 free((char *)rule->name); 13 free((char *)rule->name);
14 free((char *)rule->spec.filename); 14 free((char *)rule->spec.filename);
15 free((char *)rule->spec.source_host); 15 free((char *)rule->spec.source_host);
16 free((char *)rule->spec.source_path); 16 free((char *)rule->spec.source_path);
17 free((char *)rule->spec.tags);
18 17
19 EINA_INLIST_FOREACH(rule->spec.regex, rr) 18 EINA_LIST_FREE(rule->spec.tags, s)
19 free(s);
20
21 while (rule->spec.regex)
20 { 22 {
23 Rule_Regex *rr = EINA_INLIST_CONTAINER_GET(rule->spec.regex, Rule_Regex);
24 rule->spec.regex = eina_inlist_remove(rule->spec.regex,rule->spec.regex);
25 regfree(&(rr->preg));
21 free((char *)rr->regex); 26 free((char *)rr->regex);
22 free(rr); 27 free(rr);
23 } 28 }
29 free(rule);
24} 30}
25 31
26Rules * 32Rules *
@@ -33,6 +39,17 @@ rules_new(const char *directory)
33 return rules; 39 return rules;
34} 40}
35 41
42void
43rules_purge(Rules *rules)
44{
45 while (rules->rules)
46 {
47 Rule *rule = EINA_INLIST_CONTAINER_GET(rules->rules, Rule);
48 rules->rules = eina_inlist_remove(rules->rules, rules->rules);
49 rules_rule_free(rule);
50 }
51}
52
36Eina_Bool 53Eina_Bool
37rules_load(Rules *rules, 54rules_load(Rules *rules,
38 Rules_Progress_Cb progress_cb, 55 Rules_Progress_Cb progress_cb,
diff --git a/src/lib/spy/spy_main.c b/src/lib/spy/spy_main.c
index 3cc7f0c..1e512a0 100644
--- a/src/lib/spy/spy_main.c
+++ b/src/lib/spy/spy_main.c
@@ -26,12 +26,30 @@ spy_free(Spy *spy)
26 EINA_SAFETY_ON_NULL_RETURN(spy); 26 EINA_SAFETY_ON_NULL_RETURN(spy);
27 27
28 EINA_INLIST_FOREACH_SAFE(spy->files, l, sf) 28 EINA_INLIST_FOREACH_SAFE(spy->files, l, sf)
29 spy_file_free(sf);
30 free(spy);
31}
32
33void
34spy_file_free(Spy_File *sf)
35{
36 Spy_File *tmp;
37
38 EINA_SAFETY_ON_NULL_RETURN(sf);
39
40 EINA_INLIST_FOREACH(sf->spy->files, tmp)
29 { 41 {
30 free((char *)sf->name); 42 if (sf != tmp)
31 ecore_timer_del(sf->poll.timer); 43 continue;
32 eina_strbuf_free(sf->read.buf); 44
45 sf->spy->files = eina_inlist_remove(sf->spy->files, sf->spy->files);
46 break;
33 } 47 }
34 free(spy); 48
49 free((char *)sf->name);
50 ecore_timer_del(sf->poll.timer);
51 eina_strbuf_free(sf->read.buf);
52 free(sf);
35} 53}
36 54
37void 55void
@@ -107,7 +125,7 @@ spy_file_new(Spy *spy, const char *file)
107 125
108 sf->poll.size = st.st_size; 126 sf->poll.size = st.st_size;
109 sf->poll.timer = ecore_timer_loop_add(0.3, spy_file_poll, sf); 127 sf->poll.timer = ecore_timer_loop_add(0.3, spy_file_poll, sf);
110 ecore_timer_precision_set(1.0); 128 sf->spy = spy;
111 129
112 spy->files = eina_inlist_append(spy->files, EINA_INLIST_GET(sf)); 130 spy->files = eina_inlist_append(spy->files, EINA_INLIST_GET(sf));
113 DBG("spy_file[%p] size[%zd]", sf, st.st_size); 131 DBG("spy_file[%p] size[%zd]", sf, st.st_size);
diff --git a/src/lib/spy/spy_private.h b/src/lib/spy/spy_private.h
index 26ddfae..4851bc9 100644
--- a/src/lib/spy/spy_private.h
+++ b/src/lib/spy/spy_private.h
@@ -19,6 +19,7 @@ struct _Spy_File
19 EINA_INLIST; 19 EINA_INLIST;
20 const char *name; 20 const char *name;
21 const void *data; 21 const void *data;
22 Spy *spy;
22 23
23 struct 24 struct
24 { 25 {