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

Roshan Pius rpius at chromium.org
Tue Dec 16 10:18:27 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                                       | 24 ++++++++++++++++------
 .../76-qmi-proxy-device-ownership.rules.in         | 12 +++++++++++
 src/qmi-proxy/Makefile.am                          |  6 ++++++
 4 files changed, 39 insertions(+), 7 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..91948bd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -84,6 +84,16 @@ 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])
+AC_SUBST([QMI_USERNAME],  [$enable_qmi_username])
+
+# 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)
@@ -109,16 +119,18 @@ AC_CONFIG_FILES([Makefile
                  docs/reference/Makefile
                  docs/reference/libqmi-glib/Makefile
                  docs/reference/libqmi-glib/version.xml
-                 docs/man/Makefile])
+                 docs/man/Makefile
+                 src/qmi-proxy/76-qmi-proxy-device-ownership.rules])
 AC_OUTPUT
 
 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:         ${enable_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..caf8ee3 100644
--- a/src/qmi-proxy/Makefile.am
+++ b/src/qmi-proxy/Makefile.am
@@ -1,4 +1,7 @@
 
+udevrulesdir = $(UDEV_BASE_DIR)/rules.d
+udevrules_DATA = 76-qmi-proxy-device-ownership.rules
+
 libexec_PROGRAMS = qmi-proxy
 
 qmi_proxy_CPPFLAGS = \
@@ -14,3 +17,6 @@ qmi_proxy_SOURCES = qmi-proxy.c
 qmi_proxy_LDADD = \
 	$(GLIB_LIBS) \
 	$(top_builddir)/src/libqmi-glib/libqmi-glib.la
+
+EXTRA_DIST = \
+	$(udevrules_DATA)
-- 
2.2.0.rc0.207.ga3a616c



More information about the libqmi-devel mailing list