Home | History | Annotate | Line # | Download | only in rc.d
      1  1.1      elad #!/bin/sh
      2  1.1      elad #
      3  1.8  dholland # $NetBSD: perusertmp,v 1.8 2015/07/03 18:36:54 dholland Exp $
      4  1.1      elad #
      5  1.1      elad 
      6  1.1      elad # PROVIDE: perusertmp
      7  1.1      elad # REQUIRE: mountall
      8  1.1      elad # BEFORE:  cleartmp
      9  1.1      elad 
     10  1.1      elad $_rc_subr_loaded . /etc/rc.subr
     11  1.1      elad 
     12  1.1      elad name="perusertmp"
     13  1.1      elad rcvar="per_user_tmp"
     14  1.1      elad start_cmd="perusertmp_start"
     15  1.1      elad stop_cmd=":"
     16  1.1      elad 
     17  1.1      elad perusertmp_start()
     18  1.1      elad {
     19  1.1      elad 	echo "Preparing per-user /tmp."
     20  1.1      elad 
     21  1.1      elad 	# If /tmp is a mount point, we can't do anything.
     22  1.1      elad 	if [ -d "/tmp" ]; then
     23  1.1      elad 		local mount_point
     24  1.1      elad 
     25  1.1      elad 		mount_point=$(cd /tmp && /bin/df . | /usr/bin/tail -1 | /usr/bin/awk '{print $6}')
     26  1.6      tron 		if [ "${mount_point}" = "/tmp" ]; then
     27  1.1      elad 			echo "WARNING: /tmp is mounted."
     28  1.1      elad 			exit 1
     29  1.1      elad 		fi
     30  1.1      elad 	fi
     31  1.1      elad 
     32  1.1      elad 	# Enable magic symlinks.
     33  1.1      elad 	/sbin/sysctl -qw vfs.generic.magiclinks=1
     34  1.1      elad 
     35  1.1      elad 	# Fixup real temporary directory.
     36  1.1      elad 	if [ ! -d ${per_user_tmp_dir} ]; then
     37  1.2   xtraeme 		/bin/mkdir -p ${per_user_tmp_dir}
     38  1.1      elad 	fi
     39  1.8  dholland 	/sbin/chown root:wheel ${per_user_tmp_dir}
     40  1.4      elad 	/bin/chmod 0555 ${per_user_tmp_dir}
     41  1.1      elad 
     42  1.1      elad 	# Create magic link for /tmp.
     43  1.7       mjf 	if [ "$(/usr/bin/readlink /tmp)" != ${per_user_tmp_dir}/@ruid ]; then
     44  1.3      elad 		/bin/rm -rf /tmp
     45  1.7       mjf 		/bin/ln -s ${per_user_tmp_dir}/@ruid /tmp
     46  1.3      elad 	fi
     47  1.1      elad }
     48  1.1      elad 
     49  1.1      elad load_rc_config $name
     50  1.1      elad run_rc_command "$1"
     51