USB script executed during sysinit... how many times?

Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Broadcom SoC based Hardware
Goto page 1, 2  Next
Author Message
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 986
Location: Hung Hom, Hong Kong

PostPosted: Sat May 14, 2022 7:40    Post subject: USB script executed during sysinit... how many times? Reply with quote
How many times had rc_usb been executed? Smile

It seemed that my check [[ "$xx" > "1" ]] failed despite that there were indeed multiple entries of '{.rc_usb}' in the process list...

This was the USB script:
Code:
#!/bin/sh
#
pslog=/var/log/ps.log.txt

is-mounted.sh

logger "changmw: starting .rc_usb"

ps | grep -i usb >> $pslog
echo -n >> $pslog

xx=`ps | grep '{.rc_usb}' | grep -v grep | wc -l`
echo $xx >> $pslog
echo -n >> $pslog
if [[ "$xx" > "1" ]] ; then
   logger "changmw: .rc_usb already started($xx)"
   exit 1
fi

And here was /var/log/ps.log.txt:
Code:
> cat ps.log.txt

 2489 root     [usb-storage]
 2734 root     startservice run_rc_usb -f
 2735 root     startservice run_rc_usb -f
 2736 root     /sbin/service run_rc_usb start -f
 2739 root     /sbin/service run_rc_usb start -f
 2741 root     {.rc_usb} /bin/sh /tmp/.rc_usb blockdev_add /opt
 2742 root     {.rc_usb} /bin/sh /tmp/.rc_usb blockdev_add /opt
 2851 root     grep -i usb
 2489 root     [usb-storage]
3
 2734 root     startservice run_rc_usb -f
 2735 root     startservice run_rc_usb -f
 2736 root     /sbin/service run_rc_usb start -f
 2739 root     /sbin/service run_rc_usb start -f
 2741 root     {.rc_usb} /bin/sh /tmp/.rc_usb blockdev_add /opt
 2742 root     {.rc_usb} /bin/sh /tmp/.rc_usb blockdev_add /opt
 2856 root     {.rc_usb} /bin/sh /tmp/.rc_usb blockdev_add /opt
 2858 root     grep {.rc_usb}
 2862 root     grep -i usb
4

And here was /var/log/messages:
Code:
> grep changmw messages                                                                   

May 14 15:27:41 RT-N18U-HST user.notice root: changmw: starting .rc_usb
May 14 15:27:41 RT-N18U-HST user.notice root: changmw: starting .rc_usb
...

_________________
Router: Asus RT-N18U (rev. A1)

May the Force and farces be with you! Live long and prosper!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
Sponsor
ho1Aetoo
DD-WRT Guru


Joined: 19 Feb 2019
Posts: 1258
Location: Germany

PostPosted: Sat May 14, 2022 8:12    Post subject: Reply with quote
With one mounted USB drive/partition it will run 1x.
With multiple drives it may be executed multiple times.


Last edited by ho1Aetoo on Sat May 14, 2022 8:16; edited 1 time in total
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 986
Location: Hung Hom, Hong Kong

PostPosted: Sat May 14, 2022 8:14    Post subject: Reply with quote
ho1Aetoo wrote:
With one mounted UBS drive/partition it will run 1x.
With multiple drives it may be executed multiple times.

I have only one USB drive.

edit:

OK, my USB drive indeed had 2 partitions...

Strange that the count didn't work as expected...


_________________
Router: Asus RT-N18U (rev. A1)

May the Force and farces be with you! Live long and prosper!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832


Last edited by mwchang on Sat May 14, 2022 8:20; edited 1 time in total
ho1Aetoo
DD-WRT Guru


Joined: 19 Feb 2019
Posts: 1258
Location: Germany

PostPosted: Sat May 14, 2022 8:19    Post subject: Reply with quote
But you can also mount the USB stick twice. Smile
Simply by assigning a suitable label + mount by UUID

a screenshot of WebIF > Services > USB gives some information
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 986
Location: Hung Hom, Hong Kong

PostPosted: Sat May 14, 2022 8:23    Post subject: Reply with quote
ho1Aetoo wrote:
But you can also mount the USB stick twice. Smile
Simply by assigning a suitable label + mount by UUID

