| 1 | /* |
| 2 | * Copyright (C) 2012 David Goulet <dgoulet@efficios.com> |
| 3 | * |
| 4 | * SPDX-License-Identifier: LGPL-2.1-only |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #define _LGPL_SOURCE |
| 9 | #include "error.hpp" |
| 10 | |
| 11 | #include <common/common.hpp> |
| 12 | #include <common/compat/errno.hpp> |
| 13 | #include <common/compat/getenv.hpp> |
| 14 | #include <common/thread.hpp> |
| 15 | |
| 16 | #include <lttng/lttng-error.h> |
| 17 | |
| 18 | #include <inttypes.h> |
| 19 | #include <iostream> |
| 20 | #include <pthread.h> |
| 21 | #include <stdlib.h> |
| 22 | #include <string.h> |
| 23 | |
| 24 | namespace { |
| 25 | /* |
| 26 | * lttng_opt_abort_on_error: unset: -1, disabled: 0, enabled: 1. |
| 27 | * Controlled by the LTTNG_ABORT_ON_ERROR environment variable. |
| 28 | */ |
| 29 | int lttng_opt_abort_on_error = -1; |
| 30 | |
| 31 | /* TLS variable that contains the time of one single log entry. */ |
| 32 | thread_local struct log_time error_log_time; |
| 33 | } /* namespace */ |
| 34 | |
| 35 | thread_local const char * logger_thread_name; |
| 36 | |
| 37 | const char *log_add_time() |
| 38 | { |
| 39 | int ret; |
| 40 | struct tm tm, *res; |
| 41 | struct timespec tp; |
| 42 | time_t now; |
| 43 | const int errsv = errno; |
| 44 | |
| 45 | ret = lttng_clock_gettime(CLOCK_REALTIME, &tp); |
| 46 | if (ret < 0) { |
| 47 | goto error; |
| 48 | } |
| 49 | now = (time_t) tp.tv_sec; |
| 50 | |
| 51 | res = localtime_r(&now, &tm); |
| 52 | if (!res) { |
| 53 | goto error; |
| 54 | } |
| 55 | |
| 56 | /* Format time in the TLS variable. */ |
| 57 | ret = snprintf(error_log_time.str, |
| 58 | sizeof(error_log_time.str), |
| 59 | "%02d:%02d:%02d.%09ld", |
| 60 | tm.tm_hour, |
| 61 | tm.tm_min, |
| 62 | tm.tm_sec, |
| 63 | tp.tv_nsec); |
| 64 | if (ret < 0) { |
| 65 | goto error; |
| 66 | } |
| 67 | |
| 68 | errno = errsv; |
| 69 | return error_log_time.str; |
| 70 | |
| 71 | error: |
| 72 | /* Return an empty string on error so logging is not affected. */ |
| 73 | errno = errsv; |
| 74 | return ""; |
| 75 | } |
| 76 | |
| 77 | void logger_set_thread_name(const char *name, bool set_pthread_name) |
| 78 | { |
| 79 | int ret; |
| 80 | |
| 81 | LTTNG_ASSERT(name); |
| 82 | logger_thread_name = name; |
| 83 | |
| 84 | if (set_pthread_name) { |
| 85 | ret = lttng_thread_setname(name); |
| 86 | if (ret && ret != -ENOSYS) { |
| 87 | /* Don't fail as this is not essential. */ |
| 88 | DBG("Failed to set pthread name attribute"); |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | /* |
| 94 | * Human readable error message. |
| 95 | */ |
| 96 | static const char *lttng_error_code_str(lttng_error_code code) |
| 97 | { |
| 98 | switch (code) { |
| 99 | case LTTNG_OK: |
| 100 | return "Success"; |
| 101 | case LTTNG_ERR_UNK: |
| 102 | return "Unknown error"; |
| 103 | case LTTNG_ERR_UND: |
| 104 | return "Undefined command"; |
| 105 | case LTTNG_ERR_UNKNOWN_DOMAIN: |
| 106 | return "Unknown tracing domain"; |
| 107 | case LTTNG_ERR_NO_SESSION: |
| 108 | return "No session found"; |
| 109 | case LTTNG_ERR_CREATE_DIR_FAIL: |
| 110 | return "Create directory failed"; |
| 111 | case LTTNG_ERR_SESSION_FAIL: |
| 112 | return "Create session failed"; |
| 113 | case LTTNG_ERR_SESS_NOT_FOUND: |
| 114 | return "Session name not found"; |
| 115 | case LTTNG_ERR_FATAL: |
| 116 | return "Fatal error of the session daemon"; |
| 117 | case LTTNG_ERR_SELECT_SESS: |
| 118 | return "A session MUST be selected"; |
| 119 | case LTTNG_ERR_EXIST_SESS: |
| 120 | return "Session name already exists"; |
| 121 | case LTTNG_ERR_NO_EVENT: |
| 122 | return "Event not found"; |
| 123 | case LTTNG_ERR_CONNECT_FAIL: |
| 124 | return "Unable to connect to Unix socket"; |
| 125 | case LTTNG_ERR_EPERM: |
| 126 | return "Permission denied"; |
| 127 | case LTTNG_ERR_KERN_NA: |
| 128 | return "Kernel tracer not available"; |
| 129 | case LTTNG_ERR_KERN_VERSION: |
| 130 | return "Kernel tracer version is not compatible"; |
| 131 | case LTTNG_ERR_KERN_EVENT_EXIST: |
| 132 | return "Kernel event already exists"; |
| 133 | case LTTNG_ERR_KERN_SESS_FAIL: |
| 134 | return "Kernel create session failed"; |
| 135 | case LTTNG_ERR_KERN_CHAN_EXIST: |
| 136 | return "Kernel channel already exists"; |
| 137 | case LTTNG_ERR_KERN_CHAN_FAIL: |
| 138 | return "Kernel create channel failed"; |
| 139 | case LTTNG_ERR_KERN_CHAN_NOT_FOUND: |
| 140 | return "Kernel channel not found"; |
| 141 | case LTTNG_ERR_KERN_CHAN_DISABLE_FAIL: |
| 142 | return "Disable kernel channel failed"; |
| 143 | case LTTNG_ERR_KERN_CHAN_ENABLE_FAIL: |
| 144 | return "Enable kernel channel failed"; |
| 145 | case LTTNG_ERR_KERN_CONTEXT_FAIL: |
| 146 | return "Add kernel context failed"; |
| 147 | case LTTNG_ERR_KERN_ENABLE_FAIL: |
| 148 | return "Enable kernel event failed"; |
| 149 | case LTTNG_ERR_KERN_DISABLE_FAIL: |
| 150 | return "Disable kernel event failed"; |
| 151 | case LTTNG_ERR_KERN_META_FAIL: |
| 152 | return "Opening metadata failed"; |
| 153 | case LTTNG_ERR_KERN_START_FAIL: |
| 154 | return "Starting kernel trace failed"; |
| 155 | case LTTNG_ERR_KERN_STOP_FAIL: |
| 156 | return "Stopping kernel trace failed"; |
| 157 | case LTTNG_ERR_KERN_CONSUMER_FAIL: |
| 158 | return "Kernel consumer start failed"; |
| 159 | case LTTNG_ERR_KERN_STREAM_FAIL: |
| 160 | return "Kernel create stream failed"; |
| 161 | case LTTNG_ERR_KERN_LIST_FAIL: |
| 162 | return "Listing kernel events failed"; |
| 163 | case LTTNG_ERR_UST_CALIBRATE_FAIL: |
| 164 | return "UST calibration failed"; |
| 165 | case LTTNG_ERR_UST_SESS_FAIL: |
| 166 | return "UST create session failed"; |
| 167 | case LTTNG_ERR_UST_CHAN_FAIL: |
| 168 | return "UST create channel failed"; |
| 169 | case LTTNG_ERR_UST_CHAN_EXIST: |
| 170 | return "UST channel already exist"; |
| 171 | case LTTNG_ERR_UST_CHAN_NOT_FOUND: |
| 172 | return "UST channel not found"; |
| 173 | case LTTNG_ERR_UST_CHAN_DISABLE_FAIL: |
| 174 | return "Disable UST channel failed"; |
| 175 | case LTTNG_ERR_UST_CHAN_ENABLE_FAIL: |
| 176 | return "Enable UST channel failed"; |
| 177 | case LTTNG_ERR_UST_ENABLE_FAIL: |
| 178 | return "Enable UST event failed"; |
| 179 | case LTTNG_ERR_UST_DISABLE_FAIL: |
| 180 | return "Disable UST event failed"; |
| 181 | case LTTNG_ERR_UST_META_FAIL: |
| 182 | return "Opening metadata failed"; |
| 183 | case LTTNG_ERR_UST_START_FAIL: |
| 184 | return "Starting UST trace failed"; |
| 185 | case LTTNG_ERR_UST_STOP_FAIL: |
| 186 | return "Stopping UST trace failed"; |
| 187 | case LTTNG_ERR_UST_CONSUMER64_FAIL: |
| 188 | return "64-bit UST consumer start failed"; |
| 189 | case LTTNG_ERR_UST_CONSUMER32_FAIL: |
| 190 | return "32-bit UST consumer start failed"; |
| 191 | case LTTNG_ERR_UST_STREAM_FAIL: |
| 192 | return "UST create stream failed"; |
| 193 | case LTTNG_ERR_UST_LIST_FAIL: |
| 194 | return "Listing UST events failed"; |
| 195 | case LTTNG_ERR_UST_EVENT_EXIST: |
| 196 | return "UST event already exist"; |
| 197 | case LTTNG_ERR_UST_EVENT_NOT_FOUND: |
| 198 | return "UST event not found"; |
| 199 | case LTTNG_ERR_UST_CONTEXT_EXIST: |
| 200 | return "UST context already exist"; |
| 201 | case LTTNG_ERR_UST_CONTEXT_INVAL: |
| 202 | return "UST invalid context"; |
| 203 | case LTTNG_ERR_NEED_ROOT_SESSIOND: |
| 204 | return "Tracing the kernel requires a root lttng-sessiond daemon, as well as \"tracing\" group membership or root user ID for the lttng client"; |
| 205 | case LTTNG_ERR_NO_UST: |
| 206 | return "LTTng-UST tracer is not supported. Please rebuild lttng-tools with lttng-ust support enabled"; |
| 207 | case LTTNG_ERR_TRACE_ALREADY_STARTED: |
| 208 | return "Tracing has already been started once"; |
| 209 | case LTTNG_ERR_TRACE_ALREADY_STOPPED: |
| 210 | return "Tracing has already been stopped"; |
| 211 | case LTTNG_ERR_KERN_EVENT_ENOSYS: |
| 212 | return "Kernel event type not supported"; |
| 213 | case LTTNG_ERR_NEED_CHANNEL_NAME: |
| 214 | return "Non-default channel exists within session: channel name needs to be specified with '-c name'"; |
| 215 | case LTTNG_ERR_INVALID: |
| 216 | return "Invalid parameter"; |
| 217 | case LTTNG_ERR_NO_USTCONSUMERD: |
| 218 | return "No UST consumer detected"; |
| 219 | case LTTNG_ERR_NO_KERNCONSUMERD: |
| 220 | return "No kernel consumer detected"; |
| 221 | case LTTNG_ERR_EVENT_EXIST_LOGLEVEL: |
| 222 | return "Event already enabled with different loglevel"; |
| 223 | case LTTNG_ERR_URL_DATA_MISS: |
| 224 | return "Missing data path URL"; |
| 225 | case LTTNG_ERR_URL_CTRL_MISS: |
| 226 | return "Missing control path URL"; |
| 227 | case LTTNG_ERR_ENABLE_CONSUMER_FAIL: |
| 228 | return "Enabling consumer failed"; |
| 229 | case LTTNG_ERR_RELAYD_CONNECT_FAIL: |
| 230 | return "Unable to connect to lttng-relayd"; |
| 231 | case LTTNG_ERR_RELAYD_VERSION_FAIL: |
| 232 | return "Relay daemon not compatible"; |
| 233 | case LTTNG_ERR_FILTER_INVAL: |
| 234 | return "Invalid filter bytecode"; |
| 235 | case LTTNG_ERR_FILTER_NOMEM: |
| 236 | return "Not enough memory for filter bytecode"; |
| 237 | case LTTNG_ERR_FILTER_EXIST: |
| 238 | return "Filter already exist"; |
| 239 | case LTTNG_ERR_NO_CONSUMER: |
| 240 | return "Consumer not found for recording session"; |
| 241 | case LTTNG_ERR_EXCLUSION_INVAL: |
| 242 | return "Invalid event exclusion data"; |
| 243 | case LTTNG_ERR_EXCLUSION_NOMEM: |
| 244 | return "Lack of memory while processing event exclusions"; |
| 245 | case LTTNG_ERR_NO_SESSIOND: |
| 246 | return "No session daemon is available"; |
| 247 | case LTTNG_ERR_SESSION_STARTED: |
| 248 | return "Session is running"; |
| 249 | case LTTNG_ERR_NOT_SUPPORTED: |
| 250 | return "Operation not supported"; |
| 251 | case LTTNG_ERR_UST_EVENT_ENABLED: |
| 252 | return "UST event already enabled"; |
| 253 | case LTTNG_ERR_SET_URL: |
| 254 | return "Error setting URL"; |
| 255 | case LTTNG_ERR_URL_EXIST: |
| 256 | return "URL already exists"; |
| 257 | case LTTNG_ERR_BUFFER_NOT_SUPPORTED: |
| 258 | return "Buffer type not supported"; |
| 259 | case LTTNG_ERR_BUFFER_TYPE_MISMATCH: |
| 260 | return "Buffer type mismatch for session"; |
| 261 | case LTTNG_ERR_NOMEM: |
| 262 | return "Not enough memory"; |
| 263 | case LTTNG_ERR_SNAPSHOT_OUTPUT_EXIST: |
| 264 | return "Snapshot output already exists"; |
| 265 | case LTTNG_ERR_START_SESSION_ONCE: |
| 266 | return "Session needs to be started once"; |
| 267 | case LTTNG_ERR_SNAPSHOT_FAIL: |
| 268 | return "Snapshot record failed"; |
| 269 | case LTTNG_ERR_NO_STREAM: |
| 270 | return "Index without stream on relay"; |
| 271 | case LTTNG_ERR_CHAN_EXIST: |
| 272 | return "Channel already exists"; |
| 273 | case LTTNG_ERR_SNAPSHOT_NODATA: |
| 274 | return "No data available in snapshot"; |
| 275 | case LTTNG_ERR_NO_CHANNEL: |
| 276 | return "No channel found in the session"; |
| 277 | case LTTNG_ERR_SESSION_INVALID_CHAR: |
| 278 | return "Invalid character found in session name"; |
| 279 | case LTTNG_ERR_SAVE_FILE_EXIST: |
| 280 | return "Session file already exists"; |
| 281 | case LTTNG_ERR_SAVE_IO_FAIL: |
| 282 | return "IO error while writing session configuration"; |
| 283 | case LTTNG_ERR_LOAD_INVALID_CONFIG: |
| 284 | return "Invalid session configuration"; |
| 285 | case LTTNG_ERR_LOAD_IO_FAIL: |
| 286 | return "IO error while reading a session configuration"; |
| 287 | case LTTNG_ERR_LOAD_SESSION_NOENT: |
| 288 | return "Session file not found"; |
| 289 | case LTTNG_ERR_MAX_SIZE_INVALID: |
| 290 | return "Snapshot max size is invalid"; |
| 291 | case LTTNG_ERR_MI_OUTPUT_TYPE: |
| 292 | return "Invalid MI output format"; |
| 293 | case LTTNG_ERR_MI_IO_FAIL: |
| 294 | return "IO error while writing MI output"; |
| 295 | case LTTNG_ERR_MI_NOT_IMPLEMENTED: |
| 296 | return "Mi feature not implemented"; |
| 297 | case LTTNG_ERR_INVALID_EVENT_NAME: |
| 298 | return "Invalid event name"; |
| 299 | case LTTNG_ERR_INVALID_CHANNEL_NAME: |
| 300 | return "Invalid channel name"; |
| 301 | case LTTNG_ERR_PROCESS_ATTR_EXISTS: |
| 302 | return "Process attribute is already tracked"; |
| 303 | case LTTNG_ERR_PROCESS_ATTR_MISSING: |
| 304 | return "Process attribute was not tracked"; |
| 305 | case LTTNG_ERR_INVALID_CHANNEL_DOMAIN: |
| 306 | return "Invalid channel domain"; |
| 307 | case LTTNG_ERR_OVERFLOW: |
| 308 | return "Overflow occurred"; |
| 309 | case LTTNG_ERR_SESSION_NOT_STARTED: |
| 310 | return "Session not started"; |
| 311 | case LTTNG_ERR_LIVE_SESSION: |
| 312 | return "Live sessions are not supported"; |
| 313 | case LTTNG_ERR_PER_PID_SESSION: |
| 314 | return "Per-PID recording sessions are not supported"; |
| 315 | case LTTNG_ERR_KERN_CONTEXT_UNAVAILABLE: |
| 316 | return "Context unavailable on this kernel"; |
| 317 | case LTTNG_ERR_REGEN_STATEDUMP_FAIL: |
| 318 | return "Failed to regenerate the state dump"; |
| 319 | case LTTNG_ERR_REGEN_STATEDUMP_NOMEM: |
| 320 | return "Failed to regenerate the state dump, not enough memory"; |
| 321 | case LTTNG_ERR_NOT_SNAPSHOT_SESSION: |
| 322 | return "Snapshot command can't be applied to a non-snapshot session"; |
| 323 | case LTTNG_ERR_INVALID_TRIGGER: |
| 324 | return "Invalid trigger"; |
| 325 | case LTTNG_ERR_TRIGGER_EXISTS: |
| 326 | return "Trigger already registered"; |
| 327 | case LTTNG_ERR_TRIGGER_NOT_FOUND: |
| 328 | return "Trigger not found"; |
| 329 | case LTTNG_ERR_COMMAND_CANCELLED: |
| 330 | return "Command cancelled"; |
| 331 | case LTTNG_ERR_ROTATION_PENDING: |
| 332 | return "Rotation already pending for this session"; |
| 333 | case LTTNG_ERR_ROTATION_NOT_AVAILABLE: |
| 334 | return "Rotation feature not available for this session's creation mode"; |
| 335 | case LTTNG_ERR_ROTATION_SCHEDULE_SET: |
| 336 | return "A session rotation schedule of this type is already set on the session"; |
| 337 | case LTTNG_ERR_ROTATION_SCHEDULE_NOT_SET: |
| 338 | return "No session rotation schedule of this type is set on the session"; |
| 339 | case LTTNG_ERR_ROTATION_MULTIPLE_AFTER_STOP: |
| 340 | return "Session was already rotated once since it became inactive"; |
| 341 | case LTTNG_ERR_ROTATION_WRONG_VERSION: |
| 342 | return "Session rotation is not supported by this kernel tracer version"; |
| 343 | case LTTNG_ERR_NO_SESSION_OUTPUT: |
| 344 | return "Session has no output"; |
| 345 | case LTTNG_ERR_ROTATION_NOT_AVAILABLE_RELAY: |
| 346 | return "Rotation feature not available on the relay"; |
| 347 | case LTTNG_ERR_AGENT_TRACING_DISABLED: |
| 348 | return "Session daemon agent tracing is disabled"; |
| 349 | case LTTNG_ERR_PROBE_LOCATION_INVAL: |
| 350 | return "Invalid userspace probe location"; |
| 351 | case LTTNG_ERR_ELF_PARSING: |
| 352 | return "ELF parsing error"; |
| 353 | case LTTNG_ERR_SDT_PROBE_SEMAPHORE: |
| 354 | return "SDT probe guarded by a semaphore"; |
| 355 | case LTTNG_ERR_ROTATION_FAIL_CONSUMER: |
| 356 | return "Rotation failure on consumer"; |
| 357 | case LTTNG_ERR_ROTATE_RENAME_FAIL_CONSUMER: |
| 358 | return "Rotation rename failure on consumer"; |
| 359 | case LTTNG_ERR_ROTATION_PENDING_LOCAL_FAIL_CONSUMER: |
| 360 | return "Rotation pending check (local) failure on consumer"; |
| 361 | case LTTNG_ERR_ROTATION_PENDING_RELAY_FAIL_CONSUMER: |
| 362 | return "Rotation pending check (relay) failure on consumer"; |
| 363 | case LTTNG_ERR_MKDIR_FAIL_CONSUMER: |
| 364 | return "Directory creation failure on consumer"; |
| 365 | case LTTNG_ERR_CHAN_NOT_FOUND: |
| 366 | return "Channel not found"; |
| 367 | case LTTNG_ERR_SNAPSHOT_UNSUPPORTED: |
| 368 | return "Session configuration does not allow the use of snapshots"; |
| 369 | case LTTNG_ERR_SESSION_NOT_EXIST: |
| 370 | return "Recording session does not exist"; |
| 371 | case LTTNG_ERR_CREATE_TRACE_CHUNK_FAIL_CONSUMER: |
| 372 | return "Trace chunk creation failed on consumer"; |
| 373 | case LTTNG_ERR_CLOSE_TRACE_CHUNK_FAIL_CONSUMER: |
| 374 | return "Trace chunk close failed on consumer"; |
| 375 | case LTTNG_ERR_TRACE_CHUNK_EXISTS_FAIL_CONSUMER: |
| 376 | return "Failed to query consumer for trace chunk existence"; |
| 377 | case LTTNG_ERR_INVALID_PROTOCOL: |
| 378 | return "Protocol error occurred"; |
| 379 | case LTTNG_ERR_FILE_CREATION_ERROR: |
| 380 | return "Failed to create file"; |
| 381 | case LTTNG_ERR_TIMER_STOP_ERROR: |
| 382 | return "Failed to stop a timer"; |
| 383 | case LTTNG_ERR_ROTATION_NOT_AVAILABLE_KERNEL: |
| 384 | return "Rotation feature not supported by the kernel tracer"; |
| 385 | case LTTNG_ERR_CLEAR_RELAY_DISALLOWED: |
| 386 | return "Relayd daemon peer does not allow sessions to be cleared"; |
| 387 | case LTTNG_ERR_CLEAR_NOT_AVAILABLE_RELAY: |
| 388 | return "Clearing a session is not supported by the relay daemon"; |
| 389 | case LTTNG_ERR_CLEAR_FAIL_CONSUMER: |
| 390 | return "Consumer failed to clear the session"; |
| 391 | case LTTNG_ERR_ROTATION_AFTER_STOP_CLEAR: |
| 392 | return "Session was already cleared since it became inactive"; |
| 393 | case LTTNG_ERR_USER_NOT_FOUND: |
| 394 | return "User not found"; |
| 395 | case LTTNG_ERR_GROUP_NOT_FOUND: |
| 396 | return "Group not found"; |
| 397 | case LTTNG_ERR_UNSUPPORTED_DOMAIN: |
| 398 | return "Unsupported domain used"; |
| 399 | case LTTNG_ERR_PROCESS_ATTR_TRACKER_INVALID_TRACKING_POLICY: |
| 400 | return "Operation does not apply to the process attribute tracker's tracking policy"; |
| 401 | case LTTNG_ERR_EVENT_NOTIFIER_GROUP_NOTIFICATION_FD: |
| 402 | return "Failed to create an event notifier group notification file descriptor"; |
| 403 | case LTTNG_ERR_INVALID_CAPTURE_EXPRESSION: |
| 404 | return "Invalid capture expression"; |
| 405 | case LTTNG_ERR_EVENT_NOTIFIER_REGISTRATION: |
| 406 | return "Failed to create event notifier"; |
| 407 | case LTTNG_ERR_EVENT_NOTIFIER_ERROR_ACCOUNTING: |
| 408 | return "Failed to initialize event notifier error accounting"; |
| 409 | case LTTNG_ERR_EVENT_NOTIFIER_ERROR_ACCOUNTING_FULL: |
| 410 | return "No index available in event notifier error accounting"; |
| 411 | case LTTNG_ERR_INVALID_ERROR_QUERY_TARGET: |
| 412 | return "Invalid error query target."; |
| 413 | case LTTNG_ERR_BUFFER_FLUSH_FAILED: |
| 414 | return "Failed to flush stream buffer"; |
| 415 | case LTTNG_ERR_NR: |
| 416 | abort(); |
| 417 | } |
| 418 | |
| 419 | abort(); |
| 420 | }; |
| 421 | |
| 422 | /* |
| 423 | * Return ptr to string representing a human readable error code from the |
| 424 | * lttng_error_code enum. |
| 425 | * |
| 426 | * These code MUST be negative in other to treat that as an error value. |
| 427 | */ |
| 428 | const char *error_get_str(int32_t code) |
| 429 | { |
| 430 | code = -code; |
| 431 | |
| 432 | if (code < LTTNG_OK || code >= LTTNG_ERR_NR) { |
| 433 | code = LTTNG_ERR_UNK; |
| 434 | } |
| 435 | |
| 436 | return lttng_error_code_str((lttng_error_code) code); |
| 437 | } |
| 438 | |
| 439 | void lttng_abort_on_error(void) |
| 440 | { |
| 441 | if (lttng_opt_abort_on_error < 0) { |
| 442 | /* Use lttng_secure_getenv() to query its state. */ |
| 443 | const char *value; |
| 444 | |
| 445 | value = lttng_secure_getenv("LTTNG_ABORT_ON_ERROR"); |
| 446 | if (value && !strcmp(value, "1")) { |
| 447 | lttng_opt_abort_on_error = 1; |
| 448 | } else { |
| 449 | lttng_opt_abort_on_error = 0; |
| 450 | } |
| 451 | } |
| 452 | if (lttng_opt_abort_on_error > 0) { |
| 453 | abort(); |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | [[noreturn]] void |
| 458 | lttng::logging::details::die_formatting_exception(const char *format, |
| 459 | const std::exception& formatting_exception) |
| 460 | { |
| 461 | std::cerr << "Error occurred while formatting logging message: msg=`" << format |
| 462 | << "`: " << formatting_exception.what(); |
| 463 | abort(); |
| 464 | } |