Skip to content

Commit

Permalink
utils: suppress errors on missing legacy iptables
Browse files Browse the repository at this point in the history
When the legacy iptables backend is not installed, iptables-legacy-save
and ip6tables-legacy-save binary files are missing. This results in the
following error messages:

	(00.062021) iptables has nft backend: iptables-save v1.8.8 (nf_tables)
	Error (criu/util.c:626): execvp("iptables-legacy-save", ...) failed: No such file or directory
	(00.062793) Error (criu/util.c:641): exited, status=1
	(00.062800) Error (criu/util.c:1566): iptables-legacy-save -V failed
	(00.069758) iptables has nft backend: ip6tables-save v1.8.8 (nf_tables)
	Error (criu/util.c:626): execvp("ip6tables-legacy-save", ...) failed: No such file or directory
	(00.070615) Error (criu/util.c:641): exited, status=1
	(00.070624) Error (criu/util.c:1566): ip6tables-legacy-save -V failed
	(00.070632) skipping iptables dump - no legacy version present
	(00.070635) skipping ip6tables dump - no legacy version present

The error messages "No such file or directory" can be be ignored.
This patch avoids printing out the unnecessary and confusing error messages.
Instead only the following messages will be included in the logs:

	(00.048281) iptables has nft backend: iptables-save v1.8.7 (nf_tables)
	(00.048905) iptables-legacy-save -V failed
	(00.050044) iptables has nft backend: ip6tables-save v1.8.7 (nf_tables)
	(00.050661) ip6tables-legacy-save -V failed
	(00.050677) skipping iptables dump - no legacy version present
	(00.050680) skipping ip6tables dump - no legacy version present

Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
  • Loading branch information
rst0git committed Aug 1, 2023
1 parent 988a5f4 commit 853881c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion criu/include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ extern int is_anon_link_type(char *link, char *type);

#define is_hex_digit(c) (((c) >= '0' && (c) <= '9') || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))

#define CRS_CAN_FAIL 0x1 /* cmd can validly exit with non zero code */
#define CRS_CAN_FAIL 0x1 /* cmd can validly exit with non zero code */
#define CRS_CAN_ENOENT 0x2 /* cmd can fail with "No such file or directory" */

extern int cr_system(int in, int out, int err, char *cmd, char *const argv[], unsigned flags);
extern int cr_system_userns(int in, int out, int err, char *cmd, char *const argv[], unsigned flags, int userns_pid);
Expand Down
16 changes: 12 additions & 4 deletions criu/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,10 @@ int cr_system_userns(int in, int out, int err, char *cmd, char *const argv[], un

execvp(cmd, argv);

if (errno == ENOENT && (flags & CRS_CAN_ENOENT)) {
_exit(ENOENT);
}

/* We can't use pr_error() as log file fd is closed. */
fprintf(stderr, "Error (%s:%d): " LOG_PREFIX "execvp(\"%s\", ...) failed: %s\n", __FILE__, __LINE__,
cmd, strerror(errno));
Expand All @@ -639,8 +643,12 @@ int cr_system_userns(int in, int out, int err, char *cmd, char *const argv[], un
}

if (WIFEXITED(status)) {
if (!(flags & CRS_CAN_FAIL) && WEXITSTATUS(status))
pr_err("exited, status=%d\n", WEXITSTATUS(status));
int exit_status = WEXITSTATUS(status);
/* Don't print error message for ENOENT (No such file or directory)
* when CRS_CAN_ENOENT flag has been set. */
if (exit_status != ENOENT || !(flags & CRS_CAN_ENOENT))
if (!(flags & CRS_CAN_FAIL) && exit_status)
pr_err("exited, status=%d\n", WEXITSTATUS(status));
break;
} else if (WIFSIGNALED(status)) {
pr_err("killed by signal %d: %s\n", WTERMSIG(status), strsignal(WTERMSIG(status)));
Expand Down Expand Up @@ -1649,9 +1657,9 @@ static int is_iptables_nft(char *bin)
goto err;
}

ret = cr_system(-1, pfd[1], -1, cmd[0], cmd, CRS_CAN_FAIL);
ret = cr_system(-1, pfd[1], -1, cmd[0], cmd, CRS_CAN_ENOENT);
if (ret) {
pr_err("%s -V failed\n", cmd[0]);
pr_debug("%s -V failed\n", cmd[0]);
goto err;
}

Expand Down

0 comments on commit 853881c

Please sign in to comment.