SVN: rc-scripts/trunk: . Makefile.am configure.ac doc doc/make-html doc/upstart.txt init init/Makefi...

jajcus jajcus at pld-linux.org
Mon May 10 13:23:26 CEST 2010


Author: jajcus
Date: Mon May 10 13:23:25 2010
New Revision: 11419

Added:
   rc-scripts/trunk/doc/upstart.txt
      - copied unchanged from rev 11418, rc-scripts/branches/upstart_native/doc/upstart.txt
   rc-scripts/trunk/init/   (props changed)
      - copied from rev 11418, rc-scripts/branches/upstart_native/init/
   rc-scripts/trunk/init/Makefile.am
      - copied unchanged from rev 11418, rc-scripts/branches/upstart_native/init/Makefile.am
   rc-scripts/trunk/init/random.conf
      - copied unchanged from rev 11418, rc-scripts/branches/upstart_native/init/random.conf
   rc-scripts/trunk/src/setuidgid.c
      - copied unchanged from rev 11418, rc-scripts/branches/upstart_native/src/setuidgid.c
Modified:
   rc-scripts/trunk/   (props changed)
   rc-scripts/trunk/Makefile.am
   rc-scripts/trunk/configure.ac
   rc-scripts/trunk/doc/   (props changed)
   rc-scripts/trunk/doc/make-html
   rc-scripts/trunk/isapnp/   (props changed)
   rc-scripts/trunk/man/   (props changed)
   rc-scripts/trunk/man/de/   (props changed)
   rc-scripts/trunk/man/es/   (props changed)
   rc-scripts/trunk/man/fr/   (props changed)
   rc-scripts/trunk/man/ja/   (props changed)
   rc-scripts/trunk/man/ru/   (props changed)
   rc-scripts/trunk/man/sv/   (props changed)
   rc-scripts/trunk/po/   (props changed)
   rc-scripts/trunk/ppp/   (props changed)
   rc-scripts/trunk/rc.d/   (props changed)
   rc-scripts/trunk/rc.d/init.d/   (props changed)
   rc-scripts/trunk/rc.d/init.d/functions
   rc-scripts/trunk/rc.d/init.d/network
   rc-scripts/trunk/rc.d/init.d/random
   rc-scripts/trunk/rc.d/rc
   rc-scripts/trunk/rc.d/rc.shutdown
   rc-scripts/trunk/rc.d/rc.sysinit
   rc-scripts/trunk/service
   rc-scripts/trunk/src/   (props changed)
   rc-scripts/trunk/src/Makefile.am
   rc-scripts/trunk/sysconfig/   (props changed)
   rc-scripts/trunk/sysconfig/cpusets/   (props changed)
   rc-scripts/trunk/sysconfig/hwprofiles/   (props changed)
   rc-scripts/trunk/sysconfig/interfaces/   (props changed)
   rc-scripts/trunk/sysconfig/interfaces/data/   (props changed)
   rc-scripts/trunk/sysconfig/interfaces/down.d/   (props changed)
   rc-scripts/trunk/sysconfig/interfaces/down.d/all/   (props changed)
   rc-scripts/trunk/sysconfig/interfaces/down.d/ip/   (props changed)
   rc-scripts/trunk/sysconfig/interfaces/down.d/ipx/   (props changed)
   rc-scripts/trunk/sysconfig/interfaces/down.d/ppp/   (props changed)
   rc-scripts/trunk/sysconfig/interfaces/down.d/tnl/   (props changed)
   rc-scripts/trunk/sysconfig/interfaces/up.d/   (props changed)
   rc-scripts/trunk/sysconfig/interfaces/up.d/all/   (props changed)
   rc-scripts/trunk/sysconfig/interfaces/up.d/ip/   (props changed)
   rc-scripts/trunk/sysconfig/interfaces/up.d/ipx/   (props changed)
   rc-scripts/trunk/sysconfig/interfaces/up.d/ppp/   (props changed)
   rc-scripts/trunk/sysconfig/interfaces/up.d/tnl/   (props changed)
   rc-scripts/trunk/sysconfig/network-scripts/   (props changed)
   rc-scripts/trunk/t/backtick-test.sh   (props changed)
