... | ... |
@@ -251,7 +251,7 @@ int main_loop() |
251 | 251 |
/* we need another process to act as the timer*/ |
252 | 252 |
if (timer_list){ |
253 | 253 |
if ((pid=fork())<0){ |
254 |
- LOG(L_CRIT, "main_loop: Cannot fork\n"); |
|
254 |
+ LOG(L_CRIT, "ERRROR: main_loop: Cannot fork\n"); |
|
255 | 255 |
goto error; |
256 | 256 |
} |
257 | 257 |
if (pid==0){ |
... | ... |
@@ -514,11 +514,16 @@ int main(int argc, char** argv) |
514 | 514 |
#endif |
515 | 515 |
|
516 | 516 |
#ifdef SHM_MEM |
517 |
- if (shm_mem_init()==-1) { |
|
517 |
+ if (shm_mem_init()<0) { |
|
518 | 518 |
LOG(L_CRIT, "could not initialize shared memory pool, exiting...\n"); |
519 | 519 |
goto error; |
520 | 520 |
} |
521 | 521 |
#endif |
522 |
+ /*init timer, before parsing the cfg!*/ |
|
523 |
+ if (init_timer()<0){ |
|
524 |
+ LOG(L_CRIT, "could not initialize timer, exiting...\n"); |
|
525 |
+ goto error; |
|
526 |
+ } |
|
522 | 527 |
|
523 | 528 |
yyin=cfg_stream; |
524 | 529 |
if ((yyparse()!=0)||(cfg_errors)){ |
... | ... |
@@ -6,15 +6,42 @@ |
6 | 6 |
#include "dprint.h" |
7 | 7 |
#include "error.h" |
8 | 8 |
#include "config.h" |
9 |
+#ifdef SHM_MEM |
|
10 |
+#include "shm_mem.h" |
|
11 |
+#endif |
|
9 | 12 |
|
10 | 13 |
#include <stdlib.h> |
11 | 14 |
|
12 | 15 |
|
13 | 16 |
struct sr_timer* timer_list=0; |
14 | 17 |
|
15 |
-static int jiffies=0; |
|
18 |
+static int* jiffies=0; |
|
16 | 19 |
static int timer_id=0; |
17 | 20 |
|
21 |
+ |
|
22 |
+ |
|
23 |
+/* ret 0 on success, <0 on error*/ |
|
24 |
+int init_timer() |
|
25 |
+{ |
|
26 |
+#ifdef SHM_MEM |
|
27 |
+ jiffies=shm_malloc(sizeof(int)); |
|
28 |
+#else |
|
29 |
+ /* in this case get_ticks won't work! */ |
|
30 |
+ LOG(L_INFO, "WARNING: no shared memory support compiled in" |
|
31 |
+ " get_ticks won't work\n"); |
|
32 |
+ jiffies=malloc(sizeof(int)); |
|
33 |
+#endif |
|
34 |
+ if (jiffies==0){ |
|
35 |
+ LOG(L_CRIT, "ERROR: init_timer: could not init jiffies\n"); |
|
36 |
+ return E_OUT_OF_MEM; |
|
37 |
+ } |
|
38 |
+ *jiffies=0; |
|
39 |
+ return 0; |
|
40 |
+} |
|
41 |
+ |
|
42 |
+ |
|
43 |
+ |
|
44 |
+ |
|
18 | 45 |
/*register a periodic timer; |
19 | 46 |
* ret: <0 on error*/ |
20 | 47 |
int register_timer(timer_function f, void* param, unsigned int interval) |
... | ... |
@@ -30,7 +57,7 @@ int register_timer(timer_function f, void* param, unsigned int interval) |
30 | 57 |
t->timer_f=f; |
31 | 58 |
t->t_param=param; |
32 | 59 |
t->interval=interval; |
33 |
- t->expires=jiffies+interval; |
|
60 |
+ t->expires=*jiffies+interval; |
|
34 | 61 |
/* insert it into the list*/ |
35 | 62 |
t->next=timer_list; |
36 | 63 |
timer_list=t; |
... | ... |
@@ -47,23 +74,23 @@ void timer_ticker() |
47 | 74 |
struct sr_timer* t; |
48 | 75 |
unsigned int prev_jiffies; |
49 | 76 |
|
50 |
- prev_jiffies=jiffies; |
|
51 |
- jiffies+=TIMER_TICK; |
|
77 |
+ prev_jiffies=*jiffies; |
|
78 |
+ *jiffies+=TIMER_TICK; |
|
52 | 79 |
/* test for overflow (if tick= 1s =>overflow in 136 years)*/ |
53 |
- if (jiffies<prev_jiffies){ |
|
80 |
+ if (*jiffies<prev_jiffies){ |
|
54 | 81 |
/*force expire & update every timer, a little buggy but it |
55 | 82 |
* happens once in 136 years :) */ |
56 | 83 |
for(t=timer_list;t;t=t->next){ |
57 |
- t->expires=jiffies+t->interval; |
|
58 |
- t->timer_f(jiffies, t->t_param); |
|
84 |
+ t->expires=*jiffies+t->interval; |
|
85 |
+ t->timer_f(*jiffies, t->t_param); |
|
59 | 86 |
} |
60 | 87 |
return; |
61 | 88 |
} |
62 | 89 |
|
63 | 90 |
for (t=timer_list;t; t=t->next){ |
64 |
- if (jiffies>=t->expires){ |
|
65 |
- t->expires=jiffies+t->interval; |
|
66 |
- t->timer_f(jiffies, t->t_param); |
|
91 |
+ if (*jiffies>=t->expires){ |
|
92 |
+ t->expires=*jiffies+t->interval; |
|
93 |
+ t->timer_f(*jiffies, t->t_param); |
|
67 | 94 |
} |
68 | 95 |
} |
69 | 96 |
} |
... | ... |
@@ -72,5 +99,14 @@ void timer_ticker() |
72 | 99 |
|
73 | 100 |
unsigned int get_ticks() |
74 | 101 |
{ |
75 |
- return jiffies; |
|
102 |
+ if (jiffies==0){ |
|
103 |
+ LOG(L_CRIT, "BUG: get_ticks: jiffies not intialized\n"); |
|
104 |
+ return 0; |
|
105 |
+ } |
|
106 |
+#ifndef SHM_MEM |
|
107 |
+ LOG(L_CRIT, "WARNING: get_ticks: no shared memory support compiled in" |
|
108 |
+ ", returning 0 (probably wrong)"); |
|
109 |
+ return 0; |
|
110 |
+#endif |
|
111 |
+ return *jiffies; |
|
76 | 112 |
} |