Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Freezing on non-systemd GNU/Linux distributions when activated by udev #210

Open
BalkanMadman opened this issue Feb 21, 2023 · 3 comments
Open

Comments

@BalkanMadman
Copy link
Contributor

BalkanMadman commented Feb 21, 2023

Gentoo GNU/Linux. I suppose it is because of some kind of data race when it gets executed twice in a very short amount of time. Relevant code snippet from udev rule:

# Initialize iOS devices into "deactivated" USB configuration state and activate usbmuxd
SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{PRODUCT}=="5ac/12[9a][0-9a-f]/*|5ac/8600/*", ACTION=="add", ENV{USBMUX_SUPPORTED}="1", ATTR{bConfigurationValue}="0", OWNER="usbmux", RUN+="/usr/sbin/usbmuxd --user usbmux --udev"

# Make sure properties don't get lost when bind action is called
SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{PRODUCT}=="5ac/12[9a][0-9a-f]/*|5ac/8600/*", ACTION=="bind", ENV{USBMUX_SUPPORTED}="1", OWNER="usbmux", RUN+="/usr/sbin/usbmuxd --user usbmux --udev"

The latter follows the former almost immediately, causing some kind of a data race (I guess).

Got it working by applying the next fix (simply removed the run part when device is added):

--- /lib/udev/rules.d/39-usbmuxd.rules	2023-01-22 00:01:59.127987197 +0200
+++ /etc/udev/rules.d/39-usbmuxd.rules	2023-01-27 11:51:07.222984812 +0200
@@ -4,7 +4,7 @@
 SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{PRODUCT}=="5ac/12[9a][0-9a-f]/*|5ac/8600/*", TAG+="systemd"

 # Initialize iOS devices into "deactivated" USB configuration state and activate usbmuxd
-SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{PRODUCT}=="5ac/12[9a][0-9a-f]/*|5ac/8600/*", ACTION=="add", ENV{USBMUX_SUPPORTED}="1", ATTR{bConfigurationValue}="0", OWNER="usbmux", RUN+="/usr/sbin/usbmuxd --user usbmux --udev"
+SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{PRODUCT}=="5ac/12[9a][0-9a-f]/*|5ac/8600/*", ACTION=="add", ENV{USBMUX_SUPPORTED}="1", ATTR{bConfigurationValue}="0", OWNER="usbmux"

 # Make sure properties don't get lost when bind action is called
 SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{PRODUCT}=="5ac/12[9a][0-9a-f]/*|5ac/8600/*", ACTION=="bind", ENV{USBMUX_SUPPORTED}="1", OWNER="usbmux", RUN+="/usr/sbin/usbmuxd --user usbmux --udev"
@BalkanMadman BalkanMadman changed the title Freezes on non-systemd GNU/Linux distributions when activated by udev Freezing on non-systemd GNU/Linux distributions when activated by udev Feb 21, 2023
@BalkanMadman
Copy link
Contributor Author

BalkanMadman commented Feb 21, 2023

Fixed in e55e6e7

@BalkanMadman
Copy link
Contributor Author

It turns out the commit e55e6e7 didn't actually fix the problem.

I investigated this a bit further and found that the problem may be in one of the functions in https://github.com/libimobiledevice/usbmuxd/blob/master/src/usb.c. I don't remember which one exactly; the corresponding logs will be attached later.
So, there are two issues with the current handling of udev activation:

  1. usbmuxd is a daemon — a long living process — and udev manpage especially discourages starting daemons with RUN attribute (this is what is done on non-systemd builds). Being unconditionally killed may be the reason why it freezes.
  2. The actual reason behind freezing lies somewhere in usbmuxd code, i.e. there is a bug.

To deal with 1. we need to provide the actual OpenRC service file and implement udev activation via it. I've already done, so wait for the draft PR shortly after the publication of this comment.
The other part of the issue needs to be traced down though.

@BalkanMadman BalkanMadman reopened this Aug 29, 2023
@BalkanMadman
Copy link
Contributor Author

