[CALUG] How do I get out of X?

Rajiv Gunja opn.src.rocks at gmail.com
Wed Aug 30 22:06:03 CDT 2006


> Here's some wild speculation as to how it went:
>
>   - Originally there were very few things init needed to be able to
>     do, and a few signals such as HUP and TERM would be sufficient to
>     tell it to do those things.  No need for something like "telinit".


Dave,
There is no need to speculate. All we need to do is understand why a design
was done the way it was done. In the earlier days, as I said before, the
concept of a Unix machine was still perceived as a mainframe, where things
were separate and different departments were given different tasks to
perform. The evidence to this theory is the concept of groups. A good
example would be printer administration, adding users, mounting FS,
allocating terminal access and the shutdown/reboot of a system.

When Unix was written, the coders did not want anyone messing with the
kernel directly and they wanted only 1 process to talk to the kernel and
only 1 process to allocate the user space and control things within it.

Init not only had couple of things to do, but it had a the most important
job. Depending on the OS flavour, it did things a couple of different ways.
If you look at BSD, there was an PID 0, which was the swapper and then PID
1, init was started. On SunOS the kernel would kick off init, pageout and
fsflush (modern system).

But what has not changed with init in all these ages, which makes it the
parent/mother of all process? It is still the process which starts other
processes using the rc scripts. Of course even now, if you look at the OS
design, there is a slight different between all the major flavours of UNIX,
but in essence the same.


  - Then multiple runlevels were introduced, and the signals were no
>     longer enough.  A protocol was designed to pass additional
>     instructions to init, and "telinit" was created as a command-line
>     way of performing that protocol.


I would not call it protocol, I would say a "messaging" method. Because, in
an Unix environment, everything is via IPC. As init and telinit achieves it
stuff via a fifo.


  - Someone decides that the protocol stuff results in enough shared
>     code between init and telinit that it's easier to just make them
>     into a single executable.  This also has the advantage of being
>     more efficient in both memory and disk accesses.  The executable
>     now has to figure out at startup whether it's supposed to be
>     running as "init" or "telinit".  In other such cases this is
>     usually done by checking argv[0], but since init will always have
>     PID 1 it's _much_ simpler and more reliable to just test for that.



Yes .... I think it was more to do with the design and to have a less
complex process. Why go to Houston to reach Seattle, we can go to Seattle
via Minneapolis.

The fact remains that it only works because init/telinit doesn't
> bother to check argv[0] like other combined programs usually do.  You
> could presumably run "telinit" with PID 1 and get the init daemon
> behavior -- or give it a third name and use that likewise.
>
> > 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 ;-)


Dave, you put too much weight into the man page that comes from a commercial
vendor. No matter what the man page says, the behaviour of the program
cannot change unless written into it is the logic to differentiate itself.
As I said, I have run "init Q/q" numerous times in my previous job. Init and
telinit are the same command. Here is a little piece of code to drive in my
point.

Please notice the highlighted text, which is the main fifo init talks to. So
no matter what you execute on the command line (telinit or init) it does the
same thing.

My System:
Agni-3:~$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=6.06
DISTRIB_CODENAME=dapper
DISTRIB_DESCRIPTION="Ubuntu 6.06 LTS"

Agni-3:~$ cat /proc/version
Linux version 2.6.15-25-sparc64-smp (buildd at vivies) (gcc version 4.0.3(Ubuntu
4.0.3-1ubuntu5)) #1 SMP Wed Jun 14 11:47:38 UTC 2006

===========================
*******   001 *******
===========================

