Skip to content

Commit

Permalink
Add error logging to config + crtools init
Browse files Browse the repository at this point in the history
CRIU sometimes returns 1 from main() with no explanation.
Changes made add more logging in the case of
initialization errors in config and crtools.

Signed-off-by: Angie Ni <[email protected]>
  • Loading branch information
Angie Ni authored and avagin committed Jul 16, 2020
1 parent 1177e82 commit df2610b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 13 deletions.
32 changes: 24 additions & 8 deletions criu/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,10 @@ int parse_options(int argc, char **argv, bool *usage_error,
opts.final_state = TASK_ALIVE;
break;
case 'x':
if (optarg && unix_sk_ids_parse(optarg) < 0)
if (optarg && unix_sk_ids_parse(optarg) < 0) {
pr_err("Failed to parse unix socket inode from optarg: %s\n", optarg);
return 1;
}
opts.ext_unix_sk = true;
break;
case 't':
Expand Down Expand Up @@ -648,13 +650,17 @@ int parse_options(int argc, char **argv, bool *usage_error,
goto bad_arg;

*aux = '\0';
if (veth_pair_add(optarg, aux + 1))
if (veth_pair_add(optarg, aux + 1)) {
pr_err("Failed to add veth pair: %s, %s.\n", optarg, aux + 1);
return 1;
}
}
break;
case 1049:
if (add_script(optarg))
if (add_script(optarg)) {
pr_err("Failed to add action-script: %s.\n", optarg);
return 1;
}
break;
case 1051:
SET_CHAR_OPTS(addr, optarg);
Expand Down Expand Up @@ -724,12 +730,16 @@ int parse_options(int argc, char **argv, bool *usage_error,
return 0;
break;
case 1064:
if (!add_skip_mount(optarg))
if (!add_skip_mount(optarg)) {
pr_err("Failed to add skip-mnt: %s\n", optarg);
return 1;
}
break;
case 1065:
if (!add_fsname_auto(optarg))
if (!add_fsname_auto(optarg)) {
pr_err("Failed while parsing --enable-fs option: %s", optarg);
return 1;
}
break;
case 1068:
SET_CHAR_OPTS(freeze_cgroup, optarg);
Expand All @@ -738,8 +748,10 @@ int parse_options(int argc, char **argv, bool *usage_error,
opts.ghost_limit = parse_size(optarg);
break;
case 1070:
if (irmap_scan_path_add(optarg))
if (irmap_scan_path_add(optarg)) {
pr_err("Failed while parsing --irmap-scan-path option: %s", optarg);
return -1;
}
break;
case 1071:
SET_CHAR_OPTS(lsm_profile, optarg);
Expand All @@ -765,13 +777,17 @@ int parse_options(int argc, char **argv, bool *usage_error,
goto bad_arg;

*aux = '\0';
if (ext_mount_add(optarg, aux + 1))
if (ext_mount_add(optarg, aux + 1)) {
pr_err("Could not add external mount when initializing config: %s, %s\n", optarg, aux + 1);
return 1;
}
}
break;
case 1073:
if (add_external(optarg))
if (add_external(optarg)) {
pr_err("Could not add external resource when initializing config: %s\n", optarg);
return 1;
}
break;
case 1074:
if (!strcmp("net", optarg))
Expand Down
12 changes: 9 additions & 3 deletions criu/crtools.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ int main(int argc, char *argv[], char *envp[])
BUG_ON(get_service_fd(SERVICE_FD_MIN+1) <
get_service_fd(SERVICE_FD_MAX-1));

if (fault_injection_init())
if (fault_injection_init()) {
pr_err("Failed to initialize fault injection when initializing crtools.\n");
return 1;
}

cr_pb_init();
setproctitle_init(argc, argv, envp);
Expand Down Expand Up @@ -171,8 +173,10 @@ int main(int argc, char *argv[], char *envp[])
/* We must not open imgs dir, if service is called */
if (strcmp(argv[optind], "service")) {
ret = open_image_dir(opts.imgs_dir, image_dir_mode(argv, optind));
if (ret < 0)
if (ret < 0) {
pr_err("Couldn't open image dir: %s", opts.imgs_dir);
return 1;
}
}

/*
Expand Down Expand Up @@ -205,8 +209,10 @@ int main(int argc, char *argv[], char *envp[])
if (log_init(opts.output))
return 1;

if (kerndat_init())
if (kerndat_init()) {
pr_err("Could not initialize kernel features detection.\n");
return 1;
}

if (fault_injected(FI_CANNOT_MAP_VDSO))
kdat.can_map_vdso = 0;
Expand Down
5 changes: 4 additions & 1 deletion criu/fault-injection.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdlib.h>
#include "criu-log.h"
#include "fault-injection.h"

enum faults fi_strategy;
Expand All @@ -14,8 +15,10 @@ int fault_injection_init(void)

start = atoi(val);

if (start <= 0 || start >= FI_MAX)
if (start <= 0 || start >= FI_MAX) {
pr_err("CRIU_FAULT out of bounds.\n");
return -1;
}

fi_strategy = start;
return 0;
Expand Down
4 changes: 3 additions & 1 deletion criu/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,10 @@ int open_image_dir(char *dir, int mode)
}

ret = install_service_fd(IMG_FD_OFF, fd);
if (ret < 0)
if (ret < 0) {
pr_err("install_service_fd failed.\n");
return -1;
}
fd = ret;

if (opts.stream) {
Expand Down
1 change: 1 addition & 0 deletions criu/include/criu-log.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define __CRIU_LOG_H__

#include "log.h"
#include <sys/types.h>

extern int log_init(const char *output);
extern void log_fini(void);
Expand Down

0 comments on commit df2610b

Please sign in to comment.