The issue on the Gentoo bugzilla: https://bugs.gentoo.org/show_bug.cgi?id=910706

BalkanMadman added a commit to BalkanMadman/usbmuxd that referenced this issue Aug 29, 2023
This commit adds a service script for an OpenRC init system.
It intends to mitigate "race" caused by a start of long-living process
(that is `usbmuxd` itself) by udev rules, which is highly discouraged by
the `udev` manpage:
"Starting daemons or other long-running processes is not allowed; the
forked processes, detached or not, will be unconditionally killed after
the event handling has finished."
There is a bug in `usbmuxd`, which causes the hang, but this is to be
handled in a different commit.

This adds two new `configure` flags:
* `--with-openrc`: toggles on or off (default - off) OpenRC service
  installation and udev activation via that. Conflicts with systemd, so
  the latter must be disabled explicitly:
  `--with-openrc --without-systemd`
* `--with-rcservicedir=DIR`: specifies directory where to install service
  file. Defaults to `$sysconfdir/init.d` (which is `/etc/init.d`)

Issue: libimobiledevice#210
Signed-off-by: BalkanMadman <[email protected]>
BalkanMadman added a commit to BalkanMadman/usbmuxd that referenced this issue Aug 29, 2023
This commit adds a service script for an OpenRC init system.
It intends to mitigate "race" caused by a start of long-living process
(that is `usbmuxd` itself) by udev rules, which is highly discouraged by
the `udev` manpage:
"Starting daemons or other long-running processes is not allowed; the
forked processes, detached or not, will be unconditionally killed after
the event handling has finished."
There is a bug in `usbmuxd`, which causes the hang, but this is to be
handled in a different commit.

This adds two new `configure` flags:
* `--with-openrc`: toggles on or off (default - off) OpenRC service
  installation and udev activation via that. Conflicts with systemd, so
  the latter must be disabled explicitly:
  `--with-openrc --without-systemd`
* `--with-rcservicedir=DIR`: specifies directory where to install service
  file. Defaults to `$sysconfdir/init.d` (which is `/etc/init.d`)

Issue: libimobiledevice#210
Signed-off-by: BalkanMadman <[email protected]>
BalkanMadman added a commit to BalkanMadman/usbmuxd that referenced this issue Jan 16, 2024
This commit adds a service script for an OpenRC init system.
It intends to mitigate "race" caused by a start of long-living process
(that is `usbmuxd` itself) by udev rules, which is highly discouraged by
the `udev` manpage:
"Starting daemons or other long-running processes is not allowed; the
forked processes, detached or not, will be unconditionally killed after
the event handling has finished."
There is a bug in `usbmuxd`, which causes the hang, but this is to be
handled in a different commit.

This adds two new `configure` flags:
* `--with-openrc`: toggles on or off (default - off) OpenRC service
  installation and udev activation via that. Conflicts with systemd, so
  the latter must be disabled explicitly:
  `--with-openrc --without-systemd`
* `--with-rcservicedir=DIR`: specifies directory where to install service
  file. Defaults to `$sysconfdir/init.d` (which is `/etc/init.d`)

Issue: libimobiledevice#210
Signed-off-by: BalkanMadman <[email protected]>
BalkanMadman added a commit to BalkanMadman/usbmuxd that referenced this issue Jan 16, 2024
This commit adds a service script for an OpenRC init system.
It intends to mitigate "race" caused by a start of long-living process
(that is `usbmuxd` itself) by udev rules, which is highly discouraged by
the `udev` manpage:
"Starting daemons or other long-running processes is not allowed; the
forked processes, detached or not, will be unconditionally killed after
the event handling has finished."
There is a bug in `usbmuxd`, which causes the hang, but this is to be
handled in a different commit.

This adds two new `configure` flags:
* `--with-openrc`: toggles on or off (default - off) OpenRC service
  installation and udev activation via that. Conflicts with systemd, so
  the latter must be disabled explicitly:
  `--with-openrc --without-systemd`
