From 10c53c54d76a2be9e3b3d766958993ffcc9098c1 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Mon, 11 Dec 2017 11:48:19 -0500 Subject: [PATCH] Support alternative lxcpath in sudo wrapper The previously hardcoded lxc path prevented the sudo wrapper from working in environment with alternative `lxcpath`. I had to move `sudo_wrapper` from `provider` to `LXC` because the concept of "provider" is tied to a machine when a command sush as `sudoers` is not. Fixes #413 and #399 --- lib/vagrant-lxc.rb | 8 ++++++++ lib/vagrant-lxc/command/sudoers.rb | 4 ++++ lib/vagrant-lxc/provider.rb | 8 +------- templates/sudoers.rb.erb | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/vagrant-lxc.rb b/lib/vagrant-lxc.rb index 825eb18..a1e3bf1 100644 --- a/lib/vagrant-lxc.rb +++ b/lib/vagrant-lxc.rb @@ -1,5 +1,6 @@ require "vagrant-lxc/version" require "vagrant-lxc/plugin" +require "vagrant-lxc/sudo_wrapper" module Vagrant module LXC @@ -10,5 +11,12 @@ module Vagrant def self.sudo_wrapper_path "/usr/local/bin/vagrant-lxc-wrapper" end + + def self.sudo_wrapper + wrapper = Pathname.new(sudo_wrapper_path).exist? && + sudo_wrapper_path || nil + SudoWrapper.new(wrapper) + end + end end diff --git a/lib/vagrant-lxc/command/sudoers.rb b/lib/vagrant-lxc/command/sudoers.rb index 0016c13..58752e7 100644 --- a/lib/vagrant-lxc/command/sudoers.rb +++ b/lib/vagrant-lxc/command/sudoers.rb @@ -1,5 +1,7 @@ require 'tempfile' +require "vagrant-lxc/driver" + module Vagrant module LXC module Command @@ -43,11 +45,13 @@ module Vagrant # This requires vagrant 1.5.2+ https://github.com/mitchellh/vagrant/commit/3371c3716278071680af9b526ba19235c79c64cb def create_wrapper! + lxc_base_path = Driver.new(0, LXC.sudo_wrapper).containers_path wrapper = Tempfile.new('lxc-wrapper').tap do |file| template = Vagrant::Util::TemplateRenderer.new( 'sudoers.rb', :template_root => Vagrant::LXC.source_root.join('templates').to_s, :cmd_paths => build_cmd_paths_hash, + :lxc_base_path => lxc_base_path, :pipework_regex => "#{ENV['HOME']}/\.vagrant\.d/gems/(?:\\d+?\\.\\d+?\\.\\d+?/)?gems/vagrant-lxc.+/scripts/pipework" ) file.puts template.render diff --git a/lib/vagrant-lxc/provider.rb b/lib/vagrant-lxc/provider.rb index dead6ab..806733d 100644 --- a/lib/vagrant-lxc/provider.rb +++ b/lib/vagrant-lxc/provider.rb @@ -2,7 +2,6 @@ require "log4r" require "vagrant-lxc/action" require "vagrant-lxc/driver" -require "vagrant-lxc/sudo_wrapper" module Vagrant module LXC @@ -26,12 +25,7 @@ module Vagrant end def sudo_wrapper - @shell ||= begin - wrapper = Pathname.new(LXC.sudo_wrapper_path).exist? && - LXC.sudo_wrapper_path || nil - @logger.debug("Found sudo wrapper : #{wrapper}") if wrapper - SudoWrapper.new(wrapper) - end + @shell ||= LXC.sudo_wrapper end def ensure_lxc_installed! diff --git a/templates/sudoers.rb.erb b/templates/sudoers.rb.erb index cfcb68a..6f91123 100644 --- a/templates/sudoers.rb.erb +++ b/templates/sudoers.rb.erb @@ -78,7 +78,7 @@ class Whitelist end end -base = "/var/lib/lxc" +base = "<%= lxc_base_path %>" base_path = %r{\A#{base}/.*\z} ##