a screenshot of WebIF > Services > USB gives some information

Well, as you said, I had 2 partitions, mounted as /opt and /jffs respectively, each had it's UUID. Because /dev/sda was also mounted with a failure, I guess it meant rc_usb was indeed executed 3 times (sda, sda1, sda2) according to your saying.

Here was the USB tab:
Code:
--- /dev/sda
Block device, size 14.91 GiB (16008609792 bytes)
DOS/MBR partition map

Partition 1: 2 GiB (2147483648 bytes, 4194304 sectors from 32)
Type 0x83 (Linux)
Ext4 file system
UUID D75E81C7-527A-427D-xxxxx (DCE, v4)
Last mounted at "/jffs"
Volume size 2 GiB (2147483648 bytes, 524288 blocks of 4 KiB)

Partition 2: 12.91 GiB (13861109760 bytes, 27072480 sectors from 4194336)
Type 0x83 (Linux)
Ext4 file system
UUID 4BCEF791-82FC-487F-xxxxx (DCE, v4)
Last mounted at "/opt"
Volume size 12.91 GiB (13861109760 bytes, 3384060 blocks of 4 KiB)

FAT32 file system (hints score 4 of 5)
Volume size 14.89 GiB (15992987648 bytes, 1952269 clusters of 8 KiB)
Volume name ""
/dev/sda not mounted Unsupported Filesystem

--- /dev/sda1
Block device, size 2 GiB (2147483648 bytes)
Ext4 file system
UUID D75E81C7-527A-427D-xxxxx (DCE, v4)
Last mounted at "/jffs"
Volume size 2 GiB (2147483648 bytes, 524288 blocks of 4 KiB)
/dev/sda1 mounted to /jffs

--- /dev/sda2
Block device, size 12.91 GiB (13861109760 bytes)
Ext4 file system
UUID 4BCEF791-82FC-487F-xxxxxx (DCE, v4)
Last mounted at "/opt"
Volume size 12.91 GiB (13861109760 bytes, 3384060 blocks of 4 KiB)
/dev/sda2 mounted to /opt

_________________
Router: Asus RT-N18U (rev. A1)

May the Force and farces be with you! Live long and prosper!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832


Last edited by mwchang on Sat May 14, 2022 8:32; edited 2 times in total
ho1Aetoo
DD-WRT Guru


Joined: 19 Feb 2019
Posts: 1258
Location: Germany

PostPosted: Sat May 14, 2022 8:29    Post subject: Reply with quote
BS said to me then I must write my script so that a multiple execution does not interfere

Well I only see 2 mounted drives.
The script should be executed only 2x.
(in my opinion still 1x too much)
the-joker
DD-WRT Developer/Maintainer


Joined: 31 Jul 2021
Posts: 672
Location: All over YOUR webs

PostPosted: Sat May 14, 2022 9:20    Post subject: Reply with quote
As far as I know, when USB is started devices etc pluged into USB, things rinse and repeat. Nothing to do with sysinit I think.

egc is the one who knows exactly whats going on there.

Sorry Im not looking at the code.

_________________
Saving your retinas from the burn!🔥
DD-WRT Inspired themes for routers
DD-WRT Inspired themes for the phpBB Forum
DD-WRT Inspired themes for the SVN Trac & FTP site
Join in for a chat @ #style_it_themes_public:matrix.org or #style_it_themes:discord

DD-WRT UI Themes Bug Reporting and Discussion thread

Router: ANus RT-AC68U E1 (recognized as C1)
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 986
Location: Hung Hom, Hong Kong

PostPosted: Sat May 14, 2022 9:33    Post subject: Reply with quote
ho1Aetoo wrote:
BS said to me then I must write my script so that a multiple execution does not interfere

Well I only see 2 mounted drives.
The script should be executed only 2x.
(in my opinion still 1x too much)

Even more horrifying is sfe ... Smile
Code:
> grep -E 'sfe|changmw|cleanup' /var/log/messages

