Gentoo Archives: gentoo-user

From: Mike Mazur <mmazur@×××××.com>
To: gentoo-user@l.g.o
Subject: Why does /sbin/rc not work when called from a script? (WAS: Re: [gentoo-user] Power management updates?)
Date: Wed, 24 Jun 2009 13:50:52
Message-Id: 184110a70906240650g6db27ae0qdcc59b8b57a00912@mail.gmail.com
1 Hi,
2
3 On Wed, Jun 24, 2009 at 17:50, Alan McKinnon<alan.mckinnon@×××××.com> wrote:
4 > On Wednesday 24 June 2009 03:28:55 Mike Mazur wrote:
5 >> Still one issue remains -- why are my RC states not automatically
6 >> switched between default and battery even though my acpid setup is
7 >> right and works (according to the log messages)?
8 >
9 > The simplest answer (usually the right one) is that you are probably grepping
10 > for the wrong string. These things are subject to change and there's no easy
11 > way for you to find out when it happens.
12
13 You mean grepping for the wrong string in syslog? I don't think that's
14 an issue, since pmg_switch_runlevel.sh is being called (as can be seen
15 by the log messages).
16
17 I looked inside /sbin/rc and discovered that control flow ends up at
18 the elsif statement on line 607. This is because $RUNLEVEL is "S" and
19 $argv1 is "battery". The relevant code is:
20
21 elif [[ ( ${RUNLEVEL} == "S" || ${RUNLEVEL} == "1" ) && ${argv1} != "single" ]]
22 then
23 level=$(awk -v level="${argv1}" '
24 $2 == level {
25 split($0, fields, ":")
26 print fields[2]
27 exit
28 }' /etc/inittab 2>/dev/null)
29 [[ -z ${level} ]] && level=3
30 /sbin/telinit "${level}"
31 exit 0
32 fi
33
34 AFAICT, this code looks for the desired runlevel in /etc/inittab and
35 if that runlevel is there, we change to runlevel 3 (aka default). The
36 battery runlevel does not exist in /etc/inittab (and I'm pretty sure
37 it never did before), so the runlevel is never changed to battery.
38
39 What is interesting, though, is if I run `/sbin/rc battery` manually
40 from the command line, there are no problems and I find myself in the
41 battery runlevel. So I guess something has changed in /sbin/rc which
42 causes it to function differently when called from a script.
43
44 Does anyone know what's the proper way of calling /sbin/rc from a
45 script? Perhaps there are some parameters I should pass it to get the
46 runlevels to switch? I'm running sys-apps/baselayout-1.12.11.1 and it
47 doesn't seem to have a man page.
48
49 Thanks,
50 Mike