X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Fevent-rule%2Fuserspace-probe.c;h=52c7553e90fc52980b9d24e2b3a50b17148c1813;hb=10685de6af924c0ea83e451697639ed9c16586cc;hp=66db5a6e404dbc4bce90d2e2dbd4cb13394e4985;hpb=e957bf98e634c79b13281d0a2fe144be0245d310;p=lttng-tools.git diff --git a/src/common/event-rule/userspace-probe.c b/src/common/event-rule/userspace-probe.c index 66db5a6e4..52c7553e9 100644 --- a/src/common/event-rule/userspace-probe.c +++ b/src/common/event-rule/userspace-probe.c @@ -187,7 +187,35 @@ lttng_event_rule_userspace_probe_hash( return hash; } -struct lttng_event_rule *lttng_event_rule_userspace_probe_create(void) +static +int userspace_probe_set_location( + struct lttng_event_rule_userspace_probe *uprobe, + const struct lttng_userspace_probe_location *location) +{ + int ret; + struct lttng_userspace_probe_location *location_copy = NULL; + + if (!uprobe || !location || uprobe->location) { + ret = -1; + goto end; + } + + location_copy = lttng_userspace_probe_location_copy(location); + if (!location_copy) { + ret = -1; + goto end; + } + + uprobe->location = location_copy; + location_copy = NULL; + ret = 0; +end: + lttng_userspace_probe_location_destroy(location_copy); + return ret; +} + +struct lttng_event_rule *lttng_event_rule_userspace_probe_create( + const struct lttng_userspace_probe_location *location) { struct lttng_event_rule *rule = NULL; struct lttng_event_rule_userspace_probe *urule; @@ -212,6 +240,11 @@ struct lttng_event_rule *lttng_event_rule_userspace_probe_create(void) lttng_event_rule_userspace_probe_generate_exclusions; urule->parent.hash = lttng_event_rule_userspace_probe_hash; + if (userspace_probe_set_location(urule, location)) { + lttng_event_rule_destroy(rule); + rule = NULL; + } + end: return rule; } @@ -226,8 +259,7 @@ ssize_t lttng_event_rule_userspace_probe_create_from_payload( const char *name; struct lttng_buffer_view current_buffer_view; struct lttng_event_rule *rule = NULL; - struct lttng_userspace_probe_location *location; - struct lttng_event_rule_userspace_probe *uprobe; + struct lttng_userspace_probe_location *location = NULL; enum lttng_event_rule_status status; if (!_event_rule) { @@ -244,12 +276,6 @@ ssize_t lttng_event_rule_userspace_probe_create_from_payload( } uprobe_comm = (typeof(uprobe_comm)) current_buffer_view.data; - rule = lttng_event_rule_userspace_probe_create(); - if (!rule) { - ERR("Failed to create event rule uprobe"); - ret = -1; - goto end; - } /* Skip to payload. */ offset += current_buffer_view.size; @@ -297,10 +323,14 @@ ssize_t lttng_event_rule_userspace_probe_create_from_payload( /* Skip after the location. */ offset += uprobe_comm->location_len; - uprobe = container_of(rule, struct lttng_event_rule_userspace_probe, parent); - uprobe->location = location; + rule = lttng_event_rule_userspace_probe_create(location); + if (!rule) { + ERR("Failed to create event rule uprobe."); + ret = -1; + goto end; + } - status = lttng_event_rule_userspace_probe_set_name(rule, name); + status = lttng_event_rule_userspace_probe_set_event_name(rule, name); if (status != LTTNG_EVENT_RULE_STATUS_OK) { ret = -1; goto end; @@ -315,40 +345,11 @@ ssize_t lttng_event_rule_userspace_probe_create_from_payload( rule = NULL; ret = offset; end: + lttng_userspace_probe_location_destroy(location); lttng_event_rule_destroy(rule); return ret; } -enum lttng_event_rule_status lttng_event_rule_userspace_probe_set_location( - struct lttng_event_rule *rule, - const struct lttng_userspace_probe_location *location) -{ - struct lttng_userspace_probe_location *location_copy = NULL; - struct lttng_event_rule_userspace_probe *uprobe; - enum lttng_event_rule_status status = LTTNG_EVENT_RULE_STATUS_OK; - - if (!rule || !IS_UPROBE_EVENT_RULE(rule) || !location) { - status = LTTNG_EVENT_RULE_STATUS_INVALID; - goto end; - } - - uprobe = container_of(rule, struct lttng_event_rule_userspace_probe, parent); - location_copy = lttng_userspace_probe_location_copy(location); - if (!location_copy) { - status = LTTNG_EVENT_RULE_STATUS_ERROR; - goto end; - } - - if (uprobe->location) { - lttng_userspace_probe_location_destroy(uprobe->location); - } - - uprobe->location = location_copy; - location_copy = NULL; -end: - lttng_userspace_probe_location_destroy(location_copy); - return status; -} enum lttng_event_rule_status lttng_event_rule_userspace_probe_get_location( const struct lttng_event_rule *rule, @@ -384,7 +385,7 @@ lttng_event_rule_userspace_probe_get_location_mutable( return uprobe->location; } -enum lttng_event_rule_status lttng_event_rule_userspace_probe_set_name( +enum lttng_event_rule_status lttng_event_rule_userspace_probe_set_event_name( struct lttng_event_rule *rule, const char *name) { char *name_copy = NULL; @@ -414,7 +415,7 @@ end: return status; } -enum lttng_event_rule_status lttng_event_rule_userspace_probe_get_name( +enum lttng_event_rule_status lttng_event_rule_userspace_probe_get_event_name( const struct lttng_event_rule *rule, const char **name) { struct lttng_event_rule_userspace_probe *uprobe;