tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

rc.subr: unset _rc_pid (fixes network after acpi S3 wakeup)



Hi,

I've recently switched from netbsd-6 to netbsd-7 (amd64) and today i found out that the wakeup from the S3 acpi sleep state on my old ThinkPad SL510 finally reliably works (using hw.acpi.sleep.vbios=2). Thanks to everybody responsible!

One minor problem was the network connection, which presented itself by a missing default route. I am using a statically configured ip address on a re0 interface.

The powerd script /etc/powerd/scripts/sleep_button is responsible for invoking "/etc/rc.d/network start". Setting the shell xtrace in /etc/rc.d/network revealed (see attachment last_xtrace_lines.txt and _have_rc_postprocessor() from rc.subr) that the network script is failing because it thinks (due to the inherited fd 9 and environment variables: /etc/rc{,.subr} => powerd => /etc/powerd/scripts/sleep_button => /etc/rc.d/network) it is running from /etc/rc and writes to closed fd 9 (_rc_postprocessor_fd). One way to avoid this is to unset the variables exported by /etc/rc and /etc/rc.subr before running rc.d commands.

Attached diffs:

7_rc.subr.diff
  * for netbsd-7, tested
* when executing run_rc_command() with "start" argument, unset all the variables, which are exported by /etc/rc and /etc/rc.subr before running the command

HEAD_rc.subr.diff
  * for HEAD, untested
* when executing run_rc_command() with "start" argument, unset all the variables, which are exported by /etc/rc and /etc/rc.subr before running the command * set cloexec flag on fd 9 (_rc_postprocessor_fd), cf. src/etc/rc 1.171, 1.172

Thanks,

r.
--- etc/rc.subr.orig	2017-03-19 14:42:23.000000000 +0100
+++ etc/rc.subr	2017-03-19 14:54:59.000000000 +0100
@@ -645,18 +645,22 @@
 					# setup the command to run, and run it
 					#
 			echo "Starting ${name}."
+			exported_rc_vars="RC_PID _rc_pid \
+_rc_original_stdout_fd _rc_original_stderr_fd _rc_postprocessor_fd"
 			if [ -n "$_chroot" ]; then
-				_doit="\
+				_doit="(\
+unset $exported_rc_vars; \
 ${_env:+env $_env }\
 ${_nice:+nice -n $_nice }\
 chroot ${_user:+-u $_user }${_group:+-g $_group }${_groups:+-G $_groups }\
-$_chroot $command $rc_flags $command_args"
+$_chroot $command $rc_flags $command_args)"
 			else
-				_doit="\
+				_doit="(\
+unset $exported_rc_vars; \
 ${_chdir:+cd $_chdir; }\
 ${_env:+env $_env }\
 ${_nice:+nice -n $_nice }\
-$command $rc_flags $command_args"
+$command $rc_flags $command_args)"
 				if [ -n "$_user" ]; then
 				    _doit="su -m $_user -c 'sh -c \"$_doit\"'"
 				fi
--- etc/rc.subr.orig	2017-03-19 15:04:05.000000000 +0100
+++ etc/rc.subr	2017-03-19 15:15:36.000000000 +0100
@@ -663,18 +663,22 @@
 					# setup the command to run, and run it
 					#
 			echo "Starting ${name}."
+			exported_rc_vars="RC_PID _rc_pid \
+_rc_original_stdout_fd _rc_original_stderr_fd _rc_postprocessor_fd"
 			if [ -n "$_chroot" ]; then
-				_doit="\
+				_doit="(\
+unset $exported_rc_vars; \
 ${_env:+env $_env }\
 ${_nice:+nice -n $_nice }\
 chroot ${_user:+-u $_user }${_group:+-g $_group }${_groups:+-G $_groups }\
-$_chroot $command $rc_flags $command_args"
+$_chroot $command $rc_flags $command_args)"
 			else
-				_doit="\
+				_doit="(\
+unset $exported_rc_vars; \
 ${_chdir:+cd $_chdir; }\
 ${_env:+env $_env }\
 ${_nice:+nice -n $_nice }\
-$command $rc_flags $command_args"
+$command $rc_flags $command_args)"
 				if [ -n "$_user" ]; then
 				    _doit="su -m $_user -c 'sh -c \"$_doit\"'"
 				fi
@@ -818,6 +822,7 @@
 	[ -n "${_rc_postprocessor_fd}" ] || { unset _rc_pid; return 1; }
 	eval ": >&${_rc_postprocessor_fd}" 2>/dev/null \
 	|| { unset _rc_pid; return 1; }
+	fdflags -s +cloexec "${_rc_postprocessor_fd}"
 
 	return 0
 }
+ echo -n 'Configuring network interfaces:' 
+ command echo -n 'Configuring network interfaces:' 
Configuring network interfaces:+ '_flush_rc_output' 
+ 'print_rc_metadata' nop 
+ '_have_rc_postprocessor' 
+ '[' -n 3755 ']' 
+ '[' -n 9 ']' 
+ eval ': >&9' 
+ return 0 
+ command printf '%s%s\n' '' nop 


Home | Main Index | Thread Index | Old Index