Repository: hashicorp/vagrant (Ruby)

Issue:
Vagrant makes LANG=C setting which breaks VBoxManage output
Vagrant [sets LANG=C](https://github.com/hashicorp/vagrant/blob/9076445d648a221ec43f0fcf363d0581dcb51de3/plugins/providers/virtualbox/driver/base.rb#L465) to make VBoxManage output independent of locale. However, on my system (Arch Linux, VirtualBox 7.0.8) VBoxManage doesn't produce any useful output when LANG is set to C. It does, however, produce the needed output when LANG=C.UTF-8.

### Debug output

https://gist.github.com/gentoo-root/911854ad48374df6cf0fe116d606fb30

### Expected behavior

Vagrant should work, i.e. start a VM with the simple Vagrantfile below.

### Actual behavior

`vagrant up` fails, because vagrant sets LANG=C when it runs VBoxManage commands, and VBoxManage doesn't produce any useful output when LANG=C is set.

### Reproduction information 

#### Vagrant version

Vagrant 2.3.4

#### Host operating system

Arch Linux

#### Guest operating system

Doesn't matter.

#### Steps to reproduce

Simple test for VirtualBox:

0. Make sure VBoxXPCOMIPCD is not running, because it caches the LANG setting. It's usually enough to wait for 5 seconds, unless something is interacting with VirtualBox.
1. Run `LANG=C VBoxManage list systemproperties` and observe empty output.
2. After VBoxXPCOMIPCD quits, run `LANG=C.UTF-8 VBoxManage list systemproperties` and observe plenty of output.

Vagrant-specific test:

1. Run `VAGRANT_LOG=info vagrant up` with the Vagrantfile below.
2. Observe the [error](https://gist.github.com/gentoo-root/911854ad48374df6cf0fe116d606fb30#file-vagrant-bad-log).
3. Wait for VBoxXPCOMIPCD to quit.
4. Run `LANG=C.UTF-8 VBoxManage list systemproperties | tail -n1; VAGRANT_LOG=info vagrant up`. The first command starts VBoxXPCOMIPCD and assigns LANG=C.UTF-8 to it, so even when vagrant uses LANG=C afterwards (within 5 seconds after the first command), vagrant's setting is ignored, and the VBoxManage commands started by vagrant run properly and produce output.
5. Observe the [good log](https://gist.github.com/gentoo-root/911854ad48374df6cf0fe116d606fb30#file-vagrant-good-log).

#### Vagrantfile

```ruby
Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/jammy64"
  config.vm.synced_folder ".", "/shared"
end
```


Discussion:
Unfortunately, #13150 didn't fix this bug. `locale -a` contains both `C` and `C.UTF-8` on my system, so `LANG=C` is still selected after this patch, and nothing really changes for me.

@chrisroberts, could you please reopen the issue?

```
DEBUG virtualbox_7_0: list of available C locales: ["C", "C.UTF-8", "en_US.utf8", "POSIX"]
DEBUG virtualbox_7_0: valid variation found for LANG value: C
DEBUG virtualbox_7_0: LANG value set: "C"
```
@gentoo-root Thanks for the update. I'll reorder the values so `C` is less preferred. 
@gentoo-root if you are able, would you mind giving the dev build a run and see if it resolves your issue: https://github.com/hashicorp/vagrant/releases/tag/2.3.6.dev%2B68b3d94



Patch:
diff --git a/plugins/providers/virtualbox/driver/base.rb b/plugins/providers/virtualbox/driver/base.rb
index 7da23e23b01..1304012516a 100644
--- a/plugins/providers/virtualbox/driver/base.rb
+++ b/plugins/providers/virtualbox/driver/base.rb
@@ -475,7 +475,7 @@ def raw(*command, &block)
         private
 
         # List of LANG values to attempt to use
-        LANG_VARIATIONS = %w(C C.UTF-8 C.utf8 en_US.UTF-8 en_US.utf8 POSIX).map(&:freeze).freeze
+        LANG_VARIATIONS = %w(C.UTF-8 C.utf8 en_US.UTF-8 en_US.utf8 C POSIX).map(&:freeze).freeze
 
         # By default set the LANG to C. If the host has the locale command
         # available, check installed locales and verify C is included (or


Test patch:
diff --git a/test/unit/plugins/providers/virtualbox/driver/base.rb b/test/unit/plugins/providers/virtualbox/driver/base.rb
index 08c94283ca2..766a506dcf1 100644
--- a/test/unit/plugins/providers/virtualbox/driver/base.rb
+++ b/test/unit/plugins/providers/virtualbox/driver/base.rb
@@ -42,6 +42,22 @@
           it "should use C for the lang" do
             expect(subject.send(:env_lang)).to eq({LANG: "C"})
           end
+
+          context "when stdout includes UTF-8 variants of C" do
+            let(:stdout) { "#{base}C\nC.UTF-8" }
+
+            it "should use the UTF-8 variant" do
+              expect(subject.send(:env_lang)).to eq({LANG: "C.UTF-8"})
+            end
+          end
+
+          context "when stdout includes utf8 variants of C" do
+            let(:stdout) { "#{base}C\nC.utf8" }
+
+            it "should use the utf8 variant" do
+              expect(subject.send(:env_lang)).to eq({LANG: "C.utf8"})
+            end
+          end
         end
 
         context "when stdout does not include C" do