Log:
- upstart_native branch merged


Modified: rc-scripts/trunk/Makefile.am
==============================================================================
--- rc-scripts/trunk/Makefile.am	(original)
+++ rc-scripts/trunk/Makefile.am	Mon May 10 13:23:25 2010
@@ -2,7 +2,7 @@
 #	$Id$
 #
 
-SUBDIRS = src ppp isapnp sysconfig rc.d doc man po
+SUBDIRS = src ppp isapnp sysconfig rc.d doc man po init
 
 sysconf_DATA = \
 	adjtime \

Modified: rc-scripts/trunk/configure.ac
==============================================================================
--- rc-scripts/trunk/configure.ac	(original)
+++ rc-scripts/trunk/configure.ac	Mon May 10 13:23:25 2010
@@ -28,6 +28,7 @@
 downdir='${sysconfigdir}/interfaces/down.d'
 networkscriptsdir='${sysconfigdir}/network-scripts'
 rcdir='${sysconfdir}/rc.d'
+initdir='${sysconfdir}/init'
 docdir="${prefix}/doc/$PACKAGE-$VERSION"
 
 dnl i18n support
@@ -106,6 +107,7 @@
 AC_SUBST(updir)
 AC_SUBST(downdir)
 AC_SUBST(rcdir)
+AC_SUBST(initdir)
 AC_SUBST(docdir)
 AC_SUBST(GLIBDIR)
 AC_SUBST(GLIBNAME)
@@ -222,5 +224,6 @@
 	sysconfig/interfaces/down.d/tnl/Makefile \
 	rc.d/Makefile rc.d/init.d/Makefile \
 	po/Makefile \
+	init/Makefile \
 	])
 AC_OUTPUT

Modified: rc-scripts/trunk/doc/make-html
==============================================================================
--- rc-scripts/trunk/doc/make-html	(original)
+++ rc-scripts/trunk/doc/make-html	Mon May 10 13:23:25 2010
@@ -2,3 +2,4 @@
 
 jade -t sgml -d polski.dsl rc-scripts.docb
 #jade -t sgml -d polski.dsl test-ogonki.docb
+rst2html upstart.txt upstart.html

Modified: rc-scripts/trunk/rc.d/init.d/functions
==============================================================================
--- rc-scripts/trunk/rc.d/init.d/functions	(original)
+++ rc-scripts/trunk/rc.d/init.d/functions	Mon May 10 13:23:25 2010
@@ -1078,6 +1078,237 @@
 	fi
 }
 
