[Pkg-phototools-devel] Bug#531978: libgphoto2: Please modernize udev rules
Martin Pitt
martin.pitt at ubuntu.com
Fri Jun 5 12:50:43 UTC 2009
Package: libgphoto2
Version: 2.4.6-1
Tags: patch
User: ubuntu-devel at lists.ubuntu.com
Usertags: origin-ubuntu ubuntu-patch karmic
Hello,
I recently did some ramblings about modernizing libgphoto2's udev
rules to work in a Linux world without hal [1]. I added a new udev
rule mode "136" and while I was at it, replaced the slow
check-ptp-camera shell script with a more efficient udev db query.
The patch got committed upstream now.
This doesn't break functionality with hal at all, of course.
This debdiff applies it to the Debian package and also moves udev rule
creation from postinst to debian/rules. This is possible now, since
from udev 136 on, rules are shipped in /lib/udev/rules.d/, thus
avoid becoming conffiles.
Thanks for considering,
Martin
[1] http://lists.freedesktop.org/archives/devkit-devel/2009-June/000191.html
[2] https://sourceforge.net/tracker/?func=detail&aid=2801117&group_id=8874&atid=308874
--
Martin Pitt | http://www.piware.de
Ubuntu Developer (www.ubuntu.com) | Debian Developer (www.debian.org)
-------------- next part --------------
* Add patch 01_udev_rules_136: Add a new udev mode "136" to create
contemporary udev rules which will avoid using the check_ptp_camera
script, and provide udev DB tags for the hal deprecation. (Now accepted
into upstream svn).
* debian/libgphoto2-2.postinst: Drop udev rule creation. Udev rules are
shipped in /lib now since udev 136, thus we can do it at build time. Drop
debian/libgphoto2-2.dirs for this.
* debian/rules: Create udev rules (with new mode 136), install them with
dh_installudev.
diff -u libgphoto2-2.4.6/debian/libgphoto2-2.postinst libgphoto2-2.4.6/debian/libgphoto2-2.postinst
--- libgphoto2-2.4.6/debian/libgphoto2-2.postinst
+++ libgphoto2-2.4.6/debian/libgphoto2-2.postinst
@@ -16,25 +16,6 @@
rm -f /usr/share/hal/fdi/information/10freedesktop/10-camera-$PACKAGE.fdi
rm -f /usr/share/hal/fdi/information/20thirdparty/$PACKAGE.fdi
rm -f /usr/share/hal/fdi/information/10freedesktop/10-camera-$PACKAGE-device.fdi
-
- # create udev rules file
- if [ -d /etc/udev/ ]; then
- /usr/lib/$PACKAGE/print-camera-list udev-rules version 0.98 mode 0664 group plugdev > /etc/udev/$PACKAGE.rules
- # install the udev file only once:
- # - the first time the package is installed
- # OR - the first time the package is upgraded from a version earlier than 2.1.6-5.1
- if [ -z "$2" ] || dpkg --compare-versions "$2" lt 2.1.6-5.1 ; then
- ln -sf ../$PACKAGE.rules /etc/udev/rules.d/025_$PACKAGE.rules
- fi
-
- if [ -L /etc/udev/rules.d/020_libgphoto2_generic-ptp_support.rules ]; then
- rm -f /etc/udev/rules.d/020_libgphoto2_generic-ptp_support.rules
- fi
-
- if [ -f /etc/udev/libgphoto2_generic-ptp_support.rules ]; then
- rm -f /etc/udev/libgphoto2_generic-ptp_support.rules
- fi
- fi
;;
abort-upgrade|abort-remove|abort-deconfigure)
diff -u libgphoto2-2.4.6/debian/libgphoto2-2.postrm libgphoto2-2.4.6/debian/libgphoto2-2.postrm
diff -u libgphoto2-2.4.6/debian/changelog libgphoto2-2.4.6/debian/changelog
--- libgphoto2-2.4.6/debian/rules
+++ libgphoto2-2.4.6/debian/rules
@@ -85,8 +85,14 @@
debian/libgphoto2-port0/usr/share/doc/libgphoto2-port0
ifeq ($(DEB_HOST_ARCH_OS),linux)
- install -D packaging/generic/check-ptp-camera debian/libgphoto2-$(major)/lib/udev/check-ptp-camera
+ # we don't need this any more with current udev
rm debian/tmp/usr/lib/udev/check-ptp-camera
+
+ # create udev rules
+ ./packaging/generic/print-camera-list udev-rules version 136 mode 0664 group plugdev > debian/libgphoto2-$(major).udev
+ dh_installudev
+ rm debian/libgphoto2-$(major).udev
+
-test -e debian/tmp/usr/lib/udev/check-mtp-device && \
mkdir -p debian/libgphoto2-port0/lib/udev && \
mv debian/tmp/usr/lib/udev/check-mtp-device \
@@ -122,7 +128,7 @@
dh_gencontrol -plibgphoto2-$(major)-dev
dh_gencontrol -plibgphoto2-port0
ifeq (linux,$(DEB_HOST_ARCH_OS))
- dh_gencontrol -plibgphoto2-$(major) -- -Vudev-hotplug='udev (>= 0.113-1)'
+ dh_gencontrol -plibgphoto2-$(major) -- -Vudev-hotplug='udev (>= 0.136)'
else
dh_gencontrol -plibgphoto2-$(major)
endif
reverted:
--- libgphoto2-2.4.6/debian/libgphoto2-2.dirs
+++ libgphoto2-2.4.6.orig/debian/libgphoto2-2.dirs
@@ -1 +0,0 @@
-etc/udev/rules.d
diff -u libgphoto2-2.4.6/debian/patches/series libgphoto2-2.4.6/debian/patches/series
--- libgphoto2-2.4.6/debian/patches/series
+++ libgphoto2-2.4.6/debian/patches/series
@@ -1,3 +1,4 @@
+01_udev_rules_136
10_disable_cache
#11_hurd_no_path_max_bsdsource
#45_increase_canon_timeout
only in patch2:
unchanged:
--- libgphoto2-2.4.6.orig/debian/patches/01_udev_rules_136
+++ libgphoto2-2.4.6/debian/patches/01_udev_rules_136
@@ -0,0 +1,108 @@
+# Description: Add a new udev mode "136" to create contemporary udev rules which will avoid using the check_ptp_camera script, and provide udev DB tags for the hal deprecation. See http://lists.freedesktop.org/archives/devkit-devel/2009-June/000191.html for discussion.
+# Upstream: http://sourceforge.net/tracker/?func=detail&aid=2801117&group_id=8874&atid=308874 (in svn head)
+Index: libgphoto2-2.4.6/packaging/generic/print-camera-list.c
+===================================================================
+--- libgphoto2-2.4.6.orig/packaging/generic/print-camera-list.c 2009-06-05 13:34:52.000000000 +0200
++++ libgphoto2-2.4.6/packaging/generic/print-camera-list.c 2009-06-05 13:35:17.000000000 +0200
+@@ -366,12 +366,14 @@
+
+ typedef enum {
+ UDEV_PRE_0_98 = 0,
+- UDEV_0_98 = 1
++ UDEV_0_98 = 1,
++ UDEV_136 = 2
+ } udev_version_t;
+
+ static const StringFlagItem udev_version_t_map[] = {
+ { "pre-0.98", UDEV_PRE_0_98 },
+ { "0.98", UDEV_0_98 },
++ { "136", UDEV_136 },
+ { NULL, 0 }
+ };
+
+@@ -399,13 +401,20 @@
+ "ACTION!=\"add\", GOTO=\"libgphoto2_rules_end\"\n\n",
+ /* UDEV_0_98 */
+ "SUBSYSTEM!=\"usb|usb_device\", GOTO=\"libgphoto2_rules_end\"\n"
++ "ACTION!=\"add\", GOTO=\"libgphoto2_rules_end\"\n\n",
++ /* UDEV_136 */
++ "SUBSYSTEM!=\"usb\", GOTO=\"libgphoto2_rules_end\"\n"
++ "ENV{DEVTYPE}!=\"usb_device\", GOTO=\"libgphoto2_rules_end\"\n"
+ "ACTION!=\"add\", GOTO=\"libgphoto2_rules_end\"\n\n"
++ "ENV{ID_USB_INTERFACES}==\"\", IMPORT{program}=\"usb_id --export %%p\"\n\n"
+ };
+ static const char * const usbcam_strings[] = {
+ /* UDEV_PRE_0_98 */
+- "SYSFS{idVendor}==\"%04x\", SYSFS{idProduct}==\"%04x\", ",
++ "SYSFS{idVendor}==\"%04x\", SYSFS{idProduct}==\"%04x\"",
+ /* UDEV_0_98 */
+- "ATTRS{idVendor}==\"%04x\", ATTRS{idProduct}==\"%04x\", ",
++ "ATTRS{idVendor}==\"%04x\", ATTRS{idProduct}==\"%04x\"",
++ /* UDEV_136 */
++ "ATTRS{idVendor}==\"%04x\", ATTRS{idProduct}==\"%04x\", ENV{ID_GPHOTO2}=\"1\", ENV{GPHOTO2_DRIVER}=\"proprietary\""
+ };
+ udev_persistent_data_t *pdata;
+ pdata = calloc(1, sizeof(udev_persistent_data_t));
+@@ -444,7 +453,8 @@
+ && pdata->mode == NULL
+ && pdata->group == NULL
+ && pdata->owner == NULL
+- && pdata->script == NULL) {
++ && pdata->script == NULL
++ && pdata->version <= UDEV_0_98) {
+ FATAL("Either <script> or <mode,group,owner> parameters must be given.");
+ }
+ if ((pdata->script != NULL) && (pdata->mode != NULL
+@@ -547,7 +557,11 @@
+
+ if (flags & GP_USB_HOTPLUG_MATCH_INT_CLASS) {
+ if ((flags & (GP_USB_HOTPLUG_MATCH_INT_CLASS|GP_USB_HOTPLUG_MATCH_INT_SUBCLASS|GP_USB_HOTPLUG_MATCH_INT_PROTOCOL)) == (GP_USB_HOTPLUG_MATCH_INT_CLASS|GP_USB_HOTPLUG_MATCH_INT_SUBCLASS|GP_USB_HOTPLUG_MATCH_INT_PROTOCOL)) {
+- printf("PROGRAM=\"check-ptp-camera %02d/%02d/%02d\", ", class, subclass, proto);
++ if (pdata->version == UDEV_136) {
++ printf("ENV{ID_USB_INTERFACES}==\"*:%02d%02d%02d:*\", ENV{ID_GPHOTO2}=\"1\", ENV{GPHOTO2_DRIVER}=\"PTP\"", class, subclass, proto);
++ } else {
++ printf("PROGRAM=\"check-ptp-camera %02d/%02d/%02d\"", class, subclass, proto);
++ }
+ has_valid_rule = 1;
+ } else {
+ if (class == 666) {
+@@ -568,6 +582,9 @@
+ }
+ }
+ if (has_valid_rule != 0) {
++ if (pdata->script != NULL || pdata->mode != NULL || pdata->owner != NULL || pdata->group != NULL)
++ printf(", ");
++
+ if (pdata->script != NULL) {
+ printf("RUN+=\"%s\"\n", pdata->script);
+ } else if (pdata->mode != NULL || pdata->owner != NULL || pdata->group != NULL) {
+@@ -589,7 +606,8 @@
+ printf("\n");
+ } else {
+ printf("\n");
+- FATAL("udev_camera_func(): illegal branch");
++ if (pdata->version < UDEV_136)
++ FATAL("udev_camera_func(): illegal branch");
+ }
+ }
+ return 0;
+@@ -1118,12 +1136,16 @@
+ fdi_device_end_func
+ },
+ {"udev-rules",
+- "udev rules file either for pre-0.98 or 0.98 and later",
+- "Put it into /etc/udev/rules.d/90-libgphoto2.rules, set file mode, owner, group\n"
++ "udev rules file",
++ "For modes \"pre-0.98\" and \"0.98\" (and later), put it into\n"
++ " /etc/udev/rules.d/90-libgphoto2.rules, set file mode, owner, group\n"
+ " or add script to run. This rule files also uses the\n"
+ " check-ptp-camera script included in libgphoto2 source. Either put it to\n"
+ " /lib/udev/check-ptp-camera or adjust the path in the generated rules file.\n"
+- " If you give a script parameter, the mode, owner, group parameters will be ignored.",
++ " If you give a script parameter, the mode, owner, group parameters will be ignored.\n"
++ " For mode \"136\" put it into /lib/udev/rules.d/40-libgphoto2.rules;\n"
++ " you can still use mode/owner/group, but the preferred mode of operation\n"
++ " is to use udev-extras for dynamic access permissions.\n",
+ "[script <PATH_TO_SCRIPT>|version <version>|mode <mode>|owner <owner>|group <group>]*",
+ udev_begin_func,
+ udev_camera_func,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
URL: <http://lists.alioth.debian.org/pipermail/pkg-phototools-devel/attachments/20090605/04cc9e8f/attachment.pgp>
More information about the Pkg-phototools-devel
mailing list