Skip to content
Advertisement

mount fails from spawned process

I want to start a process that uses a USB hard drive once it gets inserted.
Since UDEV rules specifically mentions not to run long-time processes from RUN command, I send a FIFO message to my service which then opens the relevant process.

So the flow goes like this:
UDEV > runs action process > sends FIFO message to service > service gets message > runs the process who works with the HDD (aka HDD-PROCESS).

If I run my service from shell-1 and run ‘action process’ (the one that UDEV runs) from shell-2 everything works (including when trying it with udev).
But in deployment, the service is spawned from init, and when it does, the mount command fails saying “No such device”.

I then detached “HDD-PROCESS” with fork and setsid, but that didn’t help either.

from inittab:

::respawn:/opt/spwn_frm_init

ps relevant output:

PID    PPID  PGID  SID  COMM             ARGS
31112     1 31112 31112 spwn_frm_init    /bin/sh /opt/spwn_frm_init
31113 31112 31112 31112 runSvc           /bin/sh /app/sys/runSvc
31114 31113 31112 31112 python           python /app/sys/mainSvc.py
24064     1 24064 24064 python           /usr/bin/python /app/sys/hdd_proc.py sdb1
  • everything runs under root (ps shows that too, I omitted that to save screen space).

So in short: when I run /opt/spwn_frm_init from shell, everything works. when I kill it and let it re-spawn from inittab, it doesn’t and mount fails with error above.

UPDATE:
There is no problem when trying to mount an ext3 drive, but only on the NTFS one (using ntfs-3g).

Advertisement

Answer

Found it!
One of the differences between spawned process and another one who runs from shell is the environment variables which usually should be a problem when all I want is to call mount.
But when I noticed the problem happens only with the NTFS drive, it suddenly occurred to me that mount might need to call ntfs-3g so it worth checking if the second is accessible in the PATH variable.

which ntfs-3g led to /usr/local/bin/ntfs-3g which was mentioned in the default shell PATH but not in the one spawned from init.

To solve it, I added this /usr/local/bin to PATH in the “HDD-PROCESS” and mount began to work 🙂

A better error message in mount could have saved a lot of time here…

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement