Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 565262 - sys-apps/usb_modeswitch - udev support needs RW temporary directory
Summary: sys-apps/usb_modeswitch - udev support needs RW temporary directory
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Rafael Martins (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-09 16:24 UTC by Maciej S. Szmigiero
Modified: 2017-02-03 21:48 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Maciej S. Szmigiero 2015-11-09 16:24:14 UTC
Sometimes, when system is started with USB modem that needs to be switched by usb_modeswitch 
plugged in it is not switched correctly.
This happens at least if USB host controller modules are loaded via /etc/conf.d/modules.

It turns out that usb_modeswitch udev support needs root mounted read-write, so if "modules" init script is started before "root" this results in following error in udevdebug.log:
creating symlink '/dev/char/189:513' to '../bus/usb/005/002'
created db file '/run/udev/data/c189:513' for '/devices/pci0000:00/0000:00:12.2/usb5/5-5'
starting 'usb_modeswitch '/5-5''
'usb_modeswitch '/5-5''(err) '/lib/udev/usb_modeswitch: line 77: cannot create temp file for here-document: Read-only file system'

And the USB modem isn't switched (so it does not work).

If usb_modeswitch logging is enabled in /etc/usb_modeswitch.conf it also complains that it cannot create log file:
'usb_modeswitch '/5-5''(err) 'couldn't write file "/var/log/usb_modeswitch_5-5": read-only file system'

Simplest solution is to let "modules" init script be ordered after "root" by adding "after root"
to /etc/init.d/modules.

After doing this the USB modem is switched correctly on every boot.


Reproducible: Always
Comment 1 Maciej S. Szmigiero 2016-09-09 18:00:43 UTC
> Simplest solution is to let "modules" init script be ordered after "root" by
> adding "after root" to /etc/init.d/modules.

In openrc-0.21+ /etc/init.d/modules-load needs similar treatment, too.

However, there is a problem that now fsck service will be run after root was
mounted RW (since it contains "use modules") and so will not check root
filesystem.

I think that fsck should be split into two services: one for checking root fs
(and without "use modules") and second one for checking remaining filesystems
(which can need some modules loaded so with "use modules").
Comment 2 Maciej S. Szmigiero 2016-12-15 16:02:24 UTC
> > Simplest solution is to let "modules" init script be ordered after "root" by
> > adding "after root" to /etc/init.d/modules.
> 
> In openrc-0.21+ /etc/init.d/modules-load needs similar treatment, too.
> 
> However, there is a problem that now fsck service will be run after root was
> mounted RW (since it contains "use modules") and so will not check root
> filesystem.
> 
> I think that fsck should be split into two services: one for checking root fs
> (and without "use modules") and second one for checking remaining filesystems
> (which can need some modules loaded so with "use modules").

It looks like there are even more init scripts with dependency on "root" init script being after "modules" that changing them all would amount to a significant work (not to mention a real possibility of breaking some use case).

Fortunately, what sys-apps/usb_modeswitch scripts really want is just a writable temporary directory:
it is needed (at least) for shell here-document in /lib/udev/usb_modeswitch and
for Tcl exec command used by /usr/sbin/usb_modeswitch_dispatcher.

This requirement can easily be satisfied on current OpenRC by setting TMPDIR to "/run" in /lib/udev/usb_modeswitch:
--- a/usb_modeswitch.sh 2016-11-29 17:29:47.000000000 +0100
+++ b/usb_modeswitch.sh 2016-11-30 01:11:51.747993839 +0100
@@ -17,6 +17,8 @@
        return 0
 }
 
+export TMPDIR=/run
+
 if [ $(expr "$1" : "--.*") ]; then
        p_id=$4
        if [ -z $p_id ]; then

This way USB modem switching on boot works properly without any changes to init
scripts (tested by me).
Comment 3 Maciej S. Szmigiero 2017-01-08 22:59:22 UTC
Created Github PR 3389 that includes a fix for this bug.
Comment 4 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2017-02-03 21:48:19 UTC
Need this to fix my laptop.

[master 2e2ceb7093] sys-apps/usb_modeswitch: udev scripts need RW temporary directory
 Author: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
 Date: Sun Jan 8 23:47:56 2017 +0100
 2 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 sys-apps/usb_modeswitch/files/usb_modeswitch.sh-tmpdir.patch
 rename sys-apps/usb_modeswitch/{usb_modeswitch-2.4.0.ebuild => usb_modeswitch-2.4.0-r1.ebuild} (94%)