lxc-start 936 Bytes
#!/bin/sh

function lxc-start()
{
	local LXC_START=/usr/bin/lxc-start
	local TEST=/usr/bin/test
	local ECHO=/bin/echo
	local MKDIR=/bin/mkdir
	local CHOWN=/bin/chown
	local SUDO=/usr/bin/sudo
	local TEE=/usr/bin/tee

	(
		PID=$(exec /bin/sh -c 'echo $PPID')
		for ctrl in /sys/fs/cgroup/*
		do
			${TEST} ${ctrl##*/} = 'openrc' && continue

			if ${TEST} ! -d ${ctrl}/${USER}
			then
				${TEST} ${ctrl##*/} = 'cpuset' && \
					${ECHO} 1 | ${SUDO} ${TEE} ${ctrl}/cgroup.clone_children >/dev/null
				${TEST} ${ctrl##*/} = 'memory' && \
					${ECHO} 1 | ${SUDO} ${TEE} ${ctrl}/memory.use_hierarchy >/dev/null

				${SUDO} ${MKDIR} ${ctrl}/${USER}/
				${SUDO} ${CHOWN} ${USER}: ${ctrl}/${USER}
				${SUDO} ${CHOWN} ${USER}: ${ctrl}/${USER}/tasks
				${SUDO} ${CHOWN} ${USER}: ${ctrl}/${USER}/cgroup.procs
			fi
			${ECHO} ${PID} >>"${ctrl}/${USER}/tasks"
		done

		${LXC_START} $@
	)
}

export -f lxc-start

# vim: set ft=sh ts=4 sw=4: