Skip to content

Conversation

@bells17
Copy link
Contributor

@bells17 bells17 commented Oct 6, 2025

Description

Looking at runc's implementation, even when the HOME environment variable is specified, it does not add it if it's an empty string.
https://github.com/opencontainers/runc/blob/v1.3.2/libcontainer/env.go#L64

However, in youki, it appeared to be set even when it's an empty string, so I made a fix to align with runc's implementation.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test updates
  • CI/CD related changes
  • Other (please describe):

Testing

  • Added new unit tests
  • Added new integration tests
  • Ran existing test suite
  • Tested manually (please provide steps)

Related Issues

Fixes #

Additional Context

none

@bells17 bells17 marked this pull request as ready for review October 6, 2025 07:55
@saku3 saku3 added the kind/bug label Oct 6, 2025
@bells17 bells17 force-pushed the fix-home-env branch 2 times, most recently from 96ae877 to 97516cc Compare October 6, 2025 08:00
Copy link
Collaborator

@YJDoc2 YJDoc2 left a comment

Choose a reason for hiding this comment

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

Overall LGTM, a couple of nits/questions

fn set_home_env_if_not_exists(envs: &mut HashMap<String, String>, uid: Uid) {
if envs.get("HOME").is_none_or(|v| v.is_empty()) {
if let Some(dir_home) = utils::get_user_home(uid.into()) {
envs.insert("HOME".to_owned(), dir_home.to_string_lossy().to_string());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we be using to_string_lossy here? If for some reason, the home path has some invalid unicode chars, it will get incorrectly converted here right? Should we instead use to_str and in case of None, silently ignore like runc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing that out. I've fixed it according to your comment and added tests. Could you please review it again?
dd0e822

fn test_set_home_env_if_not_exists_not_set() {
let mut envs = HashMap::new();

set_home_env_if_not_exists(&mut envs, Uid::from_raw(0));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add one more test for non-zero uid?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added it. Can you check it again, please?
dd0e822

@bells17
Copy link
Contributor Author

bells17 commented Oct 17, 2025

Sorry, the test failed, I'll fix it.

@saku3
Copy link
Member

saku3 commented Nov 9, 2025

@bells17
Could you please resolve the conflict?
I think the tests will pass if we rerun them

@YJDoc2
Copy link
Collaborator

YJDoc2 commented Dec 2, 2025

@bells17 ping!
If you got busy with something else, and cannot work on this for now, that is ok, please let us know, so we can plan for this PR accordingly. Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants