@@ -226,14 +226,16 @@ struct ReloaderImplArg {
226
226
};
227
227
228
228
std::vector<std::pair<std::filesystem::path, std::filesystem::path>>
229
- GetSourcesAndTargets (const std::filesystem::path& pivot_root_dir,
230
- absl::Span<const std::string> mounts) {
229
+ GetSourcesAndTargets (absl::Span<const std::string> mounts) {
231
230
std::vector<std::pair<std::filesystem::path, std::filesystem::path>>
232
231
sources_and_targets;
233
232
sources_and_targets.reserve (mounts.size ());
234
233
for (const std::filesystem::path mount : mounts) {
234
+ // Mount /x -> /x and /y/z -> /z.
235
235
sources_and_targets.push_back (
236
- {mount, pivot_root_dir / mount.relative_path ()});
236
+ {mount,
237
+ " /" /
238
+ (mount.has_filename () ? mount : mount.parent_path ()).filename ()});
237
239
}
238
240
return sources_and_targets;
239
241
}
@@ -248,21 +250,32 @@ int ReloaderImpl(void* arg) {
248
250
const absl::StatusOr<std::filesystem::path> pivot_root_dir =
249
251
CreatePivotRootDir ();
250
252
CHECK_OK (pivot_root_dir);
251
- const std::vector<std::pair<std::filesystem::path, std::filesystem::path>>
252
- sources_and_targets_read_only =
253
- GetSourcesAndTargets (*pivot_root_dir, reloader_impl_arg.mounts );
254
253
{
255
254
const std::filesystem::path socket_dir =
256
255
std::filesystem::path (reloader_impl_arg.socket_name ).parent_path ();
257
256
std::vector<std::pair<std::filesystem::path, std::filesystem::path>>
258
- socket_dir_read_and_write = {
259
- {socket_dir, *pivot_root_dir / socket_dir.relative_path ()}};
257
+ sources_and_targets_read_only =
258
+ GetSourcesAndTargets (reloader_impl_arg.mounts );
259
+ sources_and_targets_read_only.push_back ({socket_dir, socket_dir});
260
+
260
261
// SetupPivotRoot reduces the base filesystem image size. This pivot root
261
262
// includes the socket_dir, which must not be shared with the pivot_root
262
263
// created by the worker.
263
264
CHECK_OK (::privacy_sandbox::server_common::byob::SetupPivotRoot (
264
- *pivot_root_dir, socket_dir_read_and_write,
265
- /* cleanup_pivot_root_dir=*/ true , sources_and_targets_read_only));
265
+ *pivot_root_dir, sources_and_targets_read_only,
266
+ /* cleanup_pivot_root_dir=*/ true ,
267
+ /* sources_and_targets_read_and_write=*/
268
+ {{reloader_impl_arg.log_dir_name , reloader_impl_arg.log_dir_name }}));
269
+ }
270
+
271
+ // Reloader mounts /x -> /x and /y/z -> /z.
272
+ // Workers mounts /a -> /a.
273
+ std::vector<std::pair<std::filesystem::path, std::filesystem::path>>
274
+ sources_and_targets_read_only;
275
+ sources_and_targets_read_only.reserve (reloader_impl_arg.mounts .size ());
276
+ for (const auto & [_, target] :
277
+ GetSourcesAndTargets (reloader_impl_arg.mounts )) {
278
+ sources_and_targets_read_only.push_back ({target, target});
266
279
}
267
280
while (true ) {
268
281
// Start a new worker.
@@ -488,7 +501,7 @@ class WorkerRunner final : public WorkerRunnerService::Service {
488
501
return absl::OkStatus ();
489
502
}
490
503
491
- absl::Status CreateWorkerPool (std::filesystem::path binary_path,
504
+ absl::Status CreateWorkerPool (const std::filesystem::path binary_path,
492
505
std::string_view code_token,
493
506
const int num_workers,
494
507
const bool enable_log_egress)
@@ -498,15 +511,14 @@ class WorkerRunner final : public WorkerRunnerService::Service {
498
511
code_token_to_reloader_pids_[code_token].reserve (num_workers);
499
512
}
500
513
std::vector<std::string> mounts = mounts_;
501
- mounts.push_back (binary_path.parent_path ());
502
- if (enable_log_egress) {
503
- mounts.push_back (log_dir_name_);
504
- }
514
+ const std::filesystem::path binary_dir = binary_path.parent_path ();
515
+ mounts.push_back (binary_dir);
505
516
ReloaderImplArg reloader_impl_arg{
506
517
.mounts = std::move (mounts),
507
518
.socket_name = socket_name_,
508
519
.code_token = std::string (code_token),
509
- .binary_path = std::move (binary_path),
520
+ // Within the pivot root, binary_dir is a child of root, not progdir.
521
+ .binary_path = binary_dir.filename () / binary_path.filename (),
510
522
.dev_null_fd = dev_null_fd_,
511
523
.enable_log_egress = enable_log_egress,
512
524
.log_dir_name = log_dir_name_,
0 commit comments