[Techtalk] Open file descriptors

dominik.schramm at gmxpro.net dominik.schramm at gmxpro.net
Fri Jan 9 13:16:20 EST 2004


Hi David,

David Sumbler <david at aeolia.co.uk> writes:
> I originally asked this question on NewChix.  Unfortunately I had no
> replies, but I am sure that somebody out there must know the answer.

Looks like noone here knows. :-)
Here is what I found out by looking at the source (couldn't stand
to see your message unanswered).

Note that (for me) the source is pretty unreadable since almost
nothing is commented. But I think the description is accurate 
enough to make rc.sysinit's behavior more intelligible.

> Amongst the options detailed by 'man initlog' are:
>
> -c. --cmd=[program]
>               Execute the specified program, logging anything output to stdout
>               or stderr.
>
> -r. --run=[program]
>               Execute the specified program, with an open file
>               descriptor so that the program can pass back
>               commands to initlog.

> Could somebody explain to me what an "open file descriptor" is, and
> how the execution of a program using '-r' is different from using
> '-c'?  How does the program "pass back commands to initlog"?

It passes the commands back to initlog by writing them to a pipe
that is opened by initlog when given the -r switch and 
(for the forked program to know about it) "passed on" to the 
program that is started. 
These commands have to be valid for initlog to be able to understand
them, so I guess only sysinit-related programs use this feature
(or even only *initlog* itself).

To answer your (much) earlier question (it was yours, wasn't it?) 
why rc.sysinit does not start itself infinitely often:
When rc.sysinit is first run, it restarts itself through 
initlog with the -r switch. 
Like this:
# Rerun ourselves through initlog
if [ -z "$IN_INITLOG" -a -x /sbin/initlog ]; then
    exec /sbin/initlog $INITLOG_ARGS -r /etc/rc.d/rc.sysinit
fi

initlog starts any desired program in question and sets the 
environment variable IN_INITLOG to 1 if the reexec parameter
was given (-r switch; which by the way supports my theory
that only initlog itself is called with the -r switch). So
from rc.sysinit it starts initlog, which sets this variable,
and from then on, rc.sysinit does not execute the if block
any more.

BTW. the man page looks like it was written by a developer,
so don't worry if you didn't understand it. Also, you needn't
understand it because you very likely will never need to use
the -r switch in your own scripts. 

I hope this doesn't confuse things more than it explains them.
regards,
dominik

-- 
Dominik Schramm <dominik.schramm at gmxpro.net>
pgp key available via e-mail, web, and FTP from 
http://www.cam.ac.uk.pgp.net/pgpnet/wwwkeys.html



More information about the Techtalk mailing list