Agni-3:~$ sudo strace -f telinit -t 10 q
execve("/sbin/telinit", ["telinit", "-t", "10", "q"], [/* 22 vars */]) = 0
uname({sys="Linux", node="Agni-3", ...}) = 0
brk(0)                                  = 0x28000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or
directory)
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or
directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=51114, ...}) = 0
mmap(NULL, 51114, PROT_READ, MAP_PRIVATE, 3, 0) = 0xf7fd0000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or
directory)
open("/lib/libc.so.6", O_RDONLY)        = 3
read(3, "\177ELF\1\2\1\0\0\0\0\0\0\0\0\0\0\3\0\22\0\0\0\1\0\1\307"..., 512)
= 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=1345940, ...}) = 0
mmap(NULL, 1415816, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) =
0xf7e74000
mprotect(0xf7fb4000, 105096, PROT_NONE) = 0
mmap(0xf7fc2000, 40960, PROT_READ|PROT_WRITE|PROT_EXEC,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x13e000) = 0xf7fc2000
mmap(0xf7fcc000, 6792, PROT_READ|PROT_WRITE|PROT_EXEC,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xf7fcc000
close(3)                                = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0xf7fce000
mprotect(0xf7fc2000, 16384, PROT_READ)  = 0
munmap(0xf7fd0000, 51114)               = 0
umask(022)                              = 022
geteuid32()                             = 0
getpid()                                = 8611
rt_sigaction(SIGALRM, {0x11cf4, [], 0}, NULL, 0xf7ea78d8, 4294967295) = 0
alarm(3)                                = 0
open("/dev/initctl", O_WRONLY)          = 3
write(3, "\3\t\31i\0\0\0\1\0\0\0q\0\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0"..., 384)
= 384
close(3)                                = 0
alarm(0)                                = 3
exit_group(0)                           = ?
===========================
*******   002 *******
===========================
Agni-3:~$ sudo strace -f init -t 10 q
execve("/sbin/init", ["init", "-t", "10", "q"], [/* 22 vars */]) = 0
uname({sys="Linux", node="Agni-3", ...}) = 0
brk(0)                                  = 0x28000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or
directory)
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or
directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=51114, ...}) = 0
mmap(NULL, 51114, PROT_READ, MAP_PRIVATE, 3, 0) = 0xf7f14000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or
directory)
open("/lib/libc.so.6", O_RDONLY)        = 3
read(3, "\177ELF\1\2\1\0\0\0\0\0\0\0\0\0\0\3\0\22\0\0\0\1\0\1\307"..., 512)
= 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=1345940, ...}) = 0
mmap(NULL, 1415816, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) =
0xf7db8000
mprotect(0xf7ef8000, 105096, PROT_NONE) = 0
mmap(0xf7f06000, 40960, PROT_READ|PROT_WRITE|PROT_EXEC,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x13e000) = 0xf7f06000
mmap(0xf7f10000, 6792, PROT_READ|PROT_WRITE|PROT_EXEC,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xf7f10000
close(3)                                = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0xf7f12000
mprotect(0xf7f06000, 16384, PROT_READ)  = 0
munmap(0xf7f14000, 51114)               = 0
umask(022)                              = 022
geteuid32()                             = 0
getpid()                                = 8613
rt_sigaction(SIGALRM, {0x11cf4, [], 0}, NULL, 0xf7deb8d8, 4294967295) = 0
alarm(3)                                = 0
open("/dev/initctl", O_WRONLY)          = 3
write(3, "\3\t\31i\0\0\0\1\0\0\0q\0\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0"..., 384)
= 384
close(3)                                = 0
alarm(0)                                = 3
exit_group(0)                           = ?
===========================
===========================
-


Rajiv G Gunja
System Analyst / Engg
SUN / AIX / HPUX / Linux Admin
IM: AOL / Yahoo / MSN : ggvrsn
Skype: rajiv_gunja

Actually my immediate guess when wondering how to make it re-read its
> config file is "kill -HUP 1", because HUP is traditionally used for
> this in other Unix daemons.  Indeed this produces the "telinit q"
> behavior on Linux.
>
>                                                   -Dave Dodge
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://calug.com/pipermail/lug/attachments/20060830/ea745ea9/attachment.html 


More information about the lug mailing list