Skip to content

Commit 4c65839

Browse files
author
Andrea Righi
committed
virtme-init: resync with upstream virtme-ng-init
Apply to virtme-init the same console/virtio-ports fixes applied to virtme-ng-init: - dcefa64 virtme-ng-init: set the proper ownership on the virtio-ports devices - f6a7ef5 virtme-ng-init: set proper ownership of the default console device - 97070a7 virtme-ng-init: always set XDG_RUNTIME_DIR See also: https://github.com/arighi/virtme-ng-init Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
1 parent 5d6be91 commit 4c65839

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

virtme/guest/virtme-init

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,16 @@ if [[ -n "${user_cmd}" ]]; then
235235
exit 1
236236
fi
237237

238+
# Set proper ownership on the virtio-ports devices
239+
if [[ -n "${virtme_user}" ]]; then
240+
chown ${virtme_user}:${virtme_user} \
241+
/dev/virtio-ports/virtme.stdin \
242+
/dev/virtio-ports/virtme.stdout \
243+
/dev/virtio-ports/virtme.stderr \
244+
/dev/virtio-ports/virtme.dev_stdout \
245+
/dev/virtio-ports/virtme.dev_stderr
246+
fi
247+
238248
# Fix /dev/stdout and /dev/stderr.
239249
#
240250
# When using a virtio serial port, the EBUSY error can occur if multiple
@@ -277,6 +287,9 @@ if [[ -z "$consdev" ]]; then
277287
log "can't deduce console device"
278288
exec bash --login # At least try to be helpful
279289
fi
290+
if [[ -n "${virtme_user}" ]]; then
291+
chown ${virtme_user}:${virtme_user} /dev/${consdev}
292+
fi
280293

281294
deallocvt
282295

@@ -312,6 +325,15 @@ install -d -m 0755 /tmp/roothome
312325
export HOME=/tmp/roothome
313326
mount --bind /tmp/roothome /root
314327

328+
# $XDG_RUNTIME_DIR defines the base directory relative to which user-specific
329+
# non-essential runtime files and other file objects (such as sockets, named
330+
# pipes, ...) should be stored.
331+
export XDG_RUNTIME_DIR=/run/user/$(id -u ${virtme_user})
332+
mkdir -p $XDG_RUNTIME_DIR
333+
if [[ -n "${virtme_user}" ]]; then
334+
chown ${virtme_user}:${virtme_user} $XDG_RUNTIME_DIR
335+
fi
336+
315337
# Bring up a functioning shell on the console. This is a bit magical:
316338
# We have no controlling terminal because we're attached to a fake
317339
# console device (probably something like /dev/console), which can't
@@ -323,11 +345,6 @@ if [[ -n "${virtme_stty_con}" ]]; then
323345
stty ${virtme_stty_con} <"/dev/$consdev"
324346
fi
325347
if [[ -n "${virtme_graphics}" ]]; then
326-
# Initialize XDG_RUNTIME_DIR (required to provide a better compatibility
327-
# with graphic apps).
328-
export XDG_RUNTIME_DIR=/run/user/$(id -u ${virtme_user})
329-
mkdir -p $XDG_RUNTIME_DIR
330-
331348
# Check if we need to enable the sound system.
332349
if cat /proc/cmdline |grep -q -E '(^| )virtme.sound($| )'; then
333350
pre_exec_cmd="$(dirname $0)/virtme-sound-script"
@@ -340,7 +357,6 @@ if [[ -n "${virtme_graphics}" ]]; then
340357
echo -e "${pre_exec_cmd}\nexec /tmp/.virtme-script" > ${xinit_rc}
341358
chmod +x /tmp/.virtme-script
342359
if [[ -n "${virtme_user}" ]]; then
343-
chown ${virtme_user}:${virtme_user} $XDG_RUNTIME_DIR
344360
chown ${virtme_user}:${virtme_user} ${xinit_rc}
345361
# Try to fix permissions on the virtual consoles, we are starting X
346362
# directly here so we may need extra permissions on the tty devices.

0 commit comments

Comments
 (0)