diff options
author | Dmitry Kozlov <xeb@mail.ru> | 2013-10-15 11:44:28 +0400 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2013-10-15 11:44:28 +0400 |
commit | cdfcd0c5d6f040ea7ce6df13e4cbae3a7ca2c1e0 (patch) | |
tree | a6cbe85d243c171ad549329174c11f0488cc272b /accel-pppd/shaper/shaper.c | |
parent | e112b9a40ce02081d52cfc144a9842ff3b4cd8d4 (diff) | |
download | accel-ppp-cdfcd0c5d6f040ea7ce6df13e4cbae3a7ca2c1e0.tar.gz accel-ppp-cdfcd0c5d6f040ea7ce6df13e4cbae3a7ca2c1e0.zip |
shaper: fixed invalid reference counting (caused unexpected removal of internal structure)
shaper: do not start time range end timer if end time is equal to start time of other range
Signed-off-by: Dmitry Kozlov <xeb@mail.ru>
Diffstat (limited to 'accel-pppd/shaper/shaper.c')
-rw-r--r-- | accel-pppd/shaper/shaper.c | 57 |
1 files changed, 35 insertions, 22 deletions
diff --git a/accel-pppd/shaper/shaper.c b/accel-pppd/shaper/shaper.c index b89ad36a..229ab415 100644 --- a/accel-pppd/shaper/shaper.c +++ b/accel-pppd/shaper/shaper.c @@ -680,16 +680,17 @@ static void time_range_end_timer(struct triton_timer_t *t) log_debug("shaper: time_range_end_timer\n"); pthread_rwlock_rdlock(&shaper_lock); - list_for_each_entry(pd, &shaper_list, entry) + list_for_each_entry(pd, &shaper_list, entry) { + pd->refs++; triton_context_call(pd->ses->ctrl->ctx, (triton_event_func)update_shaper_tr, pd); + } pthread_rwlock_unlock(&shaper_lock); } -static struct time_range_t *parse_range(const char *val) +static struct time_range_t *parse_range(time_t t, const char *val) { char *endptr; int id; - time_t t; struct tm begin_tm, end_tm; struct time_range_t *r; @@ -699,11 +700,9 @@ static struct time_range_t *parse_range(const char *val) if (id <= 0) return NULL; - time(&t); localtime_r(&t, &begin_tm); - begin_tm.tm_sec = 1; + begin_tm.tm_sec = 0; end_tm = begin_tm; - end_tm.tm_sec = 0; endptr = strptime(endptr + 1, "%H:%M", &begin_tm); if (*endptr != '-') @@ -731,7 +730,7 @@ static void load_time_ranges(void) { struct conf_sect_t *s = conf_get_section("shaper"); struct conf_option_t *opt; - struct time_range_t *r; + struct time_range_t *r, *r1; time_t ts; if (!s) @@ -752,24 +751,38 @@ static void load_time_ranges(void) list_for_each_entry(opt, &s->items, entry) { if (strcmp(opt->name, "time-range")) continue; - r = parse_range(opt->val); - if (r) { + r = parse_range(ts, opt->val); + if (r) list_add_tail(&r->entry, &time_range_list); - if (r->begin.expire_tv.tv_sec > r->end.expire_tv.tv_sec) { - if (ts >= r->begin.expire_tv.tv_sec || ts <= r->end.expire_tv.tv_sec) - time_range_begin_timer(&r->begin); - } else { - if (ts >= r->begin.expire_tv.tv_sec && ts <= r->end.expire_tv.tv_sec) - time_range_begin_timer(&r->begin); + else + log_emerg("shaper: failed to parse time-range '%s'\n", opt->val); + } + + list_for_each_entry(r, &time_range_list, entry) { + list_for_each_entry(r1, &time_range_list, entry) { + if (r->end.expire_tv.tv_sec == r1->begin.expire_tv.tv_sec) { + r->end.period = 0; + break; } - if (r->begin.expire_tv.tv_sec < ts) - r->begin.expire_tv.tv_sec += 24 * 60 * 60; - if (r->end.expire_tv.tv_sec < ts) - r->end.expire_tv.tv_sec += 24 * 60 * 60; - triton_timer_add(&shaper_ctx, &r->begin, 1); + } + + if (r->begin.expire_tv.tv_sec > r->end.expire_tv.tv_sec) { + if (ts >= r->begin.expire_tv.tv_sec || ts <= r->end.expire_tv.tv_sec) + time_range_begin_timer(&r->begin); + } else { + if (ts >= r->begin.expire_tv.tv_sec && ts <= r->end.expire_tv.tv_sec) + time_range_begin_timer(&r->begin); + } + + if (r->begin.expire_tv.tv_sec < ts) + r->begin.expire_tv.tv_sec += 24 * 60 * 60; + if (r->end.expire_tv.tv_sec < ts) + r->end.expire_tv.tv_sec += 24 * 60 * 60; + + triton_timer_add(&shaper_ctx, &r->begin, 1); + + if (r->end.period) triton_timer_add(&shaper_ctx, &r->end, 1); - } else - log_emerg("shaper: failed to parse time-range '%s'\n", opt->val); } } |