Runlevel testing in init scripts

Richard Lightman richard at nezumi.plus.com
Tue Sep 10 00:30:45 PDT 2002


* DJ Lucas <dj_me at swbell.net> [2002-09-10 07:55]:
> First thing I need to do this, is a way to get the name of the currently
> running script (preferably not the name of the symlink).

Bash needs to read the script, so it has a file descriptor open
to do so. AFAIK, it chooses descriptor 255 (I do not know what happens
if this is already in use). The file attached to each descriptor
can be found in the /proc directory: /proc/<process id>/fd/<descriptor>
is a link to the honest file, not some symlink (I have not checked
mount --bind). A bash script can find its own process id in $$.
Remember find is in /usr/bin, and /usr need not be mounted when
some of the init scripts run:

[richard at urusai tmp]$ cat x
#! /bin/bash

find /proc/$$/fd -name 255 -printf '%l\n'
[richard at urusai tmp]$ ls -l
total 4
drwxr-xr-x    4 root     root            0 Sep 10 07:37 urusai
-rwxr-xr-x    1 richard  richard        56 Sep 10 08:19 x
lrwxrwxrwx    1 richard  richard         1 Sep 10 08:08 y -> x
lrwxrwxrwx    1 richard  richard         9 Sep 10 08:14 z -> /var/tmp/
[richard at urusai tmp]$ ./x
/var/tmp/x
[richard at urusai tmp]$ ./y
/var/tmp/x
[richard at urusai tmp]$ ./z/x
/var/tmp/x
[richard at urusai tmp]$ ./z/y
/var/tmp/x
[richard at urusai tmp]$ /var/tmp/x
/var/tmp/x
[richard at urusai tmp]$ /var/tmp/y
/var/tmp/x
[richard at urusai tmp]$ /var/tmp/z/x
/var/tmp/x
[richard at urusai tmp]$ /var/tmp/z/y
/var/tmp/x
[richard at urusai tmp]$


Richard
-- 
Unsubscribe: send email to listar at linuxfromscratch.org
and put 'unsubscribe lfs-chat' in the subject header of the message



More information about the lfs-chat mailing list