* `--with-rcservicedir=DIR`: specifies directory where to install service
  file. Defaults to `$sysconfdir/init.d` (which is `/etc/init.d`)

Issue: libimobiledevice#210
Signed-off-by: BalkanMadman <[email protected]>
BalkanMadman added a commit to BalkanMadman/usbmuxd that referenced this issue Jan 16, 2024
This commit adds a service script for an OpenRC init system.
It intends to mitigate "race" caused by a start of long-living process
(that is `usbmuxd` itself) by udev rules, which is highly discouraged by
the `udev` manpage:
"Starting daemons or other long-running processes is not allowed; the
forked processes, detached or not, will be unconditionally killed after
the event handling has finished."
There is a bug in `usbmuxd`, which causes the hang, but this is to be
handled in a different commit.

This adds two new `configure` flags:
* `--with-openrc`: toggles on or off (default - off) OpenRC service
  installation and udev activation via that. Conflicts with systemd, so
  the latter must be disabled explicitly:
  `--with-openrc --without-systemd`
* `--with-rcservicedir=DIR`: specifies directory where to install service
  file. Defaults to `$sysconfdir/init.d` (which is `/etc/init.d`)

Issue: libimobiledevice#210
Signed-off-by: BalkanMadman <[email protected]>
BalkanMadman added a commit to BalkanMadman/usbmuxd that referenced this issue Jan 16, 2024
This commit adds a service script for an OpenRC init system.
It intends to mitigate a "race" caused by a start of long-living process
(that is `usbmuxd` itself) by udev rules, which is highly discouraged by
the `udev` manpage:
"Starting daemons or other long-running processes is not allowed; the
forked processes, detached or not, will be unconditionally killed after
the event handling has finished."
There is a bug in `usbmuxd`, which causes the hang, but this is to be
handled in a different commit.

This adds two new `configure` flags:
* `--with-openrc`: toggles on or off (default - off) OpenRC service
  installation and udev activation via that. Conflicts with systemd, so
  the latter must be disabled explicitly:
  `--with-openrc --without-systemd`
* `--with-rcservicedir=DIR`: specifies directory where to install service
  file. Defaults to `$sysconfdir/init.d` (which is `/etc/init.d`)

Issue: libimobiledevice#210
Signed-off-by: BalkanMadman <[email protected]>
BalkanMadman added a commit to BalkanMadman/usbmuxd that referenced this issue May 4, 2024
This commit adds a service script for an OpenRC init system.
It intends to conform more closely to the way services are started by
udev.
usbmuxd detaches and daemonises itself correctly, yet the fact that its
execution skips an init system results in a rather low level of
integration with the running system.

This adds two new `configure` flags:
* `--with-openrc`: toggles on or off (default - off) OpenRC service
  installation and udev activation via that. Conflicts with systemd, so
  the latter must be disabled explicitly:
  `--with-openrc --without-systemd`
* `--with-rcservicedir=DIR`: specifies directory where to install service
  file. Defaults to `$sysconfdir/init.d` (which is `/etc/init.d`)

Issue: libimobiledevice#210
Signed-off-by: BalkanMadman <[email protected]>
BalkanMadman added a commit to BalkanMadman/usbmuxd that referenced this issue May 5, 2024
This commit adds a usbmuxd service script for the OpenRC init system.
It intends to conform more closely to the way services are started by
udev. Previously, on non-systemd systems, udev would start the `usbmuxd`
binary directly. This commits makes udev start `usbmuxd` in a much
cleaner way, by using the OpenRC service manager.

This adds two new `configure` flags:
* `--with-openrc`: toggles on or off (default - off) OpenRC service
  installation and udev activation via that. Conflicts with systemd, so
  the latter must be disabled explicitly:
  `--with-openrc --without-systemd`
* `--with-rcservicedir=DIR`: specifies directory where to install service
  file. Defaults to `$sysconfdir/init.d` (which is `/etc/init.d`)

Issue: libimobiledevice#210
Signed-off-by: BalkanMadman <[email protected]>
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 a pull request may close this issue.

1 participant