aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/run-firecracker-vm/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/run-firecracker-vm/default.nix')
-rw-r--r--pkgs/run-firecracker-vm/default.nix9
1 files changed, 8 insertions, 1 deletions
diff --git a/pkgs/run-firecracker-vm/default.nix b/pkgs/run-firecracker-vm/default.nix
index 37047b0..b6e5387 100644
--- a/pkgs/run-firecracker-vm/default.nix
+++ b/pkgs/run-firecracker-vm/default.nix
@@ -374,10 +374,17 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ ''
# VM holds. The lock is held until the script exits. The MAC address is
# derived from the tap's number, as modules/host does, for the tap's
# fixed address.
+ # Lock files in a directory of the user's own: in /tmp, another user
+ # could take them first.
+ lockdir=''${XDG_RUNTIME_DIR:-/run/user/$(id -u)}
+ if ! test -d "$lockdir" -a -O "$lockdir"; then
+ echo "$0: $lockdir isn't a directory of $(id -un)'s; set XDG_RUNTIME_DIR" >&2
+ exit 1
+ fi
tap=
for t in $(find /sys/class/net -maxdepth 1 -name 'fctap*' -printf '%f\n' | sort -V); do
test "$(cat /sys/class/net/$t/owner)" = "$(id -u)" || continue
- exec {lock}>"''${XDG_RUNTIME_DIR:-/tmp}/run-firecracker-vm.$t.lock"
+ exec {lock}>"$lockdir/run-firecracker-vm.$t.lock"
if flock -n "$lock"; then
tap=$t
break