Skip to content

files: Fix service startup race condition with udev rules#311

Open
quic-vkatoch wants to merge 1 commit intoqualcomm:developmentfrom
quic-vkatoch:udev-rule
Open

files: Fix service startup race condition with udev rules#311
quic-vkatoch wants to merge 1 commit intoqualcomm:developmentfrom
quic-vkatoch:udev-rule

Conversation

@quic-vkatoch
Copy link
Contributor

@quic-vkatoch quic-vkatoch commented Mar 6, 2026

The After= clause has no effect on the race between WantedBy=multi-user.target and kernel module loading. If multi-user.target is reached before the kernel module loads, the daemon will never start.

Fix by using ENV{SYSTEMD_WANTS} in udev rules to trigger services when FastRPC devices are detected.

Changes:

  • Add 71-fastrpc.rules with device-triggered service startup
  • Remove [Install] sections from all service files
  • Update configure.ac to use pkg-config to query udevdir variable
  • Update files/Makefile.am to install udev rules

Services now start only when device nodes are created, eliminating the race condition.

Fixes: #309

@quic-vkatoch
Copy link
Contributor Author

@basak-qcom @lumag, could you please review this change?

Copy link

@basak-qcom basak-qcom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change itself looks good to me. Thanks! One comment inline on the autoconf change.

[udevrulesdir="$withval"],
[udevrulesdir="/lib/udev/rules.d"])
AC_MSG_NOTICE([udev rules directory: $udevrulesdir])
AC_SUBST([udevrulesdir])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use pkg-config instead, querying for the udevdir variable? On Debian, /usr/lib/udev/rules.d is used (due to usrmerge), and I'd prefer for that to be automatic rather than have to use this project-specific --with-udevrulesdir or have the fallback diversion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It says "Get udev directory from pkg-config" but doesn't seem to be?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So now the --with-udevrulesdir=DIR option is available, so if another distro wants to install the rules into a specific path, they can provide it explicitly. If we do not specify anything, the directory is taken from pkg-config. I just want to confirm that I am understanding this correctly.

Here is what I observe during Yocto compilation:

Image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@basak-qcom, can you please check once?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I missed your reply before.

I understand that --with-udevrulesdir=DIR is available. But what I mean is that regardless of what distro you're building on, it shouldn't be necessary to use this option because pkg-config --variable=udevdir udev should provide the correct per-distro directory to use, and then autoconf should use that one automatically. It's fine to have an override, but it should never be necessary to use this.

The After= clause has no effect on the race between WantedBy=multi-user.target
and kernel module loading. If multi-user.target is reached before the kernel
module loads, the daemon will never start.

Fix by using ENV{SYSTEMD_WANTS} in udev rules to trigger services when
FastRPC devices are detected.

Changes:
- Add 71-fastrpc.rules with device-triggered service startup
- Remove [Install] sections from all service files
- Update configure.ac to use pkg-config to query udevdir variable
- Update files/Makefile.am to install udev rules

Services now start only when device nodes are created, eliminating the
race condition.

Signed-off-by: Vinayak Katoch <vkatoch@qti.qualcomm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

systemd service definitions are flawed

2 participants