Skip to content

Conversation

@rst0git
Copy link
Member

@rst0git rst0git commented Sep 3, 2025

When an additional configuration file is specified via RPC, this file is parsed twice: first at an early stage to load options such as --log-file, --work-dir, and --images-dir; and again after all RPC options and configuration files have been evaluated.

This allows users to overwrite options specified via RPC by the container runtime (e.g., --tcp-established). However, processing the RPC config file twice leads to silently duplicating the values of repeatable options such as --action-script.

To address this problem, we adjust the order of options parsing so that the RPC config file is evaluated only once. This does not introduce any functional changes.

Fixes #2727

@rst0git rst0git force-pushed the rpc-config-action-script branch 3 times, most recently from 8e1b574 to 247c479 Compare September 3, 2025 20:47
@rst0git rst0git force-pushed the rpc-config-action-script branch from 247c479 to 91cdf5d Compare September 3, 2025 20:54
@rst0git rst0git marked this pull request as ready for review September 3, 2025 21:44
@avagin
Copy link
Member

avagin commented Sep 4, 2025

Could you explain why we need to parse it twice? Why do we need to handle log-file, workdir before parsing other options? Why we can't handle these option on the second run?

@rst0git
Copy link
Member Author

rst0git commented Sep 4, 2025

@avagin The only information I found are the following commit messages:

cr-service: add support for configuration files in RPC mode

Most CRIU options are correctly used by just writing the new values to
the corresponding fields of the opts structure. For the RPC case there
are, however, a few options (output, work_dir, imgs_dir) which need
special handling.
So the RPC configuration file is parsed twice. First time to get output,
work_dir and imgs_dir. Once those are read and correctly used, the RPC
code overwrites all options again by values set by the RPC interface. At
the end the RPC configuration file is read a second time and finally
overwrites the values set via RPC.

Fix RPC configuration file handling

While writing runc test cases to verify that runc correctly uses RPC
configuration files it became clear that some things were not working as
they are supposed to. Looking closer at the code to set log files
via RPC configuration files I discovered that the code seems wrong (at
least I did not understand it any more (or the intentions behind it)).

@adrianreber Do you remember by any chance why we need to parse the RPC configuration file twice?

@avagin
Copy link
Member

avagin commented Sep 4, 2025

are, however, a few options (output, work_dir, imgs_dir) which need

I think we need to rework how these options are handled.

@rst0git rst0git force-pushed the rpc-config-action-script branch from 91cdf5d to aab4344 Compare September 10, 2025 10:28
@rst0git rst0git changed the title cr-service: Refactor early RPC config parsing cr-service: Refactor RPC config parsing Sep 10, 2025
@rst0git
Copy link
Member Author

rst0git commented Sep 10, 2025

I think we need to rework how these options are handled.

@avagin I've updated the pull request with these changes.

@adrianreber
Copy link
Member

adrianreber commented Sep 10, 2025

Concerning this line from the commit:

This does not introduce any functional changes.

This is not true. Probably better to remove that line. Because you will be loosing early log messages with this change. Output from a couple of functions (check_caps(), kerndat_init() and more) will be written to another log file (or maybe nowhere) if the log file is changed via an additional configuration file. This means the user will now miss some debug output.

@rst0git
Copy link
Member Author

rst0git commented Sep 10, 2025

Thanks for the comments Adrian!

Because you will be loosing early log messages with this change.

Early log messages are still preserved with this change. We handle these in log_init() with flush_early_log_buffer().

@adrianreber
Copy link
Member

Thanks for the comments Adrian!

Because you will be loosing early log messages with this change.

Early log messages are still preserved with this change. We handle these in log_init().

That is good to know. Maybe add that as a comment in the code or commit.

@rst0git rst0git force-pushed the rpc-config-action-script branch from aab4344 to cb984b6 Compare September 10, 2025 11:58
@rst0git rst0git force-pushed the rpc-config-action-script branch 2 times, most recently from 9d89004 to bdfedae Compare October 1, 2025 09:19
@rst0git rst0git force-pushed the rpc-config-action-script branch from bdfedae to c945890 Compare October 3, 2025 02:40
@rst0git rst0git requested a review from avagin October 3, 2025 06:32
@avagin avagin requested a review from adrianreber October 3, 2025 15:38
When an additional configuration file is specified via RPC, this file is
parsed twice: first at an early stage to load options such as --log-file,
--work-dir, and --images-dir; and again after all RPC options and
configuration files have been evaluated.

This allows users to overwrite options specified via RPC by the
container runtime (e.g., --tcp-established). However, processing
the RPC config file twice leads to silently duplicating the values
of repeatable options such as `--action-script`.

To address this problem, we adjust the order of options parsing so
that the RPC config file is evaluated only once. This change should
not introduce any functional changes. Note that this change does
not affect the logging functionality, as early log messages are
temporarily buffered and only written to the log file once it has
been initialized (see commit 1ff2333 "Printout early log messages").

Fixes checkpoint-restore#2727

Suggested-by: Andrei Vagin <avagin@google.com>
Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
Extend the test for overwriting config options via RPC with
repeatable option (--action-script) and verify that the value
will not be silently duplicated.

Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
@rst0git rst0git force-pushed the rpc-config-action-script branch from c945890 to 659a158 Compare October 4, 2025 03:26
@rst0git rst0git requested a review from avagin October 4, 2025 04:02
@avagin avagin merged commit c14c2ae into checkpoint-restore:criu-dev Oct 13, 2025
42 of 46 checks passed
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.

Parsing runc.conf results in duplicate values

3 participants