Skip to content

Update main.cpp - #7217

Open
LezheGao wants to merge 6 commits into
BOINC:masterfrom
LezheGao:patch-2
Open

Update main.cpp#7217
LezheGao wants to merge 6 commits into
BOINC:masterfrom
LezheGao:patch-2

Conversation

@LezheGao

@LezheGao LezheGao commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #1544

Description of the Change

Reorder the initialization sequence in init_core_client() to ensure that command-line arguments correctly override settings from cc_config.xml.

Before: command-line parsing happened before reading the config file, so XML values unconditionally overwrote the earlier command-line settings.
After:

  1. The --dir/-dir argument is extracted and handled early to change the working directory before any config file is read.
  2. cc_config.defaults() and nvc_config.defaults() are called.
  3. A first pass of gstate.parse_cmdline() parses all remaining arguments.
  4. read_config_file(true) loads cc_config.xml from the now-correct working directory.
  5. A second pass of gstate.parse_cmdline() re-applies all command-line options, which now take precedence over the XML-loaded values.

This change also updates do_gpu_detection() to follow the same pattern (read config first, then parse command line), keeping behaviour consistent.
Assisted-by: (not using an agent): DeepSeek-V4

Alternate Designs
Two other approaches were considered:

  1. Add source-tracking flags – extend CC_CONFIG with per-option set_by_cmdline booleans and skip XML assignment when that flag is true. This is more invasive, touches many configuration members, and increases maintenance overhead.
  2. Swap only the order without handling --dir specially – but this would break if cc_config.xml is not in the current directory when the client starts, because the directory change would happen after reading the file.

The chosen design is the simplest and least intrusive: it uses the existing parsing mechanism twice, requiring no changes to parse_options_client() or CC_CONFIG structure, and correctly handles directory changes.

Release Notes
Fix command-line options being overridden by cc_config.xml; command‑line arguments now take precedence over the configuration file.


Summary by cubic

Command-line arguments now correctly override cc_config.xml across platforms. init_core_client(): extract and apply --dir before first parse, switch to the data dir (or default on Windows), read config, then re-parse CLI to override; do_gpu_detection(): read config before CLI parse and remove the late read so diagnostics honor flags.

Written for commit 5d583a4. Summary will update on new commits.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 1 file

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread client/main.cpp Outdated
@LezheGao
LezheGao marked this pull request as draft August 12, 2026 08:34
@LezheGao
LezheGao marked this pull request as ready for review August 12, 2026 08:50
@LezheGao
LezheGao marked this pull request as draft August 12, 2026 08:53
@LezheGao
LezheGao marked this pull request as ready for review August 12, 2026 08:54
@LezheGao
LezheGao marked this pull request as draft August 12, 2026 08:58

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread client/main.cpp
Comment thread client/main.cpp Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread client/main.cpp
Comment thread client/main.cpp
@LezheGao
LezheGao marked this pull request as ready for review August 12, 2026 11:33

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 issue found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="client/main.cpp">

<violation number="1" location="client/main.cpp:194">
P2: Behavior regression in `--dir` error handling. The previous `-dir` branch in `parse_cmdline` did `if (chdir(argv[++i])) { perror("chdir"); exit(1); }`, so a bad directory terminated the client. The new code only logs an error and continues, and it sets `dir_specified = true` even when the chdir failed. As a result, on Windows the `chdir_to_data_dir()` fallback is also skipped (because `dir_specified` is true), and the client runs on with an unexpected working directory instead of failing fast as before.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread client/main.cpp
argv[j] = argv[j+2];
}
argc -= 2;
if (boinc_chdir(dir_path)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: Behavior regression in --dir error handling. The previous -dir branch in parse_cmdline did if (chdir(argv[++i])) { perror("chdir"); exit(1); }, so a bad directory terminated the client. The new code only logs an error and continues, and it sets dir_specified = true even when the chdir failed. As a result, on Windows the chdir_to_data_dir() fallback is also skipped (because dir_specified is true), and the client runs on with an unexpected working directory instead of failing fast as before.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At client/main.cpp, line 194:

<comment>Behavior regression in `--dir` error handling. The previous `-dir` branch in `parse_cmdline` did `if (chdir(argv[++i])) { perror("chdir"); exit(1); }`, so a bad directory terminated the client. The new code only logs an error and continues, and it sets `dir_specified = true` even when the chdir failed. As a result, on Windows the `chdir_to_data_dir()` fallback is also skipped (because `dir_specified` is true), and the client runs on with an unexpected working directory instead of failing fast as before.</comment>

<file context>
@@ -180,17 +180,46 @@ static void init_core_client(int argc, char** argv) {
+                    argv[j] = argv[j+2];
+                }
+                argc -= 2;
+                if (boinc_chdir(dir_path)) {
+                    log_message_error("Failed to chdir to specified directory");
+                }
</file context>

@davidpanderson

Copy link
Copy Markdown
Contributor

The BOINC docs don't specify the priority of

  • config file
  • cmdline args
  • env vars

So I suggest that we leave things the way they are.

@AenBleidd

Copy link
Copy Markdown
Member

We need to specify this somewhere to avoid misunderstandings.
I'll note this, and we discuss during one of the next calls.

@AenBleidd

Copy link
Copy Markdown
Member

@davidpanderson, I did a little research on this topic.
The general priorities list is the next (from lowest priority to highest priority):

  1. Build-in defaults
  2. Configuration file
  3. Environment variables
  4. Command-line parameters

I think we should document this and fix it whenever possible to follow this priorities list.
But before doing that, let's discuss it.

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.

Client: commandline arguments do not override cc_config.xml

3 participants