Version 2.13.1
[lttng-ust.git] / src / lib / lttng-ust / strerror.c
... / ...
CommitLineData
1/*
2 * SPDX-License-Identifier: LGPL-2.1-only
3 *
4 * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
5 * Copyright (C) 2011-2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 */
7
8#include <lttng/ust-error.h>
9
10#define CODE_OFFSET(code) \
11 (code == LTTNG_UST_OK ? 0 : (code - LTTNG_UST_ERR + 1))
12
13/*
14 * Human readable error message.
15 */
16static const char *ustcomm_readable_code[] = {
17 [ CODE_OFFSET(LTTNG_UST_OK) ] = "Success",
18 [ CODE_OFFSET(LTTNG_UST_ERR) ] = "Unknown error",
19 [ CODE_OFFSET(LTTNG_UST_ERR_NOENT) ] = "No entry",
20 [ CODE_OFFSET(LTTNG_UST_ERR_EXIST) ] = "Object already exists",
21 [ CODE_OFFSET(LTTNG_UST_ERR_INVAL) ] = "Invalid argument",
22 [ CODE_OFFSET(LTTNG_UST_ERR_PERM) ] = "Permission denied",
23 [ CODE_OFFSET(LTTNG_UST_ERR_NOSYS) ] = "Not implemented",
24 [ CODE_OFFSET(LTTNG_UST_ERR_EXITING) ] = "Process is exiting",
25
26 [ CODE_OFFSET(LTTNG_UST_ERR_INVAL_MAGIC) ] = "Invalid magic number",
27 [ CODE_OFFSET(LTTNG_UST_ERR_INVAL_SOCKET_TYPE) ] = "Invalid socket type",
28 [ CODE_OFFSET(LTTNG_UST_ERR_UNSUP_MAJOR) ] = "Unsupported major version",
29 [ CODE_OFFSET(LTTNG_UST_ERR_PEERCRED) ] = "Cannot get unix socket peer credentials",
30 [ CODE_OFFSET(LTTNG_UST_ERR_PEERCRED_PID) ] = "Peer credentials PID is invalid. Socket appears to belong to a distinct, non-nested pid namespace.",
31};
32
33/*
34 * lttng_ust_strerror
35 * @code: must be a negative value of enum lttng_ust_error_code (or 0).
36 *
37 * Returns a ptr to a string representing a human readable error code from the
38 * ustcomm_return_code enum.
39 */
40const char *lttng_ust_strerror(int code)
41{
42 code = -code;
43
44 if (code < LTTNG_UST_OK || code >= LTTNG_UST_ERR_NR)
45 code = LTTNG_UST_ERR;
46
47 return ustcomm_readable_code[CODE_OFFSET(code)];
48}
This page took 0.023482 seconds and 4 git commands to generate.