#! /bin/sh
### BEGIN INIT INFO
# Provides:          mountdevsubfs
# Required-Start:    mountkernfs
# Required-Stop:
# Should-Start:      udev
# Default-Start:     S
# Default-Stop:
# Short-Description: Mount special file systems under /dev.
# Description:       Mount the virtual filesystems the kernel provides
#                    that ordinarily live under the /dev filesystem.
### END INIT INFO
#
# This script gets called multiple times during boot
#

setvar PATH = "/sbin:/bin"
setvar TTYGRP = '5'
setvar TTYMODE = '620'
test -f /etc/default/devpts && source /etc/default/devpts

setvar KERNEL = "$(uname -s)"

source /lib/lsb/init-functions
source /lib/init/vars.sh
source /lib/init/tmpfs.sh

source /lib/init/mount-functions.sh

# May be run several times, so must be idempotent.
# $1: Mount mode, to allow for remounting
proc mount_filesystems {
	setvar MNTMODE = "$1"

	# Mount a tmpfs on /run/shm
	mount_shm $MNTMODE

	# Mount /dev/pts
	if test $KERNEL = Linux
	{
		if test ! -d /dev/pts
		{
			mkdir --mode=755 /dev/pts
			test -x /sbin/restorecon && /sbin/restorecon /dev/pts
		}
		domount $MNTMODE devpts "" /dev/pts devpts "-onoexec,nosuid,gid=$TTYGRP,mode=$TTYMODE"
	}
}

case (1) {
  "" {
	echo "Warning: mountdevsubfs should be called with the 'start' argument." >&2
	mount_filesystems mount_noupdate
	}
  start {
	mount_filesystems mount_noupdate
	}
  restart|reload|force-reload {
	mount_filesystems remount
	}
  stop|status {
	# No-op
	}
  * {
	echo "Usage: mountdevsubfs [start|stop]" >&2
	exit 3
	}
}