+use_upstart () {
+	# True when upstart-event-based boot should be used
+	is_yes "$USE_UPSTART" && return 0
+	is_no "$USE_UPSTART" && return 1
+	if [ ! -x /sbin/initctl ] ; then
+		USE_UPSTART="no"
+		return 1
+	fi
+	local cmdline=$(cat /proc/cmdline)
+	if strstr "$cmdline" "pld.no-upstart" ; then
+		USE_UPSTART="no"
+		return 1
+	else
+		USE_UPSTART="yes"
+		return 0
+	fi
+}
+
+emit () {
+	# emit upstart signal
+	# only when 'upstart' boot is enabled
+	use_upstart || return 0
+	/sbin/initctl emit "$@"
+}
+
+is_upstart_task() {
+	# Return 0 if the given service is an upstart task.
+	grep -q '^task' "/etc/init/$1.conf"
+}
+is_upstart_running() {
+	# Return 0 if the given service is running via upstart
+	initctl status "$1" 2>/dev/null | grep -q running
+}
+upstart_start() {
+	local service=$1
+	is_upstart_running "${service}" && return 0
+	msg_starting "${service}"
+	if errors=$(/sbin/initctl start ${service} 2>&1) ; then
+		ok
+		return 0
+	else
+		fail
+		echo "$errors" >&2
+		return 1
+	fi
+}
+upstart_stop() {
+	local service=$1
+	if ! is_upstart_running "${service}" && ! is_upstart_task "${service}" ; then
+		return 0
+	fi
+	msg_stopping "${service}"
+	if errors=$(/sbin/initctl stop ${service}) ; then
+		ok
+		return 0
+	else
+		fail
+		echo "$errors" >&2
+		return 1
+	fi
+}
+upstart_reload() {
+	local service=$1
+	if ! is_upstart_running "${service}" && ! is_upstart_task "${service}" ; then
+		return 0
+	fi
+	msg_reloading "${service}"
+	if errors=$(/sbin/initctl reload ${service}) ; then
+		ok
+		return 0
+	else
+		fail
+		echo "$errors" >&2
+		return 1
+	fi
+}
+upstart_status() {
+	# get service status
+	# should be compliant with
+        # http://refspecs.freestandards.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/iniscrptact.html
+	local service=$1
+	local status
+	if is_upstart_task "${service}" ; then
+		# we probably should have a way to handle task status
+		return 0
+	fi
+	if ! status=$(/sbin/initctl status "${service}") ; then
+		# program or service status is not known
+		return 4
+	fi
+	if strstr "$status" "running" ; then
+		# program is running or service is OK
+		echo "$status"
+		return 0
+	else
+		# program is not running
+		echo "$status"
+		return 3
+	fi
+	# TODO: other statuses
+}
+
+_upstart_controlled () {
+	# If the service is to be handled by upstart
+	# execute the start/stop/etc. commands the upstart way
+	if ! use_upstart ; then
+		return 0
+	fi	
+	local script=$1
+	shift
+	local command=$1
+	shift
+	local name=$(basename "$script")
+	if [ ! -f /etc/init/${name}.conf ] ; then
+		return 0
+	fi
+	local commands
+	local extra_commands
+	local has_configtest
+	if [ "$1" = "--except" ] ; then
+		shift
+		commands="$*"
+		for cmd in $commands ; do
+			if [ "$command" = "$cmd" ] ; then
+				return 0
+			fi
+			case "$cmd" in
+				start|stop|status|reload|restart|try-restart|force-reload)
+					;;
+				configtest)
+					has_configtest=yes
+					extra_commands="|$cmd"
+					;;
+				*)
+					extra_commands="|$cmd"
+					;;
+			esac
+		done
+	elif [ -n "$*" ] ; then
+		commands="$*"
+		local cmd
+		local found=0
+		# is there a better way
+		for cmd in $commands ; do
+			if [ "$command" = "$cmd" ] ; then
+				found=1
+				break;
+			fi
+		done
+		if [ $found = 0 ] ; then
+			# let the script handle it
+			return 0
+		fi
+	fi
+	case "$command" in
+		start)
+			upstart_start $name
+			exit $?
+			;;
+		stop)
+			upstart_stop $name
+			exit $?
+			;;
+		status)
+			upstart_status $name
+			exit $?
+			;;
+		restart)
+			if is_yes $has_configtest ; then
+				"$script" configtest || exit 1
+			fi
+			upstart_stop $name
+			upstart_start $name
+			exit $?
+			;;
+		try-restart)
+			if ! is_upstart_running "$name" ; then
+				exit 0
+			fi
+			if is_yes $has_configtest ; then
+				"$script" configtest || exit 1
+			fi
+			upstart_stop $name
+			upstart_start $name
+			exit $?
+			;;
+		reload)
+			if is_yes $has_configtest ; then
+				"$script" configtest || exit 1
+			fi
+			if is_upstart_task "$name" ; then
+				nls "$command not implemented for $name"
+				exit 3
+			else
+				upstart_reload "$name"
+				exit $?
+			fi
+			;;
+		force-reload)
+			if is_yes $has_configtest ; then
+				"$script" configtest || exit 1
+			fi
+			if is_upstart_task "$name" ; then
+				upstart_stop "$name"
+				upstart_start "$name"
+				exit $?
+			else
+				upstart_reload "$name"
+				exit $?
+			fi
+			;;
+		*)
+		        msg_usage "$0 {start|stop|restart|reload|force-reload|status$extra_commands}"
+			exit 3
+			;;
+	esac
+	return 1 # should not happen
+}
+
+# Usage:
+#   somewhere at the begining of init script:
+#     upstart_controlled
+#		- to pass implement all upstart commands via initctl
+#                 start, stop, status, restart, reload and force_reload
+#		  are implemented
+#     upstart_controlled command...
+#		- to pass handle only specific commands the upstart way
+#                 and leave the rest to the script
+#
+alias upstart_controlled='_upstart_controlled $0 "$@"'
+
 rc_gettext_init
 rc_cache_init
 

