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

provide more info on usb device, deal w/ stale lockfiles on ubuntu 18.04 #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions my-udev-notify.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ DIR="$(dirname $(readlink -f "$0"))"

# file for storing list of currently plugged devices
devlist_file="/var/tmp/udev-notify-devices"
devlist_lock="/var/lock/.udev-notify-devices.exclusivelock"

show_notifications=true
notification_icons=true
Expand Down Expand Up @@ -229,8 +230,9 @@ notify_unplugged()

{
# we need for lock our $devlist_file
exec 200>/var/lock/.udev-notify-devices.exclusivelock
flock -x -w 10 200 || exit 1
exec 200>$devlist_lock
#flock --verbose -x -w 10 200 || exit 1
flock -x -w 10 200 || rm $devlist_lock
case $action in

"reboot" )
Expand All @@ -249,8 +251,9 @@ notify_unplugged()
# Retrieve device title. Currently it's done just by lsusb and grep.
# Not so good: if one day lsusb change its output format, this script
# might stop working.
dev_title=`lsusb -D /dev/bus/usb/$bus_num/$dev_num | grep '^Device:\|bInterfaceClass\|bInterfaceSubClass\|bInterfaceProtocol'|sed 's/^\s*\([a-zA-Z]\+\):*\s*[0-9]*\s*/<b>\1:<\/b> /' | awk 1 ORS='###'`
dev_title=`lsusb -D /dev/bus/usb/$bus_num/$dev_num | grep '^Device:\|iProduct\|bInterfaceClass\|bInterfaceSubClass\|bInterfaceProtocol'|sed 's/^\s*\([a-zA-Z]\+\):*\s*[0-9]*\s*/<b>\1:<\/b> /' | awk 1 ORS='###'`
dev_name=`lsusb -D /dev/bus/usb/$bus_num/$dev_num | grep idProduct | tr -s ' ' | cut -s -d' ' -f4,5,6,7,8,9`
[ -z $dev_name ] && dev_name=`lsusb -D /dev/bus/usb/$bus_num/$dev_num | grep iProduct | tr -s ' ' | cut -s -d' ' -f4,5,6,7,8,9`

# Sometimes we might have the same device attached to different bus_num or dev_num:
# in this case, we just modify bus_num and dev_num to the current ones.
Expand Down Expand Up @@ -300,6 +303,7 @@ notify_unplugged()

#unlock $devlist_file
flock -u 200
rm $devlist_lock
}


Expand Down