Skip to contentSkip to conversation

udev: Allow ALSA input jacks to be accessed by the current user

PATCH New David Henningsson 1 participant 1 message Jun 15, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 udev: Allow ALSA input jacks to be accessed by the current user

I know this is probably not the correct upstream, but I just wanted to run it through alsa-devel first to make sure that you don't think this is all madness. :-)

So, one missing piece for userspace (PulseAudio etc) to actually be able to use the jack input devices that ALSA create, is that these devices are accessible by root only. This patch makes the input device nodes accessible by the same users that can access the sound card: the current logged in user, as well as users in the audio group.

One thing I was thinking about, was that the udev-acl rule actually grants read-write access to the input device node, where probably only read access is needed. Is this dangerous?

Signature · 2 lines
David Henningsson, Canonical Ltd.
http://launchpad.net/~diwic
Quoted 1 line

From a45276437c8c3fe62fc001f43d715bfe931dd438 Mon Sep 17 00:00:00 2001

From: David Henningsson <[email protected]>
Date: Wed, 15 Jun 2011 20:36:16 +0200
Subject: [PATCH] udev: Allow ALSA input jacks to be accessed by the current user

One missing piece for userspace (PulseAudio etc) to actually be able to use the jack input devices that ALSA create, is that these devices are accessible by root only. This patch makes the input device nodes accessible by the same users that can access the sound card: the current logged in user, as well as users in the audio group.

---
 extras/input_id/input_id.c              |   23 +++++++++++++++++++++++
 extras/udev-acl/70-acl.rules            |    1 +
 rules/rules.d/60-persistent-input.rules |    1 +
 3 files changed, 25 insertions(+), 0 deletions(-)
extras/input_id/input_id.c +23 -0
index ba53df0..814ce8e 100644
@@ -189,6 +189,25 @@ static void test_key (struct udev *udev,
 		puts("ID_INPUT_KEYBOARD=1");
 }
 
+static void test_sound (struct udev_device *dev,
+		        const unsigned long* bitmask_sw)
+{
+
+	struct udev_device *snd_dev;
+
+	/* Ensure parent is sound card */
+	snd_dev = udev_device_get_parent_with_subsystem_devtype(dev, "sound", NULL);
+	if (!snd_dev)
+		return;
+
+	/* Check that there is at least one relevant switch type */
+	if (test_bit(SW_HEADPHONE_INSERT, bitmask_sw) || 
+	    test_bit(SW_MICROPHONE_INSERT, bitmask_sw) || 
+	    test_bit(SW_LINEOUT_INSERT, bitmask_sw) || 
+	    test_bit(SW_VIDEOOUT_INSERT, bitmask_sw))
+		puts("ID_INPUT_SNDJACK=1");	    
+}
+
 static void help(void)
 {
 	printf("Usage: input_id [options] <device path>\n"
@@ -212,6 +231,7 @@ int main (int argc, char** argv)
 	unsigned long bitmask_abs[NBITS(ABS_MAX)];
 	unsigned long bitmask_key[NBITS(KEY_MAX)];
 	unsigned long bitmask_rel[NBITS(REL_MAX)];
+	unsigned long bitmask_sw[NBITS(SW_MAX)];
 
 	udev = udev_new();
 	if (udev == NULL)
@@ -272,10 +292,13 @@ int main (int argc, char** argv)
 	get_cap_mask (dev, "capabilities/abs", bitmask_abs, sizeof (bitmask_abs));
 	get_cap_mask (dev, "capabilities/rel", bitmask_rel, sizeof (bitmask_rel));
 	get_cap_mask (dev, "capabilities/key", bitmask_key, sizeof (bitmask_key));
+	get_cap_mask (dev, "capabilities/sw", bitmask_sw, sizeof (bitmask_sw));
 
 	test_pointers(bitmask_ev, bitmask_abs, bitmask_key, bitmask_rel);
 
 	test_key(udev, bitmask_ev, bitmask_key);
 
+	test_sound(dev, bitmask_sw);
+
 	return 0;
 }
extras/udev-acl/70-acl.rules +1 -0
index 037349d..a6f54d9 100644
@@ -25,6 +25,7 @@ SUBSYSTEM=="scsi_generic", SUBSYSTEMS=="scsi", ATTRS{type}=="4|5", TAG+="udev-ac
 
 # sound devices
 SUBSYSTEM=="sound", TAG+="udev-acl"
+SUBSYSTEM=="input", ENV{ID_INPUT_SNDJACK}=="1", TAG+="udev-acl"
 
 # ffado is an userspace driver for firewire sound cards
 SUBSYSTEM=="firewire", ENV{ID_FFADO}=="1", TAG+="udev-acl"
rules/rules.d/60-persistent-input.rules +1 -0
index cd1de4e..d04c09e 100644
@@ -12,6 +12,7 @@ ENV{ID_INPUT_MOUSE}=="?*", ENV{.INPUT_CLASS}="mouse"
 ENV{ID_INPUT_TOUCHPAD}=="?*", ENV{.INPUT_CLASS}="mouse"
 ENV{ID_INPUT_TABLET}=="?*", ENV{.INPUT_CLASS}="mouse"
 ENV{ID_INPUT_JOYSTICK}=="?*", ENV{.INPUT_CLASS}="joystick"
+ENV{ID_INPUT_SNDJACK}=="?*", ENV{.INPUT_CLASS}="sndjack", GROUP="audio"
 DRIVERS=="pcspkr", ENV{.INPUT_CLASS}="spkr"
 ATTRS{name}=="*dvb*|*DVB*|* IR *", ENV{.INPUT_CLASS}="ir"
 
Signature · 1 line
1.7.4.1