+/* TODO: is this the best place to perform this? (code wise) */
+/*
+ * Set sock to -1 if reception of more information is not necessary e.g on
+ * unregister. TODO find a better way.
+ *
+ * On success LTTNG_OK. On error, returns lttng_error code.
+ * */
+static enum lttng_error_code prepare_trigger_object(struct lttng_trigger *trigger, int sock)
+{
+ enum lttng_error_code ret;
+ /* Internal object of the trigger might have to "generate" and
+ * "populate" internal field e.g filter bytecode
+ */
+ struct lttng_condition *condition = NULL;
+ condition = lttng_trigger_get_condition(trigger);
+ if (!condition) {
+ ret = LTTNG_ERR_INVALID_TRIGGER;
+ goto end;
+ }
+
+ switch (lttng_condition_get_type(condition)) {
+ case LTTNG_CONDITION_TYPE_EVENT_RULE_HIT:
+ {
+ struct lttng_event_rule *event_rule;
+ const struct lttng_credentials *credential = lttng_trigger_get_credentials(trigger);
+ lttng_condition_event_rule_get_rule_no_const(
+ condition, &event_rule);
+ ret = lttng_event_rule_populate(event_rule, credential->uid, credential->gid);
+ if (ret != LTTNG_OK) {
+ goto end;
+ }
+
+ switch (lttng_event_rule_get_type(event_rule)) {
+ case LTTNG_EVENT_RULE_TYPE_UPROBE:
+ {
+ int fd;
+ struct lttng_userspace_probe_location *location = lttng_event_rule_uprobe_get_location_no_const(event_rule);
+
+ if (sock < 0) {
+ /* Nothing to receive */
+ break;
+ }
+ /*
+ * Receive the file descriptor to the target binary from
+ * the client.
+ */
+ DBG("Receiving userspace probe target FD from client ...");
+ ret = lttcomm_recv_fds_unix_sock(sock, &fd, 1);
+ if (ret <= 0) {
+ DBG("Nothing recv() from client userspace probe fd... continuing");
+ ret = LTTNG_ERR_PROBE_LOCATION_INVAL;
+ goto end;
+ }
+
+ /*
+ * Set the file descriptor received from the client
+ * through the unix socket in the probe location.
+ */
+ ret = lttng_userspace_probe_location_set_binary_fd(
+ location, fd);
+ if (ret) {
+ ret = LTTNG_ERR_PROBE_LOCATION_INVAL;
+ goto end;
+ }
+
+ break;
+ }
+ default:
+ /* Nothing to do */
+ break;
+ }
+ ret = LTTNG_OK;
+ break;
+ }
+ default:
+ {
+ ret = LTTNG_OK;
+ break;
+ }
+ }
+end:
+ return ret;
+}
+
+/* Caller must call lttng_destroy_trigger on the returned trigger object */