Modify

Opened 9 years ago

Closed 7 years ago

Last modified 5 years ago

#1945 closed defect (fixed)

/etc/rc.d/K* script don't run due to /etc/init.d/rcS running in background

Reported by: atomota Owned by: developers
Priority: normal Milestone:
Component: base system Version:
Keywords: Cc:

Description

In Kamikaze 7.06, /etc/init.d/rcS runs the /etc/rc.d/K* scripts in the background. Note the ampersand at the end:

#!/bin/sh
# Copyright (C) 2006 OpenWrt.org

{
        for i in /etc/rc.d/$1*; do
                $i $2 2>&1
        done
} | logger -s -p 6 -t '' &

This means that on reboot, /etc/init.d/rcS completes very quickly and init then proceeds to kill everything and reboot while the scripts are still trying to run. Consequently, most cleanup actions won't be performed and filesystems won't be cleanly unmounted, which is not good for filesystems attached via USB (at least).

I fixed this on my system by simply removing the ampersand. I believe this is ok but haven't thoroughly investigated the interactions with init.

Attachments (2)

rcs.patch (579 bytes) - added by jirif <jiri.fojtasek@…> 9 years ago.
fix
rcs-2.patch (581 bytes) - added by blackbox@… 7 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 Changed 9 years ago by atomota

It turns out that just removing the & leaves zombies left and right. I've removed the entire "| logger ... &" as a workaround.

comment:2 Changed 9 years ago by jirif <jiri.fojtasek@…>

rcs.patch i posted fixing it and adding informational output to the system console about what service starting. The problem was than logger cannot be used before syslog is started, othervise stuck in deadloop.

Jiri

Changed 9 years ago by jirif <jiri.fojtasek@…>

fix

comment:3 Changed 9 years ago by azaghal

This might have some nasty consequences if left as it is. For start, the /etc/rc.d/K99umount won't get run (which means a possible data loss). I've actually ran into this problem while trying to save date on reboot (since the router can't keep track of time across reboots).
Maybe a solution would be to move logging to actual /etc/init.d scripts instead of having it here? (this way you'd be able to produce a more sane/controlled logging information anyway)

comment:4 Changed 8 years ago by mk144210@…

Your script did not work for me (the router never started up after rebooting). The following worked for me however:

#!/bin/sh
# Copyright (C) 2006 OpenWrt.org

if [ "$1" == "K" ]; then
        # Run synchronously
        {
                for i in /etc/rc.d/$1*; do
                        $i $2 2>&1
                done 
        } | logger -s -p 6 -t ''
else
        # Run asynchronously
        {
                for i in /etc/rc.d/$1*; do
                        $i $2 2>&1
                done 
        } | logger -s -p 6 -t '' &
fi

comment:5 Changed 8 years ago by blackbox@…

I faced the same proplem on my nslu2. The solution above of mk144210@… works well.

I find this a serious issue since devices left mounted could cause data loss. Please apply the simple fix in the trunk and close this ticket soon.

IMO the original rcs.patch is insufficient:

  • As atomota noted "just removing the & leaves zombies left and right."
  • the additional check of a running syslog daemon isn't nessesary (any more?) since /etc/rc.d/S01syslog is (now?) the first script executed. (I haven't checked the file histories, maybe there was a problem with logging some time ago.)

Instead we simply check wether rcS is used for booting or shutdown/reboot and add a & accordingly.

chris

comment:6 Changed 8 years ago by anarchetic@…

Slightly off-topic, but while people are looking at this file ... I've just installed Kamikaze 7.09, and I've noticed logger running. Looking at its fds, it's reading from a pipe:

root@OpenWrt:/etc/rc.d# ls -l /proc/63/fd
lr-x------    1 root     root           64 Jul 30 22:55 0 -> pipe:[147]
lrwx------    1 root     root           64 Jul 30 22:55 1 -> /dev/tts/0
lrwx------    1 root     root           64 Jul 30 22:55 2 -> /dev/tts/0
lrwx------    1 root     root           64 Jul 30 22:55 3 -> socket:[215]

The other end of this pipe, is as far as I can see, only attached to klogd:

root@OpenWrt:/etc/rc.d# ls -l /proc/99/fd
lr-x------    1 root     root           64 Jul 30 22:56 0 -> /dev/null
l-wx------    1 root     root           64 Jul 30 22:56 1 -> pipe:[147]
l-wx------    1 root     root           64 Jul 30 22:56 2 -> pipe:[147]
lrwx------    1 root     root           64 Jul 30 22:56 3 -> socket:[206]

Looking at the bb code for klogd, I can't see that it ever writes to stdout / stderr; if it closed them, presumably logger could exit and free a little memory.. (Looking at the bb source, though, I can't actually work out why klogd doesn't close these fds whereas everything else does.)

comment:7 Changed 7 years ago by Warren Turkal <wt@…>

Has this been addressed for the newer RC releases?

comment:8 Changed 7 years ago by florian

  • Resolution set to fixed
  • Status changed from new to closed

base-files changed a lot since this ticket was open if the issue is still present, please re-open with the updated fix.

Changed 7 years ago by blackbox@…

comment:9 Changed 7 years ago by blackbox@…

I re-open since the issue is still present.
You can test playing around with sleep and switching the leds in /etc/init.d/umount (at least on my nslu2, the umount command will not execute with the default rcS file)

Attached is an appropriate fix (rcs-2.patch).

Add Comment

Modify Ticket

Action
as closed .
The resolution will be deleted. Next status will be 'reopened'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.