|
41 | 41 | /* Timeout in seconds for waiting for join semaphore. */ |
42 | 42 | #define JOIN_TIMEOUT 30 |
43 | 43 |
|
44 | | -/* Maximum length of paths we're willing to deal with. (Note that |
| 44 | +/* Maximum length of paths we’re willing to deal with. (Note that |
45 | 45 | system-defined PATH_MAX isn't reliable.) */ |
46 | 46 | #define PATH_CHARS 4096 |
47 | 47 |
|
| 48 | +/* Mount point for the tmpfs used by -W. We want this to be (a) always |
| 49 | + available [1], (b) short, (c) not used by anything else we care about |
| 50 | + during container setup, and (d) not wildly confusing if users see it in an |
| 51 | + error message. Must be a string literal because we use C’s literal |
| 52 | + concatenation feature. Options considered (all of these required by FHS): |
| 53 | +
|
| 54 | + /boot Not present if host is booted in some strange way? |
| 55 | + /etc Likely very reliable but seems risky |
| 56 | + /mnt Used for images on GitHub Actions and causes CI failures |
| 57 | + /opt Seems very omittable |
| 58 | + /srv I’ve never actually seen it used; reliable? |
| 59 | + /var Too aggressive? |
| 60 | + /var/spool Long; omittable for lightweight hosts? |
| 61 | +
|
| 62 | + [1]: https://www.pathname.com/fhs/pub/fhs-2.3.pdf */ |
| 63 | +#define WF_MNT "/srv" |
| 64 | + |
48 | 65 |
|
49 | 66 | /** Constants **/ |
50 | 67 |
|
@@ -306,26 +323,30 @@ void enter_udss(struct container *c) |
306 | 323 | // https://www.kernel.org/doc/html/v5.11/filesystems/tmpfs.html |
307 | 324 | // https://www.kernel.org/doc/html/v5.11/filesystems/overlayfs.html |
308 | 325 | if (c->overlay_size != NULL) { |
309 | | - VERBOSE("overlaying tmpfs for --write-fake (%s)", c->overlay_size); |
310 | 326 | char *options; |
| 327 | + struct stat st; |
| 328 | + VERBOSE("overlaying tmpfs for --write-fake (%s)", c->overlay_size); |
311 | 329 | T_ (1 <= asprintf(&options, "size=%s", c->overlay_size)); |
312 | | - Zf (mount(NULL, "/mnt", "tmpfs", 0, options), // host should have /mnt |
| 330 | + Zf (mount(NULL, WF_MNT, "tmpfs", 0, options), |
313 | 331 | "cannot mount tmpfs for overlay"); |
314 | 332 | free(options); |
315 | | - Z_ (mkdir("/mnt/upper", 0700)); |
316 | | - Z_ (mkdir("/mnt/work", 0700)); |
317 | | - Z_ (mkdir("/mnt/merged", 0700)); |
318 | | - mkdir_scratch = "/mnt/mkdir_overmount"; |
| 333 | + Z_ (mkdir(WF_MNT "/upper", 0700)); |
| 334 | + Z_ (mkdir(WF_MNT "/work", 0700)); |
| 335 | + Z_ (mkdir(WF_MNT "/merged", 0700)); |
| 336 | + mkdir_scratch = WF_MNT "/mkdir_overmount"; |
319 | 337 | Z_ (mkdir(mkdir_scratch, 0700)); |
320 | | - T_ (1 <= asprintf(&options, "lowerdir=%s,upperdir=%s,workdir=%s," |
321 | | - "index=on,userxattr,volatile", |
322 | | - c->newroot, "/mnt/upper", "/mnt/work")); |
| 338 | + T_ (1 <= asprintf(&options, ("lowerdir=%s,upperdir=%s,workdir=%s," |
| 339 | + "index=on,userxattr,volatile"), |
| 340 | + c->newroot, WF_MNT "/upper", WF_MNT "/work")); |
323 | 341 | // update newroot |
324 | | - c->newroot = "/mnt/merged"; |
| 342 | + Zf (stat(c->newroot, &st), |
| 343 | + "can't stat new root; overmounted by tmpfs for -W?: %s", c->newroot); |
| 344 | + c->newroot = WF_MNT "/merged"; |
325 | 345 | free(nr_parent); |
326 | 346 | free(nr_base); |
327 | 347 | path_split(c->newroot, &nr_parent, &nr_base); |
328 | | - Zf (mount(NULL, c->newroot, "overlay", 0, options), "can't overlay"); |
| 348 | + Zf (mount(NULL, c->newroot, "overlay", 0, options), |
| 349 | + "can't overlay: %s, %s", c->newroot, options); |
329 | 350 | VERBOSE("newroot updated: %s", c->newroot); |
330 | 351 | free(options); |
331 | 352 | } |
|
0 commit comments