[CALUG] How do I get out of X?
dododge at dododge.net
Thu Aug 31 03:12:41 CDT 2006
On Wed, Aug 30, 2006 at 11:06:03PM -0400, Rajiv Gunja wrote:
> >> The only times I remember using init was to make the server
> >> re-read its inittab file. (Q/q).
> >Note that "init" has no "q" command-line argument -- but "telinit"
> >does ;-)
> No matter what the man page says, the behaviour of the program
> cannot change unless written into it is the logic to differentiate
I'm not saying that it doesn't _work_, but merely that this
differentiation exists internally and conceptually in the program. In
the sourcecode for a recent Linux sysvinit, it does something like
this at startup:
/* Is this telinit or init? */
if(getpid() != 1)
...else do the init daemon behavior...
There's an actual C function called "telinit" which works like a
program main() and does all of the telinit stuff. That's where
options such as '-t' and 'q' are processed.
That said, things become a lot murkier the further back you look. It
appears that instead of telinit and init being merged over time,
they're actually being split. Because options have been added to
them, the distinction between them is stronger now than it used to be.
The code for sysvinit back in 1996 looks quite a bit different. It
goes more like this:
if(getpid() == 1 || (argv looks like init))
...do the init daemon behavior...
...do the telinit behavior...
There's no "telinit" function and the options available to the two
operating modes are more limited and similar.
> I would not call it protocol, I would say a "messaging"
> method. Because, in an Unix environment, everything is via IPC.
I'm using "protocol" in the generic sense: how the data is passed,
what formatting is used, the sequence of events, and so on.
> As init and telinit achieves it stuff via a fifo.
The fifo turns out to be a relatively new technique. The 1996
sysvinit has the fifo code #ifdef'd as a new feature, and also
supports an older protocol that passes the command through a regular
file in /etc.
> As I said, I have run "init Q/q" numerous times in my previous
After further reading it's not surprising that this works.
> Init and telinit are the same command.
Again it looks like my speculation was backwards. The "telinit"
command actually isn't part of System V at all. Some vendor added it
after the fact and I guess it became a popular extension. I don't
know where it originally comes from.
In System V, the standard way to change runlevels is indeed the "init"
Something to note about this, though, is that there is an explicit
distinction in SVID between the "init command" and the "init process".
The program called "init" is the init _command_, and its only
functionality is to signal the init _process_. The actual init
process is started by the system through some (as far as I can see)
unspecified technique, and its code comes from some unspecified place.
[SVID 4th Ed Vol 2 Page 339]
So Linux is a bit different from System V, and confuses things, by
trying to have /sbin/init be both the init process and the init
command at the same time. Then telinit is thrown into the mix to
further confuse things. This is probably due to historical reasons
specific to Linux.
BTW the Unix Standard leaves all of this unspecified and doesn't say
anything about the init command or runlevels.
More information about the lug