Skip to content

Fix main_ctx_init: remove premature dir creation, increase MAX_PATH, add config file fallback#806

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-main-ctx-init-issues
Draft

Fix main_ctx_init: remove premature dir creation, increase MAX_PATH, add config file fallback#806
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-main-ctx-init-issues

Conversation

Copy link
Contributor

Copilot AI commented Mar 9, 2026

main_ctx_init eagerly creates a logs/ directory and sets the log file before callers can customize paths. Config file lookup is also hardcoded to a single location.

  • MAX_PATH: 260 → 1024. The Windows-era default was too small for typical Unix paths.
  • Remove premature side effects: Removed hv_mkdir(logdir) and hlog_set_file() from main_ctx_init. Callers can now customize g_main_ctx.logfile before the log directory is created.
  • Config file fallback chain: Search for the config file across multiple standard locations instead of assuming run_dir/etc/:
    1. run_dir/etc/{program}.conf
    2. run_dir/{program}.conf
    3. /usr/local/etc/{program}.conf (Unix)
    4. /etc/{program}.conf (Unix)
    5. Falls back to run_dir/etc/{program}.conf if none found
Original prompt

This section details on the original issue you should resolve

<issue_title>Some issues about the function main_ctx_init</issue_title>
<issue_description>1. The length of the macro MAX_PATH is only 260, isn't it really too small?
2. The logdir directly reads the running directory, then creates and uses the directory logs in this directory. Even if the directory was modified later, an empty directory has already been created here.
3. The configuration file directory should have a rollback: first try the current directory (not the current directory/etc), then try the directory /usr/local/etc if it does not exist, and finally try the directory /etc.

The main issue is that the directory will be automatically created before customizing the path.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…add config fallback

1. Increase MAX_PATH from 260 to 1024 to handle longer file paths
2. Remove premature hv_mkdir(logdir) and hlog_set_file() calls from
   main_ctx_init to avoid creating directories before user customization
3. Add config file path fallback: run_dir/etc/prog.conf -> run_dir/prog.conf
   -> /usr/local/etc/prog.conf -> /etc/prog.conf (Unix only for last two)

Co-authored-by: ithewei <26049660+ithewei@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issues with main_ctx_init function directory handling Fix main_ctx_init: remove premature dir creation, increase MAX_PATH, add config file fallback Mar 9, 2026
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.

Some issues about the function main_ctx_init

2 participants