From 7f58f7a26e09f9781c7488fbdfcb7025bb935f97 Mon Sep 17 00:00:00 2001
From: Fabio Rehm <fgrehm@gmail.com>
Date: Sun, 28 Jul 2013 02:28:03 -0300
Subject: [PATCH] Add support for logging `redir` output by setting REDIR_LOG
 env var

Closes #51
---
 CHANGELOG.md                            | 1 +
 lib/vagrant-lxc/action/forward_ports.rb | 6 ++++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 70c45a4..26145c8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@ FEATURES:
 
   - Add support for salt-minion and add latest dev release for ubuntu codenamed saucy [#116](https://github.com/fgrehm/vagrant-lxc/pull/116)
   - Add support for using a sudo wrapper script [#90](https://github.com/fgrehm/vagrant-lxc/issues/90)
+  - `redir` will log to `/var/log/syslog` if `REDIR_LOG` env var is provided
 
 IMPROVEMENTS:
 
diff --git a/lib/vagrant-lxc/action/forward_ports.rb b/lib/vagrant-lxc/action/forward_ports.rb
index 75084ff..e548e7e 100644
--- a/lib/vagrant-lxc/action/forward_ports.rb
+++ b/lib/vagrant-lxc/action/forward_ports.rb
@@ -72,8 +72,10 @@ module Vagrant
         end
 
         def redirect_port(host_ip, host_port, guest_ip, guest_port)
-          host_ip = "--laddr=#{host_ip} " if host_ip
-          redir_cmd = "redir #{host_ip}--lport=#{host_port} --caddr=#{guest_ip} --cport=#{guest_port} 2>/dev/null"
+          params = %W( --lport=#{host_port} --caddr=#{guest_ip} --cport=#{guest_port} )
+          params.unshift "--laddr=#{host_ip}" if host_ip
+          params << '--syslog' if ENV['REDIR_LOG']
+          redir_cmd = "redir #{params.join(' ')} 2>/dev/null"
 
           @logger.debug "Forwarding port with `#{redir_cmd}`"
           spawn redir_cmd