Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 488068 - sys-power/apcupsd - Udev rule creates a non functioning device link.
Summary: sys-power/apcupsd - Udev rule creates a non functioning device link.
Status: UNCONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: AMD64 Linux
: Normal normal
Assignee: John Einar Reitan
URL:
Whiteboard:
Keywords: PATCH
Depends on:
Blocks:
 
Reported: 2013-10-14 21:10 UTC by Jon Gerdes
Modified: 2018-05-01 07:58 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
ebuild patch with return to original run directories (apcupsd-ebuild.patch,1.22 KB, patch)
2013-11-23 23:58 UTC, Billy DeVincentis
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jon Gerdes 2013-10-14 21:10:52 UTC
The udev rule created by the ebuild (/lib/udev/rules.d/60-apcupsd.rules) causes a nicely named symlink to appear. If I try to use that device apcupsd fails to start.  If I instead reference a generic link it does work. 



Reproducible: Always





It may be that the link is to a wrong major number device as far as apcupsd is concerned.  Note the link is to major = 189 but the working node has major 180.

This is the rule generated symlink:
rwxrwxrwx 1 root root 21 Oct 14 20:55 /dev/apcups/by-id/usb-4B1043P30894 -> ../../bus/usb/002/004

Which maps to:
crw-rw-r-- 1 root usb 189, 131 Oct 14 20:55 /dev/apcups/by-id/../../bus/usb/002/004

I can use this device in apcupsd.conf:
crw------- 1 root root 180, 96 Oct 14 20:55 /dev/usb/hiddev0

# lsusb
Bus 002 Device 004: ID 051d:0002 American Power Conversion Uninterruptible Power Supply
Bus 002 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub
Bus 002 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 002: ID 0572:6831 Conexant Systems (Rockwell), Inc. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub


Sample entry from apcupsd.events logfile:
013-10-12 17:11:01 +0100  apcupsd FATAL ERROR in linux-usb.c at line 605
Cannot open UPS device: "/dev/apcups/by-id/usb-4B1043P30894"
Comment 1 Sven Vermeulen (RETIRED) gentoo-dev 2013-10-27 17:42:10 UTC
I think this is for the apcupsd package itself, not for the SELinux policy (which does not create a udev rules file)? Reassigning to Matthew as apcupsd ebuild maintainer.
Comment 2 Matthew Marlowe (RETIRED) gentoo-dev 2013-10-28 05:25:31 UTC
I'm going to need more info to debug this.

Can you provide the output of emerge --info and also the specific use flags and ebuild that you built apcupsd from.  The version of udev you are using would also help.

On my test system:
hyperion ~ # ls -al /dev/apcups/by-id/usb-AS1225221068 
lrwxrwxrwx 1 root root 17 Oct 20 22:06 /dev/apcups/by-id/usb-AS1225221068 -> ../../usb/hiddev0

Furthermore, the udev rule says:
# do not edit this file, it will be overwritten on update

ACTION!="add", GOTO="apcupsd_end"
SUBSYSTEM!="usb", GOTO="apcupsd_end"
ENV{ID_VENDOR}=="", IMPORT{program}="usb_id --export %p"
ENV{ID_VENDOR_ID}!="051d", GOTO="apcupsd_end"

KERNEL=="?*", SYMLINK+="apcups/by-id/$env{ID_BUS}-$env{ID_SERIAL_SHORT}"

LABEL="apcupsd_end"

which indicates that there are no hardcoded values in the rule...they are gathered at runtime from usb_id and udev itself using the vendor_id search function.

