Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: redirect nftables stdout and stderr to log CRIU's log file #2549

Open
wants to merge 1 commit into
base: criu-dev
Choose a base branch
from

Conversation

adrianreber
Copy link
Member

When using the nftables network locking backend and restoring a process a second time the network locking has already been deleted by the first restore. The second restore will print out to the console text like:

Error: Could not process rule: No such file or directory
delete table inet CRIU-202621

With this change CRIU's log FD is used by linbftables stdout and stderr.

When using the nftables network locking backend and restoring a process
a second time the network locking has already been deleted by the first
restore. The second restore will print out to the console text like:

Error: Could not process rule: No such file or directory
delete table inet CRIU-202621

With this change CRIU's log FD is used by linbftables stdout and stderr.

Signed-off-by: Adrian Reber <[email protected]>
goto err3;
}
nft_ctx_set_output(nft, fp);
nft_ctx_set_error(nft, fp);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code in nftables_lock_network_internal() and nftables_network_unlock() looks very similar.

Would it make sense to create a function?

static inline int nftables_set_logfd(struct nft_ctx *nft)
{
	FILE *fp;
	fp = fdopen(log_get_fd(), "w");
	if (!fp) {
		pr_perror("fdopen() failed");
		return -1;
	}
	nft_ctx_set_output(nft, fp);
	nft_ctx_set_error(nft, fp);

	fflush(fp);
	fclose(fp);
	return 0;
}

We can use this function in nftables_lock_network_internal():

if (nftables_set_logfd(nft)) {
	goto err2;
}

and in nftables_network_unlock():

if (nftables_set_logfd(nft)) {
	nft_ctx_free(nft);
	return -1;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nft_ctx_set_output() and nft_ctx_set_error() functions set the output or error file pointer in ctx to the value of fp. They return the previous value to aid in temporary file pointer overrides. On error, these functions return NULL. 

nftables_set_logfd can't close fp...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants