Skip to content

Commit b432306

Browse files
committed
init: use the same exit codes as chroot/podman
For consistency for the container isolation use case, let's use in init the same exit codes as chroot and podman do: 125: "init" cannot set up the environment inside the microVM. 126: "init" can find the executable to be run inside the microVM but cannot not execute it. 127: "init" cannot find the executable to be run inside the microVM. Signed-off-by: Sergio Lopez <[email protected]>
1 parent 2c06cad commit b432306

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

include/libkrun.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -582,10 +582,16 @@ int32_t krun_split_irqchip(uint32_t ctx_id, bool enable);
582582
* Arguments:
583583
* "ctx_id" - the configuration context ID.
584584
*
585-
* Returns:
585+
* Notes:
586586
* This function only returns if an error happens before starting the microVM. Otherwise, the
587587
* VMM assumes it has full control of the process, and will call to exit() once the microVM shuts
588588
* down.
589+
*
590+
* Returns:
591+
* -EINVAL - The VMM has detected an error in the microVM configuration.
592+
* 125 - "init" cannot set up the environment inside the microVM.
593+
* 126 - "init" can find the executable to be run inside the microVM but cannot not execute it.
594+
* 127 - "init" cannot find the executable to be run inside the microVM.
589595
*/
590596
int32_t krun_start_enter(uint32_t ctx_id);
591597

init/init.c

+11-3
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,7 @@ int main(int argc, char **argv)
980980
struct ifreq ifr;
981981
int sockfd;
982982
int status;
983+
int saved_errno;
983984
char localhost[] = "localhost\0";
984985
char *hostname;
985986
char *krun_home;
@@ -1067,16 +1068,23 @@ int main(int argc, char **argv)
10671068
int child = fork();
10681069
if (child < 0) {
10691070
perror("fork");
1070-
exit(-3);
1071+
set_exit_code(125);
1072+
exit(125);
10711073
}
10721074
if (child == 0) { // child
10731075
if (setup_redirects() < 0) {
1074-
exit(-4);
1076+
exit(125);
10751077
}
10761078
if (execvp(exec_argv[0], exec_argv) < 0) {
1079+
saved_errno = errno;
10771080
printf("Couldn't execute '%s' inside the vm: %s\n", exec_argv[0],
10781081
strerror(errno));
1079-
exit(-3);
1082+
// Use the same exit code as chroot and podman do.
1083+
if (saved_errno == ENOENT) {
1084+
exit(127);
1085+
} else {
1086+
exit(126);
1087+
}
10801088
}
10811089
} else { // parent
10821090
// Wait until the workload's entrypoint has exited, ignoring any other

0 commit comments

Comments
 (0)