dev-setup: allow a path prefix for use in chroots

With this adjustment, we can reuse this code elsewhere, such as in
nspawn.
This commit is contained in:
Dave Reisner 2012-08-14 20:00:30 -04:00 committed by Lennart Poettering
parent 50b3e64e27
commit 8f0e73f250
4 changed files with 17 additions and 10 deletions

View File

@ -398,7 +398,7 @@ int mount_setup(bool loaded_policy) {
/* Create a few default symlinks, which are normally created /* Create a few default symlinks, which are normally created
* by udevd, but some scripts might need them before we start * by udevd, but some scripts might need them before we start
* udevd. */ * udevd. */
dev_setup(); dev_setup("");
/* Mark the root directory as shared in regards to mount /* Mark the root directory as shared in regards to mount
* propagation. The kernel defaults to "private", but we think * propagation. The kernel defaults to "private", but we think

View File

@ -50,7 +50,7 @@ static int symlink_and_label(const char *old_path, const char *new_path) {
return r; return r;
} }
void dev_setup(void) { void dev_setup(const char *pathprefix) {
const char *j, *k; const char *j, *k;
static const char symlinks[] = static const char symlinks[] =
@ -60,6 +60,16 @@ void dev_setup(void) {
"/proc/self/fd/1\0" "/dev/stdout\0" "/proc/self/fd/1\0" "/dev/stdout\0"
"/proc/self/fd/2\0" "/dev/stderr\0"; "/proc/self/fd/2\0" "/dev/stderr\0";
NULSTR_FOREACH_PAIR(j, k, symlinks) NULSTR_FOREACH_PAIR(j, k, symlinks) {
symlink_and_label(j, k); char *linkname;
if (asprintf(&linkname, "%s/%s", pathprefix, k) < 0) {
log_oom();
break;
}
symlink_and_label(j, linkname);
free(linkname);
}
} }

View File

@ -1,7 +1,6 @@
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
#ifndef foodevsetuphfoo #pragma once
#define foodevsetuphfoo
/*** /***
This file is part of systemd. This file is part of systemd.
@ -22,6 +21,4 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>. along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/ ***/
void dev_setup(void); void dev_setup(const char *pathprefix);
#endif

View File

@ -1155,7 +1155,7 @@ int main(int argc, char *argv[])
mkdir("/run/udev", 0755); mkdir("/run/udev", 0755);
dev_setup(); dev_setup("");
static_dev_create_from_modules(udev); static_dev_create_from_modules(udev);
/* before opening new files, make sure std{in,out,err} fds are in a sane state */ /* before opening new files, make sure std{in,out,err} fds are in a sane state */