Skip to content

Commit a1ce94d

Browse files
e9925248tiwai
authored andcommitted
ALSA: seq: Provide card number / PID via sequencer client info
rawmidi devices expose the card number via IOCTLs, which allows to find the corresponding device in sysfs. The sequencer provides no identifing data. Chromium works around this issue by scanning rawmidi as well as sequencer devices and matching them by using assumtions, how the kernel register sequencer devices. This changes adds support for exposing the card number for kernel clients as well as the PID for user client. The minor of the API version is changed to distinguish between the zero initialised reserved field and card number 0. [minor coding style fixes by tiwai] Signed-off-by: Martin Koegler <[email protected]> Acked-by: Clemens Ladisch <[email protected]> Signed-off-by: Takashi Iwai <[email protected]>
1 parent 56d94d7 commit a1ce94d

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

include/uapi/sound/asequencer.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <sound/asound.h>
2626

2727
/** version of the sequencer */
28-
#define SNDRV_SEQ_VERSION SNDRV_PROTOCOL_VERSION (1, 0, 1)
28+
#define SNDRV_SEQ_VERSION SNDRV_PROTOCOL_VERSION(1, 0, 2)
2929

3030
/**
3131
* definition of sequencer event types
@@ -357,7 +357,9 @@ struct snd_seq_client_info {
357357
unsigned char event_filter[32]; /* event filter bitmap */
358358
int num_ports; /* RO: number of ports */
359359
int event_lost; /* number of lost events */
360-
char reserved[64]; /* for future use */
360+
int card; /* RO: card number[kernel] */
361+
int pid; /* RO: pid[user] */
362+
char reserved[56]; /* for future use */
361363
};
362364

363365

sound/core/seq/seq_clientmgr.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ static int snd_seq_open(struct inode *inode, struct file *file)
364364
/* fill client data */
365365
user->file = file;
366366
sprintf(client->name, "Client-%d", c);
367+
client->data.user.owner = get_pid(task_pid(current));
367368

368369
/* make others aware this new client */
369370
snd_seq_system_client_ev_client_start(c);
@@ -380,6 +381,7 @@ static int snd_seq_release(struct inode *inode, struct file *file)
380381
seq_free_client(client);
381382
if (client->data.user.fifo)
382383
snd_seq_fifo_delete(&client->data.user.fifo);
384+
put_pid(client->data.user.owner);
383385
kfree(client);
384386
}
385387

@@ -1197,6 +1199,17 @@ static void get_client_info(struct snd_seq_client *cptr,
11971199
info->event_lost = cptr->event_lost;
11981200
memcpy(info->event_filter, cptr->event_filter, 32);
11991201
info->num_ports = cptr->num_ports;
1202+
1203+
if (cptr->type == USER_CLIENT)
1204+
info->pid = pid_vnr(cptr->data.user.owner);
1205+
else
1206+
info->pid = -1;
1207+
1208+
if (cptr->type == KERNEL_CLIENT)
1209+
info->card = cptr->data.kernel.card ? cptr->data.kernel.card->number : -1;
1210+
else
1211+
info->card = -1;
1212+
12001213
memset(info->reserved, 0, sizeof(info->reserved));
12011214
}
12021215

@@ -2271,6 +2284,7 @@ int snd_seq_create_kernel_client(struct snd_card *card, int client_index,
22712284

22722285
client->accept_input = 1;
22732286
client->accept_output = 1;
2287+
client->data.kernel.card = card;
22742288

22752289
va_start(args, name_fmt);
22762290
vsnprintf(client->name, sizeof(client->name), name_fmt, args);

sound/core/seq/seq_clientmgr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
struct snd_seq_user_client {
3434
struct file *file; /* file struct of client */
3535
/* ... */
36+
struct pid *owner;
3637

3738
/* fifo */
3839
struct snd_seq_fifo *fifo; /* queue for incoming events */
@@ -41,6 +42,7 @@ struct snd_seq_user_client {
4142

4243
struct snd_seq_kernel_client {
4344
/* ... */
45+
struct snd_card *card;
4446
};
4547

4648

0 commit comments

Comments
 (0)