diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-12-12 16:59:15 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-12-12 17:30:25 +0100 |
commit | c4e34a612c81266773cf8358cb38a43d2e43474e (patch) | |
tree | 30365df7de959342130bd88d1ce6d6be7c32d73d /src/shared/util.c | |
parent | df9a75e480ecbfe230589a7c1e8e0bb790ee0595 (diff) |
nspawn: allow spawning ephemeral nspawn containers based on the root file system of the OS
This works now:
# systemd-nspawn -xb -D / -M foobar
Which boots up an ephemeral container, based on the host's root file
system. Or in other words: you can now run the very same host OS you
booted your system with also in a container, on top of it, without
having it interfere. Great for testing whether the init system you are
hacking on still boots without reboot the system!
Diffstat (limited to 'src/shared/util.c')
-rw-r--r-- | src/shared/util.c | 52 |
1 files changed, 50 insertions, 2 deletions
diff --git a/src/shared/util.c b/src/shared/util.c index 254b5637ae..ee95a4b6f7 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -6977,6 +6977,14 @@ int tempfn_xxxxxx(const char *p, char **ret) { assert(p); assert(ret); + /* + * Turns this: + * /foo/bar/waldo + * + * Into this: + * /foo/bar/.waldoXXXXXX + */ + fn = basename(p); if (!filename_is_valid(fn)) return -EINVAL; @@ -6987,7 +6995,7 @@ int tempfn_xxxxxx(const char *p, char **ret) { strcpy(stpcpy(stpcpy(mempcpy(t, p, fn - p), "."), fn), "XXXXXX"); - *ret = t; + *ret = path_kill_slashes(t); return 0; } @@ -7000,6 +7008,14 @@ int tempfn_random(const char *p, char **ret) { assert(p); assert(ret); + /* + * Turns this: + * /foo/bar/waldo + * + * Into this: + * /foo/bar/.waldobaa2a261115984a9 + */ + fn = basename(p); if (!filename_is_valid(fn)) return -EINVAL; @@ -7018,7 +7034,39 @@ int tempfn_random(const char *p, char **ret) { *x = 0; - *ret = t; + *ret = path_kill_slashes(t); + return 0; +} + +int tempfn_random_child(const char *p, char **ret) { + char *t, *x; + uint64_t u; + unsigned i; + + assert(p); + assert(ret); + + /* Turns this: + * /foo/bar/waldo + * Into this: + * /foo/bar/waldo/.3c2b6219aa75d7d0 + */ + + t = new(char, strlen(p) + 2 + 16 + 1); + if (!t) + return -ENOMEM; + + x = stpcpy(stpcpy(t, p), "/."); + + u = random_u64(); + for (i = 0; i < 16; i++) { + *(x++) = hexchar(u & 0xF); + u >>= 4; + } + + *x = 0; + + *ret = path_kill_slashes(t); return 0; } |