#!/usr/bin/execlineb -P
# /dev/{fd,stdin,stdout,stderr,core} links + pts/shm.
# /dev/shm may already be a tmpfs, a directory on devtmpfs, or a symlink
# to /run/shm (Debian). mkdir -p fails on a symlink ("File exists");
# remounting with source name "shm" can yield "bad superblock on shm".
# shm logic lives in shell_up (execlineb cannot quote multiline sh -c).

foreground { ln -snf /proc/self/fd /dev/fd }
foreground { ln -snf /proc/self/fd/0 /dev/stdin }
foreground { ln -snf /proc/self/fd/1 /dev/stdout }
foreground { ln -snf /proc/self/fd/2 /dev/stderr }
foreground { ln -snf /proc/kcore /dev/core }

foreground {
	ifelse { test -d /dev/pts } { }
	{ mkdir -p /dev/pts }
}
foreground {
	if -n { mountpoint -q /dev/pts }
	mount -t devpts -o mode=0620,gid=5,nosuid,noexec devpts /dev/pts
}

foreground {
	/bin/sh /etc/s6-rc/sv/mount-devfs/shell_up
}
