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