Which ups model do you have and how is it connected?  Also, what kernel are you running?
Comment 3 Matthew Marlowe (RETIRED) gentoo-dev 2013-10-28 05:27:18 UTC
output of 'lsusb' would also help.
Comment 4 Jon Gerdes 2013-10-30 16:57:12 UTC
noddy ~ # emerge --info
Portage 2.2.7 (default/linux/amd64/13.0, gcc-4.7.3, glibc-2.17, 3.10.11-gentoo x86_64)
=================================================================
System uname: Linux-3.10.11-gentoo-x86_64-Intel-R-_Xeon-R-_CPU_E5-2407_0_@_2.20GHz-with-gentoo-2.2
KiB Mem:     6118688 total,     63988 free
KiB Swap:    2097148 total,   2096932 free
Timestamp of tree: Wed, 30 Oct 2013 13:30:01 +0000
ld GNU ld (GNU Binutils) 2.23.2
app-shells/bash:          4.2_p45
dev-lang/python:          2.7.5-r2, 3.2.5-r2, 3.3.2-r2
dev-util/cmake:           2.8.11.2
dev-util/pkgconfig:       0.28
sys-apps/baselayout:      2.2
sys-apps/openrc:          0.12.2
sys-apps/sandbox:         2.6-r1
sys-devel/autoconf:       2.69
sys-devel/automake:       1.11.6, 1.13.4, 1.14
sys-devel/binutils:       2.23.2
sys-devel/gcc:            4.7.3-r1
sys-devel/gcc-config:     1.8
sys-devel/libtool:        2.4.2
sys-devel/make:           3.82-r4
sys-kernel/linux-headers: 3.11 (virtual/os-headers)
sys-libs/glibc:           2.17
Repositories: gentoo x-portage
ACCEPT_KEYWORDS="amd64 ~amd64"
ACCEPT_LICENSE="*"
CBUILD="x86_64-pc-linux-gnu"                                                                                                                                                                                                     
CFLAGS="-O2 -march=native -pipe"                                                                                                                                                                                                 
CHOST="x86_64-pc-linux-gnu"                                                                                                                                                                                                      
CONFIG_PROTECT="/etc /usr/share/gnupg/qualified.txt"                                                                                                                                                                             
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/php/apache2-php5.5/ext-active/ /etc/php/cgi-php5.5/ext-active/ /etc/php/cli-php5.5/ext-active/ /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"                                                                                                                                                                                              
CXXFLAGS="-O2 -march=native -pipe"                                                                                                                                                                                               
DISTDIR="/usr/portage/distfiles"                                                                                                                                                                                                 
EMERGE_DEFAULT_OPTS="--quiet-build=n"                                                                                                                                                                                            
FCFLAGS="-O2 -pipe"                                                                                                                                                                                                              
FEATURES="assume-digests binpkg-logs config-protect-if-modified distlocks ebuild-locks fixlafiles merge-sync news parallel-fetch preserve-libs protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"                                                                                                                                                                             
FFLAGS="-O2 -pipe"                                                                                                                                                                                                               
GENTOO_MIRRORS="http://distfiles.gentoo.org"                                                                                                                                                                                     
LANG="en_GB.UTF-8"                                                                                                                                                                                                               
LDFLAGS="-Wl,-O1 -Wl,--as-needed"                                                                                                                                                                                                
MAKEOPTS="-j5"                                                                                                                                                                                                                   
PKGDIR="/usr/portage/packages"                                                                                                                                                                                                   
PORTAGE_CONFIGROOT="/"                                                                                                                                                                                                           
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages" 
PORTAGE_TMPDIR="/var/tmp"                                                                                                                                                                                                        
PORTDIR="/usr/portage"                                                                                                                                                                                                           
PORTDIR_OVERLAY="/usr/local/portage"                                                                                                                                                                                             
USE="acl admin ads amd64 apache2 augeas bash-completion berkdb bzip2 bzlib cgi clamdtop cli client cpdflib cracklib crypt curl cxx dba dbus dbx dlz dnsdb dri dv dvd dynamicplugin elf enscript etwin exiscan exiscan-acl fastcgi flexresp2 fortran ftp gd gdbm gif glep icap-client iconv idn imagemagick imap iproute2 ipv6 jpeg jpeg2k kerberos krb5 ldap linux-smp-stats logrotate maildir mime mmx mmx2 modules mp3 mp4 mpeg mpeg2 mudflap multilib multipath multiuser mysql ncurses nls nptl ogg openmp pam pcre pdf php pkcs11 png quotas react readline realms rle rrdcgi rrdtool samba server session slang snmp soap sockets spf srs sse sse2 sse3 sse4 sse4_1 ssl syslog tcpd timestats tools truetype underscores unicode winbind xattr zlib" ABI_X86="64" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" APACHE2_MODULES="actions alias auth_basic auth_digest authn_anon authn_dbd authn_dbm authn_default authn_file authnz_ldap authz_dbm authz_default authz_groupfile authz_host authz_owner \ authz_user autoindex cache cgi cgid dav dav_fs dav_lock dbd deflate dir disk_cache doc env expires ext_filter file_cache filter headers ident imagemap include info ldap log_config logio mem_cache mime mime_magic negotiation proxy proxy_ajp proxy_balancer proxy_connect proxy_http rewrite setenvif so speling ssl status suexec unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="kexi words flow plan sheets stage tables krita karbon braindump author" CAMERAS="ptp2" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ubx" GRUB_PLATFORMS="pc" INPUT_DEVICES="keyboard mouse evdev" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php5-5" PYTHON_SINGLE_TARGET="python2_7" PYTHON_TARGETS="python2_7 python3_2" RUBY_TARGETS="ruby19 ruby18" USERLAND="GNU" VIDEO_CARDS="vmware" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CPPFLAGS, CTARGET, INSTALL_MASK, LC_ALL, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, SYNC, USE_PYTHON
Comment 5 Jon Gerdes 2013-10-30 17:02:25 UTC
noddy ~ # lsusb
Bus 002 Device 004: ID 051d:0002 American Power Conversion Uninterruptible Power Supply
Bus 002 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub
Bus 002 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 002: ID 0572:6831 Conexant Systems (Rockwell), Inc. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Comment 6 Jon Gerdes 2013-10-30 17:03:25 UTC
I've just noticed a newer ebuild whilst doing this ...
Comment 7 Jon Gerdes 2013-10-30 17:16:24 UTC
noddy ~ # emerge -uva apcupsd

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild     U  ] sys-apps/util-linux-2.24 [2.23.2-r2] USE="bash-completion cramfs ncurses nls pam slang suid tty-helpers* unicode -caps -cytune -fdformat -python% (-selinux) -static-libs {-test} -udev (-old-linux%)" PYTHON_SINGLE_TARGET="python2_7%* -python3_2% -python3_3%" PYTHON_TARGETS="python2_7%* python3_2%* -python3_3%" 3,450 kB
[ebuild     U  ] sys-power/apcupsd-3.14.10-r5 [3.14.10-r2] USE="cgi nls usb -gnome -snmp -systemd%" 0 kB

