forked from microsoft/WSL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWslDistributionConfig.cpp
More file actions
132 lines (102 loc) · 4.23 KB
/
Copy pathWslDistributionConfig.cpp
File metadata and controls
132 lines (102 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*++
Copyright (c) Microsoft. All rights reserved.
Module Name:
WslDistributionConfig.h
Abstract:
This file contains the WslDistributionConfig class implementation.
--*/
#include "WslDistributionConfig.h"
#include "configfile.h"
#include "util.h"
using wsl::linux::WslDistributionConfig;
using namespace wsl::linux;
WslDistributionConfig::WslDistributionConfig(const char* configFilePath)
{
std::vector<ConfigKey> keys = {
ConfigKey(c_ConfigAutoMountOption, AutoMount),
ConfigKey("automount.root", DrvFsPrefix),
ConfigKey("automount.options", DrvFsOptions),
ConfigKey(c_ConfigMountFsTabOption, MountFsTab),
ConfigKey(c_ConfigLinkOsLibsOption, LinkOsLibs),
ConfigKey("filesystem.umask", Umask),
ConfigKey(c_ConfigInteropAppendWindowsPathOption, InteropAppendWindowsPath),
ConfigKey(c_ConfigInteropEnabledOption, InteropEnabled),
ConfigKey(c_ConfigGenerateHostsOption, GenerateHosts),
ConfigKey(c_ConfigGenerateResolvConfOption, GenerateResolvConf),
ConfigKey("network.hostname", HostName),
ConfigKey(c_ConfigAutoUpdateTimezoneOption, AutoUpdateTimezone),
ConfigKey(c_ConfigPlan9EnabledOption, Plan9Enabled),
ConfigKey("fileServer.logFile", Plan9LogFile),
ConfigKey("fileServer.logLevel", Plan9LogLevel),
ConfigKey("fileServer.logTruncate", Plan9LogTruncate),
ConfigKey(c_ConfigGpuEnabledOption, GpuEnabled),
ConfigKey(c_ConfigAppendGpuLibPathOption, AppendGpuLibPath),
ConfigKey("user.default", DefaultUser),
ConfigKey(c_ConfigBootCommandOption, BootCommand),
ConfigKey(c_ConfigBootSystemdOption, BootInit),
ConfigKey("boot.initTimeout", BootInitTimeout),
ConfigKey(c_ConfigBootProtectBinfmtOption, BootProtectBinfmt),
ConfigKey(c_ConfigEnableGuiAppsOption, GuiAppsEnabled),
};
//
// If the config file does not exist, then ParseConfigFile sets all the configuration
// values to their defaults.
//
wil::unique_file File{fopen(configFilePath, "r")};
ParseConfigFile(keys, File.get(), CFG_SKIP_UNKNOWN_VALUES, STRING_TO_WSTRING(CONFIG_FILE));
//
// Ensure the DrvFs prefix is well-formed (not empty and ends with a path separator).
//
std::string Prefix;
if (!DrvFsPrefix.empty())
{
Prefix = DrvFsPrefix;
}
if (Prefix.empty() || Prefix.back() != '/')
{
Prefix += '/';
DrvFsPrefix = Prefix;
}
//
// Using boot.systemd is only supported on WSL2.
//
BootInit &= UtilIsUtilityVm();
if (BootInit && (access(INIT_PATH, X_OK) < 0))
{
LOG_WARNING("access({}) failed {} - {} disabled", INIT_PATH, errno, c_ConfigBootSystemdOption);
BootInit = false;
}
//
// Apply safe mode overrides.
//
const char* Value = getenv(LX_WSL2_SAFE_MODE);
if (Value && (strcmp(Value, "1") == 0))
{
auto DisableBoolOption = [&](const char* Option, bool& ConfigValue) {
if (ConfigValue)
{
LOG_WARNING("{} - {} disabled", WSL_SAFE_MODE_WARNING, Option);
ConfigValue = false;
}
};
bool BootCommandEnabled = (BootCommand.has_value());
for (const auto& ConfigOption : std::vector<std::pair<const char*, bool&>>{
{c_ConfigAutoMountOption, AutoMount},
{c_ConfigLinkOsLibsOption, LinkOsLibs},
{c_ConfigMountFsTabOption, MountFsTab},
{c_ConfigBootCommandOption, BootCommandEnabled},
{c_ConfigBootSystemdOption, BootInit},
{c_ConfigGenerateHostsOption, GenerateHosts},
{c_ConfigGenerateResolvConfOption, GenerateResolvConf},
{c_ConfigPlan9EnabledOption, Plan9Enabled},
{c_ConfigAppendGpuLibPathOption, AppendGpuLibPath},
{c_ConfigGpuEnabledOption, GpuEnabled},
{c_ConfigInteropAppendWindowsPathOption, InteropAppendWindowsPath},
{c_ConfigInteropEnabledOption, InteropEnabled},
{c_ConfigAutoUpdateTimezoneOption, AutoUpdateTimezone}})
{
DisableBoolOption(ConfigOption.first, ConfigOption.second);
}
BootCommand = {};
}
}