Modified: rc-scripts/trunk/rc.d/init.d/network
==============================================================================
--- rc-scripts/trunk/rc.d/init.d/network	(original)
+++ rc-scripts/trunk/rc.d/init.d/network	Mon May 10 13:23:25 2010
@@ -193,6 +193,7 @@
 }
 
 start() {
+	emit pld.network-starting
 	rc_splash "bootnetwork start"
 	network_init
 
@@ -212,9 +213,11 @@
 	network_postinit
 
 	touch /var/lock/subsys/network
+	emit --no-wait pld.network-started
 }
 
 stop() {
+	emit pld.network-stopping
 	# If we go to runlevel 0, 1 or 6 then umount all network fs
 	if [ "$RUNLEVEL" = "6" -o "$RUNLEVEL" = "0" -o "$RUNLEVEL" = "1" ]; then
 		if [ -x /etc/rc.d/init.d/netfs -a -f /var/lock/subsys/netfs ];
@@ -250,6 +253,7 @@
 	network_deinit
 
 	rm -f /var/lock/subsys/network
+	emit --no-wait pld.network-stopped
 }
 
 # Reload all active interfaces
@@ -330,7 +334,9 @@
 case "$1" in
   start)
 	if is_yes "$VSERVER"; then
+		emit pld.network-starting
 		touch /var/lock/subsys/network
+		emit pld.network-started
 		exit 0
 	fi
   	start
@@ -338,7 +344,9 @@
 
   stop)
 	if is_yes "$VSERVER"; then
+		emit pld.network-stopping
 		rm -f /var/lock/subsys/network
+		emit pld.network-stopped
 		exit 0
 	fi
 	stop

Modified: rc-scripts/trunk/rc.d/init.d/random
==============================================================================
--- rc-scripts/trunk/rc.d/init.d/random	(original)
+++ rc-scripts/trunk/rc.d/init.d/random	Mon May 10 13:23:25 2010
@@ -12,50 +12,59 @@
 # Source function library.
 . /etc/rc.d/init.d/functions
 
+upstart_controlled start stop
+
 random_seed=/var/run/random-seed
 
+poolfile=/proc/sys/kernel/random/poolsize
+[ -r $poolfile ] && bytes="$(cat $poolfile)" || bytes=512
+
+
 # See how we were called.
 case "$1" in
   start)
 	# Check if the service is already running?
 	if [ ! -f /var/lock/subsys/random ]; then
+		emit starting JOB=random
 		show "Initializing random number generator"
 		busy
 		# Carry a random seed from start-up to start-up
-		# Load and then save 512 bytes, which is the size of the entropy pool
 		if [ -f $random_seed ]; then
 			cat $random_seed >/dev/urandom
 		else
 			touch $random_seed
 		fi
 		chmod 600 $random_seed
-		dd if=/dev/urandom of=$random_seed count=1 bs=512 2>/dev/null
+		dd if=/dev/urandom of=$random_seed count=1 bs=$bytes 2>/dev/null
 		touch /var/lock/subsys/random
 		deltext
 		ok
+		emit --nowait started JOB=random
 	fi
 	;;
   stop)
 	if [ -f /var/lock/subsys/random ]; then
 		# Carry a random seed from shut-down to start-up
-		# Save 512 bytes, which is the size of the entropy pool
+		emit stopping JOB=random
 		show "Saving random seed"
 		busy
 		touch $random_seed
 		chmod 600 $random_seed
-		dd if=/dev/urandom of=$random_seed count=1 bs=512 2>/dev/null
+		dd if=/dev/urandom of=$random_seed count=1 bs=$bytes 2>/dev/null
 
 		rm -f /var/lock/subsys/random
 		deltext
 		ok
+		emit --no-wait stopped JOB=random
 	fi
 	;;
   status)
