1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605
|
/*
* SPDX-FileCopyrightText: 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
*
* SPDX-License-Identifier: LGPL-2.1-only
*
*/
#ifndef LTTNG_TRIGGER_H
#define LTTNG_TRIGGER_H
#include <lttng/constant.h>
#include <lttng/lttng-error.h>
#include <lttng/lttng-export.h>
#include <inttypes.h>
#include <sys/types.h>
#ifdef __cplusplus
extern "C" {
#endif
/*!
@addtogroup api_trigger
@{
*/
struct lttng_action;
struct lttng_condition;
/*!
@struct lttng_trigger
@brief
Trigger (opaque type).
*/
struct lttng_trigger;
/*!
@struct lttng_triggers
@brief
Trigger list (opaque type).
*/
struct lttng_triggers;
enum lttng_register_trigger_status {
LTTNG_REGISTER_TRIGGER_STATUS_OK = 0,
LTTNG_REGISTER_TRIGGER_STATUS_INVALID = -1,
};
/*!
@brief
Return type of trigger API functions.
*/
enum lttng_trigger_status {
/// Success.
LTTNG_TRIGGER_STATUS_OK = 0,
/// Error.
LTTNG_TRIGGER_STATUS_ERROR = -1,
/* Unused for the moment */
LTTNG_TRIGGER_STATUS_UNKNOWN = -2,
LTTNG_TRIGGER_STATUS_UNSUPPORTED = -5,
/// Unsatisfied precondition.
LTTNG_TRIGGER_STATUS_INVALID = -3,
/// Not set.
LTTNG_TRIGGER_STATUS_UNSET = -4,
/// Permission denied.
LTTNG_TRIGGER_STATUS_PERMISSION_DENIED = -6,
};
/*!
@brief
Creates a trigger to attempt to execute the
\ref api_trigger_action "action" \lt_p{action}
when the \ref api_trigger_cond "condition" \lt_p{condition}
is satisfied.
This function only creates the trigger object, but doesn't register it
to the LTTng session daemon: use
lttng_register_trigger_with_automatic_name() or
lttng_register_trigger_with_name().
@param[in] condition
Condition of the trigger to create (not moved).
@param[in] action
@parblock
Action of the trigger to create (not moved).
If you need LTTng to execute more than one action when
\lt_p{condition} is satisfied, then use an
\ref api_trigger_action_list "action list".
@endparblock
@returns
@parblock
Trigger on success, or \c NULL on error.
Destroy the returned trigger with lttng_trigger_destroy().
@endparblock
@pre
@lt_pre_not_null{condition}
@lt_pre_not_null{action}
*/
LTTNG_EXPORT extern struct lttng_trigger *lttng_trigger_create(struct lttng_condition *condition,
struct lttng_action *action);
/*!
@brief
Sets the owner Unix user ID (UID) of the trigger \lt_p{trigger} to
\lt_p{uid}.
This function can only succeed if your Unix user is \c root and you're
\ref api-gen-sessiond-conn "connecting" to a root LTTng session daemon.
When you register \lt_p{trigger} with lttng_register_trigger_with_name()
or lttng_register_trigger_with_automatic_name() after calling this
function, it's equivalent to some process of Unix user \lt_p{uid}, part
of the tracing group, doing it.
@param[in] trigger
Trigger of which to set the owner UID to \lt_p{uid}.
@param[in] uid
Owner UID of \lt_p{trigger}.
@retval #LTTNG_TRIGGER_STATUS_OK
Success.
@retval #LTTNG_TRIGGER_STATUS_PERMISSION_DENIED
Permission denied.
@retval #LTTNG_TRIGGER_STATUS_INVALID
Unsatisfied precondition.
@pre
- Your Unix user is <code>root</code> (UID 0).
@lt_pre_not_null{trigger}
- \lt_p{trigger} isn't registered yet (you didn't call
lttng_register_trigger_with_name() or
lttng_register_trigger_with_automatic_name() with it).
@sa lttng_trigger_get_owner_uid() --
Get the owner UID of a trigger.
*/
LTTNG_EXPORT extern enum lttng_trigger_status
lttng_trigger_set_owner_uid(struct lttng_trigger *trigger, uid_t uid);
/*!
@brief
Sets \lt_p{*uid} to the owner Unix user ID (UID) of the trigger
\lt_p{trigger}.
@param[in] trigger
Trigger of which to get the owner UID.
@param[out] uid
<strong>On success</strong>, this function sets \lt_p{*uid}
to the owner UID of \lt_p{trigger}.
@retval #LTTNG_TRIGGER_STATUS_OK
Success.
@retval #LTTNG_TRIGGER_STATUS_UNSET
\lt_p{trigger} has no specific owner UID.
@retval #LTTNG_TRIGGER_STATUS_INVALID
Unsatisfied precondition.
@pre
@lt_pre_not_null{trigger}
@lt_pre_not_null{uid}
@sa lttng_trigger_set_owner_uid() --
Set the owner UID of a trigger.
*/
LTTNG_EXPORT extern enum lttng_trigger_status
lttng_trigger_get_owner_uid(const struct lttng_trigger *trigger, uid_t *uid);
/*!
@brief
Returns the \ref api_trigger_cond "condition" of the
trigger \lt_p{trigger}.
@param[in] trigger
Trigger of which to get the condition.
@returns
@parblock
Condition of \lt_p{trigger}, or \c NULL on error.
\lt_p{trigger} owns the returned condition.
The returned condition remains valid as long
as \lt_p{trigger} exists.
@endparblock
@pre
@lt_pre_not_null{trigger}
*/
LTTNG_EXPORT extern struct lttng_condition *
lttng_trigger_get_condition(struct lttng_trigger *trigger);
/*!
@brief
Returns the \ref api_trigger_cond "condition" of the
trigger \lt_p{trigger} (<code>const</code> version).
@param[in] trigger
Trigger of which to get the condition.
@returns
@parblock
Condition of \lt_p{trigger}, or \c NULL on error.
\lt_p{trigger} owns the returned condition.
The returned condition remains valid as long
as \lt_p{trigger} exists.
@endparblock
@pre
@lt_pre_not_null{trigger}
*/
LTTNG_EXPORT extern const struct lttng_condition *
lttng_trigger_get_const_condition(const struct lttng_trigger *trigger);
/*!
@brief
Returns the \ref api_trigger_action "action" of the
trigger \lt_p{trigger}.
@param[in] trigger
Trigger of which to get the action.
@returns
@parblock
Action of \lt_p{trigger}, or \c NULL on error.
\lt_p{trigger} owns the returned action.
The returned action remains valid as long
as \lt_p{trigger} exists.
@endparblock
@pre
@lt_pre_not_null{trigger}
*/
LTTNG_EXPORT extern struct lttng_action *lttng_trigger_get_action(struct lttng_trigger *trigger);
/*!
@brief
Returns the \ref api_trigger_action "action" of the
trigger \lt_p{trigger} (<code>const</code> version).
@param[in] trigger
Trigger of which to get the action.
@returns
@parblock
Action of \lt_p{trigger}, or \c NULL on error.
\lt_p{trigger} owns the returned action.
The returned action remains valid as long
as \lt_p{trigger} exists.
@endparblock
@pre
@lt_pre_not_null{trigger}
*/
LTTNG_EXPORT extern const struct lttng_action *
lttng_trigger_get_const_action(const struct lttng_trigger *trigger);
/*!
@brief
Sets \lt_p{*name} to the name of the trigger \lt_p{trigger}.
@param[in] trigger
Trigger of which to get the name.
@param[out] name
@parblock
<strong>On success</strong>, this function sets \lt_p{*name}
to the name of \lt_p{trigger}.
\lt_p{trigger} owns \lt_p{*name}.
\lt_p{*name} remains valid until the next
function call with \lt_p{trigger}.
@endparblock
@retval #LTTNG_TRIGGER_STATUS_OK
Success.
@retval #LTTNG_TRIGGER_STATUS_UNSET
\lt_p{trigger} has no name.
@retval #LTTNG_TRIGGER_STATUS_INVALID
Unsatisfied precondition.
@pre
@lt_pre_not_null{trigger}
@lt_pre_not_null{name}
*/
LTTNG_EXPORT extern enum lttng_trigger_status
lttng_trigger_get_name(const struct lttng_trigger *trigger, const char **name);
/*!
@brief
Destroys the trigger \lt_p{trigger}.
@param[in] trigger
@parblock
Trigger to destroy.
May be \c NULL.
@endparblock
*/
LTTNG_EXPORT extern void lttng_trigger_destroy(struct lttng_trigger *trigger);
/*!
@brief
Registers the trigger \lt_p{trigger} to the session daemon
with the name \lt_p{name}.
This function
\ref api-gen-sessiond-conn "connects to the session daemon" to
register \lt_p{trigger}.
If lttng_trigger_get_owner_uid() returns #LTTNG_TRIGGER_STATUS_UNSET
with \lt_p{trigger}, then this function sets your current UID as the
owner UID for \lt_p{trigger}.
@param[in] trigger
@parblock
Trigger to register to the session daemon (not moved).
It's safe to destroy \lt_p{trigger} with lttng_trigger_destroy()
after calling this function.
@endparblock
@param[in] name
Name of the trigger to register (copied).
@returns
<dl>
<dt>#LTTNG_OK
<dd>Success
<dt>Another #lttng_error_code enumerator
<dd>Error
</dl>
@pre
@lt_pre_conn
@lt_pre_not_null{trigger}
- You created \lt_p{trigger} with lttng_trigger_create().
- The condition and action of \lt_p{trigger} are valid.
The documentation of each trigger condition and action creation
function indicates how to build a valid condition/action.
- Your Unix user ID (UID) is either 0 (<code>root</code>) or
the same as the
\link lttng_trigger_get_owner_uid() owner UID\endlink of
\lt_p{trigger}.
@lt_pre_not_null{name}
- No other trigger with the same
\link lttng_trigger_get_owner_uid() owner UID\endlink
has the name \lt_p{name}.
@sa lttng_register_trigger_with_automatic_name() --
Register a trigger with a generated unique name.
@sa lttng_unregister_trigger() --
Unregister a trigger.
*/
LTTNG_EXPORT extern enum lttng_error_code
lttng_register_trigger_with_name(struct lttng_trigger *trigger, const char *name);
/*!
@brief
Registers the trigger \lt_p{trigger} to the session daemon
with a generated unique name.
This function
\ref api-gen-sessiond-conn "connects to the session daemon" to
register \lt_p{trigger}.
If lttng_trigger_get_owner_uid() returns #LTTNG_TRIGGER_STATUS_UNSET
with \lt_p{trigger}, then this function sets your current UID as the
owner UID for \lt_p{trigger}.
@param[in] trigger
@parblock
Trigger to register to the session daemon (not moved).
It's safe to destroy \lt_p{trigger} with lttng_trigger_destroy()
after calling this function.
@endparblock
@returns
<dl>
<dt>#LTTNG_OK
<dd>Success
<dt>Another #lttng_error_code enumerator
<dd>Error
</dl>
@pre
@lt_pre_conn
@lt_pre_not_null{trigger}
- You created \lt_p{trigger} with lttng_trigger_create().
- The condition and action of \lt_p{trigger} are valid.
The documentation of each trigger condition and action creation
function indicates how to build a valid condition/action.
- Your Unix user ID (UID) is either 0 (<code>root</code>) or
the same as the
\link lttng_trigger_get_owner_uid() owner UID\endlink of
\lt_p{trigger}.
@sa lttng_register_trigger_with_name() --
Register a trigger with a specific name.
@sa lttng_unregister_trigger() --
Unregister a trigger.
*/
LTTNG_EXPORT extern enum lttng_error_code
lttng_register_trigger_with_automatic_name(struct lttng_trigger *trigger);
/*!
@brief
Unregisters the trigger \lt_p{trigger} from the session daemon.
This function
\ref api-gen-sessiond-conn "connects to the session daemon" to
unregister \lt_p{trigger}.
@param[in] trigger
@parblock
Trigger to unregister from the session daemon (not moved).
It's safe to destroy \lt_p{trigger} with lttng_trigger_destroy()
after calling this function.
@endparblock
@returns
<dl>
<dt>0
<dd>Success
<dt>\em Negative #lttng_error_code enumerator
<dd>Error
</dl>
@pre
@lt_pre_conn
@lt_pre_not_null{trigger}
- \lt_p{trigger} is currently registered to the session daemon
to connect to.
- Your Unix user ID (UID) is either 0 (<code>root</code>) or
the same as the
\link lttng_trigger_get_owner_uid() owner UID\endlink of
\lt_p{trigger}.
@sa lttng_register_trigger_with_automatic_name() --
Register a trigger with a generated unique name.
@sa lttng_register_trigger_with_name() --
Register a trigger with a specific name.
*/
LTTNG_EXPORT extern int lttng_unregister_trigger(const struct lttng_trigger *trigger);
/*!
@brief
Sets \lt_p{*triggers} to a list of available triggers.
This function
\ref api-gen-sessiond-conn "connects to the session daemon" to
list triggers.
The available triggers are, depending on your
Unix user ID (UID):
<dl>
<dt>0 (<code>root</code>)
<dd>All the triggers of the session daemon to connect to.
<dt>Other UID \lt_var{UID}
<dd>Only the triggers having the owner UID \lt_var{UID}.
</dl>
@param[out] triggers
@parblock
<strong>On success</strong>, this function sets \lt_p{*triggers}
to a list of available triggers.
Destroy the returned trigger list with lttng_triggers_destroy().
@endparblock
@returns
<dl>
<dt>#LTTNG_OK
<dd>Success
<dt>Another #lttng_error_code enumerator
<dd>Error
</dl>
@pre
@lt_pre_conn
@lt_pre_not_null{triggers}
@sa lttng_triggers_get_count() --
Get the length of a trigger list.
@sa lttng_triggers_get_at_index() --
Get a trigger from a trigger list by index.
*/
LTTNG_EXPORT extern enum lttng_error_code lttng_list_triggers(struct lttng_triggers **triggers);
/*!
@brief
Returns the trigger of the trigger list \lt_p{triggers}
at the index \lt_p{index}.
@param[in] triggers
Trigger list of which to get the trigger
at the index \lt_p{index}.
@param[in] index
Index of the trigger to get from \lt_p{triggers}.
@returns
@parblock
Trigger of the triggers
\lt_p{triggers} at the index \lt_p{index}, or \c NULL on error.
\lt_p{triggers} owns the returned trigger.
The returned trigger remains valid as long
as \lt_p{triggers} exists.
@endparblock
@pre
@lt_pre_not_null{triggers}
- \lt_p{index} is less than the number of triggers
(as returned by lttng_triggers_get_count())
of \lt_p{triggers}.
@sa lttng_triggers_get_count() --
Get the length of a trigger list.
*/
LTTNG_EXPORT extern const struct lttng_trigger *
lttng_triggers_get_at_index(const struct lttng_triggers *triggers, unsigned int index);
/*!
@brief
Sets \lt_p{*count} to the number of triggers contained in
the trigger list \lt_p{triggers}.
@param[in] triggers
Trigger list of which to get the number of contained triggers.
@param[out] count
<strong>On success</strong>, this function sets \lt_p{*count}
to the number of triggers in \lt_p{triggers}.
@retval #LTTNG_TRIGGER_STATUS_OK
Success.
@retval #LTTNG_TRIGGER_STATUS_INVALID
Unsatisfied precondition.
@pre
@lt_pre_not_null{triggers}
@lt_pre_not_null{count}
@sa lttng_triggers_get_at_index() --
Get a trigger from a trigger list by index.
*/
LTTNG_EXPORT extern enum lttng_trigger_status
lttng_triggers_get_count(const struct lttng_triggers *triggers, unsigned int *count);
/*!
@brief
Destroys the trigger list \lt_p{triggers}.
@param[in] triggers
@parblock
Trigger list to destroy.
May be \c NULL.
@endparblock
*/
LTTNG_EXPORT extern void lttng_triggers_destroy(struct lttng_triggers *triggers);
/*
* Deprecated: invocations should be replaced by
* lttng_register_trigger_with_automatic_name().
*
* Register a trigger to the session daemon.
*
* The trigger can be destroyed after this call.
*
* Return 0 on success, a negative LTTng error code on error.
*/
LTTNG_DEPRECATED("Use lttng_register_trigger_with_automatic_name")
LTTNG_EXPORT extern int lttng_register_trigger(struct lttng_trigger *trigger);
/// @}
#ifdef __cplusplus
}
#endif
#endif /* LTTNG_TRIGGER_H */
|