struct pass_resmon *resmon = monitor->resmon;
int ret;
- /* Add new timer-based resmon to timer_list if it's not created */
+ /* Add new timer-based resmon to timer_list */
if (!resmon_is_created(resmon, RESMON_TIMER, monitor->src_type)) {
- resmon->timer_list =
- g_list_append(resmon->timer_list,
- (gpointer)monitor);
- resmon->timer_state |= monitor->src_type;
+ monitor->timer_id = g_timeout_add((guint)interval,
+ (GSourceFunc)resmon_timer_func,
+ (gpointer)monitor);
+ if (!monitor->timer_id)
+ return -EPERM;
+ monitor->timer_interval = interval;
if (monitor->ops && monitor->ops->init) {
ret = monitor->ops->init(monitor);
- if (ret < 0)
+ if (ret < 0) {
+ g_source_remove(monitor->timer_id);
+ monitor->timer_interval = 0;
return ret;
+ }
}
- /*
- * Remove the registered timer-based resmon in order to update interval
- * of timer-based resmon if it's already created.
- */
+
+ resmon->timer_list = g_list_append(resmon->timer_list,
+ (gpointer)monitor);
+ resmon->timer_state |= monitor->src_type;
+
+ /* Update timer interval of the registered timer-based resmon */
} else {
g_source_remove(monitor->timer_id);
- }
+ monitor->timer_interval = 0;
- /* Add timer-based resmon with new interval to update the interval */
- monitor->timer_id = g_timeout_add((guint)interval,
- (GSourceFunc)resmon_timer_func,
- (gpointer)monitor);
- if (!monitor->timer_id) {
- resmon->timer_list = g_list_remove(resmon->timer_list,
- (gpointer)monitor);
- resmon->timer_state &= ~monitor->src_type;
- return -EPERM;
+ /* Update timer interval of timer-based resmon */
+ monitor->timer_id = g_timeout_add((guint)interval,
+ (GSourceFunc)resmon_timer_func,
+ (gpointer)monitor);
+ if (!monitor->timer_id)
+ return -EPERM;
+ monitor->timer_interval = interval;
}
- monitor->timer_interval = interval;
-
return 0;
}