summaryrefslogtreecommitdiff
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
parent7648d81d7cab7a537c3c7f6a660e394bb097f765 (diff)
Make Smman catch SIGUSR1 signals to reload rules. Make Smman v2.0.0
-rw-r--r--configure.ac4
-rw-r--r--src/bin/filter.c46
-rw-r--r--src/bin/main.c1
-rw-r--r--src/bin/smman.h4
-rw-r--r--src/include/Rules.h1
-rw-r--r--src/include/Spy.h1
-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
10 files changed, 102 insertions, 14 deletions
diff --git a/configure.ac b/configure.ac
index 0c0c1c2..5f3b7f6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,6 +1,6 @@
1m4_define([v_maj], [1]) 1m4_define([v_maj], [2])
2m4_define([v_min], [0]) 2m4_define([v_min], [0])
3m4_define([v_mic], [1]) 3m4_define([v_mic], [0])
4m4_define([v_ver], [v_maj.v_min.v_mic]) 4m4_define([v_ver], [v_maj.v_min.v_mic])
5 5
6AC_INIT([smman], [v_ver], [kuri@efl.so]) 6AC_INIT([smman], [v_ver], [kuri@efl.so])
diff --git a/src/bin/filter.c b/src/bin/filter.c
index fec905e..a75c364 100644
--- a/src/bin/filter.c
+++ b/src/bin/filter.c
@@ -2,9 +2,32 @@
2#include <glob.h> 2#include <glob.h>
3 3
4static void 4static void
5_filter_rules_free(void *data) 5_filter_rules_free(void *data EINA_UNUSED)
6{ 6{
7 rules_rule_free((Rule *)data); 7}
8
9Eina_Bool
10filter_reload(void *data,
11 int type EINA_UNUSED,
12 void *ev EINA_UNUSED)
13{
14 Smman *smman = data;
15 Filter *filter;
16
17 DBG("smman[%p]", smman);
18
19 EINA_INLIST_FOREACH(smman->filters, filter)
20 {
21 spy_file_pause(filter->sf);
22 eina_hash_free(filter->rules);
23 filter->rules = eina_hash_string_superfast_new(_filter_rules_free);
24 }
25
26 rules_purge(smman->rules);
27
28 rules_load(smman->rules, filter_load, filter_load_done,
29 filter_load_error, smman);
30 return EINA_TRUE;
8} 31}
9 32
10Filter * 33Filter *
@@ -90,12 +113,31 @@ filter_load_done(void *data,
90 Rules *rules) 113 Rules *rules)
91{ 114{
92 Smman *smman; 115 Smman *smman;
116 Filter *filter;
117 Eina_Inlist *l;
93 118
94 smman = data; 119 smman = data;
95 if (smman->rules != rules) 120 if (smman->rules != rules)
96 return; 121 return;
97 122
98 DBG("smman[%p] rules[%p]", smman, rules); 123 DBG("smman[%p] rules[%p]", smman, rules);
124
125 EINA_INLIST_FOREACH_SAFE(smman->filters, l, filter)
126 {
127 if (eina_hash_population(filter->rules))
128 {
129 DBG("Resuming sf[%p]", filter->sf);
130 spy_file_resume(filter->sf);
131 continue;
132 }
133
134 DBG("Freeing filter %s", filter->filename);
135 smman->filters = eina_inlist_remove(smman->filters, smman->filters);
136 spy_file_free(filter->sf);
137 free((char *)filter->filename);
138 eina_hash_free(filter->rules);
139 free(filter);
140 }
99} 141}
100 142
101void 143void
diff --git a/src/bin/main.c b/src/bin/main.c
index 9a73992..34d45b9 100644
--- a/src/bin/main.c
+++ b/src/bin/main.c
@@ -77,6 +77,7 @@ init(void)
77 } 77 }
78 78
79 smman->ev.sl = ecore_event_handler_add(SPY_EVENT_LINE,log_line_event, smman); 79 smman->ev.sl = ecore_event_handler_add(SPY_EVENT_LINE,log_line_event, smman);
80 smman->ev.su = ecore_event_handler_add(ECORE_EVENT_SIGNAL_USER, filter_reload, smman);
80 return smman; 81 return smman;
81} 82}
82 83
diff --git a/src/bin/smman.h b/src/bin/smman.h
index d912ffa..55584a7 100644
--- a/src/bin/smman.h
+++ b/src/bin/smman.h
@@ -29,7 +29,8 @@ typedef struct _Smman
29 29
30 struct 30 struct
31 { 31 {
32 Ecore_Event_Handler *sl; /* SPY_EVENT_LINE */ 32 Ecore_Event_Handler *sl, /* SPY_EVENT_LINE */
33 *su; /* ECORE_EVENT_SIGNAL_USER */
33 } ev; 34 } ev;
34} Smman; 35} Smman;
35 36
@@ -53,6 +54,7 @@ void config_error(void *data, Conf *conf, const char *errstr);
53void filter_load(void *data, Rules *rules, Rule *rule); 54void filter_load(void *data, Rules *rules, Rule *rule);
54void filter_load_done(void *data, Rules *rules); 55void filter_load_done(void *data, Rules *rules);
55void filter_load_error(void *data, Rules *rules, const char *errstr); 56void filter_load_error(void *data, Rules *rules, const char *errstr);
57Eina_Bool filter_reload(void *data, int type, void *ev);
56 58
57Eina_Bool log_line_event(void *data, int type, void *event); 59Eina_Bool log_line_event(void *data, int type, void *event);
58 60
diff --git a/src/include/Rules.h b/src/include/Rules.h
index fbd30be..fc8518d 100644
--- a/src/include/Rules.h
+++ b/src/include/Rules.h
@@ -44,6 +44,7 @@ int rules_init(void);
44int rules_shutdown(void); 44int rules_shutdown(void);
45 45
46Rules * rules_new(const char *directory); 46Rules * rules_new(const char *directory);
47void rules_purge(Rules *rules);
47Eina_Bool rules_load(Rules *rules, Rules_Progress_Cb progress_cb, Rules_Done_Cb done_cb, Rules_Error_Cb error_cb, void *data); 48Eina_Bool rules_load(Rules *rules, Rules_Progress_Cb progress_cb, Rules_Done_Cb done_cb, Rules_Error_Cb error_cb, void *data);
48 49
49void rules_rule_free(Rule *rule); 50void rules_rule_free(Rule *rule);
diff --git a/src/include/Spy.h b/src/include/Spy.h
index 4064d62..3590075 100644
--- a/src/include/Spy.h
+++ b/src/include/Spy.h
@@ -16,6 +16,7 @@ int spy_shutdown(void);
16Spy * spy_new(void); 16Spy * spy_new(void);
17void spy_free(Spy *spy); 17void spy_free(Spy *spy);
18 18
19void spy_file_free(Spy_File *sf);
19Spy_File * spy_file_new(Spy *spy, const char *file); 20Spy_File * spy_file_new(Spy *spy, const char *file);
20Spy_File * spy_file_get(Spy *spy, const char *file); 21Spy_File * spy_file_get(Spy *spy, const char *file);
21const char * spy_file_name_get(Spy_File *sf); 22const char * spy_file_name_get(Spy_File *sf);
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 {