Merge branch 'master' into next
[dss.git] / err.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 extern char *dss_errlist[];
3 extern char *dss_error_txt;
4
5 void dss_log_set_params(int ll, const char *file, int line, const char *func);
6 __printf_1_2 void dss_log(const char* fmt,...);
7
8 /**
9  * This bit indicates whether a number is considered a system error number
10  * If yes, the system errno is just the result of clearing this bit from
11  * the given number.
12  */
13 #define SYSTEM_ERROR_BIT 30
14
15 /** Check whether the system error bit is set. */
16 #define IS_SYSTEM_ERROR(num) (!!((num) & (1 << SYSTEM_ERROR_BIT)))
17
18 /** Set the system error bit for the given number. */
19 #define ERRNO_TO_DSS_ERROR(num) ((num) | (1 << SYSTEM_ERROR_BIT))
20
21 /**
22  * dss' version of strerror(3).
23  *
24  * \param num The error number.
25  *
26  * \return The error text of \a num.
27  */
28 static inline char *dss_strerror(int num)
29 {
30         assert(num > 0);
31         if (IS_SYSTEM_ERROR(num))
32                 return strerror((num) & ((1 << SYSTEM_ERROR_BIT) - 1));
33         else
34                 return dss_errlist[num];
35 }
36
37 #define DSS_ERRORS \
38         DSS_ERROR(SUCCESS, "success"), \
39         DSS_ERROR(SYNTAX, "syntax error"), \
40         DSS_ERROR(ATOI_OVERFLOW, "value too large"), \
41         DSS_ERROR(STRTOLL, "unknown strtoll error"), \
42         DSS_ERROR(ATOI_NO_DIGITS, "no digits found in string"), \
43         DSS_ERROR(ATOI_JUNK_AT_END, "further characters after number"), \
44         DSS_ERROR(INVALID_NUMBER, "invalid number"), \
45         DSS_ERROR(STRFTIME, "strftime() failed"), \
46         DSS_ERROR(LOCALTIME, "localtime() failed"), \
47         DSS_ERROR(HOOK_FAILED, "hook failure"), \
48         DSS_ERROR(MOUNTPOINT, "destination directory is no mountpoint"), \
49         DSS_ERROR(NULL_OPEN, "can not open /dev/null"), \
50         DSS_ERROR(DUP_PIPE, "exec error: can not create pipe"), \
51         DSS_ERROR(INVOLUNTARY_EXIT, "unexpected termination cause"), \
52         DSS_ERROR(BAD_EXIT_CODE, "unexpected exit code"), \
53         DSS_ERROR(SIGNAL_SIG_ERR, "signal() returned SIG_ERR"), \
54         DSS_ERROR(SIGNAL, "caught terminating signal"), \
55         DSS_ERROR(KILL_TIMEOUT, "signal timeout expired"), \
56         DSS_ERROR(BUG, "values of beta might cause dom!"), \
57         DSS_ERROR(NOT_RUNNING, "dss not running"), \
58         DSS_ERROR(ALREADY_RUNNING, "dss already running"), \
59         DSS_ERROR(TOO_MANY_RSYNC_ERRORS, "too many consecutive rsync errors"), \
60         DSS_ERROR(LOPSUB, "lopsub error")
61
62 /**
63  * This is temporarily defined to expand to its first argument (prefixed by
64  * 'E_') and gets later redefined to expand to the error text only
65  */
66 #define DSS_ERROR(err, msg) E_ ## err
67
68 enum dss_error_codes {
69         DSS_ERRORS
70 };
71 #undef DSS_ERROR
72 #define DSS_ERROR(err, msg) msg
73 #define DEFINE_DSS_ERRLIST char *dss_errlist[] = {DSS_ERRORS}