move rc_svcdir to /run/openrc on Linux systems
If you are not using linux, this should not affect you. If you are using linux, from this point forward, openrc requires the /run directory to be a mounted tmpfs. If it is, you can run @LIBEXECDIR@/sh/migrate-to-run.sh as root to migrate your dependency tree and state information to the new location. If it is not, you must create the /run directory as root with permissions 755 then reboot your system. reported-by: Maxim Kammerer <mk@dee.su> X-Gentoo-Bug: 401059 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=401059
This commit is contained in:
		
							
								
								
									
										2
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								Makefile
									
									
									
									
									
								
							| @@ -25,6 +25,8 @@ include ${MK}/dist.mk | |||||||
| include ${MK}/git.mk | include ${MK}/git.mk | ||||||
|  |  | ||||||
| _installafter: | _installafter: | ||||||
|  | ifneq ($(OS),Linux) | ||||||
| 	${INSTALL} -d ${DESTDIR}/${LIBEXECDIR}/init.d | 	${INSTALL} -d ${DESTDIR}/${LIBEXECDIR}/init.d | ||||||
|  | endif | ||||||
| 	${INSTALL} -d ${DESTDIR}/${LIBEXECDIR}/tmp | 	${INSTALL} -d ${DESTDIR}/${LIBEXECDIR}/tmp | ||||||
| 	${ECHO} "${VERSION}${GITVER}" > ${DESTDIR}/${LIBEXECDIR}/version | 	${ECHO} "${VERSION}${GITVER}" > ${DESTDIR}/${LIBEXECDIR}/version | ||||||
|   | |||||||
							
								
								
									
										1
									
								
								sh/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								sh/.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -10,3 +10,4 @@ ifwatchd-carrier.sh | |||||||
