MCPcopy Create free account
hub / github.com/apache/mesos / parseArchMap

Function parseArchMap

src/linux/seccomp/seccomp_parser.cpp:102–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100
101
102Try<Nothing> parseArchMap(
103 const JSON::Object& json,
104 ContainerSeccompProfile* profile)
105{
106 Result<JSON::Array> archMap = json.at<JSON::Array>("archMap");
107 if (!archMap.isSome()) {
108 return Error(
109 "Cannot determine 'archMap' for the Seccomp configuration: " +
110 (archMap.isError() ? archMap.error() : "Not found"));
111 }
112
113 foreach (const JSON::Value& item, archMap->values) {
114 if (!item.is<JSON::Object>()) {
115 return Error("'archMap' contains a non-object item");
116 }
117
118 const auto architecture =
119 item.as<JSON::Object>().at<JSON::String>("architecture");
120
121 if (!architecture.isSome()) {
122 return Error(
123 "Cannot determine 'architecture' field for 'archMap' item: " +
124 (architecture.isError() ? architecture.error() : "Not found"));
125 }
126
127 const auto arch = parseArchitecture(architecture->value);
128 if (arch.isError()) {
129 return Error(arch.error());
130 }
131
132 Try<bool> nativeArch = SeccompFilter::nativeArch(arch.get());
133 if (nativeArch.isError()) {
134 return Error(nativeArch.error());
135 }
136
137 // We ignore architectures that doesn't match the native architecture of
138 // this host.
139 if (!nativeArch.get()) {
140 continue;
141 }
142
143 // Add this architecture with corresponding subarchitectures to the list of
144 // architectures of the profile.
145 const auto subArchitectures =
146 item.as<JSON::Object>().at<JSON::Array>("subArchitectures");
147
148 if (!subArchitectures.isSome()) {
149 return Error(
150 "Cannot determine 'subArchitectures' field for 'archMap' item: " +
151 (subArchitectures.isError() ? subArchitectures.error()
152 : "Not found"));
153 }
154
155 foreach (const JSON::Value& subItem, subArchitectures->values) {
156 if (!subItem.is<JSON::String>()) {
157 return Error("'subArchitectures' contains a non-string item");
158 }
159

Callers 1

parseProfileDataFunction · 0.85

Calls 5

NothingClass · 0.85
errorMethod · 0.65
ErrorFunction · 0.50
isSomeMethod · 0.45
isErrorMethod · 0.45

Tested by

no test coverage detected