X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Flib%2Flttng-ctl%2Flttng-ctl.c;h=5529b3364f12027c8b143fbdcba8a4e7304dad70;hb=b61776fb63d4bb14df77c0b5a15de28beed7ddfc;hp=38df4cb7b11c1234c5b33f8b92d1731ea541585f;hpb=e1b624d005769d1a2e9eb39fee63c73c6395fd76;p=lttng-tools.git diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index 38df4cb7b..5529b3364 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -116,7 +116,8 @@ static int send_session_msg(struct lttcomm_session_msg *lsm) goto end; } - DBG("LSM cmd type : %d", lsm->cmd_type); + DBG("LSM cmd type: '%s' (%d)", lttcomm_sessiond_command_str(lsm->cmd_type), + lsm->cmd_type); ret = lttcomm_send_creds_unix_sock(sessiond_socket, lsm, sizeof(struct lttcomm_session_msg)); @@ -652,7 +653,12 @@ int lttng_ctl_ask_sessiond_payload(struct lttng_payload_view *message, /* Check error code if OK */ if (llm.ret_code != LTTNG_OK) { - ret = -llm.ret_code; + if (llm.ret_code < LTTNG_OK || llm.ret_code >= LTTNG_ERR_NR) { + /* Invalid error code received. */ + ret = -LTTNG_ERR_UNK; + } else { + ret = -llm.ret_code; + } goto end; } @@ -3141,18 +3147,18 @@ int lttng_register_trigger(struct lttng_trigger *trigger) goto end; } - /* - * This is needed to populate the trigger object size for the command - * header. - */ - message_lsm = (struct lttcomm_session_msg *) message.buffer.data; - ret = lttng_trigger_serialize(trigger, &message); if (ret < 0) { ret = -LTTNG_ERR_UNK; goto end; } + /* + * This is needed to populate the trigger object size for the command + * header. + */ + message_lsm = (struct lttcomm_session_msg *) message.buffer.data; + message_lsm->u.trigger.length = (uint32_t) message.buffer.size - sizeof(lsm); { @@ -3195,13 +3201,14 @@ end: return ret; } -int lttng_unregister_trigger(struct lttng_trigger *trigger) +int lttng_unregister_trigger(const struct lttng_trigger *trigger) { int ret; struct lttcomm_session_msg lsm; struct lttcomm_session_msg *message_lsm; struct lttng_payload message; struct lttng_payload reply; + struct lttng_trigger *copy = NULL; const struct lttng_credentials user_creds = { .uid = LTTNG_OPTIONAL_INIT_VALUE(geteuid()), .gid = LTTNG_OPTIONAL_INIT_UNSET, @@ -3215,9 +3222,15 @@ int lttng_unregister_trigger(struct lttng_trigger *trigger) goto end; } - if (!trigger->creds.uid.is_set) { - /* Use the client's credentials as the trigger credentials. */ - lttng_trigger_set_credentials(trigger, &user_creds); + copy = lttng_trigger_copy(trigger); + if (!copy) { + ret = -LTTNG_ERR_UNK; + goto end; + } + + if (!copy->creds.uid.is_set) { + /* Use the client credentials as the trigger credentials */ + lttng_trigger_set_credentials(copy, &user_creds); } else { /* * Validate that either the current trigger credentials and the @@ -3230,8 +3243,7 @@ int lttng_unregister_trigger(struct lttng_trigger *trigger) * "safety" checks. */ const struct lttng_credentials *trigger_creds = - lttng_trigger_get_credentials(trigger); - + lttng_trigger_get_credentials(copy); if (!lttng_credentials_is_equal_uid(trigger_creds, &user_creds)) { if (lttng_credentials_get_uid(&user_creds) != 0) { ret = -LTTNG_ERR_EPERM; @@ -3240,7 +3252,7 @@ int lttng_unregister_trigger(struct lttng_trigger *trigger) } } - if (!lttng_trigger_validate(trigger)) { + if (!lttng_trigger_validate(copy)) { ret = -LTTNG_ERR_INVALID_TRIGGER; goto end; } @@ -3260,7 +3272,7 @@ int lttng_unregister_trigger(struct lttng_trigger *trigger) */ message_lsm = (struct lttcomm_session_msg *) message.buffer.data; - ret = lttng_trigger_serialize(trigger, &message); + ret = lttng_trigger_serialize(copy, &message); if (ret < 0) { ret = -LTTNG_ERR_UNK; goto end; @@ -3288,6 +3300,7 @@ int lttng_unregister_trigger(struct lttng_trigger *trigger) ret = 0; end: + lttng_trigger_destroy(copy); lttng_payload_reset(&message); lttng_payload_reset(&reply); return ret;