| ifwatchd-nocarrier.sh | ifwatchd-nocarrier.sh | ||||||
| udhcpc-hook.sh | udhcpc-hook.sh | ||||||
| tmpfiles.sh | tmpfiles.sh | ||||||
|  | migrate-to-run.sh | ||||||
|   | |||||||
| @@ -12,8 +12,10 @@ include ${MK}/os.mk | |||||||
| SRCS-FreeBSD= | SRCS-FreeBSD= | ||||||
| BIN-FreeBSD= | BIN-FreeBSD= | ||||||
|  |  | ||||||
| SRCS-Linux=	cgroup-release-agent.sh.in init-early.sh.in udhcpc-hook.sh.in | SRCS-Linux=	cgroup-release-agent.sh.in init-early.sh.in migrate-to-run.sh.in \ | ||||||
| BIN-Linux=	cgroup-release-agent.sh init-early.sh udhcpc-hook.sh | 	udhcpc-hook.sh.in | ||||||
|  | BIN-Linux=	cgroup-release-agent.sh init-early.sh migrate-to-run.sh \ | ||||||
|  | 	udhcpc-hook.sh | ||||||
|  |  | ||||||
| SRCS-NetBSD=	ifwatchd-carrier.sh.in ifwatchd-nocarrier.sh.in | SRCS-NetBSD=	ifwatchd-carrier.sh.in ifwatchd-nocarrier.sh.in | ||||||
| BIN-NetBSD=	ifwatchd-carrier.sh ifwatchd-nocarrier.sh | BIN-NetBSD=	ifwatchd-carrier.sh ifwatchd-nocarrier.sh | ||||||
|   | |||||||
| @@ -3,62 +3,6 @@ | |||||||
| # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> | # Copyright (c) 2007-2009 Roy Marples <roy@marples.name> | ||||||
| # Released under the 2-clause BSD license. | # Released under the 2-clause BSD license. | ||||||
|  |  | ||||||
| # This basically mounts $RC_SVCDIR as a ramdisk. |  | ||||||
| # The tricky part is finding something our kernel supports |  | ||||||
| # tmpfs and ramfs are easy, so force one or the other. |  | ||||||
| svcdir_restorecon() |  | ||||||
| { |  | ||||||
| 	local rc=0 |  | ||||||
| 	if [ -x /usr/sbin/selinuxenabled -a -c /selinux/null ] && |  | ||||||
| 	  selinuxenabled; then |  | ||||||
| 		restorecon $RC_SVCDIR |  | ||||||
| 		rc=$? |  | ||||||
| 	fi |  | ||||||
| 	return $rc |  | ||||||
| } |  | ||||||
|  |  | ||||||
| mount_svcdir() |  | ||||||
| { |  | ||||||
| 	# mount from fstab if we can |  | ||||||
| 	fstabinfo --mount "$RC_SVCDIR" && return 0 |  | ||||||
|  |  | ||||||
| 	local fs= fsopts="-o rw,noexec,nodev,nosuid" |  | ||||||
| 	local svcsize=${rc_svcsize:-1024} |  | ||||||
|  |  | ||||||
| 	# Some buggy kernels report tmpfs even when not present :( |  | ||||||
| 	if grep -Eq "[[:space:]]+tmpfs$" /proc/filesystems; then |  | ||||||
| 		local tmpfsopts="${fsopts},mode=755,size=${svcsize}k" |  | ||||||
| 		mount -n -t tmpfs $tmpfsopts rc-svcdir "$RC_SVCDIR" |  | ||||||
| 		if [ $? -eq 0 ]; then |  | ||||||
| 			svcdir_restorecon |  | ||||||
| 			[ $? -eq 0 ] && return 0 |  | ||||||
| 		fi |  | ||||||
| 	fi |  | ||||||
|  |  | ||||||
| 	if grep -Eq "[[:space:]]+ramfs$" /proc/filesystems; then |  | ||||||
| 		fs="ramfs" |  | ||||||
| 		# ramfs has no special options |  | ||||||
| 	elif [ -e /dev/ram0 ] \ |  | ||||||
| 		&& grep -Eq "[[:space:]]+ext2$" /proc/filesystems; then |  | ||||||
| 		devdir="/dev/ram0" |  | ||||||
| 		fs="ext2" |  | ||||||
| 		dd if=/dev/zero of="$devdir" bs=1k count="$svcsize" |  | ||||||
| 		mkfs -t "$fs" -i 1024 -vm0 "$devdir" "$svcsize" |  | ||||||
| 	else |  | ||||||
| 		echo |  | ||||||
| 		eerror "OpenRC requires tmpfs, ramfs or a ramdisk + ext2" |  | ||||||
| 		eerror "compiled into the kernel" |  | ||||||
| 		echo |  | ||||||
| 		return 1 |  | ||||||
| 	fi |  | ||||||
|  |  | ||||||
| 	mount -n -t "$fs" $fsopts rc-svcdir "$RC_SVCDIR" |  | ||||||
| 	if [ $? -eq 0 ]; then |  | ||||||
| 		svcdir_restorecon |  | ||||||
| 		[ $? -eq 0 ] && return 0 |  | ||||||
| 	fi |  | ||||||
| } |  | ||||||
|  |  | ||||||
| . "$RC_LIBEXECDIR"/sh/functions.sh | . "$RC_LIBEXECDIR"/sh/functions.sh | ||||||
| [ -r /etc/rc.conf ] && . /etc/rc.conf | [ -r /etc/rc.conf ] && . /etc/rc.conf | ||||||
|  |  | ||||||
| @@ -91,24 +35,32 @@ if $mountproc; then | |||||||
| 	eend $? | 	eend $? | ||||||
| fi | fi | ||||||
|  |  | ||||||
| # Mount tmpfs on /run when directory exists. |  | ||||||
| # /run is a new directory for storing volatile runtime data. | # /run is a new directory for storing volatile runtime data. | ||||||
| # Read more about /run at https://lwn.net/Articles/436012 | # Read more about /run at https://lwn.net/Articles/436012 | ||||||
| if [ -d /run ]; then | if [ ! -d /run ]; then | ||||||
| 	if mountinfo -q /run; then | 	eerror "The /run directory does not exist. Unable to continue." | ||||||
| 		einfo "/run is already mounted, skipping" | 	return 1 | ||||||
| 	else |  | ||||||
| 		ebegin "Mounting /run" |  | ||||||
| 		if ! fstabinfo --mount /run; then |  | ||||||
| 			mount -t tmpfs -o mode=0755,nosuid,nodev tmpfs /run |  | ||||||
| 		fi |  | ||||||
| 		eend $? |  | ||||||
| 	fi |  | ||||||
| 	checkpath -d -m 0775 -o root:uucp /run/lock |  | ||||||
| elif [ -e /run ]; then |  | ||||||
| 	einfo "Unable to mount /run since it is not a directory" |  | ||||||
| fi | fi | ||||||
|  |  | ||||||
|  | if mountinfo -q /run; then | ||||||
|  | 	einfo "/run is already mounted, skipping" | ||||||
|  | else | ||||||
|  | 	ebegin "Mounting /run" | ||||||
|  | 	rc=0 | ||||||
|  | 	if ! fstabinfo --mount /run; then | ||||||
|  | 		mount -t tmpfs -o mode=0755,nosuid,nodev tmpfs /run | ||||||
|  | 		rc=$? | ||||||
|  | 	fi | ||||||
|  | 	if [ $rc != 0 ]; then | ||||||
|  | 		eerror "Unable to mount tmpfs on /run." | ||||||
|  | 		eerror "Can't continue." | ||||||
|  | 		exit 1 | ||||||
|  | 	fi | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | checkpath -d $RC_SVCDIR | ||||||
|  | checkpath -d -m 0775 -o root:uucp /run/lock | ||||||
|  |  | ||||||
| # Try to mount xenfs as early as possible, otherwise rc_sys() will always | # Try to mount xenfs as early as possible, otherwise rc_sys() will always | ||||||
| # return RC_SYS_XENU and will think that we are in a domU while it's not. | # return RC_SYS_XENU and will think that we are in a domU while it's not. | ||||||
| if grep -Eq "[[:space:]]+xenfs$" /proc/filesystems; then | if grep -Eq "[[:space:]]+xenfs$" /proc/filesystems; then | ||||||
| @@ -119,4 +71,9 @@ if grep -Eq "[[:space:]]+xenfs$" /proc/filesystems; then | |||||||
| 	eend $? | 	eend $? | ||||||
| fi | fi | ||||||
|  |  | ||||||
| . "$RC_LIBEXECDIR"/sh/init-common-post.sh | if [ -e "$RC_LIBEXECDIR"/cache/deptree ]; then | ||||||
|  | 	cp -p "$RC_LIBEXECDIR"/cache/* "$RC_SVCDIR" 2>/dev/null | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | echo sysinit >"$RC_SVCDIR"/softlevel | ||||||
|  | exit 0 | ||||||
|   | |||||||
							
								
								
									
										50
									
								
								sh/migrate-to-run.sh.in
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								sh/migrate-to-run.sh.in
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,50 @@ | |||||||
|  | #!@SHELL@ | ||||||
|  | # Copyright (c) 2012 William Hubbs <w.d.hubbs@gmail.com> | ||||||
|  | # Released under the 2-clause BSD license. | ||||||
|  |  | ||||||
|  | . "@LIBEXECDIR@/sh/functions.sh" | ||||||
|  |  | ||||||
|  | if ! mountinfo -q -f tmpfs "@LIBEXECDIR@/init.d"; then | ||||||
|  | 	einfo "The OpenRC dependency data has already been migrated." | ||||||
|  | 	exit 0 | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | if [ ! -d "@PREFIX@/run" ]; then | ||||||
|  | 	eerror "'@PREFIX@/run' is not a directory." | ||||||
|  | 	eerror "This means the OpenRC dependency data cannot be migrated." | ||||||
|  | 	eerror "Please create the '@PREFIX@/run' directory and reboot the system." | ||||||
|  | 	exit 1 | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | if ! mountinfo -q -f tmpfs "@PREFIX@/run"; then | ||||||
|  | 	local x | ||||||
|  | 	for x in "@PREFIX@/run/."* "@PREFIX@/run/"*; do | ||||||
|  | 		case "$x" in | ||||||
|  | 			"@PREFIX@/run/."|"@PREFIX@/run/..") | ||||||
|  | 				continue | ||||||
|  | 				;; | ||||||
|  | 		esac | ||||||
|  | 		if [ -e "$x" ]; then | ||||||
|  | 				eerror "Your '@PREFIX@/run' directory contains files." | ||||||
|  | 				eerror "Please reboot the system." | ||||||
|  | 				exit 1 | ||||||
|  | 		fi | ||||||
|  | 	done | ||||||
|  |  | ||||||
|  | 	mount -t tmpfs -o mode=0755,nosuid,nodev \ | ||||||
|  | 		tmpfs "@PREFIX@/run" 2> /dev/null | ||||||
|  | 	if [ $? != 0 ]; then | ||||||
|  | 		eerror "Unable to mount a tmpfs on '@PREFIX@/run'." | ||||||
|  | 		eerror "This means the OpenRC dependency data cannot be migrated." | ||||||
|  | 		eerror "Please create the '@PREFIX@/run' directory and reboot the system." | ||||||
|  | 		exit 1 | ||||||
|  | 	fi | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | rm -rf "@PREFIX@/run/openrc" | ||||||
|  | cp -a "@LIBEXECDIR@/init.d" "@PREFIX@/run/openrc" | ||||||
|  | rc-update -u | ||||||
|  | rm -rf "@LIBEXECDIR@/init.d" | ||||||
|  | umount "@LIBEXECDIR@/init.d" | ||||||
|  | einfo "The OpenRC dependency data was migrated successfully." | ||||||
|  | exit 0 | ||||||
| @@ -36,7 +36,11 @@ __BEGIN_DECLS | |||||||
| #define RC_SYSCONFDIR		"@SYSCONFDIR@" | #define RC_SYSCONFDIR		"@SYSCONFDIR@" | ||||||
| #define RC_LIBDIR               "@PREFIX@/@LIB@/rc" | #define RC_LIBDIR               "@PREFIX@/@LIB@/rc" | ||||||
| #define RC_LIBEXECDIR           "@LIBEXECDIR@" | #define RC_LIBEXECDIR           "@LIBEXECDIR@" | ||||||
|  | #ifdef __linux__ | ||||||
|  | #define RC_SVCDIR               "@PREFIX@/run/openrc" | ||||||
|  | #else | ||||||
| #define RC_SVCDIR               RC_LIBEXECDIR "/init.d" | #define RC_SVCDIR               RC_LIBEXECDIR "/init.d" | ||||||
|  | #endif | ||||||
| #define RC_RUNLEVELDIR          RC_SYSCONFDIR "/runlevels" | #define RC_RUNLEVELDIR          RC_SYSCONFDIR "/runlevels" | ||||||
| #define RC_INITDIR              RC_SYSCONFDIR "/init.d" | #define RC_INITDIR              RC_SYSCONFDIR "/init.d" | ||||||
| #define RC_CONFDIR              RC_SYSCONFDIR "/conf.d" | #define RC_CONFDIR              RC_SYSCONFDIR "/conf.d" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user