version 1.1

- bind whole /etc and /var when installing, removing or reconfiguring packages

- update readme
This commit is contained in:
Evgeny Zinoviev 2020-12-01 02:28:59 +03:00
parent 72fa0b987a
commit 743c8945fe
2 changed files with 55 additions and 13 deletions

View File

@ -1,6 +1,6 @@
# voidnsrun
`voidnsrun` is utility for launching programs in an isolated namespace with
**voidnsrun** is utility for launching programs in an isolated namespace with
alternative `/usr` tree. Its primary goal is to run glibc programs in
musl-libc Void Linux environments or vice-versa.
@ -33,7 +33,7 @@ Options:
-v: print version
```
`voidnsrun` needs to know the path to your alternative root directory and it can
**voidnsrun** needs to know the path to your alternative root directory and it can
read it from the `VOIDNSRUN_DIR` environment variable or you can use `-r`
argument to specify it.
@ -43,13 +43,19 @@ You may want to add something like this to your `~/.bashrc` or similar script:
export VOIDNSRUN_DIR=/glibc
```
By default, `voidnsrun` binds these paths from alternative root to the new
By default, **voidnsrun** binds these paths from alternative root to the new
namespace:
- `/usr`
- `/var/db/xbps`
- `/etc/xbps.d`
If you want to mount something else, use `-m` argument.
But if you're launching `xbps-install`, `xbps-remove` or `xbps-reconfigure`
and using **voidnsrun** version 1.1 or newer, this is what it will bind:
- `/usr`
- `/var`
- `/etc`
If you want to bind something else, use the `-m` argument.
## Example
@ -64,7 +70,7 @@ separate new directory:
# XBPS_ARCH=x86_64 xbps-install --repository=http://alpha.de.repo.voidlinux.org/current -r /glibc -S base-voidstrap
```
Export path to this installation for `voidnsrun`:
Export path to this installation for **voidnsrun**:
```
export VOIDNSRUN_DIR=/glibc
```
@ -93,9 +99,9 @@ glib-devel-2.66.2_1 /usr/share/gdb/auto-load/usr/lib/libgobject-2.0.so.0.6600.2-
libglib-devel-2.66.2_1 /usr/lib/libgobject-2.0.so -> /usr/lib/libgobject-2.0.so.0
```
Sync repos and install `glib`. You can use `voidnsrun` for this purpose too.
Sync repos and install `glib`. You can use **voidnsrun** for this purpose too.
Also, I think you should bind `/etc` and `/var` while using `xbps-install` via
`voidnsrun`, to not mess with your main system files.
**voidnsrun**, to not mess with your main system files.
```
$ sudo voidnsrun -r /glibc -m /etc -m /var xbps-install -Su
$ sudo voidnsrun -r /glibc -m /etc -m /var xbps-install glib
@ -113,6 +119,17 @@ end, it will work. (If it's not, then something's still missing. In particular,
make sure to install fonts related packages: `xorg-fonts`, `freetype`,
`fontconfig`, `libXft`.)
## Changelog
##### 1.1
- Bind whole `/etc` and `/var` when launching `xbps-install`, `xbps-remove` or
`xbps-reconfigure`.
##### 1.0
Initial release.
## License
BSD-2c

View File

@ -76,6 +76,24 @@ bool mountlist(
return true;
}
bool isxbpscommand(const char *s)
{
const char *commands[] = {
"/xbps-install",
"/xbps-remove",
"/xbps-reconfigure"
};
for (size_t i = 0; i < ARRAY_SIZE(commands); i++) {
const char *command = commands[i];
if (!strcmp(s, command+1))
return true;
char *slash = strrchr(s, '/');
if (slash && !strcmp(slash, command))
return true;
}
return false;
}
int main(int argc, char **argv)
{
if (argc < 2) {
@ -87,7 +105,7 @@ int main(int argc, char **argv)
char *dir = NULL;
size_t dirlen;
const char *usermounts[USERMOUNTS_MAX] = {0};
int usermounts_count = 0;
int usermounts_num = 0;
int c;
while ((c = getopt(argc, argv, "vhm:r:")) != -1) {
switch (c) {
@ -101,8 +119,8 @@ int main(int argc, char **argv)
dir = optarg;
break;
case 'm':
if (usermounts_count < USERMOUNTS_MAX) {
usermounts[usermounts_count++] = optarg;
if (usermounts_num < USERMOUNTS_MAX) {
usermounts[usermounts_num++] = optarg;
break;
} else {
ERROR("error: only up to %d user mounts allowed.\n",
@ -138,11 +156,18 @@ int main(int argc, char **argv)
}
/* Mount stuff from altroot to our private namespace. */
const char *mountpoints[] = {"/usr", "/var/db/xbps", "/etc/xbps.d"};
const char *mountpoints[3] = {"/usr", NULL, NULL};
if (isxbpscommand(argv[optind])) {
mountpoints[1] = "/var";
mountpoints[2] = "/etc";
} else {
mountpoints[1] = "/var/db/xbps";
mountpoints[2] = "/etc/xbps.d";
}
if (!mountlist(dir, dirlen, mountpoints, ARRAY_SIZE(mountpoints), true))
return 1;
if (usermounts_count > 0 &&
!mountlist(dir, dirlen, usermounts, usermounts_count, false))
if (usermounts_num > 0 &&
!mountlist(dir, dirlen, usermounts, usermounts_num, false))
return 1;
/* Drop root. */