Jan  1 08:00:12 RT-N18U-HST kern.info kernel: [    0.942366] PCI: bus0: Fast back to back transfers disabled
Jan  1 08:00:12 RT-N18U-HST kern.info kernel: [    0.942820] PCI: bus1: Fast back to back transfers disabled
Jan  1 08:00:14 RT-N18U-HST user.info : [sfe] : shortcut forwarding engine successfully stopped
Jan  1 08:00:19 RT-N18U-HST user.info : [sfe] : shortcut forwarding engine successfully started
Jan  1 08:00:22 RT-N18U-HST user.info : [sfe] : shortcut forwarding engine successfully started
Jan  1 08:00:28 RT-N18U-HST user.info : [sfe] : shortcut forwarding engine successfully stopped
Jan  1 08:00:28 RT-N18U-HST user.info : [sfe] : shortcut forwarding engine successfully started
Jan  1 08:00:29 RT-N18U-HST user.info : [sfe] : shortcut forwarding engine successfully stopped
Jan  1 08:00:30 RT-N18U-HST user.info : [sfe] : shortcut forwarding engine successfully started
Jan  1 08:00:33 RT-N18U-HST user.info : [sfe] : shortcut forwarding engine successfully started
May 14 17:25:37 RT-N18U-HST user.info : [sfe] : shortcut forwarding engine successfully stopped
May 14 17:25:37 RT-N18U-HST user.info : [sfe] : shortcut forwarding engine successfully started
May 14 17:25:39 RT-N18U-HST user.info : [sfe] : shortcut forwarding engine successfully stopped
May 14 17:25:42 RT-N18U-HST user.info : [sfe] : shortcut forwarding engine successfully started
May 14 17:25:45 RT-N18U-HST user.info : [sfe] : shortcut forwarding engine successfully started
May 14 17:25:48 RT-N18U-HST daemon.info process_monitor[1863]: [process_monitor] : cleanup timers
May 14 17:25:51 RT-N18U-HST user.notice root: changmw: starting .rc_usb
May 14 17:25:51 RT-N18U-HST user.notice root: changmw: starting .rc_usb
May 14 17:25:51 RT-N18U-HST user.notice root: changmw: .rc_usb already started
May 14 17:25:51 RT-N18U-HST user.notice root: 0: changmw waiting for init for 5 seconds
May 14 17:25:56 RT-N18U-HST user.notice root: 1: changmw waiting for init for 5 seconds
May 14 17:26:01 RT-N18U-HST user.notice root: 2: changmw waiting for init for 5 seconds
May 14 17:26:06 RT-N18U-HST user.notice root: 3: changmw waiting for init for 5 seconds
May 14 17:26:11 RT-N18U-HST user.notice root: 4: changmw re-starting unbound
May 14 17:26:13 RT-N18U-HST user.notice root: 4: changmw re-starting minidlna



_________________
Router: Asus RT-N18U (rev. A1)

May the Force and farces be with you! Live long and prosper!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
the-joker
DD-WRT Developer/Maintainer


Joined: 31 Jul 2021
Posts: 672
Location: All over YOUR webs

PostPosted: Sat May 14, 2022 10:31    Post subject: Reply with quote
and Dnsmasq here it repeats everything several times, the logs is just spam of useless stuff. The services restart for no real reason, and some services do not start at all unless you hammer the apply button https://forum.dd-wrt.com/phpBB2/viewtopic.php?p=1262339
_________________
Saving your retinas from the burn!🔥
DD-WRT Inspired themes for routers
DD-WRT Inspired themes for the phpBB Forum
DD-WRT Inspired themes for the SVN Trac & FTP site
Join in for a chat @ #style_it_themes_public:matrix.org or #style_it_themes:discord

DD-WRT UI Themes Bug Reporting and Discussion thread

Router: ANus RT-AC68U E1 (recognized as C1)
kernel-panic69
DD-WRT Guru


Joined: 08 May 2018
Posts: 12419
Location: Texas, USA