Installed this and restarted using this in apcupsd.conf:
DEVICE /dev/apcups/by-id/usb-4B1043P30894

In /var/log/apcupsd.events:
013-10-30 17:09:47 +0000  apcupsd FATAL ERROR in linux-usb.c at line 605
Cannot open UPS device: "/dev/apcups/by-id/usb-4B1043P30894" --

Changing back to DEVICE /dev/usb/hiddev0

2013-10-30 17:14:52 +0000  apcupsd 3.14.10 (13 September 2011) gentoo startup succeeded
Comment 8 Jon Gerdes 2013-10-30 17:25:39 UTC
noddy ~ # uname -a
Linux noddy 3.10.11-gentoo #1 SMP Sat Oct 12 17:41:01 BST 2013 x86_64 Intel(R) Xeon(R) CPU E5-2407 0 @ 2.20GHz GenuineIntel GNU/Linux
Comment 9 Jon Gerdes 2013-10-30 17:30:22 UTC
This device does not work for me:
lrwxrwxrwx 1 root root 21 Oct 16 10:26 /dev/apcups/by-id/usb-4B1043P30894 -> ../../bus/usb/002/004
crw-rw-r-- 1 root usb 189, 131 Oct 16 10:26 /dev/bus/usb/002/004

This device does work:
crw------- 1 root root 180, 96 Oct 16 10:26 /dev/usb/hiddev0

Also, udev is version 208
Comment 10 Jon Gerdes 2013-10-30 18:11:34 UTC
It seems the problem is either the symlink is creating a link to the wrong type of device node or the udev rule is creating the wrong kind of node.

I don't know what the real difference between a device with major 189 is compared to one with 180 but the one with 180 works with apcupsd!  

According to /proc/devices: 

180 usb
189 usb_device

and I found this in dmesg at boot up:
hid-generic 0003:051D:0002.0003: hiddev0,hidraw2: USB HID v1.10 Device [American Power Conversion Back-UPS CS 650 FW:817.v7 .I USB FW:v7 ] on usb-0000:02:00.0-2.1/input0
Comment 11 Billy DeVincentis 2013-11-18 00:04:21 UTC
having same problem, r5 simply doesn't start up for me. For the life of me I don't know what the difference is that casuing this to fail
Comment 12 Billy DeVincentis 2013-11-23 16:06:25 UTC
I don't know why so many changes to the old ebuild were necessary. I have been working on this all morning and can't seem to get anywhere. r5 simply doesn't work and this in my opinion is much more than just a udev symlink issue.
Comment 13 Billy DeVincentis 2013-11-23 21:55:36 UTC
Okay, I have tracked down why the current ebuild is not working, at least for me but I am quite sure that this is the problem. Along with the new ebuild , run directories were changed and then updated in the new apcupsd.conf which is in the files directory and gets installed with the new ebuild. By changing
LOCKFILE /var/run/apcupsd

