]>
Commit | Line | Data |
---|---|---|
cc73685d | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
58412580 | 2 | |
3 | #include <stdio.h> | |
1f3da8f8 | 4 | #include <stdlib.h> |
e043236e | 5 | #include <sys/wait.h> |
f2363e38 | 6 | |
58412580 | 7 | #include "error.h" |
e043236e MN |
8 | #include "log.h" |
9 | ||
ac2cecc4 | 10 | lxc_log_define(error, lxc); |
58412580 | 11 | |
e043236e MN |
12 | /*---------------------------------------------------------------------------*/ |
13 | /* lxc_error_set_and_log | |
14 | * function is here to convert | |
15 | * the reported status to an exit code as detailed here: | |
16 | * | |
17 | * 0-126 exit code of the application | |
18 | * 128+n signal n received by the application | |
19 | * 255 lxc error | |
20 | */ | |
21 | extern int lxc_error_set_and_log(int pid, int status) | |
22 | { | |
23 | int ret = 0; | |
24 | ||
25 | if (WIFEXITED(status)) { | |
26 | ret = WEXITSTATUS(status); | |
27 | if (ret) | |
1bfb1200 | 28 | INFO("Child <%d> ended on error (%d)", pid, ret); |
e043236e MN |
29 | } |
30 | ||
31 | if (WIFSIGNALED(status)) { | |
32 | int signal = WTERMSIG(status); | |
1bfb1200 | 33 | INFO("Child <%d> ended on signal (%d)", pid, signal); |
19cfa02c | 34 | ret = 128 + signal; |
e043236e MN |
35 | } |
36 | ||
37 | return ret; | |
38 | } |