shell programming question

Hello,

My goal is to write some script in order to restart devb-eide driver. Since 6.2 NC release doesn’t
include tools for rebuilding images and my system is very limited in RAM size, I still use 6.1A
release. I suppose the options for eide from /etc/system/enum/include/block are not used in 6.2
release also, isn’t it? So, there is no any way to pass parameters during start-up.

In order to move to new 6.2NC and don’t waste 6Mb for cache from total 32Mb of memory, I’m trying
the next script (QNX6.1A):
==========eide.rst================
#!/bin/sh

An useful function

function waitfor {
typeset -i i=0
while test $i -lt 60 -a ! $1 -ef $1 ; do
sleep 1 ;
let i=i+1 ;
done
unset i
}

Start ramdisk manager (just now anounced by RK)

/root/ramdisk/ramdisk &
waitfor /ramdisk

Copy required files to ramdisk

cp -p /x86/sbin/devb-eide /ramdisk/devb-eide
cp -p /x86/bin/mount /ramdisk/mount

Unmount automounted filesystems

umount -v -f /fs/*

Kill EIDE manager

slay devb-eide

Start EIDE manager

/ramdisk/devb-eide blk noatime,cache=1m,rmvto=3s,bufsz=512:32k,automount=/dev/hd1t79:/:qnx4 dos
noexec cam quiet &
waitfor /boot/fs/qnxbase.qfs

Mount base package of binaries

/ramdisk/mount -t qnx4 /boot/fs/qnxbase.qfs /pkgs/base

Mount a rest stuff (using ‘mount’ from /bin)

mount -t dos /dev/hd0t6 /fs/hd0-C
mount -t dos /dev/hd0t6.1 /fs/hd0-D
mount -t dos /dev/hd0t6.2 /fs/hd0-E
mount -t dos /dev/hd1t6 /fs/hd1-myC

Remove ramdisk

slay ramdisk

==========end of eide.rst================
I get
…/eide.rst[28]: cannot fork - try again

So it cannot launch devb-eide. I guess it is because there is no sh link nor ksh under /bin at this
time, no? How can I avoid this problem? After that error report I have normal shell prompt and all
is OK when I start the driver by hands from that prompt. Why?

Thanks in advance and sorry for stupid newbie’s questions :slight_smile:

Eduard.
ed1k at ukr dot net

ed1k@spamerstrap.com sed in 01c25016$8e623aa0$106fa8c0@ED1K:

./eide.rst[28]: cannot fork - try again

You can put “set -x” at beginning to see where it stops…
(yours seems to stop on slay)

Trying out myself (using devb-ram) revealed other pitfalls,
but script below seems to to the job.
Adjust accordingly for your env.


Ed will know it but for other guys:
Killing the device drivers in middle of the operation, with files open
is definitely unsupported.
See output of “sin -p 1 fds” before & after for example.

(I guess this seems to work because QNX doesn’t lazy-load but
loads all the code onto core on exec())

kabe

#!/bin/sh
set -x

default 512*512=256kB ramdisk at /dev/ram0t77

slay devb-ram
devb-ram disk name=ram ram capacity=512 blk cache=0
waitfor /dev/ram0t77 10

store away needed programs

mount /dev/ram0t77 /fs/ram
waitfor /fs/ram 5
cp -p /sbin/devb-eide /fs/ram
cp -p /bin/mount /fs/ram
cp -p /bin/slay /fs/ram
cp -p /bin/waitfor /fs/ram

copy myself to ram and restart from there

cat << ‘EOF’ >/fs/ram/reload; exec sh /fs/ram/reload

set -x

unmounts

umount /fs/hd0-dos*

force unmount

umount -vvv -f /fs/hd0*

kill devb-eide

/fs/ram/slay devb-eide
#(without copying this script to ram, it stops here)

start new devb-eide

libc and others should be in /proc/boot

/fs/ram/devb-eide blk cache=1m,automount=/dev/hd0t78:/:qnx4 &
/fs/ram/waitfor /boot/fs/qnxbase.qfs 10

reload /pkgs/base

/fs/ram/mount /boot/fs/qnxbase.qfs /pkgs/base

EOF

ed1k@spamerstrap.com sed in 01c25016$8e623aa0$106fa8c0@ED1K

release. I suppose the options for eide from /etc/system/enum/include/block are not used in 6.2
release also, isn’t it? So, there is no any way to pass parameters during start-up.
Not used.

devb-eide (and other block driver) options are passed by
`diskboot “-odevb-eide,…”’ which needs *.ifs rebuid to change.
(Ok, you already know that)

In order to move to new 6.2NC and don’t waste 6Mb for cache from total 32Mb
I’ve been using 32MB machine for a while, but you are

likely confined to console (touch /etc/system/config/nophoton)

Using Photon with gcc will soak up 32MB, even after devb-eide tuning.
+16MB=48MB became fairly good…
(and suprise, http://www.qnx.com/nc/ demands 128MB after all :stuck_out_tongue:)

kabe

Kabe,
Thanks for response. I will try to reply both your posts here :slight_smile:
There was rumour at qnx.org.ru that QNX6.2 release use options for devb-eide from
/etc/system/enum/include/block… I didn’t check it and this is not very important for me now
because I wonder what I’m missing with restarting :slight_smile: If that really improved then this thread is
useless in practice but very useful/interesting for me to understand things right. Yes, I’m booting
first to console for many resons and than type ‘ph’ if I need Photon :slight_smile: gcc is working good from
console for my modest educational purposes (maybe it uses swap :slight_smile:.
I added ‘set -x’ line to my script. Sure it still cannot launch the driver. Here is output:

  • waitfor /ramdisk
  • /root/ramdisk/ramdisk
  • cp -p /x86/sbin/devb-eide /ramdisk/devb-eide
  • cp -p /x86/bin/mount /ramdisk/mount
  • umount -v -f /fs/cd0 /fs/hd0-dos-1 /fs/hd0-dos-2 /fs/hd0-dos-3 /fs/hd1-dos
    Attempting to umount: /fs/cd0
    Attempting to umount: /fs/hd0-dos-1
    Attempting to umount: /fs/hd0-dos-2
    Attempting to umount: /fs/hd0-dos-3
    Attempting to umount: /fs/hd1-dos
  • slay devb-eide
    …/eide.rst [28]: cannot fork - try again

Here I can manually launch devb-eide driver & mount base package.
Your script doesn’t leave system in such hard position but doesn’t restart the driver.
Could you, please, tell me more about this trick:

copy myself to ram and restart from there

cat << ‘EOF’ >/fs/ram/reload; exec sh /fs/ram/reload
It seems don’t work for me :frowning: Probably I don’t understand something. But seems it is last line
which works in your script. What did I miss? I tried to write two scripts, first one to copy all
required to memory include second one and exec second script, and second script to slay/restart…
But I had the same problem “cannot fork - try again” :slight_smile:

Thank you,

Eduard.
ed1k at ukr dot net

kabe@sra-tohoku.co.jp wrote in article <ako29q$9ek$1@inn.qnx.com>…

ed1k@spamerstrap.com > sed in <01c25016$8e623aa0$106fa8c0@ED1K

[…]

ed1k <ed1k@spamerstrap.com> wrote in article 01c25041$bb029480$106fa8c0@ED1K

I tried to write two scripts, first one to copy all
required to memory include second one and exec second script, and second script to
slay/restart…
But I had the same problem “cannot fork - try again” > :slight_smile:

Sorry, my mistake… Another error “Can’t access shared library”.
/proc/boot is in PATH variable. libc.so.2 is in /proc/boot…

Here is what I’m doing:
=========go=======
#!/bin/sh

set -x

An useful function

function waitfor {
typeset -i i=0
while test $i -lt 60 -a ! $1 -ef $1 ; do
sleep 1 ;
let i=i+1 ;
done
unset i
}

Start ramdisk manager

/root/ramdisk/ramdisk &
waitfor /ramdisk

Copy required files to ramdisk

cp -p /sbin/devb-eide /ramdisk/devb-eide
cp -p /bin/mount /ramdisk/mount
cp -p /bin/ksh /ramdisk/ksh
cp -p /root/reload /ramdisk/reload

Unmount automounted filesystems

umount -v -f /fs/*

Kill EIDE manager

slay devb-eide
exec /ramdisk/ksh /ramdisk/reload
=========end of go=======
=========reload=========
#!/ramdisk/ksh

set -x

An useful function

function waitfor {
typeset -i i=0
while test $i -lt 60 -a ! $1 -ef $1 ; do
sleep 1 ;
let i=i+1 ;
done
unset i
}

Start of EIDE manager

/ramdisk/devb-eide blk noatime,cache=1m,rmvto=3s,bufsz=512:32k,automount=/dev/hd1t79:/:qnx4 dos
noexec cam quiet &
waitfor /boot/fs/qnxbase.qfs

Mount base package of binaries

/ramdisk/mount -t qnx4 /boot/fs/qnxbase.qfs /pkgs/base

Mount a rest stuff (using ‘mount’ from /bin)

mount -t dos /dev/hd0t6 /fs/hd0-dos-1
mount -t dos /dev/hd0t6.1 /fs/hd0-dos-2
mount -t dos /dev/hd0t6.2 /fs/hd0-dos-3
mount -t dos /dev/hd1t6 /fs/hd1-dos

Remove ramdisk

slay ramdisk

=========end of reload=========

Eduard.
ed1k at ukr dot net

ed1k@spamerstrap.com sed in 01c25041$bb029480$106fa8c0@ED1K

Your script doesn’t leave system in such hard position but doesn’t restart the driver.
Could you, please, tell me more about this trick:

copy myself to ram and restart from there

cat << ‘EOF’ >/fs/ram/reload; exec sh /fs/ram/reload
It seems don’t work for me > :frowning: > Probably I don’t understand something. But seems it is last line

Did you left out the last “EOF” line?
The line is needed to indicate termination for “cat << ‘EOF’”.
See Bourne Shell manual for more info. (grep for “<<”)


slay devb-eide
exec /ramdisk/ksh /ramdisk/reload
This may not work, cus shell tries to read from disk after slay line.

That’s why I’m slaying from the ramdisk script.
But if the trouble is “Can’t access shared library” maybe its different.
Tried setting LD_LIBRARY_PATH?

Another gotcha may be the RK’s ramdisk wasn’t sufficient for this operation;
does devb-ram work?


kabe

ed1k@spamerstrap.com sed in 01c2504b$a4167660$106fa8c0@ED1K

DING here:

function waitfor {
typeset -i i=0
while test $i -lt 60 -a ! $1 -ef $1 ; do
sleep 1 ;
let i=i+1 ;
done
unset i
}

“sleep” is external (/usr/bin/sleep).

kabe

kabe@sra-tohoku.co.jp wrote in article <akoca5$hpg$1@inn.qnx.com>…

ed1k@spamerstrap.com > sed in <01c25041$bb029480$106fa8c0@ED1K

Your script doesn’t leave system in such hard position but doesn’t restart the driver.
Could you, please, tell me more about this trick:

copy myself to ram and restart from there

cat << ‘EOF’ >/fs/ram/reload; exec sh /fs/ram/reload
It seems don’t work for me > :frowning: > Probably I don’t understand something. But seems it is last line

Did you left out the last “EOF” line?
The line is needed to indicate termination for “cat << ‘EOF’”.
See Bourne Shell manual for more info. (grep for “<<”)


slay devb-eide
exec /ramdisk/ksh /ramdisk/reload
This may not work, cus shell tries to read from disk after slay line.
That’s why I’m slaying from the ramdisk script.
But if the trouble is “Can’t access shared library” maybe its different.
Tried setting LD_LIBRARY_PATH?

No :slight_smile:

Another gotcha may be the RK’s ramdisk wasn’t sufficient for this operation;
does devb-ram work?

No. My initial script with some modifications actually works :slight_smile:
I found that sleep is external, but even if I copy it to memory it doesn’t seem to work. The
problem was I must to wait few secs between ‘slay devb-eide’ and ‘/dev/shmem/devb-eide…’ than it
can fork :smiley:

Yes :slight_smile: That is not typo, RK’s ramdisk and devb-ram works equally for me as well as /dev/shmem :slight_smile:
But I need ‘cp -t …’ while copying :slight_smile:

Have no time to play around this script now. If I will get stable result I’ll public it here.

Thanks for your help,
Cheers,

Eduard.
ed1k at ukr dot net

kabe@sra-tohoku.co.jp wrote:

ed1k@spamerstrap.com > sed in <01c25041$bb029480$106fa8c0@ED1K

Your script doesn’t leave system in such hard position but doesn’t restart the driver.
Could you, please, tell me more about this trick:

copy myself to ram and restart from there

cat << ‘EOF’ >/fs/ram/reload; exec sh /fs/ram/reload
It seems don’t work for me > :frowning: > Probably I don’t understand something. But seems it is last line

Did you left out the last “EOF” line?
The line is needed to indicate termination for “cat << ‘EOF’”.
See Bourne Shell manual for more info. (grep for “<<”)



slay devb-eide
exec /ramdisk/ksh /ramdisk/reload
This may not work, cus shell tries to read from disk after slay line.
That’s why I’m slaying from the ramdisk script.
But if the trouble is “Can’t access shared library” maybe its different.
Tried setting LD_LIBRARY_PATH?

Another gotcha may be the RK’s ramdisk wasn’t sufficient for this operation;
does devb-ram work?

Hi,

If you’re trying the ramdisk and find problems, please let me know! I haven’t been
following this thread…

Cheers,
-RK


Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Video-based and Instructor-led
Training and Consulting at www.parse.com.
Email my initials at parse dot com.

At least it’s working on my P166mmx with 32 MB RAM. Thanks everybody for help.

=========== file “devb-eide.restart” ===========
#!/bin/sh

set -x

Copy required files to RAM

cp -t /sbin/devb-eide /dev/shmem/devb-eide
cp -t /bin/mount /dev/shmem/mount
cp -t /usr/bin/sleep /dev/shmem/sleep

Copy myself to RAM and exec me

cat <<‘EOF’ >/dev/shmem/reload; exec sh /dev/shmem/reload

set -x

An useful function

function waitfor {
typeset -i i=0
while test $i -lt $2 -a ! $1 -ef $1 ; do
/dev/shmem/sleep 1 ;
let i=i+1 ;
done
unset i
}

Unmount automounted filesystems

umount -v -f /fs/*

Kill EIDE manager

slay devb-eide

Dummy sleep for a few seconds

waitfor /boot/fs/qnxbase.qfs 3

Start of new improved EIDE manager

/dev/shmem/devb-eide blk noatime,cache=1m,rmvto=3s,bufsz=512:32k,automount=/dev/hd1t79:/:qnx4 dos
noexec cam quiet &
waitfor /boot/fs/qnxbase.qfs 60

Mount base package of binaries and rest filesystems

/dev/shmem/mount -tqnx4 /boot/fs/qnxbase.qfs /pkgs/base
/dev/shmem/mount -tdos /dev/hd0t6 /fs/C
/dev/shmem/mount -tdos /dev/hd0t6.1 /fs/E
/dev/shmem/mount -tdos /dev/hd0t6.2 /fs/F
/dev/shmem/mount -tdos /dev/hd1t6 /fs/D

Remove files from RAM

rm /dev/shmem/mount
rm /dev/shmem/reload
rm /dev/shmem/devb-eide
rm /dev/shmem/sleep

EOF

=========== end of file “devb-eide.restart” ===========


Eduard.
ed1k at ukr dot net

(SUMMARY: the initial motivation was to pass devb-eide the
custom options, which needs *.ifs rebuild, which in turn
is disabled in 6.2NC which lacks “Embedding Tools” (mkifs et al).
A method to restart devb-eide after boot was discussed.)

ed1k@spamerstrap.com sed in 01c25363$e9f7e400$106fa8c0@ED1K

At least it’s working on my P166mmx with 32 MB RAM. Thanks everybody for help.
Seems to work on my P166mmx 48MB too. (Dell XPi CD)


Dummy sleep for a few seconds

waitfor /boot/fs/qnxbase.qfs 3

/dev/shmem/devb-eide blk noatime,cache=1m,rmvto=3s,bufsz=512:32k,automount=/dev/hd1t79:/:qnx4 dos noexec cam quiet &
waitfor /boot/fs/qnxbase.qfs 60
(dunno why but “noexec cam” line is broken in your article)

The reason for “dummy” sleep MAYBE the weird test in function waitfor
(you gleaned it from /etc/rc.d/rc.sysinit right?)

while test $i -lt $2 -a ! $1 -ef $1 ; do
which look more proper with

while test $i -lt $2 -a ! -e $1 ; do

Or, devb-eide couldn’t detach from /dev before next invocation
(“slay” sends signal so is asyncronous)
so waiting to be sure the previous devb-eide is gone may help.


FYI my modified script below will re-mount the current mounts
so it’ll be more or less generic.

kabe

#!/bin/sh

Ed’s devb-eide restarter, modified

set -x

Copy required files to RAM

cp -t /sbin/devb-eide /dev/shmem/
cp -t /bin/mount /dev/shmem/
cp -t /usr/bin/sleep /dev/shmem/

Copy myself to RAM and exec me

cat <<‘EOF’ >/dev/shmem/reload;
mount | sort +2 |
awk ‘$5 !~ /pkg/ {
print “waitfor”,$1,10; print “/dev/shmem/mount -t”,$5,$1,$3
}’ >> /dev/shmem/reload;
exec sh /dev/shmem/reload

set -x

An useful function

function waitfor {
typeset -i i=0
while test $i -lt $2 -a ! -e $1 ; do
echo wait for $1 $i;
/dev/shmem/sleep 1 ;
let i=i+1 ;
done
unset i
}

Unmount automounted filesystems

umount -v -f /fs/*

Kill EIDE manager, be sure it’s gone

PID_EIDE=slay -p devb-eide
if [ -z $PID_EIDE ]; then echo “No devb-eide.” 1>&2; exit; fi
slay devb-eide
while test -d /proc/$PID_EIDE; do /dev/shmem/sleep 1; done

Dummy sleep for a few seconds

#/dev/shmem/sleep 3

Start of new improved EIDE manager

#/dev/shmem/devb-eide blk noatime,cache=1m,rmvto=3s,bufsz=512:32k,automount=/dev/hd0t78:/:qnx4 &
/dev/shmem/devb-eide blk noatime,cache=1m,rmvto=3s,bufsz=512:32k &

mount commands follow

EOF

kabe@sra-tohoku.co.jp wrote in article <al31fr$bjb$1@inn.qnx.com>…

(SUMMARY: the initial motivation was to pass devb-eide the
custom options, which needs *.ifs rebuild, which in turn
is disabled in 6.2NC which lacks “Embedding Tools” (mkifs et al).
A method to restart devb-eide after boot was discussed.)

ed1k@spamerstrap.com > sed in <01c25363$e9f7e400$106fa8c0@ED1K

At least it’s working on my P166mmx with 32 MB RAM. Thanks everybody for help.
Seems to work on my P166mmx 48MB too. (Dell XPi CD)

Yes, I think it depends on IDE hardware also :slight_smile: My is old m/b from VIA VPX-(VT82C585VPX+VT82C586A),
Quantum 4G & Seagate 2G & old dual speed CD-ROM (name is removed by time).

Dummy sleep for a few seconds

waitfor /boot/fs/qnxbase.qfs 3

/dev/shmem/devb-eide blk noatime,cache=1m,rmvto=3s,bufsz=512:32k,automount=/dev/hd1t79:/:qnx4
dos noexec cam quiet &
waitfor /boot/fs/qnxbase.qfs 60
(dunno why but “noexec cam” line is broken in your article)

Just that line was too long line from point of view of my newsreader :slight_smile:

The reason for “dummy” sleep MAYBE the weird test in function waitfor
(you gleaned it from /etc/rc.d/rc.sysinit right?)

right :slight_smile: But I think the problem is in another, see below

while test $i -lt $2 -a ! $1 -ef $1 ; do
which look more proper with
while test $i -lt $2 -a ! -e $1 ; do

Or, devb-eide couldn’t detach from /dev before next invocation
(“slay” sends signal so is asyncronous)
so waiting to be sure the previous devb-eide is gone may help.

Yes. My system is in very unstable state while spirit of devb-eide is going away :slight_smile: see below :slight_smile:

FYI my modified script below will re-mount the current mounts
so it’ll be more or less generic.

Good work. Thanks! It will not work in QNX 6.1A, but fortunatelly there is embedding tools in this
release. The problem is with output of mount. For root filesystem it is reported /dev/hd1t7 (eats
last ‘9’ because there is ‘backspace’ symbol exactly after ‘9’). I think it’s improved in 6.2
release. BTW, I have t7 (NTFS4) partition… can imagine :slight_smile:

[snip the begin of good script]

Kill EIDE manager, be sure it’s gone

PID_EIDE=slay -p devb-eide
if [ -z $PID_EIDE ]; then echo “No devb-eide.” 1>&2; exit; fi
slay devb-eide
while test -d /proc/$PID_EIDE; do /dev/shmem/sleep 1; done

Here I have something like:

  • test /proc/6
  • /dev/shmem/sleep 1
    /dev/shmem/sleep: Can’t access shared library
  • test /proc/6

It is good case. But sometimes there is the situation:

  • test /proc/6
  • /dev/shmem/sleep 1
    /dev/shmem/reload[22]: Can’t fork - try again

I think while devb-eide is going dead no one can access /proc/boot/libc.so in better case and in
worse case ksh can’t fork process and aborts the script. Dunno why it is but my solution is don’t
use external commands at all. So better is

while test -d /proc/$PID_EIDE; do test -d /dev/hd0; done

It’s my last modification. Now it works good and reliable enough for me.

Thank you very much.

Eduard.
ed1k at ukr dot net

ed1k <ed1k@spamerstrap.com> wrote in article
[…]

Good work. Thanks! It will not work in QNX 6.1A, but fortunatelly there is embedding tools in
this
release. The problem is with output of mount. For root filesystem it is reported /dev/hd1t7 (eats
last ‘9’ because there is ‘backspace’ symbol exactly after ‘9’). I think it’s improved in 6.2
release. BTW, I have t7 (NTFS4) partition… can imagine > :slight_smile:

After restarting of devb-eide ‘mount’ shows correct mountpoints even in 6.1A release. So, I was
able to test improved script :slight_smile:.

[…]

It’s my last modification. Now it works good and reliable enough for me.

Just a little of cosmetic (still there is no USAGE section and I think cache size could be as
parameter of script :slight_smile:)

------------------- devb-eide.restart (-rwxrw-r–) --------------------
#!/bin/sh

set -x

Copy required files to RAM

cp -t /sbin/devb-eide /dev/shmem/
cp -t /bin/mount /dev/shmem/
cp -t /usr/bin/sleep /dev/shmem/

Copy myself to RAM and exec me

cat <<‘EOF’ >/dev/shmem/reload;
mount | sort +2 |
awk ‘$5 !~ /pkg/ {
print “waitfor”,$1,10; print “/dev/shmem/mount -t”,$5,$1,$3
}’ >> /dev/shmem/reload;
echo rm /dev/shmem/devb-eide >> /dev/shmem/reload;
echo rm /dev/shmem/sleep >> /dev/shmem/reload;
echo rm /dev/shmem/mount >> /dev/shmem/reload;
echo rm /dev/shmem/reload >> /dev/shmem/reload;
exec sh /dev/shmem/reload

set -x

An useful function

function waitfor {
typeset -i i=0
while test $i -lt $2 -a ! -e $1 ; do
echo wait for $1 $i;
/dev/shmem/sleep 1 ;
let i=i+1 ;
done
unset i
}

Looking for devb-eide’s PID

PID_EIDE=slay -p devb-eide
if [ -z $PID_EIDE ]; then echo “No devb-eide.” 1>&2; exit; fi

Unmount automounted filesystems

umount -v -f /fs/*

Kill EIDE manager, be sure it’s gone

slay devb-eide
while test -d /proc/$PID_EIDE; do test -d /dev/hd0; done

Start of new improved EIDE manager

/dev/shmem/devb-eide blk noatime,cache=512k,rmvto=3s,bufsz=512:32k &

mount commands follow

EOF

------------------ end of devb-eide.restart -----------------

Eduard.
ed1k at ukr dot net

ed1k <ed1k@spamerstrap.com> wrote in article 01c25410$2b7fc940$106fa8c0@ED1K

[…]
(still there is no USAGE section and I think cache size could be as
parameter of script > :slight_smile:> )

No, I think coolest idea is to parse the file
/etc/system/enum/include/block
and take the devb-eide options from that file. I’m not strong enough for this job, but seems they
in QSS[L] want such script at least for NC :smiley:

Eduard.
ed1k at ukr dot net

ed1k@spamerstrap.com sed in 01c25422$b876a640$106fa8c0@ED1K

No, I think coolest idea is to parse the file
/etc/system/enum/include/block
and take the devb-eide options from that file.

I won’t buy this; you don’t want to rely on other files on disk
when restarting the disk driver
(ok,ok, we’re using plenty of external commands in the script anyway)

Spin-waiting for devb-eide kill isn’t neat, but I can’t think of
better solution. Time for compiled program?

It’ll be messy to cram "; " things after here-document, so moved out
things to the bottom.
Lots of comments added – the important thing is why, not always what, is done.

I’ve not tried embedding this onto /etc/system/sysinit,
but in case the calling shell lost count on devb restart,
you may want to pass the script name to continue after the restarter.

Most Important Thing: This Operation Is Unsupported. Use At Your Own Risk.

I’ve found spill files won’t work properly after restart
(editing fs-pkg managed files don’t fall to spill but goes
directly to disk)
you may want to kill&restart fs-pkg as well.

kabe

#!/bin/sh

devb-eide restarter

You should tune the devb-eide restart options to suit your needs

#if __USAGE
#%C - Restart devb-eide with new options

WARNING: This utility slay/restarts devb-eide disk driver

in middle of the operation with possible open files;

this is definitely UNSUPPORTED and be prepared for possible corruption.

#Usage:
#%C

#endif

set -x

RAMDISK=/dev/shmem; export RAMDISK

Copy required files to RAM

cp -t /sbin/devb-eide ${RAMDISK}/
cp -t /bin/mount ${RAMDISK}/
cp -t /usr/bin/sleep ${RAMDISK}/

Copy myself to RAM and exec me

cat << ‘EOF’ > ${RAMDISK}/reload

hack consideration:

avoid fork() and use ksh builtin whenever possible

as disk files isn’t always available

set -x

An useful function

function waitfor {
typeset -i i=0
while test $i -lt $2 -a ! -e $1 ; do
${RAMDISK}/sleep 1 ;
let i=i+1 ;
done
unset i
}

Look for devb-eide’s PID

PID_EIDE=slay -p devb-eide
if [ -z $PID_EIDE ]; then echo “No devb-eide.” 1>&2; exit; fi

Force unmount filesystems

umount -v -f /fs/*

Kill EIDE manager, be sure it’s gone

kill $PID_EIDE

fork()ing for “sleep” won’t work on some hardware during eide death,

so reluctantly spin-wait here

#while test -d /proc/$PID_EIDE; do ${RAMDISK}/sleep 1; done
while test -d /proc/$PID_EIDE -a -e /dev/hd0; do :; done

Start EIDE manager with new options

#${RAMDISK}/devb-eide blk noatime,cache=1m,rmvto=3s,bufsz=512:32k,automount=/dev/hd0t78:/:qnx4 &
${RAMDISK}/devb-eide blk noatime,cache=1m,rmvto=3s,bufsz=512:32k &

mount commands follow

set +x
EOF

qnet makes mount output “/net/localhost.localdomain/dev/…”

which makes hard to extract local mounts

#umount /dev/io-net/qnet*
if [ -e /dev/io-net/qnet0 ]; then
echo “qnet not supported now” >&2
exit
fi

build re-mount commands from current mounts

waitfor 10; mount -t

mount | sort +2 |
awk ‘$5 !~ /pkg/ {
print “waitfor”,$1,10; print “${RAMDISK}/mount -t”,$5,$1,$3
}’ >> ${RAMDISK}/reload

cleanup;

erasing running binaries is allowed in POSIX filesystems

cat << ‘EOF’ >> ${RAMDISK}/reload
rm -f ${RAMDISK}/devb-eide
rm -f ${RAMDISK}/mount
rm -f ${RAMDISK}/sleep
rm -f ${RAMDISK}/reload

parent shell may have lost the original script during devb reload

exec sh /etc/system/sysinit.orig

EOF

exit

exec sh ${RAMDISK}/reload

ed1k@spamerstrap.com sed in 01c253fe$1c592cc0$106fa8c0@ED1K

  • test /proc/6
  • /dev/shmem/sleep 1
    /dev/shmem/sleep: Can’t access shared library
  • test /proc/6

It is good case. But sometimes there is the situation:

  • test /proc/6
  • /dev/shmem/sleep 1
    /dev/shmem/reload[22]: Can’t fork - try again

I think while devb-eide is going dead no one can access /proc/boot/libc.so in better case and in
worse case ksh can’t fork process and aborts the script. Dunno why it is

MAYBE it’s caused by shlib search.
6.2 has a bug of always scanning “.” for shlibs.
But during devb-eide death there could be a timing
when “.” doesn’t exist.
Maybe “cd /dev/shmem” “cd /proc/boot” at the top may cure it?

Spinwait should be avoided whenever possible.

(… that won’t fix “can’t fork”…)

kabe