Skip to content
This repository has been archived by the owner on Feb 24, 2020. It is now read-only.

lkvm: cannot run rkt from systemd-run because $HOME undefined #1393

Closed
alban opened this issue Sep 14, 2015 · 11 comments
Closed

lkvm: cannot run rkt from systemd-run because $HOME undefined #1393

alban opened this issue Sep 14, 2015 · 11 comments

Comments

@alban
Copy link
Member

alban commented Sep 14, 2015

$ sudo systemd-run -t /home/alban/go/src/github.com/coreos/rkt/build-rkt-0.8.0+git/bin/rkt --debug --insecure-skip-verify run --private-net=default --volume volume-data,kind=host,source=/tmp/redis --stage1-image=/home/alban/go/src/github.com/coreos/rkt/build-rkt-0.8.0+git/bin/stage1.aci --mds-register=false --local docker://redis
...
  # lkvm run -k stage1/rootfs/bzImage -m 128 -c 1 --name rkt-431edd16-6f75-41d3-bf4f-3584ad4af3ca
bind: No such file or directory
  Error: Failed adding socket to epoll
  Warning: Failed init: kvm_ipc__init

  Fatal: Initialisation failed

The same command executed directly (without systemd-run) works fine. When adding strace -e bind,open,stat,execve -f -s 512, it shows:

bind(6, {sa_family=AF_LOCAL, sun_path="/var/lib/rkt/pods/run/6c99d0ab-a0eb-4bb0-ae02-aec1e6f9bffc/(null)/rkt-6c99d0ab-a0eb-4bb0-ae02-aec1e6f9bffc."}, 109) = -1 ENOENT (No such file or directory)

The (null) in the socket path comes from kvm-ipc.c#44:

snprintf(full_name, sizeof(full_name), "%s/%s%s",
     kvm__get_dir(), kvm->cfg.guest_name, KVM_SOCK_SUFFIX);

The problem is that kvm__get_dir() is using $HOME and that variable is undefined. Moreover, the way lkvm uses realpath will make it set the directory to an uninitialized value from the stack:
main.c#16

Workaround: define $HOME when using systemd-run

$ sudo systemd-run -t --setenv=HOME=/root ...

Alternative workaround: use --uid=0, and $HOME will be implicitly defined.

$ sudo systemd-run --uid=0 -t --setenv=HOME=/root ...
alban added a commit to alban/rkt that referenced this issue Sep 14, 2015
When rkt is started via systemd-run, $HOME might not be defined.

Symptoms:
|bind: No such file or directory
|  Error: Failed adding socket to epoll
|  Warning: Failed init: kvm_ipc__init
|
|  Fatal: Initialisation failed

Fix rkt#1393
@jonboulle
Copy link
Contributor

great find!

alban added a commit to alban/rkt that referenced this issue Sep 15, 2015
Running the lkvm flavor of rkt in systemd does not currently work if
$HOME is not defined: see rkt#1393

It should be fixed in lkvm upstream, but meanwhile, mention the
workaround in the documentation.
alban added a commit to alban/rkt that referenced this issue Sep 16, 2015
More documentation in addition to rkt#1401

Running the lkvm flavor of rkt in systemd does not currently work if
$HOME is not defined: see rkt#1393

It should be fixed in lkvm upstream, but meanwhile, mention the
workaround in the documentation.
alban added a commit to alban/rkt that referenced this issue Sep 16, 2015
More documentation in addition to rkt#1401

Running the lkvm flavor of rkt in systemd does not currently work if
$HOME is not defined: see rkt#1393

It should be fixed in lkvm upstream, but meanwhile, mention the
workaround in the documentation.
@jonboulle
Copy link
Contributor

Workaround documented: #1401

Proper solution will be in upstream patch: http://thread.gmane.org/gmane.comp.emulators.kvm.devel/140459

@alban
Copy link
Member Author

alban commented Sep 18, 2015

I wonder if instead of documenting the workaround, we should add some code in stage1/init/init.go to set $HOME if it is not already set. That would be a better workaround for the user while waiting for upstream.

@jonboulle
Copy link
Contributor

You mean just for lkvm?

On Fri, Sep 18, 2015 at 10:09 AM, Alban Crequy notifications@github.com
wrote:

I wonder if instead of documenting the workaround, we should add some code
in stage1/init/init.go to set $HOME if it is not already set. That would
be a better workaround for the user while waiting for upstream.


Reply to this email directly or view it on GitHub
#1393 (comment).

@alban
Copy link
Member Author

alban commented Sep 18, 2015

Yes, just for lkvm.

@jonboulle
Copy link
Contributor

Seems reasonable.

On Fri, Sep 18, 2015 at 11:38 AM, Alban Crequy notifications@github.com
wrote:

Yes, just for lkvm.


Reply to this email directly or view it on GitHub
#1393 (comment).

@jellonek
Copy link
Contributor

As for temporary solution - seems very reasonable.

alban added a commit to alban/rkt that referenced this issue Sep 20, 2015
kvmtool currently does not work when $HOME is not defined. When started
by a systemd unit file (or by systemd-run), $HOME is typically
undefined, unless "User=" (or resp. "--uid=") is given.

Instead of asking users to work around the issue with "User=" or
"--uid=", just define that variable in rkt before calling lkvm.

This could be removed when this gets fixed in lkvm upstream.

Issue described in rkt#1393
alban added a commit to alban/rkt that referenced this issue Sep 21, 2015
kvmtool currently does not work when $HOME is not defined. When started
by a systemd unit file (or by systemd-run), $HOME is typically
undefined, unless "User=" (or resp. "--uid=") is given.

Instead of asking users to work around the issue with "User=" or
"--uid=", just define that variable in rkt before calling lkvm.

This could be removed when this gets fixed in lkvm upstream.

Issue described in rkt#1393
@jonboulle
Copy link
Contributor

@alban @jellonek did this ever land upstream?

@jonboulle jonboulle added this to the vfuture milestone Jan 15, 2016
@alban
Copy link
Member Author

alban commented Jan 18, 2016

No, this didn't land upstream. But since #1447 is merged, rkt works fine.

@jellonek
Copy link
Contributor

Upstream topic died somewhere around September so #1447 should be treated as solution and not as a workaround.

IMO this issue should be closed.

@alban
Copy link
Member Author

alban commented Jan 18, 2016

Ok, closing.

For the record, #1447 was merged into v0.9.0.

@alban alban closed this as completed Jan 18, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants