Posts: 13
Joined: Wed Apr 06, 2016 11:48 am

udev rule not working on Raspain Jessie (mochad)

Wed Apr 06, 2016 2:58 pm


I am using Mochad ( ) on my Rpi1 with Raspbian Jessie. This programs runs when a USB compliant device is connected using a udev rule.

The content of the udev rule is as follows:

Code: Select all

SUBSYSTEM=="usb", ATTR{idVendor}=="0bc7", ATTR{idProduct}=="0001", RUN+="/usr/local/bin/mochad"
SUBSYSTEM=="usb", ATTR{idVendor}=="0bc7", ATTR{idProduct}=="0002", RUN+="/usr/local/bin/mochad"
The point is that the program runs when the USB is plugged in but suddenly stops. If I run the program (sudo /usr/local/bin/mochad) manually it works.

The program worked fine in Debian Wheezy.

Several users have contacted the programmer with no luck, me as well: ... 8f39/#5d3c

Any clues?

Posts: 13
Joined: Wed Apr 06, 2016 11:48 am

Re: udev rule not working on Raspain Jessie (mochad)

Thu Apr 07, 2016 1:28 pm

I think I found the problem: The process started by the udev rule in fact acts as a server (opens a socket and keeps listening) so it keeps opened as a daemon (the source code calls the daemon() C++ function which does a "fork") and the udev manual says: ... %7Btype%7D

Code: Select all

This can only be used for very short-running foreground tasks. Running an event process for a long period of time may block all further events for this or a dependent device.

Starting daemons or other long-running processes is not appropriate for udev; the forked processes, detached or not, will be unconditionally killed after the event handling has finished.
So it seems that the program gets killed. What I do not know is why this was working on the previous Debian (Debian Wheezy), maybe this was changed in the Jessie release?

Any advise on how to solve this?

User avatar
Posts: 4543
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: udev rule not working on Raspain Jessie (mochad)

Thu Apr 07, 2016 2:48 pm

Have udev run a short script that launches the service in the background, perhaps with the '&'.

Posts: 1
Joined: Sun May 01, 2016 8:15 pm

Re: udev rule not working on Raspain Jessie (mochad)

Sun May 01, 2016 8:51 pm

You have hit the nail on the head. Most of the fix is on the SourceForge Mochad site. Its under General Discussions.
There is a down load from Patrick with the source. (Very good job Patrick)

There are still a few problems with Raspain Jessie though.
You will need to install libmtp-runtime (or at least I did) in addition to the other USB libraries.
sudo apt-get install libusb-dev libusb-1.0-0-dev libmtp-runtime

Then you need to add an /etc/udev/rule.d file (Or modify the old one) so that that it does a RUN+="/bin/systemctl restart mochad" instead of running mochad directly. Patrick has you remove the rule, however without it you can't hot plug. His install script does not install the new version either so you will have to do that by hand.

Then remove the Restart=on-failure line in the mochad.service file. (Its in the systemd directory of the source) The restart takes a while and if you don't wait 30 seconds or so between disconnect and reconnect the reconnect will fail. Removing the Restart line (or making it a comment) allows quicker disconnects. There may be some issues with USB errors after removing this but I haven't seen any.

This works for me. I hope this helps.

Posts: 1
Joined: Tue Nov 01, 2016 2:49 am

Re: udev rule not working on Raspain Jessie (mochad)

Tue Nov 01, 2016 3:02 pm

The latest version of mochad (0.1.17, 2016-06-10) now works with Raspbian Jessie.

Unfortunately, as of 1 November 2016, SourceForge still sends version 0.1.16 when you click on the big green Download button or if you follow the instructions at ... ry-pi.html to install mochad.

You can follow the instructions at x10linux.blogspot. Instead of

Code: Select all

$ wget -O mochad.tgz
use the command

Code: Select all

$ wget -O mochad.tgz 
to download the newest version of mochad.

Of course this change will not be necessary once SourceForge serves the latest version of mochad.

By the way, I needed to reboot after a successful installation of mochad. Perhaps it was necessary to reload the udev rules ?

Return to “Raspbian”