Stephen Gran on 5 Jan 2004 04:12:02 -0000

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[PLUG] How to find parent in the shell?

Hello all,

Somebody (Bruce Perens, of all people :) recently submitted a bug report
against one of my packages (hdparm), asking that it not be run
automatically except at boot up.  The problem I'm having now is to
figure out how to figure out if it's being called at boot, or by dpkg on
upgrade, or by hand.

I've mostly solved the 'by hand' - I gave it a
/etc/init.d/hdparm manual-start option (better names accepted - rough
working copy) that bypasses the other checks.  I can think of things
like `echo $0 | grep -q '/etc/rcS.d/hdparm'`, although I see two
problems with this.

The first is it's just ugly :(  The second is that it doesn't work for
alternate boot schemes like file-rc, where $0 _won't_ be the link in
rcS.d.  I think that sets an environment variable, however, so that's
probably able to be worked in.  Also be aware - the script is run before, so my options are fairly limited in what I can use.
Really, only the most basic shell stuff, with no access to anything much

What I'm looking for is something like $PPID, or maybe $$, but that
gives me a little more information to work with, and a way to make it be
portable across the various implementations.  I sadly admit I only
really know the default Debian way of doing things as far as boot up
sequences go, so I'm hoping someone knows enough about different boot
implementations (file-rc, runit & co., SysV init, etc) to have osme
decent advice about this.  I can think of all sorts of one-each hacks to
work around the different systems as I find out how each works, but no
relatively elegant solution that would work across at least a few.  Or
maybe just be more elegant than mine :)

|  Stephen Gran                  | Envy, n.:  Wishing you'd been born with |
|             | an unfair advantage,  instead of having |
| | to try and acquire one.                 |

Attachment: pgpCvMASx9Kvh.pgp
Description: PGP signature