]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/error.c
Merge pull request #3488 from brauner/2020-07-17/fixes
[mirror_lxc.git] / src / lxc / error.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <sys/wait.h>
6
7 #include "error.h"
8 #include "log.h"
9
10 lxc_log_define(error, lxc);
11
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)
28 INFO("Child <%d> ended on error (%d)", pid, ret);
29 }
30
31 if (WIFSIGNALED(status)) {
32 int signal = WTERMSIG(status);
33 INFO("Child <%d> ended on signal (%d)", pid, signal);
34 ret = 128 + signal;
35 }
36
37 return ret;
38 }