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

Environment Variable Init: HOME #680

Closed
mitnk opened this issue Feb 3, 2022 · 15 comments
Closed

Environment Variable Init: HOME #680

mitnk opened this issue Feb 3, 2022 · 15 comments
Assignees
Labels
enhancement New feature or request

Comments

@mitnk
Copy link
Contributor

mitnk commented Feb 3, 2022

Using youki as the runtime will missing the env HOME:

$ docker run --rm --runtime youki busybox env
HOSTNAME=efff650756b1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Expected (as using runc):

$ docker run --rm busybox env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=2ec2c9640467
HOME=/root

Where is environment variables initialized? I tried but not found in code of the repo.

@utam0k
Copy link
Member

utam0k commented Feb 3, 2022

@mitnk Thanks for your report. We set the environment variables here.
https://github.com/containers/youki/blob/a8e4003bc67b0eef7fcd59ec89928f7436d5c439/crates/libcontainer/src/process/container_init_process.rs#L415-L419

I couldn't find where the HOME environment variable gets, and I couldn't find it in the runtime-spec.
https://github.com/opencontainers/runtime-spec/blob/main/config.md

I'll do some more research. Do you know anything about it?

@utam0k utam0k added the enhancement New feature or request label Feb 5, 2022
@utam0k
Copy link
Member

utam0k commented Feb 5, 2022

@utam0k
Copy link
Member

utam0k commented Feb 5, 2022

Hi, @mitnk. If you have interested in this implementation, I'll leave this implementation to you. Of course, if you don't have time to do it, feel free to ask me to implement it 🙏

@mitnk
Copy link
Contributor Author

mitnk commented Feb 5, 2022

Thanks for the info, I'll have a try :)

@utam0k
Copy link
Member

utam0k commented Feb 5, 2022

Thanks for the info, I'll have a try :)

Awesome! If you have any questions, please do not hesitate to contact me.

@mitnk
Copy link
Contributor Author

mitnk commented Feb 5, 2022

@utam0k Question 1: I tried adding a syscall.get_pwdir(proc.user().uid()) before setting envs, but the file passwd seems empty (all fields are null-like). So I cannot get the home of user like this. Any ideas?

@mitnk
Copy link
Contributor Author

mitnk commented Feb 5, 2022

Draft PR: #681

@mitnk
Copy link
Contributor Author

mitnk commented Feb 5, 2022

Another question: how to see the logs printed by code like xxx.with_context(|| "some msg"), while using docker run --runtime youki ...? Do we have a doc on this anywhere (I haven't read all the docs yet).

@mitnk
Copy link
Contributor Author

mitnk commented Feb 5, 2022

The file /etc/passwd exists. It's libc::getpwuid_r() returning 2 (No such file/dir?). still checking the reason.

Content of /etc/passwd (via fs::read_to_string() after chroot()):

root:x:0:0:root:/root:/bin/sh
daemon:x:1:1:daemon:/usr/sbin:/bin/false
bin:x:2:2:bin:/bin:/bin/false
sys:x:3:3:sys:/dev:/bin/false
sync:x:4:100:sync:/bin:/bin/sync
mail:x:8:8:mail:/var/spool/mail:/bin/false
www-data:x:33:33:www-data:/var/www:/bin/false
operator:x:37:37:Operator:/var:/bin/false
nobody:x:65534:65534:nobody:/home:/bin/false

@mitnk
Copy link
Contributor Author

mitnk commented Feb 6, 2022

Not sure why, but a re-build fixed the issue. It just works now..

@utam0k
Copy link
Member

utam0k commented Feb 6, 2022

Another question: how to see the logs printed by code like xxx.with_context(|| "some msg"), while using docker run --runtime youki ...? Do we have a doc on this anywhere (I haven't read all the docs yet).

It is hard to see the log while using docker. If you want to see the log, it would be good to use the youki directory without using docker.

@utam0k
Copy link
Member

utam0k commented Feb 6, 2022

@utam0k Question 1: I tried adding a syscall.get_pwdir(proc.user().uid()) before setting envs, but the file passwd seems empty (all fields are null-like). So I cannot get the home of user like this. Any ideas?

Did you resolve this question by yourself?

@mitnk
Copy link
Contributor Author

mitnk commented Feb 6, 2022

Yes, resolved.

@mitnk
Copy link
Contributor Author

mitnk commented Feb 9, 2022

fixed in #681 Thanks!

@mitnk mitnk closed this as completed Feb 9, 2022
@utam0k
Copy link
Member

utam0k commented Feb 9, 2022

@mitnk Nice work!

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

No branches or pull requests

2 participants