PostPosted: Sat May 14, 2022 10:39    Post subject: Reply with quote
SFE recycles every NTP sync; there are probably others that do as well. This is why I only sync NTP once per 24 hours. Less log spam Wink Cool
_________________
Official Forum Rules, Guidelines & Helpful InformationFirmware FAQInstallation WikiWhere Do I Download Firmware‽
DON'T use Chromium-based browsersRTFM/STFW TL;DR is NOT an excuse. • Why Should I Care What Color the Bikeshed Is‽
Please DO NOT PM me with questions; Ask in the forum. ---------------------- Linux User #377467 counter.li.org / linuxcounter.net
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 9585
Location: Netherlands

PostPosted: Sat May 14, 2022 10:45    Post subject: Reply with quote
The problem is that services rely on each other, lets take DNSMasq, you want it to start early to get a WAN ip address.

If you have Dot enabled then that starts after DNSMasq, but in order to work DNSMasq has to restart.

There are probably more services which are connected to DNSMasq and trigger restarts.

Maybe my example is not exactly true but you get the meaning.

Not saying all restarts are necessary though

_________________
Routers:Netgear R7800, R6400v1, R6400v2, Linksys EA8500, EA6900 (XvortexCFE), E2000 (converted WRT320N), WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 9585
Location: Netherlands

PostPosted: Sat May 14, 2022 10:46    Post subject: Reply with quote
kernel-panic69 wrote:
SFE recycles every NTP sync; there are probably others that do as well. This is why I only sync NTP once per 24 hours. Less log spam Wink Cool


Access rules
WireGuard
OpenVPN
Firewall

All trigger reset of SFE

_________________
Routers:Netgear R7800, R6400v1, R6400v2, Linksys EA8500, EA6900 (XvortexCFE), E2000 (converted WRT320N), WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
kernel-panic69
DD-WRT Guru


Joined: 08 May 2018
Posts: 12419
Location: Texas, USA

PostPosted: Sat May 14, 2022 11:01    Post subject: Reply with quote
Udhcpc gets WAN IP which DNSMasq and NTP rely on to work... for IPv4...
_________________
Official Forum Rules, Guidelines & Helpful InformationFirmware FAQInstallation WikiWhere Do I Download Firmware‽
DON'T use Chromium-based browsersRTFM/STFW TL;DR is NOT an excuse. • Why Should I Care What Color the Bikeshed Is‽
Please DO NOT PM me with questions; Ask in the forum. ---------------------- Linux User #377467 counter.li.org / linuxcounter.net
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 9585
Location: Netherlands

PostPosted: Sat May 14, 2022 11:23    Post subject: Reply with quote
kernel-panic69 wrote:
Udhcpc gets WAN IP which DNSMasq and NTP rely on to work... for IPv4...


That is why I wrote:
Quote:
Maybe my example is not exactly true but you get the meaning.

_________________
Routers:Netgear R7800, R6400v1, R6400v2, Linksys EA8500, EA6900 (XvortexCFE), E2000 (converted WRT320N), WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 986
Location: Hung Hom, Hong Kong

PostPosted: Sat May 14, 2022 12:19    Post subject: Re: USB script executed during sysinit... how many times? Reply with quote
mwchang wrote:

It seemed that my check [[ "$xx" > "1" ]] failed despite that there were indeed multiple entries of '{.rc_usb}' in the process list...

This was the USB script:
Code:

xx=`ps | grep '{.rc_usb}' | grep -v grep | wc -l`
if [[ "$xx" > "1" ]] ; then
   logger "changmw: .rc_usb already started($xx)"
   exit 1
fi


My bad, I needed to use "-gt" instead of ">". Anyway, I now use a pid file to do the instance check. Counting the number of "rc_usb" in the process list to detect multiple instances of rc_usb isn't reliable....

Code:
pidfile=/tmp/var/run/rc_usb.pid
if [[ -f $pidfile ]] ; then
   logger "changmw: .rc_usb already started"
   exit 1
fi
touch $pidfile
....
rm -f $pidfile

logger "$i: changmw exiting .rc_usb


It would be great if DD-WRT's Busybox could enable the "flock" command. Then we could use file locking to avoid multiple instancecs of a certain process.


_________________
Router: Asus RT-N18U (rev. A1)

May the Force and farces be with you! Live long and prosper!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
Goto page 1, 2  Next Display posts from previous:    Page 1 of 2
Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Broadcom SoC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum