Closed dnisyd closed 7 years ago
When you dock or undock, are the udev
rules running? To check this, run sudo journalctl -f
and then dock/undock your laptop. If the udev
rules are running, you should see lines similar to this:
Feb 24 15:08:05 mars thinkpad-dock[30409]: Event caught: off
Ideally, udev
is detecting both docking and undocking, but I suspect that it's running the undocking rule for both docking and undocking (since /sys/devices/platform/dock.*/docked
is always 0
for you). If that's the case, then it would be fairly simple to modify the hooks to take advantage of the new lsusb
-based state detection introduced in v4.9.0.
If no udev
rules are getting called, then we'll need to use ACPI events instead. This is more work to integrate into thinkpad-scripts
because we'll have to make sure udev
and acpid
don't double-count events.
Looking at 81-thinkpad-dock.rules
, there is
KERNEL=="dock.*", ATTR{type}=="dock_station", ATTR{docked}=="1", RUN+="/usr/bin/thinkpad-dock-hook on"
Assuming that the udev
stuff works, we probably can just remove the on
in the RUN
part. Then thinkpad-dock
would figure out the action to take from the user process. We will have to change thinkpad-dock-hook
such that the argument becomes optional, though.
There should be no harm at all: For platforms where the sysfs works correctly, it will deduce the on
state. For other platforms, it will use lsusb
.
But first we need to know whether the udev
events got triggered.
So I just ran sudo journalctl -f
undocking (snippet, only the relevant):
Feb 26 17:27:23 ThinkPad-X220T thinkpad-dock[10185]: Event caught: off
Feb 26 17:27:23 ThinkPad-X220T kernel: ACPI: \_SB_.GDCK: undocking
Feb 26 17:27:23 ThinkPad-X220T kernel: thinkpad_acpi: undocked from hotplug port replicator
docking (snippet, maybe something relevant):
Feb 26 17:30:34 ThinkPad-X220T kernel: thinkpad_acpi: docked into hotplug port replicator
Feb 26 17:30:34 ThinkPad-X220T kernel: usb 1-1.5: new high-speed USB device number 6 using ehci-pci
Feb 26 17:30:34 ThinkPad-X220T kernel: usb 1-1.5: New USB device found, idVendor=17ef, idProduct=100a
Feb 26 17:30:34 ThinkPad-X220T kernel: usb 1-1.5: New USB device strings: Mfr=0, Product=0, SerialNumber=0
Feb 26 17:30:34 ThinkPad-X220T kernel: hub 1-1.5:1.0: USB hub found
Feb 26 17:30:34 ThinkPad-X220T kernel: hub 1-1.5:1.0: 6 ports detected
Feb 26 17:30:36 ThinkPad-X220T kernel: thinkpad_acpi: EC reports that Thermal Table has changed
But while docking there is no "Event caught: on" from thinkpad-dock
, if that ever happens.
I could attach the full logs but I think just the snippets should be enough for your needs?
@jturner314: Shall we ask @dantempla to test the changes from the development version or is it safe enough to release a new Ubuntu package with your changes?
@dantempla: Would you be willing to test the current git devel
branch in case we won't want to package @jturner314's changes yet?
@martin-ueding: It should be safe to release a new version with my changes, although it would be nice if @dantempla can confirm that they fix his problem before doing so. The only possible backwards incompatibilities are those I mentioned in my PR (which I don't think will cause any problems). However, please at least test it on your machine before releasing it.
@dantempla: When testing with the develop
branch (or the master
branch if Martin creates a new release), add the following to your config (~/.config/thinkpad-scripts/config.ini
) to use the new ACPI hooks instead of the default udev rules (which aren't working for you):
[trigger]
dock_triggers = acpi1_on acpi1_off
Okay, I did the following and I am sure I might have done something wrong.
sudo apt purge thinkpad-scripts
.git clone https://github.com/martin-ueding/thinkpad-scripts.git
.sudo ./setup.py install
[trigger]
dock_triggers = acpi1_on acpi1_off
and deleted the old lines enable_dock = true
and enable_rotate = true
sudo journalctl -f
:
Mär 13 17:42:12 ThinkPad-X220T kernel: ACPI: \_SB_.GDCK: undocking
Mär 13 17:42:12 ThinkPad-X220T thinkpad-dock[3507]: Event caught: off
Mär 13 17:42:12 ThinkPad-X220T systemd-udevd[3509]: failed to execute '/usr/bin/thinkpad-dock-hook' '/usr/bin/thinkpad-dock-hook off': No such file or directory
Mär 13 17:42:12 ThinkPad-X220T systemd-udevd[3505]: Process '/usr/bin/thinkpad-dock-hook off' failed with exit code 2.
Mär 13 17:42:12 ThinkPad-X220T kernel: thinkpad_acpi: undocked from hotplug port replicator
And there is still no Event caught: on
for thinkpad-dock
.
I think I made a huge mistake just now so I tried git clone https://github.com/martin-ueding/thinkpad-scripts.git --branch develop
as well. Looks the same. But I guess I made some mistake somewhere ...
@dantempla Sorry, I should have provided more instructions. I think you just missed the make
, sudo make install
, and udevadm hwdb --update
steps. (sudo ./setup.py install
doesn't handle the full installation.) See the docs for the manual installation instructions.
Here they are step-by-step, including cloning the repo. (Note that you may need to install a couple of dependencies for the make
call to work.)
git clone https://github.com/martin-ueding/thinkpad-scripts.git
cd thinkpad-scripts
git checkout develop
make
sudo make install
sudo ./setup.py install
sudo systemctl restart acpid
sudo udevadm hwdb --update
or you could use the full-install
rule (which is a few less commands):
git clone https://github.com/martin-ueding/thinkpad-scripts.git
cd thinkpad-scripts
git checkout develop
make
sudo make full-install
It might also be a good idea to reboot your computer, although that's probably not necessary.
@jturner314 Thanks and sorry! I am still learning. 😃
So, I just redid everything from scratch and I still get the same output in sudo journalctl -f
I posted above.
I had to install python3-sphinx
to get make
to work. I am still unsure everything installs the right way, so I will add my output as an attachment.
output.txt
@dantempla Based on the output.txt
you posted, it looks like setuptools installed the entry points to /usr/local/bin
instead of /usr/bin
. This is probably an Ubuntu thing, and it's not something I've seen (since I'm testing on Arch Linux). First, go ahead and remove the files added to /usr/local/bin
by calling sudo pip uninstall thinkpad-scripts
. (The remaining files (ACPI hooks, udev rules, etc.) will be overwritten when you install another version of thinkpad-scripts
.) We'll need to figure out a way to install the entry points to /usr/bin
or just release a new version of thinkpad-scripts
.
@martin-ueding Do you have experience with this? My guess would be to use the --root
or --exec-prefix
option to ./setup.py install
. Alternatively, would you like to just go ahead and release a new version? That'll allow @dantempla to install the PPA package instead of figuring out the manual install process, and even if the new version doesn't fix @dantempla's problem (although I think it will), it'll make the fix simpler.
One needs to call ./setup.py
with the right --prefix
option. The --root
is only needed when building packages. For Fedora, I call it like this:
/usr/bin/python3 setup.py install --prefix=%{_prefix} --root=%{buildroot}
For Debian I use the following:
override_dh_auto_install:
./setup.py install \
--force --root="$(mydestdir)" \
--no-compile -O0 --install-layout=deb
make install DESTDIR="$(mydestdir)"
So for Debian/Ubuntu, I think that --install-layout=deb
would be the right parameter.
Thanks, @martin-ueding. On Arch Linux, ./setup.py
doesn't have an --install-layout
option (maybe it's a Debian/Ubuntu addition?), but I was able to use the --prefix
option.
@dantempla After removing the files added to /usr/local/bin
by calling sudo pip uninstall thinkpad-scripts
, try installing with:
git clone https://github.com/martin-ueding/thinkpad-scripts.git
cd thinkpad-scripts
git checkout develop
make
sudo make install
sudo ./setup.py install --install-layout=deb
sudo systemctl restart acpid
sudo udevadm hwdb --update
If the --install-layout=deb
option gives an error when calling ./setup.py
, try using the --prefix
option instead, like this:
sudo ./setup.py install --prefix=/usr
@jturner314 Okay, it works now!
I removed the files from /usr/local/bin
with rm -f thinkpad-*
and followed your instructions. No errors and --install-layout=deb
worked fine for me on Ubuntu 16.04.
Let me copy paste some interesting lines of sudo journalctl -f
:
Hardwarebutton undock:
Mär 17 05:55:14 ThinkPad-X220T sudo[3761]: root : TTY=unknown ; PWD=/ ; USER=dantempla ; COMMAND=/bin/bash -c env DISPLAY=:0.0 /usr/bin/thinkpad-dock off --via-hook acpi1_off
Mär 17 05:55:14 ThinkPad-X220T sudo[3761]: pam_unix(sudo:session): session opened for user dantempla by (uid=0)
Mär 17 05:55:14 ThinkPad-X220T systemd-udevd[3684]: Process '/usr/bin/thinkpad-dock-hook off' failed with exit code 2.
Device docked:
Mär 17 05:56:59 ThinkPad-X220T kernel: thinkpad_acpi: docked into hotplug port replicator
Mär 17 05:57:01 ThinkPad-X220T thinkpad-scripts[3926]: tps.dock WARNING unable to restart ethernet connection
Mär 17 05:57:01 ThinkPad-X220T sudo[3925]: pam_unix(sudo:session): session closed for user dantempla
Mär 17 05:57:02 ThinkPad-X220T sudo[4106]: root : TTY=unknown ; PWD=/ ; USER=dantempla ; COMMAND=/bin/bash -c env DISPLAY=:0.0 /usr/bin/thinkpad-dock --via-hook acpi2
Mär 17 05:57:02 ThinkPad-X220T sudo[4106]: pam_unix(sudo:session): session opened for user dantempla by (uid=0)
Mär 17 05:57:02 ThinkPad-X220T sudo[4106]: pam_unix(sudo:session): session closed for user dantempla
One thing that does not work is the following:
ThinkPad turned off on docking station, turning it on and boot up. After login prompt Ubuntu messes with screens and duplicates internal screen on external screen in a horrible resolution. Wireless still activated and so on means that my device does not recognize being docked. I can easily just do thinkpad-dock on|off
, I just wanted to let you guys now. Maybe that is not the same behaviour you expected.
When you boot it on the docking station, nothing is expected to happen out of the box. You need to call thinkpad-dock (no argument) in the Autostart. Then it will figure out the current state and fix everything.
I am not sure, but I think we cannot offer this automatically. There are many different ways for Autostart, and perhaps not every user on the system wants to have it at startup.
Pressing the hardware eject button does strange things for me as well, I assume that the hardware rapidly disconnects the peripherals. Then our script cannot find anything any more and crashes. -- http://martin-ueding.de/#pk_campaign=Email
Sent from my mobile, please excuse my brevity.
@dantempla Okay, that's great! I'm glad it's working now. The error in the third line of your "Hardwarebutton undock" output looks like it would result from /lib/udev/rules.d/81-thinkpad-dock.rules
remaining from an older version of thinkpad-scripts
. This file should have been overwritten when you installed the develop
branch, but udev needs to be notified of the new rules. You should be able to do this with:
sudo udevadm trigger --action=change
or by restarting udev (I think the service name is systemd-udevd
), or by rebooting your computer. We should probably add this to the installation instructions.
By the way, you should check to make sure the old ACPI hooks aren't still lying around. Delete /etc/acpi/events/thinkpad-rotate-acpi-hook-1
and /etc/acpi/events/thinkpad-rotate-acpi-hook-2
(and then restart acpid
) if they still exist.
So it is working now? Can we close this issue then?
@jturner314 @martin-ueding Yes, it is working now! Thanks for your hard work. You can close the issue now.
Good, thanks for testing!
I will then include this in the next official release.
Hello again, I just installed the new version 4.9.0.0 via apt.
apt-cache policy thinkpad-scripts
shows that4.9.0.0ubuntu-1
is installed. Auto docking still seems not to work. You mentioned in #129 that I should check out hardware events when I dock|undock.acpi_listen
: When docked:acpi_listen
: When undocked (pushing the physical eject button on the docking station):