-	# this is way overkill, but at least we have some status output...
-	if [ -c /dev/random ] ; then
-		nls "The random data source exists"
-	else
+  	entropy_avail="$(cat /proc/sys/kernel/random/entropy_avail)"
+	if [ "$entropy_avail" -eq 0 -o ! -c /dev/random ] ; then
 		nls "The random data source is missing"
+		exit 1
+	else
+		nls "$entropy_avail bytes of entropy available"
 	fi
 	;;
   *)

Modified: rc-scripts/trunk/rc.d/rc
==============================================================================
--- rc-scripts/trunk/rc.d/rc	(original)
+++ rc-scripts/trunk/rc.d/rc	Mon May 10 13:23:25 2010
@@ -196,6 +196,9 @@
 		[ -f /var/lock/subsys/$subsys ] || \
 		[ -f /var/lock/subsys/${subsys}.init ] && continue
 
+		# Check if it is managed by upstart
+		use_upstart && [ -f /etc/init/${subsys}.conf ] && continue
+
 		# If we're in confirmation mode, get user confirmation
 		[ -n "$CONFIRM" ] &&
 		{

Modified: rc-scripts/trunk/rc.d/rc.shutdown
==============================================================================
--- rc-scripts/trunk/rc.d/rc.shutdown	(original)
+++ rc-scripts/trunk/rc.d/rc.shutdown	Mon May 10 13:23:25 2010
@@ -20,6 +20,8 @@
 trap "echo" INT SEGV QUIT TERM
 set +e
 
+emit pld.shutdown-started
+
 rc_splash "reboot"
 
 # Kill all processes.

Modified: rc-scripts/trunk/rc.d/rc.sysinit
==============================================================================
--- rc-scripts/trunk/rc.d/rc.sysinit	(original)
+++ rc-scripts/trunk/rc.d/rc.sysinit	Mon May 10 13:23:25 2010
@@ -120,6 +120,9 @@
 
 	# Only read this once.
 	cmdline=$(cat /proc/cmdline)
+	if strstr "$cmdline" "pld.no-upstart" ; then
+		USE_UPSTART="no"
+	fi
 
 	# sysfs is also needed before any other things (under kernel > 2.5)
 	if grep -q sysfs /proc/filesystems 2>/dev/null ; then
@@ -520,6 +523,9 @@
 	elif is_fsmounted cpuset /dev/cpuset; then
 		mount -f -t cpuset none /dev/cpuset
 	fi
+	
+	emit --no-wait root-filesystem
+	emit --no-wait virtual-filesystems
 
 	if [ ! -f /proc/modules ]; then
 		USEMODULES=
@@ -886,6 +892,12 @@
 		run_cmd "Turning on quotas for local filesystems" /sbin/quotaon -aug
 	fi
 
+	emit --no-wait local-filesystems
+
+	# FIXME: this should be delayed until remote filesystems are mounted,
+	#        especialy when /usr or other standard fs is remote
+	emit --no-wait filesystem
+
 	# Turn on process accounting
 	if [ -x /etc/rc.d/rc.acct ]; then
 		/etc/rc.d/rc.acct start
@@ -911,6 +923,11 @@
 	# ... and here finish configuring parameters
 	sysctl -e -p /etc/sysctl.conf > /dev/null 2>&1
 else
+	emit --no-wait root-filesystem
+	emit --no-wait virtual-filesystems
+	emit --no-wait local-filesystems
+	emit --no-wait filesystem
+
 	# /var/log should be writable now, so start saving the boot output
 	if [ "$RC_BOOTLOG" ]; then
 		echo > /var/log/boot.msg
@@ -939,7 +956,7 @@
 			;;
 		esac
 	else
-		[ "$bafile" != "hwprofile" ] && rm -f $afile 2> /dev/null
+		[ "$bafile" != "hwprofile" -a "$bafile" != "random-seed" ] && rm -f $afile 2> /dev/null
 	fi
 done
 
@@ -979,6 +996,7 @@
 	run_cmd "Enabling swap space" true
 	# Right, now turn on swap in case we swap to files
 	swapon -a >/dev/null 2>&1
+	emit --no-wait all-swaps
 
 	# If a SCSI tape has been detected, load the st module unconditionally
 	# since many SCSI tapes don't deal well with st being loaded and unloaded
@@ -1004,6 +1022,8 @@
 	done
 	cp -f /var/log/dmesg /var/log/dmesg.0
 	chmod 0600 /var/log/dmesg /var/log/dmesg.0
+else
+	emit --no-wait all-swaps
 fi
 
 if ! is_no "$RC_PROMPT"; then
@@ -1027,3 +1047,6 @@
 	rm -f /var/run/getkey_done
 fi
 echo
+
+emit --no-wait pld.sysinit-done
+

Modified: rc-scripts/trunk/service
==============================================================================
--- rc-scripts/trunk/service	(original)
+++ rc-scripts/trunk/service	Mon May 10 13:23:25 2010
@@ -21,6 +21,7 @@
 [ service_name [ command | --full-restart ] ]"
 
 SERVICE=
+USE_UPSTART=
 
 if [ -d /etc/rc.d/init.d ]; then
 	SERVICEDIR="/etc/rc.d/init.d"
@@ -44,7 +45,15 @@
 		echo "${VERSION}" >&2
 		exit 0
 		;;
-	*)
+	  --upstart)
+	  	USE_UPSTART=yes
+		shift
+		;;
+	  --no-upstart)
+	  	USE_UPSTART=no
+		shift
+		;;
+	  *)
 		if [ -z "${SERVICE}" -a $# -eq 1 -a "${1}" = "--status-all" ]; then
 			cd ${SERVICEDIR}
 			for SERVICE in *; do
@@ -59,7 +68,7 @@
 						echo " [ ? ]  $SERVICE" 1>&2
 						continue
 					else
-						out=$(env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" status 2>&1)
+						out=$(env -i USE_UPSTART=$USE_UPSTART LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" status 2>&1)
 						if [ "$?" = "0" -a -n "$out" ]; then
 							#printf " %s %-60s %s\n" "[+]" "$SERVICE:" "running"
 							echo " [ + ]  $SERVICE"
@@ -79,8 +88,8 @@
 		elif [ $# -eq 2 -a "${2}" = "--full-restart" ]; then
 			SERVICE="${1}"
 			if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
-				env -i LANG=$LANG PATH=$PATH TERM=$TERM "${SERVICEDIR}/${SERVICE}" stop
-				env -i LANG=$LANG PATH=$PATH TERM=$TERM "${SERVICEDIR}/${SERVICE}" start
+				env -i USE_UPSTART=$USE_UPSTART LANG=$LANG PATH=$PATH TERM=$TERM "${SERVICEDIR}/${SERVICE}" stop
+				env -i USE_UPSTART=$USE_UPSTART LANG=$LANG PATH=$PATH TERM=$TERM "${SERVICEDIR}/${SERVICE}" start
 				exit $?
 			fi
 		elif [ -z "${SERVICE}" ]; then
@@ -96,7 +105,7 @@
 done
 
 if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
-	exec env -i LANG=$LANG PATH=$PATH TERM=$TERM "${SERVICEDIR}/${SERVICE}" ${ACTION} ${OPTIONS}
+	exec env -i USE_UPSTART=$USE_UPSTART LANG=$LANG PATH=$PATH TERM=$TERM "${SERVICEDIR}/${SERVICE}" ${ACTION} ${OPTIONS}
 else
 	echo "${SERVICE}: unrecognized service" >&2
 	exit 1

Modified: rc-scripts/trunk/src/Makefile.am
==============================================================================
--- rc-scripts/trunk/src/Makefile.am	(original)
+++ rc-scripts/trunk/src/Makefile.am	Mon May 10 13:23:25 2010
@@ -26,6 +26,7 @@
 	ppp-watch \
 	start-stop-daemon \
 	fstab-decode \
+	setuidgid \
 	usernetctl
 	
 EXTRA_PROGRAMS = \
@@ -66,4 +67,6 @@
 
 start_stop_daemon_SOURCES = start-stop-daemon.c
 
+setuidgid_SOURCES = setuidgid.c
+
 fstab_decode_SOURCES = fstab-decode.c


More information about the pld-cvs-commit mailing list