to

LOCKFILE /var/run

apcupsd now starts normal. Not sure of why but thats how I got it running
Comment 14 Billy DeVincentis 2013-11-23 23:16:00 UTC
Okay, here is the deal. The reason this can't work is because /var/run/apcupsd is not created and if it does get created by the ebuild, it get's erased on reboot so something has to be done to either create the directory on the startup of the service or return the original run directories
Comment 15 Billy DeVincentis 2013-11-23 23:58:17 UTC
Created attachment 363866 [details, diff]
ebuild patch with return to original run directories

This will return the ebuild to apcupsd's original run and lock directories, also this eliminates the need for a gentoo specific apcupsd.conf in the /etc/apcupsd directory since we are no longer modifying the standards directories
Comment 16 Matthew Marlowe (RETIRED) gentoo-dev 2013-11-24 04:48:50 UTC
apcupsd is installed and works perfectly fine here.

/var/run is really no longer supported in Gentoo - /run is replacing it, and for certain reasons..that means /run/apcupsd.  On many systems, /var/run should just be a legacy symlink to /run so some apps will still see /var/run/apcupsd.

It's possible we still need to update some init or config files to do the right thing - I thought I had got all references, but as I said - it tests and works perfectly here.

As for the udev rule changes, this is something the older maintainer of apcupsd put in place...I haven't had time yet to debug it.  It probably is just a simple matter to work though, I'll try to get to it shortly.
Comment 17 Billy DeVincentis 2013-11-29 00:36:01 UTC
Then you need to create the apcupsd.service file to create the apcupsd directory when it is started.
Comment 18 Billy DeVincentis 2013-11-29 17:04:41 UTC
Okay, after having done some research here (I'm new to this systemd thing LOL), it appears that we use a tmpfiles.d file to create needed directories so you can repair all of this with just a modified file


D /run/apcupsd 0755 root root
r /etc/apcupsd/powerfail
r /etc/nologin

 I added in 
D /run/apcupsd 0755 root root
and now it works
Comment 19 Matthew Marlowe (RETIRED) gentoo-dev 2013-11-30 02:48:16 UTC
(In reply to Billy DeVincentis from comment #18)
> Okay, after having done some research here (I'm new to this systemd thing
> LOL), it appears that we use a tmpfiles.d file to create needed directories
> so you can repair all of this with just a modified file
> 

OK, so you are using systemd.   Thanks for testing that.  Please open up a new bug with your patch and issue description as this is a completely separate issue from the udev rule. 

I'll see about having the systemd guys review and test the patch - I don't run systemd so I have to depend on user patches and systemd devs to verify.
Comment 20 Billy DeVincentis 2013-12-01 01:52:42 UTC
That's why you were not running into this problem. I will open new bug.
Comment 21 Billy DeVincentis 2013-12-01 01:58:24 UTC
https://bugs.gentoo.org/show_bug.cgi?id=492992
Comment 22 Matthew Marlowe (RETIRED) gentoo-dev 2013-12-03 20:09:18 UTC
jon - back to your bug/issue with usb/udev symlink.

What is confusing is that the apcupsd udev rule should just be running lsusb, searching for devices with the apc vendor tag, and then creating a symlink.

In your lsusb output, I see only one device with the apc vendor tag and that is the UPS.  Upon bootup, udev should be creating its own link for the ups in /dev/hid.

I'm not sure how/why the link is being made to /dev/apcups/by-id/../../bus/usb/002/004 instead of hiddev although technically they are the same device it appears since 2/4 is the usb controller/path to the UPS.

What is the kernel version and udev version of the box you are seeing the problem with?  I'm wondering if this is a timing issue where some combination of kernel/udev sees the non hiddev device first...  I assume there must be a way of modifying the udev rule to only create a symlink to the hiddev and not the generic usb device.