[PATCH v2] libqmi-glib, proxy: Change ownership of QMI devices to the configured user.

Roshan Pius rpius at chromium.org
Fri Dec 19 09:53:19 PST 2014


Adding a udev rule to change ownership of all QMI devices to the
configured user specified at compile time using --enable-qmi-username
flag.

---
 Makefile.am                                        |  4 ++-
 configure.ac                                       | 33 ++++++++++++++++------
 .../76-qmi-proxy-device-ownership.rules.in         | 12 ++++++++
 src/qmi-proxy/Makefile.am                          |  9 ++++++
 4 files changed, 49 insertions(+), 9 deletions(-)
 create mode 100644 src/qmi-proxy/76-qmi-proxy-device-ownership.rules.in

diff --git a/Makefile.am b/Makefile.am
index 21a6b18..7970fbe 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3,7 +3,9 @@ SUBDIRS = . data build-aux src utils docs
 
 ACLOCAL_AMFLAGS = -I m4
 
-DISTCHECK_CONFIGURE_FLAGS = --enable-gtk-doc
+DISTCHECK_CONFIGURE_FLAGS = \
+	--with-udev-base-dir="$$dc_install_base" \
+	--enable-gtk-doc
 
 EXTRA_DIST = \
 	gtester.make \
diff --git a/configure.ac b/configure.ac
index 754cbae..c1ca6ef 100644
--- a/configure.ac
+++ b/configure.ac
@@ -81,9 +81,25 @@ GTK_DOC_CHECK(1.0)
 
 # QMI username
 AC_ARG_ENABLE(qmi-username,
-              AS_HELP_STRING([--enable-qmi-username=<username>], [user allowed to access QMI devices]),,
-              enable_qmi_username="root")
-AC_DEFINE_UNQUOTED(QMI_USERNAME, "$enable_qmi_username", [Define the QMI username])
+              AS_HELP_STRING([--enable-qmi-username=<username>], [user allowed to access QMI devices]))
+if test -n "$enable_qmi_username" ; then
+    QMI_USERNAME="$enable_qmi_username"
+else
+    QMI_USERNAME="root"
+fi
+AM_CONDITIONAL([INSTALL_QMI_UDEV_RULES], [test "x$enable_qmi_username" = "x$QMI_USERNAME"])
+AC_SUBST(QMI_USERNAME)
+AC_DEFINE_UNQUOTED(QMI_USERNAME, "$QMI_USERNAME", [Define the QMI username])
+AM_COND_IF([INSTALL_QMI_UDEV_RULES], [AC_CONFIG_FILES([src/qmi-proxy/76-qmi-proxy-device-ownership.rules])])
+
+# udev base directory
+AC_ARG_WITH(udev-base-dir, AS_HELP_STRING([--with-udev-base-dir=DIR], [where udev base directory is]))
+if test -n "$with_udev_base_dir" ; then
+    UDEV_BASE_DIR="$with_udev_base_dir"
+else
+    UDEV_BASE_DIR="/lib/udev"
+fi
+AC_SUBST(UDEV_BASE_DIR)
 
 dnl Man page
 AC_PATH_PROG(HELP2MAN, help2man, false)
@@ -116,9 +132,10 @@ echo "
     libqmi (libqmi-glib, qmicli) $VERSION
     ==============================================
 
-    compiler:         ${CC}
-    cflags:           ${CFLAGS}
-    Maintainer mode:  ${USE_MAINTAINER_MODE}
-    Documentation:    ${enable_gtk_doc}
-    QMI username:     ${enable_qmi_username}
+    compiler:             ${CC}
+    cflags:               ${CFLAGS}
+    Maintainer mode:      ${USE_MAINTAINER_MODE}
+    udev base directory:  ${UDEV_BASE_DIR}
+    Documentation:        ${enable_gtk_doc}
+    QMI username:         ${QMI_USERNAME}
 "
diff --git a/src/qmi-proxy/76-qmi-proxy-device-ownership.rules.in b/src/qmi-proxy/76-qmi-proxy-device-ownership.rules.in
new file mode 100644
index 0000000..458113d
--- /dev/null
+++ b/src/qmi-proxy/76-qmi-proxy-device-ownership.rules.in
@@ -0,0 +1,12 @@
+# do not edit this file, it will be overwritten on update
+
+ACTION!="add|change|move", GOTO="qmi_proxy_device_ownership_end"
+
+# A 'cdc-wdm' device is from a MBIM and QMI-based modems.
+KERNEL=="cdc-wdm[0-9]", DRIVERS=="qmi_wwan", SUBSYSTEM=="usbmisc", GOTO="qmi_proxy_device_ownership_change"
+GOTO="qmi_proxy_device_ownership_end"
+
+LABEL="qmi_proxy_device_ownership_change"
+OWNER="@QMI_USERNAME@"
+
+LABEL="qmi_proxy_device_ownership_end"
diff --git a/src/qmi-proxy/Makefile.am b/src/qmi-proxy/Makefile.am
index 709f712..5ac14b7 100644
--- a/src/qmi-proxy/Makefile.am
+++ b/src/qmi-proxy/Makefile.am
@@ -14,3 +14,12 @@ qmi_proxy_SOURCES = qmi-proxy.c
 qmi_proxy_LDADD = \
 	$(GLIB_LIBS) \
 	$(top_builddir)/src/libqmi-glib/libqmi-glib.la
+
+#Install udev rules only if configured with --enable-qmi-username
+if INSTALL_QMI_UDEV_RULES
+udevrulesdir = $(UDEV_BASE_DIR)/rules.d
+udevrules_DATA = 76-qmi-proxy-device-ownership.rules
+
+EXTRA_DIST = \
+	$(udevrules_DATA)
+endif
-- 
2.2.0.rc0.207.ga3a616c



More information about the libqmi-devel mailing list