I ran into an issue locally where I didnt have lxc installed and some
commands were giving me back some false positives. Weird but this fixes
the problem I was facing.
The LXC provider issues the "fetch_ip" action to look up the IP address
of the container as part of its "ssh_info" action.
Vagrant::LXC::Action.action_fetch_ip checks the machine state using
Builtin::IsState, which calls Vagrant::Machine.state, which also updates
the state in the machine index and acquires a machine index entry lock to do that.
A race condition ensues in WaitForCommunicator.call, where ready_thr tries
to acquire the machine index lock while running ssh_info, and states_thr tries
to acquire the same lock doing its own state look up (env[:machine].state.id).
If they both try to acquire the lock at the same time, one will fail, and
an exception will be raised.
Work around this issue by checking for the desired machine state (:running) in
Vagrant::LXC::Provider.ssh_info, which can get the state from
Vagrant::LXC::Provider.state, which in turn does not write out the state into
the index file and does not acquire the index entry lock.
* for lxc to 1.0.0 using constant Vagrant::LXC::Driver::DEFAULT_CONTAINERS_PATH
* change method Vagrant::LXC::Driver::CLI#version to call lxc-create if lxc-version command not exists (to lxc version 1.0.0)
This action apparently needs to be added to every provider. See
lib/vagrant/plugins/providers/virtualbox/action.rb from the Vagrant
source for reference how the virtualbox provider is doing it.
Since the wrapper is versioned, we would end up having multiple `LXC`
command aliases, making `sudo` unusable:
```
>>> /etc/sudoers.d/vagrant-lxc-1-0-0-alpha-3-dev: Alias `LXC' already
>>> defined near line 2 <<<
sudo: parse error in /etc/sudoers.d/vagrant-lxc-1-0-0-alpha-3-dev near
line 2
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin
```
Some platforms (most notably CentOS and RHEL) use a kernel without
'attach' support. This patch detects this absence and falls back
to the alternative ways of doing things like detection of IP address
and halting the container.
It does so by running the command "true" through lxc-attach.